]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.6-201302092141.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.6-201302092141.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 74c25c8..deadba2 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 @@ -186,6 +205,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 @@ -195,6 +216,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160 +pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164 @@ -204,7 +226,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 @@ -214,8 +239,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 @@ -225,6 +253,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 @@ -236,13 +265,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 @@ -250,9 +283,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 9776f06..18b1856 100644
227 --- a/Documentation/kernel-parameters.txt
228 +++ b/Documentation/kernel-parameters.txt
229 @@ -905,6 +905,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 gpt [EFI] Forces disk with valid GPT signature but
231 invalid Protective MBR to be treated as GPT.
232
233 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234 + ignore grsecurity's /proc restrictions
235 +
236 hashdist= [KNL,NUMA] Large hashes allocated during boot
237 are distributed across NUMA nodes. Defaults on
238 for 64-bit NUMA, off otherwise.
239 @@ -2082,6 +2085,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
240 the specified number of seconds. This is to be used if
241 your oopses keep scrolling off the screen.
242
243 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
244 + virtualization environments that don't cope well with the
245 + expand down segment used by UDEREF on X86-32 or the frequent
246 + page table updates on X86-64.
247 +
248 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
249 +
250 pcbit= [HW,ISDN]
251
252 pcd. [PARIDE]
253 diff --git a/Makefile b/Makefile
254 index b6de2ea..5ba90ee 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -575,6 +576,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(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.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -731,7 +786,7 @@ export mod_sign_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -778,6 +833,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -787,7 +844,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -831,6 +888,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -938,6 +996,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -953,7 +1013,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -1013,7 +1073,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
395 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
396 signing_key.priv signing_key.x509 x509.genkey \
397 extra_certificates signing_key.x509.keyid \
398 - signing_key.x509.signer
399 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
400
401 # clean - Delete most, but leave enough to build external modules
402 #
403 @@ -1053,6 +1113,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1213,6 +1274,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1349,17 +1412,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1369,11 +1436,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index 14db93e..47bed62 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
586 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
587
588 static unsigned long
589 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
590 - unsigned long limit)
591 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
592 + unsigned long limit, unsigned long flags)
593 {
594 struct vm_area_struct *vma = find_vma(current->mm, addr);
595 -
596 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
597 while (1) {
598 /* At this point: (!vma || addr < vma->vm_end). */
599 if (limit - len < addr)
600 return -ENOMEM;
601 - if (!vma || addr + len <= vma->vm_start)
602 + if (check_heap_stack_gap(vma, addr, len, offset))
603 return addr;
604 addr = vma->vm_end;
605 vma = vma->vm_next;
606 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
607 merely specific addresses, but regions of memory -- perhaps
608 this feature should be incorporated into all ports? */
609
610 +#ifdef CONFIG_PAX_RANDMMAP
611 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
612 +#endif
613 +
614 if (addr) {
615 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
616 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
617 if (addr != (unsigned long) -ENOMEM)
618 return addr;
619 }
620
621 /* Next, try allocating at TASK_UNMAPPED_BASE. */
622 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
623 - len, limit);
624 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
625 +
626 if (addr != (unsigned long) -ENOMEM)
627 return addr;
628
629 /* Finally, try allocating in low memory. */
630 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
631 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
632
633 return addr;
634 }
635 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
636 index 0c4132d..88f0d53 100644
637 --- a/arch/alpha/mm/fault.c
638 +++ b/arch/alpha/mm/fault.c
639 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
640 __reload_thread(pcb);
641 }
642
643 +#ifdef CONFIG_PAX_PAGEEXEC
644 +/*
645 + * PaX: decide what to do with offenders (regs->pc = fault address)
646 + *
647 + * returns 1 when task should be killed
648 + * 2 when patched PLT trampoline was detected
649 + * 3 when unpatched PLT trampoline was detected
650 + */
651 +static int pax_handle_fetch_fault(struct pt_regs *regs)
652 +{
653 +
654 +#ifdef CONFIG_PAX_EMUPLT
655 + int err;
656 +
657 + do { /* PaX: patched PLT emulation #1 */
658 + unsigned int ldah, ldq, jmp;
659 +
660 + err = get_user(ldah, (unsigned int *)regs->pc);
661 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
662 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
663 +
664 + if (err)
665 + break;
666 +
667 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
668 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
669 + jmp == 0x6BFB0000U)
670 + {
671 + unsigned long r27, addr;
672 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
673 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
674 +
675 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
676 + err = get_user(r27, (unsigned long *)addr);
677 + if (err)
678 + break;
679 +
680 + regs->r27 = r27;
681 + regs->pc = r27;
682 + return 2;
683 + }
684 + } while (0);
685 +
686 + do { /* PaX: patched PLT emulation #2 */
687 + unsigned int ldah, lda, br;
688 +
689 + err = get_user(ldah, (unsigned int *)regs->pc);
690 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
691 + err |= get_user(br, (unsigned int *)(regs->pc+8));
692 +
693 + if (err)
694 + break;
695 +
696 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
697 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
698 + (br & 0xFFE00000U) == 0xC3E00000U)
699 + {
700 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
701 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
702 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
703 +
704 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
705 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
706 + return 2;
707 + }
708 + } while (0);
709 +
710 + do { /* PaX: unpatched PLT emulation */
711 + unsigned int br;
712 +
713 + err = get_user(br, (unsigned int *)regs->pc);
714 +
715 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
716 + unsigned int br2, ldq, nop, jmp;
717 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
718 +
719 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
720 + err = get_user(br2, (unsigned int *)addr);
721 + err |= get_user(ldq, (unsigned int *)(addr+4));
722 + err |= get_user(nop, (unsigned int *)(addr+8));
723 + err |= get_user(jmp, (unsigned int *)(addr+12));
724 + err |= get_user(resolver, (unsigned long *)(addr+16));
725 +
726 + if (err)
727 + break;
728 +
729 + if (br2 == 0xC3600000U &&
730 + ldq == 0xA77B000CU &&
731 + nop == 0x47FF041FU &&
732 + jmp == 0x6B7B0000U)
733 + {
734 + regs->r28 = regs->pc+4;
735 + regs->r27 = addr+16;
736 + regs->pc = resolver;
737 + return 3;
738 + }
739 + }
740 + } while (0);
741 +#endif
742 +
743 + return 1;
744 +}
745 +
746 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
747 +{
748 + unsigned long i;
749 +
750 + printk(KERN_ERR "PAX: bytes at PC: ");
751 + for (i = 0; i < 5; i++) {
752 + unsigned int c;
753 + if (get_user(c, (unsigned int *)pc+i))
754 + printk(KERN_CONT "???????? ");
755 + else
756 + printk(KERN_CONT "%08x ", c);
757 + }
758 + printk("\n");
759 +}
760 +#endif
761
762 /*
763 * This routine handles page faults. It determines the address,
764 @@ -133,8 +251,29 @@ retry:
765 good_area:
766 si_code = SEGV_ACCERR;
767 if (cause < 0) {
768 - if (!(vma->vm_flags & VM_EXEC))
769 + if (!(vma->vm_flags & VM_EXEC)) {
770 +
771 +#ifdef CONFIG_PAX_PAGEEXEC
772 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
773 + goto bad_area;
774 +
775 + up_read(&mm->mmap_sem);
776 + switch (pax_handle_fetch_fault(regs)) {
777 +
778 +#ifdef CONFIG_PAX_EMUPLT
779 + case 2:
780 + case 3:
781 + return;
782 +#endif
783 +
784 + }
785 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
786 + do_group_exit(SIGKILL);
787 +#else
788 goto bad_area;
789 +#endif
790 +
791 + }
792 } else if (!cause) {
793 /* Allow reads even for write-only mappings */
794 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
795 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
796 index c79f61f..9ac0642 100644
797 --- a/arch/arm/include/asm/atomic.h
798 +++ b/arch/arm/include/asm/atomic.h
799 @@ -17,17 +17,35 @@
800 #include <asm/barrier.h>
801 #include <asm/cmpxchg.h>
802
803 +#ifdef CONFIG_GENERIC_ATOMIC64
804 +#include <asm-generic/atomic64.h>
805 +#endif
806 +
807 #define ATOMIC_INIT(i) { (i) }
808
809 #ifdef __KERNEL__
810
811 +#define _ASM_EXTABLE(from, to) \
812 +" .pushsection __ex_table,\"a\"\n"\
813 +" .align 3\n" \
814 +" .long " #from ", " #to"\n" \
815 +" .popsection"
816 +
817 /*
818 * On ARM, ordinary assignment (str instruction) doesn't clear the local
819 * strex/ldrex monitor on some implementations. The reason we can use it for
820 * atomic_set() is the clrex or dummy strex done on every exception return.
821 */
822 #define atomic_read(v) (*(volatile int *)&(v)->counter)
823 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
824 +{
825 + return v->counter;
826 +}
827 #define atomic_set(v,i) (((v)->counter) = (i))
828 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
829 +{
830 + v->counter = i;
831 +}
832
833 #if __LINUX_ARM_ARCH__ >= 6
834
835 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
836 int result;
837
838 __asm__ __volatile__("@ atomic_add\n"
839 +"1: ldrex %1, [%3]\n"
840 +" adds %0, %1, %4\n"
841 +
842 +#ifdef CONFIG_PAX_REFCOUNT
843 +" bvc 3f\n"
844 +"2: bkpt 0xf103\n"
845 +"3:\n"
846 +#endif
847 +
848 +" strex %1, %0, [%3]\n"
849 +" teq %1, #0\n"
850 +" bne 1b"
851 +
852 +#ifdef CONFIG_PAX_REFCOUNT
853 +"\n4:\n"
854 + _ASM_EXTABLE(2b, 4b)
855 +#endif
856 +
857 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
858 + : "r" (&v->counter), "Ir" (i)
859 + : "cc");
860 +}
861 +
862 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
863 +{
864 + unsigned long tmp;
865 + int result;
866 +
867 + __asm__ __volatile__("@ atomic_add_unchecked\n"
868 "1: ldrex %0, [%3]\n"
869 " add %0, %0, %4\n"
870 " strex %1, %0, [%3]\n"
871 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
872 smp_mb();
873
874 __asm__ __volatile__("@ atomic_add_return\n"
875 +"1: ldrex %1, [%3]\n"
876 +" adds %0, %1, %4\n"
877 +
878 +#ifdef CONFIG_PAX_REFCOUNT
879 +" bvc 3f\n"
880 +" mov %0, %1\n"
881 +"2: bkpt 0xf103\n"
882 +"3:\n"
883 +#endif
884 +
885 +" strex %1, %0, [%3]\n"
886 +" teq %1, #0\n"
887 +" bne 1b"
888 +
889 +#ifdef CONFIG_PAX_REFCOUNT
890 +"\n4:\n"
891 + _ASM_EXTABLE(2b, 4b)
892 +#endif
893 +
894 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
895 + : "r" (&v->counter), "Ir" (i)
896 + : "cc");
897 +
898 + smp_mb();
899 +
900 + return result;
901 +}
902 +
903 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
904 +{
905 + unsigned long tmp;
906 + int result;
907 +
908 + smp_mb();
909 +
910 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
911 "1: ldrex %0, [%3]\n"
912 " add %0, %0, %4\n"
913 " strex %1, %0, [%3]\n"
914 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
915 int result;
916
917 __asm__ __volatile__("@ atomic_sub\n"
918 +"1: ldrex %1, [%3]\n"
919 +" subs %0, %1, %4\n"
920 +
921 +#ifdef CONFIG_PAX_REFCOUNT
922 +" bvc 3f\n"
923 +"2: bkpt 0xf103\n"
924 +"3:\n"
925 +#endif
926 +
927 +" strex %1, %0, [%3]\n"
928 +" teq %1, #0\n"
929 +" bne 1b"
930 +
931 +#ifdef CONFIG_PAX_REFCOUNT
932 +"\n4:\n"
933 + _ASM_EXTABLE(2b, 4b)
934 +#endif
935 +
936 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937 + : "r" (&v->counter), "Ir" (i)
938 + : "cc");
939 +}
940 +
941 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
942 +{
943 + unsigned long tmp;
944 + int result;
945 +
946 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
947 "1: ldrex %0, [%3]\n"
948 " sub %0, %0, %4\n"
949 " strex %1, %0, [%3]\n"
950 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
951 smp_mb();
952
953 __asm__ __volatile__("@ atomic_sub_return\n"
954 -"1: ldrex %0, [%3]\n"
955 -" sub %0, %0, %4\n"
956 +"1: ldrex %1, [%3]\n"
957 +" subs %0, %1, %4\n"
958 +
959 +#ifdef CONFIG_PAX_REFCOUNT
960 +" bvc 3f\n"
961 +" mov %0, %1\n"
962 +"2: bkpt 0xf103\n"
963 +"3:\n"
964 +#endif
965 +
966 " strex %1, %0, [%3]\n"
967 " teq %1, #0\n"
968 " bne 1b"
969 +
970 +#ifdef CONFIG_PAX_REFCOUNT
971 +"\n4:\n"
972 + _ASM_EXTABLE(2b, 4b)
973 +#endif
974 +
975 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
976 : "r" (&v->counter), "Ir" (i)
977 : "cc");
978 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
979 return oldval;
980 }
981
982 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
983 +{
984 + unsigned long oldval, res;
985 +
986 + smp_mb();
987 +
988 + do {
989 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
990 + "ldrex %1, [%3]\n"
991 + "mov %0, #0\n"
992 + "teq %1, %4\n"
993 + "strexeq %0, %5, [%3]\n"
994 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
995 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
996 + : "cc");
997 + } while (res);
998 +
999 + smp_mb();
1000 +
1001 + return oldval;
1002 +}
1003 +
1004 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1005 {
1006 unsigned long tmp, tmp2;
1007 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1008
1009 return val;
1010 }
1011 +
1012 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1013 +{
1014 + return atomic_add_return(i, v);
1015 +}
1016 +
1017 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1018 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1019 +{
1020 + (void) atomic_add_return(i, v);
1021 +}
1022
1023 static inline int atomic_sub_return(int i, atomic_t *v)
1024 {
1025 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1026 return val;
1027 }
1028 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1029 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1030 +{
1031 + (void) atomic_sub_return(i, v);
1032 +}
1033
1034 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1035 {
1036 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1037 return ret;
1038 }
1039
1040 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1041 +{
1042 + return atomic_cmpxchg(v, old, new);
1043 +}
1044 +
1045 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1046 {
1047 unsigned long flags;
1048 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1049 #endif /* __LINUX_ARM_ARCH__ */
1050
1051 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1052 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1053 +{
1054 + return xchg(&v->counter, new);
1055 +}
1056
1057 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1058 {
1059 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1060 }
1061
1062 #define atomic_inc(v) atomic_add(1, v)
1063 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1064 +{
1065 + atomic_add_unchecked(1, v);
1066 +}
1067 #define atomic_dec(v) atomic_sub(1, v)
1068 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1069 +{
1070 + atomic_sub_unchecked(1, v);
1071 +}
1072
1073 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1074 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1075 +{
1076 + return atomic_add_return_unchecked(1, v) == 0;
1077 +}
1078 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1079 #define atomic_inc_return(v) (atomic_add_return(1, v))
1080 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1081 +{
1082 + return atomic_add_return_unchecked(1, v);
1083 +}
1084 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1085 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1086
1087 @@ -241,6 +428,14 @@ typedef struct {
1088 u64 __aligned(8) counter;
1089 } atomic64_t;
1090
1091 +#ifdef CONFIG_PAX_REFCOUNT
1092 +typedef struct {
1093 + u64 __aligned(8) counter;
1094 +} atomic64_unchecked_t;
1095 +#else
1096 +typedef atomic64_t atomic64_unchecked_t;
1097 +#endif
1098 +
1099 #define ATOMIC64_INIT(i) { (i) }
1100
1101 static inline u64 atomic64_read(const atomic64_t *v)
1102 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1103 return result;
1104 }
1105
1106 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1107 +{
1108 + u64 result;
1109 +
1110 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1111 +" ldrexd %0, %H0, [%1]"
1112 + : "=&r" (result)
1113 + : "r" (&v->counter), "Qo" (v->counter)
1114 + );
1115 +
1116 + return result;
1117 +}
1118 +
1119 static inline void atomic64_set(atomic64_t *v, u64 i)
1120 {
1121 u64 tmp;
1122 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1123 : "cc");
1124 }
1125
1126 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1127 +{
1128 + u64 tmp;
1129 +
1130 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1131 +"1: ldrexd %0, %H0, [%2]\n"
1132 +" strexd %0, %3, %H3, [%2]\n"
1133 +" teq %0, #0\n"
1134 +" bne 1b"
1135 + : "=&r" (tmp), "=Qo" (v->counter)
1136 + : "r" (&v->counter), "r" (i)
1137 + : "cc");
1138 +}
1139 +
1140 static inline void atomic64_add(u64 i, atomic64_t *v)
1141 {
1142 u64 result;
1143 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1144 __asm__ __volatile__("@ atomic64_add\n"
1145 "1: ldrexd %0, %H0, [%3]\n"
1146 " adds %0, %0, %4\n"
1147 +" adcs %H0, %H0, %H4\n"
1148 +
1149 +#ifdef CONFIG_PAX_REFCOUNT
1150 +" bvc 3f\n"
1151 +"2: bkpt 0xf103\n"
1152 +"3:\n"
1153 +#endif
1154 +
1155 +" strexd %1, %0, %H0, [%3]\n"
1156 +" teq %1, #0\n"
1157 +" bne 1b"
1158 +
1159 +#ifdef CONFIG_PAX_REFCOUNT
1160 +"\n4:\n"
1161 + _ASM_EXTABLE(2b, 4b)
1162 +#endif
1163 +
1164 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1165 + : "r" (&v->counter), "r" (i)
1166 + : "cc");
1167 +}
1168 +
1169 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1170 +{
1171 + u64 result;
1172 + unsigned long tmp;
1173 +
1174 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1175 +"1: ldrexd %0, %H0, [%3]\n"
1176 +" adds %0, %0, %4\n"
1177 " adc %H0, %H0, %H4\n"
1178 " strexd %1, %0, %H0, [%3]\n"
1179 " teq %1, #0\n"
1180 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1181
1182 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1183 {
1184 - u64 result;
1185 - unsigned long tmp;
1186 + u64 result, tmp;
1187
1188 smp_mb();
1189
1190 __asm__ __volatile__("@ atomic64_add_return\n"
1191 +"1: ldrexd %1, %H1, [%3]\n"
1192 +" adds %0, %1, %4\n"
1193 +" adcs %H0, %H1, %H4\n"
1194 +
1195 +#ifdef CONFIG_PAX_REFCOUNT
1196 +" bvc 3f\n"
1197 +" mov %0, %1\n"
1198 +" mov %H0, %H1\n"
1199 +"2: bkpt 0xf103\n"
1200 +"3:\n"
1201 +#endif
1202 +
1203 +" strexd %1, %0, %H0, [%3]\n"
1204 +" teq %1, #0\n"
1205 +" bne 1b"
1206 +
1207 +#ifdef CONFIG_PAX_REFCOUNT
1208 +"\n4:\n"
1209 + _ASM_EXTABLE(2b, 4b)
1210 +#endif
1211 +
1212 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1213 + : "r" (&v->counter), "r" (i)
1214 + : "cc");
1215 +
1216 + smp_mb();
1217 +
1218 + return result;
1219 +}
1220 +
1221 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1222 +{
1223 + u64 result;
1224 + unsigned long tmp;
1225 +
1226 + smp_mb();
1227 +
1228 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1229 "1: ldrexd %0, %H0, [%3]\n"
1230 " adds %0, %0, %4\n"
1231 " adc %H0, %H0, %H4\n"
1232 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1233 __asm__ __volatile__("@ atomic64_sub\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " subs %0, %0, %4\n"
1236 +" sbcs %H0, %H0, %H4\n"
1237 +
1238 +#ifdef CONFIG_PAX_REFCOUNT
1239 +" bvc 3f\n"
1240 +"2: bkpt 0xf103\n"
1241 +"3:\n"
1242 +#endif
1243 +
1244 +" strexd %1, %0, %H0, [%3]\n"
1245 +" teq %1, #0\n"
1246 +" bne 1b"
1247 +
1248 +#ifdef CONFIG_PAX_REFCOUNT
1249 +"\n4:\n"
1250 + _ASM_EXTABLE(2b, 4b)
1251 +#endif
1252 +
1253 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1254 + : "r" (&v->counter), "r" (i)
1255 + : "cc");
1256 +}
1257 +
1258 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1259 +{
1260 + u64 result;
1261 + unsigned long tmp;
1262 +
1263 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1264 +"1: ldrexd %0, %H0, [%3]\n"
1265 +" subs %0, %0, %4\n"
1266 " sbc %H0, %H0, %H4\n"
1267 " strexd %1, %0, %H0, [%3]\n"
1268 " teq %1, #0\n"
1269 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1270
1271 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1272 {
1273 - u64 result;
1274 - unsigned long tmp;
1275 + u64 result, tmp;
1276
1277 smp_mb();
1278
1279 __asm__ __volatile__("@ atomic64_sub_return\n"
1280 -"1: ldrexd %0, %H0, [%3]\n"
1281 -" subs %0, %0, %4\n"
1282 -" sbc %H0, %H0, %H4\n"
1283 +"1: ldrexd %1, %H1, [%3]\n"
1284 +" subs %0, %1, %4\n"
1285 +" sbcs %H0, %H1, %H4\n"
1286 +
1287 +#ifdef CONFIG_PAX_REFCOUNT
1288 +" bvc 3f\n"
1289 +" mov %0, %1\n"
1290 +" mov %H0, %H1\n"
1291 +"2: bkpt 0xf103\n"
1292 +"3:\n"
1293 +#endif
1294 +
1295 " strexd %1, %0, %H0, [%3]\n"
1296 " teq %1, #0\n"
1297 " bne 1b"
1298 +
1299 +#ifdef CONFIG_PAX_REFCOUNT
1300 +"\n4:\n"
1301 + _ASM_EXTABLE(2b, 4b)
1302 +#endif
1303 +
1304 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1305 : "r" (&v->counter), "r" (i)
1306 : "cc");
1307 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1308 return oldval;
1309 }
1310
1311 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1312 +{
1313 + u64 oldval;
1314 + unsigned long res;
1315 +
1316 + smp_mb();
1317 +
1318 + do {
1319 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1320 + "ldrexd %1, %H1, [%3]\n"
1321 + "mov %0, #0\n"
1322 + "teq %1, %4\n"
1323 + "teqeq %H1, %H4\n"
1324 + "strexdeq %0, %5, %H5, [%3]"
1325 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1326 + : "r" (&ptr->counter), "r" (old), "r" (new)
1327 + : "cc");
1328 + } while (res);
1329 +
1330 + smp_mb();
1331 +
1332 + return oldval;
1333 +}
1334 +
1335 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1336 {
1337 u64 result;
1338 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1339
1340 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1341 {
1342 - u64 result;
1343 - unsigned long tmp;
1344 + u64 result, tmp;
1345
1346 smp_mb();
1347
1348 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1349 -"1: ldrexd %0, %H0, [%3]\n"
1350 -" subs %0, %0, #1\n"
1351 -" sbc %H0, %H0, #0\n"
1352 +"1: ldrexd %1, %H1, [%3]\n"
1353 +" subs %0, %1, #1\n"
1354 +" sbcs %H0, %H1, #0\n"
1355 +
1356 +#ifdef CONFIG_PAX_REFCOUNT
1357 +" bvc 3f\n"
1358 +" mov %0, %1\n"
1359 +" mov %H0, %H1\n"
1360 +"2: bkpt 0xf103\n"
1361 +"3:\n"
1362 +#endif
1363 +
1364 " teq %H0, #0\n"
1365 -" bmi 2f\n"
1366 +" bmi 4f\n"
1367 " strexd %1, %0, %H0, [%3]\n"
1368 " teq %1, #0\n"
1369 " bne 1b\n"
1370 -"2:"
1371 +"4:\n"
1372 +
1373 +#ifdef CONFIG_PAX_REFCOUNT
1374 + _ASM_EXTABLE(2b, 4b)
1375 +#endif
1376 +
1377 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1378 : "r" (&v->counter)
1379 : "cc");
1380 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1381 " teq %0, %5\n"
1382 " teqeq %H0, %H5\n"
1383 " moveq %1, #0\n"
1384 -" beq 2f\n"
1385 +" beq 4f\n"
1386 " adds %0, %0, %6\n"
1387 -" adc %H0, %H0, %H6\n"
1388 +" adcs %H0, %H0, %H6\n"
1389 +
1390 +#ifdef CONFIG_PAX_REFCOUNT
1391 +" bvc 3f\n"
1392 +"2: bkpt 0xf103\n"
1393 +"3:\n"
1394 +#endif
1395 +
1396 " strexd %2, %0, %H0, [%4]\n"
1397 " teq %2, #0\n"
1398 " bne 1b\n"
1399 -"2:"
1400 +"4:\n"
1401 +
1402 +#ifdef CONFIG_PAX_REFCOUNT
1403 + _ASM_EXTABLE(2b, 4b)
1404 +#endif
1405 +
1406 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1407 : "r" (&v->counter), "r" (u), "r" (a)
1408 : "cc");
1409 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1410
1411 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1412 #define atomic64_inc(v) atomic64_add(1LL, (v))
1413 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1414 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1415 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1416 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1417 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1418 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1419 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1420 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1421 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1422 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1423 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1424 index 75fe66b..ba3dee4 100644
1425 --- a/arch/arm/include/asm/cache.h
1426 +++ b/arch/arm/include/asm/cache.h
1427 @@ -4,8 +4,10 @@
1428 #ifndef __ASMARM_CACHE_H
1429 #define __ASMARM_CACHE_H
1430
1431 +#include <linux/const.h>
1432 +
1433 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1434 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1435 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1436
1437 /*
1438 * Memory returned by kmalloc() may be used for DMA, so we must make
1439 @@ -24,5 +26,6 @@
1440 #endif
1441
1442 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1443 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1444
1445 #endif
1446 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1447 index e1489c5..d418304 100644
1448 --- a/arch/arm/include/asm/cacheflush.h
1449 +++ b/arch/arm/include/asm/cacheflush.h
1450 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1451 void (*dma_unmap_area)(const void *, size_t, int);
1452
1453 void (*dma_flush_range)(const void *, const void *);
1454 -};
1455 +} __no_const;
1456
1457 /*
1458 * Select the calling method
1459 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1460 index 7eb18c1..e38b6d2 100644
1461 --- a/arch/arm/include/asm/cmpxchg.h
1462 +++ b/arch/arm/include/asm/cmpxchg.h
1463 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1464
1465 #define xchg(ptr,x) \
1466 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467 +#define xchg_unchecked(ptr,x) \
1468 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1469
1470 #include <asm-generic/cmpxchg-local.h>
1471
1472 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1473 index ab98fdd..6b19938 100644
1474 --- a/arch/arm/include/asm/delay.h
1475 +++ b/arch/arm/include/asm/delay.h
1476 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1477 void (*delay)(unsigned long);
1478 void (*const_udelay)(unsigned long);
1479 void (*udelay)(unsigned long);
1480 -} arm_delay_ops;
1481 +} *arm_delay_ops;
1482
1483 -#define __delay(n) arm_delay_ops.delay(n)
1484 +#define __delay(n) arm_delay_ops->delay(n)
1485
1486 /*
1487 * This function intentionally does not exist; if you see references to
1488 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1489 * first constant multiplications gets optimized away if the delay is
1490 * a constant)
1491 */
1492 -#define __udelay(n) arm_delay_ops.udelay(n)
1493 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1494 +#define __udelay(n) arm_delay_ops->udelay(n)
1495 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1496
1497 #define udelay(n) \
1498 (__builtin_constant_p(n) ? \
1499 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1500 index 38050b1..9d90e8b 100644
1501 --- a/arch/arm/include/asm/elf.h
1502 +++ b/arch/arm/include/asm/elf.h
1503 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1504 the loader. We need to make sure that it is out of the way of the program
1505 that it will "exec", and that there is sufficient room for the brk. */
1506
1507 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1508 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1509 +
1510 +#ifdef CONFIG_PAX_ASLR
1511 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1512 +
1513 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1514 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1515 +#endif
1516
1517 /* When the program starts, a1 contains a pointer to a function to be
1518 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1519 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1520 extern void elf_set_personality(const struct elf32_hdr *);
1521 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1522
1523 -struct mm_struct;
1524 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1525 -#define arch_randomize_brk arch_randomize_brk
1526 -
1527 #endif
1528 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1529 index 83eb2f7..ed77159 100644
1530 --- a/arch/arm/include/asm/kmap_types.h
1531 +++ b/arch/arm/include/asm/kmap_types.h
1532 @@ -4,6 +4,6 @@
1533 /*
1534 * This is the "bare minimum". AIO seems to require this.
1535 */
1536 -#define KM_TYPE_NR 16
1537 +#define KM_TYPE_NR 17
1538
1539 #endif
1540 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1541 index 9e614a1..3302cca 100644
1542 --- a/arch/arm/include/asm/mach/dma.h
1543 +++ b/arch/arm/include/asm/mach/dma.h
1544 @@ -22,7 +22,7 @@ struct dma_ops {
1545 int (*residue)(unsigned int, dma_t *); /* optional */
1546 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1547 const char *type;
1548 -};
1549 +} __do_const;
1550
1551 struct dma_struct {
1552 void *addr; /* single DMA address */
1553 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1554 index 195ac2f..2272f0d 100644
1555 --- a/arch/arm/include/asm/mach/map.h
1556 +++ b/arch/arm/include/asm/mach/map.h
1557 @@ -34,6 +34,9 @@ struct map_desc {
1558 #define MT_MEMORY_ITCM 13
1559 #define MT_MEMORY_SO 14
1560 #define MT_MEMORY_DMA_READY 15
1561 +#define MT_MEMORY_R 16
1562 +#define MT_MEMORY_RW 17
1563 +#define MT_MEMORY_RX 18
1564
1565 #ifdef CONFIG_MMU
1566 extern void iotable_init(struct map_desc *, int);
1567 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1568 index 53426c6..c7baff3 100644
1569 --- a/arch/arm/include/asm/outercache.h
1570 +++ b/arch/arm/include/asm/outercache.h
1571 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1572 #endif
1573 void (*set_debug)(unsigned long);
1574 void (*resume)(void);
1575 -};
1576 +} __no_const;
1577
1578 #ifdef CONFIG_OUTER_CACHE
1579
1580 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1581 index 812a494..71fc0b6 100644
1582 --- a/arch/arm/include/asm/page.h
1583 +++ b/arch/arm/include/asm/page.h
1584 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1585 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1586 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1587 unsigned long vaddr, struct vm_area_struct *vma);
1588 -};
1589 +} __no_const;
1590
1591 #ifdef MULTI_USER
1592 extern struct cpu_user_fns cpu_user;
1593 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1594 index 943504f..84d0f84 100644
1595 --- a/arch/arm/include/asm/pgalloc.h
1596 +++ b/arch/arm/include/asm/pgalloc.h
1597 @@ -17,6 +17,7 @@
1598 #include <asm/processor.h>
1599 #include <asm/cacheflush.h>
1600 #include <asm/tlbflush.h>
1601 +#include <asm/system_info.h>
1602
1603 #define check_pgt_cache() do { } while (0)
1604
1605 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1606 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1607 }
1608
1609 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1610 +{
1611 + pud_populate(mm, pud, pmd);
1612 +}
1613 +
1614 #else /* !CONFIG_ARM_LPAE */
1615
1616 /*
1617 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1618 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1619 #define pmd_free(mm, pmd) do { } while (0)
1620 #define pud_populate(mm,pmd,pte) BUG()
1621 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1622
1623 #endif /* CONFIG_ARM_LPAE */
1624
1625 @@ -126,6 +133,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1626 __free_page(pte);
1627 }
1628
1629 +static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1630 +{
1631 + pmdval_t pmdval = pmd_val(*pmdp) | prot;
1632 + pmdp[0] = __pmd(pmdval);
1633 +#ifndef CONFIG_ARM_LPAE
1634 + pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1635 +#endif
1636 + flush_pmd_entry(pmdp);
1637 +}
1638 +
1639 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1640 pmdval_t prot)
1641 {
1642 @@ -155,7 +172,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1643 static inline void
1644 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1645 {
1646 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1647 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1648 }
1649 #define pmd_pgtable(pmd) pmd_page(pmd)
1650
1651 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1652 index 5cfba15..d437dc2 100644
1653 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1654 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1655 @@ -20,12 +20,15 @@
1656 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1657 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1658 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1659 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1660 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1661 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1662 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1663 +
1664 /*
1665 * - section
1666 */
1667 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1668 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1669 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1670 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1671 @@ -37,6 +40,7 @@
1672 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1673 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1674 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1675 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1676
1677 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1678 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1679 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1680 index 2317a71..1897391 100644
1681 --- a/arch/arm/include/asm/pgtable-2level.h
1682 +++ b/arch/arm/include/asm/pgtable-2level.h
1683 @@ -123,6 +123,7 @@
1684 #define L_PTE_USER (_AT(pteval_t, 1) << 8)
1685 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1686 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1687 +#define L_PTE_PXN (_AT(pteval_t, 1) << 11) /* v7*/
1688
1689 /*
1690 * These are the memory types, defined to be compatible with
1691 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1692 index d795282..d82ff13 100644
1693 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1694 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1695 @@ -32,6 +32,7 @@
1696 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1697 #define PMD_BIT4 (_AT(pmdval_t, 0))
1698 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1699 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1700
1701 /*
1702 * - section
1703 @@ -41,9 +42,11 @@
1704 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1705 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1706 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1707 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1708 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1709 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1710 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1711 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1712 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1713
1714 /*
1715 @@ -66,6 +69,7 @@
1716 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1717 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1718 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1719 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1720 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1721
1722 /*
1723 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1724 index b249035..4ab204b 100644
1725 --- a/arch/arm/include/asm/pgtable-3level.h
1726 +++ b/arch/arm/include/asm/pgtable-3level.h
1727 @@ -73,6 +73,7 @@
1728 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1729 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1730 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1731 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1732 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1733 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1734 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1735 @@ -80,6 +81,7 @@
1736 /*
1737 * To be used in assembly code with the upper page attributes.
1738 */
1739 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1740 #define L_PTE_XN_HIGH (1 << (54 - 32))
1741 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1742
1743 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1744 index 08c1231..1031bb4 100644
1745 --- a/arch/arm/include/asm/pgtable.h
1746 +++ b/arch/arm/include/asm/pgtable.h
1747 @@ -30,6 +30,9 @@
1748 #include <asm/pgtable-2level.h>
1749 #endif
1750
1751 +#define ktla_ktva(addr) (addr)
1752 +#define ktva_ktla(addr) (addr)
1753 +
1754 /*
1755 * Just any arbitrary offset to the start of the vmalloc VM area: the
1756 * current 8MB value just means that there will be a 8MB "hole" after the
1757 @@ -45,6 +48,9 @@
1758 #define LIBRARY_TEXT_START 0x0c000000
1759
1760 #ifndef __ASSEMBLY__
1761 +extern pteval_t __supported_pte_mask;
1762 +extern pmdval_t __supported_pmd_mask;
1763 +
1764 extern void __pte_error(const char *file, int line, pte_t);
1765 extern void __pmd_error(const char *file, int line, pmd_t);
1766 extern void __pgd_error(const char *file, int line, pgd_t);
1767 @@ -53,6 +59,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1768 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1769 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1770
1771 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1772 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1773 +
1774 +#ifdef CONFIG_PAX_KERNEXEC
1775 +static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1776 +static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1777 +#else
1778 +static inline unsigned long pax_open_kernel(void) { return 0; }
1779 +static inline unsigned long pax_close_kernel(void) { return 0; }
1780 +#endif
1781 +
1782 /*
1783 * This is the lowest virtual address we can permit any user space
1784 * mapping to be mapped at. This is particularly important for
1785 @@ -63,8 +80,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1786 /*
1787 * The pgprot_* and protection_map entries will be fixed up in runtime
1788 * to include the cachable and bufferable bits based on memory policy,
1789 - * as well as any architecture dependent bits like global/ASID and SMP
1790 - * shared mapping bits.
1791 + * as well as any architecture dependent bits like global/ASID, PXN,
1792 + * and SMP shared mapping bits.
1793 */
1794 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
1795
1796 @@ -242,7 +259,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1797
1798 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1799 {
1800 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1801 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | __supported_pte_mask;
1802 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1803 return pte;
1804 }
1805 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1806 index f3628fb..a0672dd 100644
1807 --- a/arch/arm/include/asm/proc-fns.h
1808 +++ b/arch/arm/include/asm/proc-fns.h
1809 @@ -75,7 +75,7 @@ extern struct processor {
1810 unsigned int suspend_size;
1811 void (*do_suspend)(void *);
1812 void (*do_resume)(void *);
1813 -} processor;
1814 +} __do_const processor;
1815
1816 #ifndef MULTI_CPU
1817 extern void cpu_proc_init(void);
1818 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1819 index 2e3be16..4dc90fc 100644
1820 --- a/arch/arm/include/asm/smp.h
1821 +++ b/arch/arm/include/asm/smp.h
1822 @@ -106,7 +106,7 @@ struct smp_operations {
1823 int (*cpu_disable)(unsigned int cpu);
1824 #endif
1825 #endif
1826 -};
1827 +} __no_const;
1828
1829 /*
1830 * set platform specific SMP operations
1831 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1832 index 8477b4c..801a6a9 100644
1833 --- a/arch/arm/include/asm/thread_info.h
1834 +++ b/arch/arm/include/asm/thread_info.h
1835 @@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1836 #define TIF_SYSCALL_TRACE 8
1837 #define TIF_SYSCALL_AUDIT 9
1838 #define TIF_SYSCALL_TRACEPOINT 10
1839 +
1840 +/* within 8 bits of TIF_SYSCALL_TRACE
1841 + to meet flexible second operand requirements
1842 +*/
1843 +#define TIF_GRSEC_SETXID 11
1844 +
1845 #define TIF_USING_IWMMXT 17
1846 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1847 #define TIF_RESTORE_SIGMASK 20
1848 @@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1849 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1850 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1851 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1852 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1853
1854 /* Checks for any syscall work in entry-common.S */
1855 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1856 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1857 + _TIF_GRSEC_SETXID)
1858
1859 /*
1860 * Change these and you break ASM code in entry-common.S
1861 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1862 index 7e1f760..f2c37b1 100644
1863 --- a/arch/arm/include/asm/uaccess.h
1864 +++ b/arch/arm/include/asm/uaccess.h
1865 @@ -418,8 +418,23 @@ do { \
1866
1867
1868 #ifdef CONFIG_MMU
1869 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1870 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1871 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1872 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1873 +
1874 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1875 +{
1876 + check_object_size(to, n, false);
1877 +
1878 + return ___copy_from_user(to, from, n);
1879 +}
1880 +
1881 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1882 +{
1883 + check_object_size(from, n, true);
1884 +
1885 + return ___copy_to_user(to, from, n);
1886 +}
1887 +
1888 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1889 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1890 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1891 @@ -431,6 +446,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1892
1893 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1894 {
1895 + if ((long)n < 0)
1896 + return n;
1897 +
1898 if (access_ok(VERIFY_READ, from, n))
1899 n = __copy_from_user(to, from, n);
1900 else /* security hole - plug it */
1901 @@ -440,6 +458,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1902
1903 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1904 {
1905 + if ((long)n < 0)
1906 + return n;
1907 +
1908 if (access_ok(VERIFY_WRITE, to, n))
1909 n = __copy_to_user(to, from, n);
1910 return n;
1911 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
1912 index 96ee092..37f1844 100644
1913 --- a/arch/arm/include/uapi/asm/ptrace.h
1914 +++ b/arch/arm/include/uapi/asm/ptrace.h
1915 @@ -73,7 +73,7 @@
1916 * ARMv7 groups of PSR bits
1917 */
1918 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
1919 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
1920 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
1921 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
1922 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
1923
1924 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1925 index 60d3b73..9168db0 100644
1926 --- a/arch/arm/kernel/armksyms.c
1927 +++ b/arch/arm/kernel/armksyms.c
1928 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1929 #ifdef CONFIG_MMU
1930 EXPORT_SYMBOL(copy_page);
1931
1932 -EXPORT_SYMBOL(__copy_from_user);
1933 -EXPORT_SYMBOL(__copy_to_user);
1934 +EXPORT_SYMBOL(___copy_from_user);
1935 +EXPORT_SYMBOL(___copy_to_user);
1936 EXPORT_SYMBOL(__clear_user);
1937
1938 EXPORT_SYMBOL(__get_user_1);
1939 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1940 index 486a15a..d95523a 100644
1941 --- a/arch/arm/kernel/head.S
1942 +++ b/arch/arm/kernel/head.S
1943 @@ -52,7 +52,9 @@
1944 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1945
1946 .macro pgtbl, rd, phys
1947 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1948 + mov \rd, #TEXT_OFFSET
1949 + sub \rd, #PG_DIR_SIZE
1950 + add \rd, \rd, \phys
1951 .endm
1952
1953 /*
1954 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1955 index 1e9be5d..ef22b26 100644
1956 --- a/arch/arm/kernel/module.c
1957 +++ b/arch/arm/kernel/module.c
1958 @@ -37,12 +37,37 @@
1959 #endif
1960
1961 #ifdef CONFIG_MMU
1962 -void *module_alloc(unsigned long size)
1963 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1964 {
1965 + if (!size || PAGE_ALIGN(size) > (MODULES_END - MODULES_VADDR))
1966 + return NULL;
1967 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1968 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1969 + GFP_KERNEL, prot, -1,
1970 __builtin_return_address(0));
1971 }
1972 +
1973 +void *module_alloc(unsigned long size)
1974 +{
1975 +
1976 +#ifdef CONFIG_PAX_KERNEXEC
1977 + return __module_alloc(size, PAGE_KERNEL);
1978 +#else
1979 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1980 +#endif
1981 +
1982 +}
1983 +
1984 +#ifdef CONFIG_PAX_KERNEXEC
1985 +void module_free_exec(struct module *mod, void *module_region)
1986 +{
1987 + module_free(mod, module_region);
1988 +}
1989 +
1990 +void *module_alloc_exec(unsigned long size)
1991 +{
1992 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1993 +}
1994 +#endif
1995 #endif
1996
1997 int
1998 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1999 index 90084a6..a8b26bc 100644
2000 --- a/arch/arm/kernel/process.c
2001 +++ b/arch/arm/kernel/process.c
2002 @@ -28,7 +28,6 @@
2003 #include <linux/tick.h>
2004 #include <linux/utsname.h>
2005 #include <linux/uaccess.h>
2006 -#include <linux/random.h>
2007 #include <linux/hw_breakpoint.h>
2008 #include <linux/cpuidle.h>
2009 #include <linux/leds.h>
2010 @@ -256,9 +255,10 @@ void machine_power_off(void)
2011 machine_shutdown();
2012 if (pm_power_off)
2013 pm_power_off();
2014 + BUG();
2015 }
2016
2017 -void machine_restart(char *cmd)
2018 +__noreturn void machine_restart(char *cmd)
2019 {
2020 machine_shutdown();
2021
2022 @@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2023 init_utsname()->release,
2024 (int)strcspn(init_utsname()->version, " "),
2025 init_utsname()->version);
2026 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2027 - print_symbol("LR is at %s\n", regs->ARM_lr);
2028 + printk("PC is at %pA\n", instruction_pointer(regs));
2029 + printk("LR is at %pA\n", regs->ARM_lr);
2030 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2031 "sp : %08lx ip : %08lx fp : %08lx\n",
2032 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2033 @@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
2034 return 0;
2035 }
2036
2037 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2038 -{
2039 - unsigned long range_end = mm->brk + 0x02000000;
2040 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2041 -}
2042 -
2043 #ifdef CONFIG_MMU
2044 /*
2045 * The vectors page is always readable from user space for the
2046 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2047 index 739db3a..7f4a272 100644
2048 --- a/arch/arm/kernel/ptrace.c
2049 +++ b/arch/arm/kernel/ptrace.c
2050 @@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
2051 PTRACE_SYSCALL_EXIT,
2052 };
2053
2054 +#ifdef CONFIG_GRKERNSEC_SETXID
2055 +extern void gr_delayed_cred_worker(void);
2056 +#endif
2057 +
2058 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2059 enum ptrace_syscall_dir dir)
2060 {
2061 @@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2062
2063 current_thread_info()->syscall = scno;
2064
2065 +#ifdef CONFIG_GRKERNSEC_SETXID
2066 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2067 + gr_delayed_cred_worker();
2068 +#endif
2069 +
2070 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2071 return scno;
2072
2073 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2074 index da1d1aa..ef9bc58 100644
2075 --- a/arch/arm/kernel/setup.c
2076 +++ b/arch/arm/kernel/setup.c
2077 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2078 unsigned int elf_hwcap __read_mostly;
2079 EXPORT_SYMBOL(elf_hwcap);
2080
2081 +pteval_t __supported_pte_mask __read_only;
2082 +pmdval_t __supported_pmd_mask __read_only;
2083
2084 #ifdef MULTI_CPU
2085 -struct processor processor __read_mostly;
2086 +struct processor processor;
2087 #endif
2088 #ifdef MULTI_TLB
2089 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2090 +struct cpu_tlb_fns cpu_tlb __read_only;
2091 #endif
2092 #ifdef MULTI_USER
2093 -struct cpu_user_fns cpu_user __read_mostly;
2094 +struct cpu_user_fns cpu_user __read_only;
2095 #endif
2096 #ifdef MULTI_CACHE
2097 -struct cpu_cache_fns cpu_cache __read_mostly;
2098 +struct cpu_cache_fns cpu_cache __read_only;
2099 #endif
2100 #ifdef CONFIG_OUTER_CACHE
2101 -struct outer_cache_fns outer_cache __read_mostly;
2102 +struct outer_cache_fns outer_cache __read_only;
2103 EXPORT_SYMBOL(outer_cache);
2104 #endif
2105
2106 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2107 asm("mrc p15, 0, %0, c0, c1, 4"
2108 : "=r" (mmfr0));
2109 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2110 - (mmfr0 & 0x000000f0) >= 0x00000030)
2111 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2112 cpu_arch = CPU_ARCH_ARMv7;
2113 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2114 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2115 + __supported_pte_mask |= L_PTE_PXN;
2116 + __supported_pmd_mask |= PMD_PXNTABLE;
2117 + }
2118 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2119 (mmfr0 & 0x000000f0) == 0x00000020)
2120 cpu_arch = CPU_ARCH_ARMv6;
2121 else
2122 @@ -455,7 +461,7 @@ static void __init setup_processor(void)
2123 __cpu_architecture = __get_cpu_architecture();
2124
2125 #ifdef MULTI_CPU
2126 - processor = *list->proc;
2127 + memcpy((void *)&processor, list->proc, sizeof processor);
2128 #endif
2129 #ifdef MULTI_TLB
2130 cpu_tlb = *list->tlb;
2131 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2132 index fbc8b26..000ded0 100644
2133 --- a/arch/arm/kernel/smp.c
2134 +++ b/arch/arm/kernel/smp.c
2135 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2136
2137 static DECLARE_COMPLETION(cpu_running);
2138
2139 -static struct smp_operations smp_ops;
2140 +static struct smp_operations smp_ops __read_only;
2141
2142 void __init smp_set_ops(struct smp_operations *ops)
2143 {
2144 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2145 index b0179b8..7713948 100644
2146 --- a/arch/arm/kernel/traps.c
2147 +++ b/arch/arm/kernel/traps.c
2148 @@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2149 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2150 {
2151 #ifdef CONFIG_KALLSYMS
2152 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2153 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2154 #else
2155 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2156 #endif
2157 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2158 static int die_owner = -1;
2159 static unsigned int die_nest_count;
2160
2161 +extern void gr_handle_kernel_exploit(void);
2162 +
2163 static unsigned long oops_begin(void)
2164 {
2165 int cpu;
2166 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2167 panic("Fatal exception in interrupt");
2168 if (panic_on_oops)
2169 panic("Fatal exception");
2170 +
2171 + gr_handle_kernel_exploit();
2172 +
2173 if (signr)
2174 do_exit(signr);
2175 }
2176 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2177 index 36ff15b..75d9e9d 100644
2178 --- a/arch/arm/kernel/vmlinux.lds.S
2179 +++ b/arch/arm/kernel/vmlinux.lds.S
2180 @@ -8,7 +8,11 @@
2181 #include <asm/thread_info.h>
2182 #include <asm/memory.h>
2183 #include <asm/page.h>
2184 -
2185 +
2186 +#ifdef CONFIG_PAX_KERNEXEC
2187 +#include <asm/pgtable.h>
2188 +#endif
2189 +
2190 #define PROC_INFO \
2191 . = ALIGN(4); \
2192 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2193 @@ -90,6 +94,11 @@ SECTIONS
2194 _text = .;
2195 HEAD_TEXT
2196 }
2197 +
2198 +#ifdef CONFIG_PAX_KERNEXEC
2199 + . = ALIGN(1<<SECTION_SHIFT);
2200 +#endif
2201 +
2202 .text : { /* Real text segment */
2203 _stext = .; /* Text and read-only data */
2204 __exception_text_start = .;
2205 @@ -133,6 +142,10 @@ SECTIONS
2206
2207 _etext = .; /* End of text and rodata section */
2208
2209 +#ifdef CONFIG_PAX_KERNEXEC
2210 + . = ALIGN(1<<SECTION_SHIFT);
2211 +#endif
2212 +
2213 #ifndef CONFIG_XIP_KERNEL
2214 . = ALIGN(PAGE_SIZE);
2215 __init_begin = .;
2216 @@ -192,6 +205,11 @@ SECTIONS
2217 . = PAGE_OFFSET + TEXT_OFFSET;
2218 #else
2219 __init_end = .;
2220 +
2221 +#ifdef CONFIG_PAX_KERNEXEC
2222 + . = ALIGN(1<<SECTION_SHIFT);
2223 +#endif
2224 +
2225 . = ALIGN(THREAD_SIZE);
2226 __data_loc = .;
2227 #endif
2228 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2229 index 66a477a..bee61d3 100644
2230 --- a/arch/arm/lib/copy_from_user.S
2231 +++ b/arch/arm/lib/copy_from_user.S
2232 @@ -16,7 +16,7 @@
2233 /*
2234 * Prototype:
2235 *
2236 - * size_t __copy_from_user(void *to, const void *from, size_t n)
2237 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
2238 *
2239 * Purpose:
2240 *
2241 @@ -84,11 +84,11 @@
2242
2243 .text
2244
2245 -ENTRY(__copy_from_user)
2246 +ENTRY(___copy_from_user)
2247
2248 #include "copy_template.S"
2249
2250 -ENDPROC(__copy_from_user)
2251 +ENDPROC(___copy_from_user)
2252
2253 .pushsection .fixup,"ax"
2254 .align 0
2255 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2256 index 6ee2f67..d1cce76 100644
2257 --- a/arch/arm/lib/copy_page.S
2258 +++ b/arch/arm/lib/copy_page.S
2259 @@ -10,6 +10,7 @@
2260 * ASM optimised string functions
2261 */
2262 #include <linux/linkage.h>
2263 +#include <linux/const.h>
2264 #include <asm/assembler.h>
2265 #include <asm/asm-offsets.h>
2266 #include <asm/cache.h>
2267 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2268 index d066df6..df28194 100644
2269 --- a/arch/arm/lib/copy_to_user.S
2270 +++ b/arch/arm/lib/copy_to_user.S
2271 @@ -16,7 +16,7 @@
2272 /*
2273 * Prototype:
2274 *
2275 - * size_t __copy_to_user(void *to, const void *from, size_t n)
2276 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
2277 *
2278 * Purpose:
2279 *
2280 @@ -88,11 +88,11 @@
2281 .text
2282
2283 ENTRY(__copy_to_user_std)
2284 -WEAK(__copy_to_user)
2285 +WEAK(___copy_to_user)
2286
2287 #include "copy_template.S"
2288
2289 -ENDPROC(__copy_to_user)
2290 +ENDPROC(___copy_to_user)
2291 ENDPROC(__copy_to_user_std)
2292
2293 .pushsection .fixup,"ax"
2294 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2295 index 0dc5385..45833ef 100644
2296 --- a/arch/arm/lib/delay.c
2297 +++ b/arch/arm/lib/delay.c
2298 @@ -28,12 +28,14 @@
2299 /*
2300 * Default to the loop-based delay implementation.
2301 */
2302 -struct arm_delay_ops arm_delay_ops = {
2303 +static struct arm_delay_ops arm_loop_delay_ops = {
2304 .delay = __loop_delay,
2305 .const_udelay = __loop_const_udelay,
2306 .udelay = __loop_udelay,
2307 };
2308
2309 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2310 +
2311 static const struct delay_timer *delay_timer;
2312 static bool delay_calibrated;
2313
2314 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2315 __timer_const_udelay(usecs * UDELAY_MULT);
2316 }
2317
2318 +static struct arm_delay_ops arm_timer_delay_ops = {
2319 + .delay = __timer_delay,
2320 + .const_udelay = __timer_const_udelay,
2321 + .udelay = __timer_udelay,
2322 +};
2323 +
2324 void __init register_current_timer_delay(const struct delay_timer *timer)
2325 {
2326 if (!delay_calibrated) {
2327 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2328 delay_timer = timer;
2329 lpj_fine = timer->freq / HZ;
2330 loops_per_jiffy = lpj_fine;
2331 - arm_delay_ops.delay = __timer_delay;
2332 - arm_delay_ops.const_udelay = __timer_const_udelay;
2333 - arm_delay_ops.udelay = __timer_udelay;
2334 + arm_delay_ops = &arm_timer_delay_ops;
2335 delay_calibrated = true;
2336 } else {
2337 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2338 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2339 index 025f742..8432b08 100644
2340 --- a/arch/arm/lib/uaccess_with_memcpy.c
2341 +++ b/arch/arm/lib/uaccess_with_memcpy.c
2342 @@ -104,7 +104,7 @@ out:
2343 }
2344
2345 unsigned long
2346 -__copy_to_user(void __user *to, const void *from, unsigned long n)
2347 +___copy_to_user(void __user *to, const void *from, unsigned long n)
2348 {
2349 /*
2350 * This test is stubbed out of the main function above to keep
2351 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2352 index 2c6c218..2b87c2d 100644
2353 --- a/arch/arm/mach-kirkwood/common.c
2354 +++ b/arch/arm/mach-kirkwood/common.c
2355 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2356 clk_gate_ops.disable(hw);
2357 }
2358
2359 -static struct clk_ops clk_gate_fn_ops;
2360 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2361 +{
2362 + return clk_gate_ops.is_enabled(hw);
2363 +}
2364 +
2365 +static struct clk_ops clk_gate_fn_ops = {
2366 + .enable = clk_gate_fn_enable,
2367 + .disable = clk_gate_fn_disable,
2368 + .is_enabled = clk_gate_fn_is_enabled,
2369 +};
2370
2371 static struct clk __init *clk_register_gate_fn(struct device *dev,
2372 const char *name,
2373 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2374 gate_fn->fn_en = fn_en;
2375 gate_fn->fn_dis = fn_dis;
2376
2377 - /* ops is the gate ops, but with our enable/disable functions */
2378 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2379 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2380 - clk_gate_fn_ops = clk_gate_ops;
2381 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
2382 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
2383 - }
2384 -
2385 clk = clk_register(dev, &gate_fn->gate.hw);
2386
2387 if (IS_ERR(clk))
2388 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2389 index d95f727..12f10dd 100644
2390 --- a/arch/arm/mach-omap2/board-n8x0.c
2391 +++ b/arch/arm/mach-omap2/board-n8x0.c
2392 @@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2393 }
2394 #endif
2395
2396 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2397 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2398 .late_init = n8x0_menelaus_late_init,
2399 };
2400
2401 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2402 index 87cc6d0..fd4f248 100644
2403 --- a/arch/arm/mach-omap2/omap_hwmod.c
2404 +++ b/arch/arm/mach-omap2/omap_hwmod.c
2405 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2406 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2407 struct omap_hwmod_rst_info *ohri);
2408 int (*init_clkdm)(struct omap_hwmod *oh);
2409 -};
2410 +} __no_const;
2411
2412 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2413 -static struct omap_hwmod_soc_ops soc_ops;
2414 +static struct omap_hwmod_soc_ops soc_ops __read_only;
2415
2416 /* omap_hwmod_list contains all registered struct omap_hwmods */
2417 static LIST_HEAD(omap_hwmod_list);
2418 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2419 index 5dbf13f..9be36fd 100644
2420 --- a/arch/arm/mm/fault.c
2421 +++ b/arch/arm/mm/fault.c
2422 @@ -25,6 +25,7 @@
2423 #include <asm/system_misc.h>
2424 #include <asm/system_info.h>
2425 #include <asm/tlbflush.h>
2426 +#include <asm/sections.h>
2427
2428 #include "fault.h"
2429
2430 @@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2431 if (fixup_exception(regs))
2432 return;
2433
2434 +#ifdef CONFIG_PAX_KERNEXEC
2435 + if (fsr & FSR_WRITE) {
2436 + if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2437 + if (current->signal->curr_ip)
2438 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2439 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2440 + else
2441 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2442 + current->comm, task_pid_nr(current), current_uid(), current_euid());
2443 + }
2444 + }
2445 +#endif
2446 +
2447 /*
2448 * No handler, we'll have to terminate things with extreme prejudice.
2449 */
2450 @@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2451 }
2452 #endif
2453
2454 +#ifdef CONFIG_PAX_PAGEEXEC
2455 + if (fsr & FSR_LNX_PF) {
2456 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2457 + do_group_exit(SIGKILL);
2458 + }
2459 +#endif
2460 +
2461 tsk->thread.address = addr;
2462 tsk->thread.error_code = fsr;
2463 tsk->thread.trap_no = 14;
2464 @@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2465 }
2466 #endif /* CONFIG_MMU */
2467
2468 +#ifdef CONFIG_PAX_PAGEEXEC
2469 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2470 +{
2471 + long i;
2472 +
2473 + printk(KERN_ERR "PAX: bytes at PC: ");
2474 + for (i = 0; i < 20; i++) {
2475 + unsigned char c;
2476 + if (get_user(c, (__force unsigned char __user *)pc+i))
2477 + printk(KERN_CONT "?? ");
2478 + else
2479 + printk(KERN_CONT "%02x ", c);
2480 + }
2481 + printk("\n");
2482 +
2483 + printk(KERN_ERR "PAX: bytes at SP-4: ");
2484 + for (i = -1; i < 20; i++) {
2485 + unsigned long c;
2486 + if (get_user(c, (__force unsigned long __user *)sp+i))
2487 + printk(KERN_CONT "???????? ");
2488 + else
2489 + printk(KERN_CONT "%08lx ", c);
2490 + }
2491 + printk("\n");
2492 +}
2493 +#endif
2494 +
2495 /*
2496 * First Level Translation Fault Handler
2497 *
2498 @@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2499 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2500 struct siginfo info;
2501
2502 +#ifdef CONFIG_PAX_KERNEXEC
2503 + if (!user_mode(regs) && is_xn_fault(ifsr)) {
2504 + if (current->signal->curr_ip)
2505 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2506 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2507 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2508 + else
2509 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2510 + current->comm, task_pid_nr(current), current_uid(), current_euid(),
2511 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2512 + goto die;
2513 + }
2514 +#endif
2515 +
2516 +#ifdef CONFIG_PAX_REFCOUNT
2517 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2518 + unsigned int bkpt;
2519 +
2520 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2521 + current->thread.error_code = ifsr;
2522 + current->thread.trap_no = 0;
2523 + pax_report_refcount_overflow(regs);
2524 + fixup_exception(regs);
2525 + return;
2526 + }
2527 + }
2528 +#endif
2529 +
2530 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2531 return;
2532
2533 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2534 inf->name, ifsr, addr);
2535
2536 +die:
2537 info.si_signo = inf->sig;
2538 info.si_errno = 0;
2539 info.si_code = inf->code;
2540 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2541 index cf08bdf..f1a0383 100644
2542 --- a/arch/arm/mm/fault.h
2543 +++ b/arch/arm/mm/fault.h
2544 @@ -3,6 +3,7 @@
2545
2546 /*
2547 * Fault status register encodings. We steal bit 31 for our own purposes.
2548 + * Set when the FSR value is from an instruction fault.
2549 */
2550 #define FSR_LNX_PF (1 << 31)
2551 #define FSR_WRITE (1 << 11)
2552 @@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2553 }
2554 #endif
2555
2556 +/* valid for LPAE and !LPAE */
2557 +static inline int is_xn_fault(unsigned int fsr)
2558 +{
2559 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
2560 +}
2561 +
2562 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2563 unsigned long search_exception_table(unsigned long addr);
2564
2565 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2566 index ad722f1..46b670e 100644
2567 --- a/arch/arm/mm/init.c
2568 +++ b/arch/arm/mm/init.c
2569 @@ -734,9 +734,43 @@ void __init mem_init(void)
2570
2571 void free_initmem(void)
2572 {
2573 +
2574 +#ifdef CONFIG_PAX_KERNEXEC
2575 + unsigned long addr;
2576 + pgd_t *pgd;
2577 + pud_t *pud;
2578 + pmd_t *pmd;
2579 +#endif
2580 +
2581 #ifdef CONFIG_HAVE_TCM
2582 extern char __tcm_start, __tcm_end;
2583 +#endif
2584
2585 +#ifdef CONFIG_PAX_KERNEXEC
2586 + /* make pages tables, etc before .text NX */
2587 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2588 + pgd = pgd_offset_k(addr);
2589 + pud = pud_offset(pgd, addr);
2590 + pmd = pmd_offset(pud, addr);
2591 + __pmd_update(pmd, PMD_SECT_XN);
2592 + }
2593 + /* make init NX */
2594 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2595 + pgd = pgd_offset_k(addr);
2596 + pud = pud_offset(pgd, addr);
2597 + pmd = pmd_offset(pud, addr);
2598 + __pmd_update(pmd, PMD_SECT_XN);
2599 + }
2600 + /* make kernel code/rodata read-only */
2601 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2602 + pgd = pgd_offset_k(addr);
2603 + pud = pud_offset(pgd, addr);
2604 + pmd = pmd_offset(pud, addr);
2605 + __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2606 + }
2607 +#endif
2608 +
2609 +#ifdef CONFIG_HAVE_TCM
2610 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2611 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2612 __phys_to_pfn(__pa(&__tcm_end)),
2613 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2614 index ce8cb19..061aa14 100644
2615 --- a/arch/arm/mm/mmap.c
2616 +++ b/arch/arm/mm/mmap.c
2617 @@ -72,6 +72,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2618 unsigned long start_addr;
2619 int do_align = 0;
2620 int aliasing = cache_is_vipt_aliasing();
2621 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2622
2623 /*
2624 * We only need to do colour alignment if either the I or D
2625 @@ -93,6 +94,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2626 if (len > TASK_SIZE)
2627 return -ENOMEM;
2628
2629 +#ifdef CONFIG_PAX_RANDMMAP
2630 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2631 +#endif
2632 +
2633 if (addr) {
2634 if (do_align)
2635 addr = COLOUR_ALIGN(addr, pgoff);
2636 @@ -100,15 +105,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2637 addr = PAGE_ALIGN(addr);
2638
2639 vma = find_vma(mm, addr);
2640 - if (TASK_SIZE - len >= addr &&
2641 - (!vma || addr + len <= vma->vm_start))
2642 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2643 return addr;
2644 }
2645 if (len > mm->cached_hole_size) {
2646 - start_addr = addr = mm->free_area_cache;
2647 + start_addr = addr = mm->free_area_cache;
2648 } else {
2649 - start_addr = addr = mm->mmap_base;
2650 - mm->cached_hole_size = 0;
2651 + start_addr = addr = mm->mmap_base;
2652 + mm->cached_hole_size = 0;
2653 }
2654
2655 full_search:
2656 @@ -124,14 +128,14 @@ full_search:
2657 * Start a new search - just in case we missed
2658 * some holes.
2659 */
2660 - if (start_addr != TASK_UNMAPPED_BASE) {
2661 - start_addr = addr = TASK_UNMAPPED_BASE;
2662 + if (start_addr != mm->mmap_base) {
2663 + start_addr = addr = mm->mmap_base;
2664 mm->cached_hole_size = 0;
2665 goto full_search;
2666 }
2667 return -ENOMEM;
2668 }
2669 - if (!vma || addr + len <= vma->vm_start) {
2670 + if (check_heap_stack_gap(vma, addr, len, offset)) {
2671 /*
2672 * Remember the place where we stopped the search:
2673 */
2674 @@ -156,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2675 unsigned long addr = addr0;
2676 int do_align = 0;
2677 int aliasing = cache_is_vipt_aliasing();
2678 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2679
2680 /*
2681 * We only need to do colour alignment if either the I or D
2682 @@ -175,6 +180,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2683 return addr;
2684 }
2685
2686 +#ifdef CONFIG_PAX_RANDMMAP
2687 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2688 +#endif
2689 +
2690 /* requesting a specific address */
2691 if (addr) {
2692 if (do_align)
2693 @@ -182,8 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2694 else
2695 addr = PAGE_ALIGN(addr);
2696 vma = find_vma(mm, addr);
2697 - if (TASK_SIZE - len >= addr &&
2698 - (!vma || addr + len <= vma->vm_start))
2699 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2700 return addr;
2701 }
2702
2703 @@ -203,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2704 /* make sure it can fit in the remaining address space */
2705 if (addr > len) {
2706 vma = find_vma(mm, addr-len);
2707 - if (!vma || addr <= vma->vm_start)
2708 + if (check_heap_stack_gap(vma, addr - len, len, offset))
2709 /* remember the address as a hint for next time */
2710 return (mm->free_area_cache = addr-len);
2711 }
2712 @@ -212,17 +220,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2713 goto bottomup;
2714
2715 addr = mm->mmap_base - len;
2716 - if (do_align)
2717 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2718
2719 do {
2720 + if (do_align)
2721 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2722 /*
2723 * Lookup failure means no vma is above this address,
2724 * else if new region fits below vma->vm_start,
2725 * return with success:
2726 */
2727 vma = find_vma(mm, addr);
2728 - if (!vma || addr+len <= vma->vm_start)
2729 + if (check_heap_stack_gap(vma, addr, len, offset))
2730 /* remember the address as a hint for next time */
2731 return (mm->free_area_cache = addr);
2732
2733 @@ -231,10 +239,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2734 mm->cached_hole_size = vma->vm_start - addr;
2735
2736 /* try just below the current vma->vm_start */
2737 - addr = vma->vm_start - len;
2738 - if (do_align)
2739 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2740 - } while (len < vma->vm_start);
2741 + addr = skip_heap_stack_gap(vma, len, offset);
2742 + } while (!IS_ERR_VALUE(addr));
2743
2744 bottomup:
2745 /*
2746 @@ -259,6 +265,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2747 {
2748 unsigned long random_factor = 0UL;
2749
2750 +#ifdef CONFIG_PAX_RANDMMAP
2751 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2752 +#endif
2753 +
2754 /* 8 bits of randomness in 20 address space bits */
2755 if ((current->flags & PF_RANDOMIZE) &&
2756 !(current->personality & ADDR_NO_RANDOMIZE))
2757 @@ -266,10 +276,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2758
2759 if (mmap_is_legacy()) {
2760 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2761 +
2762 +#ifdef CONFIG_PAX_RANDMMAP
2763 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2764 + mm->mmap_base += mm->delta_mmap;
2765 +#endif
2766 +
2767 mm->get_unmapped_area = arch_get_unmapped_area;
2768 mm->unmap_area = arch_unmap_area;
2769 } else {
2770 mm->mmap_base = mmap_base(random_factor);
2771 +
2772 +#ifdef CONFIG_PAX_RANDMMAP
2773 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2774 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2775 +#endif
2776 +
2777 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2778 mm->unmap_area = arch_unmap_area_topdown;
2779 }
2780 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2781 index 99b47b9..579b667 100644
2782 --- a/arch/arm/mm/mmu.c
2783 +++ b/arch/arm/mm/mmu.c
2784 @@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2785 [MT_UNCACHED] = {
2786 .prot_pte = PROT_PTE_DEVICE,
2787 .prot_l1 = PMD_TYPE_TABLE,
2788 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2789 + .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2790 .domain = DOMAIN_IO,
2791 },
2792 [MT_CACHECLEAN] = {
2793 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2794 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2795 .domain = DOMAIN_KERNEL,
2796 },
2797 #ifndef CONFIG_ARM_LPAE
2798 [MT_MINICLEAN] = {
2799 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2800 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2801 .domain = DOMAIN_KERNEL,
2802 },
2803 #endif
2804 @@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2805 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2806 .domain = DOMAIN_KERNEL,
2807 },
2808 + [MT_MEMORY_R] = {
2809 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2810 + .prot_l1 = PMD_TYPE_TABLE,
2811 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2812 + .domain = DOMAIN_KERNEL,
2813 + },
2814 + [MT_MEMORY_RW] = {
2815 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2816 + .prot_l1 = PMD_TYPE_TABLE,
2817 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2818 + .domain = DOMAIN_KERNEL,
2819 + },
2820 + [MT_MEMORY_RX] = {
2821 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2822 + .prot_l1 = PMD_TYPE_TABLE,
2823 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2824 + .domain = DOMAIN_KERNEL,
2825 + },
2826 [MT_ROM] = {
2827 - .prot_sect = PMD_TYPE_SECT,
2828 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2829 .domain = DOMAIN_KERNEL,
2830 },
2831 [MT_MEMORY_NONCACHED] = {
2832 @@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2833 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2834 L_PTE_XN,
2835 .prot_l1 = PMD_TYPE_TABLE,
2836 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2837 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2838 .domain = DOMAIN_KERNEL,
2839 },
2840 [MT_MEMORY_ITCM] = {
2841 @@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2842 * from SVC mode and no access from userspace.
2843 */
2844 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2845 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2846 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2847 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2848 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2849 #endif
2850 @@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2851 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2852 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2853 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2854 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2855 + mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2856 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2857 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2858 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2859 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2860 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2861 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2862 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2863 @@ -487,6 +513,8 @@ static void __init build_mem_type_table(void)
2864 vecs_pgprot |= PTE_EXT_AF;
2865 #endif
2866
2867 + user_pgprot |= __supported_pte_mask;
2868 +
2869 for (i = 0; i < 16; i++) {
2870 pteval_t v = pgprot_val(protection_map[i]);
2871 protection_map[i] = __pgprot(v | user_pgprot);
2872 @@ -503,6 +531,12 @@ static void __init build_mem_type_table(void)
2873 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2874 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2875 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2876 + mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2877 + mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2878 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2879 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2880 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2881 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2882 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2883 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2884 mem_types[MT_ROM].prot_sect |= cp->pmd;
2885 @@ -1198,7 +1232,41 @@ static void __init map_lowmem(void)
2886 map.pfn = __phys_to_pfn(start);
2887 map.virtual = __phys_to_virt(start);
2888 map.length = end - start;
2889 +
2890 +#ifdef CONFIG_PAX_KERNEXEC
2891 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2892 + struct map_desc kernel;
2893 + struct map_desc initmap;
2894 +
2895 + /* when freeing initmem we will make this RW */
2896 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2897 + initmap.virtual = (unsigned long)__init_begin;
2898 + initmap.length = _sdata - __init_begin;
2899 + initmap.type = MT_MEMORY;
2900 + create_mapping(&initmap);
2901 +
2902 + /* when freeing initmem we will make this RX */
2903 + kernel.pfn = __phys_to_pfn(__pa(_stext));
2904 + kernel.virtual = (unsigned long)_stext;
2905 + kernel.length = __init_begin - _stext;
2906 + kernel.type = MT_MEMORY;
2907 + create_mapping(&kernel);
2908 +
2909 + if (map.virtual < (unsigned long)_stext) {
2910 + map.length = (unsigned long)_stext - map.virtual;
2911 + map.type = MT_MEMORY;
2912 + create_mapping(&map);
2913 + }
2914 +
2915 + map.pfn = __phys_to_pfn(__pa(_sdata));
2916 + map.virtual = (unsigned long)_sdata;
2917 + map.length = end - __pa(_sdata);
2918 + }
2919 +
2920 + map.type = MT_MEMORY_RW;
2921 +#else
2922 map.type = MT_MEMORY;
2923 +#endif
2924
2925 create_mapping(&map);
2926 }
2927 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2928 index ec63e4a..62aa5f1d 100644
2929 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2930 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2931 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2932 value in bridge_virt_base */
2933 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2934 const int win);
2935 -};
2936 +} __no_const;
2937
2938 /*
2939 * Information needed to setup one address mapping.
2940 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2941 index f5144cd..71f6d1f 100644
2942 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2943 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2944 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2945 int (*started)(unsigned ch);
2946 int (*flush)(unsigned ch);
2947 int (*stop)(unsigned ch);
2948 -};
2949 +} __no_const;
2950
2951 extern void *samsung_dmadev_get_ops(void);
2952 extern void *s3c_dma_get_ops(void);
2953 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2954 index c3a58a1..78fbf54 100644
2955 --- a/arch/avr32/include/asm/cache.h
2956 +++ b/arch/avr32/include/asm/cache.h
2957 @@ -1,8 +1,10 @@
2958 #ifndef __ASM_AVR32_CACHE_H
2959 #define __ASM_AVR32_CACHE_H
2960
2961 +#include <linux/const.h>
2962 +
2963 #define L1_CACHE_SHIFT 5
2964 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2965 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2966
2967 /*
2968 * Memory returned by kmalloc() may be used for DMA, so we must make
2969 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2970 index e2c3287..6c4f98c 100644
2971 --- a/arch/avr32/include/asm/elf.h
2972 +++ b/arch/avr32/include/asm/elf.h
2973 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2974 the loader. We need to make sure that it is out of the way of the program
2975 that it will "exec", and that there is sufficient room for the brk. */
2976
2977 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2978 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2979
2980 +#ifdef CONFIG_PAX_ASLR
2981 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2982 +
2983 +#define PAX_DELTA_MMAP_LEN 15
2984 +#define PAX_DELTA_STACK_LEN 15
2985 +#endif
2986
2987 /* This yields a mask that user programs can use to figure out what
2988 instruction set this CPU supports. This could be done in user space,
2989 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2990 index 479330b..53717a8 100644
2991 --- a/arch/avr32/include/asm/kmap_types.h
2992 +++ b/arch/avr32/include/asm/kmap_types.h
2993 @@ -2,9 +2,9 @@
2994 #define __ASM_AVR32_KMAP_TYPES_H
2995
2996 #ifdef CONFIG_DEBUG_HIGHMEM
2997 -# define KM_TYPE_NR 29
2998 +# define KM_TYPE_NR 30
2999 #else
3000 -# define KM_TYPE_NR 14
3001 +# define KM_TYPE_NR 15
3002 #endif
3003
3004 #endif /* __ASM_AVR32_KMAP_TYPES_H */
3005 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
3006 index b2f2d2d..d1c85cb 100644
3007 --- a/arch/avr32/mm/fault.c
3008 +++ b/arch/avr32/mm/fault.c
3009 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
3010
3011 int exception_trace = 1;
3012
3013 +#ifdef CONFIG_PAX_PAGEEXEC
3014 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3015 +{
3016 + unsigned long i;
3017 +
3018 + printk(KERN_ERR "PAX: bytes at PC: ");
3019 + for (i = 0; i < 20; i++) {
3020 + unsigned char c;
3021 + if (get_user(c, (unsigned char *)pc+i))
3022 + printk(KERN_CONT "???????? ");
3023 + else
3024 + printk(KERN_CONT "%02x ", c);
3025 + }
3026 + printk("\n");
3027 +}
3028 +#endif
3029 +
3030 /*
3031 * This routine handles page faults. It determines the address and the
3032 * problem, and then passes it off to one of the appropriate routines.
3033 @@ -174,6 +191,16 @@ bad_area:
3034 up_read(&mm->mmap_sem);
3035
3036 if (user_mode(regs)) {
3037 +
3038 +#ifdef CONFIG_PAX_PAGEEXEC
3039 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3040 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
3041 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
3042 + do_group_exit(SIGKILL);
3043 + }
3044 + }
3045 +#endif
3046 +
3047 if (exception_trace && printk_ratelimit())
3048 printk("%s%s[%d]: segfault at %08lx pc %08lx "
3049 "sp %08lx ecr %lu\n",
3050 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
3051 index 568885a..f8008df 100644
3052 --- a/arch/blackfin/include/asm/cache.h
3053 +++ b/arch/blackfin/include/asm/cache.h
3054 @@ -7,6 +7,7 @@
3055 #ifndef __ARCH_BLACKFIN_CACHE_H
3056 #define __ARCH_BLACKFIN_CACHE_H
3057
3058 +#include <linux/const.h>
3059 #include <linux/linkage.h> /* for asmlinkage */
3060
3061 /*
3062 @@ -14,7 +15,7 @@
3063 * Blackfin loads 32 bytes for cache
3064 */
3065 #define L1_CACHE_SHIFT 5
3066 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3067 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3068 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3069
3070 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3071 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
3072 index aea2718..3639a60 100644
3073 --- a/arch/cris/include/arch-v10/arch/cache.h
3074 +++ b/arch/cris/include/arch-v10/arch/cache.h
3075 @@ -1,8 +1,9 @@
3076 #ifndef _ASM_ARCH_CACHE_H
3077 #define _ASM_ARCH_CACHE_H
3078
3079 +#include <linux/const.h>
3080 /* Etrax 100LX have 32-byte cache-lines. */
3081 -#define L1_CACHE_BYTES 32
3082 #define L1_CACHE_SHIFT 5
3083 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3084
3085 #endif /* _ASM_ARCH_CACHE_H */
3086 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
3087 index 7caf25d..ee65ac5 100644
3088 --- a/arch/cris/include/arch-v32/arch/cache.h
3089 +++ b/arch/cris/include/arch-v32/arch/cache.h
3090 @@ -1,11 +1,12 @@
3091 #ifndef _ASM_CRIS_ARCH_CACHE_H
3092 #define _ASM_CRIS_ARCH_CACHE_H
3093
3094 +#include <linux/const.h>
3095 #include <arch/hwregs/dma.h>
3096
3097 /* A cache-line is 32 bytes. */
3098 -#define L1_CACHE_BYTES 32
3099 #define L1_CACHE_SHIFT 5
3100 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3101
3102 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3103
3104 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
3105 index b86329d..6709906 100644
3106 --- a/arch/frv/include/asm/atomic.h
3107 +++ b/arch/frv/include/asm/atomic.h
3108 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
3109 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
3110 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
3111
3112 +#define atomic64_read_unchecked(v) atomic64_read(v)
3113 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3114 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3115 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3116 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3117 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3118 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3119 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3120 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3121 +
3122 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
3123 {
3124 int c, old;
3125 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
3126 index 2797163..c2a401d 100644
3127 --- a/arch/frv/include/asm/cache.h
3128 +++ b/arch/frv/include/asm/cache.h
3129 @@ -12,10 +12,11 @@
3130 #ifndef __ASM_CACHE_H
3131 #define __ASM_CACHE_H
3132
3133 +#include <linux/const.h>
3134
3135 /* bytes per L1 cache line */
3136 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3137 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3138 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3139
3140 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3141 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3142 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3143 index 43901f2..0d8b865 100644
3144 --- a/arch/frv/include/asm/kmap_types.h
3145 +++ b/arch/frv/include/asm/kmap_types.h
3146 @@ -2,6 +2,6 @@
3147 #ifndef _ASM_KMAP_TYPES_H
3148 #define _ASM_KMAP_TYPES_H
3149
3150 -#define KM_TYPE_NR 17
3151 +#define KM_TYPE_NR 18
3152
3153 #endif
3154 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3155 index 385fd30..3aaf4fe 100644
3156 --- a/arch/frv/mm/elf-fdpic.c
3157 +++ b/arch/frv/mm/elf-fdpic.c
3158 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3159 {
3160 struct vm_area_struct *vma;
3161 unsigned long limit;
3162 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
3163
3164 if (len > TASK_SIZE)
3165 return -ENOMEM;
3166 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3167 if (addr) {
3168 addr = PAGE_ALIGN(addr);
3169 vma = find_vma(current->mm, addr);
3170 - if (TASK_SIZE - len >= addr &&
3171 - (!vma || addr + len <= vma->vm_start))
3172 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3173 goto success;
3174 }
3175
3176 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3177 for (; vma; vma = vma->vm_next) {
3178 if (addr > limit)
3179 break;
3180 - if (addr + len <= vma->vm_start)
3181 + if (check_heap_stack_gap(vma, addr, len, offset))
3182 goto success;
3183 addr = vma->vm_end;
3184 }
3185 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3186 for (; vma; vma = vma->vm_next) {
3187 if (addr > limit)
3188 break;
3189 - if (addr + len <= vma->vm_start)
3190 + if (check_heap_stack_gap(vma, addr, len, offset))
3191 goto success;
3192 addr = vma->vm_end;
3193 }
3194 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3195 index f4ca594..adc72fd6 100644
3196 --- a/arch/hexagon/include/asm/cache.h
3197 +++ b/arch/hexagon/include/asm/cache.h
3198 @@ -21,9 +21,11 @@
3199 #ifndef __ASM_CACHE_H
3200 #define __ASM_CACHE_H
3201
3202 +#include <linux/const.h>
3203 +
3204 /* Bytes per L1 cache line */
3205 -#define L1_CACHE_SHIFT (5)
3206 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3207 +#define L1_CACHE_SHIFT 5
3208 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3209
3210 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3211 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3212 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3213 index 6e6fe18..a6ae668 100644
3214 --- a/arch/ia64/include/asm/atomic.h
3215 +++ b/arch/ia64/include/asm/atomic.h
3216 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3217 #define atomic64_inc(v) atomic64_add(1, (v))
3218 #define atomic64_dec(v) atomic64_sub(1, (v))
3219
3220 +#define atomic64_read_unchecked(v) atomic64_read(v)
3221 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3222 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3223 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3224 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3225 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3226 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3227 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3228 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3229 +
3230 /* Atomic operations are already serializing */
3231 #define smp_mb__before_atomic_dec() barrier()
3232 #define smp_mb__after_atomic_dec() barrier()
3233 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3234 index 988254a..e1ee885 100644
3235 --- a/arch/ia64/include/asm/cache.h
3236 +++ b/arch/ia64/include/asm/cache.h
3237 @@ -1,6 +1,7 @@
3238 #ifndef _ASM_IA64_CACHE_H
3239 #define _ASM_IA64_CACHE_H
3240
3241 +#include <linux/const.h>
3242
3243 /*
3244 * Copyright (C) 1998-2000 Hewlett-Packard Co
3245 @@ -9,7 +10,7 @@
3246
3247 /* Bytes per L1 (data) cache line. */
3248 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3249 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3250 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3251
3252 #ifdef CONFIG_SMP
3253 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3254 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3255 index b5298eb..67c6e62 100644
3256 --- a/arch/ia64/include/asm/elf.h
3257 +++ b/arch/ia64/include/asm/elf.h
3258 @@ -42,6 +42,13 @@
3259 */
3260 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3261
3262 +#ifdef CONFIG_PAX_ASLR
3263 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3264 +
3265 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3266 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3267 +#endif
3268 +
3269 #define PT_IA_64_UNWIND 0x70000001
3270
3271 /* IA-64 relocations: */
3272 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3273 index 96a8d92..617a1cf 100644
3274 --- a/arch/ia64/include/asm/pgalloc.h
3275 +++ b/arch/ia64/include/asm/pgalloc.h
3276 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3277 pgd_val(*pgd_entry) = __pa(pud);
3278 }
3279
3280 +static inline void
3281 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3282 +{
3283 + pgd_populate(mm, pgd_entry, pud);
3284 +}
3285 +
3286 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3287 {
3288 return quicklist_alloc(0, GFP_KERNEL, NULL);
3289 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3290 pud_val(*pud_entry) = __pa(pmd);
3291 }
3292
3293 +static inline void
3294 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3295 +{
3296 + pud_populate(mm, pud_entry, pmd);
3297 +}
3298 +
3299 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3300 {
3301 return quicklist_alloc(0, GFP_KERNEL, NULL);
3302 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3303 index 815810c..d60bd4c 100644
3304 --- a/arch/ia64/include/asm/pgtable.h
3305 +++ b/arch/ia64/include/asm/pgtable.h
3306 @@ -12,7 +12,7 @@
3307 * David Mosberger-Tang <davidm@hpl.hp.com>
3308 */
3309
3310 -
3311 +#include <linux/const.h>
3312 #include <asm/mman.h>
3313 #include <asm/page.h>
3314 #include <asm/processor.h>
3315 @@ -142,6 +142,17 @@
3316 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3317 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3318 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3319 +
3320 +#ifdef CONFIG_PAX_PAGEEXEC
3321 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3322 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3323 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3324 +#else
3325 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3326 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3327 +# define PAGE_COPY_NOEXEC PAGE_COPY
3328 +#endif
3329 +
3330 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3331 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3332 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3333 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3334 index 54ff557..70c88b7 100644
3335 --- a/arch/ia64/include/asm/spinlock.h
3336 +++ b/arch/ia64/include/asm/spinlock.h
3337 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3338 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3339
3340 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3341 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3342 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3343 }
3344
3345 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3346 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3347 index 449c8c0..50cdf87 100644
3348 --- a/arch/ia64/include/asm/uaccess.h
3349 +++ b/arch/ia64/include/asm/uaccess.h
3350 @@ -42,6 +42,8 @@
3351 #include <asm/pgtable.h>
3352 #include <asm/io.h>
3353
3354 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3355 +
3356 /*
3357 * For historical reasons, the following macros are grossly misnamed:
3358 */
3359 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3360 static inline unsigned long
3361 __copy_to_user (void __user *to, const void *from, unsigned long count)
3362 {
3363 + if (count > INT_MAX)
3364 + return count;
3365 +
3366 + if (!__builtin_constant_p(count))
3367 + check_object_size(from, count, true);
3368 +
3369 return __copy_user(to, (__force void __user *) from, count);
3370 }
3371
3372 static inline unsigned long
3373 __copy_from_user (void *to, const void __user *from, unsigned long count)
3374 {
3375 + if (count > INT_MAX)
3376 + return count;
3377 +
3378 + if (!__builtin_constant_p(count))
3379 + check_object_size(to, count, false);
3380 +
3381 return __copy_user((__force void __user *) to, from, count);
3382 }
3383
3384 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3385 ({ \
3386 void __user *__cu_to = (to); \
3387 const void *__cu_from = (from); \
3388 - long __cu_len = (n); \
3389 + unsigned long __cu_len = (n); \
3390 \
3391 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
3392 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3393 + if (!__builtin_constant_p(n)) \
3394 + check_object_size(__cu_from, __cu_len, true); \
3395 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3396 + } \
3397 __cu_len; \
3398 })
3399
3400 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3401 ({ \
3402 void *__cu_to = (to); \
3403 const void __user *__cu_from = (from); \
3404 - long __cu_len = (n); \
3405 + unsigned long __cu_len = (n); \
3406 \
3407 __chk_user_ptr(__cu_from); \
3408 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
3409 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3410 + if (!__builtin_constant_p(n)) \
3411 + check_object_size(__cu_to, __cu_len, false); \
3412 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3413 + } \
3414 __cu_len; \
3415 })
3416
3417 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3418 index 24603be..948052d 100644
3419 --- a/arch/ia64/kernel/module.c
3420 +++ b/arch/ia64/kernel/module.c
3421 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3422 void
3423 module_free (struct module *mod, void *module_region)
3424 {
3425 - if (mod && mod->arch.init_unw_table &&
3426 - module_region == mod->module_init) {
3427 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3428 unw_remove_unwind_table(mod->arch.init_unw_table);
3429 mod->arch.init_unw_table = NULL;
3430 }
3431 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3432 }
3433
3434 static inline int
3435 +in_init_rx (const struct module *mod, uint64_t addr)
3436 +{
3437 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3438 +}
3439 +
3440 +static inline int
3441 +in_init_rw (const struct module *mod, uint64_t addr)
3442 +{
3443 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3444 +}
3445 +
3446 +static inline int
3447 in_init (const struct module *mod, uint64_t addr)
3448 {
3449 - return addr - (uint64_t) mod->module_init < mod->init_size;
3450 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3451 +}
3452 +
3453 +static inline int
3454 +in_core_rx (const struct module *mod, uint64_t addr)
3455 +{
3456 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3457 +}
3458 +
3459 +static inline int
3460 +in_core_rw (const struct module *mod, uint64_t addr)
3461 +{
3462 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3463 }
3464
3465 static inline int
3466 in_core (const struct module *mod, uint64_t addr)
3467 {
3468 - return addr - (uint64_t) mod->module_core < mod->core_size;
3469 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3470 }
3471
3472 static inline int
3473 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3474 break;
3475
3476 case RV_BDREL:
3477 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3478 + if (in_init_rx(mod, val))
3479 + val -= (uint64_t) mod->module_init_rx;
3480 + else if (in_init_rw(mod, val))
3481 + val -= (uint64_t) mod->module_init_rw;
3482 + else if (in_core_rx(mod, val))
3483 + val -= (uint64_t) mod->module_core_rx;
3484 + else if (in_core_rw(mod, val))
3485 + val -= (uint64_t) mod->module_core_rw;
3486 break;
3487
3488 case RV_LTV:
3489 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3490 * addresses have been selected...
3491 */
3492 uint64_t gp;
3493 - if (mod->core_size > MAX_LTOFF)
3494 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3495 /*
3496 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3497 * at the end of the module.
3498 */
3499 - gp = mod->core_size - MAX_LTOFF / 2;
3500 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3501 else
3502 - gp = mod->core_size / 2;
3503 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3504 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3505 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3506 mod->arch.gp = gp;
3507 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3508 }
3509 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3510 index d9439ef..d0cac6b 100644
3511 --- a/arch/ia64/kernel/sys_ia64.c
3512 +++ b/arch/ia64/kernel/sys_ia64.c
3513 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3514 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
3515 struct mm_struct *mm = current->mm;
3516 struct vm_area_struct *vma;
3517 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3518
3519 if (len > RGN_MAP_LIMIT)
3520 return -ENOMEM;
3521 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3522 if (REGION_NUMBER(addr) == RGN_HPAGE)
3523 addr = 0;
3524 #endif
3525 +
3526 +#ifdef CONFIG_PAX_RANDMMAP
3527 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3528 + addr = mm->free_area_cache;
3529 + else
3530 +#endif
3531 +
3532 if (!addr)
3533 addr = mm->free_area_cache;
3534
3535 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3536 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3537 /* At this point: (!vma || addr < vma->vm_end). */
3538 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3539 - if (start_addr != TASK_UNMAPPED_BASE) {
3540 + if (start_addr != mm->mmap_base) {
3541 /* Start a new search --- just in case we missed some holes. */
3542 - addr = TASK_UNMAPPED_BASE;
3543 + addr = mm->mmap_base;
3544 goto full_search;
3545 }
3546 return -ENOMEM;
3547 }
3548 - if (!vma || addr + len <= vma->vm_start) {
3549 + if (check_heap_stack_gap(vma, addr, len, offset)) {
3550 /* Remember the address where we stopped this search: */
3551 mm->free_area_cache = addr + len;
3552 return addr;
3553 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
3554 index c64460b..4d250a6 100644
3555 --- a/arch/ia64/kernel/topology.c
3556 +++ b/arch/ia64/kernel/topology.c
3557 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
3558 return NOTIFY_OK;
3559 }
3560
3561 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
3562 +static struct notifier_block cache_cpu_notifier =
3563 {
3564 .notifier_call = cache_cpu_callback
3565 };
3566 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3567 index 0ccb28f..8992469 100644
3568 --- a/arch/ia64/kernel/vmlinux.lds.S
3569 +++ b/arch/ia64/kernel/vmlinux.lds.S
3570 @@ -198,7 +198,7 @@ SECTIONS {
3571 /* Per-cpu data: */
3572 . = ALIGN(PERCPU_PAGE_SIZE);
3573 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3574 - __phys_per_cpu_start = __per_cpu_load;
3575 + __phys_per_cpu_start = per_cpu_load;
3576 /*
3577 * ensure percpu data fits
3578 * into percpu page size
3579 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3580 index 6cf0341..d352594 100644
3581 --- a/arch/ia64/mm/fault.c
3582 +++ b/arch/ia64/mm/fault.c
3583 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3584 return pte_present(pte);
3585 }
3586
3587 +#ifdef CONFIG_PAX_PAGEEXEC
3588 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3589 +{
3590 + unsigned long i;
3591 +
3592 + printk(KERN_ERR "PAX: bytes at PC: ");
3593 + for (i = 0; i < 8; i++) {
3594 + unsigned int c;
3595 + if (get_user(c, (unsigned int *)pc+i))
3596 + printk(KERN_CONT "???????? ");
3597 + else
3598 + printk(KERN_CONT "%08x ", c);
3599 + }
3600 + printk("\n");
3601 +}
3602 +#endif
3603 +
3604 # define VM_READ_BIT 0
3605 # define VM_WRITE_BIT 1
3606 # define VM_EXEC_BIT 2
3607 @@ -149,8 +166,21 @@ retry:
3608 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3609 goto bad_area;
3610
3611 - if ((vma->vm_flags & mask) != mask)
3612 + if ((vma->vm_flags & mask) != mask) {
3613 +
3614 +#ifdef CONFIG_PAX_PAGEEXEC
3615 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3616 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3617 + goto bad_area;
3618 +
3619 + up_read(&mm->mmap_sem);
3620 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3621 + do_group_exit(SIGKILL);
3622 + }
3623 +#endif
3624 +
3625 goto bad_area;
3626 + }
3627
3628 /*
3629 * If for any reason at all we couldn't handle the fault, make
3630 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3631 index 5ca674b..127c3cb 100644
3632 --- a/arch/ia64/mm/hugetlbpage.c
3633 +++ b/arch/ia64/mm/hugetlbpage.c
3634 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3635 unsigned long pgoff, unsigned long flags)
3636 {
3637 struct vm_area_struct *vmm;
3638 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
3639
3640 if (len > RGN_MAP_LIMIT)
3641 return -ENOMEM;
3642 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3643 /* At this point: (!vmm || addr < vmm->vm_end). */
3644 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3645 return -ENOMEM;
3646 - if (!vmm || (addr + len) <= vmm->vm_start)
3647 + if (check_heap_stack_gap(vmm, addr, len, offset))
3648 return addr;
3649 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3650 }
3651 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3652 index 082e383..fb7be80 100644
3653 --- a/arch/ia64/mm/init.c
3654 +++ b/arch/ia64/mm/init.c
3655 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3656 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3657 vma->vm_end = vma->vm_start + PAGE_SIZE;
3658 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3659 +
3660 +#ifdef CONFIG_PAX_PAGEEXEC
3661 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3662 + vma->vm_flags &= ~VM_EXEC;
3663 +
3664 +#ifdef CONFIG_PAX_MPROTECT
3665 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
3666 + vma->vm_flags &= ~VM_MAYEXEC;
3667 +#endif
3668 +
3669 + }
3670 +#endif
3671 +
3672 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3673 down_write(&current->mm->mmap_sem);
3674 if (insert_vm_struct(current->mm, vma)) {
3675 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3676 index 40b3ee9..8c2c112 100644
3677 --- a/arch/m32r/include/asm/cache.h
3678 +++ b/arch/m32r/include/asm/cache.h
3679 @@ -1,8 +1,10 @@
3680 #ifndef _ASM_M32R_CACHE_H
3681 #define _ASM_M32R_CACHE_H
3682
3683 +#include <linux/const.h>
3684 +
3685 /* L1 cache line size */
3686 #define L1_CACHE_SHIFT 4
3687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3688 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3689
3690 #endif /* _ASM_M32R_CACHE_H */
3691 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3692 index 82abd15..d95ae5d 100644
3693 --- a/arch/m32r/lib/usercopy.c
3694 +++ b/arch/m32r/lib/usercopy.c
3695 @@ -14,6 +14,9 @@
3696 unsigned long
3697 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3698 {
3699 + if ((long)n < 0)
3700 + return n;
3701 +
3702 prefetch(from);
3703 if (access_ok(VERIFY_WRITE, to, n))
3704 __copy_user(to,from,n);
3705 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3706 unsigned long
3707 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3708 {
3709 + if ((long)n < 0)
3710 + return n;
3711 +
3712 prefetchw(to);
3713 if (access_ok(VERIFY_READ, from, n))
3714 __copy_user_zeroing(to,from,n);
3715 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3716 index 0395c51..5f26031 100644
3717 --- a/arch/m68k/include/asm/cache.h
3718 +++ b/arch/m68k/include/asm/cache.h
3719 @@ -4,9 +4,11 @@
3720 #ifndef __ARCH_M68K_CACHE_H
3721 #define __ARCH_M68K_CACHE_H
3722
3723 +#include <linux/const.h>
3724 +
3725 /* bytes per L1 cache line */
3726 #define L1_CACHE_SHIFT 4
3727 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3728 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3729
3730 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3731
3732 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3733 index 4efe96a..60e8699 100644
3734 --- a/arch/microblaze/include/asm/cache.h
3735 +++ b/arch/microblaze/include/asm/cache.h
3736 @@ -13,11 +13,12 @@
3737 #ifndef _ASM_MICROBLAZE_CACHE_H
3738 #define _ASM_MICROBLAZE_CACHE_H
3739
3740 +#include <linux/const.h>
3741 #include <asm/registers.h>
3742
3743 #define L1_CACHE_SHIFT 5
3744 /* word-granular cache in microblaze */
3745 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3746 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3747
3748 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3749
3750 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3751 index 01cc6ba..bcb7a5d 100644
3752 --- a/arch/mips/include/asm/atomic.h
3753 +++ b/arch/mips/include/asm/atomic.h
3754 @@ -21,6 +21,10 @@
3755 #include <asm/cmpxchg.h>
3756 #include <asm/war.h>
3757
3758 +#ifdef CONFIG_GENERIC_ATOMIC64
3759 +#include <asm-generic/atomic64.h>
3760 +#endif
3761 +
3762 #define ATOMIC_INIT(i) { (i) }
3763
3764 /*
3765 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3766 */
3767 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3768
3769 +#define atomic64_read_unchecked(v) atomic64_read(v)
3770 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3771 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3772 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3773 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3774 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3775 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3776 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3777 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3778 +
3779 #endif /* CONFIG_64BIT */
3780
3781 /*
3782 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3783 index b4db69f..8f3b093 100644
3784 --- a/arch/mips/include/asm/cache.h
3785 +++ b/arch/mips/include/asm/cache.h
3786 @@ -9,10 +9,11 @@
3787 #ifndef _ASM_CACHE_H
3788 #define _ASM_CACHE_H
3789
3790 +#include <linux/const.h>
3791 #include <kmalloc.h>
3792
3793 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3794 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3795 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3796
3797 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3798 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3799 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3800 index 455c0ac..ad65fbe 100644
3801 --- a/arch/mips/include/asm/elf.h
3802 +++ b/arch/mips/include/asm/elf.h
3803 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
3804 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3805 #endif
3806
3807 +#ifdef CONFIG_PAX_ASLR
3808 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3809 +
3810 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3811 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3812 +#endif
3813 +
3814 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3815 struct linux_binprm;
3816 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3817 int uses_interp);
3818
3819 -struct mm_struct;
3820 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3821 -#define arch_randomize_brk arch_randomize_brk
3822 -
3823 #endif /* _ASM_ELF_H */
3824 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3825 index c1f6afa..38cc6e9 100644
3826 --- a/arch/mips/include/asm/exec.h
3827 +++ b/arch/mips/include/asm/exec.h
3828 @@ -12,6 +12,6 @@
3829 #ifndef _ASM_EXEC_H
3830 #define _ASM_EXEC_H
3831
3832 -extern unsigned long arch_align_stack(unsigned long sp);
3833 +#define arch_align_stack(x) ((x) & ~0xfUL)
3834
3835 #endif /* _ASM_EXEC_H */
3836 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3837 index da9bd7d..91aa7ab 100644
3838 --- a/arch/mips/include/asm/page.h
3839 +++ b/arch/mips/include/asm/page.h
3840 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3841 #ifdef CONFIG_CPU_MIPS32
3842 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3843 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3844 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3845 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3846 #else
3847 typedef struct { unsigned long long pte; } pte_t;
3848 #define pte_val(x) ((x).pte)
3849 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3850 index 881d18b..cea38bc 100644
3851 --- a/arch/mips/include/asm/pgalloc.h
3852 +++ b/arch/mips/include/asm/pgalloc.h
3853 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3854 {
3855 set_pud(pud, __pud((unsigned long)pmd));
3856 }
3857 +
3858 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859 +{
3860 + pud_populate(mm, pud, pmd);
3861 +}
3862 #endif
3863
3864 /*
3865 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3866 index 18806a5..141ffcf 100644
3867 --- a/arch/mips/include/asm/thread_info.h
3868 +++ b/arch/mips/include/asm/thread_info.h
3869 @@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3870 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3871 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3872 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3873 +/* li takes a 32bit immediate */
3874 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3875 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3876
3877 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3878 @@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3879 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3880 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3881 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3882 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3883 +
3884 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3885
3886 /* work to do in syscall_trace_leave() */
3887 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3888 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3889
3890 /* work to do on interrupt/exception return */
3891 #define _TIF_WORK_MASK \
3892 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3893 /* work to do on any return to u-space */
3894 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3895 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3896
3897 #endif /* __KERNEL__ */
3898
3899 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3900 index 9fdd8bc..4bd7f1a 100644
3901 --- a/arch/mips/kernel/binfmt_elfn32.c
3902 +++ b/arch/mips/kernel/binfmt_elfn32.c
3903 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3904 #undef ELF_ET_DYN_BASE
3905 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3906
3907 +#ifdef CONFIG_PAX_ASLR
3908 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3909 +
3910 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3911 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3912 +#endif
3913 +
3914 #include <asm/processor.h>
3915 #include <linux/module.h>
3916 #include <linux/elfcore.h>
3917 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3918 index ff44823..97f8906 100644
3919 --- a/arch/mips/kernel/binfmt_elfo32.c
3920 +++ b/arch/mips/kernel/binfmt_elfo32.c
3921 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3922 #undef ELF_ET_DYN_BASE
3923 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3924
3925 +#ifdef CONFIG_PAX_ASLR
3926 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3927 +
3928 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3929 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3930 +#endif
3931 +
3932 #include <asm/processor.h>
3933
3934 /*
3935 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3936 index 69b17a9..9db82f9 100644
3937 --- a/arch/mips/kernel/process.c
3938 +++ b/arch/mips/kernel/process.c
3939 @@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3940 out:
3941 return pc;
3942 }
3943 -
3944 -/*
3945 - * Don't forget that the stack pointer must be aligned on a 8 bytes
3946 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3947 - */
3948 -unsigned long arch_align_stack(unsigned long sp)
3949 -{
3950 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3951 - sp -= get_random_int() & ~PAGE_MASK;
3952 -
3953 - return sp & ALMASK;
3954 -}
3955 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3956 index 4812c6d..2069554 100644
3957 --- a/arch/mips/kernel/ptrace.c
3958 +++ b/arch/mips/kernel/ptrace.c
3959 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3960 return arch;
3961 }
3962
3963 +#ifdef CONFIG_GRKERNSEC_SETXID
3964 +extern void gr_delayed_cred_worker(void);
3965 +#endif
3966 +
3967 /*
3968 * Notification of system call entry/exit
3969 * - triggered by current->work.syscall_trace
3970 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3971 /* do the secure computing check first */
3972 secure_computing_strict(regs->regs[2]);
3973
3974 +#ifdef CONFIG_GRKERNSEC_SETXID
3975 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3976 + gr_delayed_cred_worker();
3977 +#endif
3978 +
3979 if (!(current->ptrace & PT_PTRACED))
3980 goto out;
3981
3982 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3983 index 374f66e..1c882a0 100644
3984 --- a/arch/mips/kernel/scall32-o32.S
3985 +++ b/arch/mips/kernel/scall32-o32.S
3986 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3987
3988 stack_done:
3989 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3990 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3991 + li t1, _TIF_SYSCALL_WORK
3992 and t0, t1
3993 bnez t0, syscall_trace_entry # -> yes
3994
3995 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3996 index 169de6a..f594a89 100644
3997 --- a/arch/mips/kernel/scall64-64.S
3998 +++ b/arch/mips/kernel/scall64-64.S
3999 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
4000
4001 sd a3, PT_R26(sp) # save a3 for syscall restarting
4002
4003 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4004 + li t1, _TIF_SYSCALL_WORK
4005 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4006 and t0, t1, t0
4007 bnez t0, syscall_trace_entry
4008 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
4009 index 86ec03f..1235baf 100644
4010 --- a/arch/mips/kernel/scall64-n32.S
4011 +++ b/arch/mips/kernel/scall64-n32.S
4012 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
4013
4014 sd a3, PT_R26(sp) # save a3 for syscall restarting
4015
4016 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4017 + li t1, _TIF_SYSCALL_WORK
4018 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4019 and t0, t1, t0
4020 bnez t0, n32_syscall_trace_entry
4021 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
4022 index 53c2d72..3734584 100644
4023 --- a/arch/mips/kernel/scall64-o32.S
4024 +++ b/arch/mips/kernel/scall64-o32.S
4025 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
4026 PTR 4b, bad_stack
4027 .previous
4028
4029 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4030 + li t1, _TIF_SYSCALL_WORK
4031 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4032 and t0, t1, t0
4033 bnez t0, trace_a_syscall
4034 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
4035 index ddcec1e..c7f983e 100644
4036 --- a/arch/mips/mm/fault.c
4037 +++ b/arch/mips/mm/fault.c
4038 @@ -27,6 +27,23 @@
4039 #include <asm/highmem.h> /* For VMALLOC_END */
4040 #include <linux/kdebug.h>
4041
4042 +#ifdef CONFIG_PAX_PAGEEXEC
4043 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4044 +{
4045 + unsigned long i;
4046 +
4047 + printk(KERN_ERR "PAX: bytes at PC: ");
4048 + for (i = 0; i < 5; i++) {
4049 + unsigned int c;
4050 + if (get_user(c, (unsigned int *)pc+i))
4051 + printk(KERN_CONT "???????? ");
4052 + else
4053 + printk(KERN_CONT "%08x ", c);
4054 + }
4055 + printk("\n");
4056 +}
4057 +#endif
4058 +
4059 /*
4060 * This routine handles page faults. It determines the address,
4061 * and the problem, and then passes it off to one of the appropriate
4062 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
4063 index 302d779..6459dc0 100644
4064 --- a/arch/mips/mm/mmap.c
4065 +++ b/arch/mips/mm/mmap.c
4066 @@ -71,6 +71,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4067 struct vm_area_struct *vma;
4068 unsigned long addr = addr0;
4069 int do_color_align;
4070 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4071
4072 if (unlikely(len > TASK_SIZE))
4073 return -ENOMEM;
4074 @@ -95,6 +96,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4075 do_color_align = 1;
4076
4077 /* requesting a specific address */
4078 +
4079 +#ifdef CONFIG_PAX_RANDMMAP
4080 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4081 +#endif
4082 +
4083 if (addr) {
4084 if (do_color_align)
4085 addr = COLOUR_ALIGN(addr, pgoff);
4086 @@ -102,8 +108,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4087 addr = PAGE_ALIGN(addr);
4088
4089 vma = find_vma(mm, addr);
4090 - if (TASK_SIZE - len >= addr &&
4091 - (!vma || addr + len <= vma->vm_start))
4092 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
4093 return addr;
4094 }
4095
4096 @@ -118,7 +123,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4097 /* At this point: (!vma || addr < vma->vm_end). */
4098 if (TASK_SIZE - len < addr)
4099 return -ENOMEM;
4100 - if (!vma || addr + len <= vma->vm_start)
4101 + if (check_heap_stack_gap(vmm, addr, len, offset))
4102 return addr;
4103 addr = vma->vm_end;
4104 if (do_color_align)
4105 @@ -145,7 +150,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4106 /* make sure it can fit in the remaining address space */
4107 if (likely(addr > len)) {
4108 vma = find_vma(mm, addr - len);
4109 - if (!vma || addr <= vma->vm_start) {
4110 + if (check_heap_stack_gap(vmm, addr - len, len, offset))
4111 /* cache the address as a hint for next time */
4112 return mm->free_area_cache = addr - len;
4113 }
4114 @@ -155,17 +160,17 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4115 goto bottomup;
4116
4117 addr = mm->mmap_base - len;
4118 - if (do_color_align)
4119 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4120
4121 do {
4122 + if (do_color_align)
4123 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4124 /*
4125 * Lookup failure means no vma is above this address,
4126 * else if new region fits below vma->vm_start,
4127 * return with success:
4128 */
4129 vma = find_vma(mm, addr);
4130 - if (likely(!vma || addr + len <= vma->vm_start)) {
4131 + if (check_heap_stack_gap(vmm, addr, len, offset)) {
4132 /* cache the address as a hint for next time */
4133 return mm->free_area_cache = addr;
4134 }
4135 @@ -175,10 +180,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4136 mm->cached_hole_size = vma->vm_start - addr;
4137
4138 /* try just below the current vma->vm_start */
4139 - addr = vma->vm_start - len;
4140 - if (do_color_align)
4141 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4142 - } while (likely(len < vma->vm_start));
4143 + addr = skip_heap_stack_gap(vma, len, offset);
4144 + } while (!IS_ERR_VALUE(addr));
4145
4146 bottomup:
4147 /*
4148 @@ -223,6 +226,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4149 {
4150 unsigned long random_factor = 0UL;
4151
4152 +#ifdef CONFIG_PAX_RANDMMAP
4153 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4154 +#endif
4155 +
4156 if (current->flags & PF_RANDOMIZE) {
4157 random_factor = get_random_int();
4158 random_factor = random_factor << PAGE_SHIFT;
4159 @@ -234,38 +241,23 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4160
4161 if (mmap_is_legacy()) {
4162 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4163 +
4164 +#ifdef CONFIG_PAX_RANDMMAP
4165 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4166 + mm->mmap_base += mm->delta_mmap;
4167 +#endif
4168 +
4169 mm->get_unmapped_area = arch_get_unmapped_area;
4170 mm->unmap_area = arch_unmap_area;
4171 } else {
4172 mm->mmap_base = mmap_base(random_factor);
4173 +
4174 +#ifdef CONFIG_PAX_RANDMMAP
4175 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4176 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4177 +#endif
4178 +
4179 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4180 mm->unmap_area = arch_unmap_area_topdown;
4181 }
4182 }
4183 -
4184 -static inline unsigned long brk_rnd(void)
4185 -{
4186 - unsigned long rnd = get_random_int();
4187 -
4188 - rnd = rnd << PAGE_SHIFT;
4189 - /* 8MB for 32bit, 256MB for 64bit */
4190 - if (TASK_IS_32BIT_ADDR)
4191 - rnd = rnd & 0x7ffffful;
4192 - else
4193 - rnd = rnd & 0xffffffful;
4194 -
4195 - return rnd;
4196 -}
4197 -
4198 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4199 -{
4200 - unsigned long base = mm->brk;
4201 - unsigned long ret;
4202 -
4203 - ret = PAGE_ALIGN(base + brk_rnd());
4204 -
4205 - if (ret < mm->brk)
4206 - return mm->brk;
4207 -
4208 - return ret;
4209 -}
4210 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4211 index 967d144..db12197 100644
4212 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
4213 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4214 @@ -11,12 +11,14 @@
4215 #ifndef _ASM_PROC_CACHE_H
4216 #define _ASM_PROC_CACHE_H
4217
4218 +#include <linux/const.h>
4219 +
4220 /* L1 cache */
4221
4222 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4223 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
4224 -#define L1_CACHE_BYTES 16 /* bytes per entry */
4225 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
4226 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4227 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
4228
4229 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4230 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4231 index bcb5df2..84fabd2 100644
4232 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4233 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4234 @@ -16,13 +16,15 @@
4235 #ifndef _ASM_PROC_CACHE_H
4236 #define _ASM_PROC_CACHE_H
4237
4238 +#include <linux/const.h>
4239 +
4240 /*
4241 * L1 cache
4242 */
4243 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4244 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4245 -#define L1_CACHE_BYTES 32 /* bytes per entry */
4246 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4247 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4248 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4249
4250 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4251 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4252 index 4ce7a01..449202a 100644
4253 --- a/arch/openrisc/include/asm/cache.h
4254 +++ b/arch/openrisc/include/asm/cache.h
4255 @@ -19,11 +19,13 @@
4256 #ifndef __ASM_OPENRISC_CACHE_H
4257 #define __ASM_OPENRISC_CACHE_H
4258
4259 +#include <linux/const.h>
4260 +
4261 /* FIXME: How can we replace these with values from the CPU...
4262 * they shouldn't be hard-coded!
4263 */
4264
4265 -#define L1_CACHE_BYTES 16
4266 #define L1_CACHE_SHIFT 4
4267 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4268
4269 #endif /* __ASM_OPENRISC_CACHE_H */
4270 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4271 index af9cf30..2aae9b2 100644
4272 --- a/arch/parisc/include/asm/atomic.h
4273 +++ b/arch/parisc/include/asm/atomic.h
4274 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4275
4276 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4277
4278 +#define atomic64_read_unchecked(v) atomic64_read(v)
4279 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4280 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4281 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4282 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4283 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4284 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4285 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4286 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4287 +
4288 #endif /* !CONFIG_64BIT */
4289
4290
4291 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4292 index 47f11c7..3420df2 100644
4293 --- a/arch/parisc/include/asm/cache.h
4294 +++ b/arch/parisc/include/asm/cache.h
4295 @@ -5,6 +5,7 @@
4296 #ifndef __ARCH_PARISC_CACHE_H
4297 #define __ARCH_PARISC_CACHE_H
4298
4299 +#include <linux/const.h>
4300
4301 /*
4302 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4303 @@ -15,13 +16,13 @@
4304 * just ruin performance.
4305 */
4306 #ifdef CONFIG_PA20
4307 -#define L1_CACHE_BYTES 64
4308 #define L1_CACHE_SHIFT 6
4309 #else
4310 -#define L1_CACHE_BYTES 32
4311 #define L1_CACHE_SHIFT 5
4312 #endif
4313
4314 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4315 +
4316 #ifndef __ASSEMBLY__
4317
4318 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4319 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4320 index 19f6cb1..6c78cf2 100644
4321 --- a/arch/parisc/include/asm/elf.h
4322 +++ b/arch/parisc/include/asm/elf.h
4323 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4324
4325 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4326
4327 +#ifdef CONFIG_PAX_ASLR
4328 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4329 +
4330 +#define PAX_DELTA_MMAP_LEN 16
4331 +#define PAX_DELTA_STACK_LEN 16
4332 +#endif
4333 +
4334 /* This yields a mask that user programs can use to figure out what
4335 instruction set this CPU supports. This could be done in user space,
4336 but it's not easy, and we've already done it here. */
4337 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4338 index fc987a1..6e068ef 100644
4339 --- a/arch/parisc/include/asm/pgalloc.h
4340 +++ b/arch/parisc/include/asm/pgalloc.h
4341 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4342 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4343 }
4344
4345 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4346 +{
4347 + pgd_populate(mm, pgd, pmd);
4348 +}
4349 +
4350 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4351 {
4352 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4353 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4354 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4355 #define pmd_free(mm, x) do { } while (0)
4356 #define pgd_populate(mm, pmd, pte) BUG()
4357 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
4358
4359 #endif
4360
4361 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4362 index ee99f23..802b0a1 100644
4363 --- a/arch/parisc/include/asm/pgtable.h
4364 +++ b/arch/parisc/include/asm/pgtable.h
4365 @@ -212,6 +212,17 @@ struct vm_area_struct;
4366 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4367 #define PAGE_COPY PAGE_EXECREAD
4368 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4369 +
4370 +#ifdef CONFIG_PAX_PAGEEXEC
4371 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4372 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4373 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4374 +#else
4375 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4376 +# define PAGE_COPY_NOEXEC PAGE_COPY
4377 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4378 +#endif
4379 +
4380 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4381 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4382 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4383 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4384 index 4ba2c93..f5e3974 100644
4385 --- a/arch/parisc/include/asm/uaccess.h
4386 +++ b/arch/parisc/include/asm/uaccess.h
4387 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4388 const void __user *from,
4389 unsigned long n)
4390 {
4391 - int sz = __compiletime_object_size(to);
4392 + size_t sz = __compiletime_object_size(to);
4393 int ret = -EFAULT;
4394
4395 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4396 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4397 ret = __copy_from_user(to, from, n);
4398 else
4399 copy_from_user_overflow();
4400 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4401 index 5e34ccf..672bc9c 100644
4402 --- a/arch/parisc/kernel/module.c
4403 +++ b/arch/parisc/kernel/module.c
4404 @@ -98,16 +98,38 @@
4405
4406 /* three functions to determine where in the module core
4407 * or init pieces the location is */
4408 +static inline int in_init_rx(struct module *me, void *loc)
4409 +{
4410 + return (loc >= me->module_init_rx &&
4411 + loc < (me->module_init_rx + me->init_size_rx));
4412 +}
4413 +
4414 +static inline int in_init_rw(struct module *me, void *loc)
4415 +{
4416 + return (loc >= me->module_init_rw &&
4417 + loc < (me->module_init_rw + me->init_size_rw));
4418 +}
4419 +
4420 static inline int in_init(struct module *me, void *loc)
4421 {
4422 - return (loc >= me->module_init &&
4423 - loc <= (me->module_init + me->init_size));
4424 + return in_init_rx(me, loc) || in_init_rw(me, loc);
4425 +}
4426 +
4427 +static inline int in_core_rx(struct module *me, void *loc)
4428 +{
4429 + return (loc >= me->module_core_rx &&
4430 + loc < (me->module_core_rx + me->core_size_rx));
4431 +}
4432 +
4433 +static inline int in_core_rw(struct module *me, void *loc)
4434 +{
4435 + return (loc >= me->module_core_rw &&
4436 + loc < (me->module_core_rw + me->core_size_rw));
4437 }
4438
4439 static inline int in_core(struct module *me, void *loc)
4440 {
4441 - return (loc >= me->module_core &&
4442 - loc <= (me->module_core + me->core_size));
4443 + return in_core_rx(me, loc) || in_core_rw(me, loc);
4444 }
4445
4446 static inline int in_local(struct module *me, void *loc)
4447 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4448 }
4449
4450 /* align things a bit */
4451 - me->core_size = ALIGN(me->core_size, 16);
4452 - me->arch.got_offset = me->core_size;
4453 - me->core_size += gots * sizeof(struct got_entry);
4454 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4455 + me->arch.got_offset = me->core_size_rw;
4456 + me->core_size_rw += gots * sizeof(struct got_entry);
4457
4458 - me->core_size = ALIGN(me->core_size, 16);
4459 - me->arch.fdesc_offset = me->core_size;
4460 - me->core_size += fdescs * sizeof(Elf_Fdesc);
4461 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4462 + me->arch.fdesc_offset = me->core_size_rw;
4463 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4464
4465 me->arch.got_max = gots;
4466 me->arch.fdesc_max = fdescs;
4467 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4468
4469 BUG_ON(value == 0);
4470
4471 - got = me->module_core + me->arch.got_offset;
4472 + got = me->module_core_rw + me->arch.got_offset;
4473 for (i = 0; got[i].addr; i++)
4474 if (got[i].addr == value)
4475 goto out;
4476 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4477 #ifdef CONFIG_64BIT
4478 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4479 {
4480 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4481 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4482
4483 if (!value) {
4484 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4485 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4486
4487 /* Create new one */
4488 fdesc->addr = value;
4489 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4490 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4491 return (Elf_Addr)fdesc;
4492 }
4493 #endif /* CONFIG_64BIT */
4494 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4495
4496 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4497 end = table + sechdrs[me->arch.unwind_section].sh_size;
4498 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4499 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4500
4501 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4502 me->arch.unwind_section, table, end, gp);
4503 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4504 index f76c108..92bad82 100644
4505 --- a/arch/parisc/kernel/sys_parisc.c
4506 +++ b/arch/parisc/kernel/sys_parisc.c
4507 @@ -33,9 +33,11 @@
4508 #include <linux/utsname.h>
4509 #include <linux/personality.h>
4510
4511 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4512 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
4513 + unsigned long flags)
4514 {
4515 struct vm_area_struct *vma;
4516 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4517
4518 addr = PAGE_ALIGN(addr);
4519
4520 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4521 /* At this point: (!vma || addr < vma->vm_end). */
4522 if (TASK_SIZE - len < addr)
4523 return -ENOMEM;
4524 - if (!vma || addr + len <= vma->vm_start)
4525 + if (check_heap_stack_gap(vma, addr, len, offset))
4526 return addr;
4527 addr = vma->vm_end;
4528 }
4529 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
4530 return offset & 0x3FF000;
4531 }
4532
4533 -static unsigned long get_shared_area(struct address_space *mapping,
4534 - unsigned long addr, unsigned long len, unsigned long pgoff)
4535 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
4536 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
4537 {
4538 struct vm_area_struct *vma;
4539 int offset = mapping ? get_offset(mapping) : 0;
4540 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4541
4542 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
4543
4544 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4545 /* At this point: (!vma || addr < vma->vm_end). */
4546 if (TASK_SIZE - len < addr)
4547 return -ENOMEM;
4548 - if (!vma || addr + len <= vma->vm_start)
4549 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
4550 return addr;
4551 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4552 if (addr < vma->vm_end) /* handle wraparound */
4553 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4554 if (flags & MAP_FIXED)
4555 return addr;
4556 if (!addr)
4557 - addr = TASK_UNMAPPED_BASE;
4558 + addr = current->mm->mmap_base;
4559
4560 if (filp) {
4561 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4562 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
4563 } else if(flags & MAP_SHARED) {
4564 - addr = get_shared_area(NULL, addr, len, pgoff);
4565 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
4566 } else {
4567 - addr = get_unshared_area(addr, len);
4568 + addr = get_unshared_area(filp, addr, len, flags);
4569 }
4570 return addr;
4571 }
4572 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4573 index 45ba99f..8e22c33 100644
4574 --- a/arch/parisc/kernel/traps.c
4575 +++ b/arch/parisc/kernel/traps.c
4576 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4577
4578 down_read(&current->mm->mmap_sem);
4579 vma = find_vma(current->mm,regs->iaoq[0]);
4580 - if (vma && (regs->iaoq[0] >= vma->vm_start)
4581 - && (vma->vm_flags & VM_EXEC)) {
4582 -
4583 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4584 fault_address = regs->iaoq[0];
4585 fault_space = regs->iasq[0];
4586
4587 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4588 index 18162ce..94de376 100644
4589 --- a/arch/parisc/mm/fault.c
4590 +++ b/arch/parisc/mm/fault.c
4591 @@ -15,6 +15,7 @@
4592 #include <linux/sched.h>
4593 #include <linux/interrupt.h>
4594 #include <linux/module.h>
4595 +#include <linux/unistd.h>
4596
4597 #include <asm/uaccess.h>
4598 #include <asm/traps.h>
4599 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4600 static unsigned long
4601 parisc_acctyp(unsigned long code, unsigned int inst)
4602 {
4603 - if (code == 6 || code == 16)
4604 + if (code == 6 || code == 7 || code == 16)
4605 return VM_EXEC;
4606
4607 switch (inst & 0xf0000000) {
4608 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4609 }
4610 #endif
4611
4612 +#ifdef CONFIG_PAX_PAGEEXEC
4613 +/*
4614 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4615 + *
4616 + * returns 1 when task should be killed
4617 + * 2 when rt_sigreturn trampoline was detected
4618 + * 3 when unpatched PLT trampoline was detected
4619 + */
4620 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4621 +{
4622 +
4623 +#ifdef CONFIG_PAX_EMUPLT
4624 + int err;
4625 +
4626 + do { /* PaX: unpatched PLT emulation */
4627 + unsigned int bl, depwi;
4628 +
4629 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4630 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4631 +
4632 + if (err)
4633 + break;
4634 +
4635 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4636 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4637 +
4638 + err = get_user(ldw, (unsigned int *)addr);
4639 + err |= get_user(bv, (unsigned int *)(addr+4));
4640 + err |= get_user(ldw2, (unsigned int *)(addr+8));
4641 +
4642 + if (err)
4643 + break;
4644 +
4645 + if (ldw == 0x0E801096U &&
4646 + bv == 0xEAC0C000U &&
4647 + ldw2 == 0x0E881095U)
4648 + {
4649 + unsigned int resolver, map;
4650 +
4651 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4652 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4653 + if (err)
4654 + break;
4655 +
4656 + regs->gr[20] = instruction_pointer(regs)+8;
4657 + regs->gr[21] = map;
4658 + regs->gr[22] = resolver;
4659 + regs->iaoq[0] = resolver | 3UL;
4660 + regs->iaoq[1] = regs->iaoq[0] + 4;
4661 + return 3;
4662 + }
4663 + }
4664 + } while (0);
4665 +#endif
4666 +
4667 +#ifdef CONFIG_PAX_EMUTRAMP
4668 +
4669 +#ifndef CONFIG_PAX_EMUSIGRT
4670 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4671 + return 1;
4672 +#endif
4673 +
4674 + do { /* PaX: rt_sigreturn emulation */
4675 + unsigned int ldi1, ldi2, bel, nop;
4676 +
4677 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4678 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4679 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4680 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4681 +
4682 + if (err)
4683 + break;
4684 +
4685 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4686 + ldi2 == 0x3414015AU &&
4687 + bel == 0xE4008200U &&
4688 + nop == 0x08000240U)
4689 + {
4690 + regs->gr[25] = (ldi1 & 2) >> 1;
4691 + regs->gr[20] = __NR_rt_sigreturn;
4692 + regs->gr[31] = regs->iaoq[1] + 16;
4693 + regs->sr[0] = regs->iasq[1];
4694 + regs->iaoq[0] = 0x100UL;
4695 + regs->iaoq[1] = regs->iaoq[0] + 4;
4696 + regs->iasq[0] = regs->sr[2];
4697 + regs->iasq[1] = regs->sr[2];
4698 + return 2;
4699 + }
4700 + } while (0);
4701 +#endif
4702 +
4703 + return 1;
4704 +}
4705 +
4706 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4707 +{
4708 + unsigned long i;
4709 +
4710 + printk(KERN_ERR "PAX: bytes at PC: ");
4711 + for (i = 0; i < 5; i++) {
4712 + unsigned int c;
4713 + if (get_user(c, (unsigned int *)pc+i))
4714 + printk(KERN_CONT "???????? ");
4715 + else
4716 + printk(KERN_CONT "%08x ", c);
4717 + }
4718 + printk("\n");
4719 +}
4720 +#endif
4721 +
4722 int fixup_exception(struct pt_regs *regs)
4723 {
4724 const struct exception_table_entry *fix;
4725 @@ -192,8 +303,33 @@ good_area:
4726
4727 acc_type = parisc_acctyp(code,regs->iir);
4728
4729 - if ((vma->vm_flags & acc_type) != acc_type)
4730 + if ((vma->vm_flags & acc_type) != acc_type) {
4731 +
4732 +#ifdef CONFIG_PAX_PAGEEXEC
4733 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4734 + (address & ~3UL) == instruction_pointer(regs))
4735 + {
4736 + up_read(&mm->mmap_sem);
4737 + switch (pax_handle_fetch_fault(regs)) {
4738 +
4739 +#ifdef CONFIG_PAX_EMUPLT
4740 + case 3:
4741 + return;
4742 +#endif
4743 +
4744 +#ifdef CONFIG_PAX_EMUTRAMP
4745 + case 2:
4746 + return;
4747 +#endif
4748 +
4749 + }
4750 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4751 + do_group_exit(SIGKILL);
4752 + }
4753 +#endif
4754 +
4755 goto bad_area;
4756 + }
4757
4758 /*
4759 * If for any reason at all we couldn't handle the fault, make
4760 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4761 index e3b1d41..8e81edf 100644
4762 --- a/arch/powerpc/include/asm/atomic.h
4763 +++ b/arch/powerpc/include/asm/atomic.h
4764 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4765 return t1;
4766 }
4767
4768 +#define atomic64_read_unchecked(v) atomic64_read(v)
4769 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4770 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4771 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4772 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4773 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4774 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4775 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4776 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4777 +
4778 #endif /* __powerpc64__ */
4779
4780 #endif /* __KERNEL__ */
4781 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4782 index 9e495c9..b6878e5 100644
4783 --- a/arch/powerpc/include/asm/cache.h
4784 +++ b/arch/powerpc/include/asm/cache.h
4785 @@ -3,6 +3,7 @@
4786
4787 #ifdef __KERNEL__
4788
4789 +#include <linux/const.h>
4790
4791 /* bytes per L1 cache line */
4792 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4793 @@ -22,7 +23,7 @@
4794 #define L1_CACHE_SHIFT 7
4795 #endif
4796
4797 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4798 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4799
4800 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4801
4802 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4803 index 6abf0a1..459d0f1 100644
4804 --- a/arch/powerpc/include/asm/elf.h
4805 +++ b/arch/powerpc/include/asm/elf.h
4806 @@ -28,8 +28,19 @@
4807 the loader. We need to make sure that it is out of the way of the program
4808 that it will "exec", and that there is sufficient room for the brk. */
4809
4810 -extern unsigned long randomize_et_dyn(unsigned long base);
4811 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4812 +#define ELF_ET_DYN_BASE (0x20000000)
4813 +
4814 +#ifdef CONFIG_PAX_ASLR
4815 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4816 +
4817 +#ifdef __powerpc64__
4818 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4819 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4820 +#else
4821 +#define PAX_DELTA_MMAP_LEN 15
4822 +#define PAX_DELTA_STACK_LEN 15
4823 +#endif
4824 +#endif
4825
4826 /*
4827 * Our registers are always unsigned longs, whether we're a 32 bit
4828 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4829 (0x7ff >> (PAGE_SHIFT - 12)) : \
4830 (0x3ffff >> (PAGE_SHIFT - 12)))
4831
4832 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4833 -#define arch_randomize_brk arch_randomize_brk
4834 -
4835 -
4836 #ifdef CONFIG_SPU_BASE
4837 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4838 #define NT_SPU 1
4839 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4840 index 8196e9c..d83a9f3 100644
4841 --- a/arch/powerpc/include/asm/exec.h
4842 +++ b/arch/powerpc/include/asm/exec.h
4843 @@ -4,6 +4,6 @@
4844 #ifndef _ASM_POWERPC_EXEC_H
4845 #define _ASM_POWERPC_EXEC_H
4846
4847 -extern unsigned long arch_align_stack(unsigned long sp);
4848 +#define arch_align_stack(x) ((x) & ~0xfUL)
4849
4850 #endif /* _ASM_POWERPC_EXEC_H */
4851 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4852 index 5acabbd..7ea14fa 100644
4853 --- a/arch/powerpc/include/asm/kmap_types.h
4854 +++ b/arch/powerpc/include/asm/kmap_types.h
4855 @@ -10,7 +10,7 @@
4856 * 2 of the License, or (at your option) any later version.
4857 */
4858
4859 -#define KM_TYPE_NR 16
4860 +#define KM_TYPE_NR 17
4861
4862 #endif /* __KERNEL__ */
4863 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4864 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4865 index 8565c25..2865190 100644
4866 --- a/arch/powerpc/include/asm/mman.h
4867 +++ b/arch/powerpc/include/asm/mman.h
4868 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4869 }
4870 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4871
4872 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4873 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4874 {
4875 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4876 }
4877 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4878 index f072e97..b436dee 100644
4879 --- a/arch/powerpc/include/asm/page.h
4880 +++ b/arch/powerpc/include/asm/page.h
4881 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4882 * and needs to be executable. This means the whole heap ends
4883 * up being executable.
4884 */
4885 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4886 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4887 +#define VM_DATA_DEFAULT_FLAGS32 \
4888 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4889 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4890
4891 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4892 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4893 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4894 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4895 #endif
4896
4897 +#define ktla_ktva(addr) (addr)
4898 +#define ktva_ktla(addr) (addr)
4899 +
4900 /*
4901 * Use the top bit of the higher-level page table entries to indicate whether
4902 * the entries we point to contain hugepages. This works because we know that
4903 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4904 index cd915d6..c10cee8 100644
4905 --- a/arch/powerpc/include/asm/page_64.h
4906 +++ b/arch/powerpc/include/asm/page_64.h
4907 @@ -154,15 +154,18 @@ do { \
4908 * stack by default, so in the absence of a PT_GNU_STACK program header
4909 * we turn execute permission off.
4910 */
4911 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4912 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4913 +#define VM_STACK_DEFAULT_FLAGS32 \
4914 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4915 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4916
4917 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4918 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4919
4920 +#ifndef CONFIG_PAX_PAGEEXEC
4921 #define VM_STACK_DEFAULT_FLAGS \
4922 (is_32bit_task() ? \
4923 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4924 +#endif
4925
4926 #include <asm-generic/getorder.h>
4927
4928 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4929 index 292725c..f87ae14 100644
4930 --- a/arch/powerpc/include/asm/pgalloc-64.h
4931 +++ b/arch/powerpc/include/asm/pgalloc-64.h
4932 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4933 #ifndef CONFIG_PPC_64K_PAGES
4934
4935 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4936 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4937
4938 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4939 {
4940 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4941 pud_set(pud, (unsigned long)pmd);
4942 }
4943
4944 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4945 +{
4946 + pud_populate(mm, pud, pmd);
4947 +}
4948 +
4949 #define pmd_populate(mm, pmd, pte_page) \
4950 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4951 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4952 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4953 #else /* CONFIG_PPC_64K_PAGES */
4954
4955 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4956 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4957
4958 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4959 pte_t *pte)
4960 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4961 index a9cbd3b..3b67efa 100644
4962 --- a/arch/powerpc/include/asm/pgtable.h
4963 +++ b/arch/powerpc/include/asm/pgtable.h
4964 @@ -2,6 +2,7 @@
4965 #define _ASM_POWERPC_PGTABLE_H
4966 #ifdef __KERNEL__
4967
4968 +#include <linux/const.h>
4969 #ifndef __ASSEMBLY__
4970 #include <asm/processor.h> /* For TASK_SIZE */
4971 #include <asm/mmu.h>
4972 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4973 index 4aad413..85d86bf 100644
4974 --- a/arch/powerpc/include/asm/pte-hash32.h
4975 +++ b/arch/powerpc/include/asm/pte-hash32.h
4976 @@ -21,6 +21,7 @@
4977 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4978 #define _PAGE_USER 0x004 /* usermode access allowed */
4979 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4980 +#define _PAGE_EXEC _PAGE_GUARDED
4981 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4982 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4983 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4984 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4985 index d24c141..b60696e 100644
4986 --- a/arch/powerpc/include/asm/reg.h
4987 +++ b/arch/powerpc/include/asm/reg.h
4988 @@ -215,6 +215,7 @@
4989 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4990 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4991 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4992 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4993 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4994 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4995 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4996 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4997 index 406b7b9..af63426 100644
4998 --- a/arch/powerpc/include/asm/thread_info.h
4999 +++ b/arch/powerpc/include/asm/thread_info.h
5000 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
5001 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
5002 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
5003 #define TIF_SINGLESTEP 8 /* singlestepping active */
5004 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
5005 #define TIF_SECCOMP 10 /* secure computing */
5006 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
5007 #define TIF_NOERROR 12 /* Force successful syscall return */
5008 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
5009 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
5010 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
5011 for stack store? */
5012 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
5013 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
5014 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
5015
5016 /* as above, but as bit values */
5017 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5018 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
5019 #define _TIF_UPROBE (1<<TIF_UPROBE)
5020 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5021 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
5022 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5023 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
5024 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
5025 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
5026 + _TIF_GRSEC_SETXID)
5027
5028 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
5029 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
5030 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
5031 index 4db4959..335e00c 100644
5032 --- a/arch/powerpc/include/asm/uaccess.h
5033 +++ b/arch/powerpc/include/asm/uaccess.h
5034 @@ -13,6 +13,8 @@
5035 #define VERIFY_READ 0
5036 #define VERIFY_WRITE 1
5037
5038 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5039 +
5040 /*
5041 * The fs value determines whether argument validity checking should be
5042 * performed or not. If get_fs() == USER_DS, checking is performed, with
5043 @@ -318,52 +320,6 @@ do { \
5044 extern unsigned long __copy_tofrom_user(void __user *to,
5045 const void __user *from, unsigned long size);
5046
5047 -#ifndef __powerpc64__
5048 -
5049 -static inline unsigned long copy_from_user(void *to,
5050 - const void __user *from, unsigned long n)
5051 -{
5052 - unsigned long over;
5053 -
5054 - if (access_ok(VERIFY_READ, from, n))
5055 - return __copy_tofrom_user((__force void __user *)to, from, n);
5056 - if ((unsigned long)from < TASK_SIZE) {
5057 - over = (unsigned long)from + n - TASK_SIZE;
5058 - return __copy_tofrom_user((__force void __user *)to, from,
5059 - n - over) + over;
5060 - }
5061 - return n;
5062 -}
5063 -
5064 -static inline unsigned long copy_to_user(void __user *to,
5065 - const void *from, unsigned long n)
5066 -{
5067 - unsigned long over;
5068 -
5069 - if (access_ok(VERIFY_WRITE, to, n))
5070 - return __copy_tofrom_user(to, (__force void __user *)from, n);
5071 - if ((unsigned long)to < TASK_SIZE) {
5072 - over = (unsigned long)to + n - TASK_SIZE;
5073 - return __copy_tofrom_user(to, (__force void __user *)from,
5074 - n - over) + over;
5075 - }
5076 - return n;
5077 -}
5078 -
5079 -#else /* __powerpc64__ */
5080 -
5081 -#define __copy_in_user(to, from, size) \
5082 - __copy_tofrom_user((to), (from), (size))
5083 -
5084 -extern unsigned long copy_from_user(void *to, const void __user *from,
5085 - unsigned long n);
5086 -extern unsigned long copy_to_user(void __user *to, const void *from,
5087 - unsigned long n);
5088 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
5089 - unsigned long n);
5090 -
5091 -#endif /* __powerpc64__ */
5092 -
5093 static inline unsigned long __copy_from_user_inatomic(void *to,
5094 const void __user *from, unsigned long n)
5095 {
5096 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
5097 if (ret == 0)
5098 return 0;
5099 }
5100 +
5101 + if (!__builtin_constant_p(n))
5102 + check_object_size(to, n, false);
5103 +
5104 return __copy_tofrom_user((__force void __user *)to, from, n);
5105 }
5106
5107 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
5108 if (ret == 0)
5109 return 0;
5110 }
5111 +
5112 + if (!__builtin_constant_p(n))
5113 + check_object_size(from, n, true);
5114 +
5115 return __copy_tofrom_user(to, (__force const void __user *)from, n);
5116 }
5117
5118 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
5119 return __copy_to_user_inatomic(to, from, size);
5120 }
5121
5122 +#ifndef __powerpc64__
5123 +
5124 +static inline unsigned long __must_check copy_from_user(void *to,
5125 + const void __user *from, unsigned long n)
5126 +{
5127 + unsigned long over;
5128 +
5129 + if ((long)n < 0)
5130 + return n;
5131 +
5132 + if (access_ok(VERIFY_READ, from, n)) {
5133 + if (!__builtin_constant_p(n))
5134 + check_object_size(to, n, false);
5135 + return __copy_tofrom_user((__force void __user *)to, from, n);
5136 + }
5137 + if ((unsigned long)from < TASK_SIZE) {
5138 + over = (unsigned long)from + n - TASK_SIZE;
5139 + if (!__builtin_constant_p(n - over))
5140 + check_object_size(to, n - over, false);
5141 + return __copy_tofrom_user((__force void __user *)to, from,
5142 + n - over) + over;
5143 + }
5144 + return n;
5145 +}
5146 +
5147 +static inline unsigned long __must_check copy_to_user(void __user *to,
5148 + const void *from, unsigned long n)
5149 +{
5150 + unsigned long over;
5151 +
5152 + if ((long)n < 0)
5153 + return n;
5154 +
5155 + if (access_ok(VERIFY_WRITE, to, n)) {
5156 + if (!__builtin_constant_p(n))
5157 + check_object_size(from, n, true);
5158 + return __copy_tofrom_user(to, (__force void __user *)from, n);
5159 + }
5160 + if ((unsigned long)to < TASK_SIZE) {
5161 + over = (unsigned long)to + n - TASK_SIZE;
5162 + if (!__builtin_constant_p(n))
5163 + check_object_size(from, n - over, true);
5164 + return __copy_tofrom_user(to, (__force void __user *)from,
5165 + n - over) + over;
5166 + }
5167 + return n;
5168 +}
5169 +
5170 +#else /* __powerpc64__ */
5171 +
5172 +#define __copy_in_user(to, from, size) \
5173 + __copy_tofrom_user((to), (from), (size))
5174 +
5175 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
5176 +{
5177 + if ((long)n < 0 || n > INT_MAX)
5178 + return n;
5179 +
5180 + if (!__builtin_constant_p(n))
5181 + check_object_size(to, n, false);
5182 +
5183 + if (likely(access_ok(VERIFY_READ, from, n)))
5184 + n = __copy_from_user(to, from, n);
5185 + else
5186 + memset(to, 0, n);
5187 + return n;
5188 +}
5189 +
5190 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
5191 +{
5192 + if ((long)n < 0 || n > INT_MAX)
5193 + return n;
5194 +
5195 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
5196 + if (!__builtin_constant_p(n))
5197 + check_object_size(from, n, true);
5198 + n = __copy_to_user(to, from, n);
5199 + }
5200 + return n;
5201 +}
5202 +
5203 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
5204 + unsigned long n);
5205 +
5206 +#endif /* __powerpc64__ */
5207 +
5208 extern unsigned long __clear_user(void __user *addr, unsigned long size);
5209
5210 static inline unsigned long clear_user(void __user *addr, unsigned long size)
5211 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
5212 index 4684e33..acc4d19e 100644
5213 --- a/arch/powerpc/kernel/exceptions-64e.S
5214 +++ b/arch/powerpc/kernel/exceptions-64e.S
5215 @@ -715,6 +715,7 @@ storage_fault_common:
5216 std r14,_DAR(r1)
5217 std r15,_DSISR(r1)
5218 addi r3,r1,STACK_FRAME_OVERHEAD
5219 + bl .save_nvgprs
5220 mr r4,r14
5221 mr r5,r15
5222 ld r14,PACA_EXGEN+EX_R14(r13)
5223 @@ -723,8 +724,7 @@ storage_fault_common:
5224 cmpdi r3,0
5225 bne- 1f
5226 b .ret_from_except_lite
5227 -1: bl .save_nvgprs
5228 - mr r5,r3
5229 +1: mr r5,r3
5230 addi r3,r1,STACK_FRAME_OVERHEAD
5231 ld r4,_DAR(r1)
5232 bl .bad_page_fault
5233 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
5234 index 10b658a..e542888 100644
5235 --- a/arch/powerpc/kernel/exceptions-64s.S
5236 +++ b/arch/powerpc/kernel/exceptions-64s.S
5237 @@ -1013,10 +1013,10 @@ handle_page_fault:
5238 11: ld r4,_DAR(r1)
5239 ld r5,_DSISR(r1)
5240 addi r3,r1,STACK_FRAME_OVERHEAD
5241 + bl .save_nvgprs
5242 bl .do_page_fault
5243 cmpdi r3,0
5244 beq+ 12f
5245 - bl .save_nvgprs
5246 mr r5,r3
5247 addi r3,r1,STACK_FRAME_OVERHEAD
5248 lwz r4,_DAR(r1)
5249 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
5250 index 2e3200c..72095ce 100644
5251 --- a/arch/powerpc/kernel/module_32.c
5252 +++ b/arch/powerpc/kernel/module_32.c
5253 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
5254 me->arch.core_plt_section = i;
5255 }
5256 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
5257 - printk("Module doesn't contain .plt or .init.plt sections.\n");
5258 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
5259 return -ENOEXEC;
5260 }
5261
5262 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
5263
5264 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
5265 /* Init, or core PLT? */
5266 - if (location >= mod->module_core
5267 - && location < mod->module_core + mod->core_size)
5268 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5269 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5270 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5271 - else
5272 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5273 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5274 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5275 + else {
5276 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5277 + return ~0UL;
5278 + }
5279
5280 /* Find this entry, or if that fails, the next avail. entry */
5281 while (entry->jump[0]) {
5282 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5283 index ba48233..16ac31d 100644
5284 --- a/arch/powerpc/kernel/process.c
5285 +++ b/arch/powerpc/kernel/process.c
5286 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5287 * Lookup NIP late so we have the best change of getting the
5288 * above info out without failing
5289 */
5290 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5291 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5292 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5293 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5294 #endif
5295 show_stack(current, (unsigned long *) regs->gpr[1]);
5296 if (!user_mode(regs))
5297 @@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5298 newsp = stack[0];
5299 ip = stack[STACK_FRAME_LR_SAVE];
5300 if (!firstframe || ip != lr) {
5301 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5302 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5303 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5304 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5305 - printk(" (%pS)",
5306 + printk(" (%pA)",
5307 (void *)current->ret_stack[curr_frame].ret);
5308 curr_frame--;
5309 }
5310 @@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5311 struct pt_regs *regs = (struct pt_regs *)
5312 (sp + STACK_FRAME_OVERHEAD);
5313 lr = regs->link;
5314 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
5315 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
5316 regs->trap, (void *)regs->nip, (void *)lr);
5317 firstframe = 1;
5318 }
5319 @@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5320 mtspr(SPRN_CTRLT, ctrl);
5321 }
5322 #endif /* CONFIG_PPC64 */
5323 -
5324 -unsigned long arch_align_stack(unsigned long sp)
5325 -{
5326 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5327 - sp -= get_random_int() & ~PAGE_MASK;
5328 - return sp & ~0xf;
5329 -}
5330 -
5331 -static inline unsigned long brk_rnd(void)
5332 -{
5333 - unsigned long rnd = 0;
5334 -
5335 - /* 8MB for 32bit, 1GB for 64bit */
5336 - if (is_32bit_task())
5337 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5338 - else
5339 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5340 -
5341 - return rnd << PAGE_SHIFT;
5342 -}
5343 -
5344 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5345 -{
5346 - unsigned long base = mm->brk;
5347 - unsigned long ret;
5348 -
5349 -#ifdef CONFIG_PPC_STD_MMU_64
5350 - /*
5351 - * If we are using 1TB segments and we are allowed to randomise
5352 - * the heap, we can put it above 1TB so it is backed by a 1TB
5353 - * segment. Otherwise the heap will be in the bottom 1TB
5354 - * which always uses 256MB segments and this may result in a
5355 - * performance penalty.
5356 - */
5357 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5358 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5359 -#endif
5360 -
5361 - ret = PAGE_ALIGN(base + brk_rnd());
5362 -
5363 - if (ret < mm->brk)
5364 - return mm->brk;
5365 -
5366 - return ret;
5367 -}
5368 -
5369 -unsigned long randomize_et_dyn(unsigned long base)
5370 -{
5371 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5372 -
5373 - if (ret < base)
5374 - return base;
5375 -
5376 - return ret;
5377 -}
5378 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5379 index 79d8e56..38ffcbb 100644
5380 --- a/arch/powerpc/kernel/ptrace.c
5381 +++ b/arch/powerpc/kernel/ptrace.c
5382 @@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5383 return ret;
5384 }
5385
5386 +#ifdef CONFIG_GRKERNSEC_SETXID
5387 +extern void gr_delayed_cred_worker(void);
5388 +#endif
5389 +
5390 /*
5391 * We must return the syscall number to actually look up in the table.
5392 * This can be -1L to skip running any syscall at all.
5393 @@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5394
5395 secure_computing_strict(regs->gpr[0]);
5396
5397 +#ifdef CONFIG_GRKERNSEC_SETXID
5398 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5399 + gr_delayed_cred_worker();
5400 +#endif
5401 +
5402 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5403 tracehook_report_syscall_entry(regs))
5404 /*
5405 @@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5406 {
5407 int step;
5408
5409 +#ifdef CONFIG_GRKERNSEC_SETXID
5410 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5411 + gr_delayed_cred_worker();
5412 +#endif
5413 +
5414 audit_syscall_exit(regs);
5415
5416 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5417 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5418 index 804e323..79181c1 100644
5419 --- a/arch/powerpc/kernel/signal_32.c
5420 +++ b/arch/powerpc/kernel/signal_32.c
5421 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5422 /* Save user registers on the stack */
5423 frame = &rt_sf->uc.uc_mcontext;
5424 addr = frame;
5425 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5426 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5427 if (save_user_regs(regs, frame, 0, 1))
5428 goto badframe;
5429 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5430 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5431 index d183f87..1867f1a 100644
5432 --- a/arch/powerpc/kernel/signal_64.c
5433 +++ b/arch/powerpc/kernel/signal_64.c
5434 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5435 current->thread.fpscr.val = 0;
5436
5437 /* Set up to return from userspace. */
5438 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5439 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5440 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5441 } else {
5442 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5443 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5444 index 3251840..3f7c77a 100644
5445 --- a/arch/powerpc/kernel/traps.c
5446 +++ b/arch/powerpc/kernel/traps.c
5447 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5448 return flags;
5449 }
5450
5451 +extern void gr_handle_kernel_exploit(void);
5452 +
5453 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5454 int signr)
5455 {
5456 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5457 panic("Fatal exception in interrupt");
5458 if (panic_on_oops)
5459 panic("Fatal exception");
5460 +
5461 + gr_handle_kernel_exploit();
5462 +
5463 do_exit(signr);
5464 }
5465
5466 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5467 index 1b2076f..835e4be 100644
5468 --- a/arch/powerpc/kernel/vdso.c
5469 +++ b/arch/powerpc/kernel/vdso.c
5470 @@ -34,6 +34,7 @@
5471 #include <asm/firmware.h>
5472 #include <asm/vdso.h>
5473 #include <asm/vdso_datapage.h>
5474 +#include <asm/mman.h>
5475
5476 #include "setup.h"
5477
5478 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5479 vdso_base = VDSO32_MBASE;
5480 #endif
5481
5482 - current->mm->context.vdso_base = 0;
5483 + current->mm->context.vdso_base = ~0UL;
5484
5485 /* vDSO has a problem and was disabled, just don't "enable" it for the
5486 * process
5487 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5488 vdso_base = get_unmapped_area(NULL, vdso_base,
5489 (vdso_pages << PAGE_SHIFT) +
5490 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5491 - 0, 0);
5492 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
5493 if (IS_ERR_VALUE(vdso_base)) {
5494 rc = vdso_base;
5495 goto fail_mmapsem;
5496 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5497 index 5eea6f3..5d10396 100644
5498 --- a/arch/powerpc/lib/usercopy_64.c
5499 +++ b/arch/powerpc/lib/usercopy_64.c
5500 @@ -9,22 +9,6 @@
5501 #include <linux/module.h>
5502 #include <asm/uaccess.h>
5503
5504 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5505 -{
5506 - if (likely(access_ok(VERIFY_READ, from, n)))
5507 - n = __copy_from_user(to, from, n);
5508 - else
5509 - memset(to, 0, n);
5510 - return n;
5511 -}
5512 -
5513 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5514 -{
5515 - if (likely(access_ok(VERIFY_WRITE, to, n)))
5516 - n = __copy_to_user(to, from, n);
5517 - return n;
5518 -}
5519 -
5520 unsigned long copy_in_user(void __user *to, const void __user *from,
5521 unsigned long n)
5522 {
5523 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5524 return n;
5525 }
5526
5527 -EXPORT_SYMBOL(copy_from_user);
5528 -EXPORT_SYMBOL(copy_to_user);
5529 EXPORT_SYMBOL(copy_in_user);
5530
5531 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5532 index 0a6b283..7674925 100644
5533 --- a/arch/powerpc/mm/fault.c
5534 +++ b/arch/powerpc/mm/fault.c
5535 @@ -32,6 +32,10 @@
5536 #include <linux/perf_event.h>
5537 #include <linux/magic.h>
5538 #include <linux/ratelimit.h>
5539 +#include <linux/slab.h>
5540 +#include <linux/pagemap.h>
5541 +#include <linux/compiler.h>
5542 +#include <linux/unistd.h>
5543
5544 #include <asm/firmware.h>
5545 #include <asm/page.h>
5546 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5547 }
5548 #endif
5549
5550 +#ifdef CONFIG_PAX_PAGEEXEC
5551 +/*
5552 + * PaX: decide what to do with offenders (regs->nip = fault address)
5553 + *
5554 + * returns 1 when task should be killed
5555 + */
5556 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5557 +{
5558 + return 1;
5559 +}
5560 +
5561 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5562 +{
5563 + unsigned long i;
5564 +
5565 + printk(KERN_ERR "PAX: bytes at PC: ");
5566 + for (i = 0; i < 5; i++) {
5567 + unsigned int c;
5568 + if (get_user(c, (unsigned int __user *)pc+i))
5569 + printk(KERN_CONT "???????? ");
5570 + else
5571 + printk(KERN_CONT "%08x ", c);
5572 + }
5573 + printk("\n");
5574 +}
5575 +#endif
5576 +
5577 /*
5578 * Check whether the instruction at regs->nip is a store using
5579 * an update addressing form which will update r1.
5580 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5581 * indicate errors in DSISR but can validly be set in SRR1.
5582 */
5583 if (trap == 0x400)
5584 - error_code &= 0x48200000;
5585 + error_code &= 0x58200000;
5586 else
5587 is_write = error_code & DSISR_ISSTORE;
5588 #else
5589 @@ -367,7 +398,7 @@ good_area:
5590 * "undefined". Of those that can be set, this is the only
5591 * one which seems bad.
5592 */
5593 - if (error_code & 0x10000000)
5594 + if (error_code & DSISR_GUARDED)
5595 /* Guarded storage error. */
5596 goto bad_area;
5597 #endif /* CONFIG_8xx */
5598 @@ -382,7 +413,7 @@ good_area:
5599 * processors use the same I/D cache coherency mechanism
5600 * as embedded.
5601 */
5602 - if (error_code & DSISR_PROTFAULT)
5603 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5604 goto bad_area;
5605 #endif /* CONFIG_PPC_STD_MMU */
5606
5607 @@ -465,6 +496,23 @@ bad_area:
5608 bad_area_nosemaphore:
5609 /* User mode accesses cause a SIGSEGV */
5610 if (user_mode(regs)) {
5611 +
5612 +#ifdef CONFIG_PAX_PAGEEXEC
5613 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5614 +#ifdef CONFIG_PPC_STD_MMU
5615 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5616 +#else
5617 + if (is_exec && regs->nip == address) {
5618 +#endif
5619 + switch (pax_handle_fetch_fault(regs)) {
5620 + }
5621 +
5622 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5623 + do_group_exit(SIGKILL);
5624 + }
5625 + }
5626 +#endif
5627 +
5628 _exception(SIGSEGV, regs, code, address);
5629 return 0;
5630 }
5631 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5632 index 67a42ed..c16ef80 100644
5633 --- a/arch/powerpc/mm/mmap_64.c
5634 +++ b/arch/powerpc/mm/mmap_64.c
5635 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
5636 {
5637 unsigned long rnd = 0;
5638
5639 +#ifdef CONFIG_PAX_RANDMMAP
5640 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5641 +#endif
5642 +
5643 if (current->flags & PF_RANDOMIZE) {
5644 /* 8MB for 32bit, 1GB for 64bit */
5645 if (is_32bit_task())
5646 @@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5647 */
5648 if (mmap_is_legacy()) {
5649 mm->mmap_base = TASK_UNMAPPED_BASE;
5650 +
5651 +#ifdef CONFIG_PAX_RANDMMAP
5652 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5653 + mm->mmap_base += mm->delta_mmap;
5654 +#endif
5655 +
5656 mm->get_unmapped_area = arch_get_unmapped_area;
5657 mm->unmap_area = arch_unmap_area;
5658 } else {
5659 mm->mmap_base = mmap_base();
5660 +
5661 +#ifdef CONFIG_PAX_RANDMMAP
5662 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5663 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5664 +#endif
5665 +
5666 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5667 mm->unmap_area = arch_unmap_area_topdown;
5668 }
5669 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5670 index 5829d2a..af84242 100644
5671 --- a/arch/powerpc/mm/slice.c
5672 +++ b/arch/powerpc/mm/slice.c
5673 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5674 if ((mm->task_size - len) < addr)
5675 return 0;
5676 vma = find_vma(mm, addr);
5677 - return (!vma || (addr + len) <= vma->vm_start);
5678 + return check_heap_stack_gap(vma, addr, len, 0);
5679 }
5680
5681 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5682 @@ -272,7 +272,7 @@ full_search:
5683 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5684 continue;
5685 }
5686 - if (!vma || addr + len <= vma->vm_start) {
5687 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5688 /*
5689 * Remember the place where we stopped the search:
5690 */
5691 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5692 }
5693 }
5694
5695 - addr = mm->mmap_base;
5696 - while (addr > len) {
5697 + if (mm->mmap_base < len)
5698 + addr = -ENOMEM;
5699 + else
5700 + addr = mm->mmap_base - len;
5701 +
5702 + while (!IS_ERR_VALUE(addr)) {
5703 /* Go down by chunk size */
5704 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5705 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
5706
5707 /* Check for hit with different page size */
5708 mask = slice_range_to_mask(addr, len);
5709 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5710 * return with success:
5711 */
5712 vma = find_vma(mm, addr);
5713 - if (!vma || (addr + len) <= vma->vm_start) {
5714 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5715 /* remember the address as a hint for next time */
5716 if (use_cache)
5717 mm->free_area_cache = addr;
5718 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5719 mm->cached_hole_size = vma->vm_start - addr;
5720
5721 /* try just below the current vma->vm_start */
5722 - addr = vma->vm_start;
5723 + addr = skip_heap_stack_gap(vma, len, 0);
5724 }
5725
5726 /*
5727 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5728 if (fixed && addr > (mm->task_size - len))
5729 return -EINVAL;
5730
5731 +#ifdef CONFIG_PAX_RANDMMAP
5732 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5733 + addr = 0;
5734 +#endif
5735 +
5736 /* If hint, make sure it matches our alignment restrictions */
5737 if (!fixed && addr) {
5738 addr = _ALIGN_UP(addr, 1ul << pshift);
5739 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5740 index c797832..ce575c8 100644
5741 --- a/arch/s390/include/asm/atomic.h
5742 +++ b/arch/s390/include/asm/atomic.h
5743 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5744 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5745 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5746
5747 +#define atomic64_read_unchecked(v) atomic64_read(v)
5748 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5749 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5750 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5751 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5752 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5753 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5754 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5755 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5756 +
5757 #define smp_mb__before_atomic_dec() smp_mb()
5758 #define smp_mb__after_atomic_dec() smp_mb()
5759 #define smp_mb__before_atomic_inc() smp_mb()
5760 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5761 index 4d7ccac..d03d0ad 100644
5762 --- a/arch/s390/include/asm/cache.h
5763 +++ b/arch/s390/include/asm/cache.h
5764 @@ -9,8 +9,10 @@
5765 #ifndef __ARCH_S390_CACHE_H
5766 #define __ARCH_S390_CACHE_H
5767
5768 -#define L1_CACHE_BYTES 256
5769 +#include <linux/const.h>
5770 +
5771 #define L1_CACHE_SHIFT 8
5772 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5773 #define NET_SKB_PAD 32
5774
5775 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5776 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5777 index 178ff96..8c93bd1 100644
5778 --- a/arch/s390/include/asm/elf.h
5779 +++ b/arch/s390/include/asm/elf.h
5780 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5781 the loader. We need to make sure that it is out of the way of the program
5782 that it will "exec", and that there is sufficient room for the brk. */
5783
5784 -extern unsigned long randomize_et_dyn(unsigned long base);
5785 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5786 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5787 +
5788 +#ifdef CONFIG_PAX_ASLR
5789 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5790 +
5791 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5792 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5793 +#endif
5794
5795 /* This yields a mask that user programs can use to figure out what
5796 instruction set this CPU supports. */
5797 @@ -210,9 +216,6 @@ struct linux_binprm;
5798 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5799 int arch_setup_additional_pages(struct linux_binprm *, int);
5800
5801 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5802 -#define arch_randomize_brk arch_randomize_brk
5803 -
5804 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5805
5806 #endif
5807 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5808 index c4a93d6..4d2a9b4 100644
5809 --- a/arch/s390/include/asm/exec.h
5810 +++ b/arch/s390/include/asm/exec.h
5811 @@ -7,6 +7,6 @@
5812 #ifndef __ASM_EXEC_H
5813 #define __ASM_EXEC_H
5814
5815 -extern unsigned long arch_align_stack(unsigned long sp);
5816 +#define arch_align_stack(x) ((x) & ~0xfUL)
5817
5818 #endif /* __ASM_EXEC_H */
5819 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5820 index 34268df..ea97318 100644
5821 --- a/arch/s390/include/asm/uaccess.h
5822 +++ b/arch/s390/include/asm/uaccess.h
5823 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
5824 copy_to_user(void __user *to, const void *from, unsigned long n)
5825 {
5826 might_fault();
5827 +
5828 + if ((long)n < 0)
5829 + return n;
5830 +
5831 if (access_ok(VERIFY_WRITE, to, n))
5832 n = __copy_to_user(to, from, n);
5833 return n;
5834 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5835 static inline unsigned long __must_check
5836 __copy_from_user(void *to, const void __user *from, unsigned long n)
5837 {
5838 + if ((long)n < 0)
5839 + return n;
5840 +
5841 if (__builtin_constant_p(n) && (n <= 256))
5842 return uaccess.copy_from_user_small(n, from, to);
5843 else
5844 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5845 static inline unsigned long __must_check
5846 copy_from_user(void *to, const void __user *from, unsigned long n)
5847 {
5848 - unsigned int sz = __compiletime_object_size(to);
5849 + size_t sz = __compiletime_object_size(to);
5850
5851 might_fault();
5852 - if (unlikely(sz != -1 && sz < n)) {
5853 +
5854 + if ((long)n < 0)
5855 + return n;
5856 +
5857 + if (unlikely(sz != (size_t)-1 && sz < n)) {
5858 copy_from_user_overflow();
5859 return n;
5860 }
5861 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5862 index 4610dea..cf0af21 100644
5863 --- a/arch/s390/kernel/module.c
5864 +++ b/arch/s390/kernel/module.c
5865 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5866
5867 /* Increase core size by size of got & plt and set start
5868 offsets for got and plt. */
5869 - me->core_size = ALIGN(me->core_size, 4);
5870 - me->arch.got_offset = me->core_size;
5871 - me->core_size += me->arch.got_size;
5872 - me->arch.plt_offset = me->core_size;
5873 - me->core_size += me->arch.plt_size;
5874 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
5875 + me->arch.got_offset = me->core_size_rw;
5876 + me->core_size_rw += me->arch.got_size;
5877 + me->arch.plt_offset = me->core_size_rx;
5878 + me->core_size_rx += me->arch.plt_size;
5879 return 0;
5880 }
5881
5882 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5883 if (info->got_initialized == 0) {
5884 Elf_Addr *gotent;
5885
5886 - gotent = me->module_core + me->arch.got_offset +
5887 + gotent = me->module_core_rw + me->arch.got_offset +
5888 info->got_offset;
5889 *gotent = val;
5890 info->got_initialized = 1;
5891 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5892 else if (r_type == R_390_GOTENT ||
5893 r_type == R_390_GOTPLTENT)
5894 *(unsigned int *) loc =
5895 - (val + (Elf_Addr) me->module_core - loc) >> 1;
5896 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5897 else if (r_type == R_390_GOT64 ||
5898 r_type == R_390_GOTPLT64)
5899 *(unsigned long *) loc = val;
5900 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5901 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5902 if (info->plt_initialized == 0) {
5903 unsigned int *ip;
5904 - ip = me->module_core + me->arch.plt_offset +
5905 + ip = me->module_core_rx + me->arch.plt_offset +
5906 info->plt_offset;
5907 #ifndef CONFIG_64BIT
5908 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5909 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5910 val - loc + 0xffffUL < 0x1ffffeUL) ||
5911 (r_type == R_390_PLT32DBL &&
5912 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5913 - val = (Elf_Addr) me->module_core +
5914 + val = (Elf_Addr) me->module_core_rx +
5915 me->arch.plt_offset +
5916 info->plt_offset;
5917 val += rela->r_addend - loc;
5918 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5919 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5920 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5921 val = val + rela->r_addend -
5922 - ((Elf_Addr) me->module_core + me->arch.got_offset);
5923 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5924 if (r_type == R_390_GOTOFF16)
5925 *(unsigned short *) loc = val;
5926 else if (r_type == R_390_GOTOFF32)
5927 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5928 break;
5929 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5930 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5931 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
5932 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5933 rela->r_addend - loc;
5934 if (r_type == R_390_GOTPC)
5935 *(unsigned int *) loc = val;
5936 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5937 index cd31ad4..201c5a3 100644
5938 --- a/arch/s390/kernel/process.c
5939 +++ b/arch/s390/kernel/process.c
5940 @@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5941 }
5942 return 0;
5943 }
5944 -
5945 -unsigned long arch_align_stack(unsigned long sp)
5946 -{
5947 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5948 - sp -= get_random_int() & ~PAGE_MASK;
5949 - return sp & ~0xf;
5950 -}
5951 -
5952 -static inline unsigned long brk_rnd(void)
5953 -{
5954 - /* 8MB for 32bit, 1GB for 64bit */
5955 - if (is_32bit_task())
5956 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5957 - else
5958 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5959 -}
5960 -
5961 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5962 -{
5963 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5964 -
5965 - if (ret < mm->brk)
5966 - return mm->brk;
5967 - return ret;
5968 -}
5969 -
5970 -unsigned long randomize_et_dyn(unsigned long base)
5971 -{
5972 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5973 -
5974 - if (!(current->flags & PF_RANDOMIZE))
5975 - return base;
5976 - if (ret < base)
5977 - return base;
5978 - return ret;
5979 -}
5980 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5981 index c59a5ef..3fae59c 100644
5982 --- a/arch/s390/mm/mmap.c
5983 +++ b/arch/s390/mm/mmap.c
5984 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5985 */
5986 if (mmap_is_legacy()) {
5987 mm->mmap_base = TASK_UNMAPPED_BASE;
5988 +
5989 +#ifdef CONFIG_PAX_RANDMMAP
5990 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5991 + mm->mmap_base += mm->delta_mmap;
5992 +#endif
5993 +
5994 mm->get_unmapped_area = arch_get_unmapped_area;
5995 mm->unmap_area = arch_unmap_area;
5996 } else {
5997 mm->mmap_base = mmap_base();
5998 +
5999 +#ifdef CONFIG_PAX_RANDMMAP
6000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6001 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6002 +#endif
6003 +
6004 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6005 mm->unmap_area = arch_unmap_area_topdown;
6006 }
6007 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6008 */
6009 if (mmap_is_legacy()) {
6010 mm->mmap_base = TASK_UNMAPPED_BASE;
6011 +
6012 +#ifdef CONFIG_PAX_RANDMMAP
6013 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6014 + mm->mmap_base += mm->delta_mmap;
6015 +#endif
6016 +
6017 mm->get_unmapped_area = s390_get_unmapped_area;
6018 mm->unmap_area = arch_unmap_area;
6019 } else {
6020 mm->mmap_base = mmap_base();
6021 +
6022 +#ifdef CONFIG_PAX_RANDMMAP
6023 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6024 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6025 +#endif
6026 +
6027 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
6028 mm->unmap_area = arch_unmap_area_topdown;
6029 }
6030 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
6031 index ae3d59f..f65f075 100644
6032 --- a/arch/score/include/asm/cache.h
6033 +++ b/arch/score/include/asm/cache.h
6034 @@ -1,7 +1,9 @@
6035 #ifndef _ASM_SCORE_CACHE_H
6036 #define _ASM_SCORE_CACHE_H
6037
6038 +#include <linux/const.h>
6039 +
6040 #define L1_CACHE_SHIFT 4
6041 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6042 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6043
6044 #endif /* _ASM_SCORE_CACHE_H */
6045 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
6046 index f9f3cd5..58ff438 100644
6047 --- a/arch/score/include/asm/exec.h
6048 +++ b/arch/score/include/asm/exec.h
6049 @@ -1,6 +1,6 @@
6050 #ifndef _ASM_SCORE_EXEC_H
6051 #define _ASM_SCORE_EXEC_H
6052
6053 -extern unsigned long arch_align_stack(unsigned long sp);
6054 +#define arch_align_stack(x) (x)
6055
6056 #endif /* _ASM_SCORE_EXEC_H */
6057 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
6058 index 637970c..0b6556b 100644
6059 --- a/arch/score/kernel/process.c
6060 +++ b/arch/score/kernel/process.c
6061 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
6062
6063 return task_pt_regs(task)->cp0_epc;
6064 }
6065 -
6066 -unsigned long arch_align_stack(unsigned long sp)
6067 -{
6068 - return sp;
6069 -}
6070 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
6071 index ef9e555..331bd29 100644
6072 --- a/arch/sh/include/asm/cache.h
6073 +++ b/arch/sh/include/asm/cache.h
6074 @@ -9,10 +9,11 @@
6075 #define __ASM_SH_CACHE_H
6076 #ifdef __KERNEL__
6077
6078 +#include <linux/const.h>
6079 #include <linux/init.h>
6080 #include <cpu/cache.h>
6081
6082 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6083 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6084
6085 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6086
6087 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
6088 index afeb710..e8366ef 100644
6089 --- a/arch/sh/mm/mmap.c
6090 +++ b/arch/sh/mm/mmap.c
6091 @@ -49,6 +49,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6092 struct vm_area_struct *vma;
6093 unsigned long start_addr;
6094 int do_colour_align;
6095 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6096
6097 if (flags & MAP_FIXED) {
6098 /* We do not accept a shared mapping if it would violate
6099 @@ -74,8 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6100 addr = PAGE_ALIGN(addr);
6101
6102 vma = find_vma(mm, addr);
6103 - if (TASK_SIZE - len >= addr &&
6104 - (!vma || addr + len <= vma->vm_start))
6105 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6106 return addr;
6107 }
6108
6109 @@ -106,7 +106,7 @@ full_search:
6110 }
6111 return -ENOMEM;
6112 }
6113 - if (likely(!vma || addr + len <= vma->vm_start)) {
6114 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6115 /*
6116 * Remember the place where we stopped the search:
6117 */
6118 @@ -131,6 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6119 struct mm_struct *mm = current->mm;
6120 unsigned long addr = addr0;
6121 int do_colour_align;
6122 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6123
6124 if (flags & MAP_FIXED) {
6125 /* We do not accept a shared mapping if it would violate
6126 @@ -157,8 +158,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6127 addr = PAGE_ALIGN(addr);
6128
6129 vma = find_vma(mm, addr);
6130 - if (TASK_SIZE - len >= addr &&
6131 - (!vma || addr + len <= vma->vm_start))
6132 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6133 return addr;
6134 }
6135
6136 @@ -179,7 +179,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6137 /* make sure it can fit in the remaining address space */
6138 if (likely(addr > len)) {
6139 vma = find_vma(mm, addr-len);
6140 - if (!vma || addr <= vma->vm_start) {
6141 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6142 /* remember the address as a hint for next time */
6143 return (mm->free_area_cache = addr-len);
6144 }
6145 @@ -188,18 +188,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6146 if (unlikely(mm->mmap_base < len))
6147 goto bottomup;
6148
6149 - addr = mm->mmap_base-len;
6150 - if (do_colour_align)
6151 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6152 + addr = mm->mmap_base - len;
6153
6154 do {
6155 + if (do_colour_align)
6156 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6157 /*
6158 * Lookup failure means no vma is above this address,
6159 * else if new region fits below vma->vm_start,
6160 * return with success:
6161 */
6162 vma = find_vma(mm, addr);
6163 - if (likely(!vma || addr+len <= vma->vm_start)) {
6164 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6165 /* remember the address as a hint for next time */
6166 return (mm->free_area_cache = addr);
6167 }
6168 @@ -209,10 +209,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6169 mm->cached_hole_size = vma->vm_start - addr;
6170
6171 /* try just below the current vma->vm_start */
6172 - addr = vma->vm_start-len;
6173 - if (do_colour_align)
6174 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6175 - } while (likely(len < vma->vm_start));
6176 + addr = skip_heap_stack_gap(vma, len, offset);
6177 + } while (!IS_ERR_VALUE(addr));
6178
6179 bottomup:
6180 /*
6181 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
6182 index be56a24..443328f 100644
6183 --- a/arch/sparc/include/asm/atomic_64.h
6184 +++ b/arch/sparc/include/asm/atomic_64.h
6185 @@ -14,18 +14,40 @@
6186 #define ATOMIC64_INIT(i) { (i) }
6187
6188 #define atomic_read(v) (*(volatile int *)&(v)->counter)
6189 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6190 +{
6191 + return v->counter;
6192 +}
6193 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
6194 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6195 +{
6196 + return v->counter;
6197 +}
6198
6199 #define atomic_set(v, i) (((v)->counter) = i)
6200 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6201 +{
6202 + v->counter = i;
6203 +}
6204 #define atomic64_set(v, i) (((v)->counter) = i)
6205 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6206 +{
6207 + v->counter = i;
6208 +}
6209
6210 extern void atomic_add(int, atomic_t *);
6211 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
6212 extern void atomic64_add(long, atomic64_t *);
6213 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
6214 extern void atomic_sub(int, atomic_t *);
6215 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
6216 extern void atomic64_sub(long, atomic64_t *);
6217 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
6218
6219 extern int atomic_add_ret(int, atomic_t *);
6220 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
6221 extern long atomic64_add_ret(long, atomic64_t *);
6222 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
6223 extern int atomic_sub_ret(int, atomic_t *);
6224 extern long atomic64_sub_ret(long, atomic64_t *);
6225
6226 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6227 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
6228
6229 #define atomic_inc_return(v) atomic_add_ret(1, v)
6230 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6231 +{
6232 + return atomic_add_ret_unchecked(1, v);
6233 +}
6234 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
6235 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6236 +{
6237 + return atomic64_add_ret_unchecked(1, v);
6238 +}
6239
6240 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
6241 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
6242
6243 #define atomic_add_return(i, v) atomic_add_ret(i, v)
6244 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6245 +{
6246 + return atomic_add_ret_unchecked(i, v);
6247 +}
6248 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
6249 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6250 +{
6251 + return atomic64_add_ret_unchecked(i, v);
6252 +}
6253
6254 /*
6255 * atomic_inc_and_test - increment and test
6256 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6257 * other cases.
6258 */
6259 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6260 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6261 +{
6262 + return atomic_inc_return_unchecked(v) == 0;
6263 +}
6264 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6265
6266 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
6267 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6268 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
6269
6270 #define atomic_inc(v) atomic_add(1, v)
6271 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6272 +{
6273 + atomic_add_unchecked(1, v);
6274 +}
6275 #define atomic64_inc(v) atomic64_add(1, v)
6276 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6277 +{
6278 + atomic64_add_unchecked(1, v);
6279 +}
6280
6281 #define atomic_dec(v) atomic_sub(1, v)
6282 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6283 +{
6284 + atomic_sub_unchecked(1, v);
6285 +}
6286 #define atomic64_dec(v) atomic64_sub(1, v)
6287 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6288 +{
6289 + atomic64_sub_unchecked(1, v);
6290 +}
6291
6292 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
6293 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
6294
6295 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6296 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6297 +{
6298 + return cmpxchg(&v->counter, old, new);
6299 +}
6300 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6301 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6302 +{
6303 + return xchg(&v->counter, new);
6304 +}
6305
6306 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6307 {
6308 - int c, old;
6309 + int c, old, new;
6310 c = atomic_read(v);
6311 for (;;) {
6312 - if (unlikely(c == (u)))
6313 + if (unlikely(c == u))
6314 break;
6315 - old = atomic_cmpxchg((v), c, c + (a));
6316 +
6317 + asm volatile("addcc %2, %0, %0\n"
6318 +
6319 +#ifdef CONFIG_PAX_REFCOUNT
6320 + "tvs %%icc, 6\n"
6321 +#endif
6322 +
6323 + : "=r" (new)
6324 + : "0" (c), "ir" (a)
6325 + : "cc");
6326 +
6327 + old = atomic_cmpxchg(v, c, new);
6328 if (likely(old == c))
6329 break;
6330 c = old;
6331 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6332 #define atomic64_cmpxchg(v, o, n) \
6333 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6334 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6335 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6336 +{
6337 + return xchg(&v->counter, new);
6338 +}
6339
6340 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6341 {
6342 - long c, old;
6343 + long c, old, new;
6344 c = atomic64_read(v);
6345 for (;;) {
6346 - if (unlikely(c == (u)))
6347 + if (unlikely(c == u))
6348 break;
6349 - old = atomic64_cmpxchg((v), c, c + (a));
6350 +
6351 + asm volatile("addcc %2, %0, %0\n"
6352 +
6353 +#ifdef CONFIG_PAX_REFCOUNT
6354 + "tvs %%xcc, 6\n"
6355 +#endif
6356 +
6357 + : "=r" (new)
6358 + : "0" (c), "ir" (a)
6359 + : "cc");
6360 +
6361 + old = atomic64_cmpxchg(v, c, new);
6362 if (likely(old == c))
6363 break;
6364 c = old;
6365 }
6366 - return c != (u);
6367 + return c != u;
6368 }
6369
6370 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6371 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6372 index 5bb6991..5c2132e 100644
6373 --- a/arch/sparc/include/asm/cache.h
6374 +++ b/arch/sparc/include/asm/cache.h
6375 @@ -7,10 +7,12 @@
6376 #ifndef _SPARC_CACHE_H
6377 #define _SPARC_CACHE_H
6378
6379 +#include <linux/const.h>
6380 +
6381 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6382
6383 #define L1_CACHE_SHIFT 5
6384 -#define L1_CACHE_BYTES 32
6385 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6386
6387 #ifdef CONFIG_SPARC32
6388 #define SMP_CACHE_BYTES_SHIFT 5
6389 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6390 index ac74a2c..a9e58af 100644
6391 --- a/arch/sparc/include/asm/elf_32.h
6392 +++ b/arch/sparc/include/asm/elf_32.h
6393 @@ -114,6 +114,13 @@ typedef struct {
6394
6395 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6396
6397 +#ifdef CONFIG_PAX_ASLR
6398 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
6399 +
6400 +#define PAX_DELTA_MMAP_LEN 16
6401 +#define PAX_DELTA_STACK_LEN 16
6402 +#endif
6403 +
6404 /* This yields a mask that user programs can use to figure out what
6405 instruction set this cpu supports. This can NOT be done in userspace
6406 on Sparc. */
6407 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6408 index 370ca1e..d4f4a98 100644
6409 --- a/arch/sparc/include/asm/elf_64.h
6410 +++ b/arch/sparc/include/asm/elf_64.h
6411 @@ -189,6 +189,13 @@ typedef struct {
6412 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6413 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6414
6415 +#ifdef CONFIG_PAX_ASLR
6416 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6417 +
6418 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6419 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6420 +#endif
6421 +
6422 extern unsigned long sparc64_elf_hwcap;
6423 #define ELF_HWCAP sparc64_elf_hwcap
6424
6425 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6426 index 9b1c36d..209298b 100644
6427 --- a/arch/sparc/include/asm/pgalloc_32.h
6428 +++ b/arch/sparc/include/asm/pgalloc_32.h
6429 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6430 }
6431
6432 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6433 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6434
6435 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6436 unsigned long address)
6437 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6438 index bcfe063..b333142 100644
6439 --- a/arch/sparc/include/asm/pgalloc_64.h
6440 +++ b/arch/sparc/include/asm/pgalloc_64.h
6441 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6442 }
6443
6444 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6445 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6446
6447 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6448 {
6449 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6450 index 6fc1348..390c50a 100644
6451 --- a/arch/sparc/include/asm/pgtable_32.h
6452 +++ b/arch/sparc/include/asm/pgtable_32.h
6453 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6454 #define PAGE_SHARED SRMMU_PAGE_SHARED
6455 #define PAGE_COPY SRMMU_PAGE_COPY
6456 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6457 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6458 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6459 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6460 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6461
6462 /* Top-level page directory - dummy used by init-mm.
6463 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6464
6465 /* xwr */
6466 #define __P000 PAGE_NONE
6467 -#define __P001 PAGE_READONLY
6468 -#define __P010 PAGE_COPY
6469 -#define __P011 PAGE_COPY
6470 +#define __P001 PAGE_READONLY_NOEXEC
6471 +#define __P010 PAGE_COPY_NOEXEC
6472 +#define __P011 PAGE_COPY_NOEXEC
6473 #define __P100 PAGE_READONLY
6474 #define __P101 PAGE_READONLY
6475 #define __P110 PAGE_COPY
6476 #define __P111 PAGE_COPY
6477
6478 #define __S000 PAGE_NONE
6479 -#define __S001 PAGE_READONLY
6480 -#define __S010 PAGE_SHARED
6481 -#define __S011 PAGE_SHARED
6482 +#define __S001 PAGE_READONLY_NOEXEC
6483 +#define __S010 PAGE_SHARED_NOEXEC
6484 +#define __S011 PAGE_SHARED_NOEXEC
6485 #define __S100 PAGE_READONLY
6486 #define __S101 PAGE_READONLY
6487 #define __S110 PAGE_SHARED
6488 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6489 index 79da178..c2eede8 100644
6490 --- a/arch/sparc/include/asm/pgtsrmmu.h
6491 +++ b/arch/sparc/include/asm/pgtsrmmu.h
6492 @@ -115,6 +115,11 @@
6493 SRMMU_EXEC | SRMMU_REF)
6494 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6495 SRMMU_EXEC | SRMMU_REF)
6496 +
6497 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6498 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6499 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6500 +
6501 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6502 SRMMU_DIRTY | SRMMU_REF)
6503
6504 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6505 index 9689176..63c18ea 100644
6506 --- a/arch/sparc/include/asm/spinlock_64.h
6507 +++ b/arch/sparc/include/asm/spinlock_64.h
6508 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6509
6510 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6511
6512 -static void inline arch_read_lock(arch_rwlock_t *lock)
6513 +static inline void arch_read_lock(arch_rwlock_t *lock)
6514 {
6515 unsigned long tmp1, tmp2;
6516
6517 __asm__ __volatile__ (
6518 "1: ldsw [%2], %0\n"
6519 " brlz,pn %0, 2f\n"
6520 -"4: add %0, 1, %1\n"
6521 +"4: addcc %0, 1, %1\n"
6522 +
6523 +#ifdef CONFIG_PAX_REFCOUNT
6524 +" tvs %%icc, 6\n"
6525 +#endif
6526 +
6527 " cas [%2], %0, %1\n"
6528 " cmp %0, %1\n"
6529 " bne,pn %%icc, 1b\n"
6530 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6531 " .previous"
6532 : "=&r" (tmp1), "=&r" (tmp2)
6533 : "r" (lock)
6534 - : "memory");
6535 + : "memory", "cc");
6536 }
6537
6538 -static int inline arch_read_trylock(arch_rwlock_t *lock)
6539 +static inline int arch_read_trylock(arch_rwlock_t *lock)
6540 {
6541 int tmp1, tmp2;
6542
6543 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6544 "1: ldsw [%2], %0\n"
6545 " brlz,a,pn %0, 2f\n"
6546 " mov 0, %0\n"
6547 -" add %0, 1, %1\n"
6548 +" addcc %0, 1, %1\n"
6549 +
6550 +#ifdef CONFIG_PAX_REFCOUNT
6551 +" tvs %%icc, 6\n"
6552 +#endif
6553 +
6554 " cas [%2], %0, %1\n"
6555 " cmp %0, %1\n"
6556 " bne,pn %%icc, 1b\n"
6557 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6558 return tmp1;
6559 }
6560
6561 -static void inline arch_read_unlock(arch_rwlock_t *lock)
6562 +static inline void arch_read_unlock(arch_rwlock_t *lock)
6563 {
6564 unsigned long tmp1, tmp2;
6565
6566 __asm__ __volatile__(
6567 "1: lduw [%2], %0\n"
6568 -" sub %0, 1, %1\n"
6569 +" subcc %0, 1, %1\n"
6570 +
6571 +#ifdef CONFIG_PAX_REFCOUNT
6572 +" tvs %%icc, 6\n"
6573 +#endif
6574 +
6575 " cas [%2], %0, %1\n"
6576 " cmp %0, %1\n"
6577 " bne,pn %%xcc, 1b\n"
6578 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6579 : "memory");
6580 }
6581
6582 -static void inline arch_write_lock(arch_rwlock_t *lock)
6583 +static inline void arch_write_lock(arch_rwlock_t *lock)
6584 {
6585 unsigned long mask, tmp1, tmp2;
6586
6587 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6588 : "memory");
6589 }
6590
6591 -static void inline arch_write_unlock(arch_rwlock_t *lock)
6592 +static inline void arch_write_unlock(arch_rwlock_t *lock)
6593 {
6594 __asm__ __volatile__(
6595 " stw %%g0, [%0]"
6596 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6597 : "memory");
6598 }
6599
6600 -static int inline arch_write_trylock(arch_rwlock_t *lock)
6601 +static inline int arch_write_trylock(arch_rwlock_t *lock)
6602 {
6603 unsigned long mask, tmp1, tmp2, result;
6604
6605 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6606 index 25849ae..924c54b 100644
6607 --- a/arch/sparc/include/asm/thread_info_32.h
6608 +++ b/arch/sparc/include/asm/thread_info_32.h
6609 @@ -49,6 +49,8 @@ struct thread_info {
6610 unsigned long w_saved;
6611
6612 struct restart_block restart_block;
6613 +
6614 + unsigned long lowest_stack;
6615 };
6616
6617 /*
6618 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6619 index a3fe4dc..cae132a 100644
6620 --- a/arch/sparc/include/asm/thread_info_64.h
6621 +++ b/arch/sparc/include/asm/thread_info_64.h
6622 @@ -63,6 +63,8 @@ struct thread_info {
6623 struct pt_regs *kern_una_regs;
6624 unsigned int kern_una_insn;
6625
6626 + unsigned long lowest_stack;
6627 +
6628 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6629 };
6630
6631 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6632 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6633 /* flag bit 6 is available */
6634 #define TIF_32BIT 7 /* 32-bit binary */
6635 -/* flag bit 8 is available */
6636 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6637 #define TIF_SECCOMP 9 /* secure computing */
6638 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6639 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6640 +
6641 /* NOTE: Thread flags >= 12 should be ones we have no interest
6642 * in using in assembly, else we can't use the mask as
6643 * an immediate value in instructions such as andcc.
6644 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6645 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6646 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6647 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6648 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6649
6650 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6651 _TIF_DO_NOTIFY_RESUME_MASK | \
6652 _TIF_NEED_RESCHED)
6653 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6654
6655 +#define _TIF_WORK_SYSCALL \
6656 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6657 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6658 +
6659 +
6660 /*
6661 * Thread-synchronous status.
6662 *
6663 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6664 index 0167d26..9acd8ed 100644
6665 --- a/arch/sparc/include/asm/uaccess.h
6666 +++ b/arch/sparc/include/asm/uaccess.h
6667 @@ -1,5 +1,13 @@
6668 #ifndef ___ASM_SPARC_UACCESS_H
6669 #define ___ASM_SPARC_UACCESS_H
6670 +
6671 +#ifdef __KERNEL__
6672 +#ifndef __ASSEMBLY__
6673 +#include <linux/types.h>
6674 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6675 +#endif
6676 +#endif
6677 +
6678 #if defined(__sparc__) && defined(__arch64__)
6679 #include <asm/uaccess_64.h>
6680 #else
6681 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6682 index 53a28dd..50c38c3 100644
6683 --- a/arch/sparc/include/asm/uaccess_32.h
6684 +++ b/arch/sparc/include/asm/uaccess_32.h
6685 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6686
6687 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6688 {
6689 - if (n && __access_ok((unsigned long) to, n))
6690 + if ((long)n < 0)
6691 + return n;
6692 +
6693 + if (n && __access_ok((unsigned long) to, n)) {
6694 + if (!__builtin_constant_p(n))
6695 + check_object_size(from, n, true);
6696 return __copy_user(to, (__force void __user *) from, n);
6697 - else
6698 + } else
6699 return n;
6700 }
6701
6702 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6703 {
6704 + if ((long)n < 0)
6705 + return n;
6706 +
6707 + if (!__builtin_constant_p(n))
6708 + check_object_size(from, n, true);
6709 +
6710 return __copy_user(to, (__force void __user *) from, n);
6711 }
6712
6713 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6714 {
6715 - if (n && __access_ok((unsigned long) from, n))
6716 + if ((long)n < 0)
6717 + return n;
6718 +
6719 + if (n && __access_ok((unsigned long) from, n)) {
6720 + if (!__builtin_constant_p(n))
6721 + check_object_size(to, n, false);
6722 return __copy_user((__force void __user *) to, from, n);
6723 - else
6724 + } else
6725 return n;
6726 }
6727
6728 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6729 {
6730 + if ((long)n < 0)
6731 + return n;
6732 +
6733 return __copy_user((__force void __user *) to, from, n);
6734 }
6735
6736 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6737 index 73083e1..2bc62a6 100644
6738 --- a/arch/sparc/include/asm/uaccess_64.h
6739 +++ b/arch/sparc/include/asm/uaccess_64.h
6740 @@ -10,6 +10,7 @@
6741 #include <linux/compiler.h>
6742 #include <linux/string.h>
6743 #include <linux/thread_info.h>
6744 +#include <linux/kernel.h>
6745 #include <asm/asi.h>
6746 #include <asm/spitfire.h>
6747 #include <asm-generic/uaccess-unaligned.h>
6748 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6749 static inline unsigned long __must_check
6750 copy_from_user(void *to, const void __user *from, unsigned long size)
6751 {
6752 - unsigned long ret = ___copy_from_user(to, from, size);
6753 + unsigned long ret;
6754
6755 + if ((long)size < 0 || size > INT_MAX)
6756 + return size;
6757 +
6758 + if (!__builtin_constant_p(size))
6759 + check_object_size(to, size, false);
6760 +
6761 + ret = ___copy_from_user(to, from, size);
6762 if (unlikely(ret))
6763 ret = copy_from_user_fixup(to, from, size);
6764
6765 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6766 static inline unsigned long __must_check
6767 copy_to_user(void __user *to, const void *from, unsigned long size)
6768 {
6769 - unsigned long ret = ___copy_to_user(to, from, size);
6770 + unsigned long ret;
6771
6772 + if ((long)size < 0 || size > INT_MAX)
6773 + return size;
6774 +
6775 + if (!__builtin_constant_p(size))
6776 + check_object_size(from, size, true);
6777 +
6778 + ret = ___copy_to_user(to, from, size);
6779 if (unlikely(ret))
6780 ret = copy_to_user_fixup(to, from, size);
6781 return ret;
6782 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6783 index 6cf591b..b49e65a 100644
6784 --- a/arch/sparc/kernel/Makefile
6785 +++ b/arch/sparc/kernel/Makefile
6786 @@ -3,7 +3,7 @@
6787 #
6788
6789 asflags-y := -ansi
6790 -ccflags-y := -Werror
6791 +#ccflags-y := -Werror
6792
6793 extra-y := head_$(BITS).o
6794
6795 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6796 index 487bffb..955a925 100644
6797 --- a/arch/sparc/kernel/process_32.c
6798 +++ b/arch/sparc/kernel/process_32.c
6799 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6800
6801 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6802 r->psr, r->pc, r->npc, r->y, print_tainted());
6803 - printk("PC: <%pS>\n", (void *) r->pc);
6804 + printk("PC: <%pA>\n", (void *) r->pc);
6805 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6806 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6807 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6808 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6809 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6810 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6811 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6812 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6813
6814 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6815 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6816 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6817 rw = (struct reg_window32 *) fp;
6818 pc = rw->ins[7];
6819 printk("[%08lx : ", pc);
6820 - printk("%pS ] ", (void *) pc);
6821 + printk("%pA ] ", (void *) pc);
6822 fp = rw->ins[6];
6823 } while (++count < 16);
6824 printk("\n");
6825 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6826 index c6e0c29..052832b 100644
6827 --- a/arch/sparc/kernel/process_64.c
6828 +++ b/arch/sparc/kernel/process_64.c
6829 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6830 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6831 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6832 if (regs->tstate & TSTATE_PRIV)
6833 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6834 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6835 }
6836
6837 void show_regs(struct pt_regs *regs)
6838 {
6839 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6840 regs->tpc, regs->tnpc, regs->y, print_tainted());
6841 - printk("TPC: <%pS>\n", (void *) regs->tpc);
6842 + printk("TPC: <%pA>\n", (void *) regs->tpc);
6843 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6844 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6845 regs->u_regs[3]);
6846 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6847 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6848 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6849 regs->u_regs[15]);
6850 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6851 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6852 show_regwindow(regs);
6853 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6854 }
6855 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6856 ((tp && tp->task) ? tp->task->pid : -1));
6857
6858 if (gp->tstate & TSTATE_PRIV) {
6859 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6860 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6861 (void *) gp->tpc,
6862 (void *) gp->o7,
6863 (void *) gp->i7,
6864 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6865 index 7ff45e4..a58f271 100644
6866 --- a/arch/sparc/kernel/ptrace_64.c
6867 +++ b/arch/sparc/kernel/ptrace_64.c
6868 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6869 return ret;
6870 }
6871
6872 +#ifdef CONFIG_GRKERNSEC_SETXID
6873 +extern void gr_delayed_cred_worker(void);
6874 +#endif
6875 +
6876 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6877 {
6878 int ret = 0;
6879 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6880 /* do the secure computing check first */
6881 secure_computing_strict(regs->u_regs[UREG_G1]);
6882
6883 +#ifdef CONFIG_GRKERNSEC_SETXID
6884 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6885 + gr_delayed_cred_worker();
6886 +#endif
6887 +
6888 if (test_thread_flag(TIF_SYSCALL_TRACE))
6889 ret = tracehook_report_syscall_entry(regs);
6890
6891 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6892
6893 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6894 {
6895 +#ifdef CONFIG_GRKERNSEC_SETXID
6896 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6897 + gr_delayed_cred_worker();
6898 +#endif
6899 +
6900 audit_syscall_exit(regs);
6901
6902 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6903 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6904 index 0c9b31b..55a8ba6 100644
6905 --- a/arch/sparc/kernel/sys_sparc_32.c
6906 +++ b/arch/sparc/kernel/sys_sparc_32.c
6907 @@ -39,6 +39,7 @@ asmlinkage unsigned long sys_getpagesize(void)
6908 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6909 {
6910 struct vm_area_struct * vmm;
6911 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6912
6913 if (flags & MAP_FIXED) {
6914 /* We do not accept a shared mapping if it would violate
6915 @@ -54,7 +55,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6916 if (len > TASK_SIZE - PAGE_SIZE)
6917 return -ENOMEM;
6918 if (!addr)
6919 - addr = TASK_UNMAPPED_BASE;
6920 + addr = current->mm->mmap_base;
6921
6922 if (flags & MAP_SHARED)
6923 addr = COLOUR_ALIGN(addr);
6924 @@ -65,7 +66,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6925 /* At this point: (!vmm || addr < vmm->vm_end). */
6926 if (TASK_SIZE - PAGE_SIZE - len < addr)
6927 return -ENOMEM;
6928 - if (!vmm || addr + len <= vmm->vm_start)
6929 + if (check_heap_stack_gap(vmm, addr, len, offset))
6930 return addr;
6931 addr = vmm->vm_end;
6932 if (flags & MAP_SHARED)
6933 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6934 index 878ef3d..f100719 100644
6935 --- a/arch/sparc/kernel/sys_sparc_64.c
6936 +++ b/arch/sparc/kernel/sys_sparc_64.c
6937 @@ -102,12 +102,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6938 unsigned long task_size = TASK_SIZE;
6939 unsigned long start_addr;
6940 int do_color_align;
6941 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6942
6943 if (flags & MAP_FIXED) {
6944 /* We do not accept a shared mapping if it would violate
6945 * cache aliasing constraints.
6946 */
6947 - if ((flags & MAP_SHARED) &&
6948 + if ((filp || (flags & MAP_SHARED)) &&
6949 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6950 return -EINVAL;
6951 return addr;
6952 @@ -122,6 +123,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6953 if (filp || (flags & MAP_SHARED))
6954 do_color_align = 1;
6955
6956 +#ifdef CONFIG_PAX_RANDMMAP
6957 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6958 +#endif
6959 +
6960 if (addr) {
6961 if (do_color_align)
6962 addr = COLOUR_ALIGN(addr, pgoff);
6963 @@ -129,15 +134,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6964 addr = PAGE_ALIGN(addr);
6965
6966 vma = find_vma(mm, addr);
6967 - if (task_size - len >= addr &&
6968 - (!vma || addr + len <= vma->vm_start))
6969 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6970 return addr;
6971 }
6972
6973 if (len > mm->cached_hole_size) {
6974 - start_addr = addr = mm->free_area_cache;
6975 + start_addr = addr = mm->free_area_cache;
6976 } else {
6977 - start_addr = addr = TASK_UNMAPPED_BASE;
6978 + start_addr = addr = mm->mmap_base;
6979 mm->cached_hole_size = 0;
6980 }
6981
6982 @@ -157,14 +161,14 @@ full_search:
6983 vma = find_vma(mm, VA_EXCLUDE_END);
6984 }
6985 if (unlikely(task_size < addr)) {
6986 - if (start_addr != TASK_UNMAPPED_BASE) {
6987 - start_addr = addr = TASK_UNMAPPED_BASE;
6988 + if (start_addr != mm->mmap_base) {
6989 + start_addr = addr = mm->mmap_base;
6990 mm->cached_hole_size = 0;
6991 goto full_search;
6992 }
6993 return -ENOMEM;
6994 }
6995 - if (likely(!vma || addr + len <= vma->vm_start)) {
6996 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6997 /*
6998 * Remember the place where we stopped the search:
6999 */
7000 @@ -190,6 +194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7001 unsigned long task_size = STACK_TOP32;
7002 unsigned long addr = addr0;
7003 int do_color_align;
7004 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7005
7006 /* This should only ever run for 32-bit processes. */
7007 BUG_ON(!test_thread_flag(TIF_32BIT));
7008 @@ -198,7 +203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7009 /* We do not accept a shared mapping if it would violate
7010 * cache aliasing constraints.
7011 */
7012 - if ((flags & MAP_SHARED) &&
7013 + if ((filp || (flags & MAP_SHARED)) &&
7014 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
7015 return -EINVAL;
7016 return addr;
7017 @@ -219,8 +224,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7018 addr = PAGE_ALIGN(addr);
7019
7020 vma = find_vma(mm, addr);
7021 - if (task_size - len >= addr &&
7022 - (!vma || addr + len <= vma->vm_start))
7023 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7024 return addr;
7025 }
7026
7027 @@ -241,7 +245,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7028 /* make sure it can fit in the remaining address space */
7029 if (likely(addr > len)) {
7030 vma = find_vma(mm, addr-len);
7031 - if (!vma || addr <= vma->vm_start) {
7032 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
7033 /* remember the address as a hint for next time */
7034 return (mm->free_area_cache = addr-len);
7035 }
7036 @@ -250,18 +254,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7037 if (unlikely(mm->mmap_base < len))
7038 goto bottomup;
7039
7040 - addr = mm->mmap_base-len;
7041 - if (do_color_align)
7042 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7043 + addr = mm->mmap_base - len;
7044
7045 do {
7046 + if (do_color_align)
7047 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7048 /*
7049 * Lookup failure means no vma is above this address,
7050 * else if new region fits below vma->vm_start,
7051 * return with success:
7052 */
7053 vma = find_vma(mm, addr);
7054 - if (likely(!vma || addr+len <= vma->vm_start)) {
7055 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
7056 /* remember the address as a hint for next time */
7057 return (mm->free_area_cache = addr);
7058 }
7059 @@ -271,10 +275,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7060 mm->cached_hole_size = vma->vm_start - addr;
7061
7062 /* try just below the current vma->vm_start */
7063 - addr = vma->vm_start-len;
7064 - if (do_color_align)
7065 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7066 - } while (likely(len < vma->vm_start));
7067 + addr = skip_heap_stack_gap(vma, len, offset);
7068 + } while (!IS_ERR_VALUE(addr));
7069
7070 bottomup:
7071 /*
7072 @@ -348,6 +350,10 @@ static unsigned long mmap_rnd(void)
7073 {
7074 unsigned long rnd = 0UL;
7075
7076 +#ifdef CONFIG_PAX_RANDMMAP
7077 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7078 +#endif
7079 +
7080 if (current->flags & PF_RANDOMIZE) {
7081 unsigned long val = get_random_int();
7082 if (test_thread_flag(TIF_32BIT))
7083 @@ -373,6 +379,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7084 gap == RLIM_INFINITY ||
7085 sysctl_legacy_va_layout) {
7086 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7087 +
7088 +#ifdef CONFIG_PAX_RANDMMAP
7089 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7090 + mm->mmap_base += mm->delta_mmap;
7091 +#endif
7092 +
7093 mm->get_unmapped_area = arch_get_unmapped_area;
7094 mm->unmap_area = arch_unmap_area;
7095 } else {
7096 @@ -385,6 +397,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7097 gap = (task_size / 6 * 5);
7098
7099 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
7100 +
7101 +#ifdef CONFIG_PAX_RANDMMAP
7102 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7103 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7104 +#endif
7105 +
7106 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7107 mm->unmap_area = arch_unmap_area_topdown;
7108 }
7109 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
7110 index bf23477..b7425a6 100644
7111 --- a/arch/sparc/kernel/syscalls.S
7112 +++ b/arch/sparc/kernel/syscalls.S
7113 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
7114 #endif
7115 .align 32
7116 1: ldx [%g6 + TI_FLAGS], %l5
7117 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7118 + andcc %l5, _TIF_WORK_SYSCALL, %g0
7119 be,pt %icc, rtrap
7120 nop
7121 call syscall_trace_leave
7122 @@ -189,7 +189,7 @@ linux_sparc_syscall32:
7123
7124 srl %i5, 0, %o5 ! IEU1
7125 srl %i2, 0, %o2 ! IEU0 Group
7126 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7127 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7128 bne,pn %icc, linux_syscall_trace32 ! CTI
7129 mov %i0, %l5 ! IEU1
7130 call %l7 ! CTI Group brk forced
7131 @@ -212,7 +212,7 @@ linux_sparc_syscall:
7132
7133 mov %i3, %o3 ! IEU1
7134 mov %i4, %o4 ! IEU0 Group
7135 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7136 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7137 bne,pn %icc, linux_syscall_trace ! CTI Group
7138 mov %i0, %l5 ! IEU0
7139 2: call %l7 ! CTI Group brk forced
7140 @@ -228,7 +228,7 @@ ret_sys_call:
7141
7142 cmp %o0, -ERESTART_RESTARTBLOCK
7143 bgeu,pn %xcc, 1f
7144 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7145 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7146 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
7147
7148 2:
7149 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
7150 index a5785ea..405c5f7 100644
7151 --- a/arch/sparc/kernel/traps_32.c
7152 +++ b/arch/sparc/kernel/traps_32.c
7153 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
7154 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
7155 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
7156
7157 +extern void gr_handle_kernel_exploit(void);
7158 +
7159 void die_if_kernel(char *str, struct pt_regs *regs)
7160 {
7161 static int die_counter;
7162 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7163 count++ < 30 &&
7164 (((unsigned long) rw) >= PAGE_OFFSET) &&
7165 !(((unsigned long) rw) & 0x7)) {
7166 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
7167 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
7168 (void *) rw->ins[7]);
7169 rw = (struct reg_window32 *)rw->ins[6];
7170 }
7171 }
7172 printk("Instruction DUMP:");
7173 instruction_dump ((unsigned long *) regs->pc);
7174 - if(regs->psr & PSR_PS)
7175 + if(regs->psr & PSR_PS) {
7176 + gr_handle_kernel_exploit();
7177 do_exit(SIGKILL);
7178 + }
7179 do_exit(SIGSEGV);
7180 }
7181
7182 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
7183 index b66a779..8e8d66c 100644
7184 --- a/arch/sparc/kernel/traps_64.c
7185 +++ b/arch/sparc/kernel/traps_64.c
7186 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
7187 i + 1,
7188 p->trapstack[i].tstate, p->trapstack[i].tpc,
7189 p->trapstack[i].tnpc, p->trapstack[i].tt);
7190 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
7191 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
7192 }
7193 }
7194
7195 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
7196
7197 lvl -= 0x100;
7198 if (regs->tstate & TSTATE_PRIV) {
7199 +
7200 +#ifdef CONFIG_PAX_REFCOUNT
7201 + if (lvl == 6)
7202 + pax_report_refcount_overflow(regs);
7203 +#endif
7204 +
7205 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
7206 die_if_kernel(buffer, regs);
7207 }
7208 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
7209 void bad_trap_tl1(struct pt_regs *regs, long lvl)
7210 {
7211 char buffer[32];
7212 -
7213 +
7214 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
7215 0, lvl, SIGTRAP) == NOTIFY_STOP)
7216 return;
7217
7218 +#ifdef CONFIG_PAX_REFCOUNT
7219 + if (lvl == 6)
7220 + pax_report_refcount_overflow(regs);
7221 +#endif
7222 +
7223 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
7224
7225 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
7226 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
7227 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
7228 printk("%s" "ERROR(%d): ",
7229 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
7230 - printk("TPC<%pS>\n", (void *) regs->tpc);
7231 + printk("TPC<%pA>\n", (void *) regs->tpc);
7232 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
7233 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
7234 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
7235 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7236 smp_processor_id(),
7237 (type & 0x1) ? 'I' : 'D',
7238 regs->tpc);
7239 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
7240 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
7241 panic("Irrecoverable Cheetah+ parity error.");
7242 }
7243
7244 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7245 smp_processor_id(),
7246 (type & 0x1) ? 'I' : 'D',
7247 regs->tpc);
7248 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
7249 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
7250 }
7251
7252 struct sun4v_error_entry {
7253 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
7254
7255 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
7256 regs->tpc, tl);
7257 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
7258 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
7259 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7260 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
7261 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
7262 (void *) regs->u_regs[UREG_I7]);
7263 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
7264 "pte[%lx] error[%lx]\n",
7265 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
7266
7267 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
7268 regs->tpc, tl);
7269 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
7270 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
7271 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7272 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
7273 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
7274 (void *) regs->u_regs[UREG_I7]);
7275 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
7276 "pte[%lx] error[%lx]\n",
7277 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
7278 fp = (unsigned long)sf->fp + STACK_BIAS;
7279 }
7280
7281 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7282 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7283 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7284 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
7285 int index = tsk->curr_ret_stack;
7286 if (tsk->ret_stack && index >= graph) {
7287 pc = tsk->ret_stack[index - graph].ret;
7288 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7289 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7290 graph++;
7291 }
7292 }
7293 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
7294 return (struct reg_window *) (fp + STACK_BIAS);
7295 }
7296
7297 +extern void gr_handle_kernel_exploit(void);
7298 +
7299 void die_if_kernel(char *str, struct pt_regs *regs)
7300 {
7301 static int die_counter;
7302 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7303 while (rw &&
7304 count++ < 30 &&
7305 kstack_valid(tp, (unsigned long) rw)) {
7306 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
7307 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
7308 (void *) rw->ins[7]);
7309
7310 rw = kernel_stack_up(rw);
7311 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7312 }
7313 user_instruction_dump ((unsigned int __user *) regs->tpc);
7314 }
7315 - if (regs->tstate & TSTATE_PRIV)
7316 + if (regs->tstate & TSTATE_PRIV) {
7317 + gr_handle_kernel_exploit();
7318 do_exit(SIGKILL);
7319 + }
7320 do_exit(SIGSEGV);
7321 }
7322 EXPORT_SYMBOL(die_if_kernel);
7323 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
7324 index 8201c25e..072a2a7 100644
7325 --- a/arch/sparc/kernel/unaligned_64.c
7326 +++ b/arch/sparc/kernel/unaligned_64.c
7327 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7328 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7329
7330 if (__ratelimit(&ratelimit)) {
7331 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
7332 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
7333 regs->tpc, (void *) regs->tpc);
7334 }
7335 }
7336 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7337 index 8410065f2..4fd4ca22 100644
7338 --- a/arch/sparc/lib/Makefile
7339 +++ b/arch/sparc/lib/Makefile
7340 @@ -2,7 +2,7 @@
7341 #
7342
7343 asflags-y := -ansi -DST_DIV0=0x02
7344 -ccflags-y := -Werror
7345 +#ccflags-y := -Werror
7346
7347 lib-$(CONFIG_SPARC32) += ashrdi3.o
7348 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7349 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7350 index 85c233d..68500e0 100644
7351 --- a/arch/sparc/lib/atomic_64.S
7352 +++ b/arch/sparc/lib/atomic_64.S
7353 @@ -17,7 +17,12 @@
7354 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7355 BACKOFF_SETUP(%o2)
7356 1: lduw [%o1], %g1
7357 - add %g1, %o0, %g7
7358 + addcc %g1, %o0, %g7
7359 +
7360 +#ifdef CONFIG_PAX_REFCOUNT
7361 + tvs %icc, 6
7362 +#endif
7363 +
7364 cas [%o1], %g1, %g7
7365 cmp %g1, %g7
7366 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7367 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7368 2: BACKOFF_SPIN(%o2, %o3, 1b)
7369 ENDPROC(atomic_add)
7370
7371 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7372 + BACKOFF_SETUP(%o2)
7373 +1: lduw [%o1], %g1
7374 + add %g1, %o0, %g7
7375 + cas [%o1], %g1, %g7
7376 + cmp %g1, %g7
7377 + bne,pn %icc, 2f
7378 + nop
7379 + retl
7380 + nop
7381 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7382 +ENDPROC(atomic_add_unchecked)
7383 +
7384 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7385 BACKOFF_SETUP(%o2)
7386 1: lduw [%o1], %g1
7387 - sub %g1, %o0, %g7
7388 + subcc %g1, %o0, %g7
7389 +
7390 +#ifdef CONFIG_PAX_REFCOUNT
7391 + tvs %icc, 6
7392 +#endif
7393 +
7394 cas [%o1], %g1, %g7
7395 cmp %g1, %g7
7396 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7397 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7398 2: BACKOFF_SPIN(%o2, %o3, 1b)
7399 ENDPROC(atomic_sub)
7400
7401 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7402 + BACKOFF_SETUP(%o2)
7403 +1: lduw [%o1], %g1
7404 + sub %g1, %o0, %g7
7405 + cas [%o1], %g1, %g7
7406 + cmp %g1, %g7
7407 + bne,pn %icc, 2f
7408 + nop
7409 + retl
7410 + nop
7411 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7412 +ENDPROC(atomic_sub_unchecked)
7413 +
7414 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7415 BACKOFF_SETUP(%o2)
7416 1: lduw [%o1], %g1
7417 - add %g1, %o0, %g7
7418 + addcc %g1, %o0, %g7
7419 +
7420 +#ifdef CONFIG_PAX_REFCOUNT
7421 + tvs %icc, 6
7422 +#endif
7423 +
7424 cas [%o1], %g1, %g7
7425 cmp %g1, %g7
7426 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7427 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7428 2: BACKOFF_SPIN(%o2, %o3, 1b)
7429 ENDPROC(atomic_add_ret)
7430
7431 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7432 + BACKOFF_SETUP(%o2)
7433 +1: lduw [%o1], %g1
7434 + addcc %g1, %o0, %g7
7435 + cas [%o1], %g1, %g7
7436 + cmp %g1, %g7
7437 + bne,pn %icc, 2f
7438 + add %g7, %o0, %g7
7439 + sra %g7, 0, %o0
7440 + retl
7441 + nop
7442 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7443 +ENDPROC(atomic_add_ret_unchecked)
7444 +
7445 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7446 BACKOFF_SETUP(%o2)
7447 1: lduw [%o1], %g1
7448 - sub %g1, %o0, %g7
7449 + subcc %g1, %o0, %g7
7450 +
7451 +#ifdef CONFIG_PAX_REFCOUNT
7452 + tvs %icc, 6
7453 +#endif
7454 +
7455 cas [%o1], %g1, %g7
7456 cmp %g1, %g7
7457 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7458 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7459 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7460 BACKOFF_SETUP(%o2)
7461 1: ldx [%o1], %g1
7462 - add %g1, %o0, %g7
7463 + addcc %g1, %o0, %g7
7464 +
7465 +#ifdef CONFIG_PAX_REFCOUNT
7466 + tvs %xcc, 6
7467 +#endif
7468 +
7469 casx [%o1], %g1, %g7
7470 cmp %g1, %g7
7471 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7472 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7473 2: BACKOFF_SPIN(%o2, %o3, 1b)
7474 ENDPROC(atomic64_add)
7475
7476 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7477 + BACKOFF_SETUP(%o2)
7478 +1: ldx [%o1], %g1
7479 + addcc %g1, %o0, %g7
7480 + casx [%o1], %g1, %g7
7481 + cmp %g1, %g7
7482 + bne,pn %xcc, 2f
7483 + nop
7484 + retl
7485 + nop
7486 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7487 +ENDPROC(atomic64_add_unchecked)
7488 +
7489 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7490 BACKOFF_SETUP(%o2)
7491 1: ldx [%o1], %g1
7492 - sub %g1, %o0, %g7
7493 + subcc %g1, %o0, %g7
7494 +
7495 +#ifdef CONFIG_PAX_REFCOUNT
7496 + tvs %xcc, 6
7497 +#endif
7498 +
7499 casx [%o1], %g1, %g7
7500 cmp %g1, %g7
7501 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7502 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7503 2: BACKOFF_SPIN(%o2, %o3, 1b)
7504 ENDPROC(atomic64_sub)
7505
7506 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7507 + BACKOFF_SETUP(%o2)
7508 +1: ldx [%o1], %g1
7509 + subcc %g1, %o0, %g7
7510 + casx [%o1], %g1, %g7
7511 + cmp %g1, %g7
7512 + bne,pn %xcc, 2f
7513 + nop
7514 + retl
7515 + nop
7516 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7517 +ENDPROC(atomic64_sub_unchecked)
7518 +
7519 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7520 BACKOFF_SETUP(%o2)
7521 1: ldx [%o1], %g1
7522 - add %g1, %o0, %g7
7523 + addcc %g1, %o0, %g7
7524 +
7525 +#ifdef CONFIG_PAX_REFCOUNT
7526 + tvs %xcc, 6
7527 +#endif
7528 +
7529 casx [%o1], %g1, %g7
7530 cmp %g1, %g7
7531 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7532 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7533 2: BACKOFF_SPIN(%o2, %o3, 1b)
7534 ENDPROC(atomic64_add_ret)
7535
7536 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7537 + BACKOFF_SETUP(%o2)
7538 +1: ldx [%o1], %g1
7539 + addcc %g1, %o0, %g7
7540 + casx [%o1], %g1, %g7
7541 + cmp %g1, %g7
7542 + bne,pn %xcc, 2f
7543 + add %g7, %o0, %g7
7544 + mov %g7, %o0
7545 + retl
7546 + nop
7547 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7548 +ENDPROC(atomic64_add_ret_unchecked)
7549 +
7550 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7551 BACKOFF_SETUP(%o2)
7552 1: ldx [%o1], %g1
7553 - sub %g1, %o0, %g7
7554 + subcc %g1, %o0, %g7
7555 +
7556 +#ifdef CONFIG_PAX_REFCOUNT
7557 + tvs %xcc, 6
7558 +#endif
7559 +
7560 casx [%o1], %g1, %g7
7561 cmp %g1, %g7
7562 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7563 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7564 index 0c4e35e..745d3e4 100644
7565 --- a/arch/sparc/lib/ksyms.c
7566 +++ b/arch/sparc/lib/ksyms.c
7567 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7568
7569 /* Atomic counter implementation. */
7570 EXPORT_SYMBOL(atomic_add);
7571 +EXPORT_SYMBOL(atomic_add_unchecked);
7572 EXPORT_SYMBOL(atomic_add_ret);
7573 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
7574 EXPORT_SYMBOL(atomic_sub);
7575 +EXPORT_SYMBOL(atomic_sub_unchecked);
7576 EXPORT_SYMBOL(atomic_sub_ret);
7577 EXPORT_SYMBOL(atomic64_add);
7578 +EXPORT_SYMBOL(atomic64_add_unchecked);
7579 EXPORT_SYMBOL(atomic64_add_ret);
7580 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7581 EXPORT_SYMBOL(atomic64_sub);
7582 +EXPORT_SYMBOL(atomic64_sub_unchecked);
7583 EXPORT_SYMBOL(atomic64_sub_ret);
7584 EXPORT_SYMBOL(atomic64_dec_if_positive);
7585
7586 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7587 index 30c3ecc..736f015 100644
7588 --- a/arch/sparc/mm/Makefile
7589 +++ b/arch/sparc/mm/Makefile
7590 @@ -2,7 +2,7 @@
7591 #
7592
7593 asflags-y := -ansi
7594 -ccflags-y := -Werror
7595 +#ccflags-y := -Werror
7596
7597 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7598 obj-y += fault_$(BITS).o
7599 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7600 index e98bfda..ea8d221 100644
7601 --- a/arch/sparc/mm/fault_32.c
7602 +++ b/arch/sparc/mm/fault_32.c
7603 @@ -21,6 +21,9 @@
7604 #include <linux/perf_event.h>
7605 #include <linux/interrupt.h>
7606 #include <linux/kdebug.h>
7607 +#include <linux/slab.h>
7608 +#include <linux/pagemap.h>
7609 +#include <linux/compiler.h>
7610
7611 #include <asm/page.h>
7612 #include <asm/pgtable.h>
7613 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7614 return safe_compute_effective_address(regs, insn);
7615 }
7616
7617 +#ifdef CONFIG_PAX_PAGEEXEC
7618 +#ifdef CONFIG_PAX_DLRESOLVE
7619 +static void pax_emuplt_close(struct vm_area_struct *vma)
7620 +{
7621 + vma->vm_mm->call_dl_resolve = 0UL;
7622 +}
7623 +
7624 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7625 +{
7626 + unsigned int *kaddr;
7627 +
7628 + vmf->page = alloc_page(GFP_HIGHUSER);
7629 + if (!vmf->page)
7630 + return VM_FAULT_OOM;
7631 +
7632 + kaddr = kmap(vmf->page);
7633 + memset(kaddr, 0, PAGE_SIZE);
7634 + kaddr[0] = 0x9DE3BFA8U; /* save */
7635 + flush_dcache_page(vmf->page);
7636 + kunmap(vmf->page);
7637 + return VM_FAULT_MAJOR;
7638 +}
7639 +
7640 +static const struct vm_operations_struct pax_vm_ops = {
7641 + .close = pax_emuplt_close,
7642 + .fault = pax_emuplt_fault
7643 +};
7644 +
7645 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7646 +{
7647 + int ret;
7648 +
7649 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7650 + vma->vm_mm = current->mm;
7651 + vma->vm_start = addr;
7652 + vma->vm_end = addr + PAGE_SIZE;
7653 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7654 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7655 + vma->vm_ops = &pax_vm_ops;
7656 +
7657 + ret = insert_vm_struct(current->mm, vma);
7658 + if (ret)
7659 + return ret;
7660 +
7661 + ++current->mm->total_vm;
7662 + return 0;
7663 +}
7664 +#endif
7665 +
7666 +/*
7667 + * PaX: decide what to do with offenders (regs->pc = fault address)
7668 + *
7669 + * returns 1 when task should be killed
7670 + * 2 when patched PLT trampoline was detected
7671 + * 3 when unpatched PLT trampoline was detected
7672 + */
7673 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7674 +{
7675 +
7676 +#ifdef CONFIG_PAX_EMUPLT
7677 + int err;
7678 +
7679 + do { /* PaX: patched PLT emulation #1 */
7680 + unsigned int sethi1, sethi2, jmpl;
7681 +
7682 + err = get_user(sethi1, (unsigned int *)regs->pc);
7683 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7684 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7685 +
7686 + if (err)
7687 + break;
7688 +
7689 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7690 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7691 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7692 + {
7693 + unsigned int addr;
7694 +
7695 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7696 + addr = regs->u_regs[UREG_G1];
7697 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7698 + regs->pc = addr;
7699 + regs->npc = addr+4;
7700 + return 2;
7701 + }
7702 + } while (0);
7703 +
7704 + do { /* PaX: patched PLT emulation #2 */
7705 + unsigned int ba;
7706 +
7707 + err = get_user(ba, (unsigned int *)regs->pc);
7708 +
7709 + if (err)
7710 + break;
7711 +
7712 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7713 + unsigned int addr;
7714 +
7715 + if ((ba & 0xFFC00000U) == 0x30800000U)
7716 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7717 + else
7718 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7719 + regs->pc = addr;
7720 + regs->npc = addr+4;
7721 + return 2;
7722 + }
7723 + } while (0);
7724 +
7725 + do { /* PaX: patched PLT emulation #3 */
7726 + unsigned int sethi, bajmpl, nop;
7727 +
7728 + err = get_user(sethi, (unsigned int *)regs->pc);
7729 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7730 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7731 +
7732 + if (err)
7733 + break;
7734 +
7735 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7736 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7737 + nop == 0x01000000U)
7738 + {
7739 + unsigned int addr;
7740 +
7741 + addr = (sethi & 0x003FFFFFU) << 10;
7742 + regs->u_regs[UREG_G1] = addr;
7743 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7744 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7745 + else
7746 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7747 + regs->pc = addr;
7748 + regs->npc = addr+4;
7749 + return 2;
7750 + }
7751 + } while (0);
7752 +
7753 + do { /* PaX: unpatched PLT emulation step 1 */
7754 + unsigned int sethi, ba, nop;
7755 +
7756 + err = get_user(sethi, (unsigned int *)regs->pc);
7757 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
7758 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7759 +
7760 + if (err)
7761 + break;
7762 +
7763 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7764 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7765 + nop == 0x01000000U)
7766 + {
7767 + unsigned int addr, save, call;
7768 +
7769 + if ((ba & 0xFFC00000U) == 0x30800000U)
7770 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7771 + else
7772 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7773 +
7774 + err = get_user(save, (unsigned int *)addr);
7775 + err |= get_user(call, (unsigned int *)(addr+4));
7776 + err |= get_user(nop, (unsigned int *)(addr+8));
7777 + if (err)
7778 + break;
7779 +
7780 +#ifdef CONFIG_PAX_DLRESOLVE
7781 + if (save == 0x9DE3BFA8U &&
7782 + (call & 0xC0000000U) == 0x40000000U &&
7783 + nop == 0x01000000U)
7784 + {
7785 + struct vm_area_struct *vma;
7786 + unsigned long call_dl_resolve;
7787 +
7788 + down_read(&current->mm->mmap_sem);
7789 + call_dl_resolve = current->mm->call_dl_resolve;
7790 + up_read(&current->mm->mmap_sem);
7791 + if (likely(call_dl_resolve))
7792 + goto emulate;
7793 +
7794 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7795 +
7796 + down_write(&current->mm->mmap_sem);
7797 + if (current->mm->call_dl_resolve) {
7798 + call_dl_resolve = current->mm->call_dl_resolve;
7799 + up_write(&current->mm->mmap_sem);
7800 + if (vma)
7801 + kmem_cache_free(vm_area_cachep, vma);
7802 + goto emulate;
7803 + }
7804 +
7805 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7806 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7807 + up_write(&current->mm->mmap_sem);
7808 + if (vma)
7809 + kmem_cache_free(vm_area_cachep, vma);
7810 + return 1;
7811 + }
7812 +
7813 + if (pax_insert_vma(vma, call_dl_resolve)) {
7814 + up_write(&current->mm->mmap_sem);
7815 + kmem_cache_free(vm_area_cachep, vma);
7816 + return 1;
7817 + }
7818 +
7819 + current->mm->call_dl_resolve = call_dl_resolve;
7820 + up_write(&current->mm->mmap_sem);
7821 +
7822 +emulate:
7823 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7824 + regs->pc = call_dl_resolve;
7825 + regs->npc = addr+4;
7826 + return 3;
7827 + }
7828 +#endif
7829 +
7830 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7831 + if ((save & 0xFFC00000U) == 0x05000000U &&
7832 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7833 + nop == 0x01000000U)
7834 + {
7835 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7836 + regs->u_regs[UREG_G2] = addr + 4;
7837 + addr = (save & 0x003FFFFFU) << 10;
7838 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7839 + regs->pc = addr;
7840 + regs->npc = addr+4;
7841 + return 3;
7842 + }
7843 + }
7844 + } while (0);
7845 +
7846 + do { /* PaX: unpatched PLT emulation step 2 */
7847 + unsigned int save, call, nop;
7848 +
7849 + err = get_user(save, (unsigned int *)(regs->pc-4));
7850 + err |= get_user(call, (unsigned int *)regs->pc);
7851 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
7852 + if (err)
7853 + break;
7854 +
7855 + if (save == 0x9DE3BFA8U &&
7856 + (call & 0xC0000000U) == 0x40000000U &&
7857 + nop == 0x01000000U)
7858 + {
7859 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7860 +
7861 + regs->u_regs[UREG_RETPC] = regs->pc;
7862 + regs->pc = dl_resolve;
7863 + regs->npc = dl_resolve+4;
7864 + return 3;
7865 + }
7866 + } while (0);
7867 +#endif
7868 +
7869 + return 1;
7870 +}
7871 +
7872 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7873 +{
7874 + unsigned long i;
7875 +
7876 + printk(KERN_ERR "PAX: bytes at PC: ");
7877 + for (i = 0; i < 8; i++) {
7878 + unsigned int c;
7879 + if (get_user(c, (unsigned int *)pc+i))
7880 + printk(KERN_CONT "???????? ");
7881 + else
7882 + printk(KERN_CONT "%08x ", c);
7883 + }
7884 + printk("\n");
7885 +}
7886 +#endif
7887 +
7888 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7889 int text_fault)
7890 {
7891 @@ -230,6 +504,24 @@ good_area:
7892 if (!(vma->vm_flags & VM_WRITE))
7893 goto bad_area;
7894 } else {
7895 +
7896 +#ifdef CONFIG_PAX_PAGEEXEC
7897 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7898 + up_read(&mm->mmap_sem);
7899 + switch (pax_handle_fetch_fault(regs)) {
7900 +
7901 +#ifdef CONFIG_PAX_EMUPLT
7902 + case 2:
7903 + case 3:
7904 + return;
7905 +#endif
7906 +
7907 + }
7908 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7909 + do_group_exit(SIGKILL);
7910 + }
7911 +#endif
7912 +
7913 /* Allow reads even for write-only mappings */
7914 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7915 goto bad_area;
7916 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7917 index 097aee7..5ca6697 100644
7918 --- a/arch/sparc/mm/fault_64.c
7919 +++ b/arch/sparc/mm/fault_64.c
7920 @@ -21,6 +21,9 @@
7921 #include <linux/kprobes.h>
7922 #include <linux/kdebug.h>
7923 #include <linux/percpu.h>
7924 +#include <linux/slab.h>
7925 +#include <linux/pagemap.h>
7926 +#include <linux/compiler.h>
7927
7928 #include <asm/page.h>
7929 #include <asm/pgtable.h>
7930 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7931 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7932 regs->tpc);
7933 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7934 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7935 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7936 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7937 dump_stack();
7938 unhandled_fault(regs->tpc, current, regs);
7939 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7940 show_regs(regs);
7941 }
7942
7943 +#ifdef CONFIG_PAX_PAGEEXEC
7944 +#ifdef CONFIG_PAX_DLRESOLVE
7945 +static void pax_emuplt_close(struct vm_area_struct *vma)
7946 +{
7947 + vma->vm_mm->call_dl_resolve = 0UL;
7948 +}
7949 +
7950 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7951 +{
7952 + unsigned int *kaddr;
7953 +
7954 + vmf->page = alloc_page(GFP_HIGHUSER);
7955 + if (!vmf->page)
7956 + return VM_FAULT_OOM;
7957 +
7958 + kaddr = kmap(vmf->page);
7959 + memset(kaddr, 0, PAGE_SIZE);
7960 + kaddr[0] = 0x9DE3BFA8U; /* save */
7961 + flush_dcache_page(vmf->page);
7962 + kunmap(vmf->page);
7963 + return VM_FAULT_MAJOR;
7964 +}
7965 +
7966 +static const struct vm_operations_struct pax_vm_ops = {
7967 + .close = pax_emuplt_close,
7968 + .fault = pax_emuplt_fault
7969 +};
7970 +
7971 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7972 +{
7973 + int ret;
7974 +
7975 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7976 + vma->vm_mm = current->mm;
7977 + vma->vm_start = addr;
7978 + vma->vm_end = addr + PAGE_SIZE;
7979 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7980 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7981 + vma->vm_ops = &pax_vm_ops;
7982 +
7983 + ret = insert_vm_struct(current->mm, vma);
7984 + if (ret)
7985 + return ret;
7986 +
7987 + ++current->mm->total_vm;
7988 + return 0;
7989 +}
7990 +#endif
7991 +
7992 +/*
7993 + * PaX: decide what to do with offenders (regs->tpc = fault address)
7994 + *
7995 + * returns 1 when task should be killed
7996 + * 2 when patched PLT trampoline was detected
7997 + * 3 when unpatched PLT trampoline was detected
7998 + */
7999 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8000 +{
8001 +
8002 +#ifdef CONFIG_PAX_EMUPLT
8003 + int err;
8004 +
8005 + do { /* PaX: patched PLT emulation #1 */
8006 + unsigned int sethi1, sethi2, jmpl;
8007 +
8008 + err = get_user(sethi1, (unsigned int *)regs->tpc);
8009 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
8010 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
8011 +
8012 + if (err)
8013 + break;
8014 +
8015 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8016 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
8017 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
8018 + {
8019 + unsigned long addr;
8020 +
8021 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8022 + addr = regs->u_regs[UREG_G1];
8023 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8024 +
8025 + if (test_thread_flag(TIF_32BIT))
8026 + addr &= 0xFFFFFFFFUL;
8027 +
8028 + regs->tpc = addr;
8029 + regs->tnpc = addr+4;
8030 + return 2;
8031 + }
8032 + } while (0);
8033 +
8034 + do { /* PaX: patched PLT emulation #2 */
8035 + unsigned int ba;
8036 +
8037 + err = get_user(ba, (unsigned int *)regs->tpc);
8038 +
8039 + if (err)
8040 + break;
8041 +
8042 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8043 + unsigned long addr;
8044 +
8045 + if ((ba & 0xFFC00000U) == 0x30800000U)
8046 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8047 + else
8048 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8049 +
8050 + if (test_thread_flag(TIF_32BIT))
8051 + addr &= 0xFFFFFFFFUL;
8052 +
8053 + regs->tpc = addr;
8054 + regs->tnpc = addr+4;
8055 + return 2;
8056 + }
8057 + } while (0);
8058 +
8059 + do { /* PaX: patched PLT emulation #3 */
8060 + unsigned int sethi, bajmpl, nop;
8061 +
8062 + err = get_user(sethi, (unsigned int *)regs->tpc);
8063 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
8064 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8065 +
8066 + if (err)
8067 + break;
8068 +
8069 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8070 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8071 + nop == 0x01000000U)
8072 + {
8073 + unsigned long addr;
8074 +
8075 + addr = (sethi & 0x003FFFFFU) << 10;
8076 + regs->u_regs[UREG_G1] = addr;
8077 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8078 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8079 + else
8080 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8081 +
8082 + if (test_thread_flag(TIF_32BIT))
8083 + addr &= 0xFFFFFFFFUL;
8084 +
8085 + regs->tpc = addr;
8086 + regs->tnpc = addr+4;
8087 + return 2;
8088 + }
8089 + } while (0);
8090 +
8091 + do { /* PaX: patched PLT emulation #4 */
8092 + unsigned int sethi, mov1, call, mov2;
8093 +
8094 + err = get_user(sethi, (unsigned int *)regs->tpc);
8095 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
8096 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
8097 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
8098 +
8099 + if (err)
8100 + break;
8101 +
8102 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8103 + mov1 == 0x8210000FU &&
8104 + (call & 0xC0000000U) == 0x40000000U &&
8105 + mov2 == 0x9E100001U)
8106 + {
8107 + unsigned long addr;
8108 +
8109 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
8110 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8111 +
8112 + if (test_thread_flag(TIF_32BIT))
8113 + addr &= 0xFFFFFFFFUL;
8114 +
8115 + regs->tpc = addr;
8116 + regs->tnpc = addr+4;
8117 + return 2;
8118 + }
8119 + } while (0);
8120 +
8121 + do { /* PaX: patched PLT emulation #5 */
8122 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
8123 +
8124 + err = get_user(sethi, (unsigned int *)regs->tpc);
8125 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8126 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8127 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
8128 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
8129 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
8130 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
8131 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
8132 +
8133 + if (err)
8134 + break;
8135 +
8136 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8137 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8138 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8139 + (or1 & 0xFFFFE000U) == 0x82106000U &&
8140 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8141 + sllx == 0x83287020U &&
8142 + jmpl == 0x81C04005U &&
8143 + nop == 0x01000000U)
8144 + {
8145 + unsigned long addr;
8146 +
8147 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8148 + regs->u_regs[UREG_G1] <<= 32;
8149 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8150 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8151 + regs->tpc = addr;
8152 + regs->tnpc = addr+4;
8153 + return 2;
8154 + }
8155 + } while (0);
8156 +
8157 + do { /* PaX: patched PLT emulation #6 */
8158 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
8159 +
8160 + err = get_user(sethi, (unsigned int *)regs->tpc);
8161 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8162 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8163 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
8164 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
8165 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
8166 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
8167 +
8168 + if (err)
8169 + break;
8170 +
8171 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8172 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8173 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8174 + sllx == 0x83287020U &&
8175 + (or & 0xFFFFE000U) == 0x8A116000U &&
8176 + jmpl == 0x81C04005U &&
8177 + nop == 0x01000000U)
8178 + {
8179 + unsigned long addr;
8180 +
8181 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
8182 + regs->u_regs[UREG_G1] <<= 32;
8183 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
8184 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8185 + regs->tpc = addr;
8186 + regs->tnpc = addr+4;
8187 + return 2;
8188 + }
8189 + } while (0);
8190 +
8191 + do { /* PaX: unpatched PLT emulation step 1 */
8192 + unsigned int sethi, ba, nop;
8193 +
8194 + err = get_user(sethi, (unsigned int *)regs->tpc);
8195 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8196 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8197 +
8198 + if (err)
8199 + break;
8200 +
8201 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8202 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8203 + nop == 0x01000000U)
8204 + {
8205 + unsigned long addr;
8206 + unsigned int save, call;
8207 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
8208 +
8209 + if ((ba & 0xFFC00000U) == 0x30800000U)
8210 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8211 + else
8212 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8213 +
8214 + if (test_thread_flag(TIF_32BIT))
8215 + addr &= 0xFFFFFFFFUL;
8216 +
8217 + err = get_user(save, (unsigned int *)addr);
8218 + err |= get_user(call, (unsigned int *)(addr+4));
8219 + err |= get_user(nop, (unsigned int *)(addr+8));
8220 + if (err)
8221 + break;
8222 +
8223 +#ifdef CONFIG_PAX_DLRESOLVE
8224 + if (save == 0x9DE3BFA8U &&
8225 + (call & 0xC0000000U) == 0x40000000U &&
8226 + nop == 0x01000000U)
8227 + {
8228 + struct vm_area_struct *vma;
8229 + unsigned long call_dl_resolve;
8230 +
8231 + down_read(&current->mm->mmap_sem);
8232 + call_dl_resolve = current->mm->call_dl_resolve;
8233 + up_read(&current->mm->mmap_sem);
8234 + if (likely(call_dl_resolve))
8235 + goto emulate;
8236 +
8237 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8238 +
8239 + down_write(&current->mm->mmap_sem);
8240 + if (current->mm->call_dl_resolve) {
8241 + call_dl_resolve = current->mm->call_dl_resolve;
8242 + up_write(&current->mm->mmap_sem);
8243 + if (vma)
8244 + kmem_cache_free(vm_area_cachep, vma);
8245 + goto emulate;
8246 + }
8247 +
8248 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8249 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8250 + up_write(&current->mm->mmap_sem);
8251 + if (vma)
8252 + kmem_cache_free(vm_area_cachep, vma);
8253 + return 1;
8254 + }
8255 +
8256 + if (pax_insert_vma(vma, call_dl_resolve)) {
8257 + up_write(&current->mm->mmap_sem);
8258 + kmem_cache_free(vm_area_cachep, vma);
8259 + return 1;
8260 + }
8261 +
8262 + current->mm->call_dl_resolve = call_dl_resolve;
8263 + up_write(&current->mm->mmap_sem);
8264 +
8265 +emulate:
8266 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8267 + regs->tpc = call_dl_resolve;
8268 + regs->tnpc = addr+4;
8269 + return 3;
8270 + }
8271 +#endif
8272 +
8273 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8274 + if ((save & 0xFFC00000U) == 0x05000000U &&
8275 + (call & 0xFFFFE000U) == 0x85C0A000U &&
8276 + nop == 0x01000000U)
8277 + {
8278 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8279 + regs->u_regs[UREG_G2] = addr + 4;
8280 + addr = (save & 0x003FFFFFU) << 10;
8281 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8282 +
8283 + if (test_thread_flag(TIF_32BIT))
8284 + addr &= 0xFFFFFFFFUL;
8285 +
8286 + regs->tpc = addr;
8287 + regs->tnpc = addr+4;
8288 + return 3;
8289 + }
8290 +
8291 + /* PaX: 64-bit PLT stub */
8292 + err = get_user(sethi1, (unsigned int *)addr);
8293 + err |= get_user(sethi2, (unsigned int *)(addr+4));
8294 + err |= get_user(or1, (unsigned int *)(addr+8));
8295 + err |= get_user(or2, (unsigned int *)(addr+12));
8296 + err |= get_user(sllx, (unsigned int *)(addr+16));
8297 + err |= get_user(add, (unsigned int *)(addr+20));
8298 + err |= get_user(jmpl, (unsigned int *)(addr+24));
8299 + err |= get_user(nop, (unsigned int *)(addr+28));
8300 + if (err)
8301 + break;
8302 +
8303 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
8304 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8305 + (or1 & 0xFFFFE000U) == 0x88112000U &&
8306 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8307 + sllx == 0x89293020U &&
8308 + add == 0x8A010005U &&
8309 + jmpl == 0x89C14000U &&
8310 + nop == 0x01000000U)
8311 + {
8312 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8313 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8314 + regs->u_regs[UREG_G4] <<= 32;
8315 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8316 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
8317 + regs->u_regs[UREG_G4] = addr + 24;
8318 + addr = regs->u_regs[UREG_G5];
8319 + regs->tpc = addr;
8320 + regs->tnpc = addr+4;
8321 + return 3;
8322 + }
8323 + }
8324 + } while (0);
8325 +
8326 +#ifdef CONFIG_PAX_DLRESOLVE
8327 + do { /* PaX: unpatched PLT emulation step 2 */
8328 + unsigned int save, call, nop;
8329 +
8330 + err = get_user(save, (unsigned int *)(regs->tpc-4));
8331 + err |= get_user(call, (unsigned int *)regs->tpc);
8332 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8333 + if (err)
8334 + break;
8335 +
8336 + if (save == 0x9DE3BFA8U &&
8337 + (call & 0xC0000000U) == 0x40000000U &&
8338 + nop == 0x01000000U)
8339 + {
8340 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8341 +
8342 + if (test_thread_flag(TIF_32BIT))
8343 + dl_resolve &= 0xFFFFFFFFUL;
8344 +
8345 + regs->u_regs[UREG_RETPC] = regs->tpc;
8346 + regs->tpc = dl_resolve;
8347 + regs->tnpc = dl_resolve+4;
8348 + return 3;
8349 + }
8350 + } while (0);
8351 +#endif
8352 +
8353 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8354 + unsigned int sethi, ba, nop;
8355 +
8356 + err = get_user(sethi, (unsigned int *)regs->tpc);
8357 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8358 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8359 +
8360 + if (err)
8361 + break;
8362 +
8363 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8364 + (ba & 0xFFF00000U) == 0x30600000U &&
8365 + nop == 0x01000000U)
8366 + {
8367 + unsigned long addr;
8368 +
8369 + addr = (sethi & 0x003FFFFFU) << 10;
8370 + regs->u_regs[UREG_G1] = addr;
8371 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8372 +
8373 + if (test_thread_flag(TIF_32BIT))
8374 + addr &= 0xFFFFFFFFUL;
8375 +
8376 + regs->tpc = addr;
8377 + regs->tnpc = addr+4;
8378 + return 2;
8379 + }
8380 + } while (0);
8381 +
8382 +#endif
8383 +
8384 + return 1;
8385 +}
8386 +
8387 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8388 +{
8389 + unsigned long i;
8390 +
8391 + printk(KERN_ERR "PAX: bytes at PC: ");
8392 + for (i = 0; i < 8; i++) {
8393 + unsigned int c;
8394 + if (get_user(c, (unsigned int *)pc+i))
8395 + printk(KERN_CONT "???????? ");
8396 + else
8397 + printk(KERN_CONT "%08x ", c);
8398 + }
8399 + printk("\n");
8400 +}
8401 +#endif
8402 +
8403 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8404 {
8405 struct mm_struct *mm = current->mm;
8406 @@ -341,6 +804,29 @@ retry:
8407 if (!vma)
8408 goto bad_area;
8409
8410 +#ifdef CONFIG_PAX_PAGEEXEC
8411 + /* PaX: detect ITLB misses on non-exec pages */
8412 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8413 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8414 + {
8415 + if (address != regs->tpc)
8416 + goto good_area;
8417 +
8418 + up_read(&mm->mmap_sem);
8419 + switch (pax_handle_fetch_fault(regs)) {
8420 +
8421 +#ifdef CONFIG_PAX_EMUPLT
8422 + case 2:
8423 + case 3:
8424 + return;
8425 +#endif
8426 +
8427 + }
8428 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8429 + do_group_exit(SIGKILL);
8430 + }
8431 +#endif
8432 +
8433 /* Pure DTLB misses do not tell us whether the fault causing
8434 * load/store/atomic was a write or not, it only says that there
8435 * was no match. So in such a case we (carefully) read the
8436 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8437 index f76f83d..ee0d859 100644
8438 --- a/arch/sparc/mm/hugetlbpage.c
8439 +++ b/arch/sparc/mm/hugetlbpage.c
8440 @@ -34,6 +34,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
8441 struct vm_area_struct * vma;
8442 unsigned long task_size = TASK_SIZE;
8443 unsigned long start_addr;
8444 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8445
8446 if (test_thread_flag(TIF_32BIT))
8447 task_size = STACK_TOP32;
8448 @@ -67,7 +68,7 @@ full_search:
8449 }
8450 return -ENOMEM;
8451 }
8452 - if (likely(!vma || addr + len <= vma->vm_start)) {
8453 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8454 /*
8455 * Remember the place where we stopped the search:
8456 */
8457 @@ -90,6 +91,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8458 struct vm_area_struct *vma;
8459 struct mm_struct *mm = current->mm;
8460 unsigned long addr = addr0;
8461 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8462
8463 /* This should only ever run for 32-bit processes. */
8464 BUG_ON(!test_thread_flag(TIF_32BIT));
8465 @@ -106,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8466 /* make sure it can fit in the remaining address space */
8467 if (likely(addr > len)) {
8468 vma = find_vma(mm, addr-len);
8469 - if (!vma || addr <= vma->vm_start) {
8470 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
8471 /* remember the address as a hint for next time */
8472 return (mm->free_area_cache = addr-len);
8473 }
8474 @@ -115,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8475 if (unlikely(mm->mmap_base < len))
8476 goto bottomup;
8477
8478 - addr = (mm->mmap_base-len) & HPAGE_MASK;
8479 + addr = mm->mmap_base - len;
8480
8481 do {
8482 + addr &= HPAGE_MASK;
8483 /*
8484 * Lookup failure means no vma is above this address,
8485 * else if new region fits below vma->vm_start,
8486 * return with success:
8487 */
8488 vma = find_vma(mm, addr);
8489 - if (likely(!vma || addr+len <= vma->vm_start)) {
8490 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8491 /* remember the address as a hint for next time */
8492 return (mm->free_area_cache = addr);
8493 }
8494 @@ -134,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8495 mm->cached_hole_size = vma->vm_start - addr;
8496
8497 /* try just below the current vma->vm_start */
8498 - addr = (vma->vm_start-len) & HPAGE_MASK;
8499 - } while (likely(len < vma->vm_start));
8500 + addr = skip_heap_stack_gap(vma, len, offset);
8501 + } while (!IS_ERR_VALUE(addr));
8502
8503 bottomup:
8504 /*
8505 @@ -163,6 +166,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8506 struct mm_struct *mm = current->mm;
8507 struct vm_area_struct *vma;
8508 unsigned long task_size = TASK_SIZE;
8509 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8510
8511 if (test_thread_flag(TIF_32BIT))
8512 task_size = STACK_TOP32;
8513 @@ -181,8 +185,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8514 if (addr) {
8515 addr = ALIGN(addr, HPAGE_SIZE);
8516 vma = find_vma(mm, addr);
8517 - if (task_size - len >= addr &&
8518 - (!vma || addr + len <= vma->vm_start))
8519 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8520 return addr;
8521 }
8522 if (mm->get_unmapped_area == arch_get_unmapped_area)
8523 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8524 index f4500c6..889656c 100644
8525 --- a/arch/tile/include/asm/atomic_64.h
8526 +++ b/arch/tile/include/asm/atomic_64.h
8527 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8528
8529 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8530
8531 +#define atomic64_read_unchecked(v) atomic64_read(v)
8532 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8533 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8534 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8535 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8536 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8537 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8538 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8539 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8540 +
8541 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8542 #define smp_mb__before_atomic_dec() smp_mb()
8543 #define smp_mb__after_atomic_dec() smp_mb()
8544 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8545 index a9a5299..0fce79e 100644
8546 --- a/arch/tile/include/asm/cache.h
8547 +++ b/arch/tile/include/asm/cache.h
8548 @@ -15,11 +15,12 @@
8549 #ifndef _ASM_TILE_CACHE_H
8550 #define _ASM_TILE_CACHE_H
8551
8552 +#include <linux/const.h>
8553 #include <arch/chip.h>
8554
8555 /* bytes per L1 data cache line */
8556 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8557 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8558 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8559
8560 /* bytes per L2 cache line */
8561 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8562 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8563 index 9ab078a..d6635c2 100644
8564 --- a/arch/tile/include/asm/uaccess.h
8565 +++ b/arch/tile/include/asm/uaccess.h
8566 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8567 const void __user *from,
8568 unsigned long n)
8569 {
8570 - int sz = __compiletime_object_size(to);
8571 + size_t sz = __compiletime_object_size(to);
8572
8573 - if (likely(sz == -1 || sz >= n))
8574 + if (likely(sz == (size_t)-1 || sz >= n))
8575 n = _copy_from_user(to, from, n);
8576 else
8577 copy_from_user_overflow();
8578 diff --git a/arch/um/Makefile b/arch/um/Makefile
8579 index 133f7de..1d6f2f1 100644
8580 --- a/arch/um/Makefile
8581 +++ b/arch/um/Makefile
8582 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8583 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8584 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8585
8586 +ifdef CONSTIFY_PLUGIN
8587 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8588 +endif
8589 +
8590 #This will adjust *FLAGS accordingly to the platform.
8591 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8592
8593 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8594 index 19e1bdd..3665b77 100644
8595 --- a/arch/um/include/asm/cache.h
8596 +++ b/arch/um/include/asm/cache.h
8597 @@ -1,6 +1,7 @@
8598 #ifndef __UM_CACHE_H
8599 #define __UM_CACHE_H
8600
8601 +#include <linux/const.h>
8602
8603 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8604 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8605 @@ -12,6 +13,6 @@
8606 # define L1_CACHE_SHIFT 5
8607 #endif
8608
8609 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8610 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8611
8612 #endif
8613 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8614 index 2e0a6b1..a64d0f5 100644
8615 --- a/arch/um/include/asm/kmap_types.h
8616 +++ b/arch/um/include/asm/kmap_types.h
8617 @@ -8,6 +8,6 @@
8618
8619 /* No more #include "asm/arch/kmap_types.h" ! */
8620
8621 -#define KM_TYPE_NR 14
8622 +#define KM_TYPE_NR 15
8623
8624 #endif
8625 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8626 index 5ff53d9..5850cdf 100644
8627 --- a/arch/um/include/asm/page.h
8628 +++ b/arch/um/include/asm/page.h
8629 @@ -14,6 +14,9 @@
8630 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8631 #define PAGE_MASK (~(PAGE_SIZE-1))
8632
8633 +#define ktla_ktva(addr) (addr)
8634 +#define ktva_ktla(addr) (addr)
8635 +
8636 #ifndef __ASSEMBLY__
8637
8638 struct page;
8639 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8640 index 0032f92..cd151e0 100644
8641 --- a/arch/um/include/asm/pgtable-3level.h
8642 +++ b/arch/um/include/asm/pgtable-3level.h
8643 @@ -58,6 +58,7 @@
8644 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8645 #define pud_populate(mm, pud, pmd) \
8646 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8647 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8648
8649 #ifdef CONFIG_64BIT
8650 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8651 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8652 index b6d699c..df7ac1d 100644
8653 --- a/arch/um/kernel/process.c
8654 +++ b/arch/um/kernel/process.c
8655 @@ -387,22 +387,6 @@ int singlestepping(void * t)
8656 return 2;
8657 }
8658
8659 -/*
8660 - * Only x86 and x86_64 have an arch_align_stack().
8661 - * All other arches have "#define arch_align_stack(x) (x)"
8662 - * in their asm/system.h
8663 - * As this is included in UML from asm-um/system-generic.h,
8664 - * we can use it to behave as the subarch does.
8665 - */
8666 -#ifndef arch_align_stack
8667 -unsigned long arch_align_stack(unsigned long sp)
8668 -{
8669 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8670 - sp -= get_random_int() % 8192;
8671 - return sp & ~0xf;
8672 -}
8673 -#endif
8674 -
8675 unsigned long get_wchan(struct task_struct *p)
8676 {
8677 unsigned long stack_page, sp, ip;
8678 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8679 index ad8f795..2c7eec6 100644
8680 --- a/arch/unicore32/include/asm/cache.h
8681 +++ b/arch/unicore32/include/asm/cache.h
8682 @@ -12,8 +12,10 @@
8683 #ifndef __UNICORE_CACHE_H__
8684 #define __UNICORE_CACHE_H__
8685
8686 -#define L1_CACHE_SHIFT (5)
8687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8688 +#include <linux/const.h>
8689 +
8690 +#define L1_CACHE_SHIFT 5
8691 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8692
8693 /*
8694 * Memory returned by kmalloc() may be used for DMA, so we must make
8695 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8696 index 46c3bff..b82f26b 100644
8697 --- a/arch/x86/Kconfig
8698 +++ b/arch/x86/Kconfig
8699 @@ -241,7 +241,7 @@ config X86_HT
8700
8701 config X86_32_LAZY_GS
8702 def_bool y
8703 - depends on X86_32 && !CC_STACKPROTECTOR
8704 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8705
8706 config ARCH_HWEIGHT_CFLAGS
8707 string
8708 @@ -1033,6 +1033,7 @@ config MICROCODE_OLD_INTERFACE
8709
8710 config X86_MSR
8711 tristate "/dev/cpu/*/msr - Model-specific register support"
8712 + depends on !GRKERNSEC_KMEM
8713 ---help---
8714 This device gives privileged processes access to the x86
8715 Model-Specific Registers (MSRs). It is a character device with
8716 @@ -1056,7 +1057,7 @@ choice
8717
8718 config NOHIGHMEM
8719 bool "off"
8720 - depends on !X86_NUMAQ
8721 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8722 ---help---
8723 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8724 However, the address space of 32-bit x86 processors is only 4
8725 @@ -1093,7 +1094,7 @@ config NOHIGHMEM
8726
8727 config HIGHMEM4G
8728 bool "4GB"
8729 - depends on !X86_NUMAQ
8730 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8731 ---help---
8732 Select this if you have a 32-bit processor and between 1 and 4
8733 gigabytes of physical RAM.
8734 @@ -1147,7 +1148,7 @@ config PAGE_OFFSET
8735 hex
8736 default 0xB0000000 if VMSPLIT_3G_OPT
8737 default 0x80000000 if VMSPLIT_2G
8738 - default 0x78000000 if VMSPLIT_2G_OPT
8739 + default 0x70000000 if VMSPLIT_2G_OPT
8740 default 0x40000000 if VMSPLIT_1G
8741 default 0xC0000000
8742 depends on X86_32
8743 @@ -1548,6 +1549,7 @@ config SECCOMP
8744
8745 config CC_STACKPROTECTOR
8746 bool "Enable -fstack-protector buffer overflow detection"
8747 + depends on X86_64 || !PAX_MEMORY_UDEREF
8748 ---help---
8749 This option turns on the -fstack-protector GCC feature. This
8750 feature puts, at the beginning of functions, a canary value on
8751 @@ -1605,6 +1607,7 @@ config KEXEC_JUMP
8752 config PHYSICAL_START
8753 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8754 default "0x1000000"
8755 + range 0x400000 0x40000000
8756 ---help---
8757 This gives the physical address where the kernel is loaded.
8758
8759 @@ -1668,6 +1671,7 @@ config X86_NEED_RELOCS
8760 config PHYSICAL_ALIGN
8761 hex "Alignment value to which kernel should be aligned" if X86_32
8762 default "0x1000000"
8763 + range 0x400000 0x1000000 if PAX_KERNEXEC
8764 range 0x2000 0x1000000
8765 ---help---
8766 This value puts the alignment restrictions on physical address
8767 @@ -1699,9 +1703,10 @@ config HOTPLUG_CPU
8768 Say N if you want to disable CPU hotplug.
8769
8770 config COMPAT_VDSO
8771 - def_bool y
8772 + def_bool n
8773 prompt "Compat VDSO support"
8774 depends on X86_32 || IA32_EMULATION
8775 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
8776 ---help---
8777 Map the 32-bit VDSO to the predictable old-style address too.
8778
8779 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8780 index f3b86d0..17fd30f 100644
8781 --- a/arch/x86/Kconfig.cpu
8782 +++ b/arch/x86/Kconfig.cpu
8783 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8784
8785 config X86_F00F_BUG
8786 def_bool y
8787 - depends on M586MMX || M586TSC || M586 || M486 || M386
8788 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8789
8790 config X86_INVD_BUG
8791 def_bool y
8792 @@ -359,7 +359,7 @@ config X86_POPAD_OK
8793
8794 config X86_ALIGNMENT_16
8795 def_bool y
8796 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8797 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8798
8799 config X86_INTEL_USERCOPY
8800 def_bool y
8801 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
8802 # generates cmov.
8803 config X86_CMOV
8804 def_bool y
8805 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8806 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8807
8808 config X86_MINIMUM_CPU_FAMILY
8809 int
8810 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8811 index b322f12..652d0d9 100644
8812 --- a/arch/x86/Kconfig.debug
8813 +++ b/arch/x86/Kconfig.debug
8814 @@ -84,7 +84,7 @@ config X86_PTDUMP
8815 config DEBUG_RODATA
8816 bool "Write protect kernel read-only data structures"
8817 default y
8818 - depends on DEBUG_KERNEL
8819 + depends on DEBUG_KERNEL && BROKEN
8820 ---help---
8821 Mark the kernel read-only data as write-protected in the pagetables,
8822 in order to catch accidental (and incorrect) writes to such const
8823 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8824
8825 config DEBUG_SET_MODULE_RONX
8826 bool "Set loadable kernel module data as NX and text as RO"
8827 - depends on MODULES
8828 + depends on MODULES && BROKEN
8829 ---help---
8830 This option helps catch unintended modifications to loadable
8831 kernel module's text and read-only data. It also prevents execution
8832 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8833
8834 config DEBUG_STRICT_USER_COPY_CHECKS
8835 bool "Strict copy size checks"
8836 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8837 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8838 ---help---
8839 Enabling this option turns a certain set of sanity checks for user
8840 copy operations into compile time failures.
8841 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8842 index 05afcca..b6ecb51 100644
8843 --- a/arch/x86/Makefile
8844 +++ b/arch/x86/Makefile
8845 @@ -50,6 +50,7 @@ else
8846 UTS_MACHINE := x86_64
8847 CHECKFLAGS += -D__x86_64__ -m64
8848
8849 + biarch := $(call cc-option,-m64)
8850 KBUILD_AFLAGS += -m64
8851 KBUILD_CFLAGS += -m64
8852
8853 @@ -229,3 +230,12 @@ define archhelp
8854 echo ' FDARGS="..." arguments for the booted kernel'
8855 echo ' FDINITRD=file initrd for the booted kernel'
8856 endef
8857 +
8858 +define OLD_LD
8859 +
8860 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8861 +*** Please upgrade your binutils to 2.18 or newer
8862 +endef
8863 +
8864 +archprepare:
8865 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8866 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8867 index ccce0ed..fd9da25 100644
8868 --- a/arch/x86/boot/Makefile
8869 +++ b/arch/x86/boot/Makefile
8870 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8871 $(call cc-option, -fno-stack-protector) \
8872 $(call cc-option, -mpreferred-stack-boundary=2)
8873 KBUILD_CFLAGS += $(call cc-option, -m32)
8874 +ifdef CONSTIFY_PLUGIN
8875 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8876 +endif
8877 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8878 GCOV_PROFILE := n
8879
8880 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8881 index 878e4b9..20537ab 100644
8882 --- a/arch/x86/boot/bitops.h
8883 +++ b/arch/x86/boot/bitops.h
8884 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8885 u8 v;
8886 const u32 *p = (const u32 *)addr;
8887
8888 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8889 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8890 return v;
8891 }
8892
8893 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8894
8895 static inline void set_bit(int nr, void *addr)
8896 {
8897 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8898 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8899 }
8900
8901 #endif /* BOOT_BITOPS_H */
8902 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8903 index 18997e5..83d9c67 100644
8904 --- a/arch/x86/boot/boot.h
8905 +++ b/arch/x86/boot/boot.h
8906 @@ -85,7 +85,7 @@ static inline void io_delay(void)
8907 static inline u16 ds(void)
8908 {
8909 u16 seg;
8910 - asm("movw %%ds,%0" : "=rm" (seg));
8911 + asm volatile("movw %%ds,%0" : "=rm" (seg));
8912 return seg;
8913 }
8914
8915 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8916 static inline int memcmp(const void *s1, const void *s2, size_t len)
8917 {
8918 u8 diff;
8919 - asm("repe; cmpsb; setnz %0"
8920 + asm volatile("repe; cmpsb; setnz %0"
8921 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8922 return diff;
8923 }
8924 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8925 index 8a84501..b2d165f 100644
8926 --- a/arch/x86/boot/compressed/Makefile
8927 +++ b/arch/x86/boot/compressed/Makefile
8928 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8929 KBUILD_CFLAGS += $(cflags-y)
8930 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8931 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8932 +ifdef CONSTIFY_PLUGIN
8933 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8934 +endif
8935
8936 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8937 GCOV_PROFILE := n
8938 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8939 index ccae7e2..8ac70be 100644
8940 --- a/arch/x86/boot/compressed/eboot.c
8941 +++ b/arch/x86/boot/compressed/eboot.c
8942 @@ -144,7 +144,6 @@ again:
8943 *addr = max_addr;
8944 }
8945
8946 -free_pool:
8947 efi_call_phys1(sys_table->boottime->free_pool, map);
8948
8949 fail:
8950 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8951 if (i == map_size / desc_size)
8952 status = EFI_NOT_FOUND;
8953
8954 -free_pool:
8955 efi_call_phys1(sys_table->boottime->free_pool, map);
8956 fail:
8957 return status;
8958 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8959 index ccb2f4a..e49b20e 100644
8960 --- a/arch/x86/boot/compressed/head_32.S
8961 +++ b/arch/x86/boot/compressed/head_32.S
8962 @@ -118,7 +118,7 @@ preferred_addr:
8963 notl %eax
8964 andl %eax, %ebx
8965 #else
8966 - movl $LOAD_PHYSICAL_ADDR, %ebx
8967 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8968 #endif
8969
8970 /* Target address to relocate to for decompression */
8971 @@ -204,7 +204,7 @@ relocated:
8972 * and where it was actually loaded.
8973 */
8974 movl %ebp, %ebx
8975 - subl $LOAD_PHYSICAL_ADDR, %ebx
8976 + subl $____LOAD_PHYSICAL_ADDR, %ebx
8977 jz 2f /* Nothing to be done if loaded at compiled addr. */
8978 /*
8979 * Process relocations.
8980 @@ -212,8 +212,7 @@ relocated:
8981
8982 1: subl $4, %edi
8983 movl (%edi), %ecx
8984 - testl %ecx, %ecx
8985 - jz 2f
8986 + jecxz 2f
8987 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8988 jmp 1b
8989 2:
8990 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8991 index 2c4b171..e1fa5b1 100644
8992 --- a/arch/x86/boot/compressed/head_64.S
8993 +++ b/arch/x86/boot/compressed/head_64.S
8994 @@ -91,7 +91,7 @@ ENTRY(startup_32)
8995 notl %eax
8996 andl %eax, %ebx
8997 #else
8998 - movl $LOAD_PHYSICAL_ADDR, %ebx
8999 + movl $____LOAD_PHYSICAL_ADDR, %ebx
9000 #endif
9001
9002 /* Target address to relocate to for decompression */
9003 @@ -273,7 +273,7 @@ preferred_addr:
9004 notq %rax
9005 andq %rax, %rbp
9006 #else
9007 - movq $LOAD_PHYSICAL_ADDR, %rbp
9008 + movq $____LOAD_PHYSICAL_ADDR, %rbp
9009 #endif
9010
9011 /* Target address to relocate to for decompression */
9012 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
9013 index 88f7ff6..ed695dd 100644
9014 --- a/arch/x86/boot/compressed/misc.c
9015 +++ b/arch/x86/boot/compressed/misc.c
9016 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
9017 case PT_LOAD:
9018 #ifdef CONFIG_RELOCATABLE
9019 dest = output;
9020 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
9021 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
9022 #else
9023 dest = (void *)(phdr->p_paddr);
9024 #endif
9025 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
9026 error("Destination address too large");
9027 #endif
9028 #ifndef CONFIG_RELOCATABLE
9029 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
9030 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
9031 error("Wrong destination address");
9032 #endif
9033
9034 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
9035 index 4d3ff03..e4972ff 100644
9036 --- a/arch/x86/boot/cpucheck.c
9037 +++ b/arch/x86/boot/cpucheck.c
9038 @@ -74,7 +74,7 @@ static int has_fpu(void)
9039 u16 fcw = -1, fsw = -1;
9040 u32 cr0;
9041
9042 - asm("movl %%cr0,%0" : "=r" (cr0));
9043 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
9044 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
9045 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
9046 asm volatile("movl %0,%%cr0" : : "r" (cr0));
9047 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
9048 {
9049 u32 f0, f1;
9050
9051 - asm("pushfl ; "
9052 + asm volatile("pushfl ; "
9053 "pushfl ; "
9054 "popl %0 ; "
9055 "movl %0,%1 ; "
9056 @@ -115,7 +115,7 @@ static void get_flags(void)
9057 set_bit(X86_FEATURE_FPU, cpu.flags);
9058
9059 if (has_eflag(X86_EFLAGS_ID)) {
9060 - asm("cpuid"
9061 + asm volatile("cpuid"
9062 : "=a" (max_intel_level),
9063 "=b" (cpu_vendor[0]),
9064 "=d" (cpu_vendor[1]),
9065 @@ -124,7 +124,7 @@ static void get_flags(void)
9066
9067 if (max_intel_level >= 0x00000001 &&
9068 max_intel_level <= 0x0000ffff) {
9069 - asm("cpuid"
9070 + asm volatile("cpuid"
9071 : "=a" (tfms),
9072 "=c" (cpu.flags[4]),
9073 "=d" (cpu.flags[0])
9074 @@ -136,7 +136,7 @@ static void get_flags(void)
9075 cpu.model += ((tfms >> 16) & 0xf) << 4;
9076 }
9077
9078 - asm("cpuid"
9079 + asm volatile("cpuid"
9080 : "=a" (max_amd_level)
9081 : "a" (0x80000000)
9082 : "ebx", "ecx", "edx");
9083 @@ -144,7 +144,7 @@ static void get_flags(void)
9084 if (max_amd_level >= 0x80000001 &&
9085 max_amd_level <= 0x8000ffff) {
9086 u32 eax = 0x80000001;
9087 - asm("cpuid"
9088 + asm volatile("cpuid"
9089 : "+a" (eax),
9090 "=c" (cpu.flags[6]),
9091 "=d" (cpu.flags[1])
9092 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9093 u32 ecx = MSR_K7_HWCR;
9094 u32 eax, edx;
9095
9096 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9097 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9098 eax &= ~(1 << 15);
9099 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9100 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9101
9102 get_flags(); /* Make sure it really did something */
9103 err = check_flags();
9104 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9105 u32 ecx = MSR_VIA_FCR;
9106 u32 eax, edx;
9107
9108 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9109 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9110 eax |= (1<<1)|(1<<7);
9111 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9112 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9113
9114 set_bit(X86_FEATURE_CX8, cpu.flags);
9115 err = check_flags();
9116 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9117 u32 eax, edx;
9118 u32 level = 1;
9119
9120 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9121 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9122 - asm("cpuid"
9123 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9124 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9125 + asm volatile("cpuid"
9126 : "+a" (level), "=d" (cpu.flags[0])
9127 : : "ecx", "ebx");
9128 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9129 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9130
9131 err = check_flags();
9132 }
9133 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
9134 index 8c132a6..13e5c96 100644
9135 --- a/arch/x86/boot/header.S
9136 +++ b/arch/x86/boot/header.S
9137 @@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
9138 # single linked list of
9139 # struct setup_data
9140
9141 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
9142 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
9143
9144 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
9145 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
9146 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
9147 +#else
9148 #define VO_INIT_SIZE (VO__end - VO__text)
9149 +#endif
9150 #if ZO_INIT_SIZE > VO_INIT_SIZE
9151 #define INIT_SIZE ZO_INIT_SIZE
9152 #else
9153 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
9154 index db75d07..8e6d0af 100644
9155 --- a/arch/x86/boot/memory.c
9156 +++ b/arch/x86/boot/memory.c
9157 @@ -19,7 +19,7 @@
9158
9159 static int detect_memory_e820(void)
9160 {
9161 - int count = 0;
9162 + unsigned int count = 0;
9163 struct biosregs ireg, oreg;
9164 struct e820entry *desc = boot_params.e820_map;
9165 static struct e820entry buf; /* static so it is zeroed */
9166 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
9167 index 11e8c6e..fdbb1ed 100644
9168 --- a/arch/x86/boot/video-vesa.c
9169 +++ b/arch/x86/boot/video-vesa.c
9170 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
9171
9172 boot_params.screen_info.vesapm_seg = oreg.es;
9173 boot_params.screen_info.vesapm_off = oreg.di;
9174 + boot_params.screen_info.vesapm_size = oreg.cx;
9175 }
9176
9177 /*
9178 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
9179 index 43eda28..5ab5fdb 100644
9180 --- a/arch/x86/boot/video.c
9181 +++ b/arch/x86/boot/video.c
9182 @@ -96,7 +96,7 @@ static void store_mode_params(void)
9183 static unsigned int get_entry(void)
9184 {
9185 char entry_buf[4];
9186 - int i, len = 0;
9187 + unsigned int i, len = 0;
9188 int key;
9189 unsigned int v;
9190
9191 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
9192 index 5b577d5..3c1fed4 100644
9193 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
9194 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
9195 @@ -8,6 +8,8 @@
9196 * including this sentence is retained in full.
9197 */
9198
9199 +#include <asm/alternative-asm.h>
9200 +
9201 .extern crypto_ft_tab
9202 .extern crypto_it_tab
9203 .extern crypto_fl_tab
9204 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
9205 je B192; \
9206 leaq 32(r9),r9;
9207
9208 +#define ret pax_force_retaddr 0, 1; ret
9209 +
9210 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
9211 movq r1,r2; \
9212 movq r3,r4; \
9213 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
9214 index 3470624..201259d 100644
9215 --- a/arch/x86/crypto/aesni-intel_asm.S
9216 +++ b/arch/x86/crypto/aesni-intel_asm.S
9217 @@ -31,6 +31,7 @@
9218
9219 #include <linux/linkage.h>
9220 #include <asm/inst.h>
9221 +#include <asm/alternative-asm.h>
9222
9223 #ifdef __x86_64__
9224 .data
9225 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
9226 pop %r14
9227 pop %r13
9228 pop %r12
9229 + pax_force_retaddr 0, 1
9230 ret
9231 +ENDPROC(aesni_gcm_dec)
9232
9233
9234 /*****************************************************************************
9235 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
9236 pop %r14
9237 pop %r13
9238 pop %r12
9239 + pax_force_retaddr 0, 1
9240 ret
9241 +ENDPROC(aesni_gcm_enc)
9242
9243 #endif
9244
9245 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
9246 pxor %xmm1, %xmm0
9247 movaps %xmm0, (TKEYP)
9248 add $0x10, TKEYP
9249 + pax_force_retaddr_bts
9250 ret
9251
9252 .align 4
9253 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
9254 shufps $0b01001110, %xmm2, %xmm1
9255 movaps %xmm1, 0x10(TKEYP)
9256 add $0x20, TKEYP
9257 + pax_force_retaddr_bts
9258 ret
9259
9260 .align 4
9261 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
9262
9263 movaps %xmm0, (TKEYP)
9264 add $0x10, TKEYP
9265 + pax_force_retaddr_bts
9266 ret
9267
9268 .align 4
9269 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
9270 pxor %xmm1, %xmm2
9271 movaps %xmm2, (TKEYP)
9272 add $0x10, TKEYP
9273 + pax_force_retaddr_bts
9274 ret
9275
9276 /*
9277 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
9278 #ifndef __x86_64__
9279 popl KEYP
9280 #endif
9281 + pax_force_retaddr 0, 1
9282 ret
9283 +ENDPROC(aesni_set_key)
9284
9285 /*
9286 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
9287 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
9288 popl KLEN
9289 popl KEYP
9290 #endif
9291 + pax_force_retaddr 0, 1
9292 ret
9293 +ENDPROC(aesni_enc)
9294
9295 /*
9296 * _aesni_enc1: internal ABI
9297 @@ -1959,6 +1972,7 @@ _aesni_enc1:
9298 AESENC KEY STATE
9299 movaps 0x70(TKEYP), KEY
9300 AESENCLAST KEY STATE
9301 + pax_force_retaddr_bts
9302 ret
9303
9304 /*
9305 @@ -2067,6 +2081,7 @@ _aesni_enc4:
9306 AESENCLAST KEY STATE2
9307 AESENCLAST KEY STATE3
9308 AESENCLAST KEY STATE4
9309 + pax_force_retaddr_bts
9310 ret
9311
9312 /*
9313 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
9314 popl KLEN
9315 popl KEYP
9316 #endif
9317 + pax_force_retaddr 0, 1
9318 ret
9319 +ENDPROC(aesni_dec)
9320
9321 /*
9322 * _aesni_dec1: internal ABI
9323 @@ -2146,6 +2163,7 @@ _aesni_dec1:
9324 AESDEC KEY STATE
9325 movaps 0x70(TKEYP), KEY
9326 AESDECLAST KEY STATE
9327 + pax_force_retaddr_bts
9328 ret
9329
9330 /*
9331 @@ -2254,6 +2272,7 @@ _aesni_dec4:
9332 AESDECLAST KEY STATE2
9333 AESDECLAST KEY STATE3
9334 AESDECLAST KEY STATE4
9335 + pax_force_retaddr_bts
9336 ret
9337
9338 /*
9339 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
9340 popl KEYP
9341 popl LEN
9342 #endif
9343 + pax_force_retaddr 0, 1
9344 ret
9345 +ENDPROC(aesni_ecb_enc)
9346
9347 /*
9348 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9349 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
9350 popl KEYP
9351 popl LEN
9352 #endif
9353 + pax_force_retaddr 0, 1
9354 ret
9355 +ENDPROC(aesni_ecb_dec)
9356
9357 /*
9358 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9359 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9360 popl LEN
9361 popl IVP
9362 #endif
9363 + pax_force_retaddr 0, 1
9364 ret
9365 +ENDPROC(aesni_cbc_enc)
9366
9367 /*
9368 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9369 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9370 popl LEN
9371 popl IVP
9372 #endif
9373 + pax_force_retaddr 0, 1
9374 ret
9375 +ENDPROC(aesni_cbc_dec)
9376
9377 #ifdef __x86_64__
9378 .align 16
9379 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
9380 mov $1, TCTR_LOW
9381 MOVQ_R64_XMM TCTR_LOW INC
9382 MOVQ_R64_XMM CTR TCTR_LOW
9383 + pax_force_retaddr_bts
9384 ret
9385
9386 /*
9387 @@ -2554,6 +2582,7 @@ _aesni_inc:
9388 .Linc_low:
9389 movaps CTR, IV
9390 PSHUFB_XMM BSWAP_MASK IV
9391 + pax_force_retaddr_bts
9392 ret
9393
9394 /*
9395 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9396 .Lctr_enc_ret:
9397 movups IV, (IVP)
9398 .Lctr_enc_just_ret:
9399 + pax_force_retaddr 0, 1
9400 ret
9401 +ENDPROC(aesni_ctr_enc)
9402 #endif
9403 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9404 index 391d245..67f35c2 100644
9405 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9406 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9407 @@ -20,6 +20,8 @@
9408 *
9409 */
9410
9411 +#include <asm/alternative-asm.h>
9412 +
9413 .file "blowfish-x86_64-asm.S"
9414 .text
9415
9416 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
9417 jnz __enc_xor;
9418
9419 write_block();
9420 + pax_force_retaddr 0, 1
9421 ret;
9422 __enc_xor:
9423 xor_block();
9424 + pax_force_retaddr 0, 1
9425 ret;
9426
9427 .align 8
9428 @@ -188,6 +192,7 @@ blowfish_dec_blk:
9429
9430 movq %r11, %rbp;
9431
9432 + pax_force_retaddr 0, 1
9433 ret;
9434
9435 /**********************************************************************
9436 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9437
9438 popq %rbx;
9439 popq %rbp;
9440 + pax_force_retaddr 0, 1
9441 ret;
9442
9443 __enc_xor4:
9444 @@ -349,6 +355,7 @@ __enc_xor4:
9445
9446 popq %rbx;
9447 popq %rbp;
9448 + pax_force_retaddr 0, 1
9449 ret;
9450
9451 .align 8
9452 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9453 popq %rbx;
9454 popq %rbp;
9455
9456 + pax_force_retaddr 0, 1
9457 ret;
9458
9459 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9460 index 0b33743..7a56206 100644
9461 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9462 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9463 @@ -20,6 +20,8 @@
9464 *
9465 */
9466
9467 +#include <asm/alternative-asm.h>
9468 +
9469 .file "camellia-x86_64-asm_64.S"
9470 .text
9471
9472 @@ -229,12 +231,14 @@ __enc_done:
9473 enc_outunpack(mov, RT1);
9474
9475 movq RRBP, %rbp;
9476 + pax_force_retaddr 0, 1
9477 ret;
9478
9479 __enc_xor:
9480 enc_outunpack(xor, RT1);
9481
9482 movq RRBP, %rbp;
9483 + pax_force_retaddr 0, 1
9484 ret;
9485
9486 .global camellia_dec_blk;
9487 @@ -275,6 +279,7 @@ __dec_rounds16:
9488 dec_outunpack();
9489
9490 movq RRBP, %rbp;
9491 + pax_force_retaddr 0, 1
9492 ret;
9493
9494 /**********************************************************************
9495 @@ -468,6 +473,7 @@ __enc2_done:
9496
9497 movq RRBP, %rbp;
9498 popq %rbx;
9499 + pax_force_retaddr 0, 1
9500 ret;
9501
9502 __enc2_xor:
9503 @@ -475,6 +481,7 @@ __enc2_xor:
9504
9505 movq RRBP, %rbp;
9506 popq %rbx;
9507 + pax_force_retaddr 0, 1
9508 ret;
9509
9510 .global camellia_dec_blk_2way;
9511 @@ -517,4 +524,5 @@ __dec2_rounds16:
9512
9513 movq RRBP, %rbp;
9514 movq RXOR, %rbx;
9515 + pax_force_retaddr 0, 1
9516 ret;
9517 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9518 index a41a3aa..bdf5753 100644
9519 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9520 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9521 @@ -23,6 +23,8 @@
9522 *
9523 */
9524
9525 +#include <asm/alternative-asm.h>
9526 +
9527 .file "cast5-avx-x86_64-asm_64.S"
9528
9529 .extern cast5_s1
9530 @@ -293,6 +295,7 @@ __skip_enc:
9531 leaq 3*(2*4*4)(%r11), %rax;
9532 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9533
9534 + pax_force_retaddr 0, 1
9535 ret;
9536
9537 __enc_xor16:
9538 @@ -303,6 +306,7 @@ __enc_xor16:
9539 leaq 3*(2*4*4)(%r11), %rax;
9540 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9541
9542 + pax_force_retaddr 0, 1
9543 ret;
9544
9545 .align 16
9546 @@ -369,6 +373,7 @@ __dec_tail:
9547 leaq 3*(2*4*4)(%r11), %rax;
9548 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9549
9550 + pax_force_retaddr 0, 1
9551 ret;
9552
9553 __skip_dec:
9554 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9555 index 218d283..819e6da 100644
9556 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9557 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9558 @@ -23,6 +23,8 @@
9559 *
9560 */
9561
9562 +#include <asm/alternative-asm.h>
9563 +
9564 .file "cast6-avx-x86_64-asm_64.S"
9565
9566 .extern cast6_s1
9567 @@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9568 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9569 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9570
9571 + pax_force_retaddr 0, 1
9572 ret;
9573
9574 __enc_xor8:
9575 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9576 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9577
9578 + pax_force_retaddr 0, 1
9579 ret;
9580
9581 .align 16
9582 @@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9583 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9584 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9585
9586 + pax_force_retaddr 0, 1
9587 ret;
9588 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9589 index 6214a9b..1f4fc9a 100644
9590 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9591 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9592 @@ -1,3 +1,5 @@
9593 +#include <asm/alternative-asm.h>
9594 +
9595 # enter ECRYPT_encrypt_bytes
9596 .text
9597 .p2align 5
9598 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9599 add %r11,%rsp
9600 mov %rdi,%rax
9601 mov %rsi,%rdx
9602 + pax_force_retaddr 0, 1
9603 ret
9604 # bytesatleast65:
9605 ._bytesatleast65:
9606 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
9607 add %r11,%rsp
9608 mov %rdi,%rax
9609 mov %rsi,%rdx
9610 + pax_force_retaddr
9611 ret
9612 # enter ECRYPT_ivsetup
9613 .text
9614 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9615 add %r11,%rsp
9616 mov %rdi,%rax
9617 mov %rsi,%rdx
9618 + pax_force_retaddr
9619 ret
9620 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9621 index 504106b..4e50951 100644
9622 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9623 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9624 @@ -24,6 +24,8 @@
9625 *
9626 */
9627
9628 +#include <asm/alternative-asm.h>
9629 +
9630 .file "serpent-avx-x86_64-asm_64.S"
9631 .text
9632
9633 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9634 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9635 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9636
9637 + pax_force_retaddr
9638 ret;
9639
9640 __enc_xor8:
9641 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9642 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9643
9644 + pax_force_retaddr
9645 ret;
9646
9647 .align 8
9648 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9649 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9650 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9651
9652 + pax_force_retaddr
9653 ret;
9654 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9655 index 3ee1ff0..cbc568b 100644
9656 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9657 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9658 @@ -24,6 +24,8 @@
9659 *
9660 */
9661
9662 +#include <asm/alternative-asm.h>
9663 +
9664 .file "serpent-sse2-x86_64-asm_64.S"
9665 .text
9666
9667 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9668 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9669 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9670
9671 + pax_force_retaddr
9672 ret;
9673
9674 __enc_xor8:
9675 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9676 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9677
9678 + pax_force_retaddr
9679 ret;
9680
9681 .align 8
9682 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9683 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9684 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9685
9686 + pax_force_retaddr
9687 ret;
9688 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9689 index 49d6987..df66bd4 100644
9690 --- a/arch/x86/crypto/sha1_ssse3_asm.S
9691 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
9692 @@ -28,6 +28,8 @@
9693 * (at your option) any later version.
9694 */
9695
9696 +#include <asm/alternative-asm.h>
9697 +
9698 #define CTX %rdi // arg1
9699 #define BUF %rsi // arg2
9700 #define CNT %rdx // arg3
9701 @@ -104,6 +106,7 @@
9702 pop %r12
9703 pop %rbp
9704 pop %rbx
9705 + pax_force_retaddr 0, 1
9706 ret
9707
9708 .size \name, .-\name
9709 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9710 index 1585abb..1ff9d9b 100644
9711 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9712 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9713 @@ -23,6 +23,8 @@
9714 *
9715 */
9716
9717 +#include <asm/alternative-asm.h>
9718 +
9719 .file "twofish-avx-x86_64-asm_64.S"
9720 .text
9721
9722 @@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9723 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9724 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9725
9726 + pax_force_retaddr 0, 1
9727 ret;
9728
9729 __enc_xor8:
9730 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9731 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9732
9733 + pax_force_retaddr 0, 1
9734 ret;
9735
9736 .align 8
9737 @@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9738 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9739 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9740
9741 + pax_force_retaddr 0, 1
9742 ret;
9743 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9744 index 5b012a2..36d5364 100644
9745 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9746 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9747 @@ -20,6 +20,8 @@
9748 *
9749 */
9750
9751 +#include <asm/alternative-asm.h>
9752 +
9753 .file "twofish-x86_64-asm-3way.S"
9754 .text
9755
9756 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9757 popq %r13;
9758 popq %r14;
9759 popq %r15;
9760 + pax_force_retaddr 0, 1
9761 ret;
9762
9763 __enc_xor3:
9764 @@ -271,6 +274,7 @@ __enc_xor3:
9765 popq %r13;
9766 popq %r14;
9767 popq %r15;
9768 + pax_force_retaddr 0, 1
9769 ret;
9770
9771 .global twofish_dec_blk_3way
9772 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9773 popq %r13;
9774 popq %r14;
9775 popq %r15;
9776 + pax_force_retaddr 0, 1
9777 ret;
9778
9779 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9780 index 7bcf3fc..f53832f 100644
9781 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9782 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9783 @@ -21,6 +21,7 @@
9784 .text
9785
9786 #include <asm/asm-offsets.h>
9787 +#include <asm/alternative-asm.h>
9788
9789 #define a_offset 0
9790 #define b_offset 4
9791 @@ -268,6 +269,7 @@ twofish_enc_blk:
9792
9793 popq R1
9794 movq $1,%rax
9795 + pax_force_retaddr 0, 1
9796 ret
9797
9798 twofish_dec_blk:
9799 @@ -319,4 +321,5 @@ twofish_dec_blk:
9800
9801 popq R1
9802 movq $1,%rax
9803 + pax_force_retaddr 0, 1
9804 ret
9805 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9806 index 07b3a68..bd2a388 100644
9807 --- a/arch/x86/ia32/ia32_aout.c
9808 +++ b/arch/x86/ia32/ia32_aout.c
9809 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9810 unsigned long dump_start, dump_size;
9811 struct user32 dump;
9812
9813 + memset(&dump, 0, sizeof(dump));
9814 +
9815 fs = get_fs();
9816 set_fs(KERNEL_DS);
9817 has_dumped = 1;
9818 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9819 index efc6a95..95abfe2 100644
9820 --- a/arch/x86/ia32/ia32_signal.c
9821 +++ b/arch/x86/ia32/ia32_signal.c
9822 @@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9823 }
9824 seg = get_fs();
9825 set_fs(KERNEL_DS);
9826 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9827 - (stack_t __force __user *) &uoss, regs->sp);
9828 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9829 + (stack_t __force_user *) &uoss, regs->sp);
9830 set_fs(seg);
9831 if (ret >= 0 && uoss_ptr) {
9832 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9833 @@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9834 sp -= frame_size;
9835 /* Align the stack pointer according to the i386 ABI,
9836 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9837 - sp = ((sp + 4) & -16ul) - 4;
9838 + sp = ((sp - 12) & -16ul) - 4;
9839 return (void __user *) sp;
9840 }
9841
9842 @@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9843 * These are actually not used anymore, but left because some
9844 * gdb versions depend on them as a marker.
9845 */
9846 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9847 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9848 } put_user_catch(err);
9849
9850 if (err)
9851 @@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9852 0xb8,
9853 __NR_ia32_rt_sigreturn,
9854 0x80cd,
9855 - 0,
9856 + 0
9857 };
9858
9859 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9860 @@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9861
9862 if (ka->sa.sa_flags & SA_RESTORER)
9863 restorer = ka->sa.sa_restorer;
9864 + else if (current->mm->context.vdso)
9865 + /* Return stub is in 32bit vsyscall page */
9866 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9867 else
9868 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9869 - rt_sigreturn);
9870 + restorer = &frame->retcode;
9871 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9872
9873 /*
9874 * Not actually used anymore, but left because some gdb
9875 * versions need it.
9876 */
9877 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9878 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9879 } put_user_catch(err);
9880
9881 err |= copy_siginfo_to_user32(&frame->info, info);
9882 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9883 index 076745f..ae8f6cb 100644
9884 --- a/arch/x86/ia32/ia32entry.S
9885 +++ b/arch/x86/ia32/ia32entry.S
9886 @@ -15,8 +15,10 @@
9887 #include <asm/irqflags.h>
9888 #include <asm/asm.h>
9889 #include <asm/smap.h>
9890 +#include <asm/pgtable.h>
9891 #include <linux/linkage.h>
9892 #include <linux/err.h>
9893 +#include <asm/alternative-asm.h>
9894
9895 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9896 #include <linux/elf-em.h>
9897 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9898 ENDPROC(native_irq_enable_sysexit)
9899 #endif
9900
9901 + .macro pax_enter_kernel_user
9902 + pax_set_fptr_mask
9903 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9904 + call pax_enter_kernel_user
9905 +#endif
9906 + .endm
9907 +
9908 + .macro pax_exit_kernel_user
9909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9910 + call pax_exit_kernel_user
9911 +#endif
9912 +#ifdef CONFIG_PAX_RANDKSTACK
9913 + pushq %rax
9914 + pushq %r11
9915 + call pax_randomize_kstack
9916 + popq %r11
9917 + popq %rax
9918 +#endif
9919 + .endm
9920 +
9921 +.macro pax_erase_kstack
9922 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9923 + call pax_erase_kstack
9924 +#endif
9925 +.endm
9926 +
9927 /*
9928 * 32bit SYSENTER instruction entry.
9929 *
9930 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9931 CFI_REGISTER rsp,rbp
9932 SWAPGS_UNSAFE_STACK
9933 movq PER_CPU_VAR(kernel_stack), %rsp
9934 - addq $(KERNEL_STACK_OFFSET),%rsp
9935 - /*
9936 - * No need to follow this irqs on/off section: the syscall
9937 - * disabled irqs, here we enable it straight after entry:
9938 - */
9939 - ENABLE_INTERRUPTS(CLBR_NONE)
9940 movl %ebp,%ebp /* zero extension */
9941 pushq_cfi $__USER32_DS
9942 /*CFI_REL_OFFSET ss,0*/
9943 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9944 CFI_REL_OFFSET rsp,0
9945 pushfq_cfi
9946 /*CFI_REL_OFFSET rflags,0*/
9947 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9948 - CFI_REGISTER rip,r10
9949 + orl $X86_EFLAGS_IF,(%rsp)
9950 + GET_THREAD_INFO(%r11)
9951 + movl TI_sysenter_return(%r11), %r11d
9952 + CFI_REGISTER rip,r11
9953 pushq_cfi $__USER32_CS
9954 /*CFI_REL_OFFSET cs,0*/
9955 movl %eax, %eax
9956 - pushq_cfi %r10
9957 + pushq_cfi %r11
9958 CFI_REL_OFFSET rip,0
9959 pushq_cfi %rax
9960 cld
9961 SAVE_ARGS 0,1,0
9962 + pax_enter_kernel_user
9963 +
9964 +#ifdef CONFIG_PAX_RANDKSTACK
9965 + pax_erase_kstack
9966 +#endif
9967 +
9968 + /*
9969 + * No need to follow this irqs on/off section: the syscall
9970 + * disabled irqs, here we enable it straight after entry:
9971 + */
9972 + ENABLE_INTERRUPTS(CLBR_NONE)
9973 /* no need to do an access_ok check here because rbp has been
9974 32bit zero extended */
9975 +
9976 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9977 + mov $PAX_USER_SHADOW_BASE,%r11
9978 + add %r11,%rbp
9979 +#endif
9980 +
9981 ASM_STAC
9982 1: movl (%rbp),%ebp
9983 _ASM_EXTABLE(1b,ia32_badarg)
9984 ASM_CLAC
9985 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9986 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9987 + GET_THREAD_INFO(%r11)
9988 + orl $TS_COMPAT,TI_status(%r11)
9989 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9990 CFI_REMEMBER_STATE
9991 jnz sysenter_tracesys
9992 cmpq $(IA32_NR_syscalls-1),%rax
9993 @@ -162,12 +204,15 @@ sysenter_do_call:
9994 sysenter_dispatch:
9995 call *ia32_sys_call_table(,%rax,8)
9996 movq %rax,RAX-ARGOFFSET(%rsp)
9997 + GET_THREAD_INFO(%r11)
9998 DISABLE_INTERRUPTS(CLBR_NONE)
9999 TRACE_IRQS_OFF
10000 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10001 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10002 jnz sysexit_audit
10003 sysexit_from_sys_call:
10004 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10005 + pax_exit_kernel_user
10006 + pax_erase_kstack
10007 + andl $~TS_COMPAT,TI_status(%r11)
10008 /* clear IF, that popfq doesn't enable interrupts early */
10009 andl $~0x200,EFLAGS-R11(%rsp)
10010 movl RIP-R11(%rsp),%edx /* User %eip */
10011 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
10012 movl %eax,%esi /* 2nd arg: syscall number */
10013 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
10014 call __audit_syscall_entry
10015 +
10016 + pax_erase_kstack
10017 +
10018 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
10019 cmpq $(IA32_NR_syscalls-1),%rax
10020 ja ia32_badsys
10021 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
10022 .endm
10023
10024 .macro auditsys_exit exit
10025 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10026 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10027 jnz ia32_ret_from_sys_call
10028 TRACE_IRQS_ON
10029 sti
10030 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
10031 1: setbe %al /* 1 if error, 0 if not */
10032 movzbl %al,%edi /* zero-extend that into %edi */
10033 call __audit_syscall_exit
10034 + GET_THREAD_INFO(%r11)
10035 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
10036 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
10037 cli
10038 TRACE_IRQS_OFF
10039 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10040 + testl %edi,TI_flags(%r11)
10041 jz \exit
10042 CLEAR_RREGS -ARGOFFSET
10043 jmp int_with_check
10044 @@ -237,7 +286,7 @@ sysexit_audit:
10045
10046 sysenter_tracesys:
10047 #ifdef CONFIG_AUDITSYSCALL
10048 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10049 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10050 jz sysenter_auditsys
10051 #endif
10052 SAVE_REST
10053 @@ -249,6 +298,9 @@ sysenter_tracesys:
10054 RESTORE_REST
10055 cmpq $(IA32_NR_syscalls-1),%rax
10056 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
10057 +
10058 + pax_erase_kstack
10059 +
10060 jmp sysenter_do_call
10061 CFI_ENDPROC
10062 ENDPROC(ia32_sysenter_target)
10063 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
10064 ENTRY(ia32_cstar_target)
10065 CFI_STARTPROC32 simple
10066 CFI_SIGNAL_FRAME
10067 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
10068 + CFI_DEF_CFA rsp,0
10069 CFI_REGISTER rip,rcx
10070 /*CFI_REGISTER rflags,r11*/
10071 SWAPGS_UNSAFE_STACK
10072 movl %esp,%r8d
10073 CFI_REGISTER rsp,r8
10074 movq PER_CPU_VAR(kernel_stack),%rsp
10075 + SAVE_ARGS 8*6,0,0
10076 + pax_enter_kernel_user
10077 +
10078 +#ifdef CONFIG_PAX_RANDKSTACK
10079 + pax_erase_kstack
10080 +#endif
10081 +
10082 /*
10083 * No need to follow this irqs on/off section: the syscall
10084 * disabled irqs and here we enable it straight after entry:
10085 */
10086 ENABLE_INTERRUPTS(CLBR_NONE)
10087 - SAVE_ARGS 8,0,0
10088 movl %eax,%eax /* zero extension */
10089 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
10090 movq %rcx,RIP-ARGOFFSET(%rsp)
10091 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
10092 /* no need to do an access_ok check here because r8 has been
10093 32bit zero extended */
10094 /* hardware stack frame is complete now */
10095 +
10096 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10097 + mov $PAX_USER_SHADOW_BASE,%r11
10098 + add %r11,%r8
10099 +#endif
10100 +
10101 ASM_STAC
10102 1: movl (%r8),%r9d
10103 _ASM_EXTABLE(1b,ia32_badarg)
10104 ASM_CLAC
10105 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10106 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10107 + GET_THREAD_INFO(%r11)
10108 + orl $TS_COMPAT,TI_status(%r11)
10109 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10110 CFI_REMEMBER_STATE
10111 jnz cstar_tracesys
10112 cmpq $IA32_NR_syscalls-1,%rax
10113 @@ -319,12 +384,15 @@ cstar_do_call:
10114 cstar_dispatch:
10115 call *ia32_sys_call_table(,%rax,8)
10116 movq %rax,RAX-ARGOFFSET(%rsp)
10117 + GET_THREAD_INFO(%r11)
10118 DISABLE_INTERRUPTS(CLBR_NONE)
10119 TRACE_IRQS_OFF
10120 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10121 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10122 jnz sysretl_audit
10123 sysretl_from_sys_call:
10124 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10125 + pax_exit_kernel_user
10126 + pax_erase_kstack
10127 + andl $~TS_COMPAT,TI_status(%r11)
10128 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
10129 movl RIP-ARGOFFSET(%rsp),%ecx
10130 CFI_REGISTER rip,rcx
10131 @@ -352,7 +420,7 @@ sysretl_audit:
10132
10133 cstar_tracesys:
10134 #ifdef CONFIG_AUDITSYSCALL
10135 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10136 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10137 jz cstar_auditsys
10138 #endif
10139 xchgl %r9d,%ebp
10140 @@ -366,6 +434,9 @@ cstar_tracesys:
10141 xchgl %ebp,%r9d
10142 cmpq $(IA32_NR_syscalls-1),%rax
10143 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
10144 +
10145 + pax_erase_kstack
10146 +
10147 jmp cstar_do_call
10148 END(ia32_cstar_target)
10149
10150 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
10151 CFI_REL_OFFSET rip,RIP-RIP
10152 PARAVIRT_ADJUST_EXCEPTION_FRAME
10153 SWAPGS
10154 - /*
10155 - * No need to follow this irqs on/off section: the syscall
10156 - * disabled irqs and here we enable it straight after entry:
10157 - */
10158 - ENABLE_INTERRUPTS(CLBR_NONE)
10159 movl %eax,%eax
10160 pushq_cfi %rax
10161 cld
10162 /* note the registers are not zero extended to the sf.
10163 this could be a problem. */
10164 SAVE_ARGS 0,1,0
10165 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10166 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10167 + pax_enter_kernel_user
10168 +
10169 +#ifdef CONFIG_PAX_RANDKSTACK
10170 + pax_erase_kstack
10171 +#endif
10172 +
10173 + /*
10174 + * No need to follow this irqs on/off section: the syscall
10175 + * disabled irqs and here we enable it straight after entry:
10176 + */
10177 + ENABLE_INTERRUPTS(CLBR_NONE)
10178 + GET_THREAD_INFO(%r11)
10179 + orl $TS_COMPAT,TI_status(%r11)
10180 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10181 jnz ia32_tracesys
10182 cmpq $(IA32_NR_syscalls-1),%rax
10183 ja ia32_badsys
10184 @@ -442,6 +520,9 @@ ia32_tracesys:
10185 RESTORE_REST
10186 cmpq $(IA32_NR_syscalls-1),%rax
10187 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
10188 +
10189 + pax_erase_kstack
10190 +
10191 jmp ia32_do_call
10192 END(ia32_syscall)
10193
10194 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
10195 index 86d68d1..f9960fe 100644
10196 --- a/arch/x86/ia32/sys_ia32.c
10197 +++ b/arch/x86/ia32/sys_ia32.c
10198 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
10199 */
10200 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
10201 {
10202 - typeof(ubuf->st_uid) uid = 0;
10203 - typeof(ubuf->st_gid) gid = 0;
10204 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
10205 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
10206 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
10207 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
10208 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
10209 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
10210 mm_segment_t old_fs = get_fs();
10211
10212 set_fs(KERNEL_DS);
10213 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
10214 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
10215 set_fs(old_fs);
10216 if (put_compat_timespec(&t, interval))
10217 return -EFAULT;
10218 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
10219 mm_segment_t old_fs = get_fs();
10220
10221 set_fs(KERNEL_DS);
10222 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
10223 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
10224 set_fs(old_fs);
10225 if (!ret) {
10226 switch (_NSIG_WORDS) {
10227 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
10228 if (copy_siginfo_from_user32(&info, uinfo))
10229 return -EFAULT;
10230 set_fs(KERNEL_DS);
10231 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
10232 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
10233 set_fs(old_fs);
10234 return ret;
10235 }
10236 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
10237 return -EFAULT;
10238
10239 set_fs(KERNEL_DS);
10240 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
10241 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
10242 count);
10243 set_fs(old_fs);
10244
10245 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
10246 index 372231c..a5aa1a1 100644
10247 --- a/arch/x86/include/asm/alternative-asm.h
10248 +++ b/arch/x86/include/asm/alternative-asm.h
10249 @@ -18,6 +18,45 @@
10250 .endm
10251 #endif
10252
10253 +#ifdef KERNEXEC_PLUGIN
10254 + .macro pax_force_retaddr_bts rip=0
10255 + btsq $63,\rip(%rsp)
10256 + .endm
10257 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10258 + .macro pax_force_retaddr rip=0, reload=0
10259 + btsq $63,\rip(%rsp)
10260 + .endm
10261 + .macro pax_force_fptr ptr
10262 + btsq $63,\ptr
10263 + .endm
10264 + .macro pax_set_fptr_mask
10265 + .endm
10266 +#endif
10267 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
10268 + .macro pax_force_retaddr rip=0, reload=0
10269 + .if \reload
10270 + pax_set_fptr_mask
10271 + .endif
10272 + orq %r10,\rip(%rsp)
10273 + .endm
10274 + .macro pax_force_fptr ptr
10275 + orq %r10,\ptr
10276 + .endm
10277 + .macro pax_set_fptr_mask
10278 + movabs $0x8000000000000000,%r10
10279 + .endm
10280 +#endif
10281 +#else
10282 + .macro pax_force_retaddr rip=0, reload=0
10283 + .endm
10284 + .macro pax_force_fptr ptr
10285 + .endm
10286 + .macro pax_force_retaddr_bts rip=0
10287 + .endm
10288 + .macro pax_set_fptr_mask
10289 + .endm
10290 +#endif
10291 +
10292 .macro altinstruction_entry orig alt feature orig_len alt_len
10293 .long \orig - .
10294 .long \alt - .
10295 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
10296 index 58ed6d9..f1cbe58 100644
10297 --- a/arch/x86/include/asm/alternative.h
10298 +++ b/arch/x86/include/asm/alternative.h
10299 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10300 ".pushsection .discard,\"aw\",@progbits\n" \
10301 DISCARD_ENTRY(1) \
10302 ".popsection\n" \
10303 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10304 + ".pushsection .altinstr_replacement, \"a\"\n" \
10305 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
10306 ".popsection"
10307
10308 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10309 DISCARD_ENTRY(1) \
10310 DISCARD_ENTRY(2) \
10311 ".popsection\n" \
10312 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10313 + ".pushsection .altinstr_replacement, \"a\"\n" \
10314 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
10315 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
10316 ".popsection"
10317 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
10318 index 3388034..ba52312 100644
10319 --- a/arch/x86/include/asm/apic.h
10320 +++ b/arch/x86/include/asm/apic.h
10321 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
10322
10323 #ifdef CONFIG_X86_LOCAL_APIC
10324
10325 -extern unsigned int apic_verbosity;
10326 +extern int apic_verbosity;
10327 extern int local_apic_timer_c2_ok;
10328
10329 extern int disable_apic;
10330 @@ -391,7 +391,7 @@ struct apic {
10331 */
10332 int (*x86_32_numa_cpu_node)(int cpu);
10333 #endif
10334 -};
10335 +} __do_const;
10336
10337 /*
10338 * Pointer to the local APIC driver in use on this system (there's
10339 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
10340 index 20370c6..a2eb9b0 100644
10341 --- a/arch/x86/include/asm/apm.h
10342 +++ b/arch/x86/include/asm/apm.h
10343 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
10344 __asm__ __volatile__(APM_DO_ZERO_SEGS
10345 "pushl %%edi\n\t"
10346 "pushl %%ebp\n\t"
10347 - "lcall *%%cs:apm_bios_entry\n\t"
10348 + "lcall *%%ss:apm_bios_entry\n\t"
10349 "setc %%al\n\t"
10350 "popl %%ebp\n\t"
10351 "popl %%edi\n\t"
10352 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
10353 __asm__ __volatile__(APM_DO_ZERO_SEGS
10354 "pushl %%edi\n\t"
10355 "pushl %%ebp\n\t"
10356 - "lcall *%%cs:apm_bios_entry\n\t"
10357 + "lcall *%%ss:apm_bios_entry\n\t"
10358 "setc %%bl\n\t"
10359 "popl %%ebp\n\t"
10360 "popl %%edi\n\t"
10361 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10362 index b6c3b82..b4c077a 100644
10363 --- a/arch/x86/include/asm/atomic.h
10364 +++ b/arch/x86/include/asm/atomic.h
10365 @@ -22,7 +22,18 @@
10366 */
10367 static inline int atomic_read(const atomic_t *v)
10368 {
10369 - return (*(volatile int *)&(v)->counter);
10370 + return (*(volatile const int *)&(v)->counter);
10371 +}
10372 +
10373 +/**
10374 + * atomic_read_unchecked - read atomic variable
10375 + * @v: pointer of type atomic_unchecked_t
10376 + *
10377 + * Atomically reads the value of @v.
10378 + */
10379 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10380 +{
10381 + return (*(volatile const int *)&(v)->counter);
10382 }
10383
10384 /**
10385 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10386 }
10387
10388 /**
10389 + * atomic_set_unchecked - set atomic variable
10390 + * @v: pointer of type atomic_unchecked_t
10391 + * @i: required value
10392 + *
10393 + * Atomically sets the value of @v to @i.
10394 + */
10395 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10396 +{
10397 + v->counter = i;
10398 +}
10399 +
10400 +/**
10401 * atomic_add - add integer to atomic variable
10402 * @i: integer value to add
10403 * @v: pointer of type atomic_t
10404 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10405 */
10406 static inline void atomic_add(int i, atomic_t *v)
10407 {
10408 - asm volatile(LOCK_PREFIX "addl %1,%0"
10409 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10410 +
10411 +#ifdef CONFIG_PAX_REFCOUNT
10412 + "jno 0f\n"
10413 + LOCK_PREFIX "subl %1,%0\n"
10414 + "int $4\n0:\n"
10415 + _ASM_EXTABLE(0b, 0b)
10416 +#endif
10417 +
10418 + : "+m" (v->counter)
10419 + : "ir" (i));
10420 +}
10421 +
10422 +/**
10423 + * atomic_add_unchecked - add integer to atomic variable
10424 + * @i: integer value to add
10425 + * @v: pointer of type atomic_unchecked_t
10426 + *
10427 + * Atomically adds @i to @v.
10428 + */
10429 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10430 +{
10431 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10432 : "+m" (v->counter)
10433 : "ir" (i));
10434 }
10435 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10436 */
10437 static inline void atomic_sub(int i, atomic_t *v)
10438 {
10439 - asm volatile(LOCK_PREFIX "subl %1,%0"
10440 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10441 +
10442 +#ifdef CONFIG_PAX_REFCOUNT
10443 + "jno 0f\n"
10444 + LOCK_PREFIX "addl %1,%0\n"
10445 + "int $4\n0:\n"
10446 + _ASM_EXTABLE(0b, 0b)
10447 +#endif
10448 +
10449 + : "+m" (v->counter)
10450 + : "ir" (i));
10451 +}
10452 +
10453 +/**
10454 + * atomic_sub_unchecked - subtract integer from atomic variable
10455 + * @i: integer value to subtract
10456 + * @v: pointer of type atomic_unchecked_t
10457 + *
10458 + * Atomically subtracts @i from @v.
10459 + */
10460 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10461 +{
10462 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10463 : "+m" (v->counter)
10464 : "ir" (i));
10465 }
10466 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10467 {
10468 unsigned char c;
10469
10470 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10471 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
10472 +
10473 +#ifdef CONFIG_PAX_REFCOUNT
10474 + "jno 0f\n"
10475 + LOCK_PREFIX "addl %2,%0\n"
10476 + "int $4\n0:\n"
10477 + _ASM_EXTABLE(0b, 0b)
10478 +#endif
10479 +
10480 + "sete %1\n"
10481 : "+m" (v->counter), "=qm" (c)
10482 : "ir" (i) : "memory");
10483 return c;
10484 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10485 */
10486 static inline void atomic_inc(atomic_t *v)
10487 {
10488 - asm volatile(LOCK_PREFIX "incl %0"
10489 + asm volatile(LOCK_PREFIX "incl %0\n"
10490 +
10491 +#ifdef CONFIG_PAX_REFCOUNT
10492 + "jno 0f\n"
10493 + LOCK_PREFIX "decl %0\n"
10494 + "int $4\n0:\n"
10495 + _ASM_EXTABLE(0b, 0b)
10496 +#endif
10497 +
10498 + : "+m" (v->counter));
10499 +}
10500 +
10501 +/**
10502 + * atomic_inc_unchecked - increment atomic variable
10503 + * @v: pointer of type atomic_unchecked_t
10504 + *
10505 + * Atomically increments @v by 1.
10506 + */
10507 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10508 +{
10509 + asm volatile(LOCK_PREFIX "incl %0\n"
10510 : "+m" (v->counter));
10511 }
10512
10513 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10514 */
10515 static inline void atomic_dec(atomic_t *v)
10516 {
10517 - asm volatile(LOCK_PREFIX "decl %0"
10518 + asm volatile(LOCK_PREFIX "decl %0\n"
10519 +
10520 +#ifdef CONFIG_PAX_REFCOUNT
10521 + "jno 0f\n"
10522 + LOCK_PREFIX "incl %0\n"
10523 + "int $4\n0:\n"
10524 + _ASM_EXTABLE(0b, 0b)
10525 +#endif
10526 +
10527 + : "+m" (v->counter));
10528 +}
10529 +
10530 +/**
10531 + * atomic_dec_unchecked - decrement atomic variable
10532 + * @v: pointer of type atomic_unchecked_t
10533 + *
10534 + * Atomically decrements @v by 1.
10535 + */
10536 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10537 +{
10538 + asm volatile(LOCK_PREFIX "decl %0\n"
10539 : "+m" (v->counter));
10540 }
10541
10542 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10543 {
10544 unsigned char c;
10545
10546 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
10547 + asm volatile(LOCK_PREFIX "decl %0\n"
10548 +
10549 +#ifdef CONFIG_PAX_REFCOUNT
10550 + "jno 0f\n"
10551 + LOCK_PREFIX "incl %0\n"
10552 + "int $4\n0:\n"
10553 + _ASM_EXTABLE(0b, 0b)
10554 +#endif
10555 +
10556 + "sete %1\n"
10557 : "+m" (v->counter), "=qm" (c)
10558 : : "memory");
10559 return c != 0;
10560 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10561 {
10562 unsigned char c;
10563
10564 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
10565 + asm volatile(LOCK_PREFIX "incl %0\n"
10566 +
10567 +#ifdef CONFIG_PAX_REFCOUNT
10568 + "jno 0f\n"
10569 + LOCK_PREFIX "decl %0\n"
10570 + "int $4\n0:\n"
10571 + _ASM_EXTABLE(0b, 0b)
10572 +#endif
10573 +
10574 + "sete %1\n"
10575 + : "+m" (v->counter), "=qm" (c)
10576 + : : "memory");
10577 + return c != 0;
10578 +}
10579 +
10580 +/**
10581 + * atomic_inc_and_test_unchecked - increment and test
10582 + * @v: pointer of type atomic_unchecked_t
10583 + *
10584 + * Atomically increments @v by 1
10585 + * and returns true if the result is zero, or false for all
10586 + * other cases.
10587 + */
10588 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10589 +{
10590 + unsigned char c;
10591 +
10592 + asm volatile(LOCK_PREFIX "incl %0\n"
10593 + "sete %1\n"
10594 : "+m" (v->counter), "=qm" (c)
10595 : : "memory");
10596 return c != 0;
10597 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10598 {
10599 unsigned char c;
10600
10601 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10602 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
10603 +
10604 +#ifdef CONFIG_PAX_REFCOUNT
10605 + "jno 0f\n"
10606 + LOCK_PREFIX "subl %2,%0\n"
10607 + "int $4\n0:\n"
10608 + _ASM_EXTABLE(0b, 0b)
10609 +#endif
10610 +
10611 + "sets %1\n"
10612 : "+m" (v->counter), "=qm" (c)
10613 : "ir" (i) : "memory");
10614 return c;
10615 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10616 goto no_xadd;
10617 #endif
10618 /* Modern 486+ processor */
10619 - return i + xadd(&v->counter, i);
10620 + return i + xadd_check_overflow(&v->counter, i);
10621
10622 #ifdef CONFIG_M386
10623 no_xadd: /* Legacy 386 processor */
10624 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10625 }
10626
10627 /**
10628 + * atomic_add_return_unchecked - add integer and return
10629 + * @i: integer value to add
10630 + * @v: pointer of type atomic_unchecked_t
10631 + *
10632 + * Atomically adds @i to @v and returns @i + @v
10633 + */
10634 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10635 +{
10636 +#ifdef CONFIG_M386
10637 + int __i;
10638 + unsigned long flags;
10639 + if (unlikely(boot_cpu_data.x86 <= 3))
10640 + goto no_xadd;
10641 +#endif
10642 + /* Modern 486+ processor */
10643 + return i + xadd(&v->counter, i);
10644 +
10645 +#ifdef CONFIG_M386
10646 +no_xadd: /* Legacy 386 processor */
10647 + raw_local_irq_save(flags);
10648 + __i = atomic_read_unchecked(v);
10649 + atomic_set_unchecked(v, i + __i);
10650 + raw_local_irq_restore(flags);
10651 + return i + __i;
10652 +#endif
10653 +}
10654 +
10655 +/**
10656 * atomic_sub_return - subtract integer and return
10657 * @v: pointer of type atomic_t
10658 * @i: integer value to subtract
10659 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10660 }
10661
10662 #define atomic_inc_return(v) (atomic_add_return(1, v))
10663 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10664 +{
10665 + return atomic_add_return_unchecked(1, v);
10666 +}
10667 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10668
10669 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10670 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10671 return cmpxchg(&v->counter, old, new);
10672 }
10673
10674 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10675 +{
10676 + return cmpxchg(&v->counter, old, new);
10677 +}
10678 +
10679 static inline int atomic_xchg(atomic_t *v, int new)
10680 {
10681 return xchg(&v->counter, new);
10682 }
10683
10684 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10685 +{
10686 + return xchg(&v->counter, new);
10687 +}
10688 +
10689 /**
10690 * __atomic_add_unless - add unless the number is already a given value
10691 * @v: pointer of type atomic_t
10692 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10693 */
10694 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10695 {
10696 - int c, old;
10697 + int c, old, new;
10698 c = atomic_read(v);
10699 for (;;) {
10700 - if (unlikely(c == (u)))
10701 + if (unlikely(c == u))
10702 break;
10703 - old = atomic_cmpxchg((v), c, c + (a));
10704 +
10705 + asm volatile("addl %2,%0\n"
10706 +
10707 +#ifdef CONFIG_PAX_REFCOUNT
10708 + "jno 0f\n"
10709 + "subl %2,%0\n"
10710 + "int $4\n0:\n"
10711 + _ASM_EXTABLE(0b, 0b)
10712 +#endif
10713 +
10714 + : "=r" (new)
10715 + : "0" (c), "ir" (a));
10716 +
10717 + old = atomic_cmpxchg(v, c, new);
10718 if (likely(old == c))
10719 break;
10720 c = old;
10721 @@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10722 }
10723
10724 /**
10725 + * atomic_inc_not_zero_hint - increment if not null
10726 + * @v: pointer of type atomic_t
10727 + * @hint: probable value of the atomic before the increment
10728 + *
10729 + * This version of atomic_inc_not_zero() gives a hint of probable
10730 + * value of the atomic. This helps processor to not read the memory
10731 + * before doing the atomic read/modify/write cycle, lowering
10732 + * number of bus transactions on some arches.
10733 + *
10734 + * Returns: 0 if increment was not done, 1 otherwise.
10735 + */
10736 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10737 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10738 +{
10739 + int val, c = hint, new;
10740 +
10741 + /* sanity test, should be removed by compiler if hint is a constant */
10742 + if (!hint)
10743 + return __atomic_add_unless(v, 1, 0);
10744 +
10745 + do {
10746 + asm volatile("incl %0\n"
10747 +
10748 +#ifdef CONFIG_PAX_REFCOUNT
10749 + "jno 0f\n"
10750 + "decl %0\n"
10751 + "int $4\n0:\n"
10752 + _ASM_EXTABLE(0b, 0b)
10753 +#endif
10754 +
10755 + : "=r" (new)
10756 + : "0" (c));
10757 +
10758 + val = atomic_cmpxchg(v, c, new);
10759 + if (val == c)
10760 + return 1;
10761 + c = val;
10762 + } while (c);
10763 +
10764 + return 0;
10765 +}
10766 +
10767 +/**
10768 * atomic_inc_short - increment of a short integer
10769 * @v: pointer to type int
10770 *
10771 @@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10772 #endif
10773
10774 /* These are x86-specific, used by some header files */
10775 -#define atomic_clear_mask(mask, addr) \
10776 - asm volatile(LOCK_PREFIX "andl %0,%1" \
10777 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
10778 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10779 +{
10780 + asm volatile(LOCK_PREFIX "andl %1,%0"
10781 + : "+m" (v->counter)
10782 + : "r" (~(mask))
10783 + : "memory");
10784 +}
10785
10786 -#define atomic_set_mask(mask, addr) \
10787 - asm volatile(LOCK_PREFIX "orl %0,%1" \
10788 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10789 - : "memory")
10790 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10791 +{
10792 + asm volatile(LOCK_PREFIX "andl %1,%0"
10793 + : "+m" (v->counter)
10794 + : "r" (~(mask))
10795 + : "memory");
10796 +}
10797 +
10798 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10799 +{
10800 + asm volatile(LOCK_PREFIX "orl %1,%0"
10801 + : "+m" (v->counter)
10802 + : "r" (mask)
10803 + : "memory");
10804 +}
10805 +
10806 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10807 +{
10808 + asm volatile(LOCK_PREFIX "orl %1,%0"
10809 + : "+m" (v->counter)
10810 + : "r" (mask)
10811 + : "memory");
10812 +}
10813
10814 /* Atomic operations are already serializing on x86 */
10815 #define smp_mb__before_atomic_dec() barrier()
10816 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10817 index b154de7..aadebd8 100644
10818 --- a/arch/x86/include/asm/atomic64_32.h
10819 +++ b/arch/x86/include/asm/atomic64_32.h
10820 @@ -12,6 +12,14 @@ typedef struct {
10821 u64 __aligned(8) counter;
10822 } atomic64_t;
10823
10824 +#ifdef CONFIG_PAX_REFCOUNT
10825 +typedef struct {
10826 + u64 __aligned(8) counter;
10827 +} atomic64_unchecked_t;
10828 +#else
10829 +typedef atomic64_t atomic64_unchecked_t;
10830 +#endif
10831 +
10832 #define ATOMIC64_INIT(val) { (val) }
10833
10834 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10835 @@ -37,21 +45,31 @@ typedef struct {
10836 ATOMIC64_DECL_ONE(sym##_386)
10837
10838 ATOMIC64_DECL_ONE(add_386);
10839 +ATOMIC64_DECL_ONE(add_unchecked_386);
10840 ATOMIC64_DECL_ONE(sub_386);
10841 +ATOMIC64_DECL_ONE(sub_unchecked_386);
10842 ATOMIC64_DECL_ONE(inc_386);
10843 +ATOMIC64_DECL_ONE(inc_unchecked_386);
10844 ATOMIC64_DECL_ONE(dec_386);
10845 +ATOMIC64_DECL_ONE(dec_unchecked_386);
10846 #endif
10847
10848 #define alternative_atomic64(f, out, in...) \
10849 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10850
10851 ATOMIC64_DECL(read);
10852 +ATOMIC64_DECL(read_unchecked);
10853 ATOMIC64_DECL(set);
10854 +ATOMIC64_DECL(set_unchecked);
10855 ATOMIC64_DECL(xchg);
10856 ATOMIC64_DECL(add_return);
10857 +ATOMIC64_DECL(add_return_unchecked);
10858 ATOMIC64_DECL(sub_return);
10859 +ATOMIC64_DECL(sub_return_unchecked);
10860 ATOMIC64_DECL(inc_return);
10861 +ATOMIC64_DECL(inc_return_unchecked);
10862 ATOMIC64_DECL(dec_return);
10863 +ATOMIC64_DECL(dec_return_unchecked);
10864 ATOMIC64_DECL(dec_if_positive);
10865 ATOMIC64_DECL(inc_not_zero);
10866 ATOMIC64_DECL(add_unless);
10867 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10868 }
10869
10870 /**
10871 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10872 + * @p: pointer to type atomic64_unchecked_t
10873 + * @o: expected value
10874 + * @n: new value
10875 + *
10876 + * Atomically sets @v to @n if it was equal to @o and returns
10877 + * the old value.
10878 + */
10879 +
10880 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10881 +{
10882 + return cmpxchg64(&v->counter, o, n);
10883 +}
10884 +
10885 +/**
10886 * atomic64_xchg - xchg atomic64 variable
10887 * @v: pointer to type atomic64_t
10888 * @n: value to assign
10889 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10890 }
10891
10892 /**
10893 + * atomic64_set_unchecked - set atomic64 variable
10894 + * @v: pointer to type atomic64_unchecked_t
10895 + * @n: value to assign
10896 + *
10897 + * Atomically sets the value of @v to @n.
10898 + */
10899 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10900 +{
10901 + unsigned high = (unsigned)(i >> 32);
10902 + unsigned low = (unsigned)i;
10903 + alternative_atomic64(set, /* no output */,
10904 + "S" (v), "b" (low), "c" (high)
10905 + : "eax", "edx", "memory");
10906 +}
10907 +
10908 +/**
10909 * atomic64_read - read atomic64 variable
10910 * @v: pointer to type atomic64_t
10911 *
10912 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10913 }
10914
10915 /**
10916 + * atomic64_read_unchecked - read atomic64 variable
10917 + * @v: pointer to type atomic64_unchecked_t
10918 + *
10919 + * Atomically reads the value of @v and returns it.
10920 + */
10921 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10922 +{
10923 + long long r;
10924 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10925 + return r;
10926 + }
10927 +
10928 +/**
10929 * atomic64_add_return - add and return
10930 * @i: integer value to add
10931 * @v: pointer to type atomic64_t
10932 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10933 return i;
10934 }
10935
10936 +/**
10937 + * atomic64_add_return_unchecked - add and return
10938 + * @i: integer value to add
10939 + * @v: pointer to type atomic64_unchecked_t
10940 + *
10941 + * Atomically adds @i to @v and returns @i + *@v
10942 + */
10943 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10944 +{
10945 + alternative_atomic64(add_return_unchecked,
10946 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10947 + ASM_NO_INPUT_CLOBBER("memory"));
10948 + return i;
10949 +}
10950 +
10951 /*
10952 * Other variants with different arithmetic operators:
10953 */
10954 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10955 return a;
10956 }
10957
10958 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10959 +{
10960 + long long a;
10961 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
10962 + "S" (v) : "memory", "ecx");
10963 + return a;
10964 +}
10965 +
10966 static inline long long atomic64_dec_return(atomic64_t *v)
10967 {
10968 long long a;
10969 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10970 }
10971
10972 /**
10973 + * atomic64_add_unchecked - add integer to atomic64 variable
10974 + * @i: integer value to add
10975 + * @v: pointer to type atomic64_unchecked_t
10976 + *
10977 + * Atomically adds @i to @v.
10978 + */
10979 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10980 +{
10981 + __alternative_atomic64(add_unchecked, add_return_unchecked,
10982 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10983 + ASM_NO_INPUT_CLOBBER("memory"));
10984 + return i;
10985 +}
10986 +
10987 +/**
10988 * atomic64_sub - subtract the atomic64 variable
10989 * @i: integer value to subtract
10990 * @v: pointer to type atomic64_t
10991 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10992 index 0e1cbfc..5623683 100644
10993 --- a/arch/x86/include/asm/atomic64_64.h
10994 +++ b/arch/x86/include/asm/atomic64_64.h
10995 @@ -18,7 +18,19 @@
10996 */
10997 static inline long atomic64_read(const atomic64_t *v)
10998 {
10999 - return (*(volatile long *)&(v)->counter);
11000 + return (*(volatile const long *)&(v)->counter);
11001 +}
11002 +
11003 +/**
11004 + * atomic64_read_unchecked - read atomic64 variable
11005 + * @v: pointer of type atomic64_unchecked_t
11006 + *
11007 + * Atomically reads the value of @v.
11008 + * Doesn't imply a read memory barrier.
11009 + */
11010 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
11011 +{
11012 + return (*(volatile const long *)&(v)->counter);
11013 }
11014
11015 /**
11016 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
11017 }
11018
11019 /**
11020 + * atomic64_set_unchecked - set atomic64 variable
11021 + * @v: pointer to type atomic64_unchecked_t
11022 + * @i: required value
11023 + *
11024 + * Atomically sets the value of @v to @i.
11025 + */
11026 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
11027 +{
11028 + v->counter = i;
11029 +}
11030 +
11031 +/**
11032 * atomic64_add - add integer to atomic64 variable
11033 * @i: integer value to add
11034 * @v: pointer to type atomic64_t
11035 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
11036 */
11037 static inline void atomic64_add(long i, atomic64_t *v)
11038 {
11039 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
11040 +
11041 +#ifdef CONFIG_PAX_REFCOUNT
11042 + "jno 0f\n"
11043 + LOCK_PREFIX "subq %1,%0\n"
11044 + "int $4\n0:\n"
11045 + _ASM_EXTABLE(0b, 0b)
11046 +#endif
11047 +
11048 + : "=m" (v->counter)
11049 + : "er" (i), "m" (v->counter));
11050 +}
11051 +
11052 +/**
11053 + * atomic64_add_unchecked - add integer to atomic64 variable
11054 + * @i: integer value to add
11055 + * @v: pointer to type atomic64_unchecked_t
11056 + *
11057 + * Atomically adds @i to @v.
11058 + */
11059 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
11060 +{
11061 asm volatile(LOCK_PREFIX "addq %1,%0"
11062 : "=m" (v->counter)
11063 : "er" (i), "m" (v->counter));
11064 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
11065 */
11066 static inline void atomic64_sub(long i, atomic64_t *v)
11067 {
11068 - asm volatile(LOCK_PREFIX "subq %1,%0"
11069 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
11070 +
11071 +#ifdef CONFIG_PAX_REFCOUNT
11072 + "jno 0f\n"
11073 + LOCK_PREFIX "addq %1,%0\n"
11074 + "int $4\n0:\n"
11075 + _ASM_EXTABLE(0b, 0b)
11076 +#endif
11077 +
11078 + : "=m" (v->counter)
11079 + : "er" (i), "m" (v->counter));
11080 +}
11081 +
11082 +/**
11083 + * atomic64_sub_unchecked - subtract the atomic64 variable
11084 + * @i: integer value to subtract
11085 + * @v: pointer to type atomic64_unchecked_t
11086 + *
11087 + * Atomically subtracts @i from @v.
11088 + */
11089 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
11090 +{
11091 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
11092 : "=m" (v->counter)
11093 : "er" (i), "m" (v->counter));
11094 }
11095 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11096 {
11097 unsigned char c;
11098
11099 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
11100 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
11101 +
11102 +#ifdef CONFIG_PAX_REFCOUNT
11103 + "jno 0f\n"
11104 + LOCK_PREFIX "addq %2,%0\n"
11105 + "int $4\n0:\n"
11106 + _ASM_EXTABLE(0b, 0b)
11107 +#endif
11108 +
11109 + "sete %1\n"
11110 : "=m" (v->counter), "=qm" (c)
11111 : "er" (i), "m" (v->counter) : "memory");
11112 return c;
11113 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11114 */
11115 static inline void atomic64_inc(atomic64_t *v)
11116 {
11117 + asm volatile(LOCK_PREFIX "incq %0\n"
11118 +
11119 +#ifdef CONFIG_PAX_REFCOUNT
11120 + "jno 0f\n"
11121 + LOCK_PREFIX "decq %0\n"
11122 + "int $4\n0:\n"
11123 + _ASM_EXTABLE(0b, 0b)
11124 +#endif
11125 +
11126 + : "=m" (v->counter)
11127 + : "m" (v->counter));
11128 +}
11129 +
11130 +/**
11131 + * atomic64_inc_unchecked - increment atomic64 variable
11132 + * @v: pointer to type atomic64_unchecked_t
11133 + *
11134 + * Atomically increments @v by 1.
11135 + */
11136 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
11137 +{
11138 asm volatile(LOCK_PREFIX "incq %0"
11139 : "=m" (v->counter)
11140 : "m" (v->counter));
11141 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
11142 */
11143 static inline void atomic64_dec(atomic64_t *v)
11144 {
11145 - asm volatile(LOCK_PREFIX "decq %0"
11146 + asm volatile(LOCK_PREFIX "decq %0\n"
11147 +
11148 +#ifdef CONFIG_PAX_REFCOUNT
11149 + "jno 0f\n"
11150 + LOCK_PREFIX "incq %0\n"
11151 + "int $4\n0:\n"
11152 + _ASM_EXTABLE(0b, 0b)
11153 +#endif
11154 +
11155 + : "=m" (v->counter)
11156 + : "m" (v->counter));
11157 +}
11158 +
11159 +/**
11160 + * atomic64_dec_unchecked - decrement atomic64 variable
11161 + * @v: pointer to type atomic64_t
11162 + *
11163 + * Atomically decrements @v by 1.
11164 + */
11165 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
11166 +{
11167 + asm volatile(LOCK_PREFIX "decq %0\n"
11168 : "=m" (v->counter)
11169 : "m" (v->counter));
11170 }
11171 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
11172 {
11173 unsigned char c;
11174
11175 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
11176 + asm volatile(LOCK_PREFIX "decq %0\n"
11177 +
11178 +#ifdef CONFIG_PAX_REFCOUNT
11179 + "jno 0f\n"
11180 + LOCK_PREFIX "incq %0\n"
11181 + "int $4\n0:\n"
11182 + _ASM_EXTABLE(0b, 0b)
11183 +#endif
11184 +
11185 + "sete %1\n"
11186 : "=m" (v->counter), "=qm" (c)
11187 : "m" (v->counter) : "memory");
11188 return c != 0;
11189 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
11190 {
11191 unsigned char c;
11192
11193 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
11194 + asm volatile(LOCK_PREFIX "incq %0\n"
11195 +
11196 +#ifdef CONFIG_PAX_REFCOUNT
11197 + "jno 0f\n"
11198 + LOCK_PREFIX "decq %0\n"
11199 + "int $4\n0:\n"
11200 + _ASM_EXTABLE(0b, 0b)
11201 +#endif
11202 +
11203 + "sete %1\n"
11204 : "=m" (v->counter), "=qm" (c)
11205 : "m" (v->counter) : "memory");
11206 return c != 0;
11207 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11208 {
11209 unsigned char c;
11210
11211 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
11212 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
11213 +
11214 +#ifdef CONFIG_PAX_REFCOUNT
11215 + "jno 0f\n"
11216 + LOCK_PREFIX "subq %2,%0\n"
11217 + "int $4\n0:\n"
11218 + _ASM_EXTABLE(0b, 0b)
11219 +#endif
11220 +
11221 + "sets %1\n"
11222 : "=m" (v->counter), "=qm" (c)
11223 : "er" (i), "m" (v->counter) : "memory");
11224 return c;
11225 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11226 */
11227 static inline long atomic64_add_return(long i, atomic64_t *v)
11228 {
11229 + return i + xadd_check_overflow(&v->counter, i);
11230 +}
11231 +
11232 +/**
11233 + * atomic64_add_return_unchecked - add and return
11234 + * @i: integer value to add
11235 + * @v: pointer to type atomic64_unchecked_t
11236 + *
11237 + * Atomically adds @i to @v and returns @i + @v
11238 + */
11239 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
11240 +{
11241 return i + xadd(&v->counter, i);
11242 }
11243
11244 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
11245 }
11246
11247 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
11248 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
11249 +{
11250 + return atomic64_add_return_unchecked(1, v);
11251 +}
11252 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
11253
11254 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11255 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11256 return cmpxchg(&v->counter, old, new);
11257 }
11258
11259 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
11260 +{
11261 + return cmpxchg(&v->counter, old, new);
11262 +}
11263 +
11264 static inline long atomic64_xchg(atomic64_t *v, long new)
11265 {
11266 return xchg(&v->counter, new);
11267 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
11268 */
11269 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
11270 {
11271 - long c, old;
11272 + long c, old, new;
11273 c = atomic64_read(v);
11274 for (;;) {
11275 - if (unlikely(c == (u)))
11276 + if (unlikely(c == u))
11277 break;
11278 - old = atomic64_cmpxchg((v), c, c + (a));
11279 +
11280 + asm volatile("add %2,%0\n"
11281 +
11282 +#ifdef CONFIG_PAX_REFCOUNT
11283 + "jno 0f\n"
11284 + "sub %2,%0\n"
11285 + "int $4\n0:\n"
11286 + _ASM_EXTABLE(0b, 0b)
11287 +#endif
11288 +
11289 + : "=r" (new)
11290 + : "0" (c), "ir" (a));
11291 +
11292 + old = atomic64_cmpxchg(v, c, new);
11293 if (likely(old == c))
11294 break;
11295 c = old;
11296 }
11297 - return c != (u);
11298 + return c != u;
11299 }
11300
11301 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11302 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
11303 index 6dfd019..0c6699f 100644
11304 --- a/arch/x86/include/asm/bitops.h
11305 +++ b/arch/x86/include/asm/bitops.h
11306 @@ -40,7 +40,7 @@
11307 * a mask operation on a byte.
11308 */
11309 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
11310 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
11311 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
11312 #define CONST_MASK(nr) (1 << ((nr) & 7))
11313
11314 /**
11315 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
11316 index b13fe63..0dab13a 100644
11317 --- a/arch/x86/include/asm/boot.h
11318 +++ b/arch/x86/include/asm/boot.h
11319 @@ -11,10 +11,15 @@
11320 #include <asm/pgtable_types.h>
11321
11322 /* Physical address where kernel should be loaded. */
11323 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11324 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11325 + (CONFIG_PHYSICAL_ALIGN - 1)) \
11326 & ~(CONFIG_PHYSICAL_ALIGN - 1))
11327
11328 +#ifndef __ASSEMBLY__
11329 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
11330 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
11331 +#endif
11332 +
11333 /* Minimum kernel alignment, as a power of two */
11334 #ifdef CONFIG_X86_64
11335 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
11336 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
11337 index 48f99f1..d78ebf9 100644
11338 --- a/arch/x86/include/asm/cache.h
11339 +++ b/arch/x86/include/asm/cache.h
11340 @@ -5,12 +5,13 @@
11341
11342 /* L1 cache line size */
11343 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11344 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11345 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11346
11347 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
11348 +#define __read_only __attribute__((__section__(".data..read_only")))
11349
11350 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
11351 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
11352 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
11353
11354 #ifdef CONFIG_X86_VSMP
11355 #ifdef CONFIG_SMP
11356 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
11357 index 9863ee3..4a1f8e1 100644
11358 --- a/arch/x86/include/asm/cacheflush.h
11359 +++ b/arch/x86/include/asm/cacheflush.h
11360 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11361 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11362
11363 if (pg_flags == _PGMT_DEFAULT)
11364 - return -1;
11365 + return ~0UL;
11366 else if (pg_flags == _PGMT_WC)
11367 return _PAGE_CACHE_WC;
11368 else if (pg_flags == _PGMT_UC_MINUS)
11369 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11370 index 46fc474..b02b0f9 100644
11371 --- a/arch/x86/include/asm/checksum_32.h
11372 +++ b/arch/x86/include/asm/checksum_32.h
11373 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11374 int len, __wsum sum,
11375 int *src_err_ptr, int *dst_err_ptr);
11376
11377 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11378 + int len, __wsum sum,
11379 + int *src_err_ptr, int *dst_err_ptr);
11380 +
11381 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11382 + int len, __wsum sum,
11383 + int *src_err_ptr, int *dst_err_ptr);
11384 +
11385 /*
11386 * Note: when you get a NULL pointer exception here this means someone
11387 * passed in an incorrect kernel address to one of these functions.
11388 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11389 int *err_ptr)
11390 {
11391 might_sleep();
11392 - return csum_partial_copy_generic((__force void *)src, dst,
11393 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
11394 len, sum, err_ptr, NULL);
11395 }
11396
11397 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11398 {
11399 might_sleep();
11400 if (access_ok(VERIFY_WRITE, dst, len))
11401 - return csum_partial_copy_generic(src, (__force void *)dst,
11402 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11403 len, sum, NULL, err_ptr);
11404
11405 if (len)
11406 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11407 index 8d871ea..c1a0dc9 100644
11408 --- a/arch/x86/include/asm/cmpxchg.h
11409 +++ b/arch/x86/include/asm/cmpxchg.h
11410 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11411 __compiletime_error("Bad argument size for cmpxchg");
11412 extern void __xadd_wrong_size(void)
11413 __compiletime_error("Bad argument size for xadd");
11414 +extern void __xadd_check_overflow_wrong_size(void)
11415 + __compiletime_error("Bad argument size for xadd_check_overflow");
11416 extern void __add_wrong_size(void)
11417 __compiletime_error("Bad argument size for add");
11418 +extern void __add_check_overflow_wrong_size(void)
11419 + __compiletime_error("Bad argument size for add_check_overflow");
11420
11421 /*
11422 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11423 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11424 __ret; \
11425 })
11426
11427 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11428 + ({ \
11429 + __typeof__ (*(ptr)) __ret = (arg); \
11430 + switch (sizeof(*(ptr))) { \
11431 + case __X86_CASE_L: \
11432 + asm volatile (lock #op "l %0, %1\n" \
11433 + "jno 0f\n" \
11434 + "mov %0,%1\n" \
11435 + "int $4\n0:\n" \
11436 + _ASM_EXTABLE(0b, 0b) \
11437 + : "+r" (__ret), "+m" (*(ptr)) \
11438 + : : "memory", "cc"); \
11439 + break; \
11440 + case __X86_CASE_Q: \
11441 + asm volatile (lock #op "q %q0, %1\n" \
11442 + "jno 0f\n" \
11443 + "mov %0,%1\n" \
11444 + "int $4\n0:\n" \
11445 + _ASM_EXTABLE(0b, 0b) \
11446 + : "+r" (__ret), "+m" (*(ptr)) \
11447 + : : "memory", "cc"); \
11448 + break; \
11449 + default: \
11450 + __ ## op ## _check_overflow_wrong_size(); \
11451 + } \
11452 + __ret; \
11453 + })
11454 +
11455 /*
11456 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11457 * Since this is generally used to protect other memory information, we
11458 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11459 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11460 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11461
11462 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11463 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11464 +
11465 #define __add(ptr, inc, lock) \
11466 ({ \
11467 __typeof__ (*(ptr)) __ret = (inc); \
11468 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11469 index 8c297aa..7a90f03 100644
11470 --- a/arch/x86/include/asm/cpufeature.h
11471 +++ b/arch/x86/include/asm/cpufeature.h
11472 @@ -205,7 +205,7 @@
11473 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11474 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11475 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11476 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11477 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11478 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11479 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11480 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11481 @@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11482 ".section .discard,\"aw\",@progbits\n"
11483 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11484 ".previous\n"
11485 - ".section .altinstr_replacement,\"ax\"\n"
11486 + ".section .altinstr_replacement,\"a\"\n"
11487 "3: movb $1,%0\n"
11488 "4:\n"
11489 ".previous\n"
11490 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11491 index 8bf1c06..f723dfd 100644
11492 --- a/arch/x86/include/asm/desc.h
11493 +++ b/arch/x86/include/asm/desc.h
11494 @@ -4,6 +4,7 @@
11495 #include <asm/desc_defs.h>
11496 #include <asm/ldt.h>
11497 #include <asm/mmu.h>
11498 +#include <asm/pgtable.h>
11499
11500 #include <linux/smp.h>
11501 #include <linux/percpu.h>
11502 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11503
11504 desc->type = (info->read_exec_only ^ 1) << 1;
11505 desc->type |= info->contents << 2;
11506 + desc->type |= info->seg_not_present ^ 1;
11507
11508 desc->s = 1;
11509 desc->dpl = 0x3;
11510 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11511 }
11512
11513 extern struct desc_ptr idt_descr;
11514 -extern gate_desc idt_table[];
11515 extern struct desc_ptr nmi_idt_descr;
11516 -extern gate_desc nmi_idt_table[];
11517 -
11518 -struct gdt_page {
11519 - struct desc_struct gdt[GDT_ENTRIES];
11520 -} __attribute__((aligned(PAGE_SIZE)));
11521 -
11522 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11523 +extern gate_desc idt_table[256];
11524 +extern gate_desc nmi_idt_table[256];
11525
11526 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11527 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11528 {
11529 - return per_cpu(gdt_page, cpu).gdt;
11530 + return cpu_gdt_table[cpu];
11531 }
11532
11533 #ifdef CONFIG_X86_64
11534 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11535 unsigned long base, unsigned dpl, unsigned flags,
11536 unsigned short seg)
11537 {
11538 - gate->a = (seg << 16) | (base & 0xffff);
11539 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11540 + gate->gate.offset_low = base;
11541 + gate->gate.seg = seg;
11542 + gate->gate.reserved = 0;
11543 + gate->gate.type = type;
11544 + gate->gate.s = 0;
11545 + gate->gate.dpl = dpl;
11546 + gate->gate.p = 1;
11547 + gate->gate.offset_high = base >> 16;
11548 }
11549
11550 #endif
11551 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11552
11553 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11554 {
11555 + pax_open_kernel();
11556 memcpy(&idt[entry], gate, sizeof(*gate));
11557 + pax_close_kernel();
11558 }
11559
11560 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11561 {
11562 + pax_open_kernel();
11563 memcpy(&ldt[entry], desc, 8);
11564 + pax_close_kernel();
11565 }
11566
11567 static inline void
11568 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11569 default: size = sizeof(*gdt); break;
11570 }
11571
11572 + pax_open_kernel();
11573 memcpy(&gdt[entry], desc, size);
11574 + pax_close_kernel();
11575 }
11576
11577 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11578 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11579
11580 static inline void native_load_tr_desc(void)
11581 {
11582 + pax_open_kernel();
11583 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11584 + pax_close_kernel();
11585 }
11586
11587 static inline void native_load_gdt(const struct desc_ptr *dtr)
11588 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11589 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11590 unsigned int i;
11591
11592 + pax_open_kernel();
11593 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11594 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11595 + pax_close_kernel();
11596 }
11597
11598 #define _LDT_empty(info) \
11599 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11600 }
11601
11602 #ifdef CONFIG_X86_64
11603 -static inline void set_nmi_gate(int gate, void *addr)
11604 +static inline void set_nmi_gate(int gate, const void *addr)
11605 {
11606 gate_desc s;
11607
11608 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11609 }
11610 #endif
11611
11612 -static inline void _set_gate(int gate, unsigned type, void *addr,
11613 +static inline void _set_gate(int gate, unsigned type, const void *addr,
11614 unsigned dpl, unsigned ist, unsigned seg)
11615 {
11616 gate_desc s;
11617 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11618 * Pentium F0 0F bugfix can have resulted in the mapped
11619 * IDT being write-protected.
11620 */
11621 -static inline void set_intr_gate(unsigned int n, void *addr)
11622 +static inline void set_intr_gate(unsigned int n, const void *addr)
11623 {
11624 BUG_ON((unsigned)n > 0xFF);
11625 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11626 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11627 /*
11628 * This routine sets up an interrupt gate at directory privilege level 3.
11629 */
11630 -static inline void set_system_intr_gate(unsigned int n, void *addr)
11631 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
11632 {
11633 BUG_ON((unsigned)n > 0xFF);
11634 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11635 }
11636
11637 -static inline void set_system_trap_gate(unsigned int n, void *addr)
11638 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
11639 {
11640 BUG_ON((unsigned)n > 0xFF);
11641 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11642 }
11643
11644 -static inline void set_trap_gate(unsigned int n, void *addr)
11645 +static inline void set_trap_gate(unsigned int n, const void *addr)
11646 {
11647 BUG_ON((unsigned)n > 0xFF);
11648 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11649 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11650 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11651 {
11652 BUG_ON((unsigned)n > 0xFF);
11653 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11654 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11655 }
11656
11657 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11658 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11659 {
11660 BUG_ON((unsigned)n > 0xFF);
11661 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11662 }
11663
11664 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11665 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11666 {
11667 BUG_ON((unsigned)n > 0xFF);
11668 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11669 }
11670
11671 +#ifdef CONFIG_X86_32
11672 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11673 +{
11674 + struct desc_struct d;
11675 +
11676 + if (likely(limit))
11677 + limit = (limit - 1UL) >> PAGE_SHIFT;
11678 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
11679 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11680 +}
11681 +#endif
11682 +
11683 #endif /* _ASM_X86_DESC_H */
11684 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11685 index 278441f..b95a174 100644
11686 --- a/arch/x86/include/asm/desc_defs.h
11687 +++ b/arch/x86/include/asm/desc_defs.h
11688 @@ -31,6 +31,12 @@ struct desc_struct {
11689 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11690 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11691 };
11692 + struct {
11693 + u16 offset_low;
11694 + u16 seg;
11695 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11696 + unsigned offset_high: 16;
11697 + } gate;
11698 };
11699 } __attribute__((packed));
11700
11701 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11702 index 3778256..c5d4fce 100644
11703 --- a/arch/x86/include/asm/e820.h
11704 +++ b/arch/x86/include/asm/e820.h
11705 @@ -69,7 +69,7 @@ struct e820map {
11706 #define ISA_START_ADDRESS 0xa0000
11707 #define ISA_END_ADDRESS 0x100000
11708
11709 -#define BIOS_BEGIN 0x000a0000
11710 +#define BIOS_BEGIN 0x000c0000
11711 #define BIOS_END 0x00100000
11712
11713 #define BIOS_ROM_BASE 0xffe00000
11714 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11715 index 5939f44..f8845f6 100644
11716 --- a/arch/x86/include/asm/elf.h
11717 +++ b/arch/x86/include/asm/elf.h
11718 @@ -243,7 +243,25 @@ extern int force_personality32;
11719 the loader. We need to make sure that it is out of the way of the program
11720 that it will "exec", and that there is sufficient room for the brk. */
11721
11722 +#ifdef CONFIG_PAX_SEGMEXEC
11723 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11724 +#else
11725 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11726 +#endif
11727 +
11728 +#ifdef CONFIG_PAX_ASLR
11729 +#ifdef CONFIG_X86_32
11730 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11731 +
11732 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11733 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11734 +#else
11735 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
11736 +
11737 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11738 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11739 +#endif
11740 +#endif
11741
11742 /* This yields a mask that user programs can use to figure out what
11743 instruction set this CPU supports. This could be done in user space,
11744 @@ -296,16 +314,12 @@ do { \
11745
11746 #define ARCH_DLINFO \
11747 do { \
11748 - if (vdso_enabled) \
11749 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11750 - (unsigned long)current->mm->context.vdso); \
11751 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11752 } while (0)
11753
11754 #define ARCH_DLINFO_X32 \
11755 do { \
11756 - if (vdso_enabled) \
11757 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11758 - (unsigned long)current->mm->context.vdso); \
11759 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11760 } while (0)
11761
11762 #define AT_SYSINFO 32
11763 @@ -320,7 +334,7 @@ else \
11764
11765 #endif /* !CONFIG_X86_32 */
11766
11767 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11768 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11769
11770 #define VDSO_ENTRY \
11771 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11772 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11773 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11774 #define compat_arch_setup_additional_pages syscall32_setup_pages
11775
11776 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11777 -#define arch_randomize_brk arch_randomize_brk
11778 -
11779 /*
11780 * True on X86_32 or when emulating IA32 on X86_64
11781 */
11782 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11783 index 75ce3f4..882e801 100644
11784 --- a/arch/x86/include/asm/emergency-restart.h
11785 +++ b/arch/x86/include/asm/emergency-restart.h
11786 @@ -13,6 +13,6 @@ enum reboot_type {
11787
11788 extern enum reboot_type reboot_type;
11789
11790 -extern void machine_emergency_restart(void);
11791 +extern void machine_emergency_restart(void) __noreturn;
11792
11793 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11794 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11795 index 41ab26e..a88c9e6 100644
11796 --- a/arch/x86/include/asm/fpu-internal.h
11797 +++ b/arch/x86/include/asm/fpu-internal.h
11798 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11799 ({ \
11800 int err; \
11801 asm volatile(ASM_STAC "\n" \
11802 - "1:" #insn "\n\t" \
11803 + "1:" \
11804 + __copyuser_seg \
11805 + #insn "\n\t" \
11806 "2: " ASM_CLAC "\n" \
11807 ".section .fixup,\"ax\"\n" \
11808 "3: movl $-1,%[err]\n" \
11809 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11810 "emms\n\t" /* clear stack tags */
11811 "fildl %P[addr]", /* set F?P to defined value */
11812 X86_FEATURE_FXSAVE_LEAK,
11813 - [addr] "m" (tsk->thread.fpu.has_fpu));
11814 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11815
11816 return fpu_restore_checking(&tsk->thread.fpu);
11817 }
11818 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11819 index f373046..02653e2 100644
11820 --- a/arch/x86/include/asm/futex.h
11821 +++ b/arch/x86/include/asm/futex.h
11822 @@ -12,6 +12,7 @@
11823 #include <asm/smap.h>
11824
11825 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11826 + typecheck(u32 __user *, uaddr); \
11827 asm volatile("\t" ASM_STAC "\n" \
11828 "1:\t" insn "\n" \
11829 "2:\t" ASM_CLAC "\n" \
11830 @@ -20,15 +21,16 @@
11831 "\tjmp\t2b\n" \
11832 "\t.previous\n" \
11833 _ASM_EXTABLE(1b, 3b) \
11834 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11835 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11836 : "i" (-EFAULT), "0" (oparg), "1" (0))
11837
11838 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11839 + typecheck(u32 __user *, uaddr); \
11840 asm volatile("\t" ASM_STAC "\n" \
11841 "1:\tmovl %2, %0\n" \
11842 "\tmovl\t%0, %3\n" \
11843 "\t" insn "\n" \
11844 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11845 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11846 "\tjnz\t1b\n" \
11847 "3:\t" ASM_CLAC "\n" \
11848 "\t.section .fixup,\"ax\"\n" \
11849 @@ -38,7 +40,7 @@
11850 _ASM_EXTABLE(1b, 4b) \
11851 _ASM_EXTABLE(2b, 4b) \
11852 : "=&a" (oldval), "=&r" (ret), \
11853 - "+m" (*uaddr), "=&r" (tem) \
11854 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11855 : "r" (oparg), "i" (-EFAULT), "1" (0))
11856
11857 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11858 @@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11859
11860 switch (op) {
11861 case FUTEX_OP_SET:
11862 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11863 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11864 break;
11865 case FUTEX_OP_ADD:
11866 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11867 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11868 uaddr, oparg);
11869 break;
11870 case FUTEX_OP_OR:
11871 @@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11872 return -EFAULT;
11873
11874 asm volatile("\t" ASM_STAC "\n"
11875 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11876 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11877 "2:\t" ASM_CLAC "\n"
11878 "\t.section .fixup, \"ax\"\n"
11879 "3:\tmov %3, %0\n"
11880 "\tjmp 2b\n"
11881 "\t.previous\n"
11882 _ASM_EXTABLE(1b, 3b)
11883 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11884 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11885 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11886 : "memory"
11887 );
11888 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11889 index eb92a6e..b98b2f4 100644
11890 --- a/arch/x86/include/asm/hw_irq.h
11891 +++ b/arch/x86/include/asm/hw_irq.h
11892 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11893 extern void enable_IO_APIC(void);
11894
11895 /* Statistics */
11896 -extern atomic_t irq_err_count;
11897 -extern atomic_t irq_mis_count;
11898 +extern atomic_unchecked_t irq_err_count;
11899 +extern atomic_unchecked_t irq_mis_count;
11900
11901 /* EISA */
11902 extern void eisa_set_level_irq(unsigned int irq);
11903 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11904 index d8e8eef..15b1179 100644
11905 --- a/arch/x86/include/asm/io.h
11906 +++ b/arch/x86/include/asm/io.h
11907 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11908 return ioremap_nocache(offset, size);
11909 }
11910
11911 -extern void iounmap(volatile void __iomem *addr);
11912 +extern void iounmap(const volatile void __iomem *addr);
11913
11914 extern void set_iounmap_nonlazy(void);
11915
11916 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11917
11918 #include <linux/vmalloc.h>
11919
11920 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11921 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11922 +{
11923 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11924 +}
11925 +
11926 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11927 +{
11928 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11929 +}
11930 +
11931 /*
11932 * Convert a virtual cached pointer to an uncached pointer
11933 */
11934 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11935 index bba3cf8..06bc8da 100644
11936 --- a/arch/x86/include/asm/irqflags.h
11937 +++ b/arch/x86/include/asm/irqflags.h
11938 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11939 sti; \
11940 sysexit
11941
11942 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
11943 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11944 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
11945 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11946 +
11947 #else
11948 #define INTERRUPT_RETURN iret
11949 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11950 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11951 index d3ddd17..c9fb0cc 100644
11952 --- a/arch/x86/include/asm/kprobes.h
11953 +++ b/arch/x86/include/asm/kprobes.h
11954 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11955 #define RELATIVEJUMP_SIZE 5
11956 #define RELATIVECALL_OPCODE 0xe8
11957 #define RELATIVE_ADDR_SIZE 4
11958 -#define MAX_STACK_SIZE 64
11959 -#define MIN_STACK_SIZE(ADDR) \
11960 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11961 - THREAD_SIZE - (unsigned long)(ADDR))) \
11962 - ? (MAX_STACK_SIZE) \
11963 - : (((unsigned long)current_thread_info()) + \
11964 - THREAD_SIZE - (unsigned long)(ADDR)))
11965 +#define MAX_STACK_SIZE 64UL
11966 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11967
11968 #define flush_insn_slot(p) do { } while (0)
11969
11970 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
11971 index b2e11f4..f293e2e 100644
11972 --- a/arch/x86/include/asm/kvm_host.h
11973 +++ b/arch/x86/include/asm/kvm_host.h
11974 @@ -707,7 +707,7 @@ struct kvm_x86_ops {
11975 int (*check_intercept)(struct kvm_vcpu *vcpu,
11976 struct x86_instruction_info *info,
11977 enum x86_intercept_stage stage);
11978 -};
11979 +} __do_const;
11980
11981 struct kvm_arch_async_pf {
11982 u32 token;
11983 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11984 index c8bed0d..85c03fd 100644
11985 --- a/arch/x86/include/asm/local.h
11986 +++ b/arch/x86/include/asm/local.h
11987 @@ -10,33 +10,97 @@ typedef struct {
11988 atomic_long_t a;
11989 } local_t;
11990
11991 +typedef struct {
11992 + atomic_long_unchecked_t a;
11993 +} local_unchecked_t;
11994 +
11995 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11996
11997 #define local_read(l) atomic_long_read(&(l)->a)
11998 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11999 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
12000 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
12001
12002 static inline void local_inc(local_t *l)
12003 {
12004 - asm volatile(_ASM_INC "%0"
12005 + asm volatile(_ASM_INC "%0\n"
12006 +
12007 +#ifdef CONFIG_PAX_REFCOUNT
12008 + "jno 0f\n"
12009 + _ASM_DEC "%0\n"
12010 + "int $4\n0:\n"
12011 + _ASM_EXTABLE(0b, 0b)
12012 +#endif
12013 +
12014 + : "+m" (l->a.counter));
12015 +}
12016 +
12017 +static inline void local_inc_unchecked(local_unchecked_t *l)
12018 +{
12019 + asm volatile(_ASM_INC "%0\n"
12020 : "+m" (l->a.counter));
12021 }
12022
12023 static inline void local_dec(local_t *l)
12024 {
12025 - asm volatile(_ASM_DEC "%0"
12026 + asm volatile(_ASM_DEC "%0\n"
12027 +
12028 +#ifdef CONFIG_PAX_REFCOUNT
12029 + "jno 0f\n"
12030 + _ASM_INC "%0\n"
12031 + "int $4\n0:\n"
12032 + _ASM_EXTABLE(0b, 0b)
12033 +#endif
12034 +
12035 + : "+m" (l->a.counter));
12036 +}
12037 +
12038 +static inline void local_dec_unchecked(local_unchecked_t *l)
12039 +{
12040 + asm volatile(_ASM_DEC "%0\n"
12041 : "+m" (l->a.counter));
12042 }
12043
12044 static inline void local_add(long i, local_t *l)
12045 {
12046 - asm volatile(_ASM_ADD "%1,%0"
12047 + asm volatile(_ASM_ADD "%1,%0\n"
12048 +
12049 +#ifdef CONFIG_PAX_REFCOUNT
12050 + "jno 0f\n"
12051 + _ASM_SUB "%1,%0\n"
12052 + "int $4\n0:\n"
12053 + _ASM_EXTABLE(0b, 0b)
12054 +#endif
12055 +
12056 + : "+m" (l->a.counter)
12057 + : "ir" (i));
12058 +}
12059 +
12060 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
12061 +{
12062 + asm volatile(_ASM_ADD "%1,%0\n"
12063 : "+m" (l->a.counter)
12064 : "ir" (i));
12065 }
12066
12067 static inline void local_sub(long i, local_t *l)
12068 {
12069 - asm volatile(_ASM_SUB "%1,%0"
12070 + asm volatile(_ASM_SUB "%1,%0\n"
12071 +
12072 +#ifdef CONFIG_PAX_REFCOUNT
12073 + "jno 0f\n"
12074 + _ASM_ADD "%1,%0\n"
12075 + "int $4\n0:\n"
12076 + _ASM_EXTABLE(0b, 0b)
12077 +#endif
12078 +
12079 + : "+m" (l->a.counter)
12080 + : "ir" (i));
12081 +}
12082 +
12083 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
12084 +{
12085 + asm volatile(_ASM_SUB "%1,%0\n"
12086 : "+m" (l->a.counter)
12087 : "ir" (i));
12088 }
12089 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
12090 {
12091 unsigned char c;
12092
12093 - asm volatile(_ASM_SUB "%2,%0; sete %1"
12094 + asm volatile(_ASM_SUB "%2,%0\n"
12095 +
12096 +#ifdef CONFIG_PAX_REFCOUNT
12097 + "jno 0f\n"
12098 + _ASM_ADD "%2,%0\n"
12099 + "int $4\n0:\n"
12100 + _ASM_EXTABLE(0b, 0b)
12101 +#endif
12102 +
12103 + "sete %1\n"
12104 : "+m" (l->a.counter), "=qm" (c)
12105 : "ir" (i) : "memory");
12106 return c;
12107 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
12108 {
12109 unsigned char c;
12110
12111 - asm volatile(_ASM_DEC "%0; sete %1"
12112 + asm volatile(_ASM_DEC "%0\n"
12113 +
12114 +#ifdef CONFIG_PAX_REFCOUNT
12115 + "jno 0f\n"
12116 + _ASM_INC "%0\n"
12117 + "int $4\n0:\n"
12118 + _ASM_EXTABLE(0b, 0b)
12119 +#endif
12120 +
12121 + "sete %1\n"
12122 : "+m" (l->a.counter), "=qm" (c)
12123 : : "memory");
12124 return c != 0;
12125 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
12126 {
12127 unsigned char c;
12128
12129 - asm volatile(_ASM_INC "%0; sete %1"
12130 + asm volatile(_ASM_INC "%0\n"
12131 +
12132 +#ifdef CONFIG_PAX_REFCOUNT
12133 + "jno 0f\n"
12134 + _ASM_DEC "%0\n"
12135 + "int $4\n0:\n"
12136 + _ASM_EXTABLE(0b, 0b)
12137 +#endif
12138 +
12139 + "sete %1\n"
12140 : "+m" (l->a.counter), "=qm" (c)
12141 : : "memory");
12142 return c != 0;
12143 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
12144 {
12145 unsigned char c;
12146
12147 - asm volatile(_ASM_ADD "%2,%0; sets %1"
12148 + asm volatile(_ASM_ADD "%2,%0\n"
12149 +
12150 +#ifdef CONFIG_PAX_REFCOUNT
12151 + "jno 0f\n"
12152 + _ASM_SUB "%2,%0\n"
12153 + "int $4\n0:\n"
12154 + _ASM_EXTABLE(0b, 0b)
12155 +#endif
12156 +
12157 + "sets %1\n"
12158 : "+m" (l->a.counter), "=qm" (c)
12159 : "ir" (i) : "memory");
12160 return c;
12161 @@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
12162 #endif
12163 /* Modern 486+ processor */
12164 __i = i;
12165 - asm volatile(_ASM_XADD "%0, %1;"
12166 + asm volatile(_ASM_XADD "%0, %1\n"
12167 +
12168 +#ifdef CONFIG_PAX_REFCOUNT
12169 + "jno 0f\n"
12170 + _ASM_MOV "%0,%1\n"
12171 + "int $4\n0:\n"
12172 + _ASM_EXTABLE(0b, 0b)
12173 +#endif
12174 +
12175 : "+r" (i), "+m" (l->a.counter)
12176 : : "memory");
12177 return i + __i;
12178 @@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
12179 #endif
12180 }
12181
12182 +/**
12183 + * local_add_return_unchecked - add and return
12184 + * @i: integer value to add
12185 + * @l: pointer to type local_unchecked_t
12186 + *
12187 + * Atomically adds @i to @l and returns @i + @l
12188 + */
12189 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
12190 +{
12191 + long __i;
12192 +#ifdef CONFIG_M386
12193 + unsigned long flags;
12194 + if (unlikely(boot_cpu_data.x86 <= 3))
12195 + goto no_xadd;
12196 +#endif
12197 + /* Modern 486+ processor */
12198 + __i = i;
12199 + asm volatile(_ASM_XADD "%0, %1\n"
12200 + : "+r" (i), "+m" (l->a.counter)
12201 + : : "memory");
12202 + return i + __i;
12203 +
12204 +#ifdef CONFIG_M386
12205 +no_xadd: /* Legacy 386 processor */
12206 + local_irq_save(flags);
12207 + __i = local_read_unchecked(l);
12208 + local_set_unchecked(l, i + __i);
12209 + local_irq_restore(flags);
12210 + return i + __i;
12211 +#endif
12212 +}
12213 +
12214 static inline long local_sub_return(long i, local_t *l)
12215 {
12216 return local_add_return(-i, l);
12217 @@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
12218
12219 #define local_cmpxchg(l, o, n) \
12220 (cmpxchg_local(&((l)->a.counter), (o), (n)))
12221 +#define local_cmpxchg_unchecked(l, o, n) \
12222 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
12223 /* Always has a lock prefix */
12224 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
12225
12226 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
12227 index 593e51d..fa69c9a 100644
12228 --- a/arch/x86/include/asm/mman.h
12229 +++ b/arch/x86/include/asm/mman.h
12230 @@ -5,4 +5,14 @@
12231
12232 #include <asm-generic/mman.h>
12233
12234 +#ifdef __KERNEL__
12235 +#ifndef __ASSEMBLY__
12236 +#ifdef CONFIG_X86_32
12237 +#define arch_mmap_check i386_mmap_check
12238 +int i386_mmap_check(unsigned long addr, unsigned long len,
12239 + unsigned long flags);
12240 +#endif
12241 +#endif
12242 +#endif
12243 +
12244 #endif /* _ASM_X86_MMAN_H */
12245 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
12246 index 5f55e69..e20bfb1 100644
12247 --- a/arch/x86/include/asm/mmu.h
12248 +++ b/arch/x86/include/asm/mmu.h
12249 @@ -9,7 +9,7 @@
12250 * we put the segment information here.
12251 */
12252 typedef struct {
12253 - void *ldt;
12254 + struct desc_struct *ldt;
12255 int size;
12256
12257 #ifdef CONFIG_X86_64
12258 @@ -18,7 +18,19 @@ typedef struct {
12259 #endif
12260
12261 struct mutex lock;
12262 - void *vdso;
12263 + unsigned long vdso;
12264 +
12265 +#ifdef CONFIG_X86_32
12266 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12267 + unsigned long user_cs_base;
12268 + unsigned long user_cs_limit;
12269 +
12270 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12271 + cpumask_t cpu_user_cs_mask;
12272 +#endif
12273 +
12274 +#endif
12275 +#endif
12276 } mm_context_t;
12277
12278 #ifdef CONFIG_SMP
12279 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
12280 index cdbf367..adb37ac 100644
12281 --- a/arch/x86/include/asm/mmu_context.h
12282 +++ b/arch/x86/include/asm/mmu_context.h
12283 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
12284
12285 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12286 {
12287 +
12288 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12289 + unsigned int i;
12290 + pgd_t *pgd;
12291 +
12292 + pax_open_kernel();
12293 + pgd = get_cpu_pgd(smp_processor_id());
12294 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
12295 + set_pgd_batched(pgd+i, native_make_pgd(0));
12296 + pax_close_kernel();
12297 +#endif
12298 +
12299 #ifdef CONFIG_SMP
12300 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
12301 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
12302 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12303 struct task_struct *tsk)
12304 {
12305 unsigned cpu = smp_processor_id();
12306 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12307 + int tlbstate = TLBSTATE_OK;
12308 +#endif
12309
12310 if (likely(prev != next)) {
12311 #ifdef CONFIG_SMP
12312 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12313 + tlbstate = this_cpu_read(cpu_tlbstate.state);
12314 +#endif
12315 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12316 this_cpu_write(cpu_tlbstate.active_mm, next);
12317 #endif
12318 cpumask_set_cpu(cpu, mm_cpumask(next));
12319
12320 /* Re-load page tables */
12321 +#ifdef CONFIG_PAX_PER_CPU_PGD
12322 + pax_open_kernel();
12323 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12324 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12325 + pax_close_kernel();
12326 + load_cr3(get_cpu_pgd(cpu));
12327 +#else
12328 load_cr3(next->pgd);
12329 +#endif
12330
12331 /* stop flush ipis for the previous mm */
12332 cpumask_clear_cpu(cpu, mm_cpumask(prev));
12333 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12334 */
12335 if (unlikely(prev->context.ldt != next->context.ldt))
12336 load_LDT_nolock(&next->context);
12337 - }
12338 +
12339 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12340 + if (!(__supported_pte_mask & _PAGE_NX)) {
12341 + smp_mb__before_clear_bit();
12342 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
12343 + smp_mb__after_clear_bit();
12344 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12345 + }
12346 +#endif
12347 +
12348 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12349 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
12350 + prev->context.user_cs_limit != next->context.user_cs_limit))
12351 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12352 #ifdef CONFIG_SMP
12353 + else if (unlikely(tlbstate != TLBSTATE_OK))
12354 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12355 +#endif
12356 +#endif
12357 +
12358 + }
12359 else {
12360 +
12361 +#ifdef CONFIG_PAX_PER_CPU_PGD
12362 + pax_open_kernel();
12363 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12364 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12365 + pax_close_kernel();
12366 + load_cr3(get_cpu_pgd(cpu));
12367 +#endif
12368 +
12369 +#ifdef CONFIG_SMP
12370 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12371 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12372
12373 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12374 * tlb flush IPI delivery. We must reload CR3
12375 * to make sure to use no freed page tables.
12376 */
12377 +
12378 +#ifndef CONFIG_PAX_PER_CPU_PGD
12379 load_cr3(next->pgd);
12380 +#endif
12381 +
12382 load_LDT_nolock(&next->context);
12383 +
12384 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12385 + if (!(__supported_pte_mask & _PAGE_NX))
12386 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12387 +#endif
12388 +
12389 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12390 +#ifdef CONFIG_PAX_PAGEEXEC
12391 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12392 +#endif
12393 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12394 +#endif
12395 +
12396 }
12397 +#endif
12398 }
12399 -#endif
12400 }
12401
12402 #define activate_mm(prev, next) \
12403 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12404 index 9eae775..c914fea 100644
12405 --- a/arch/x86/include/asm/module.h
12406 +++ b/arch/x86/include/asm/module.h
12407 @@ -5,6 +5,7 @@
12408
12409 #ifdef CONFIG_X86_64
12410 /* X86_64 does not define MODULE_PROC_FAMILY */
12411 +#define MODULE_PROC_FAMILY ""
12412 #elif defined CONFIG_M386
12413 #define MODULE_PROC_FAMILY "386 "
12414 #elif defined CONFIG_M486
12415 @@ -59,8 +60,20 @@
12416 #error unknown processor family
12417 #endif
12418
12419 -#ifdef CONFIG_X86_32
12420 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12421 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12422 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12423 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12424 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12425 +#else
12426 +#define MODULE_PAX_KERNEXEC ""
12427 #endif
12428
12429 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12430 +#define MODULE_PAX_UDEREF "UDEREF "
12431 +#else
12432 +#define MODULE_PAX_UDEREF ""
12433 +#endif
12434 +
12435 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12436 +
12437 #endif /* _ASM_X86_MODULE_H */
12438 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12439 index 320f7bb..e89f8f8 100644
12440 --- a/arch/x86/include/asm/page_64_types.h
12441 +++ b/arch/x86/include/asm/page_64_types.h
12442 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12443
12444 /* duplicated to the one in bootmem.h */
12445 extern unsigned long max_pfn;
12446 -extern unsigned long phys_base;
12447 +extern const unsigned long phys_base;
12448
12449 extern unsigned long __phys_addr(unsigned long);
12450 #define __phys_reloc_hide(x) (x)
12451 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12452 index a0facf3..c017b15 100644
12453 --- a/arch/x86/include/asm/paravirt.h
12454 +++ b/arch/x86/include/asm/paravirt.h
12455 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12456 val);
12457 }
12458
12459 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12460 +{
12461 + pgdval_t val = native_pgd_val(pgd);
12462 +
12463 + if (sizeof(pgdval_t) > sizeof(long))
12464 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12465 + val, (u64)val >> 32);
12466 + else
12467 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12468 + val);
12469 +}
12470 +
12471 static inline void pgd_clear(pgd_t *pgdp)
12472 {
12473 set_pgd(pgdp, __pgd(0));
12474 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12475 pv_mmu_ops.set_fixmap(idx, phys, flags);
12476 }
12477
12478 +#ifdef CONFIG_PAX_KERNEXEC
12479 +static inline unsigned long pax_open_kernel(void)
12480 +{
12481 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12482 +}
12483 +
12484 +static inline unsigned long pax_close_kernel(void)
12485 +{
12486 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12487 +}
12488 +#else
12489 +static inline unsigned long pax_open_kernel(void) { return 0; }
12490 +static inline unsigned long pax_close_kernel(void) { return 0; }
12491 +#endif
12492 +
12493 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12494
12495 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12496 @@ -929,7 +956,7 @@ extern void default_banner(void);
12497
12498 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12499 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12500 -#define PARA_INDIRECT(addr) *%cs:addr
12501 +#define PARA_INDIRECT(addr) *%ss:addr
12502 #endif
12503
12504 #define INTERRUPT_RETURN \
12505 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
12506 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12507 CLBR_NONE, \
12508 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12509 +
12510 +#define GET_CR0_INTO_RDI \
12511 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12512 + mov %rax,%rdi
12513 +
12514 +#define SET_RDI_INTO_CR0 \
12515 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12516 +
12517 +#define GET_CR3_INTO_RDI \
12518 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12519 + mov %rax,%rdi
12520 +
12521 +#define SET_RDI_INTO_CR3 \
12522 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12523 +
12524 #endif /* CONFIG_X86_32 */
12525
12526 #endif /* __ASSEMBLY__ */
12527 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12528 index 142236e..57cf5ea 100644
12529 --- a/arch/x86/include/asm/paravirt_types.h
12530 +++ b/arch/x86/include/asm/paravirt_types.h
12531 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
12532 struct paravirt_callee_save make_pud;
12533
12534 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12535 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12536 #endif /* PAGETABLE_LEVELS == 4 */
12537 #endif /* PAGETABLE_LEVELS >= 3 */
12538
12539 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
12540 an mfn. We can tell which is which from the index. */
12541 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12542 phys_addr_t phys, pgprot_t flags);
12543 +
12544 +#ifdef CONFIG_PAX_KERNEXEC
12545 + unsigned long (*pax_open_kernel)(void);
12546 + unsigned long (*pax_close_kernel)(void);
12547 +#endif
12548 +
12549 };
12550
12551 struct arch_spinlock;
12552 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12553 index b4389a4..7024269 100644
12554 --- a/arch/x86/include/asm/pgalloc.h
12555 +++ b/arch/x86/include/asm/pgalloc.h
12556 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12557 pmd_t *pmd, pte_t *pte)
12558 {
12559 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12560 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12561 +}
12562 +
12563 +static inline void pmd_populate_user(struct mm_struct *mm,
12564 + pmd_t *pmd, pte_t *pte)
12565 +{
12566 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12567 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12568 }
12569
12570 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12571
12572 #ifdef CONFIG_X86_PAE
12573 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12574 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12575 +{
12576 + pud_populate(mm, pudp, pmd);
12577 +}
12578 #else /* !CONFIG_X86_PAE */
12579 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12580 {
12581 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12582 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12583 }
12584 +
12585 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12586 +{
12587 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12588 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12589 +}
12590 #endif /* CONFIG_X86_PAE */
12591
12592 #if PAGETABLE_LEVELS > 3
12593 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12594 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12595 }
12596
12597 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12598 +{
12599 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12600 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12601 +}
12602 +
12603 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12604 {
12605 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12606 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12607 index f2b489c..4f7e2e5 100644
12608 --- a/arch/x86/include/asm/pgtable-2level.h
12609 +++ b/arch/x86/include/asm/pgtable-2level.h
12610 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12611
12612 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12613 {
12614 + pax_open_kernel();
12615 *pmdp = pmd;
12616 + pax_close_kernel();
12617 }
12618
12619 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12620 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12621 index 4cc9f2b..5fd9226 100644
12622 --- a/arch/x86/include/asm/pgtable-3level.h
12623 +++ b/arch/x86/include/asm/pgtable-3level.h
12624 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12625
12626 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12627 {
12628 + pax_open_kernel();
12629 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12630 + pax_close_kernel();
12631 }
12632
12633 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12634 {
12635 + pax_open_kernel();
12636 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12637 + pax_close_kernel();
12638 }
12639
12640 /*
12641 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12642 index a1f780d..a3eb32f 100644
12643 --- a/arch/x86/include/asm/pgtable.h
12644 +++ b/arch/x86/include/asm/pgtable.h
12645 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12646
12647 #ifndef __PAGETABLE_PUD_FOLDED
12648 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12649 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12650 #define pgd_clear(pgd) native_pgd_clear(pgd)
12651 #endif
12652
12653 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12654
12655 #define arch_end_context_switch(prev) do {} while(0)
12656
12657 +#define pax_open_kernel() native_pax_open_kernel()
12658 +#define pax_close_kernel() native_pax_close_kernel()
12659 #endif /* CONFIG_PARAVIRT */
12660
12661 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
12662 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12663 +
12664 +#ifdef CONFIG_PAX_KERNEXEC
12665 +static inline unsigned long native_pax_open_kernel(void)
12666 +{
12667 + unsigned long cr0;
12668 +
12669 + preempt_disable();
12670 + barrier();
12671 + cr0 = read_cr0() ^ X86_CR0_WP;
12672 + BUG_ON(cr0 & X86_CR0_WP);
12673 + write_cr0(cr0);
12674 + return cr0 ^ X86_CR0_WP;
12675 +}
12676 +
12677 +static inline unsigned long native_pax_close_kernel(void)
12678 +{
12679 + unsigned long cr0;
12680 +
12681 + cr0 = read_cr0() ^ X86_CR0_WP;
12682 + BUG_ON(!(cr0 & X86_CR0_WP));
12683 + write_cr0(cr0);
12684 + barrier();
12685 + preempt_enable_no_resched();
12686 + return cr0 ^ X86_CR0_WP;
12687 +}
12688 +#else
12689 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
12690 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
12691 +#endif
12692 +
12693 /*
12694 * The following only work if pte_present() is true.
12695 * Undefined behaviour if not..
12696 */
12697 +static inline int pte_user(pte_t pte)
12698 +{
12699 + return pte_val(pte) & _PAGE_USER;
12700 +}
12701 +
12702 static inline int pte_dirty(pte_t pte)
12703 {
12704 return pte_flags(pte) & _PAGE_DIRTY;
12705 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12706 return pte_clear_flags(pte, _PAGE_RW);
12707 }
12708
12709 +static inline pte_t pte_mkread(pte_t pte)
12710 +{
12711 + return __pte(pte_val(pte) | _PAGE_USER);
12712 +}
12713 +
12714 static inline pte_t pte_mkexec(pte_t pte)
12715 {
12716 - return pte_clear_flags(pte, _PAGE_NX);
12717 +#ifdef CONFIG_X86_PAE
12718 + if (__supported_pte_mask & _PAGE_NX)
12719 + return pte_clear_flags(pte, _PAGE_NX);
12720 + else
12721 +#endif
12722 + return pte_set_flags(pte, _PAGE_USER);
12723 +}
12724 +
12725 +static inline pte_t pte_exprotect(pte_t pte)
12726 +{
12727 +#ifdef CONFIG_X86_PAE
12728 + if (__supported_pte_mask & _PAGE_NX)
12729 + return pte_set_flags(pte, _PAGE_NX);
12730 + else
12731 +#endif
12732 + return pte_clear_flags(pte, _PAGE_USER);
12733 }
12734
12735 static inline pte_t pte_mkdirty(pte_t pte)
12736 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12737 #endif
12738
12739 #ifndef __ASSEMBLY__
12740 +
12741 +#ifdef CONFIG_PAX_PER_CPU_PGD
12742 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12743 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12744 +{
12745 + return cpu_pgd[cpu];
12746 +}
12747 +#endif
12748 +
12749 #include <linux/mm_types.h>
12750
12751 static inline int pte_none(pte_t pte)
12752 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12753
12754 static inline int pgd_bad(pgd_t pgd)
12755 {
12756 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12757 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12758 }
12759
12760 static inline int pgd_none(pgd_t pgd)
12761 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
12762 * pgd_offset() returns a (pgd_t *)
12763 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12764 */
12765 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12766 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12767 +
12768 +#ifdef CONFIG_PAX_PER_CPU_PGD
12769 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12770 +#endif
12771 +
12772 /*
12773 * a shortcut which implies the use of the kernel's pgd, instead
12774 * of a process's
12775 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
12776 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12777 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12778
12779 +#ifdef CONFIG_X86_32
12780 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12781 +#else
12782 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12783 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12784 +
12785 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12786 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12787 +#else
12788 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12789 +#endif
12790 +
12791 +#endif
12792 +
12793 #ifndef __ASSEMBLY__
12794
12795 extern int direct_gbpages;
12796 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12797 * dst and src can be on the same page, but the range must not overlap,
12798 * and must not cross a page boundary.
12799 */
12800 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12801 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12802 {
12803 - memcpy(dst, src, count * sizeof(pgd_t));
12804 + pax_open_kernel();
12805 + while (count--)
12806 + *dst++ = *src++;
12807 + pax_close_kernel();
12808 }
12809
12810 +#ifdef CONFIG_PAX_PER_CPU_PGD
12811 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12812 +#endif
12813 +
12814 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12815 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12816 +#else
12817 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12818 +#endif
12819
12820 #include <asm-generic/pgtable.h>
12821 #endif /* __ASSEMBLY__ */
12822 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12823 index 8faa215..a8a17ea 100644
12824 --- a/arch/x86/include/asm/pgtable_32.h
12825 +++ b/arch/x86/include/asm/pgtable_32.h
12826 @@ -25,9 +25,6 @@
12827 struct mm_struct;
12828 struct vm_area_struct;
12829
12830 -extern pgd_t swapper_pg_dir[1024];
12831 -extern pgd_t initial_page_table[1024];
12832 -
12833 static inline void pgtable_cache_init(void) { }
12834 static inline void check_pgt_cache(void) { }
12835 void paging_init(void);
12836 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12837 # include <asm/pgtable-2level.h>
12838 #endif
12839
12840 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12841 +extern pgd_t initial_page_table[PTRS_PER_PGD];
12842 +#ifdef CONFIG_X86_PAE
12843 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12844 +#endif
12845 +
12846 #if defined(CONFIG_HIGHPTE)
12847 #define pte_offset_map(dir, address) \
12848 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12849 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12850 /* Clear a kernel PTE and flush it from the TLB */
12851 #define kpte_clear_flush(ptep, vaddr) \
12852 do { \
12853 + pax_open_kernel(); \
12854 pte_clear(&init_mm, (vaddr), (ptep)); \
12855 + pax_close_kernel(); \
12856 __flush_tlb_one((vaddr)); \
12857 } while (0)
12858
12859 @@ -75,6 +80,9 @@ do { \
12860
12861 #endif /* !__ASSEMBLY__ */
12862
12863 +#define HAVE_ARCH_UNMAPPED_AREA
12864 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12865 +
12866 /*
12867 * kern_addr_valid() is (1) for FLATMEM and (0) for
12868 * SPARSEMEM and DISCONTIGMEM
12869 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12870 index ed5903b..c7fe163 100644
12871 --- a/arch/x86/include/asm/pgtable_32_types.h
12872 +++ b/arch/x86/include/asm/pgtable_32_types.h
12873 @@ -8,7 +8,7 @@
12874 */
12875 #ifdef CONFIG_X86_PAE
12876 # include <asm/pgtable-3level_types.h>
12877 -# define PMD_SIZE (1UL << PMD_SHIFT)
12878 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12879 # define PMD_MASK (~(PMD_SIZE - 1))
12880 #else
12881 # include <asm/pgtable-2level_types.h>
12882 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12883 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12884 #endif
12885
12886 +#ifdef CONFIG_PAX_KERNEXEC
12887 +#ifndef __ASSEMBLY__
12888 +extern unsigned char MODULES_EXEC_VADDR[];
12889 +extern unsigned char MODULES_EXEC_END[];
12890 +#endif
12891 +#include <asm/boot.h>
12892 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12893 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12894 +#else
12895 +#define ktla_ktva(addr) (addr)
12896 +#define ktva_ktla(addr) (addr)
12897 +#endif
12898 +
12899 #define MODULES_VADDR VMALLOC_START
12900 #define MODULES_END VMALLOC_END
12901 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12902 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12903 index 47356f9..deb94a2 100644
12904 --- a/arch/x86/include/asm/pgtable_64.h
12905 +++ b/arch/x86/include/asm/pgtable_64.h
12906 @@ -16,10 +16,14 @@
12907
12908 extern pud_t level3_kernel_pgt[512];
12909 extern pud_t level3_ident_pgt[512];
12910 +extern pud_t level3_vmalloc_start_pgt[512];
12911 +extern pud_t level3_vmalloc_end_pgt[512];
12912 +extern pud_t level3_vmemmap_pgt[512];
12913 +extern pud_t level2_vmemmap_pgt[512];
12914 extern pmd_t level2_kernel_pgt[512];
12915 extern pmd_t level2_fixmap_pgt[512];
12916 -extern pmd_t level2_ident_pgt[512];
12917 -extern pgd_t init_level4_pgt[];
12918 +extern pmd_t level2_ident_pgt[512*2];
12919 +extern pgd_t init_level4_pgt[512];
12920
12921 #define swapper_pg_dir init_level4_pgt
12922
12923 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12924
12925 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12926 {
12927 + pax_open_kernel();
12928 *pmdp = pmd;
12929 + pax_close_kernel();
12930 }
12931
12932 static inline void native_pmd_clear(pmd_t *pmd)
12933 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12934
12935 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12936 {
12937 + pax_open_kernel();
12938 *pudp = pud;
12939 + pax_close_kernel();
12940 }
12941
12942 static inline void native_pud_clear(pud_t *pud)
12943 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12944
12945 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12946 {
12947 + pax_open_kernel();
12948 + *pgdp = pgd;
12949 + pax_close_kernel();
12950 +}
12951 +
12952 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12953 +{
12954 *pgdp = pgd;
12955 }
12956
12957 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12958 index 766ea16..5b96cb3 100644
12959 --- a/arch/x86/include/asm/pgtable_64_types.h
12960 +++ b/arch/x86/include/asm/pgtable_64_types.h
12961 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12962 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12963 #define MODULES_END _AC(0xffffffffff000000, UL)
12964 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12965 +#define MODULES_EXEC_VADDR MODULES_VADDR
12966 +#define MODULES_EXEC_END MODULES_END
12967 +
12968 +#define ktla_ktva(addr) (addr)
12969 +#define ktva_ktla(addr) (addr)
12970
12971 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12972 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12973 index ec8a1fc..7ccb593 100644
12974 --- a/arch/x86/include/asm/pgtable_types.h
12975 +++ b/arch/x86/include/asm/pgtable_types.h
12976 @@ -16,13 +16,12 @@
12977 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
12978 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
12979 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
12980 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
12981 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
12982 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
12983 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
12984 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
12985 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
12986 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
12987 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
12988 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
12989 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
12990 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
12991
12992 /* If _PAGE_BIT_PRESENT is clear, we use these: */
12993 @@ -40,7 +39,6 @@
12994 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
12995 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
12996 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
12997 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
12998 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
12999 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
13000 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
13001 @@ -57,8 +55,10 @@
13002
13003 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
13004 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
13005 -#else
13006 +#elif defined(CONFIG_KMEMCHECK)
13007 #define _PAGE_NX (_AT(pteval_t, 0))
13008 +#else
13009 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
13010 #endif
13011
13012 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
13013 @@ -96,6 +96,9 @@
13014 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
13015 _PAGE_ACCESSED)
13016
13017 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
13018 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
13019 +
13020 #define __PAGE_KERNEL_EXEC \
13021 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
13022 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
13023 @@ -106,7 +109,7 @@
13024 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
13025 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
13026 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
13027 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
13028 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
13029 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
13030 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
13031 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
13032 @@ -168,8 +171,8 @@
13033 * bits are combined, this will alow user to access the high address mapped
13034 * VDSO in the presence of CONFIG_COMPAT_VDSO
13035 */
13036 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
13037 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
13038 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13039 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13040 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
13041 #endif
13042
13043 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
13044 {
13045 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
13046 }
13047 +#endif
13048
13049 +#if PAGETABLE_LEVELS == 3
13050 +#include <asm-generic/pgtable-nopud.h>
13051 +#endif
13052 +
13053 +#if PAGETABLE_LEVELS == 2
13054 +#include <asm-generic/pgtable-nopmd.h>
13055 +#endif
13056 +
13057 +#ifndef __ASSEMBLY__
13058 #if PAGETABLE_LEVELS > 3
13059 typedef struct { pudval_t pud; } pud_t;
13060
13061 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
13062 return pud.pud;
13063 }
13064 #else
13065 -#include <asm-generic/pgtable-nopud.h>
13066 -
13067 static inline pudval_t native_pud_val(pud_t pud)
13068 {
13069 return native_pgd_val(pud.pgd);
13070 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
13071 return pmd.pmd;
13072 }
13073 #else
13074 -#include <asm-generic/pgtable-nopmd.h>
13075 -
13076 static inline pmdval_t native_pmd_val(pmd_t pmd)
13077 {
13078 return native_pgd_val(pmd.pud.pgd);
13079 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
13080
13081 extern pteval_t __supported_pte_mask;
13082 extern void set_nx(void);
13083 -extern int nx_enabled;
13084
13085 #define pgprot_writecombine pgprot_writecombine
13086 extern pgprot_t pgprot_writecombine(pgprot_t prot);
13087 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
13088 index ad1fc85..0b15fe1 100644
13089 --- a/arch/x86/include/asm/processor.h
13090 +++ b/arch/x86/include/asm/processor.h
13091 @@ -289,7 +289,7 @@ struct tss_struct {
13092
13093 } ____cacheline_aligned;
13094
13095 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
13096 +extern struct tss_struct init_tss[NR_CPUS];
13097
13098 /*
13099 * Save the original ist values for checking stack pointers during debugging
13100 @@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
13101 */
13102 #define TASK_SIZE PAGE_OFFSET
13103 #define TASK_SIZE_MAX TASK_SIZE
13104 +
13105 +#ifdef CONFIG_PAX_SEGMEXEC
13106 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
13107 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
13108 +#else
13109 #define STACK_TOP TASK_SIZE
13110 -#define STACK_TOP_MAX STACK_TOP
13111 +#endif
13112 +
13113 +#define STACK_TOP_MAX TASK_SIZE
13114
13115 #define INIT_THREAD { \
13116 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13117 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13118 .vm86_info = NULL, \
13119 .sysenter_cs = __KERNEL_CS, \
13120 .io_bitmap_ptr = NULL, \
13121 @@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
13122 */
13123 #define INIT_TSS { \
13124 .x86_tss = { \
13125 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13126 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13127 .ss0 = __KERNEL_DS, \
13128 .ss1 = __KERNEL_CS, \
13129 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
13130 @@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
13131 extern unsigned long thread_saved_pc(struct task_struct *tsk);
13132
13133 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
13134 -#define KSTK_TOP(info) \
13135 -({ \
13136 - unsigned long *__ptr = (unsigned long *)(info); \
13137 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
13138 -})
13139 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
13140
13141 /*
13142 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
13143 @@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13144 #define task_pt_regs(task) \
13145 ({ \
13146 struct pt_regs *__regs__; \
13147 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
13148 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
13149 __regs__ - 1; \
13150 })
13151
13152 @@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13153 /*
13154 * User space process size. 47bits minus one guard page.
13155 */
13156 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
13157 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
13158
13159 /* This decides where the kernel will search for a free chunk of vm
13160 * space during mmap's.
13161 */
13162 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
13163 - 0xc0000000 : 0xFFFFe000)
13164 + 0xc0000000 : 0xFFFFf000)
13165
13166 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
13167 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
13168 @@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13169 #define STACK_TOP_MAX TASK_SIZE_MAX
13170
13171 #define INIT_THREAD { \
13172 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13173 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13174 }
13175
13176 #define INIT_TSS { \
13177 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13178 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13179 }
13180
13181 /*
13182 @@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
13183 */
13184 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
13185
13186 +#ifdef CONFIG_PAX_SEGMEXEC
13187 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
13188 +#endif
13189 +
13190 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
13191
13192 /* Get/set a process' ability to use the timestamp counter instruction */
13193 @@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
13194 #define cpu_has_amd_erratum(x) (false)
13195 #endif /* CONFIG_CPU_SUP_AMD */
13196
13197 -extern unsigned long arch_align_stack(unsigned long sp);
13198 +#define arch_align_stack(x) ((x) & ~0xfUL)
13199 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
13200
13201 void default_idle(void);
13202 bool set_pm_idle_to_default(void);
13203
13204 -void stop_this_cpu(void *dummy);
13205 +void stop_this_cpu(void *dummy) __noreturn;
13206
13207 #endif /* _ASM_X86_PROCESSOR_H */
13208 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
13209 index 19f16eb..b50624b 100644
13210 --- a/arch/x86/include/asm/ptrace.h
13211 +++ b/arch/x86/include/asm/ptrace.h
13212 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
13213 }
13214
13215 /*
13216 - * user_mode_vm(regs) determines whether a register set came from user mode.
13217 + * user_mode(regs) determines whether a register set came from user mode.
13218 * This is true if V8086 mode was enabled OR if the register set was from
13219 * protected mode with RPL-3 CS value. This tricky test checks that with
13220 * one comparison. Many places in the kernel can bypass this full check
13221 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
13222 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
13223 + * be used.
13224 */
13225 -static inline int user_mode(struct pt_regs *regs)
13226 +static inline int user_mode_novm(struct pt_regs *regs)
13227 {
13228 #ifdef CONFIG_X86_32
13229 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
13230 #else
13231 - return !!(regs->cs & 3);
13232 + return !!(regs->cs & SEGMENT_RPL_MASK);
13233 #endif
13234 }
13235
13236 -static inline int user_mode_vm(struct pt_regs *regs)
13237 +static inline int user_mode(struct pt_regs *regs)
13238 {
13239 #ifdef CONFIG_X86_32
13240 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
13241 USER_RPL;
13242 #else
13243 - return user_mode(regs);
13244 + return user_mode_novm(regs);
13245 #endif
13246 }
13247
13248 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
13249 #ifdef CONFIG_X86_64
13250 static inline bool user_64bit_mode(struct pt_regs *regs)
13251 {
13252 + unsigned long cs = regs->cs & 0xffff;
13253 #ifndef CONFIG_PARAVIRT
13254 /*
13255 * On non-paravirt systems, this is the only long mode CPL 3
13256 * selector. We do not allow long mode selectors in the LDT.
13257 */
13258 - return regs->cs == __USER_CS;
13259 + return cs == __USER_CS;
13260 #else
13261 /* Headers are too twisted for this to go in paravirt.h. */
13262 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
13263 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
13264 #endif
13265 }
13266 #endif
13267 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
13268 index fe1ec5b..dc5c3fe 100644
13269 --- a/arch/x86/include/asm/realmode.h
13270 +++ b/arch/x86/include/asm/realmode.h
13271 @@ -22,16 +22,14 @@ struct real_mode_header {
13272 #endif
13273 /* APM/BIOS reboot */
13274 u32 machine_real_restart_asm;
13275 -#ifdef CONFIG_X86_64
13276 u32 machine_real_restart_seg;
13277 -#endif
13278 };
13279
13280 /* This must match data at trampoline_32/64.S */
13281 struct trampoline_header {
13282 #ifdef CONFIG_X86_32
13283 u32 start;
13284 - u16 gdt_pad;
13285 + u16 boot_cs;
13286 u16 gdt_limit;
13287 u32 gdt_base;
13288 #else
13289 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
13290 index a82c4f1..f9c9696 100644
13291 --- a/arch/x86/include/asm/reboot.h
13292 +++ b/arch/x86/include/asm/reboot.h
13293 @@ -6,12 +6,12 @@
13294 struct pt_regs;
13295
13296 struct machine_ops {
13297 - void (*restart)(char *cmd);
13298 - void (*halt)(void);
13299 - void (*power_off)(void);
13300 + void (* __noreturn restart)(char *cmd);
13301 + void (* __noreturn halt)(void);
13302 + void (* __noreturn power_off)(void);
13303 void (*shutdown)(void);
13304 void (*crash_shutdown)(struct pt_regs *);
13305 - void (*emergency_restart)(void);
13306 + void (* __noreturn emergency_restart)(void);
13307 };
13308
13309 extern struct machine_ops machine_ops;
13310 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
13311 index 2dbe4a7..ce1db00 100644
13312 --- a/arch/x86/include/asm/rwsem.h
13313 +++ b/arch/x86/include/asm/rwsem.h
13314 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
13315 {
13316 asm volatile("# beginning down_read\n\t"
13317 LOCK_PREFIX _ASM_INC "(%1)\n\t"
13318 +
13319 +#ifdef CONFIG_PAX_REFCOUNT
13320 + "jno 0f\n"
13321 + LOCK_PREFIX _ASM_DEC "(%1)\n"
13322 + "int $4\n0:\n"
13323 + _ASM_EXTABLE(0b, 0b)
13324 +#endif
13325 +
13326 /* adds 0x00000001 */
13327 " jns 1f\n"
13328 " call call_rwsem_down_read_failed\n"
13329 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
13330 "1:\n\t"
13331 " mov %1,%2\n\t"
13332 " add %3,%2\n\t"
13333 +
13334 +#ifdef CONFIG_PAX_REFCOUNT
13335 + "jno 0f\n"
13336 + "sub %3,%2\n"
13337 + "int $4\n0:\n"
13338 + _ASM_EXTABLE(0b, 0b)
13339 +#endif
13340 +
13341 " jle 2f\n\t"
13342 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13343 " jnz 1b\n\t"
13344 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13345 long tmp;
13346 asm volatile("# beginning down_write\n\t"
13347 LOCK_PREFIX " xadd %1,(%2)\n\t"
13348 +
13349 +#ifdef CONFIG_PAX_REFCOUNT
13350 + "jno 0f\n"
13351 + "mov %1,(%2)\n"
13352 + "int $4\n0:\n"
13353 + _ASM_EXTABLE(0b, 0b)
13354 +#endif
13355 +
13356 /* adds 0xffff0001, returns the old value */
13357 " test %1,%1\n\t"
13358 /* was the count 0 before? */
13359 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13360 long tmp;
13361 asm volatile("# beginning __up_read\n\t"
13362 LOCK_PREFIX " xadd %1,(%2)\n\t"
13363 +
13364 +#ifdef CONFIG_PAX_REFCOUNT
13365 + "jno 0f\n"
13366 + "mov %1,(%2)\n"
13367 + "int $4\n0:\n"
13368 + _ASM_EXTABLE(0b, 0b)
13369 +#endif
13370 +
13371 /* subtracts 1, returns the old value */
13372 " jns 1f\n\t"
13373 " call call_rwsem_wake\n" /* expects old value in %edx */
13374 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13375 long tmp;
13376 asm volatile("# beginning __up_write\n\t"
13377 LOCK_PREFIX " xadd %1,(%2)\n\t"
13378 +
13379 +#ifdef CONFIG_PAX_REFCOUNT
13380 + "jno 0f\n"
13381 + "mov %1,(%2)\n"
13382 + "int $4\n0:\n"
13383 + _ASM_EXTABLE(0b, 0b)
13384 +#endif
13385 +
13386 /* subtracts 0xffff0001, returns the old value */
13387 " jns 1f\n\t"
13388 " call call_rwsem_wake\n" /* expects old value in %edx */
13389 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13390 {
13391 asm volatile("# beginning __downgrade_write\n\t"
13392 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13393 +
13394 +#ifdef CONFIG_PAX_REFCOUNT
13395 + "jno 0f\n"
13396 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13397 + "int $4\n0:\n"
13398 + _ASM_EXTABLE(0b, 0b)
13399 +#endif
13400 +
13401 /*
13402 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13403 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13404 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13405 */
13406 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13407 {
13408 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13409 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13410 +
13411 +#ifdef CONFIG_PAX_REFCOUNT
13412 + "jno 0f\n"
13413 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
13414 + "int $4\n0:\n"
13415 + _ASM_EXTABLE(0b, 0b)
13416 +#endif
13417 +
13418 : "+m" (sem->count)
13419 : "er" (delta));
13420 }
13421 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13422 */
13423 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13424 {
13425 - return delta + xadd(&sem->count, delta);
13426 + return delta + xadd_check_overflow(&sem->count, delta);
13427 }
13428
13429 #endif /* __KERNEL__ */
13430 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13431 index c48a950..c6d7468 100644
13432 --- a/arch/x86/include/asm/segment.h
13433 +++ b/arch/x86/include/asm/segment.h
13434 @@ -64,10 +64,15 @@
13435 * 26 - ESPFIX small SS
13436 * 27 - per-cpu [ offset to per-cpu data area ]
13437 * 28 - stack_canary-20 [ for stack protector ]
13438 - * 29 - unused
13439 - * 30 - unused
13440 + * 29 - PCI BIOS CS
13441 + * 30 - PCI BIOS DS
13442 * 31 - TSS for double fault handler
13443 */
13444 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13445 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13446 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13447 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13448 +
13449 #define GDT_ENTRY_TLS_MIN 6
13450 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13451
13452 @@ -79,6 +84,8 @@
13453
13454 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13455
13456 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13457 +
13458 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13459
13460 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13461 @@ -104,6 +111,12 @@
13462 #define __KERNEL_STACK_CANARY 0
13463 #endif
13464
13465 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13466 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13467 +
13468 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13469 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13470 +
13471 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13472
13473 /*
13474 @@ -141,7 +154,7 @@
13475 */
13476
13477 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13478 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13479 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13480
13481
13482 #else
13483 @@ -165,6 +178,8 @@
13484 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13485 #define __USER32_DS __USER_DS
13486
13487 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13488 +
13489 #define GDT_ENTRY_TSS 8 /* needs two entries */
13490 #define GDT_ENTRY_LDT 10 /* needs two entries */
13491 #define GDT_ENTRY_TLS_MIN 12
13492 @@ -185,6 +200,7 @@
13493 #endif
13494
13495 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13496 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13497 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13498 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13499 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13500 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13501 {
13502 unsigned long __limit;
13503 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13504 - return __limit + 1;
13505 + return __limit;
13506 }
13507
13508 #endif /* !__ASSEMBLY__ */
13509 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13510 index 4f19a15..e04d86f 100644
13511 --- a/arch/x86/include/asm/smp.h
13512 +++ b/arch/x86/include/asm/smp.h
13513 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13514 /* cpus sharing the last level cache: */
13515 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13516 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13517 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13518 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13519
13520 static inline struct cpumask *cpu_sibling_mask(int cpu)
13521 {
13522 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13523 extern int safe_smp_processor_id(void);
13524
13525 #elif defined(CONFIG_X86_64_SMP)
13526 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13527 -
13528 -#define stack_smp_processor_id() \
13529 -({ \
13530 - struct thread_info *ti; \
13531 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13532 - ti->cpu; \
13533 -})
13534 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13535 +#define stack_smp_processor_id() raw_smp_processor_id()
13536 #define safe_smp_processor_id() smp_processor_id()
13537
13538 #endif
13539 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13540 index 33692ea..350a534 100644
13541 --- a/arch/x86/include/asm/spinlock.h
13542 +++ b/arch/x86/include/asm/spinlock.h
13543 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13544 static inline void arch_read_lock(arch_rwlock_t *rw)
13545 {
13546 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13547 +
13548 +#ifdef CONFIG_PAX_REFCOUNT
13549 + "jno 0f\n"
13550 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13551 + "int $4\n0:\n"
13552 + _ASM_EXTABLE(0b, 0b)
13553 +#endif
13554 +
13555 "jns 1f\n"
13556 "call __read_lock_failed\n\t"
13557 "1:\n"
13558 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13559 static inline void arch_write_lock(arch_rwlock_t *rw)
13560 {
13561 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13562 +
13563 +#ifdef CONFIG_PAX_REFCOUNT
13564 + "jno 0f\n"
13565 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13566 + "int $4\n0:\n"
13567 + _ASM_EXTABLE(0b, 0b)
13568 +#endif
13569 +
13570 "jz 1f\n"
13571 "call __write_lock_failed\n\t"
13572 "1:\n"
13573 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13574
13575 static inline void arch_read_unlock(arch_rwlock_t *rw)
13576 {
13577 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13578 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13579 +
13580 +#ifdef CONFIG_PAX_REFCOUNT
13581 + "jno 0f\n"
13582 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13583 + "int $4\n0:\n"
13584 + _ASM_EXTABLE(0b, 0b)
13585 +#endif
13586 +
13587 :"+m" (rw->lock) : : "memory");
13588 }
13589
13590 static inline void arch_write_unlock(arch_rwlock_t *rw)
13591 {
13592 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13593 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13594 +
13595 +#ifdef CONFIG_PAX_REFCOUNT
13596 + "jno 0f\n"
13597 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13598 + "int $4\n0:\n"
13599 + _ASM_EXTABLE(0b, 0b)
13600 +#endif
13601 +
13602 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13603 }
13604
13605 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13606 index 6a99859..03cb807 100644
13607 --- a/arch/x86/include/asm/stackprotector.h
13608 +++ b/arch/x86/include/asm/stackprotector.h
13609 @@ -47,7 +47,7 @@
13610 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13611 */
13612 #define GDT_STACK_CANARY_INIT \
13613 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13614 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13615
13616 /*
13617 * Initialize the stackprotector canary value.
13618 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13619
13620 static inline void load_stack_canary_segment(void)
13621 {
13622 -#ifdef CONFIG_X86_32
13623 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13624 asm volatile ("mov %0, %%gs" : : "r" (0));
13625 #endif
13626 }
13627 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13628 index 70bbe39..4ae2bd4 100644
13629 --- a/arch/x86/include/asm/stacktrace.h
13630 +++ b/arch/x86/include/asm/stacktrace.h
13631 @@ -11,28 +11,20 @@
13632
13633 extern int kstack_depth_to_print;
13634
13635 -struct thread_info;
13636 +struct task_struct;
13637 struct stacktrace_ops;
13638
13639 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13640 - unsigned long *stack,
13641 - unsigned long bp,
13642 - const struct stacktrace_ops *ops,
13643 - void *data,
13644 - unsigned long *end,
13645 - int *graph);
13646 +typedef unsigned long walk_stack_t(struct task_struct *task,
13647 + void *stack_start,
13648 + unsigned long *stack,
13649 + unsigned long bp,
13650 + const struct stacktrace_ops *ops,
13651 + void *data,
13652 + unsigned long *end,
13653 + int *graph);
13654
13655 -extern unsigned long
13656 -print_context_stack(struct thread_info *tinfo,
13657 - unsigned long *stack, unsigned long bp,
13658 - const struct stacktrace_ops *ops, void *data,
13659 - unsigned long *end, int *graph);
13660 -
13661 -extern unsigned long
13662 -print_context_stack_bp(struct thread_info *tinfo,
13663 - unsigned long *stack, unsigned long bp,
13664 - const struct stacktrace_ops *ops, void *data,
13665 - unsigned long *end, int *graph);
13666 +extern walk_stack_t print_context_stack;
13667 +extern walk_stack_t print_context_stack_bp;
13668
13669 /* Generic stack tracer with callbacks */
13670
13671 @@ -40,7 +32,7 @@ struct stacktrace_ops {
13672 void (*address)(void *data, unsigned long address, int reliable);
13673 /* On negative return stop dumping */
13674 int (*stack)(void *data, char *name);
13675 - walk_stack_t walk_stack;
13676 + walk_stack_t *walk_stack;
13677 };
13678
13679 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13680 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13681 index 4ec45b3..a4f0a8a 100644
13682 --- a/arch/x86/include/asm/switch_to.h
13683 +++ b/arch/x86/include/asm/switch_to.h
13684 @@ -108,7 +108,7 @@ do { \
13685 "call __switch_to\n\t" \
13686 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13687 __switch_canary \
13688 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
13689 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13690 "movq %%rax,%%rdi\n\t" \
13691 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13692 "jnz ret_from_fork\n\t" \
13693 @@ -119,7 +119,7 @@ do { \
13694 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13695 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13696 [_tif_fork] "i" (_TIF_FORK), \
13697 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
13698 + [thread_info] "m" (current_tinfo), \
13699 [current_task] "m" (current_task) \
13700 __switch_canary_iparam \
13701 : "memory", "cc" __EXTRA_CLOBBER)
13702 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13703 index 2d946e6..e453ec4 100644
13704 --- a/arch/x86/include/asm/thread_info.h
13705 +++ b/arch/x86/include/asm/thread_info.h
13706 @@ -10,6 +10,7 @@
13707 #include <linux/compiler.h>
13708 #include <asm/page.h>
13709 #include <asm/types.h>
13710 +#include <asm/percpu.h>
13711
13712 /*
13713 * low level task data that entry.S needs immediate access to
13714 @@ -24,7 +25,6 @@ struct exec_domain;
13715 #include <linux/atomic.h>
13716
13717 struct thread_info {
13718 - struct task_struct *task; /* main task structure */
13719 struct exec_domain *exec_domain; /* execution domain */
13720 __u32 flags; /* low level flags */
13721 __u32 status; /* thread synchronous flags */
13722 @@ -34,19 +34,13 @@ struct thread_info {
13723 mm_segment_t addr_limit;
13724 struct restart_block restart_block;
13725 void __user *sysenter_return;
13726 -#ifdef CONFIG_X86_32
13727 - unsigned long previous_esp; /* ESP of the previous stack in
13728 - case of nested (IRQ) stacks
13729 - */
13730 - __u8 supervisor_stack[0];
13731 -#endif
13732 + unsigned long lowest_stack;
13733 unsigned int sig_on_uaccess_error:1;
13734 unsigned int uaccess_err:1; /* uaccess failed */
13735 };
13736
13737 -#define INIT_THREAD_INFO(tsk) \
13738 +#define INIT_THREAD_INFO \
13739 { \
13740 - .task = &tsk, \
13741 .exec_domain = &default_exec_domain, \
13742 .flags = 0, \
13743 .cpu = 0, \
13744 @@ -57,7 +51,7 @@ struct thread_info {
13745 }, \
13746 }
13747
13748 -#define init_thread_info (init_thread_union.thread_info)
13749 +#define init_thread_info (init_thread_union.stack)
13750 #define init_stack (init_thread_union.stack)
13751
13752 #else /* !__ASSEMBLY__ */
13753 @@ -98,6 +92,7 @@ struct thread_info {
13754 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13755 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13756 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13757 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13758
13759 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13760 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13761 @@ -122,17 +117,18 @@ struct thread_info {
13762 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13763 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13764 #define _TIF_X32 (1 << TIF_X32)
13765 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13766
13767 /* work to do in syscall_trace_enter() */
13768 #define _TIF_WORK_SYSCALL_ENTRY \
13769 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13770 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13771 - _TIF_NOHZ)
13772 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13773
13774 /* work to do in syscall_trace_leave() */
13775 #define _TIF_WORK_SYSCALL_EXIT \
13776 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13777 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13778 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13779
13780 /* work to do on interrupt/exception return */
13781 #define _TIF_WORK_MASK \
13782 @@ -143,7 +139,7 @@ struct thread_info {
13783 /* work to do on any return to user space */
13784 #define _TIF_ALLWORK_MASK \
13785 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13786 - _TIF_NOHZ)
13787 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13788
13789 /* Only used for 64 bit */
13790 #define _TIF_DO_NOTIFY_MASK \
13791 @@ -159,45 +155,40 @@ struct thread_info {
13792
13793 #define PREEMPT_ACTIVE 0x10000000
13794
13795 -#ifdef CONFIG_X86_32
13796 -
13797 -#define STACK_WARN (THREAD_SIZE/8)
13798 -/*
13799 - * macros/functions for gaining access to the thread information structure
13800 - *
13801 - * preempt_count needs to be 1 initially, until the scheduler is functional.
13802 - */
13803 -#ifndef __ASSEMBLY__
13804 -
13805 -
13806 -/* how to get the current stack pointer from C */
13807 -register unsigned long current_stack_pointer asm("esp") __used;
13808 -
13809 -/* how to get the thread information struct from C */
13810 -static inline struct thread_info *current_thread_info(void)
13811 -{
13812 - return (struct thread_info *)
13813 - (current_stack_pointer & ~(THREAD_SIZE - 1));
13814 -}
13815 -
13816 -#else /* !__ASSEMBLY__ */
13817 -
13818 +#ifdef __ASSEMBLY__
13819 /* how to get the thread information struct from ASM */
13820 #define GET_THREAD_INFO(reg) \
13821 - movl $-THREAD_SIZE, reg; \
13822 - andl %esp, reg
13823 + mov PER_CPU_VAR(current_tinfo), reg
13824
13825 /* use this one if reg already contains %esp */
13826 -#define GET_THREAD_INFO_WITH_ESP(reg) \
13827 - andl $-THREAD_SIZE, reg
13828 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13829 +#else
13830 +/* how to get the thread information struct from C */
13831 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13832 +
13833 +static __always_inline struct thread_info *current_thread_info(void)
13834 +{
13835 + return this_cpu_read_stable(current_tinfo);
13836 +}
13837 +#endif
13838 +
13839 +#ifdef CONFIG_X86_32
13840 +
13841 +#define STACK_WARN (THREAD_SIZE/8)
13842 +/*
13843 + * macros/functions for gaining access to the thread information structure
13844 + *
13845 + * preempt_count needs to be 1 initially, until the scheduler is functional.
13846 + */
13847 +#ifndef __ASSEMBLY__
13848 +
13849 +/* how to get the current stack pointer from C */
13850 +register unsigned long current_stack_pointer asm("esp") __used;
13851
13852 #endif
13853
13854 #else /* X86_32 */
13855
13856 -#include <asm/percpu.h>
13857 -#define KERNEL_STACK_OFFSET (5*8)
13858 -
13859 /*
13860 * macros/functions for gaining access to the thread information structure
13861 * preempt_count needs to be 1 initially, until the scheduler is functional.
13862 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13863 #ifndef __ASSEMBLY__
13864 DECLARE_PER_CPU(unsigned long, kernel_stack);
13865
13866 -static inline struct thread_info *current_thread_info(void)
13867 -{
13868 - struct thread_info *ti;
13869 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
13870 - KERNEL_STACK_OFFSET - THREAD_SIZE);
13871 - return ti;
13872 -}
13873 -
13874 -#else /* !__ASSEMBLY__ */
13875 -
13876 -/* how to get the thread information struct from ASM */
13877 -#define GET_THREAD_INFO(reg) \
13878 - movq PER_CPU_VAR(kernel_stack),reg ; \
13879 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13880 -
13881 -/*
13882 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13883 - * a certain register (to be used in assembler memory operands).
13884 - */
13885 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13886 -
13887 +/* how to get the current stack pointer from C */
13888 +register unsigned long current_stack_pointer asm("rsp") __used;
13889 #endif
13890
13891 #endif /* !X86_32 */
13892 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13893 extern void arch_task_cache_init(void);
13894 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13895 extern void arch_release_task_struct(struct task_struct *tsk);
13896 +
13897 +#define __HAVE_THREAD_FUNCTIONS
13898 +#define task_thread_info(task) (&(task)->tinfo)
13899 +#define task_stack_page(task) ((task)->stack)
13900 +#define setup_thread_stack(p, org) do {} while (0)
13901 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13902 +
13903 #endif
13904 #endif /* _ASM_X86_THREAD_INFO_H */
13905 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13906 index 7ccf8d1..9a18110 100644
13907 --- a/arch/x86/include/asm/uaccess.h
13908 +++ b/arch/x86/include/asm/uaccess.h
13909 @@ -7,6 +7,7 @@
13910 #include <linux/compiler.h>
13911 #include <linux/thread_info.h>
13912 #include <linux/string.h>
13913 +#include <linux/sched.h>
13914 #include <asm/asm.h>
13915 #include <asm/page.h>
13916 #include <asm/smap.h>
13917 @@ -29,7 +30,12 @@
13918
13919 #define get_ds() (KERNEL_DS)
13920 #define get_fs() (current_thread_info()->addr_limit)
13921 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13922 +void __set_fs(mm_segment_t x);
13923 +void set_fs(mm_segment_t x);
13924 +#else
13925 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13926 +#endif
13927
13928 #define segment_eq(a, b) ((a).seg == (b).seg)
13929
13930 @@ -77,8 +83,33 @@
13931 * checks that the pointer is in the user space range - after calling
13932 * this function, memory access functions may still return -EFAULT.
13933 */
13934 -#define access_ok(type, addr, size) \
13935 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13936 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13937 +#define access_ok(type, addr, size) \
13938 +({ \
13939 + long __size = size; \
13940 + unsigned long __addr = (unsigned long)addr; \
13941 + unsigned long __addr_ao = __addr & PAGE_MASK; \
13942 + unsigned long __end_ao = __addr + __size - 1; \
13943 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13944 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13945 + while(__addr_ao <= __end_ao) { \
13946 + char __c_ao; \
13947 + __addr_ao += PAGE_SIZE; \
13948 + if (__size > PAGE_SIZE) \
13949 + cond_resched(); \
13950 + if (__get_user(__c_ao, (char __user *)__addr)) \
13951 + break; \
13952 + if (type != VERIFY_WRITE) { \
13953 + __addr = __addr_ao; \
13954 + continue; \
13955 + } \
13956 + if (__put_user(__c_ao, (char __user *)__addr)) \
13957 + break; \
13958 + __addr = __addr_ao; \
13959 + } \
13960 + } \
13961 + __ret_ao; \
13962 +})
13963
13964 /*
13965 * The exception table consists of pairs of addresses relative to the
13966 @@ -189,13 +220,21 @@ extern int __get_user_bad(void);
13967 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
13968 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
13969
13970 -
13971 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13972 +#define __copyuser_seg "gs;"
13973 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
13974 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
13975 +#else
13976 +#define __copyuser_seg
13977 +#define __COPYUSER_SET_ES
13978 +#define __COPYUSER_RESTORE_ES
13979 +#endif
13980
13981 #ifdef CONFIG_X86_32
13982 #define __put_user_asm_u64(x, addr, err, errret) \
13983 asm volatile(ASM_STAC "\n" \
13984 - "1: movl %%eax,0(%2)\n" \
13985 - "2: movl %%edx,4(%2)\n" \
13986 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
13987 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
13988 "3: " ASM_CLAC "\n" \
13989 ".section .fixup,\"ax\"\n" \
13990 "4: movl %3,%0\n" \
13991 @@ -208,8 +247,8 @@ extern int __get_user_bad(void);
13992
13993 #define __put_user_asm_ex_u64(x, addr) \
13994 asm volatile(ASM_STAC "\n" \
13995 - "1: movl %%eax,0(%1)\n" \
13996 - "2: movl %%edx,4(%1)\n" \
13997 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
13998 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
13999 "3: " ASM_CLAC "\n" \
14000 _ASM_EXTABLE_EX(1b, 2b) \
14001 _ASM_EXTABLE_EX(2b, 3b) \
14002 @@ -261,7 +300,7 @@ extern void __put_user_8(void);
14003 __typeof__(*(ptr)) __pu_val; \
14004 __chk_user_ptr(ptr); \
14005 might_fault(); \
14006 - __pu_val = x; \
14007 + __pu_val = (x); \
14008 switch (sizeof(*(ptr))) { \
14009 case 1: \
14010 __put_user_x(1, __pu_val, ptr, __ret_pu); \
14011 @@ -383,7 +422,7 @@ do { \
14012
14013 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14014 asm volatile(ASM_STAC "\n" \
14015 - "1: mov"itype" %2,%"rtype"1\n" \
14016 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
14017 "2: " ASM_CLAC "\n" \
14018 ".section .fixup,\"ax\"\n" \
14019 "3: mov %3,%0\n" \
14020 @@ -391,7 +430,7 @@ do { \
14021 " jmp 2b\n" \
14022 ".previous\n" \
14023 _ASM_EXTABLE(1b, 3b) \
14024 - : "=r" (err), ltype(x) \
14025 + : "=r" (err), ltype (x) \
14026 : "m" (__m(addr)), "i" (errret), "0" (err))
14027
14028 #define __get_user_size_ex(x, ptr, size) \
14029 @@ -416,7 +455,7 @@ do { \
14030 } while (0)
14031
14032 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
14033 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
14034 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
14035 "2:\n" \
14036 _ASM_EXTABLE_EX(1b, 2b) \
14037 : ltype(x) : "m" (__m(addr)))
14038 @@ -433,13 +472,24 @@ do { \
14039 int __gu_err; \
14040 unsigned long __gu_val; \
14041 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
14042 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
14043 + (x) = (__typeof__(*(ptr)))__gu_val; \
14044 __gu_err; \
14045 })
14046
14047 /* FIXME: this hack is definitely wrong -AK */
14048 struct __large_struct { unsigned long buf[100]; };
14049 -#define __m(x) (*(struct __large_struct __user *)(x))
14050 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14051 +#define ____m(x) \
14052 +({ \
14053 + unsigned long ____x = (unsigned long)(x); \
14054 + if (____x < PAX_USER_SHADOW_BASE) \
14055 + ____x += PAX_USER_SHADOW_BASE; \
14056 + (void __user *)____x; \
14057 +})
14058 +#else
14059 +#define ____m(x) (x)
14060 +#endif
14061 +#define __m(x) (*(struct __large_struct __user *)____m(x))
14062
14063 /*
14064 * Tell gcc we read from memory instead of writing: this is because
14065 @@ -448,7 +498,7 @@ struct __large_struct { unsigned long buf[100]; };
14066 */
14067 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14068 asm volatile(ASM_STAC "\n" \
14069 - "1: mov"itype" %"rtype"1,%2\n" \
14070 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
14071 "2: " ASM_CLAC "\n" \
14072 ".section .fixup,\"ax\"\n" \
14073 "3: mov %3,%0\n" \
14074 @@ -456,10 +506,10 @@ struct __large_struct { unsigned long buf[100]; };
14075 ".previous\n" \
14076 _ASM_EXTABLE(1b, 3b) \
14077 : "=r"(err) \
14078 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
14079 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
14080
14081 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
14082 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
14083 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
14084 "2:\n" \
14085 _ASM_EXTABLE_EX(1b, 2b) \
14086 : : ltype(x), "m" (__m(addr)))
14087 @@ -498,8 +548,12 @@ struct __large_struct { unsigned long buf[100]; };
14088 * On error, the variable @x is set to zero.
14089 */
14090
14091 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14092 +#define __get_user(x, ptr) get_user((x), (ptr))
14093 +#else
14094 #define __get_user(x, ptr) \
14095 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
14096 +#endif
14097
14098 /**
14099 * __put_user: - Write a simple value into user space, with less checking.
14100 @@ -521,8 +575,12 @@ struct __large_struct { unsigned long buf[100]; };
14101 * Returns zero on success, or -EFAULT on error.
14102 */
14103
14104 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14105 +#define __put_user(x, ptr) put_user((x), (ptr))
14106 +#else
14107 #define __put_user(x, ptr) \
14108 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
14109 +#endif
14110
14111 #define __get_user_unaligned __get_user
14112 #define __put_user_unaligned __put_user
14113 @@ -540,7 +598,7 @@ struct __large_struct { unsigned long buf[100]; };
14114 #define get_user_ex(x, ptr) do { \
14115 unsigned long __gue_val; \
14116 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
14117 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
14118 + (x) = (__typeof__(*(ptr)))__gue_val; \
14119 } while (0)
14120
14121 #ifdef CONFIG_X86_WP_WORKS_OK
14122 @@ -574,8 +632,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
14123 extern __must_check long strlen_user(const char __user *str);
14124 extern __must_check long strnlen_user(const char __user *str, long n);
14125
14126 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
14127 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
14128 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14129 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14130
14131 /*
14132 * movsl can be slow when source and dest are not both 8-byte aligned
14133 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
14134 index 7f760a9..04b1c65 100644
14135 --- a/arch/x86/include/asm/uaccess_32.h
14136 +++ b/arch/x86/include/asm/uaccess_32.h
14137 @@ -11,15 +11,15 @@
14138 #include <asm/page.h>
14139
14140 unsigned long __must_check __copy_to_user_ll
14141 - (void __user *to, const void *from, unsigned long n);
14142 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
14143 unsigned long __must_check __copy_from_user_ll
14144 - (void *to, const void __user *from, unsigned long n);
14145 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14146 unsigned long __must_check __copy_from_user_ll_nozero
14147 - (void *to, const void __user *from, unsigned long n);
14148 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14149 unsigned long __must_check __copy_from_user_ll_nocache
14150 - (void *to, const void __user *from, unsigned long n);
14151 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14152 unsigned long __must_check __copy_from_user_ll_nocache_nozero
14153 - (void *to, const void __user *from, unsigned long n);
14154 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14155
14156 /**
14157 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
14158 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
14159 static __always_inline unsigned long __must_check
14160 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14161 {
14162 + if ((long)n < 0)
14163 + return n;
14164 +
14165 + check_object_size(from, n, true);
14166 +
14167 if (__builtin_constant_p(n)) {
14168 unsigned long ret;
14169
14170 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
14171 __copy_to_user(void __user *to, const void *from, unsigned long n)
14172 {
14173 might_fault();
14174 +
14175 return __copy_to_user_inatomic(to, from, n);
14176 }
14177
14178 static __always_inline unsigned long
14179 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
14180 {
14181 + if ((long)n < 0)
14182 + return n;
14183 +
14184 /* Avoid zeroing the tail if the copy fails..
14185 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
14186 * but as the zeroing behaviour is only significant when n is not
14187 @@ -137,6 +146,12 @@ static __always_inline unsigned long
14188 __copy_from_user(void *to, const void __user *from, unsigned long n)
14189 {
14190 might_fault();
14191 +
14192 + if ((long)n < 0)
14193 + return n;
14194 +
14195 + check_object_size(to, n, false);
14196 +
14197 if (__builtin_constant_p(n)) {
14198 unsigned long ret;
14199
14200 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
14201 const void __user *from, unsigned long n)
14202 {
14203 might_fault();
14204 +
14205 + if ((long)n < 0)
14206 + return n;
14207 +
14208 if (__builtin_constant_p(n)) {
14209 unsigned long ret;
14210
14211 @@ -181,15 +200,19 @@ static __always_inline unsigned long
14212 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
14213 unsigned long n)
14214 {
14215 - return __copy_from_user_ll_nocache_nozero(to, from, n);
14216 + if ((long)n < 0)
14217 + return n;
14218 +
14219 + return __copy_from_user_ll_nocache_nozero(to, from, n);
14220 }
14221
14222 -unsigned long __must_check copy_to_user(void __user *to,
14223 - const void *from, unsigned long n);
14224 -unsigned long __must_check _copy_from_user(void *to,
14225 - const void __user *from,
14226 - unsigned long n);
14227 -
14228 +extern void copy_to_user_overflow(void)
14229 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14230 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14231 +#else
14232 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14233 +#endif
14234 +;
14235
14236 extern void copy_from_user_overflow(void)
14237 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14238 @@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
14239 #endif
14240 ;
14241
14242 -static inline unsigned long __must_check copy_from_user(void *to,
14243 - const void __user *from,
14244 - unsigned long n)
14245 +/**
14246 + * copy_to_user: - Copy a block of data into user space.
14247 + * @to: Destination address, in user space.
14248 + * @from: Source address, in kernel space.
14249 + * @n: Number of bytes to copy.
14250 + *
14251 + * Context: User context only. This function may sleep.
14252 + *
14253 + * Copy data from kernel space to user space.
14254 + *
14255 + * Returns number of bytes that could not be copied.
14256 + * On success, this will be zero.
14257 + */
14258 +static inline unsigned long __must_check
14259 +copy_to_user(void __user *to, const void *from, unsigned long n)
14260 {
14261 - int sz = __compiletime_object_size(to);
14262 + size_t sz = __compiletime_object_size(from);
14263
14264 - if (likely(sz == -1 || sz >= n))
14265 - n = _copy_from_user(to, from, n);
14266 - else
14267 + if (unlikely(sz != (size_t)-1 && sz < n))
14268 + copy_to_user_overflow();
14269 + else if (access_ok(VERIFY_WRITE, to, n))
14270 + n = __copy_to_user(to, from, n);
14271 + return n;
14272 +}
14273 +
14274 +/**
14275 + * copy_from_user: - Copy a block of data from user space.
14276 + * @to: Destination address, in kernel space.
14277 + * @from: Source address, in user space.
14278 + * @n: Number of bytes to copy.
14279 + *
14280 + * Context: User context only. This function may sleep.
14281 + *
14282 + * Copy data from user space to kernel space.
14283 + *
14284 + * Returns number of bytes that could not be copied.
14285 + * On success, this will be zero.
14286 + *
14287 + * If some data could not be copied, this function will pad the copied
14288 + * data to the requested size using zero bytes.
14289 + */
14290 +static inline unsigned long __must_check
14291 +copy_from_user(void *to, const void __user *from, unsigned long n)
14292 +{
14293 + size_t sz = __compiletime_object_size(to);
14294 +
14295 + check_object_size(to, n, false);
14296 +
14297 + if (unlikely(sz != (size_t)-1 && sz < n))
14298 copy_from_user_overflow();
14299 -
14300 + else if (access_ok(VERIFY_READ, from, n))
14301 + n = __copy_from_user(to, from, n);
14302 + else if ((long)n > 0)
14303 + memset(to, 0, n);
14304 return n;
14305 }
14306
14307 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14308 index 142810c..4b68a3e 100644
14309 --- a/arch/x86/include/asm/uaccess_64.h
14310 +++ b/arch/x86/include/asm/uaccess_64.h
14311 @@ -10,6 +10,9 @@
14312 #include <asm/alternative.h>
14313 #include <asm/cpufeature.h>
14314 #include <asm/page.h>
14315 +#include <asm/pgtable.h>
14316 +
14317 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
14318
14319 /*
14320 * Copy To/From Userspace
14321 @@ -17,13 +20,13 @@
14322
14323 /* Handles exceptions in both to and from, but doesn't do access_ok */
14324 __must_check unsigned long
14325 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14326 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14327 __must_check unsigned long
14328 -copy_user_generic_string(void *to, const void *from, unsigned len);
14329 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14330 __must_check unsigned long
14331 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14332 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14333
14334 -static __always_inline __must_check unsigned long
14335 +static __always_inline __must_check __size_overflow(3) unsigned long
14336 copy_user_generic(void *to, const void *from, unsigned len)
14337 {
14338 unsigned ret;
14339 @@ -41,142 +44,203 @@ copy_user_generic(void *to, const void *from, unsigned len)
14340 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14341 "=d" (len)),
14342 "1" (to), "2" (from), "3" (len)
14343 - : "memory", "rcx", "r8", "r9", "r10", "r11");
14344 + : "memory", "rcx", "r8", "r9", "r11");
14345 return ret;
14346 }
14347
14348 +static __always_inline __must_check unsigned long
14349 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14350 +static __always_inline __must_check unsigned long
14351 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14352 __must_check unsigned long
14353 -_copy_to_user(void __user *to, const void *from, unsigned len);
14354 -__must_check unsigned long
14355 -_copy_from_user(void *to, const void __user *from, unsigned len);
14356 -__must_check unsigned long
14357 -copy_in_user(void __user *to, const void __user *from, unsigned len);
14358 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14359 +
14360 +extern void copy_to_user_overflow(void)
14361 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14362 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14363 +#else
14364 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14365 +#endif
14366 +;
14367 +
14368 +extern void copy_from_user_overflow(void)
14369 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14370 + __compiletime_error("copy_from_user() buffer size is not provably correct")
14371 +#else
14372 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
14373 +#endif
14374 +;
14375
14376 static inline unsigned long __must_check copy_from_user(void *to,
14377 const void __user *from,
14378 unsigned long n)
14379 {
14380 - int sz = __compiletime_object_size(to);
14381 -
14382 might_fault();
14383 - if (likely(sz == -1 || sz >= n))
14384 - n = _copy_from_user(to, from, n);
14385 -#ifdef CONFIG_DEBUG_VM
14386 - else
14387 - WARN(1, "Buffer overflow detected!\n");
14388 -#endif
14389 +
14390 + check_object_size(to, n, false);
14391 + if (access_ok(VERIFY_READ, from, n))
14392 + n = __copy_from_user(to, from, n);
14393 + else if (n < INT_MAX)
14394 + memset(to, 0, n);
14395 return n;
14396 }
14397
14398 static __always_inline __must_check
14399 -int copy_to_user(void __user *dst, const void *src, unsigned size)
14400 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
14401 {
14402 might_fault();
14403
14404 - return _copy_to_user(dst, src, size);
14405 + if (access_ok(VERIFY_WRITE, dst, size))
14406 + size = __copy_to_user(dst, src, size);
14407 + return size;
14408 }
14409
14410 static __always_inline __must_check
14411 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
14412 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14413 {
14414 - int ret = 0;
14415 + size_t sz = __compiletime_object_size(dst);
14416 + unsigned ret = 0;
14417
14418 might_fault();
14419 +
14420 + if (size > INT_MAX)
14421 + return size;
14422 +
14423 + check_object_size(dst, size, false);
14424 +
14425 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14426 + if (!__access_ok(VERIFY_READ, src, size))
14427 + return size;
14428 +#endif
14429 +
14430 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14431 + copy_from_user_overflow();
14432 + return size;
14433 + }
14434 +
14435 if (!__builtin_constant_p(size))
14436 - return copy_user_generic(dst, (__force void *)src, size);
14437 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14438 switch (size) {
14439 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14440 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14441 ret, "b", "b", "=q", 1);
14442 return ret;
14443 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14444 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14445 ret, "w", "w", "=r", 2);
14446 return ret;
14447 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14448 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14449 ret, "l", "k", "=r", 4);
14450 return ret;
14451 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14452 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14453 ret, "q", "", "=r", 8);
14454 return ret;
14455 case 10:
14456 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14457 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14458 ret, "q", "", "=r", 10);
14459 if (unlikely(ret))
14460 return ret;
14461 __get_user_asm(*(u16 *)(8 + (char *)dst),
14462 - (u16 __user *)(8 + (char __user *)src),
14463 + (const u16 __user *)(8 + (const char __user *)src),
14464 ret, "w", "w", "=r", 2);
14465 return ret;
14466 case 16:
14467 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14468 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14469 ret, "q", "", "=r", 16);
14470 if (unlikely(ret))
14471 return ret;
14472 __get_user_asm(*(u64 *)(8 + (char *)dst),
14473 - (u64 __user *)(8 + (char __user *)src),
14474 + (const u64 __user *)(8 + (const char __user *)src),
14475 ret, "q", "", "=r", 8);
14476 return ret;
14477 default:
14478 - return copy_user_generic(dst, (__force void *)src, size);
14479 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14480 }
14481 }
14482
14483 static __always_inline __must_check
14484 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
14485 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14486 {
14487 - int ret = 0;
14488 + size_t sz = __compiletime_object_size(src);
14489 + unsigned ret = 0;
14490
14491 might_fault();
14492 +
14493 + if (size > INT_MAX)
14494 + return size;
14495 +
14496 + check_object_size(src, size, true);
14497 +
14498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14499 + if (!__access_ok(VERIFY_WRITE, dst, size))
14500 + return size;
14501 +#endif
14502 +
14503 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14504 + copy_to_user_overflow();
14505 + return size;
14506 + }
14507 +
14508 if (!__builtin_constant_p(size))
14509 - return copy_user_generic((__force void *)dst, src, size);
14510 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14511 switch (size) {
14512 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14513 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14514 ret, "b", "b", "iq", 1);
14515 return ret;
14516 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14517 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14518 ret, "w", "w", "ir", 2);
14519 return ret;
14520 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14521 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14522 ret, "l", "k", "ir", 4);
14523 return ret;
14524 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14525 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14526 ret, "q", "", "er", 8);
14527 return ret;
14528 case 10:
14529 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14530 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14531 ret, "q", "", "er", 10);
14532 if (unlikely(ret))
14533 return ret;
14534 asm("":::"memory");
14535 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14536 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14537 ret, "w", "w", "ir", 2);
14538 return ret;
14539 case 16:
14540 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14541 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14542 ret, "q", "", "er", 16);
14543 if (unlikely(ret))
14544 return ret;
14545 asm("":::"memory");
14546 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14547 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14548 ret, "q", "", "er", 8);
14549 return ret;
14550 default:
14551 - return copy_user_generic((__force void *)dst, src, size);
14552 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14553 }
14554 }
14555
14556 static __always_inline __must_check
14557 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14558 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14559 {
14560 - int ret = 0;
14561 + unsigned ret = 0;
14562
14563 might_fault();
14564 +
14565 + if (size > INT_MAX)
14566 + return size;
14567 +
14568 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14569 + if (!__access_ok(VERIFY_READ, src, size))
14570 + return size;
14571 + if (!__access_ok(VERIFY_WRITE, dst, size))
14572 + return size;
14573 +#endif
14574 +
14575 if (!__builtin_constant_p(size))
14576 - return copy_user_generic((__force void *)dst,
14577 - (__force void *)src, size);
14578 + return copy_user_generic((__force_kernel void *)____m(dst),
14579 + (__force_kernel const void *)____m(src), size);
14580 switch (size) {
14581 case 1: {
14582 u8 tmp;
14583 - __get_user_asm(tmp, (u8 __user *)src,
14584 + __get_user_asm(tmp, (const u8 __user *)src,
14585 ret, "b", "b", "=q", 1);
14586 if (likely(!ret))
14587 __put_user_asm(tmp, (u8 __user *)dst,
14588 @@ -185,7 +249,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14589 }
14590 case 2: {
14591 u16 tmp;
14592 - __get_user_asm(tmp, (u16 __user *)src,
14593 + __get_user_asm(tmp, (const u16 __user *)src,
14594 ret, "w", "w", "=r", 2);
14595 if (likely(!ret))
14596 __put_user_asm(tmp, (u16 __user *)dst,
14597 @@ -195,7 +259,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14598
14599 case 4: {
14600 u32 tmp;
14601 - __get_user_asm(tmp, (u32 __user *)src,
14602 + __get_user_asm(tmp, (const u32 __user *)src,
14603 ret, "l", "k", "=r", 4);
14604 if (likely(!ret))
14605 __put_user_asm(tmp, (u32 __user *)dst,
14606 @@ -204,7 +268,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14607 }
14608 case 8: {
14609 u64 tmp;
14610 - __get_user_asm(tmp, (u64 __user *)src,
14611 + __get_user_asm(tmp, (const u64 __user *)src,
14612 ret, "q", "", "=r", 8);
14613 if (likely(!ret))
14614 __put_user_asm(tmp, (u64 __user *)dst,
14615 @@ -212,41 +276,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14616 return ret;
14617 }
14618 default:
14619 - return copy_user_generic((__force void *)dst,
14620 - (__force void *)src, size);
14621 + return copy_user_generic((__force_kernel void *)____m(dst),
14622 + (__force_kernel const void *)____m(src), size);
14623 }
14624 }
14625
14626 static __must_check __always_inline int
14627 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14628 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14629 {
14630 - return copy_user_generic(dst, (__force const void *)src, size);
14631 + if (size > INT_MAX)
14632 + return size;
14633 +
14634 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14635 + if (!__access_ok(VERIFY_READ, src, size))
14636 + return size;
14637 +#endif
14638 +
14639 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14640 }
14641
14642 -static __must_check __always_inline int
14643 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14644 +static __must_check __always_inline unsigned long
14645 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14646 {
14647 - return copy_user_generic((__force void *)dst, src, size);
14648 + if (size > INT_MAX)
14649 + return size;
14650 +
14651 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14652 + if (!__access_ok(VERIFY_WRITE, dst, size))
14653 + return size;
14654 +#endif
14655 +
14656 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14657 }
14658
14659 -extern long __copy_user_nocache(void *dst, const void __user *src,
14660 - unsigned size, int zerorest);
14661 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14662 + unsigned long size, int zerorest) __size_overflow(3);
14663
14664 -static inline int
14665 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14666 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14667 {
14668 might_sleep();
14669 +
14670 + if (size > INT_MAX)
14671 + return size;
14672 +
14673 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14674 + if (!__access_ok(VERIFY_READ, src, size))
14675 + return size;
14676 +#endif
14677 +
14678 return __copy_user_nocache(dst, src, size, 1);
14679 }
14680
14681 -static inline int
14682 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14683 - unsigned size)
14684 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14685 + unsigned long size)
14686 {
14687 + if (size > INT_MAX)
14688 + return size;
14689 +
14690 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14691 + if (!__access_ok(VERIFY_READ, src, size))
14692 + return size;
14693 +#endif
14694 +
14695 return __copy_user_nocache(dst, src, size, 0);
14696 }
14697
14698 -unsigned long
14699 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14700 +extern unsigned long
14701 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14702
14703 #endif /* _ASM_X86_UACCESS_64_H */
14704 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14705 index 5b238981..77fdd78 100644
14706 --- a/arch/x86/include/asm/word-at-a-time.h
14707 +++ b/arch/x86/include/asm/word-at-a-time.h
14708 @@ -11,7 +11,7 @@
14709 * and shift, for example.
14710 */
14711 struct word_at_a_time {
14712 - const unsigned long one_bits, high_bits;
14713 + unsigned long one_bits, high_bits;
14714 };
14715
14716 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14717 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14718 index 0415cda..b43d877 100644
14719 --- a/arch/x86/include/asm/xsave.h
14720 +++ b/arch/x86/include/asm/xsave.h
14721 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14722 return -EFAULT;
14723
14724 __asm__ __volatile__(ASM_STAC "\n"
14725 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14726 + "1:"
14727 + __copyuser_seg
14728 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14729 "2: " ASM_CLAC "\n"
14730 ".section .fixup,\"ax\"\n"
14731 "3: movl $-1,%[err]\n"
14732 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14733 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14734 {
14735 int err;
14736 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14737 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14738 u32 lmask = mask;
14739 u32 hmask = mask >> 32;
14740
14741 __asm__ __volatile__(ASM_STAC "\n"
14742 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14743 + "1:"
14744 + __copyuser_seg
14745 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14746 "2: " ASM_CLAC "\n"
14747 ".section .fixup,\"ax\"\n"
14748 "3: movl $-1,%[err]\n"
14749 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14750 index 91ce48f..a48ea05 100644
14751 --- a/arch/x86/kernel/Makefile
14752 +++ b/arch/x86/kernel/Makefile
14753 @@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14754 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14755 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14756 obj-y += probe_roms.o
14757 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14758 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14759 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14760 obj-y += syscall_$(BITS).o
14761 obj-$(CONFIG_X86_64) += vsyscall_64.o
14762 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
14763 index e651f7a..c995dc4 100644
14764 --- a/arch/x86/kernel/acpi/boot.c
14765 +++ b/arch/x86/kernel/acpi/boot.c
14766 @@ -1576,7 +1576,7 @@ int __init acpi_boot_init(void)
14767 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
14768
14769 if (!acpi_noirq)
14770 - x86_init.pci.init = pci_acpi_init;
14771 + *(void **)&x86_init.pci.init = pci_acpi_init;
14772
14773 return 0;
14774 }
14775 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14776 index 11676cf..a8cf3ec 100644
14777 --- a/arch/x86/kernel/acpi/sleep.c
14778 +++ b/arch/x86/kernel/acpi/sleep.c
14779 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14780 #else /* CONFIG_64BIT */
14781 #ifdef CONFIG_SMP
14782 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14783 +
14784 + pax_open_kernel();
14785 early_gdt_descr.address =
14786 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14787 + pax_close_kernel();
14788 +
14789 initial_gs = per_cpu_offset(smp_processor_id());
14790 #endif
14791 initial_code = (unsigned long)wakeup_long64;
14792 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14793 index 13ab720..95d5442 100644
14794 --- a/arch/x86/kernel/acpi/wakeup_32.S
14795 +++ b/arch/x86/kernel/acpi/wakeup_32.S
14796 @@ -30,13 +30,11 @@ wakeup_pmode_return:
14797 # and restore the stack ... but you need gdt for this to work
14798 movl saved_context_esp, %esp
14799
14800 - movl %cs:saved_magic, %eax
14801 - cmpl $0x12345678, %eax
14802 + cmpl $0x12345678, saved_magic
14803 jne bogus_magic
14804
14805 # jump to place where we left off
14806 - movl saved_eip, %eax
14807 - jmp *%eax
14808 + jmp *(saved_eip)
14809
14810 bogus_magic:
14811 jmp bogus_magic
14812 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14813 index ef5ccca..bd83949 100644
14814 --- a/arch/x86/kernel/alternative.c
14815 +++ b/arch/x86/kernel/alternative.c
14816 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14817 */
14818 for (a = start; a < end; a++) {
14819 instr = (u8 *)&a->instr_offset + a->instr_offset;
14820 +
14821 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14822 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14823 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14824 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14825 +#endif
14826 +
14827 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14828 BUG_ON(a->replacementlen > a->instrlen);
14829 BUG_ON(a->instrlen > sizeof(insnbuf));
14830 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14831 for (poff = start; poff < end; poff++) {
14832 u8 *ptr = (u8 *)poff + *poff;
14833
14834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14835 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14836 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14837 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14838 +#endif
14839 +
14840 if (!*poff || ptr < text || ptr >= text_end)
14841 continue;
14842 /* turn DS segment override prefix into lock prefix */
14843 - if (*ptr == 0x3e)
14844 + if (*ktla_ktva(ptr) == 0x3e)
14845 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14846 }
14847 mutex_unlock(&text_mutex);
14848 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14849 for (poff = start; poff < end; poff++) {
14850 u8 *ptr = (u8 *)poff + *poff;
14851
14852 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14853 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14854 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14855 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14856 +#endif
14857 +
14858 if (!*poff || ptr < text || ptr >= text_end)
14859 continue;
14860 /* turn lock prefix into DS segment override prefix */
14861 - if (*ptr == 0xf0)
14862 + if (*ktla_ktva(ptr) == 0xf0)
14863 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14864 }
14865 mutex_unlock(&text_mutex);
14866 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14867
14868 BUG_ON(p->len > MAX_PATCH_LEN);
14869 /* prep the buffer with the original instructions */
14870 - memcpy(insnbuf, p->instr, p->len);
14871 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14872 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14873 (unsigned long)p->instr, p->len);
14874
14875 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14876 if (!uniproc_patched || num_possible_cpus() == 1)
14877 free_init_pages("SMP alternatives",
14878 (unsigned long)__smp_locks,
14879 - (unsigned long)__smp_locks_end);
14880 + PAGE_ALIGN((unsigned long)__smp_locks_end));
14881 #endif
14882
14883 apply_paravirt(__parainstructions, __parainstructions_end);
14884 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14885 * instructions. And on the local CPU you need to be protected again NMI or MCE
14886 * handlers seeing an inconsistent instruction while you patch.
14887 */
14888 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
14889 +void *__kprobes text_poke_early(void *addr, const void *opcode,
14890 size_t len)
14891 {
14892 unsigned long flags;
14893 local_irq_save(flags);
14894 - memcpy(addr, opcode, len);
14895 +
14896 + pax_open_kernel();
14897 + memcpy(ktla_ktva(addr), opcode, len);
14898 sync_core();
14899 + pax_close_kernel();
14900 +
14901 local_irq_restore(flags);
14902 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14903 that causes hangs on some VIA CPUs. */
14904 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14905 */
14906 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14907 {
14908 - unsigned long flags;
14909 - char *vaddr;
14910 + unsigned char *vaddr = ktla_ktva(addr);
14911 struct page *pages[2];
14912 - int i;
14913 + size_t i;
14914
14915 if (!core_kernel_text((unsigned long)addr)) {
14916 - pages[0] = vmalloc_to_page(addr);
14917 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14918 + pages[0] = vmalloc_to_page(vaddr);
14919 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14920 } else {
14921 - pages[0] = virt_to_page(addr);
14922 + pages[0] = virt_to_page(vaddr);
14923 WARN_ON(!PageReserved(pages[0]));
14924 - pages[1] = virt_to_page(addr + PAGE_SIZE);
14925 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14926 }
14927 BUG_ON(!pages[0]);
14928 - local_irq_save(flags);
14929 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14930 - if (pages[1])
14931 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14932 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14933 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14934 - clear_fixmap(FIX_TEXT_POKE0);
14935 - if (pages[1])
14936 - clear_fixmap(FIX_TEXT_POKE1);
14937 - local_flush_tlb();
14938 - sync_core();
14939 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
14940 - that causes hangs on some VIA CPUs. */
14941 + text_poke_early(addr, opcode, len);
14942 for (i = 0; i < len; i++)
14943 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14944 - local_irq_restore(flags);
14945 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14946 return addr;
14947 }
14948
14949 diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
14950 index e663112..21938a3 100644
14951 --- a/arch/x86/kernel/amd_gart_64.c
14952 +++ b/arch/x86/kernel/amd_gart_64.c
14953 @@ -851,7 +851,7 @@ int __init gart_iommu_init(void)
14954
14955 flush_gart();
14956 dma_ops = &gart_dma_ops;
14957 - x86_platform.iommu_shutdown = gart_iommu_shutdown;
14958 + *(void **)&x86_platform.iommu_shutdown = gart_iommu_shutdown;
14959 swiotlb = 0;
14960
14961 return 0;
14962 diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
14963 index d5fd66f..6119b16 100644
14964 --- a/arch/x86/kernel/aperture_64.c
14965 +++ b/arch/x86/kernel/aperture_64.c
14966 @@ -390,7 +390,7 @@ int __init gart_iommu_hole_init(void)
14967
14968 iommu_detected = 1;
14969 gart_iommu_aperture = 1;
14970 - x86_init.iommu.iommu_init = gart_iommu_init;
14971 + *(void **)&x86_init.iommu.iommu_init = gart_iommu_init;
14972
14973 ctl = read_pci_config(bus, slot, 3,
14974 AMD64_GARTAPERTURECTL);
14975 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14976 index b17416e..be6e5dc 100644
14977 --- a/arch/x86/kernel/apic/apic.c
14978 +++ b/arch/x86/kernel/apic/apic.c
14979 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14980 /*
14981 * Debug level, exported for io_apic.c
14982 */
14983 -unsigned int apic_verbosity;
14984 +int apic_verbosity;
14985
14986 int pic_mode;
14987
14988 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14989 apic_write(APIC_ESR, 0);
14990 v1 = apic_read(APIC_ESR);
14991 ack_APIC_irq();
14992 - atomic_inc(&irq_err_count);
14993 + atomic_inc_unchecked(&irq_err_count);
14994
14995 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14996 smp_processor_id(), v0 , v1);
14997 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
14998 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
14999 /* Should happen once for each apic */
15000 WARN_ON((*drv)->eoi_write == eoi_write);
15001 - (*drv)->eoi_write = eoi_write;
15002 + pax_open_kernel();
15003 + *(void **)&(*drv)->eoi_write = eoi_write;
15004 + pax_close_kernel();
15005 }
15006 }
15007
15008 diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
15009 index a65829a..6ddc249 100644
15010 --- a/arch/x86/kernel/apic/apic_numachip.c
15011 +++ b/arch/x86/kernel/apic/apic_numachip.c
15012 @@ -178,7 +178,7 @@ static int __init numachip_system_init(void)
15013 if (!numachip_system)
15014 return 0;
15015
15016 - x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
15017 + *(void **)&x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
15018
15019 map_csrs();
15020
15021 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
15022 index 1817fa9..7bff097 100644
15023 --- a/arch/x86/kernel/apic/io_apic.c
15024 +++ b/arch/x86/kernel/apic/io_apic.c
15025 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
15026 }
15027 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
15028
15029 -void lock_vector_lock(void)
15030 +void lock_vector_lock(void) __acquires(vector_lock)
15031 {
15032 /* Used to the online set of cpus does not change
15033 * during assign_irq_vector.
15034 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
15035 raw_spin_lock(&vector_lock);
15036 }
15037
15038 -void unlock_vector_lock(void)
15039 +void unlock_vector_lock(void) __releases(vector_lock)
15040 {
15041 raw_spin_unlock(&vector_lock);
15042 }
15043 @@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
15044 ack_APIC_irq();
15045 }
15046
15047 -atomic_t irq_mis_count;
15048 +atomic_unchecked_t irq_mis_count;
15049
15050 #ifdef CONFIG_GENERIC_PENDING_IRQ
15051 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
15052 @@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
15053 * at the cpu.
15054 */
15055 if (!(v & (1 << (i & 0x1f)))) {
15056 - atomic_inc(&irq_mis_count);
15057 + atomic_inc_unchecked(&irq_mis_count);
15058
15059 eoi_ioapic_irq(irq, cfg);
15060 }
15061 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
15062 index d661ee9..512c0a1 100644
15063 --- a/arch/x86/kernel/apic/numaq_32.c
15064 +++ b/arch/x86/kernel/apic/numaq_32.c
15065 @@ -257,14 +257,14 @@ static __init void early_check_numaq(void)
15066 early_get_smp_config();
15067
15068 if (found_numaq) {
15069 - x86_init.mpparse.mpc_record = numaq_mpc_record;
15070 - x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15071 - x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15072 - x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15073 - x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15074 - x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15075 - x86_init.timers.tsc_pre_init = numaq_tsc_init;
15076 - x86_init.pci.init = pci_numaq_init;
15077 + *(void **)&x86_init.mpparse.mpc_record = numaq_mpc_record;
15078 + *(void **)&x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15079 + *(void **)&x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15080 + *(void **)&x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15081 + *(void **)&x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15082 + *(void **)&x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15083 + *(void **)&x86_init.timers.tsc_pre_init = numaq_tsc_init;
15084 + *(void **)&x86_init.pci.init = pci_numaq_init;
15085 }
15086 }
15087
15088 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
15089 index 8cfade9..8ea7b51 100644
15090 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
15091 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
15092 @@ -139,8 +139,8 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
15093 is_uv1 ? UV1_HUB_REVISION_BASE : UV2_HUB_REVISION_BASE;
15094 pnodeid = early_get_pnodeid();
15095 early_get_apic_pnode_shift();
15096 - x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15097 - x86_platform.nmi_init = uv_nmi_init;
15098 + *(void **)&x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15099 + *(void **)&x86_platform.nmi_init = uv_nmi_init;
15100 if (!strcmp(oem_table_id, "UVL"))
15101 uv_system_type = UV_LEGACY_APIC;
15102 else if (!strcmp(oem_table_id, "UVX"))
15103 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
15104 index d65464e..1035d31 100644
15105 --- a/arch/x86/kernel/apm_32.c
15106 +++ b/arch/x86/kernel/apm_32.c
15107 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
15108 * This is for buggy BIOS's that refer to (real mode) segment 0x40
15109 * even though they are called in protected mode.
15110 */
15111 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
15112 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
15113 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
15114
15115 static const char driver_version[] = "1.16ac"; /* no spaces */
15116 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
15117 BUG_ON(cpu != 0);
15118 gdt = get_cpu_gdt_table(cpu);
15119 save_desc_40 = gdt[0x40 / 8];
15120 +
15121 + pax_open_kernel();
15122 gdt[0x40 / 8] = bad_bios_desc;
15123 + pax_close_kernel();
15124
15125 apm_irq_save(flags);
15126 APM_DO_SAVE_SEGS;
15127 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
15128 &call->esi);
15129 APM_DO_RESTORE_SEGS;
15130 apm_irq_restore(flags);
15131 +
15132 + pax_open_kernel();
15133 gdt[0x40 / 8] = save_desc_40;
15134 + pax_close_kernel();
15135 +
15136 put_cpu();
15137
15138 return call->eax & 0xff;
15139 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
15140 BUG_ON(cpu != 0);
15141 gdt = get_cpu_gdt_table(cpu);
15142 save_desc_40 = gdt[0x40 / 8];
15143 +
15144 + pax_open_kernel();
15145 gdt[0x40 / 8] = bad_bios_desc;
15146 + pax_close_kernel();
15147
15148 apm_irq_save(flags);
15149 APM_DO_SAVE_SEGS;
15150 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
15151 &call->eax);
15152 APM_DO_RESTORE_SEGS;
15153 apm_irq_restore(flags);
15154 +
15155 + pax_open_kernel();
15156 gdt[0x40 / 8] = save_desc_40;
15157 + pax_close_kernel();
15158 +
15159 put_cpu();
15160 return error;
15161 }
15162 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
15163 * code to that CPU.
15164 */
15165 gdt = get_cpu_gdt_table(0);
15166 +
15167 + pax_open_kernel();
15168 set_desc_base(&gdt[APM_CS >> 3],
15169 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
15170 set_desc_base(&gdt[APM_CS_16 >> 3],
15171 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
15172 set_desc_base(&gdt[APM_DS >> 3],
15173 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
15174 + pax_close_kernel();
15175
15176 proc_create("apm", 0, NULL, &apm_file_ops);
15177
15178 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
15179 index 2861082..6d4718e 100644
15180 --- a/arch/x86/kernel/asm-offsets.c
15181 +++ b/arch/x86/kernel/asm-offsets.c
15182 @@ -33,6 +33,8 @@ void common(void) {
15183 OFFSET(TI_status, thread_info, status);
15184 OFFSET(TI_addr_limit, thread_info, addr_limit);
15185 OFFSET(TI_preempt_count, thread_info, preempt_count);
15186 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
15187 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
15188
15189 BLANK();
15190 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
15191 @@ -53,8 +55,26 @@ void common(void) {
15192 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
15193 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
15194 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
15195 +
15196 +#ifdef CONFIG_PAX_KERNEXEC
15197 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
15198 #endif
15199
15200 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15201 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
15202 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
15203 +#ifdef CONFIG_X86_64
15204 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
15205 +#endif
15206 +#endif
15207 +
15208 +#endif
15209 +
15210 + BLANK();
15211 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
15212 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
15213 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
15214 +
15215 #ifdef CONFIG_XEN
15216 BLANK();
15217 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
15218 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
15219 index 1b4754f..fbb4227 100644
15220 --- a/arch/x86/kernel/asm-offsets_64.c
15221 +++ b/arch/x86/kernel/asm-offsets_64.c
15222 @@ -76,6 +76,7 @@ int main(void)
15223 BLANK();
15224 #undef ENTRY
15225
15226 + DEFINE(TSS_size, sizeof(struct tss_struct));
15227 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
15228 BLANK();
15229
15230 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
15231 index a0e067d..9c7db16 100644
15232 --- a/arch/x86/kernel/cpu/Makefile
15233 +++ b/arch/x86/kernel/cpu/Makefile
15234 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
15235 CFLAGS_REMOVE_perf_event.o = -pg
15236 endif
15237
15238 -# Make sure load_percpu_segment has no stackprotector
15239 -nostackp := $(call cc-option, -fno-stack-protector)
15240 -CFLAGS_common.o := $(nostackp)
15241 -
15242 obj-y := intel_cacheinfo.o scattered.o topology.o
15243 obj-y += proc.o capflags.o powerflags.o common.o
15244 obj-y += vmware.o hypervisor.o mshyperv.o
15245 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
15246 index 1b7d165..b9e2627 100644
15247 --- a/arch/x86/kernel/cpu/amd.c
15248 +++ b/arch/x86/kernel/cpu/amd.c
15249 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
15250 unsigned int size)
15251 {
15252 /* AMD errata T13 (order #21922) */
15253 - if ((c->x86 == 6)) {
15254 + if (c->x86 == 6) {
15255 /* Duron Rev A0 */
15256 if (c->x86_model == 3 && c->x86_mask == 0)
15257 size = 64;
15258 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
15259 index 7505f7b..d59dac0 100644
15260 --- a/arch/x86/kernel/cpu/common.c
15261 +++ b/arch/x86/kernel/cpu/common.c
15262 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
15263
15264 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
15265
15266 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15267 -#ifdef CONFIG_X86_64
15268 - /*
15269 - * We need valid kernel segments for data and code in long mode too
15270 - * IRET will check the segment types kkeil 2000/10/28
15271 - * Also sysret mandates a special GDT layout
15272 - *
15273 - * TLS descriptors are currently at a different place compared to i386.
15274 - * Hopefully nobody expects them at a fixed place (Wine?)
15275 - */
15276 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15277 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15278 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15279 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15280 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15281 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15282 -#else
15283 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15284 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15285 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15286 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15287 - /*
15288 - * Segments used for calling PnP BIOS have byte granularity.
15289 - * They code segments and data segments have fixed 64k limits,
15290 - * the transfer segment sizes are set at run time.
15291 - */
15292 - /* 32-bit code */
15293 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15294 - /* 16-bit code */
15295 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15296 - /* 16-bit data */
15297 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15298 - /* 16-bit data */
15299 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15300 - /* 16-bit data */
15301 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15302 - /*
15303 - * The APM segments have byte granularity and their bases
15304 - * are set at run time. All have 64k limits.
15305 - */
15306 - /* 32-bit code */
15307 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15308 - /* 16-bit code */
15309 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15310 - /* data */
15311 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15312 -
15313 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15314 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15315 - GDT_STACK_CANARY_INIT
15316 -#endif
15317 -} };
15318 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15319 -
15320 static int __init x86_xsave_setup(char *s)
15321 {
15322 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15323 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15324 {
15325 struct desc_ptr gdt_descr;
15326
15327 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15328 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15329 gdt_descr.size = GDT_SIZE - 1;
15330 load_gdt(&gdt_descr);
15331 /* Reload the per-cpu base */
15332 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15333 /* Filter out anything that depends on CPUID levels we don't have */
15334 filter_cpuid_features(c, true);
15335
15336 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15337 + setup_clear_cpu_cap(X86_FEATURE_SEP);
15338 +#endif
15339 +
15340 /* If the model name is still unset, do table lookup. */
15341 if (!c->x86_model_id[0]) {
15342 const char *p;
15343 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15344 }
15345 __setup("clearcpuid=", setup_disablecpuid);
15346
15347 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15348 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
15349 +
15350 #ifdef CONFIG_X86_64
15351 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15352 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15353 - (unsigned long) nmi_idt_table };
15354 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15355
15356 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15357 irq_stack_union) __aligned(PAGE_SIZE);
15358 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15359 EXPORT_PER_CPU_SYMBOL(current_task);
15360
15361 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15362 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15363 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15364 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15365
15366 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15367 @@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15368 {
15369 memset(regs, 0, sizeof(struct pt_regs));
15370 regs->fs = __KERNEL_PERCPU;
15371 - regs->gs = __KERNEL_STACK_CANARY;
15372 + savesegment(gs, regs->gs);
15373
15374 return regs;
15375 }
15376 @@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15377 int i;
15378
15379 cpu = stack_smp_processor_id();
15380 - t = &per_cpu(init_tss, cpu);
15381 + t = init_tss + cpu;
15382 oist = &per_cpu(orig_ist, cpu);
15383
15384 #ifdef CONFIG_NUMA
15385 @@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15386 switch_to_new_gdt(cpu);
15387 loadsegment(fs, 0);
15388
15389 - load_idt((const struct desc_ptr *)&idt_descr);
15390 + load_idt(&idt_descr);
15391
15392 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15393 syscall_init();
15394 @@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15395 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15396 barrier();
15397
15398 - x86_configure_nx();
15399 if (cpu != 0)
15400 enable_x2apic();
15401
15402 @@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15403 {
15404 int cpu = smp_processor_id();
15405 struct task_struct *curr = current;
15406 - struct tss_struct *t = &per_cpu(init_tss, cpu);
15407 + struct tss_struct *t = init_tss + cpu;
15408 struct thread_struct *thread = &curr->thread;
15409
15410 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15411 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15412 index 198e019..867575e 100644
15413 --- a/arch/x86/kernel/cpu/intel.c
15414 +++ b/arch/x86/kernel/cpu/intel.c
15415 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15416 * Update the IDT descriptor and reload the IDT so that
15417 * it uses the read-only mapped virtual address.
15418 */
15419 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15420 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15421 load_idt(&idt_descr);
15422 }
15423 #endif
15424 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15425 index 93c5451..3887433 100644
15426 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15427 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15428 @@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15429 };
15430
15431 #ifdef CONFIG_AMD_NB
15432 +static struct attribute *default_attrs_amd_nb[] = {
15433 + &type.attr,
15434 + &level.attr,
15435 + &coherency_line_size.attr,
15436 + &physical_line_partition.attr,
15437 + &ways_of_associativity.attr,
15438 + &number_of_sets.attr,
15439 + &size.attr,
15440 + &shared_cpu_map.attr,
15441 + &shared_cpu_list.attr,
15442 + NULL,
15443 + NULL,
15444 + NULL,
15445 + NULL
15446 +};
15447 +
15448 static struct attribute ** __cpuinit amd_l3_attrs(void)
15449 {
15450 static struct attribute **attrs;
15451 @@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15452
15453 n = ARRAY_SIZE(default_attrs);
15454
15455 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15456 - n += 2;
15457 -
15458 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15459 - n += 1;
15460 -
15461 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15462 - if (attrs == NULL)
15463 - return attrs = default_attrs;
15464 -
15465 - for (n = 0; default_attrs[n]; n++)
15466 - attrs[n] = default_attrs[n];
15467 + attrs = default_attrs_amd_nb;
15468
15469 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15470 attrs[n++] = &cache_disable_0.attr;
15471 @@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15472 .default_attrs = default_attrs,
15473 };
15474
15475 +#ifdef CONFIG_AMD_NB
15476 +static struct kobj_type ktype_cache_amd_nb = {
15477 + .sysfs_ops = &sysfs_ops,
15478 + .default_attrs = default_attrs_amd_nb,
15479 +};
15480 +#endif
15481 +
15482 static struct kobj_type ktype_percpu_entry = {
15483 .sysfs_ops = &sysfs_ops,
15484 };
15485 @@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15486 return retval;
15487 }
15488
15489 +#ifdef CONFIG_AMD_NB
15490 + amd_l3_attrs();
15491 +#endif
15492 +
15493 for (i = 0; i < num_cache_leaves; i++) {
15494 + struct kobj_type *ktype;
15495 +
15496 this_object = INDEX_KOBJECT_PTR(cpu, i);
15497 this_object->cpu = cpu;
15498 this_object->index = i;
15499
15500 this_leaf = CPUID4_INFO_IDX(cpu, i);
15501
15502 - ktype_cache.default_attrs = default_attrs;
15503 + ktype = &ktype_cache;
15504 #ifdef CONFIG_AMD_NB
15505 if (this_leaf->base.nb)
15506 - ktype_cache.default_attrs = amd_l3_attrs();
15507 + ktype = &ktype_cache_amd_nb;
15508 #endif
15509 retval = kobject_init_and_add(&(this_object->kobj),
15510 - &ktype_cache,
15511 + ktype,
15512 per_cpu(ici_cache_kobject, cpu),
15513 "index%1lu", i);
15514 if (unlikely(retval)) {
15515 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15516 index 46cbf86..55c7292 100644
15517 --- a/arch/x86/kernel/cpu/mcheck/mce.c
15518 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
15519 @@ -45,6 +45,7 @@
15520 #include <asm/processor.h>
15521 #include <asm/mce.h>
15522 #include <asm/msr.h>
15523 +#include <asm/local.h>
15524
15525 #include "mce-internal.h"
15526
15527 @@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15528 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15529 m->cs, m->ip);
15530
15531 - if (m->cs == __KERNEL_CS)
15532 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15533 print_symbol("{%s}", m->ip);
15534 pr_cont("\n");
15535 }
15536 @@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15537
15538 #define PANIC_TIMEOUT 5 /* 5 seconds */
15539
15540 -static atomic_t mce_paniced;
15541 +static atomic_unchecked_t mce_paniced;
15542
15543 static int fake_panic;
15544 -static atomic_t mce_fake_paniced;
15545 +static atomic_unchecked_t mce_fake_paniced;
15546
15547 /* Panic in progress. Enable interrupts and wait for final IPI */
15548 static void wait_for_panic(void)
15549 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15550 /*
15551 * Make sure only one CPU runs in machine check panic
15552 */
15553 - if (atomic_inc_return(&mce_paniced) > 1)
15554 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15555 wait_for_panic();
15556 barrier();
15557
15558 @@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15559 console_verbose();
15560 } else {
15561 /* Don't log too much for fake panic */
15562 - if (atomic_inc_return(&mce_fake_paniced) > 1)
15563 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15564 return;
15565 }
15566 /* First print corrected ones that are still unlogged */
15567 @@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15568 * might have been modified by someone else.
15569 */
15570 rmb();
15571 - if (atomic_read(&mce_paniced))
15572 + if (atomic_read_unchecked(&mce_paniced))
15573 wait_for_panic();
15574 if (!monarch_timeout)
15575 goto out;
15576 @@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15577 }
15578
15579 /* Call the installed machine check handler for this CPU setup. */
15580 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
15581 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15582 unexpected_machine_check;
15583
15584 /*
15585 @@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15586 return;
15587 }
15588
15589 + pax_open_kernel();
15590 machine_check_vector = do_machine_check;
15591 + pax_close_kernel();
15592
15593 __mcheck_cpu_init_generic();
15594 __mcheck_cpu_init_vendor(c);
15595 @@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15596 */
15597
15598 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15599 -static int mce_chrdev_open_count; /* #times opened */
15600 +static local_t mce_chrdev_open_count; /* #times opened */
15601 static int mce_chrdev_open_exclu; /* already open exclusive? */
15602
15603 static int mce_chrdev_open(struct inode *inode, struct file *file)
15604 @@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15605 spin_lock(&mce_chrdev_state_lock);
15606
15607 if (mce_chrdev_open_exclu ||
15608 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15609 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15610 spin_unlock(&mce_chrdev_state_lock);
15611
15612 return -EBUSY;
15613 @@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15614
15615 if (file->f_flags & O_EXCL)
15616 mce_chrdev_open_exclu = 1;
15617 - mce_chrdev_open_count++;
15618 + local_inc(&mce_chrdev_open_count);
15619
15620 spin_unlock(&mce_chrdev_state_lock);
15621
15622 @@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15623 {
15624 spin_lock(&mce_chrdev_state_lock);
15625
15626 - mce_chrdev_open_count--;
15627 + local_dec(&mce_chrdev_open_count);
15628 mce_chrdev_open_exclu = 0;
15629
15630 spin_unlock(&mce_chrdev_state_lock);
15631 @@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15632 return NOTIFY_OK;
15633 }
15634
15635 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15636 +static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15637 .notifier_call = mce_cpu_callback,
15638 };
15639
15640 @@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15641 static void mce_reset(void)
15642 {
15643 cpu_missing = 0;
15644 - atomic_set(&mce_fake_paniced, 0);
15645 + atomic_set_unchecked(&mce_fake_paniced, 0);
15646 atomic_set(&mce_executing, 0);
15647 atomic_set(&mce_callin, 0);
15648 atomic_set(&global_nwo, 0);
15649 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15650 index 2d5454c..51987eb 100644
15651 --- a/arch/x86/kernel/cpu/mcheck/p5.c
15652 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
15653 @@ -11,6 +11,7 @@
15654 #include <asm/processor.h>
15655 #include <asm/mce.h>
15656 #include <asm/msr.h>
15657 +#include <asm/pgtable.h>
15658
15659 /* By default disabled */
15660 int mce_p5_enabled __read_mostly;
15661 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15662 if (!cpu_has(c, X86_FEATURE_MCE))
15663 return;
15664
15665 + pax_open_kernel();
15666 machine_check_vector = pentium_machine_check;
15667 + pax_close_kernel();
15668 /* Make sure the vector pointer is visible before we enable MCEs: */
15669 wmb();
15670
15671 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15672 index 2d7998f..17c9de1 100644
15673 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
15674 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15675 @@ -10,6 +10,7 @@
15676 #include <asm/processor.h>
15677 #include <asm/mce.h>
15678 #include <asm/msr.h>
15679 +#include <asm/pgtable.h>
15680
15681 /* Machine check handler for WinChip C6: */
15682 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15683 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15684 {
15685 u32 lo, hi;
15686
15687 + pax_open_kernel();
15688 machine_check_vector = winchip_machine_check;
15689 + pax_close_kernel();
15690 /* Make sure the vector pointer is visible before we enable MCEs: */
15691 wmb();
15692
15693 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15694 index 6b96110..0da73eb 100644
15695 --- a/arch/x86/kernel/cpu/mtrr/main.c
15696 +++ b/arch/x86/kernel/cpu/mtrr/main.c
15697 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15698 u64 size_or_mask, size_and_mask;
15699 static bool mtrr_aps_delayed_init;
15700
15701 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15702 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15703
15704 const struct mtrr_ops *mtrr_if;
15705
15706 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15707 index df5e41f..816c719 100644
15708 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15709 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15710 @@ -25,7 +25,7 @@ struct mtrr_ops {
15711 int (*validate_add_page)(unsigned long base, unsigned long size,
15712 unsigned int type);
15713 int (*have_wrcomb)(void);
15714 -};
15715 +} __do_const;
15716
15717 extern int generic_get_free_region(unsigned long base, unsigned long size,
15718 int replace_reg);
15719 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15720 index d18b2b8..d3b834c 100644
15721 --- a/arch/x86/kernel/cpu/perf_event.c
15722 +++ b/arch/x86/kernel/cpu/perf_event.c
15723 @@ -1759,7 +1759,7 @@ static unsigned long get_segment_base(unsigned int segment)
15724 if (idx > GDT_ENTRIES)
15725 return 0;
15726
15727 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15728 + desc = get_cpu_gdt_table(smp_processor_id());
15729 }
15730
15731 return get_desc_base(desc + idx);
15732 @@ -1849,7 +1849,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15733 break;
15734
15735 perf_callchain_store(entry, frame.return_address);
15736 - fp = frame.next_frame;
15737 + fp = (const void __force_user *)frame.next_frame;
15738 }
15739 }
15740
15741 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15742 index 324bb52..1a93d85 100644
15743 --- a/arch/x86/kernel/cpu/perf_event_intel.c
15744 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
15745 @@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15746 * v2 and above have a perf capabilities MSR
15747 */
15748 if (version > 1) {
15749 - u64 capabilities;
15750 + u64 capabilities = x86_pmu.intel_cap.capabilities;
15751
15752 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15753 - x86_pmu.intel_cap.capabilities = capabilities;
15754 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15755 + x86_pmu.intel_cap.capabilities = capabilities;
15756 }
15757
15758 intel_ds_init();
15759 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
15760 index d22d0c4..088eb6f 100644
15761 --- a/arch/x86/kernel/cpu/vmware.c
15762 +++ b/arch/x86/kernel/cpu/vmware.c
15763 @@ -79,7 +79,7 @@ static void __init vmware_platform_setup(void)
15764 VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
15765
15766 if (ebx != UINT_MAX)
15767 - x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15768 + *(void **)&x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15769 else
15770 printk(KERN_WARNING
15771 "Failed to get TSC freq from the hypervisor\n");
15772 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15773 index 13ad899..f642b9a 100644
15774 --- a/arch/x86/kernel/crash.c
15775 +++ b/arch/x86/kernel/crash.c
15776 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15777 {
15778 #ifdef CONFIG_X86_32
15779 struct pt_regs fixed_regs;
15780 -#endif
15781
15782 -#ifdef CONFIG_X86_32
15783 - if (!user_mode_vm(regs)) {
15784 + if (!user_mode(regs)) {
15785 crash_fixup_ss_esp(&fixed_regs, regs);
15786 regs = &fixed_regs;
15787 }
15788 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15789 index 37250fe..bf2ec74 100644
15790 --- a/arch/x86/kernel/doublefault_32.c
15791 +++ b/arch/x86/kernel/doublefault_32.c
15792 @@ -11,7 +11,7 @@
15793
15794 #define DOUBLEFAULT_STACKSIZE (1024)
15795 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15796 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15797 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15798
15799 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15800
15801 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
15802 unsigned long gdt, tss;
15803
15804 store_gdt(&gdt_desc);
15805 - gdt = gdt_desc.address;
15806 + gdt = (unsigned long)gdt_desc.address;
15807
15808 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15809
15810 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15811 /* 0x2 bit is always set */
15812 .flags = X86_EFLAGS_SF | 0x2,
15813 .sp = STACK_START,
15814 - .es = __USER_DS,
15815 + .es = __KERNEL_DS,
15816 .cs = __KERNEL_CS,
15817 .ss = __KERNEL_DS,
15818 - .ds = __USER_DS,
15819 + .ds = __KERNEL_DS,
15820 .fs = __KERNEL_PERCPU,
15821
15822 .__cr3 = __pa_nodebug(swapper_pg_dir),
15823 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15824 index ae42418b..787c16b 100644
15825 --- a/arch/x86/kernel/dumpstack.c
15826 +++ b/arch/x86/kernel/dumpstack.c
15827 @@ -2,6 +2,9 @@
15828 * Copyright (C) 1991, 1992 Linus Torvalds
15829 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15830 */
15831 +#ifdef CONFIG_GRKERNSEC_HIDESYM
15832 +#define __INCLUDED_BY_HIDESYM 1
15833 +#endif
15834 #include <linux/kallsyms.h>
15835 #include <linux/kprobes.h>
15836 #include <linux/uaccess.h>
15837 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15838 static void
15839 print_ftrace_graph_addr(unsigned long addr, void *data,
15840 const struct stacktrace_ops *ops,
15841 - struct thread_info *tinfo, int *graph)
15842 + struct task_struct *task, int *graph)
15843 {
15844 - struct task_struct *task;
15845 unsigned long ret_addr;
15846 int index;
15847
15848 if (addr != (unsigned long)return_to_handler)
15849 return;
15850
15851 - task = tinfo->task;
15852 index = task->curr_ret_stack;
15853
15854 if (!task->ret_stack || index < *graph)
15855 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15856 static inline void
15857 print_ftrace_graph_addr(unsigned long addr, void *data,
15858 const struct stacktrace_ops *ops,
15859 - struct thread_info *tinfo, int *graph)
15860 + struct task_struct *task, int *graph)
15861 { }
15862 #endif
15863
15864 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15865 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15866 */
15867
15868 -static inline int valid_stack_ptr(struct thread_info *tinfo,
15869 - void *p, unsigned int size, void *end)
15870 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15871 {
15872 - void *t = tinfo;
15873 if (end) {
15874 if (p < end && p >= (end-THREAD_SIZE))
15875 return 1;
15876 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15877 }
15878
15879 unsigned long
15880 -print_context_stack(struct thread_info *tinfo,
15881 +print_context_stack(struct task_struct *task, void *stack_start,
15882 unsigned long *stack, unsigned long bp,
15883 const struct stacktrace_ops *ops, void *data,
15884 unsigned long *end, int *graph)
15885 {
15886 struct stack_frame *frame = (struct stack_frame *)bp;
15887
15888 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15889 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15890 unsigned long addr;
15891
15892 addr = *stack;
15893 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15894 } else {
15895 ops->address(data, addr, 0);
15896 }
15897 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15898 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15899 }
15900 stack++;
15901 }
15902 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
15903 EXPORT_SYMBOL_GPL(print_context_stack);
15904
15905 unsigned long
15906 -print_context_stack_bp(struct thread_info *tinfo,
15907 +print_context_stack_bp(struct task_struct *task, void *stack_start,
15908 unsigned long *stack, unsigned long bp,
15909 const struct stacktrace_ops *ops, void *data,
15910 unsigned long *end, int *graph)
15911 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15912 struct stack_frame *frame = (struct stack_frame *)bp;
15913 unsigned long *ret_addr = &frame->return_address;
15914
15915 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
15916 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
15917 unsigned long addr = *ret_addr;
15918
15919 if (!__kernel_text_address(addr))
15920 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15921 ops->address(data, addr, 1);
15922 frame = frame->next_frame;
15923 ret_addr = &frame->return_address;
15924 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15925 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15926 }
15927
15928 return (unsigned long)frame;
15929 @@ -189,7 +188,7 @@ void dump_stack(void)
15930
15931 bp = stack_frame(current, NULL);
15932 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
15933 - current->pid, current->comm, print_tainted(),
15934 + task_pid_nr(current), current->comm, print_tainted(),
15935 init_utsname()->release,
15936 (int)strcspn(init_utsname()->version, " "),
15937 init_utsname()->version);
15938 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
15939 }
15940 EXPORT_SYMBOL_GPL(oops_begin);
15941
15942 +extern void gr_handle_kernel_exploit(void);
15943 +
15944 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15945 {
15946 if (regs && kexec_should_crash(current))
15947 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15948 panic("Fatal exception in interrupt");
15949 if (panic_on_oops)
15950 panic("Fatal exception");
15951 - do_exit(signr);
15952 +
15953 + gr_handle_kernel_exploit();
15954 +
15955 + do_group_exit(signr);
15956 }
15957
15958 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15959 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15960 print_modules();
15961 show_regs(regs);
15962 #ifdef CONFIG_X86_32
15963 - if (user_mode_vm(regs)) {
15964 + if (user_mode(regs)) {
15965 sp = regs->sp;
15966 ss = regs->ss & 0xffff;
15967 } else {
15968 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
15969 unsigned long flags = oops_begin();
15970 int sig = SIGSEGV;
15971
15972 - if (!user_mode_vm(regs))
15973 + if (!user_mode(regs))
15974 report_bug(regs->ip, regs);
15975
15976 if (__die(str, regs, err))
15977 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
15978 index 1038a41..db2c12b 100644
15979 --- a/arch/x86/kernel/dumpstack_32.c
15980 +++ b/arch/x86/kernel/dumpstack_32.c
15981 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15982 bp = stack_frame(task, regs);
15983
15984 for (;;) {
15985 - struct thread_info *context;
15986 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15987
15988 - context = (struct thread_info *)
15989 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
15990 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
15991 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15992
15993 - stack = (unsigned long *)context->previous_esp;
15994 - if (!stack)
15995 + if (stack_start == task_stack_page(task))
15996 break;
15997 + stack = *(unsigned long **)stack_start;
15998 if (ops->stack(data, "IRQ") < 0)
15999 break;
16000 touch_nmi_watchdog();
16001 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
16002 {
16003 int i;
16004
16005 - __show_regs(regs, !user_mode_vm(regs));
16006 + __show_regs(regs, !user_mode(regs));
16007
16008 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
16009 TASK_COMM_LEN, current->comm, task_pid_nr(current),
16010 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
16011 * When in-kernel, we also print out the stack and code at the
16012 * time of the fault..
16013 */
16014 - if (!user_mode_vm(regs)) {
16015 + if (!user_mode(regs)) {
16016 unsigned int code_prologue = code_bytes * 43 / 64;
16017 unsigned int code_len = code_bytes;
16018 unsigned char c;
16019 u8 *ip;
16020 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
16021
16022 pr_emerg("Stack:\n");
16023 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
16024
16025 pr_emerg("Code:");
16026
16027 - ip = (u8 *)regs->ip - code_prologue;
16028 + ip = (u8 *)regs->ip - code_prologue + cs_base;
16029 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
16030 /* try starting at IP */
16031 - ip = (u8 *)regs->ip;
16032 + ip = (u8 *)regs->ip + cs_base;
16033 code_len = code_len - code_prologue + 1;
16034 }
16035 for (i = 0; i < code_len; i++, ip++) {
16036 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
16037 pr_cont(" Bad EIP value.");
16038 break;
16039 }
16040 - if (ip == (u8 *)regs->ip)
16041 + if (ip == (u8 *)regs->ip + cs_base)
16042 pr_cont(" <%02x>", c);
16043 else
16044 pr_cont(" %02x", c);
16045 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
16046 {
16047 unsigned short ud2;
16048
16049 + ip = ktla_ktva(ip);
16050 if (ip < PAGE_OFFSET)
16051 return 0;
16052 if (probe_kernel_address((unsigned short *)ip, ud2))
16053 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
16054
16055 return ud2 == 0x0b0f;
16056 }
16057 +
16058 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16059 +void pax_check_alloca(unsigned long size)
16060 +{
16061 + unsigned long sp = (unsigned long)&sp, stack_left;
16062 +
16063 + /* all kernel stacks are of the same size */
16064 + stack_left = sp & (THREAD_SIZE - 1);
16065 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16066 +}
16067 +EXPORT_SYMBOL(pax_check_alloca);
16068 +#endif
16069 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
16070 index b653675..51cc8c0 100644
16071 --- a/arch/x86/kernel/dumpstack_64.c
16072 +++ b/arch/x86/kernel/dumpstack_64.c
16073 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16074 unsigned long *irq_stack_end =
16075 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
16076 unsigned used = 0;
16077 - struct thread_info *tinfo;
16078 int graph = 0;
16079 unsigned long dummy;
16080 + void *stack_start;
16081
16082 if (!task)
16083 task = current;
16084 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16085 * current stack address. If the stacks consist of nested
16086 * exceptions
16087 */
16088 - tinfo = task_thread_info(task);
16089 for (;;) {
16090 char *id;
16091 unsigned long *estack_end;
16092 +
16093 estack_end = in_exception_stack(cpu, (unsigned long)stack,
16094 &used, &id);
16095
16096 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16097 if (ops->stack(data, id) < 0)
16098 break;
16099
16100 - bp = ops->walk_stack(tinfo, stack, bp, ops,
16101 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
16102 data, estack_end, &graph);
16103 ops->stack(data, "<EOE>");
16104 /*
16105 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16106 * second-to-last pointer (index -2 to end) in the
16107 * exception stack:
16108 */
16109 + if ((u16)estack_end[-1] != __KERNEL_DS)
16110 + goto out;
16111 stack = (unsigned long *) estack_end[-2];
16112 continue;
16113 }
16114 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16115 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
16116 if (ops->stack(data, "IRQ") < 0)
16117 break;
16118 - bp = ops->walk_stack(tinfo, stack, bp,
16119 + bp = ops->walk_stack(task, irq_stack, stack, bp,
16120 ops, data, irq_stack_end, &graph);
16121 /*
16122 * We link to the next stack (which would be
16123 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16124 /*
16125 * This handles the process stack:
16126 */
16127 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
16128 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16129 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16130 +out:
16131 put_cpu();
16132 }
16133 EXPORT_SYMBOL(dump_trace);
16134 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
16135 {
16136 int i;
16137 unsigned long sp;
16138 - const int cpu = smp_processor_id();
16139 + const int cpu = raw_smp_processor_id();
16140 struct task_struct *cur = current;
16141
16142 sp = regs->sp;
16143 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
16144
16145 return ud2 == 0x0b0f;
16146 }
16147 +
16148 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16149 +void pax_check_alloca(unsigned long size)
16150 +{
16151 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
16152 + unsigned cpu, used;
16153 + char *id;
16154 +
16155 + /* check the process stack first */
16156 + stack_start = (unsigned long)task_stack_page(current);
16157 + stack_end = stack_start + THREAD_SIZE;
16158 + if (likely(stack_start <= sp && sp < stack_end)) {
16159 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
16160 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16161 + return;
16162 + }
16163 +
16164 + cpu = get_cpu();
16165 +
16166 + /* check the irq stacks */
16167 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
16168 + stack_start = stack_end - IRQ_STACK_SIZE;
16169 + if (stack_start <= sp && sp < stack_end) {
16170 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
16171 + put_cpu();
16172 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16173 + return;
16174 + }
16175 +
16176 + /* check the exception stacks */
16177 + used = 0;
16178 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
16179 + stack_start = stack_end - EXCEPTION_STKSZ;
16180 + if (stack_end && stack_start <= sp && sp < stack_end) {
16181 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
16182 + put_cpu();
16183 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16184 + return;
16185 + }
16186 +
16187 + put_cpu();
16188 +
16189 + /* unknown stack */
16190 + BUG();
16191 +}
16192 +EXPORT_SYMBOL(pax_check_alloca);
16193 +#endif
16194 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
16195 index 9b9f18b..9fcaa04 100644
16196 --- a/arch/x86/kernel/early_printk.c
16197 +++ b/arch/x86/kernel/early_printk.c
16198 @@ -7,6 +7,7 @@
16199 #include <linux/pci_regs.h>
16200 #include <linux/pci_ids.h>
16201 #include <linux/errno.h>
16202 +#include <linux/sched.h>
16203 #include <asm/io.h>
16204 #include <asm/processor.h>
16205 #include <asm/fcntl.h>
16206 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
16207 index cf8639b..6c6a674 100644
16208 --- a/arch/x86/kernel/entry_32.S
16209 +++ b/arch/x86/kernel/entry_32.S
16210 @@ -177,13 +177,153 @@
16211 /*CFI_REL_OFFSET gs, PT_GS*/
16212 .endm
16213 .macro SET_KERNEL_GS reg
16214 +
16215 +#ifdef CONFIG_CC_STACKPROTECTOR
16216 movl $(__KERNEL_STACK_CANARY), \reg
16217 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16218 + movl $(__USER_DS), \reg
16219 +#else
16220 + xorl \reg, \reg
16221 +#endif
16222 +
16223 movl \reg, %gs
16224 .endm
16225
16226 #endif /* CONFIG_X86_32_LAZY_GS */
16227
16228 -.macro SAVE_ALL
16229 +.macro pax_enter_kernel
16230 +#ifdef CONFIG_PAX_KERNEXEC
16231 + call pax_enter_kernel
16232 +#endif
16233 +.endm
16234 +
16235 +.macro pax_exit_kernel
16236 +#ifdef CONFIG_PAX_KERNEXEC
16237 + call pax_exit_kernel
16238 +#endif
16239 +.endm
16240 +
16241 +#ifdef CONFIG_PAX_KERNEXEC
16242 +ENTRY(pax_enter_kernel)
16243 +#ifdef CONFIG_PARAVIRT
16244 + pushl %eax
16245 + pushl %ecx
16246 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
16247 + mov %eax, %esi
16248 +#else
16249 + mov %cr0, %esi
16250 +#endif
16251 + bts $16, %esi
16252 + jnc 1f
16253 + mov %cs, %esi
16254 + cmp $__KERNEL_CS, %esi
16255 + jz 3f
16256 + ljmp $__KERNEL_CS, $3f
16257 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
16258 +2:
16259 +#ifdef CONFIG_PARAVIRT
16260 + mov %esi, %eax
16261 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16262 +#else
16263 + mov %esi, %cr0
16264 +#endif
16265 +3:
16266 +#ifdef CONFIG_PARAVIRT
16267 + popl %ecx
16268 + popl %eax
16269 +#endif
16270 + ret
16271 +ENDPROC(pax_enter_kernel)
16272 +
16273 +ENTRY(pax_exit_kernel)
16274 +#ifdef CONFIG_PARAVIRT
16275 + pushl %eax
16276 + pushl %ecx
16277 +#endif
16278 + mov %cs, %esi
16279 + cmp $__KERNEXEC_KERNEL_CS, %esi
16280 + jnz 2f
16281 +#ifdef CONFIG_PARAVIRT
16282 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16283 + mov %eax, %esi
16284 +#else
16285 + mov %cr0, %esi
16286 +#endif
16287 + btr $16, %esi
16288 + ljmp $__KERNEL_CS, $1f
16289 +1:
16290 +#ifdef CONFIG_PARAVIRT
16291 + mov %esi, %eax
16292 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16293 +#else
16294 + mov %esi, %cr0
16295 +#endif
16296 +2:
16297 +#ifdef CONFIG_PARAVIRT
16298 + popl %ecx
16299 + popl %eax
16300 +#endif
16301 + ret
16302 +ENDPROC(pax_exit_kernel)
16303 +#endif
16304 +
16305 +.macro pax_erase_kstack
16306 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16307 + call pax_erase_kstack
16308 +#endif
16309 +.endm
16310 +
16311 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16312 +/*
16313 + * ebp: thread_info
16314 + */
16315 +ENTRY(pax_erase_kstack)
16316 + pushl %edi
16317 + pushl %ecx
16318 + pushl %eax
16319 +
16320 + mov TI_lowest_stack(%ebp), %edi
16321 + mov $-0xBEEF, %eax
16322 + std
16323 +
16324 +1: mov %edi, %ecx
16325 + and $THREAD_SIZE_asm - 1, %ecx
16326 + shr $2, %ecx
16327 + repne scasl
16328 + jecxz 2f
16329 +
16330 + cmp $2*16, %ecx
16331 + jc 2f
16332 +
16333 + mov $2*16, %ecx
16334 + repe scasl
16335 + jecxz 2f
16336 + jne 1b
16337 +
16338 +2: cld
16339 + mov %esp, %ecx
16340 + sub %edi, %ecx
16341 +
16342 + cmp $THREAD_SIZE_asm, %ecx
16343 + jb 3f
16344 + ud2
16345 +3:
16346 +
16347 + shr $2, %ecx
16348 + rep stosl
16349 +
16350 + mov TI_task_thread_sp0(%ebp), %edi
16351 + sub $128, %edi
16352 + mov %edi, TI_lowest_stack(%ebp)
16353 +
16354 + popl %eax
16355 + popl %ecx
16356 + popl %edi
16357 + ret
16358 +ENDPROC(pax_erase_kstack)
16359 +#endif
16360 +
16361 +.macro __SAVE_ALL _DS
16362 cld
16363 PUSH_GS
16364 pushl_cfi %fs
16365 @@ -206,7 +346,7 @@
16366 CFI_REL_OFFSET ecx, 0
16367 pushl_cfi %ebx
16368 CFI_REL_OFFSET ebx, 0
16369 - movl $(__USER_DS), %edx
16370 + movl $\_DS, %edx
16371 movl %edx, %ds
16372 movl %edx, %es
16373 movl $(__KERNEL_PERCPU), %edx
16374 @@ -214,6 +354,15 @@
16375 SET_KERNEL_GS %edx
16376 .endm
16377
16378 +.macro SAVE_ALL
16379 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16380 + __SAVE_ALL __KERNEL_DS
16381 + pax_enter_kernel
16382 +#else
16383 + __SAVE_ALL __USER_DS
16384 +#endif
16385 +.endm
16386 +
16387 .macro RESTORE_INT_REGS
16388 popl_cfi %ebx
16389 CFI_RESTORE ebx
16390 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16391 popfl_cfi
16392 jmp syscall_exit
16393 CFI_ENDPROC
16394 -END(ret_from_fork)
16395 +ENDPROC(ret_from_fork)
16396
16397 ENTRY(ret_from_kernel_thread)
16398 CFI_STARTPROC
16399 @@ -344,7 +493,15 @@ ret_from_intr:
16400 andl $SEGMENT_RPL_MASK, %eax
16401 #endif
16402 cmpl $USER_RPL, %eax
16403 +
16404 +#ifdef CONFIG_PAX_KERNEXEC
16405 + jae resume_userspace
16406 +
16407 + pax_exit_kernel
16408 + jmp resume_kernel
16409 +#else
16410 jb resume_kernel # not returning to v8086 or userspace
16411 +#endif
16412
16413 ENTRY(resume_userspace)
16414 LOCKDEP_SYS_EXIT
16415 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16416 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16417 # int/exception return?
16418 jne work_pending
16419 - jmp restore_all
16420 -END(ret_from_exception)
16421 + jmp restore_all_pax
16422 +ENDPROC(ret_from_exception)
16423
16424 #ifdef CONFIG_PREEMPT
16425 ENTRY(resume_kernel)
16426 @@ -372,7 +529,7 @@ need_resched:
16427 jz restore_all
16428 call preempt_schedule_irq
16429 jmp need_resched
16430 -END(resume_kernel)
16431 +ENDPROC(resume_kernel)
16432 #endif
16433 CFI_ENDPROC
16434 /*
16435 @@ -406,30 +563,45 @@ sysenter_past_esp:
16436 /*CFI_REL_OFFSET cs, 0*/
16437 /*
16438 * Push current_thread_info()->sysenter_return to the stack.
16439 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16440 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
16441 */
16442 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16443 + pushl_cfi $0
16444 CFI_REL_OFFSET eip, 0
16445
16446 pushl_cfi %eax
16447 SAVE_ALL
16448 + GET_THREAD_INFO(%ebp)
16449 + movl TI_sysenter_return(%ebp),%ebp
16450 + movl %ebp,PT_EIP(%esp)
16451 ENABLE_INTERRUPTS(CLBR_NONE)
16452
16453 /*
16454 * Load the potential sixth argument from user stack.
16455 * Careful about security.
16456 */
16457 + movl PT_OLDESP(%esp),%ebp
16458 +
16459 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16460 + mov PT_OLDSS(%esp),%ds
16461 +1: movl %ds:(%ebp),%ebp
16462 + push %ss
16463 + pop %ds
16464 +#else
16465 cmpl $__PAGE_OFFSET-3,%ebp
16466 jae syscall_fault
16467 ASM_STAC
16468 1: movl (%ebp),%ebp
16469 ASM_CLAC
16470 +#endif
16471 +
16472 movl %ebp,PT_EBP(%esp)
16473 _ASM_EXTABLE(1b,syscall_fault)
16474
16475 GET_THREAD_INFO(%ebp)
16476
16477 +#ifdef CONFIG_PAX_RANDKSTACK
16478 + pax_erase_kstack
16479 +#endif
16480 +
16481 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16482 jnz sysenter_audit
16483 sysenter_do_call:
16484 @@ -444,12 +616,24 @@ sysenter_do_call:
16485 testl $_TIF_ALLWORK_MASK, %ecx
16486 jne sysexit_audit
16487 sysenter_exit:
16488 +
16489 +#ifdef CONFIG_PAX_RANDKSTACK
16490 + pushl_cfi %eax
16491 + movl %esp, %eax
16492 + call pax_randomize_kstack
16493 + popl_cfi %eax
16494 +#endif
16495 +
16496 + pax_erase_kstack
16497 +
16498 /* if something modifies registers it must also disable sysexit */
16499 movl PT_EIP(%esp), %edx
16500 movl PT_OLDESP(%esp), %ecx
16501 xorl %ebp,%ebp
16502 TRACE_IRQS_ON
16503 1: mov PT_FS(%esp), %fs
16504 +2: mov PT_DS(%esp), %ds
16505 +3: mov PT_ES(%esp), %es
16506 PTGS_TO_GS
16507 ENABLE_INTERRUPTS_SYSEXIT
16508
16509 @@ -466,6 +650,9 @@ sysenter_audit:
16510 movl %eax,%edx /* 2nd arg: syscall number */
16511 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16512 call __audit_syscall_entry
16513 +
16514 + pax_erase_kstack
16515 +
16516 pushl_cfi %ebx
16517 movl PT_EAX(%esp),%eax /* reload syscall number */
16518 jmp sysenter_do_call
16519 @@ -491,10 +678,16 @@ sysexit_audit:
16520
16521 CFI_ENDPROC
16522 .pushsection .fixup,"ax"
16523 -2: movl $0,PT_FS(%esp)
16524 +4: movl $0,PT_FS(%esp)
16525 + jmp 1b
16526 +5: movl $0,PT_DS(%esp)
16527 + jmp 1b
16528 +6: movl $0,PT_ES(%esp)
16529 jmp 1b
16530 .popsection
16531 - _ASM_EXTABLE(1b,2b)
16532 + _ASM_EXTABLE(1b,4b)
16533 + _ASM_EXTABLE(2b,5b)
16534 + _ASM_EXTABLE(3b,6b)
16535 PTGS_TO_GS_EX
16536 ENDPROC(ia32_sysenter_target)
16537
16538 @@ -509,6 +702,11 @@ ENTRY(system_call)
16539 pushl_cfi %eax # save orig_eax
16540 SAVE_ALL
16541 GET_THREAD_INFO(%ebp)
16542 +
16543 +#ifdef CONFIG_PAX_RANDKSTACK
16544 + pax_erase_kstack
16545 +#endif
16546 +
16547 # system call tracing in operation / emulation
16548 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16549 jnz syscall_trace_entry
16550 @@ -527,6 +725,15 @@ syscall_exit:
16551 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16552 jne syscall_exit_work
16553
16554 +restore_all_pax:
16555 +
16556 +#ifdef CONFIG_PAX_RANDKSTACK
16557 + movl %esp, %eax
16558 + call pax_randomize_kstack
16559 +#endif
16560 +
16561 + pax_erase_kstack
16562 +
16563 restore_all:
16564 TRACE_IRQS_IRET
16565 restore_all_notrace:
16566 @@ -583,14 +790,34 @@ ldt_ss:
16567 * compensating for the offset by changing to the ESPFIX segment with
16568 * a base address that matches for the difference.
16569 */
16570 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16571 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16572 mov %esp, %edx /* load kernel esp */
16573 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16574 mov %dx, %ax /* eax: new kernel esp */
16575 sub %eax, %edx /* offset (low word is 0) */
16576 +#ifdef CONFIG_SMP
16577 + movl PER_CPU_VAR(cpu_number), %ebx
16578 + shll $PAGE_SHIFT_asm, %ebx
16579 + addl $cpu_gdt_table, %ebx
16580 +#else
16581 + movl $cpu_gdt_table, %ebx
16582 +#endif
16583 shr $16, %edx
16584 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16585 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16586 +
16587 +#ifdef CONFIG_PAX_KERNEXEC
16588 + mov %cr0, %esi
16589 + btr $16, %esi
16590 + mov %esi, %cr0
16591 +#endif
16592 +
16593 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16594 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16595 +
16596 +#ifdef CONFIG_PAX_KERNEXEC
16597 + bts $16, %esi
16598 + mov %esi, %cr0
16599 +#endif
16600 +
16601 pushl_cfi $__ESPFIX_SS
16602 pushl_cfi %eax /* new kernel esp */
16603 /* Disable interrupts, but do not irqtrace this section: we
16604 @@ -619,20 +846,18 @@ work_resched:
16605 movl TI_flags(%ebp), %ecx
16606 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16607 # than syscall tracing?
16608 - jz restore_all
16609 + jz restore_all_pax
16610 testb $_TIF_NEED_RESCHED, %cl
16611 jnz work_resched
16612
16613 work_notifysig: # deal with pending signals and
16614 # notify-resume requests
16615 + movl %esp, %eax
16616 #ifdef CONFIG_VM86
16617 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16618 - movl %esp, %eax
16619 jne work_notifysig_v86 # returning to kernel-space or
16620 # vm86-space
16621 1:
16622 -#else
16623 - movl %esp, %eax
16624 #endif
16625 TRACE_IRQS_ON
16626 ENABLE_INTERRUPTS(CLBR_NONE)
16627 @@ -653,7 +878,7 @@ work_notifysig_v86:
16628 movl %eax, %esp
16629 jmp 1b
16630 #endif
16631 -END(work_pending)
16632 +ENDPROC(work_pending)
16633
16634 # perform syscall exit tracing
16635 ALIGN
16636 @@ -661,11 +886,14 @@ syscall_trace_entry:
16637 movl $-ENOSYS,PT_EAX(%esp)
16638 movl %esp, %eax
16639 call syscall_trace_enter
16640 +
16641 + pax_erase_kstack
16642 +
16643 /* What it returned is what we'll actually use. */
16644 cmpl $(NR_syscalls), %eax
16645 jnae syscall_call
16646 jmp syscall_exit
16647 -END(syscall_trace_entry)
16648 +ENDPROC(syscall_trace_entry)
16649
16650 # perform syscall exit tracing
16651 ALIGN
16652 @@ -678,21 +906,25 @@ syscall_exit_work:
16653 movl %esp, %eax
16654 call syscall_trace_leave
16655 jmp resume_userspace
16656 -END(syscall_exit_work)
16657 +ENDPROC(syscall_exit_work)
16658 CFI_ENDPROC
16659
16660 RING0_INT_FRAME # can't unwind into user space anyway
16661 syscall_fault:
16662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16663 + push %ss
16664 + pop %ds
16665 +#endif
16666 ASM_CLAC
16667 GET_THREAD_INFO(%ebp)
16668 movl $-EFAULT,PT_EAX(%esp)
16669 jmp resume_userspace
16670 -END(syscall_fault)
16671 +ENDPROC(syscall_fault)
16672
16673 syscall_badsys:
16674 movl $-ENOSYS,PT_EAX(%esp)
16675 jmp resume_userspace
16676 -END(syscall_badsys)
16677 +ENDPROC(syscall_badsys)
16678 CFI_ENDPROC
16679 /*
16680 * End of kprobes section
16681 @@ -772,8 +1004,15 @@ ENDPROC(ptregs_clone)
16682 * normal stack and adjusts ESP with the matching offset.
16683 */
16684 /* fixup the stack */
16685 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16686 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16687 +#ifdef CONFIG_SMP
16688 + movl PER_CPU_VAR(cpu_number), %ebx
16689 + shll $PAGE_SHIFT_asm, %ebx
16690 + addl $cpu_gdt_table, %ebx
16691 +#else
16692 + movl $cpu_gdt_table, %ebx
16693 +#endif
16694 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16695 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16696 shl $16, %eax
16697 addl %esp, %eax /* the adjusted stack pointer */
16698 pushl_cfi $__KERNEL_DS
16699 @@ -826,7 +1065,7 @@ vector=vector+1
16700 .endr
16701 2: jmp common_interrupt
16702 .endr
16703 -END(irq_entries_start)
16704 +ENDPROC(irq_entries_start)
16705
16706 .previous
16707 END(interrupt)
16708 @@ -877,7 +1116,7 @@ ENTRY(coprocessor_error)
16709 pushl_cfi $do_coprocessor_error
16710 jmp error_code
16711 CFI_ENDPROC
16712 -END(coprocessor_error)
16713 +ENDPROC(coprocessor_error)
16714
16715 ENTRY(simd_coprocessor_error)
16716 RING0_INT_FRAME
16717 @@ -899,7 +1138,7 @@ ENTRY(simd_coprocessor_error)
16718 #endif
16719 jmp error_code
16720 CFI_ENDPROC
16721 -END(simd_coprocessor_error)
16722 +ENDPROC(simd_coprocessor_error)
16723
16724 ENTRY(device_not_available)
16725 RING0_INT_FRAME
16726 @@ -908,18 +1147,18 @@ ENTRY(device_not_available)
16727 pushl_cfi $do_device_not_available
16728 jmp error_code
16729 CFI_ENDPROC
16730 -END(device_not_available)
16731 +ENDPROC(device_not_available)
16732
16733 #ifdef CONFIG_PARAVIRT
16734 ENTRY(native_iret)
16735 iret
16736 _ASM_EXTABLE(native_iret, iret_exc)
16737 -END(native_iret)
16738 +ENDPROC(native_iret)
16739
16740 ENTRY(native_irq_enable_sysexit)
16741 sti
16742 sysexit
16743 -END(native_irq_enable_sysexit)
16744 +ENDPROC(native_irq_enable_sysexit)
16745 #endif
16746
16747 ENTRY(overflow)
16748 @@ -929,7 +1168,7 @@ ENTRY(overflow)
16749 pushl_cfi $do_overflow
16750 jmp error_code
16751 CFI_ENDPROC
16752 -END(overflow)
16753 +ENDPROC(overflow)
16754
16755 ENTRY(bounds)
16756 RING0_INT_FRAME
16757 @@ -938,7 +1177,7 @@ ENTRY(bounds)
16758 pushl_cfi $do_bounds
16759 jmp error_code
16760 CFI_ENDPROC
16761 -END(bounds)
16762 +ENDPROC(bounds)
16763
16764 ENTRY(invalid_op)
16765 RING0_INT_FRAME
16766 @@ -947,7 +1186,7 @@ ENTRY(invalid_op)
16767 pushl_cfi $do_invalid_op
16768 jmp error_code
16769 CFI_ENDPROC
16770 -END(invalid_op)
16771 +ENDPROC(invalid_op)
16772
16773 ENTRY(coprocessor_segment_overrun)
16774 RING0_INT_FRAME
16775 @@ -956,7 +1195,7 @@ ENTRY(coprocessor_segment_overrun)
16776 pushl_cfi $do_coprocessor_segment_overrun
16777 jmp error_code
16778 CFI_ENDPROC
16779 -END(coprocessor_segment_overrun)
16780 +ENDPROC(coprocessor_segment_overrun)
16781
16782 ENTRY(invalid_TSS)
16783 RING0_EC_FRAME
16784 @@ -964,7 +1203,7 @@ ENTRY(invalid_TSS)
16785 pushl_cfi $do_invalid_TSS
16786 jmp error_code
16787 CFI_ENDPROC
16788 -END(invalid_TSS)
16789 +ENDPROC(invalid_TSS)
16790
16791 ENTRY(segment_not_present)
16792 RING0_EC_FRAME
16793 @@ -972,7 +1211,7 @@ ENTRY(segment_not_present)
16794 pushl_cfi $do_segment_not_present
16795 jmp error_code
16796 CFI_ENDPROC
16797 -END(segment_not_present)
16798 +ENDPROC(segment_not_present)
16799
16800 ENTRY(stack_segment)
16801 RING0_EC_FRAME
16802 @@ -980,7 +1219,7 @@ ENTRY(stack_segment)
16803 pushl_cfi $do_stack_segment
16804 jmp error_code
16805 CFI_ENDPROC
16806 -END(stack_segment)
16807 +ENDPROC(stack_segment)
16808
16809 ENTRY(alignment_check)
16810 RING0_EC_FRAME
16811 @@ -988,7 +1227,7 @@ ENTRY(alignment_check)
16812 pushl_cfi $do_alignment_check
16813 jmp error_code
16814 CFI_ENDPROC
16815 -END(alignment_check)
16816 +ENDPROC(alignment_check)
16817
16818 ENTRY(divide_error)
16819 RING0_INT_FRAME
16820 @@ -997,7 +1236,7 @@ ENTRY(divide_error)
16821 pushl_cfi $do_divide_error
16822 jmp error_code
16823 CFI_ENDPROC
16824 -END(divide_error)
16825 +ENDPROC(divide_error)
16826
16827 #ifdef CONFIG_X86_MCE
16828 ENTRY(machine_check)
16829 @@ -1007,7 +1246,7 @@ ENTRY(machine_check)
16830 pushl_cfi machine_check_vector
16831 jmp error_code
16832 CFI_ENDPROC
16833 -END(machine_check)
16834 +ENDPROC(machine_check)
16835 #endif
16836
16837 ENTRY(spurious_interrupt_bug)
16838 @@ -1017,7 +1256,7 @@ ENTRY(spurious_interrupt_bug)
16839 pushl_cfi $do_spurious_interrupt_bug
16840 jmp error_code
16841 CFI_ENDPROC
16842 -END(spurious_interrupt_bug)
16843 +ENDPROC(spurious_interrupt_bug)
16844 /*
16845 * End of kprobes section
16846 */
16847 @@ -1120,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16848
16849 ENTRY(mcount)
16850 ret
16851 -END(mcount)
16852 +ENDPROC(mcount)
16853
16854 ENTRY(ftrace_caller)
16855 cmpl $0, function_trace_stop
16856 @@ -1153,7 +1392,7 @@ ftrace_graph_call:
16857 .globl ftrace_stub
16858 ftrace_stub:
16859 ret
16860 -END(ftrace_caller)
16861 +ENDPROC(ftrace_caller)
16862
16863 ENTRY(ftrace_regs_caller)
16864 pushf /* push flags before compare (in cs location) */
16865 @@ -1254,7 +1493,7 @@ trace:
16866 popl %ecx
16867 popl %eax
16868 jmp ftrace_stub
16869 -END(mcount)
16870 +ENDPROC(mcount)
16871 #endif /* CONFIG_DYNAMIC_FTRACE */
16872 #endif /* CONFIG_FUNCTION_TRACER */
16873
16874 @@ -1272,7 +1511,7 @@ ENTRY(ftrace_graph_caller)
16875 popl %ecx
16876 popl %eax
16877 ret
16878 -END(ftrace_graph_caller)
16879 +ENDPROC(ftrace_graph_caller)
16880
16881 .globl return_to_handler
16882 return_to_handler:
16883 @@ -1328,15 +1567,18 @@ error_code:
16884 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16885 REG_TO_PTGS %ecx
16886 SET_KERNEL_GS %ecx
16887 - movl $(__USER_DS), %ecx
16888 + movl $(__KERNEL_DS), %ecx
16889 movl %ecx, %ds
16890 movl %ecx, %es
16891 +
16892 + pax_enter_kernel
16893 +
16894 TRACE_IRQS_OFF
16895 movl %esp,%eax # pt_regs pointer
16896 call *%edi
16897 jmp ret_from_exception
16898 CFI_ENDPROC
16899 -END(page_fault)
16900 +ENDPROC(page_fault)
16901
16902 /*
16903 * Debug traps and NMI can happen at the one SYSENTER instruction
16904 @@ -1379,7 +1621,7 @@ debug_stack_correct:
16905 call do_debug
16906 jmp ret_from_exception
16907 CFI_ENDPROC
16908 -END(debug)
16909 +ENDPROC(debug)
16910
16911 /*
16912 * NMI is doubly nasty. It can happen _while_ we're handling
16913 @@ -1417,6 +1659,9 @@ nmi_stack_correct:
16914 xorl %edx,%edx # zero error code
16915 movl %esp,%eax # pt_regs pointer
16916 call do_nmi
16917 +
16918 + pax_exit_kernel
16919 +
16920 jmp restore_all_notrace
16921 CFI_ENDPROC
16922
16923 @@ -1453,12 +1698,15 @@ nmi_espfix_stack:
16924 FIXUP_ESPFIX_STACK # %eax == %esp
16925 xorl %edx,%edx # zero error code
16926 call do_nmi
16927 +
16928 + pax_exit_kernel
16929 +
16930 RESTORE_REGS
16931 lss 12+4(%esp), %esp # back to espfix stack
16932 CFI_ADJUST_CFA_OFFSET -24
16933 jmp irq_return
16934 CFI_ENDPROC
16935 -END(nmi)
16936 +ENDPROC(nmi)
16937
16938 ENTRY(int3)
16939 RING0_INT_FRAME
16940 @@ -1471,14 +1719,14 @@ ENTRY(int3)
16941 call do_int3
16942 jmp ret_from_exception
16943 CFI_ENDPROC
16944 -END(int3)
16945 +ENDPROC(int3)
16946
16947 ENTRY(general_protection)
16948 RING0_EC_FRAME
16949 pushl_cfi $do_general_protection
16950 jmp error_code
16951 CFI_ENDPROC
16952 -END(general_protection)
16953 +ENDPROC(general_protection)
16954
16955 #ifdef CONFIG_KVM_GUEST
16956 ENTRY(async_page_fault)
16957 @@ -1487,7 +1735,7 @@ ENTRY(async_page_fault)
16958 pushl_cfi $do_async_page_fault
16959 jmp error_code
16960 CFI_ENDPROC
16961 -END(async_page_fault)
16962 +ENDPROC(async_page_fault)
16963 #endif
16964
16965 /*
16966 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
16967 index 1328fe4..cb03298 100644
16968 --- a/arch/x86/kernel/entry_64.S
16969 +++ b/arch/x86/kernel/entry_64.S
16970 @@ -59,6 +59,8 @@
16971 #include <asm/rcu.h>
16972 #include <asm/smap.h>
16973 #include <linux/err.h>
16974 +#include <asm/pgtable.h>
16975 +#include <asm/alternative-asm.h>
16976
16977 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
16978 #include <linux/elf-em.h>
16979 @@ -80,8 +82,9 @@
16980 #ifdef CONFIG_DYNAMIC_FTRACE
16981
16982 ENTRY(function_hook)
16983 + pax_force_retaddr
16984 retq
16985 -END(function_hook)
16986 +ENDPROC(function_hook)
16987
16988 /* skip is set if stack has been adjusted */
16989 .macro ftrace_caller_setup skip=0
16990 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
16991 #endif
16992
16993 GLOBAL(ftrace_stub)
16994 + pax_force_retaddr
16995 retq
16996 -END(ftrace_caller)
16997 +ENDPROC(ftrace_caller)
16998
16999 ENTRY(ftrace_regs_caller)
17000 /* Save the current flags before compare (in SS location)*/
17001 @@ -191,7 +195,7 @@ ftrace_restore_flags:
17002 popfq
17003 jmp ftrace_stub
17004
17005 -END(ftrace_regs_caller)
17006 +ENDPROC(ftrace_regs_caller)
17007
17008
17009 #else /* ! CONFIG_DYNAMIC_FTRACE */
17010 @@ -212,6 +216,7 @@ ENTRY(function_hook)
17011 #endif
17012
17013 GLOBAL(ftrace_stub)
17014 + pax_force_retaddr
17015 retq
17016
17017 trace:
17018 @@ -225,12 +230,13 @@ trace:
17019 #endif
17020 subq $MCOUNT_INSN_SIZE, %rdi
17021
17022 + pax_force_fptr ftrace_trace_function
17023 call *ftrace_trace_function
17024
17025 MCOUNT_RESTORE_FRAME
17026
17027 jmp ftrace_stub
17028 -END(function_hook)
17029 +ENDPROC(function_hook)
17030 #endif /* CONFIG_DYNAMIC_FTRACE */
17031 #endif /* CONFIG_FUNCTION_TRACER */
17032
17033 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
17034
17035 MCOUNT_RESTORE_FRAME
17036
17037 + pax_force_retaddr
17038 retq
17039 -END(ftrace_graph_caller)
17040 +ENDPROC(ftrace_graph_caller)
17041
17042 GLOBAL(return_to_handler)
17043 subq $24, %rsp
17044 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
17045 movq 8(%rsp), %rdx
17046 movq (%rsp), %rax
17047 addq $24, %rsp
17048 + pax_force_fptr %rdi
17049 jmp *%rdi
17050 +ENDPROC(return_to_handler)
17051 #endif
17052
17053
17054 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
17055 ENDPROC(native_usergs_sysret64)
17056 #endif /* CONFIG_PARAVIRT */
17057
17058 + .macro ljmpq sel, off
17059 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
17060 + .byte 0x48; ljmp *1234f(%rip)
17061 + .pushsection .rodata
17062 + .align 16
17063 + 1234: .quad \off; .word \sel
17064 + .popsection
17065 +#else
17066 + pushq $\sel
17067 + pushq $\off
17068 + lretq
17069 +#endif
17070 + .endm
17071 +
17072 + .macro pax_enter_kernel
17073 + pax_set_fptr_mask
17074 +#ifdef CONFIG_PAX_KERNEXEC
17075 + call pax_enter_kernel
17076 +#endif
17077 + .endm
17078 +
17079 + .macro pax_exit_kernel
17080 +#ifdef CONFIG_PAX_KERNEXEC
17081 + call pax_exit_kernel
17082 +#endif
17083 + .endm
17084 +
17085 +#ifdef CONFIG_PAX_KERNEXEC
17086 +ENTRY(pax_enter_kernel)
17087 + pushq %rdi
17088 +
17089 +#ifdef CONFIG_PARAVIRT
17090 + PV_SAVE_REGS(CLBR_RDI)
17091 +#endif
17092 +
17093 + GET_CR0_INTO_RDI
17094 + bts $16,%rdi
17095 + jnc 3f
17096 + mov %cs,%edi
17097 + cmp $__KERNEL_CS,%edi
17098 + jnz 2f
17099 +1:
17100 +
17101 +#ifdef CONFIG_PARAVIRT
17102 + PV_RESTORE_REGS(CLBR_RDI)
17103 +#endif
17104 +
17105 + popq %rdi
17106 + pax_force_retaddr
17107 + retq
17108 +
17109 +2: ljmpq __KERNEL_CS,1f
17110 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
17111 +4: SET_RDI_INTO_CR0
17112 + jmp 1b
17113 +ENDPROC(pax_enter_kernel)
17114 +
17115 +ENTRY(pax_exit_kernel)
17116 + pushq %rdi
17117 +
17118 +#ifdef CONFIG_PARAVIRT
17119 + PV_SAVE_REGS(CLBR_RDI)
17120 +#endif
17121 +
17122 + mov %cs,%rdi
17123 + cmp $__KERNEXEC_KERNEL_CS,%edi
17124 + jz 2f
17125 +1:
17126 +
17127 +#ifdef CONFIG_PARAVIRT
17128 + PV_RESTORE_REGS(CLBR_RDI);
17129 +#endif
17130 +
17131 + popq %rdi
17132 + pax_force_retaddr
17133 + retq
17134 +
17135 +2: GET_CR0_INTO_RDI
17136 + btr $16,%rdi
17137 + ljmpq __KERNEL_CS,3f
17138 +3: SET_RDI_INTO_CR0
17139 + jmp 1b
17140 +ENDPROC(pax_exit_kernel)
17141 +#endif
17142 +
17143 + .macro pax_enter_kernel_user
17144 + pax_set_fptr_mask
17145 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17146 + call pax_enter_kernel_user
17147 +#endif
17148 + .endm
17149 +
17150 + .macro pax_exit_kernel_user
17151 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17152 + call pax_exit_kernel_user
17153 +#endif
17154 +#ifdef CONFIG_PAX_RANDKSTACK
17155 + pushq %rax
17156 + call pax_randomize_kstack
17157 + popq %rax
17158 +#endif
17159 + .endm
17160 +
17161 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17162 +ENTRY(pax_enter_kernel_user)
17163 + pushq %rdi
17164 + pushq %rbx
17165 +
17166 +#ifdef CONFIG_PARAVIRT
17167 + PV_SAVE_REGS(CLBR_RDI)
17168 +#endif
17169 +
17170 + GET_CR3_INTO_RDI
17171 + mov %rdi,%rbx
17172 + add $__START_KERNEL_map,%rbx
17173 + sub phys_base(%rip),%rbx
17174 +
17175 +#ifdef CONFIG_PARAVIRT
17176 + pushq %rdi
17177 + cmpl $0, pv_info+PARAVIRT_enabled
17178 + jz 1f
17179 + i = 0
17180 + .rept USER_PGD_PTRS
17181 + mov i*8(%rbx),%rsi
17182 + mov $0,%sil
17183 + lea i*8(%rbx),%rdi
17184 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17185 + i = i + 1
17186 + .endr
17187 + jmp 2f
17188 +1:
17189 +#endif
17190 +
17191 + i = 0
17192 + .rept USER_PGD_PTRS
17193 + movb $0,i*8(%rbx)
17194 + i = i + 1
17195 + .endr
17196 +
17197 +#ifdef CONFIG_PARAVIRT
17198 +2: popq %rdi
17199 +#endif
17200 + SET_RDI_INTO_CR3
17201 +
17202 +#ifdef CONFIG_PAX_KERNEXEC
17203 + GET_CR0_INTO_RDI
17204 + bts $16,%rdi
17205 + SET_RDI_INTO_CR0
17206 +#endif
17207 +
17208 +#ifdef CONFIG_PARAVIRT
17209 + PV_RESTORE_REGS(CLBR_RDI)
17210 +#endif
17211 +
17212 + popq %rbx
17213 + popq %rdi
17214 + pax_force_retaddr
17215 + retq
17216 +ENDPROC(pax_enter_kernel_user)
17217 +
17218 +ENTRY(pax_exit_kernel_user)
17219 + push %rdi
17220 +
17221 +#ifdef CONFIG_PARAVIRT
17222 + pushq %rbx
17223 + PV_SAVE_REGS(CLBR_RDI)
17224 +#endif
17225 +
17226 +#ifdef CONFIG_PAX_KERNEXEC
17227 + GET_CR0_INTO_RDI
17228 + btr $16,%rdi
17229 + SET_RDI_INTO_CR0
17230 +#endif
17231 +
17232 + GET_CR3_INTO_RDI
17233 + add $__START_KERNEL_map,%rdi
17234 + sub phys_base(%rip),%rdi
17235 +
17236 +#ifdef CONFIG_PARAVIRT
17237 + cmpl $0, pv_info+PARAVIRT_enabled
17238 + jz 1f
17239 + mov %rdi,%rbx
17240 + i = 0
17241 + .rept USER_PGD_PTRS
17242 + mov i*8(%rbx),%rsi
17243 + mov $0x67,%sil
17244 + lea i*8(%rbx),%rdi
17245 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17246 + i = i + 1
17247 + .endr
17248 + jmp 2f
17249 +1:
17250 +#endif
17251 +
17252 + i = 0
17253 + .rept USER_PGD_PTRS
17254 + movb $0x67,i*8(%rdi)
17255 + i = i + 1
17256 + .endr
17257 +
17258 +#ifdef CONFIG_PARAVIRT
17259 +2: PV_RESTORE_REGS(CLBR_RDI)
17260 + popq %rbx
17261 +#endif
17262 +
17263 + popq %rdi
17264 + pax_force_retaddr
17265 + retq
17266 +ENDPROC(pax_exit_kernel_user)
17267 +#endif
17268 +
17269 +.macro pax_erase_kstack
17270 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17271 + call pax_erase_kstack
17272 +#endif
17273 +.endm
17274 +
17275 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17276 +ENTRY(pax_erase_kstack)
17277 + pushq %rdi
17278 + pushq %rcx
17279 + pushq %rax
17280 + pushq %r11
17281 +
17282 + GET_THREAD_INFO(%r11)
17283 + mov TI_lowest_stack(%r11), %rdi
17284 + mov $-0xBEEF, %rax
17285 + std
17286 +
17287 +1: mov %edi, %ecx
17288 + and $THREAD_SIZE_asm - 1, %ecx
17289 + shr $3, %ecx
17290 + repne scasq
17291 + jecxz 2f
17292 +
17293 + cmp $2*8, %ecx
17294 + jc 2f
17295 +
17296 + mov $2*8, %ecx
17297 + repe scasq
17298 + jecxz 2f
17299 + jne 1b
17300 +
17301 +2: cld
17302 + mov %esp, %ecx
17303 + sub %edi, %ecx
17304 +
17305 + cmp $THREAD_SIZE_asm, %rcx
17306 + jb 3f
17307 + ud2
17308 +3:
17309 +
17310 + shr $3, %ecx
17311 + rep stosq
17312 +
17313 + mov TI_task_thread_sp0(%r11), %rdi
17314 + sub $256, %rdi
17315 + mov %rdi, TI_lowest_stack(%r11)
17316 +
17317 + popq %r11
17318 + popq %rax
17319 + popq %rcx
17320 + popq %rdi
17321 + pax_force_retaddr
17322 + ret
17323 +ENDPROC(pax_erase_kstack)
17324 +#endif
17325
17326 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17327 #ifdef CONFIG_TRACE_IRQFLAGS
17328 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17329 .endm
17330
17331 .macro UNFAKE_STACK_FRAME
17332 - addq $8*6, %rsp
17333 - CFI_ADJUST_CFA_OFFSET -(6*8)
17334 + addq $8*6 + ARG_SKIP, %rsp
17335 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17336 .endm
17337
17338 /*
17339 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17340 movq %rsp, %rsi
17341
17342 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17343 - testl $3, CS-RBP(%rsi)
17344 + testb $3, CS-RBP(%rsi)
17345 je 1f
17346 SWAPGS
17347 /*
17348 @@ -498,9 +774,10 @@ ENTRY(save_rest)
17349 movq_cfi r15, R15+16
17350 movq %r11, 8(%rsp) /* return address */
17351 FIXUP_TOP_OF_STACK %r11, 16
17352 + pax_force_retaddr
17353 ret
17354 CFI_ENDPROC
17355 -END(save_rest)
17356 +ENDPROC(save_rest)
17357
17358 /* save complete stack frame */
17359 .pushsection .kprobes.text, "ax"
17360 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17361 js 1f /* negative -> in kernel */
17362 SWAPGS
17363 xorl %ebx,%ebx
17364 -1: ret
17365 +1: pax_force_retaddr_bts
17366 + ret
17367 CFI_ENDPROC
17368 -END(save_paranoid)
17369 +ENDPROC(save_paranoid)
17370 .popsection
17371
17372 /*
17373 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17374
17375 RESTORE_REST
17376
17377 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17378 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17379 jz 1f
17380
17381 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17382 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17383 RESTORE_REST
17384 jmp int_ret_from_sys_call
17385 CFI_ENDPROC
17386 -END(ret_from_fork)
17387 +ENDPROC(ret_from_fork)
17388
17389 /*
17390 * System call entry. Up to 6 arguments in registers are supported.
17391 @@ -608,7 +886,7 @@ END(ret_from_fork)
17392 ENTRY(system_call)
17393 CFI_STARTPROC simple
17394 CFI_SIGNAL_FRAME
17395 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17396 + CFI_DEF_CFA rsp,0
17397 CFI_REGISTER rip,rcx
17398 /*CFI_REGISTER rflags,r11*/
17399 SWAPGS_UNSAFE_STACK
17400 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17401
17402 movq %rsp,PER_CPU_VAR(old_rsp)
17403 movq PER_CPU_VAR(kernel_stack),%rsp
17404 + SAVE_ARGS 8*6,0
17405 + pax_enter_kernel_user
17406 +
17407 +#ifdef CONFIG_PAX_RANDKSTACK
17408 + pax_erase_kstack
17409 +#endif
17410 +
17411 /*
17412 * No need to follow this irqs off/on section - it's straight
17413 * and short:
17414 */
17415 ENABLE_INTERRUPTS(CLBR_NONE)
17416 - SAVE_ARGS 8,0
17417 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17418 movq %rcx,RIP-ARGOFFSET(%rsp)
17419 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17420 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17421 + GET_THREAD_INFO(%rcx)
17422 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17423 jnz tracesys
17424 system_call_fastpath:
17425 #if __SYSCALL_MASK == ~0
17426 @@ -640,7 +925,7 @@ system_call_fastpath:
17427 cmpl $__NR_syscall_max,%eax
17428 #endif
17429 ja badsys
17430 - movq %r10,%rcx
17431 + movq R10-ARGOFFSET(%rsp),%rcx
17432 call *sys_call_table(,%rax,8) # XXX: rip relative
17433 movq %rax,RAX-ARGOFFSET(%rsp)
17434 /*
17435 @@ -654,10 +939,13 @@ sysret_check:
17436 LOCKDEP_SYS_EXIT
17437 DISABLE_INTERRUPTS(CLBR_NONE)
17438 TRACE_IRQS_OFF
17439 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17440 + GET_THREAD_INFO(%rcx)
17441 + movl TI_flags(%rcx),%edx
17442 andl %edi,%edx
17443 jnz sysret_careful
17444 CFI_REMEMBER_STATE
17445 + pax_exit_kernel_user
17446 + pax_erase_kstack
17447 /*
17448 * sysretq will re-enable interrupts:
17449 */
17450 @@ -709,14 +997,18 @@ badsys:
17451 * jump back to the normal fast path.
17452 */
17453 auditsys:
17454 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
17455 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17456 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17457 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17458 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17459 movq %rax,%rsi /* 2nd arg: syscall number */
17460 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17461 call __audit_syscall_entry
17462 +
17463 + pax_erase_kstack
17464 +
17465 LOAD_ARGS 0 /* reload call-clobbered registers */
17466 + pax_set_fptr_mask
17467 jmp system_call_fastpath
17468
17469 /*
17470 @@ -737,7 +1029,7 @@ sysret_audit:
17471 /* Do syscall tracing */
17472 tracesys:
17473 #ifdef CONFIG_AUDITSYSCALL
17474 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17475 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17476 jz auditsys
17477 #endif
17478 SAVE_REST
17479 @@ -745,12 +1037,16 @@ tracesys:
17480 FIXUP_TOP_OF_STACK %rdi
17481 movq %rsp,%rdi
17482 call syscall_trace_enter
17483 +
17484 + pax_erase_kstack
17485 +
17486 /*
17487 * Reload arg registers from stack in case ptrace changed them.
17488 * We don't reload %rax because syscall_trace_enter() returned
17489 * the value it wants us to use in the table lookup.
17490 */
17491 LOAD_ARGS ARGOFFSET, 1
17492 + pax_set_fptr_mask
17493 RESTORE_REST
17494 #if __SYSCALL_MASK == ~0
17495 cmpq $__NR_syscall_max,%rax
17496 @@ -759,7 +1055,7 @@ tracesys:
17497 cmpl $__NR_syscall_max,%eax
17498 #endif
17499 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17500 - movq %r10,%rcx /* fixup for C */
17501 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17502 call *sys_call_table(,%rax,8)
17503 movq %rax,RAX-ARGOFFSET(%rsp)
17504 /* Use IRET because user could have changed frame */
17505 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17506 andl %edi,%edx
17507 jnz int_careful
17508 andl $~TS_COMPAT,TI_status(%rcx)
17509 - jmp retint_swapgs
17510 + pax_exit_kernel_user
17511 + pax_erase_kstack
17512 + jmp retint_swapgs_pax
17513
17514 /* Either reschedule or signal or syscall exit tracking needed. */
17515 /* First do a reschedule test. */
17516 @@ -826,7 +1124,7 @@ int_restore_rest:
17517 TRACE_IRQS_OFF
17518 jmp int_with_check
17519 CFI_ENDPROC
17520 -END(system_call)
17521 +ENDPROC(system_call)
17522
17523 /*
17524 * Certain special system calls that need to save a complete full stack frame.
17525 @@ -842,7 +1140,7 @@ ENTRY(\label)
17526 call \func
17527 jmp ptregscall_common
17528 CFI_ENDPROC
17529 -END(\label)
17530 +ENDPROC(\label)
17531 .endm
17532
17533 PTREGSCALL stub_clone, sys_clone, %r8
17534 @@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17535 movq_cfi_restore R12+8, r12
17536 movq_cfi_restore RBP+8, rbp
17537 movq_cfi_restore RBX+8, rbx
17538 + pax_force_retaddr
17539 ret $REST_SKIP /* pop extended registers */
17540 CFI_ENDPROC
17541 -END(ptregscall_common)
17542 +ENDPROC(ptregscall_common)
17543
17544 ENTRY(stub_execve)
17545 CFI_STARTPROC
17546 @@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17547 RESTORE_REST
17548 jmp int_ret_from_sys_call
17549 CFI_ENDPROC
17550 -END(stub_execve)
17551 +ENDPROC(stub_execve)
17552
17553 /*
17554 * sigreturn is special because it needs to restore all registers on return.
17555 @@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17556 RESTORE_REST
17557 jmp int_ret_from_sys_call
17558 CFI_ENDPROC
17559 -END(stub_rt_sigreturn)
17560 +ENDPROC(stub_rt_sigreturn)
17561
17562 #ifdef CONFIG_X86_X32_ABI
17563 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17564 @@ -962,7 +1261,7 @@ vector=vector+1
17565 2: jmp common_interrupt
17566 .endr
17567 CFI_ENDPROC
17568 -END(irq_entries_start)
17569 +ENDPROC(irq_entries_start)
17570
17571 .previous
17572 END(interrupt)
17573 @@ -982,6 +1281,16 @@ END(interrupt)
17574 subq $ORIG_RAX-RBP, %rsp
17575 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17576 SAVE_ARGS_IRQ
17577 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17578 + testb $3, CS(%rdi)
17579 + jnz 1f
17580 + pax_enter_kernel
17581 + jmp 2f
17582 +1: pax_enter_kernel_user
17583 +2:
17584 +#else
17585 + pax_enter_kernel
17586 +#endif
17587 call \func
17588 .endm
17589
17590 @@ -1014,7 +1323,7 @@ ret_from_intr:
17591
17592 exit_intr:
17593 GET_THREAD_INFO(%rcx)
17594 - testl $3,CS-ARGOFFSET(%rsp)
17595 + testb $3,CS-ARGOFFSET(%rsp)
17596 je retint_kernel
17597
17598 /* Interrupt came from user space */
17599 @@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17600 * The iretq could re-enable interrupts:
17601 */
17602 DISABLE_INTERRUPTS(CLBR_ANY)
17603 + pax_exit_kernel_user
17604 +retint_swapgs_pax:
17605 TRACE_IRQS_IRETQ
17606 SWAPGS
17607 jmp restore_args
17608
17609 retint_restore_args: /* return to kernel space */
17610 DISABLE_INTERRUPTS(CLBR_ANY)
17611 + pax_exit_kernel
17612 + pax_force_retaddr (RIP-ARGOFFSET)
17613 /*
17614 * The iretq could re-enable interrupts:
17615 */
17616 @@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17617 #endif
17618
17619 CFI_ENDPROC
17620 -END(common_interrupt)
17621 +ENDPROC(common_interrupt)
17622 /*
17623 * End of kprobes section
17624 */
17625 @@ -1142,7 +1455,7 @@ ENTRY(\sym)
17626 interrupt \do_sym
17627 jmp ret_from_intr
17628 CFI_ENDPROC
17629 -END(\sym)
17630 +ENDPROC(\sym)
17631 .endm
17632
17633 #ifdef CONFIG_SMP
17634 @@ -1198,12 +1511,22 @@ ENTRY(\sym)
17635 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17636 call error_entry
17637 DEFAULT_FRAME 0
17638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17639 + testb $3, CS(%rsp)
17640 + jnz 1f
17641 + pax_enter_kernel
17642 + jmp 2f
17643 +1: pax_enter_kernel_user
17644 +2:
17645 +#else
17646 + pax_enter_kernel
17647 +#endif
17648 movq %rsp,%rdi /* pt_regs pointer */
17649 xorl %esi,%esi /* no error code */
17650 call \do_sym
17651 jmp error_exit /* %ebx: no swapgs flag */
17652 CFI_ENDPROC
17653 -END(\sym)
17654 +ENDPROC(\sym)
17655 .endm
17656
17657 .macro paranoidzeroentry sym do_sym
17658 @@ -1216,15 +1539,25 @@ ENTRY(\sym)
17659 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17660 call save_paranoid
17661 TRACE_IRQS_OFF
17662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17663 + testb $3, CS(%rsp)
17664 + jnz 1f
17665 + pax_enter_kernel
17666 + jmp 2f
17667 +1: pax_enter_kernel_user
17668 +2:
17669 +#else
17670 + pax_enter_kernel
17671 +#endif
17672 movq %rsp,%rdi /* pt_regs pointer */
17673 xorl %esi,%esi /* no error code */
17674 call \do_sym
17675 jmp paranoid_exit /* %ebx: no swapgs flag */
17676 CFI_ENDPROC
17677 -END(\sym)
17678 +ENDPROC(\sym)
17679 .endm
17680
17681 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17682 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17683 .macro paranoidzeroentry_ist sym do_sym ist
17684 ENTRY(\sym)
17685 INTR_FRAME
17686 @@ -1235,14 +1568,30 @@ ENTRY(\sym)
17687 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17688 call save_paranoid
17689 TRACE_IRQS_OFF_DEBUG
17690 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17691 + testb $3, CS(%rsp)
17692 + jnz 1f
17693 + pax_enter_kernel
17694 + jmp 2f
17695 +1: pax_enter_kernel_user
17696 +2:
17697 +#else
17698 + pax_enter_kernel
17699 +#endif
17700 movq %rsp,%rdi /* pt_regs pointer */
17701 xorl %esi,%esi /* no error code */
17702 +#ifdef CONFIG_SMP
17703 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17704 + lea init_tss(%r12), %r12
17705 +#else
17706 + lea init_tss(%rip), %r12
17707 +#endif
17708 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17709 call \do_sym
17710 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17711 jmp paranoid_exit /* %ebx: no swapgs flag */
17712 CFI_ENDPROC
17713 -END(\sym)
17714 +ENDPROC(\sym)
17715 .endm
17716
17717 .macro errorentry sym do_sym
17718 @@ -1254,13 +1603,23 @@ ENTRY(\sym)
17719 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17720 call error_entry
17721 DEFAULT_FRAME 0
17722 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17723 + testb $3, CS(%rsp)
17724 + jnz 1f
17725 + pax_enter_kernel
17726 + jmp 2f
17727 +1: pax_enter_kernel_user
17728 +2:
17729 +#else
17730 + pax_enter_kernel
17731 +#endif
17732 movq %rsp,%rdi /* pt_regs pointer */
17733 movq ORIG_RAX(%rsp),%rsi /* get error code */
17734 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17735 call \do_sym
17736 jmp error_exit /* %ebx: no swapgs flag */
17737 CFI_ENDPROC
17738 -END(\sym)
17739 +ENDPROC(\sym)
17740 .endm
17741
17742 /* error code is on the stack already */
17743 @@ -1274,13 +1633,23 @@ ENTRY(\sym)
17744 call save_paranoid
17745 DEFAULT_FRAME 0
17746 TRACE_IRQS_OFF
17747 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17748 + testb $3, CS(%rsp)
17749 + jnz 1f
17750 + pax_enter_kernel
17751 + jmp 2f
17752 +1: pax_enter_kernel_user
17753 +2:
17754 +#else
17755 + pax_enter_kernel
17756 +#endif
17757 movq %rsp,%rdi /* pt_regs pointer */
17758 movq ORIG_RAX(%rsp),%rsi /* get error code */
17759 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17760 call \do_sym
17761 jmp paranoid_exit /* %ebx: no swapgs flag */
17762 CFI_ENDPROC
17763 -END(\sym)
17764 +ENDPROC(\sym)
17765 .endm
17766
17767 zeroentry divide_error do_divide_error
17768 @@ -1310,9 +1679,10 @@ gs_change:
17769 2: mfence /* workaround */
17770 SWAPGS
17771 popfq_cfi
17772 + pax_force_retaddr
17773 ret
17774 CFI_ENDPROC
17775 -END(native_load_gs_index)
17776 +ENDPROC(native_load_gs_index)
17777
17778 _ASM_EXTABLE(gs_change,bad_gs)
17779 .section .fixup,"ax"
17780 @@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17781 CFI_DEF_CFA_REGISTER rsp
17782 CFI_ADJUST_CFA_OFFSET -8
17783 decl PER_CPU_VAR(irq_count)
17784 + pax_force_retaddr
17785 ret
17786 CFI_ENDPROC
17787 -END(call_softirq)
17788 +ENDPROC(call_softirq)
17789
17790 #ifdef CONFIG_XEN
17791 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17792 @@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17793 decl PER_CPU_VAR(irq_count)
17794 jmp error_exit
17795 CFI_ENDPROC
17796 -END(xen_do_hypervisor_callback)
17797 +ENDPROC(xen_do_hypervisor_callback)
17798
17799 /*
17800 * Hypervisor uses this for application faults while it executes.
17801 @@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17802 SAVE_ALL
17803 jmp error_exit
17804 CFI_ENDPROC
17805 -END(xen_failsafe_callback)
17806 +ENDPROC(xen_failsafe_callback)
17807
17808 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17809 xen_hvm_callback_vector xen_evtchn_do_upcall
17810 @@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17811 TRACE_IRQS_OFF_DEBUG
17812 testl %ebx,%ebx /* swapgs needed? */
17813 jnz paranoid_restore
17814 - testl $3,CS(%rsp)
17815 + testb $3,CS(%rsp)
17816 jnz paranoid_userspace
17817 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17818 + pax_exit_kernel
17819 + TRACE_IRQS_IRETQ 0
17820 + SWAPGS_UNSAFE_STACK
17821 + RESTORE_ALL 8
17822 + pax_force_retaddr_bts
17823 + jmp irq_return
17824 +#endif
17825 paranoid_swapgs:
17826 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17827 + pax_exit_kernel_user
17828 +#else
17829 + pax_exit_kernel
17830 +#endif
17831 TRACE_IRQS_IRETQ 0
17832 SWAPGS_UNSAFE_STACK
17833 RESTORE_ALL 8
17834 jmp irq_return
17835 paranoid_restore:
17836 + pax_exit_kernel
17837 TRACE_IRQS_IRETQ_DEBUG 0
17838 RESTORE_ALL 8
17839 + pax_force_retaddr_bts
17840 jmp irq_return
17841 paranoid_userspace:
17842 GET_THREAD_INFO(%rcx)
17843 @@ -1526,7 +1912,7 @@ paranoid_schedule:
17844 TRACE_IRQS_OFF
17845 jmp paranoid_userspace
17846 CFI_ENDPROC
17847 -END(paranoid_exit)
17848 +ENDPROC(paranoid_exit)
17849
17850 /*
17851 * Exception entry point. This expects an error code/orig_rax on the stack.
17852 @@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17853 movq_cfi r14, R14+8
17854 movq_cfi r15, R15+8
17855 xorl %ebx,%ebx
17856 - testl $3,CS+8(%rsp)
17857 + testb $3,CS+8(%rsp)
17858 je error_kernelspace
17859 error_swapgs:
17860 SWAPGS
17861 error_sti:
17862 TRACE_IRQS_OFF
17863 + pax_force_retaddr_bts
17864 ret
17865
17866 /*
17867 @@ -1585,7 +1972,7 @@ bstep_iret:
17868 movq %rcx,RIP+8(%rsp)
17869 jmp error_swapgs
17870 CFI_ENDPROC
17871 -END(error_entry)
17872 +ENDPROC(error_entry)
17873
17874
17875 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17876 @@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17877 jnz retint_careful
17878 jmp retint_swapgs
17879 CFI_ENDPROC
17880 -END(error_exit)
17881 +ENDPROC(error_exit)
17882
17883 /*
17884 * Test if a given stack is an NMI stack or not.
17885 @@ -1663,9 +2050,11 @@ ENTRY(nmi)
17886 * If %cs was not the kernel segment, then the NMI triggered in user
17887 * space, which means it is definitely not nested.
17888 */
17889 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17890 + je 1f
17891 cmpl $__KERNEL_CS, 16(%rsp)
17892 jne first_nmi
17893 -
17894 +1:
17895 /*
17896 * Check the special variable on the stack to see if NMIs are
17897 * executing.
17898 @@ -1824,6 +2213,17 @@ end_repeat_nmi:
17899 */
17900 movq %cr2, %r12
17901
17902 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17903 + testb $3, CS(%rsp)
17904 + jnz 1f
17905 + pax_enter_kernel
17906 + jmp 2f
17907 +1: pax_enter_kernel_user
17908 +2:
17909 +#else
17910 + pax_enter_kernel
17911 +#endif
17912 +
17913 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
17914 movq %rsp,%rdi
17915 movq $-1,%rsi
17916 @@ -1839,21 +2239,32 @@ end_repeat_nmi:
17917 testl %ebx,%ebx /* swapgs needed? */
17918 jnz nmi_restore
17919 nmi_swapgs:
17920 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17921 + pax_exit_kernel_user
17922 +#else
17923 + pax_exit_kernel
17924 +#endif
17925 SWAPGS_UNSAFE_STACK
17926 + RESTORE_ALL 8
17927 + /* Clear the NMI executing stack variable */
17928 + movq $0, 10*8(%rsp)
17929 + jmp irq_return
17930 nmi_restore:
17931 + pax_exit_kernel
17932 RESTORE_ALL 8
17933 + pax_force_retaddr_bts
17934 /* Clear the NMI executing stack variable */
17935 movq $0, 10*8(%rsp)
17936 jmp irq_return
17937 CFI_ENDPROC
17938 -END(nmi)
17939 +ENDPROC(nmi)
17940
17941 ENTRY(ignore_sysret)
17942 CFI_STARTPROC
17943 mov $-ENOSYS,%eax
17944 sysret
17945 CFI_ENDPROC
17946 -END(ignore_sysret)
17947 +ENDPROC(ignore_sysret)
17948
17949 /*
17950 * End of kprobes section
17951 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
17952 index 1d41402..af9a46a 100644
17953 --- a/arch/x86/kernel/ftrace.c
17954 +++ b/arch/x86/kernel/ftrace.c
17955 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
17956 {
17957 unsigned char replaced[MCOUNT_INSN_SIZE];
17958
17959 + ip = ktla_ktva(ip);
17960 +
17961 /*
17962 * Note: Due to modules and __init, code can
17963 * disappear and change, we need to protect against faulting
17964 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17965 unsigned char old[MCOUNT_INSN_SIZE], *new;
17966 int ret;
17967
17968 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
17969 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
17970 new = ftrace_call_replace(ip, (unsigned long)func);
17971
17972 /* See comment above by declaration of modifying_ftrace_code */
17973 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17974 /* Also update the regs callback function */
17975 if (!ret) {
17976 ip = (unsigned long)(&ftrace_regs_call);
17977 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
17978 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
17979 new = ftrace_call_replace(ip, (unsigned long)func);
17980 ret = ftrace_modify_code(ip, old, new);
17981 }
17982 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
17983 * kernel identity mapping to modify code.
17984 */
17985 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
17986 - ip = (unsigned long)__va(__pa(ip));
17987 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
17988
17989 return probe_kernel_write((void *)ip, val, size);
17990 }
17991 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
17992 unsigned char replaced[MCOUNT_INSN_SIZE];
17993 unsigned char brk = BREAKPOINT_INSTRUCTION;
17994
17995 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
17996 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
17997 return -EFAULT;
17998
17999 /* Make sure it is what we expect it to be */
18000 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
18001 return ret;
18002
18003 fail_update:
18004 - probe_kernel_write((void *)ip, &old_code[0], 1);
18005 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
18006 goto out;
18007 }
18008
18009 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
18010 {
18011 unsigned char code[MCOUNT_INSN_SIZE];
18012
18013 + ip = ktla_ktva(ip);
18014 +
18015 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
18016 return -EFAULT;
18017
18018 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
18019 index c18f59d..69ddbc4 100644
18020 --- a/arch/x86/kernel/head32.c
18021 +++ b/arch/x86/kernel/head32.c
18022 @@ -18,20 +18,20 @@
18023 #include <asm/io_apic.h>
18024 #include <asm/bios_ebda.h>
18025 #include <asm/tlbflush.h>
18026 +#include <asm/boot.h>
18027
18028 static void __init i386_default_early_setup(void)
18029 {
18030 /* Initialize 32bit specific setup functions */
18031 - x86_init.resources.reserve_resources = i386_reserve_resources;
18032 - x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18033 + *(void **)&x86_init.resources.reserve_resources = i386_reserve_resources;
18034 + *(void **)&x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18035
18036 reserve_ebda_region();
18037 }
18038
18039 void __init i386_start_kernel(void)
18040 {
18041 - memblock_reserve(__pa_symbol(&_text),
18042 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
18043 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
18044
18045 #ifdef CONFIG_BLK_DEV_INITRD
18046 /* Reserve INITRD */
18047 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
18048 index 4dac2f6..bc6a335 100644
18049 --- a/arch/x86/kernel/head_32.S
18050 +++ b/arch/x86/kernel/head_32.S
18051 @@ -26,6 +26,12 @@
18052 /* Physical address */
18053 #define pa(X) ((X) - __PAGE_OFFSET)
18054
18055 +#ifdef CONFIG_PAX_KERNEXEC
18056 +#define ta(X) (X)
18057 +#else
18058 +#define ta(X) ((X) - __PAGE_OFFSET)
18059 +#endif
18060 +
18061 /*
18062 * References to members of the new_cpu_data structure.
18063 */
18064 @@ -55,11 +61,7 @@
18065 * and small than max_low_pfn, otherwise will waste some page table entries
18066 */
18067
18068 -#if PTRS_PER_PMD > 1
18069 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
18070 -#else
18071 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
18072 -#endif
18073 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
18074
18075 /* Number of possible pages in the lowmem region */
18076 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
18077 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
18078 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18079
18080 /*
18081 + * Real beginning of normal "text" segment
18082 + */
18083 +ENTRY(stext)
18084 +ENTRY(_stext)
18085 +
18086 +/*
18087 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
18088 * %esi points to the real-mode code as a 32-bit pointer.
18089 * CS and DS must be 4 GB flat segments, but we don't depend on
18090 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18091 * can.
18092 */
18093 __HEAD
18094 +
18095 +#ifdef CONFIG_PAX_KERNEXEC
18096 + jmp startup_32
18097 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
18098 +.fill PAGE_SIZE-5,1,0xcc
18099 +#endif
18100 +
18101 ENTRY(startup_32)
18102 movl pa(stack_start),%ecx
18103
18104 @@ -106,6 +121,59 @@ ENTRY(startup_32)
18105 2:
18106 leal -__PAGE_OFFSET(%ecx),%esp
18107
18108 +#ifdef CONFIG_SMP
18109 + movl $pa(cpu_gdt_table),%edi
18110 + movl $__per_cpu_load,%eax
18111 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
18112 + rorl $16,%eax
18113 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
18114 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
18115 + movl $__per_cpu_end - 1,%eax
18116 + subl $__per_cpu_start,%eax
18117 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
18118 +#endif
18119 +
18120 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18121 + movl $NR_CPUS,%ecx
18122 + movl $pa(cpu_gdt_table),%edi
18123 +1:
18124 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
18125 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
18126 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
18127 + addl $PAGE_SIZE_asm,%edi
18128 + loop 1b
18129 +#endif
18130 +
18131 +#ifdef CONFIG_PAX_KERNEXEC
18132 + movl $pa(boot_gdt),%edi
18133 + movl $__LOAD_PHYSICAL_ADDR,%eax
18134 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
18135 + rorl $16,%eax
18136 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
18137 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
18138 + rorl $16,%eax
18139 +
18140 + ljmp $(__BOOT_CS),$1f
18141 +1:
18142 +
18143 + movl $NR_CPUS,%ecx
18144 + movl $pa(cpu_gdt_table),%edi
18145 + addl $__PAGE_OFFSET,%eax
18146 +1:
18147 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
18148 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
18149 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
18150 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
18151 + rorl $16,%eax
18152 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
18153 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
18154 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
18155 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
18156 + rorl $16,%eax
18157 + addl $PAGE_SIZE_asm,%edi
18158 + loop 1b
18159 +#endif
18160 +
18161 /*
18162 * Clear BSS first so that there are no surprises...
18163 */
18164 @@ -196,8 +264,11 @@ ENTRY(startup_32)
18165 movl %eax, pa(max_pfn_mapped)
18166
18167 /* Do early initialization of the fixmap area */
18168 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18169 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
18170 +#ifdef CONFIG_COMPAT_VDSO
18171 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
18172 +#else
18173 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
18174 +#endif
18175 #else /* Not PAE */
18176
18177 page_pde_offset = (__PAGE_OFFSET >> 20);
18178 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18179 movl %eax, pa(max_pfn_mapped)
18180
18181 /* Do early initialization of the fixmap area */
18182 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18183 - movl %eax,pa(initial_page_table+0xffc)
18184 +#ifdef CONFIG_COMPAT_VDSO
18185 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
18186 +#else
18187 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
18188 +#endif
18189 #endif
18190
18191 #ifdef CONFIG_PARAVIRT
18192 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18193 cmpl $num_subarch_entries, %eax
18194 jae bad_subarch
18195
18196 - movl pa(subarch_entries)(,%eax,4), %eax
18197 - subl $__PAGE_OFFSET, %eax
18198 - jmp *%eax
18199 + jmp *pa(subarch_entries)(,%eax,4)
18200
18201 bad_subarch:
18202 WEAK(lguest_entry)
18203 @@ -256,10 +328,10 @@ WEAK(xen_entry)
18204 __INITDATA
18205
18206 subarch_entries:
18207 - .long default_entry /* normal x86/PC */
18208 - .long lguest_entry /* lguest hypervisor */
18209 - .long xen_entry /* Xen hypervisor */
18210 - .long default_entry /* Moorestown MID */
18211 + .long ta(default_entry) /* normal x86/PC */
18212 + .long ta(lguest_entry) /* lguest hypervisor */
18213 + .long ta(xen_entry) /* Xen hypervisor */
18214 + .long ta(default_entry) /* Moorestown MID */
18215 num_subarch_entries = (. - subarch_entries) / 4
18216 .previous
18217 #else
18218 @@ -316,6 +388,7 @@ default_entry:
18219 movl pa(mmu_cr4_features),%eax
18220 movl %eax,%cr4
18221
18222 +#ifdef CONFIG_X86_PAE
18223 testb $X86_CR4_PAE, %al # check if PAE is enabled
18224 jz 6f
18225
18226 @@ -344,6 +417,9 @@ default_entry:
18227 /* Make changes effective */
18228 wrmsr
18229
18230 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
18231 +#endif
18232 +
18233 6:
18234
18235 /*
18236 @@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
18237 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
18238 movl %eax,%ss # after changing gdt.
18239
18240 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
18241 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
18242 movl %eax,%ds
18243 movl %eax,%es
18244
18245 movl $(__KERNEL_PERCPU), %eax
18246 movl %eax,%fs # set this cpu's percpu
18247
18248 +#ifdef CONFIG_CC_STACKPROTECTOR
18249 movl $(__KERNEL_STACK_CANARY),%eax
18250 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18251 + movl $(__USER_DS),%eax
18252 +#else
18253 + xorl %eax,%eax
18254 +#endif
18255 movl %eax,%gs
18256
18257 xorl %eax,%eax # Clear LDT
18258 @@ -526,8 +608,11 @@ setup_once:
18259 * relocation. Manually set base address in stack canary
18260 * segment descriptor.
18261 */
18262 - movl $gdt_page,%eax
18263 + movl $cpu_gdt_table,%eax
18264 movl $stack_canary,%ecx
18265 +#ifdef CONFIG_SMP
18266 + addl $__per_cpu_load,%ecx
18267 +#endif
18268 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18269 shrl $16, %ecx
18270 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18271 @@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18272 /* This is global to keep gas from relaxing the jumps */
18273 ENTRY(early_idt_handler)
18274 cld
18275 - cmpl $2,%ss:early_recursion_flag
18276 + cmpl $1,%ss:early_recursion_flag
18277 je hlt_loop
18278 incl %ss:early_recursion_flag
18279
18280 @@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18281 pushl (20+6*4)(%esp) /* trapno */
18282 pushl $fault_msg
18283 call printk
18284 -#endif
18285 call dump_stack
18286 +#endif
18287 hlt_loop:
18288 hlt
18289 jmp hlt_loop
18290 @@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18291 /* This is the default interrupt "handler" :-) */
18292 ALIGN
18293 ignore_int:
18294 - cld
18295 #ifdef CONFIG_PRINTK
18296 + cmpl $2,%ss:early_recursion_flag
18297 + je hlt_loop
18298 + incl %ss:early_recursion_flag
18299 + cld
18300 pushl %eax
18301 pushl %ecx
18302 pushl %edx
18303 @@ -626,9 +714,6 @@ ignore_int:
18304 movl $(__KERNEL_DS),%eax
18305 movl %eax,%ds
18306 movl %eax,%es
18307 - cmpl $2,early_recursion_flag
18308 - je hlt_loop
18309 - incl early_recursion_flag
18310 pushl 16(%esp)
18311 pushl 24(%esp)
18312 pushl 32(%esp)
18313 @@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18314 /*
18315 * BSS section
18316 */
18317 -__PAGE_ALIGNED_BSS
18318 - .align PAGE_SIZE
18319 #ifdef CONFIG_X86_PAE
18320 +.section .initial_pg_pmd,"a",@progbits
18321 initial_pg_pmd:
18322 .fill 1024*KPMDS,4,0
18323 #else
18324 +.section .initial_page_table,"a",@progbits
18325 ENTRY(initial_page_table)
18326 .fill 1024,4,0
18327 #endif
18328 +.section .initial_pg_fixmap,"a",@progbits
18329 initial_pg_fixmap:
18330 .fill 1024,4,0
18331 +.section .empty_zero_page,"a",@progbits
18332 ENTRY(empty_zero_page)
18333 .fill 4096,1,0
18334 +.section .swapper_pg_dir,"a",@progbits
18335 ENTRY(swapper_pg_dir)
18336 +#ifdef CONFIG_X86_PAE
18337 + .fill 4,8,0
18338 +#else
18339 .fill 1024,4,0
18340 +#endif
18341 +
18342 +/*
18343 + * The IDT has to be page-aligned to simplify the Pentium
18344 + * F0 0F bug workaround.. We have a special link segment
18345 + * for this.
18346 + */
18347 +.section .idt,"a",@progbits
18348 +ENTRY(idt_table)
18349 + .fill 256,8,0
18350
18351 /*
18352 * This starts the data section.
18353 */
18354 #ifdef CONFIG_X86_PAE
18355 -__PAGE_ALIGNED_DATA
18356 - /* Page-aligned for the benefit of paravirt? */
18357 - .align PAGE_SIZE
18358 +.section .initial_page_table,"a",@progbits
18359 ENTRY(initial_page_table)
18360 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18361 # if KPMDS == 3
18362 @@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18363 # error "Kernel PMDs should be 1, 2 or 3"
18364 # endif
18365 .align PAGE_SIZE /* needs to be page-sized too */
18366 +
18367 +#ifdef CONFIG_PAX_PER_CPU_PGD
18368 +ENTRY(cpu_pgd)
18369 + .rept NR_CPUS
18370 + .fill 4,8,0
18371 + .endr
18372 +#endif
18373 +
18374 #endif
18375
18376 .data
18377 .balign 4
18378 ENTRY(stack_start)
18379 - .long init_thread_union+THREAD_SIZE
18380 + .long init_thread_union+THREAD_SIZE-8
18381
18382 __INITRODATA
18383 int_msg:
18384 @@ -736,7 +843,7 @@ fault_msg:
18385 * segment size, and 32-bit linear address value:
18386 */
18387
18388 - .data
18389 +.section .rodata,"a",@progbits
18390 .globl boot_gdt_descr
18391 .globl idt_descr
18392
18393 @@ -745,7 +852,7 @@ fault_msg:
18394 .word 0 # 32 bit align gdt_desc.address
18395 boot_gdt_descr:
18396 .word __BOOT_DS+7
18397 - .long boot_gdt - __PAGE_OFFSET
18398 + .long pa(boot_gdt)
18399
18400 .word 0 # 32-bit align idt_desc.address
18401 idt_descr:
18402 @@ -756,7 +863,7 @@ idt_descr:
18403 .word 0 # 32 bit align gdt_desc.address
18404 ENTRY(early_gdt_descr)
18405 .word GDT_ENTRIES*8-1
18406 - .long gdt_page /* Overwritten for secondary CPUs */
18407 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
18408
18409 /*
18410 * The boot_gdt must mirror the equivalent in setup.S and is
18411 @@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18412 .align L1_CACHE_BYTES
18413 ENTRY(boot_gdt)
18414 .fill GDT_ENTRY_BOOT_CS,8,0
18415 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18416 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18417 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18418 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18419 +
18420 + .align PAGE_SIZE_asm
18421 +ENTRY(cpu_gdt_table)
18422 + .rept NR_CPUS
18423 + .quad 0x0000000000000000 /* NULL descriptor */
18424 + .quad 0x0000000000000000 /* 0x0b reserved */
18425 + .quad 0x0000000000000000 /* 0x13 reserved */
18426 + .quad 0x0000000000000000 /* 0x1b reserved */
18427 +
18428 +#ifdef CONFIG_PAX_KERNEXEC
18429 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18430 +#else
18431 + .quad 0x0000000000000000 /* 0x20 unused */
18432 +#endif
18433 +
18434 + .quad 0x0000000000000000 /* 0x28 unused */
18435 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18436 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18437 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18438 + .quad 0x0000000000000000 /* 0x4b reserved */
18439 + .quad 0x0000000000000000 /* 0x53 reserved */
18440 + .quad 0x0000000000000000 /* 0x5b reserved */
18441 +
18442 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18443 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18444 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18445 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18446 +
18447 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18448 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18449 +
18450 + /*
18451 + * Segments used for calling PnP BIOS have byte granularity.
18452 + * The code segments and data segments have fixed 64k limits,
18453 + * the transfer segment sizes are set at run time.
18454 + */
18455 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
18456 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
18457 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
18458 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
18459 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
18460 +
18461 + /*
18462 + * The APM segments have byte granularity and their bases
18463 + * are set at run time. All have 64k limits.
18464 + */
18465 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18466 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18467 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
18468 +
18469 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18470 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18471 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18472 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18473 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18474 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18475 +
18476 + /* Be sure this is zeroed to avoid false validations in Xen */
18477 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18478 + .endr
18479 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18480 index 94bf9cc..400455a 100644
18481 --- a/arch/x86/kernel/head_64.S
18482 +++ b/arch/x86/kernel/head_64.S
18483 @@ -20,6 +20,8 @@
18484 #include <asm/processor-flags.h>
18485 #include <asm/percpu.h>
18486 #include <asm/nops.h>
18487 +#include <asm/cpufeature.h>
18488 +#include <asm/alternative-asm.h>
18489
18490 #ifdef CONFIG_PARAVIRT
18491 #include <asm/asm-offsets.h>
18492 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18493 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18494 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18495 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18496 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
18497 +L3_VMALLOC_START = pud_index(VMALLOC_START)
18498 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
18499 +L3_VMALLOC_END = pud_index(VMALLOC_END)
18500 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18501 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18502
18503 .text
18504 __HEAD
18505 @@ -88,35 +96,23 @@ startup_64:
18506 */
18507 addq %rbp, init_level4_pgt + 0(%rip)
18508 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18509 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18510 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18511 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18512 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18513
18514 addq %rbp, level3_ident_pgt + 0(%rip)
18515 +#ifndef CONFIG_XEN
18516 + addq %rbp, level3_ident_pgt + 8(%rip)
18517 +#endif
18518
18519 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18520 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18521 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18522 +
18523 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18524 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18525
18526 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18527 -
18528 - /* Add an Identity mapping if I am above 1G */
18529 - leaq _text(%rip), %rdi
18530 - andq $PMD_PAGE_MASK, %rdi
18531 -
18532 - movq %rdi, %rax
18533 - shrq $PUD_SHIFT, %rax
18534 - andq $(PTRS_PER_PUD - 1), %rax
18535 - jz ident_complete
18536 -
18537 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18538 - leaq level3_ident_pgt(%rip), %rbx
18539 - movq %rdx, 0(%rbx, %rax, 8)
18540 -
18541 - movq %rdi, %rax
18542 - shrq $PMD_SHIFT, %rax
18543 - andq $(PTRS_PER_PMD - 1), %rax
18544 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18545 - leaq level2_spare_pgt(%rip), %rbx
18546 - movq %rdx, 0(%rbx, %rax, 8)
18547 -ident_complete:
18548 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18549
18550 /*
18551 * Fixup the kernel text+data virtual addresses. Note that
18552 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18553 * after the boot processor executes this code.
18554 */
18555
18556 - /* Enable PAE mode and PGE */
18557 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18558 + /* Enable PAE mode and PSE/PGE */
18559 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18560 movq %rax, %cr4
18561
18562 /* Setup early boot stage 4 level pagetables. */
18563 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18564 movl $MSR_EFER, %ecx
18565 rdmsr
18566 btsl $_EFER_SCE, %eax /* Enable System Call */
18567 - btl $20,%edi /* No Execute supported? */
18568 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18569 jnc 1f
18570 btsl $_EFER_NX, %eax
18571 + leaq init_level4_pgt(%rip), %rdi
18572 +#ifndef CONFIG_EFI
18573 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18574 +#endif
18575 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18576 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18577 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18578 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18579 1: wrmsr /* Make changes effective */
18580
18581 /* Setup cr0 */
18582 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18583 * jump. In addition we need to ensure %cs is set so we make this
18584 * a far return.
18585 */
18586 + pax_set_fptr_mask
18587 movq initial_code(%rip),%rax
18588 pushq $0 # fake return address to stop unwinder
18589 pushq $__KERNEL_CS # set correct cs
18590 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18591 bad_address:
18592 jmp bad_address
18593
18594 - .section ".init.text","ax"
18595 + __INIT
18596 .globl early_idt_handlers
18597 early_idt_handlers:
18598 # 104(%rsp) %rflags
18599 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18600 addq $16,%rsp # drop vector number and error code
18601 decl early_recursion_flag(%rip)
18602 INTERRUPT_RETURN
18603 + .previous
18604
18605 + __INITDATA
18606 .balign 4
18607 early_recursion_flag:
18608 .long 0
18609 + .previous
18610
18611 + .section .rodata,"a",@progbits
18612 #ifdef CONFIG_EARLY_PRINTK
18613 early_idt_msg:
18614 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18615 @@ -360,6 +369,7 @@ early_idt_ripmsg:
18616 #endif /* CONFIG_EARLY_PRINTK */
18617 .previous
18618
18619 + .section .rodata,"a",@progbits
18620 #define NEXT_PAGE(name) \
18621 .balign PAGE_SIZE; \
18622 ENTRY(name)
18623 @@ -372,7 +382,6 @@ ENTRY(name)
18624 i = i + 1 ; \
18625 .endr
18626
18627 - .data
18628 /*
18629 * This default setting generates an ident mapping at address 0x100000
18630 * and a mapping for the kernel that precisely maps virtual address
18631 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18632 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18633 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18634 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18635 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
18636 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18637 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
18638 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18639 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18640 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18641 .org init_level4_pgt + L4_START_KERNEL*8, 0
18642 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18643 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18644
18645 +#ifdef CONFIG_PAX_PER_CPU_PGD
18646 +NEXT_PAGE(cpu_pgd)
18647 + .rept NR_CPUS
18648 + .fill 512,8,0
18649 + .endr
18650 +#endif
18651 +
18652 NEXT_PAGE(level3_ident_pgt)
18653 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18654 +#ifdef CONFIG_XEN
18655 .fill 511,8,0
18656 +#else
18657 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18658 + .fill 510,8,0
18659 +#endif
18660 +
18661 +NEXT_PAGE(level3_vmalloc_start_pgt)
18662 + .fill 512,8,0
18663 +
18664 +NEXT_PAGE(level3_vmalloc_end_pgt)
18665 + .fill 512,8,0
18666 +
18667 +NEXT_PAGE(level3_vmemmap_pgt)
18668 + .fill L3_VMEMMAP_START,8,0
18669 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18670
18671 NEXT_PAGE(level3_kernel_pgt)
18672 .fill L3_START_KERNEL,8,0
18673 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18674 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18675 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18676
18677 +NEXT_PAGE(level2_vmemmap_pgt)
18678 + .fill 512,8,0
18679 +
18680 NEXT_PAGE(level2_fixmap_pgt)
18681 - .fill 506,8,0
18682 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18683 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18684 - .fill 5,8,0
18685 + .fill 507,8,0
18686 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18687 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18688 + .fill 4,8,0
18689
18690 -NEXT_PAGE(level1_fixmap_pgt)
18691 +NEXT_PAGE(level1_vsyscall_pgt)
18692 .fill 512,8,0
18693
18694 -NEXT_PAGE(level2_ident_pgt)
18695 - /* Since I easily can, map the first 1G.
18696 + /* Since I easily can, map the first 2G.
18697 * Don't set NX because code runs from these pages.
18698 */
18699 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18700 +NEXT_PAGE(level2_ident_pgt)
18701 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18702
18703 NEXT_PAGE(level2_kernel_pgt)
18704 /*
18705 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18706 * If you want to increase this then increase MODULES_VADDR
18707 * too.)
18708 */
18709 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18710 - KERNEL_IMAGE_SIZE/PMD_SIZE)
18711 -
18712 -NEXT_PAGE(level2_spare_pgt)
18713 - .fill 512, 8, 0
18714 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18715
18716 #undef PMDS
18717 #undef NEXT_PAGE
18718
18719 - .data
18720 + .align PAGE_SIZE
18721 +ENTRY(cpu_gdt_table)
18722 + .rept NR_CPUS
18723 + .quad 0x0000000000000000 /* NULL descriptor */
18724 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18725 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
18726 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
18727 + .quad 0x00cffb000000ffff /* __USER32_CS */
18728 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18729 + .quad 0x00affb000000ffff /* __USER_CS */
18730 +
18731 +#ifdef CONFIG_PAX_KERNEXEC
18732 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18733 +#else
18734 + .quad 0x0 /* unused */
18735 +#endif
18736 +
18737 + .quad 0,0 /* TSS */
18738 + .quad 0,0 /* LDT */
18739 + .quad 0,0,0 /* three TLS descriptors */
18740 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
18741 + /* asm/segment.h:GDT_ENTRIES must match this */
18742 +
18743 + /* zero the remaining page */
18744 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18745 + .endr
18746 +
18747 .align 16
18748 .globl early_gdt_descr
18749 early_gdt_descr:
18750 .word GDT_ENTRIES*8-1
18751 early_gdt_descr_base:
18752 - .quad INIT_PER_CPU_VAR(gdt_page)
18753 + .quad cpu_gdt_table
18754
18755 ENTRY(phys_base)
18756 /* This must match the first entry in level2_kernel_pgt */
18757 .quad 0x0000000000000000
18758
18759 #include "../../x86/xen/xen-head.S"
18760 -
18761 - .section .bss, "aw", @nobits
18762 +
18763 + .section .rodata,"a",@progbits
18764 .align L1_CACHE_BYTES
18765 ENTRY(idt_table)
18766 - .skip IDT_ENTRIES * 16
18767 + .fill 512,8,0
18768
18769 .align L1_CACHE_BYTES
18770 ENTRY(nmi_idt_table)
18771 - .skip IDT_ENTRIES * 16
18772 + .fill 512,8,0
18773
18774 __PAGE_ALIGNED_BSS
18775 .align PAGE_SIZE
18776 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18777 index 9c3bd4a..e1d9b35 100644
18778 --- a/arch/x86/kernel/i386_ksyms_32.c
18779 +++ b/arch/x86/kernel/i386_ksyms_32.c
18780 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18781 EXPORT_SYMBOL(cmpxchg8b_emu);
18782 #endif
18783
18784 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
18785 +
18786 /* Networking helper routines. */
18787 EXPORT_SYMBOL(csum_partial_copy_generic);
18788 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18789 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18790
18791 EXPORT_SYMBOL(__get_user_1);
18792 EXPORT_SYMBOL(__get_user_2);
18793 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18794
18795 EXPORT_SYMBOL(csum_partial);
18796 EXPORT_SYMBOL(empty_zero_page);
18797 +
18798 +#ifdef CONFIG_PAX_KERNEXEC
18799 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18800 +#endif
18801 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18802 index 675a050..95febfd 100644
18803 --- a/arch/x86/kernel/i387.c
18804 +++ b/arch/x86/kernel/i387.c
18805 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18806 static inline bool interrupted_user_mode(void)
18807 {
18808 struct pt_regs *regs = get_irq_regs();
18809 - return regs && user_mode_vm(regs);
18810 + return regs && user_mode(regs);
18811 }
18812
18813 /*
18814 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18815 index 9a5c460..dc4374d 100644
18816 --- a/arch/x86/kernel/i8259.c
18817 +++ b/arch/x86/kernel/i8259.c
18818 @@ -209,7 +209,7 @@ spurious_8259A_irq:
18819 "spurious 8259A interrupt: IRQ%d.\n", irq);
18820 spurious_irq_mask |= irqmask;
18821 }
18822 - atomic_inc(&irq_err_count);
18823 + atomic_inc_unchecked(&irq_err_count);
18824 /*
18825 * Theoretically we do not have to handle this IRQ,
18826 * but in Linux this does not cause problems and is
18827 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18828 index 8c96897..be66bfa 100644
18829 --- a/arch/x86/kernel/ioport.c
18830 +++ b/arch/x86/kernel/ioport.c
18831 @@ -6,6 +6,7 @@
18832 #include <linux/sched.h>
18833 #include <linux/kernel.h>
18834 #include <linux/capability.h>
18835 +#include <linux/security.h>
18836 #include <linux/errno.h>
18837 #include <linux/types.h>
18838 #include <linux/ioport.h>
18839 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18840
18841 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18842 return -EINVAL;
18843 +#ifdef CONFIG_GRKERNSEC_IO
18844 + if (turn_on && grsec_disable_privio) {
18845 + gr_handle_ioperm();
18846 + return -EPERM;
18847 + }
18848 +#endif
18849 if (turn_on && !capable(CAP_SYS_RAWIO))
18850 return -EPERM;
18851
18852 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18853 * because the ->io_bitmap_max value must match the bitmap
18854 * contents:
18855 */
18856 - tss = &per_cpu(init_tss, get_cpu());
18857 + tss = init_tss + get_cpu();
18858
18859 if (turn_on)
18860 bitmap_clear(t->io_bitmap_ptr, from, num);
18861 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18862 return -EINVAL;
18863 /* Trying to gain more privileges? */
18864 if (level > old) {
18865 +#ifdef CONFIG_GRKERNSEC_IO
18866 + if (grsec_disable_privio) {
18867 + gr_handle_iopl();
18868 + return -EPERM;
18869 + }
18870 +#endif
18871 if (!capable(CAP_SYS_RAWIO))
18872 return -EPERM;
18873 }
18874 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18875 index e4595f1..ee3bfb8 100644
18876 --- a/arch/x86/kernel/irq.c
18877 +++ b/arch/x86/kernel/irq.c
18878 @@ -18,7 +18,7 @@
18879 #include <asm/mce.h>
18880 #include <asm/hw_irq.h>
18881
18882 -atomic_t irq_err_count;
18883 +atomic_unchecked_t irq_err_count;
18884
18885 /* Function pointer for generic interrupt vector handling */
18886 void (*x86_platform_ipi_callback)(void) = NULL;
18887 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18888 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18889 seq_printf(p, " Machine check polls\n");
18890 #endif
18891 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18892 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18893 #if defined(CONFIG_X86_IO_APIC)
18894 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18895 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18896 #endif
18897 return 0;
18898 }
18899 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18900
18901 u64 arch_irq_stat(void)
18902 {
18903 - u64 sum = atomic_read(&irq_err_count);
18904 + u64 sum = atomic_read_unchecked(&irq_err_count);
18905
18906 #ifdef CONFIG_X86_IO_APIC
18907 - sum += atomic_read(&irq_mis_count);
18908 + sum += atomic_read_unchecked(&irq_mis_count);
18909 #endif
18910 return sum;
18911 }
18912 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
18913 index 344faf8..355f60d 100644
18914 --- a/arch/x86/kernel/irq_32.c
18915 +++ b/arch/x86/kernel/irq_32.c
18916 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
18917 __asm__ __volatile__("andl %%esp,%0" :
18918 "=r" (sp) : "0" (THREAD_SIZE - 1));
18919
18920 - return sp < (sizeof(struct thread_info) + STACK_WARN);
18921 + return sp < STACK_WARN;
18922 }
18923
18924 static void print_stack_overflow(void)
18925 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
18926 * per-CPU IRQ handling contexts (thread information and stack)
18927 */
18928 union irq_ctx {
18929 - struct thread_info tinfo;
18930 - u32 stack[THREAD_SIZE/sizeof(u32)];
18931 + unsigned long previous_esp;
18932 + u32 stack[THREAD_SIZE/sizeof(u32)];
18933 } __attribute__((aligned(THREAD_SIZE)));
18934
18935 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
18936 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
18937 static inline int
18938 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18939 {
18940 - union irq_ctx *curctx, *irqctx;
18941 + union irq_ctx *irqctx;
18942 u32 *isp, arg1, arg2;
18943
18944 - curctx = (union irq_ctx *) current_thread_info();
18945 irqctx = __this_cpu_read(hardirq_ctx);
18946
18947 /*
18948 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18949 * handler) we can't do that and just have to keep using the
18950 * current stack (which is the irq stack already after all)
18951 */
18952 - if (unlikely(curctx == irqctx))
18953 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
18954 return 0;
18955
18956 /* build the stack frame on the IRQ stack */
18957 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18958 - irqctx->tinfo.task = curctx->tinfo.task;
18959 - irqctx->tinfo.previous_esp = current_stack_pointer;
18960 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18961 + irqctx->previous_esp = current_stack_pointer;
18962
18963 - /* Copy the preempt_count so that the [soft]irq checks work. */
18964 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
18965 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18966 + __set_fs(MAKE_MM_SEG(0));
18967 +#endif
18968
18969 if (unlikely(overflow))
18970 call_on_stack(print_stack_overflow, isp);
18971 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18972 : "0" (irq), "1" (desc), "2" (isp),
18973 "D" (desc->handle_irq)
18974 : "memory", "cc", "ecx");
18975 +
18976 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18977 + __set_fs(current_thread_info()->addr_limit);
18978 +#endif
18979 +
18980 return 1;
18981 }
18982
18983 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18984 */
18985 void __cpuinit irq_ctx_init(int cpu)
18986 {
18987 - union irq_ctx *irqctx;
18988 -
18989 if (per_cpu(hardirq_ctx, cpu))
18990 return;
18991
18992 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18993 - THREADINFO_GFP,
18994 - THREAD_SIZE_ORDER));
18995 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18996 - irqctx->tinfo.cpu = cpu;
18997 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
18998 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18999 -
19000 - per_cpu(hardirq_ctx, cpu) = irqctx;
19001 -
19002 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
19003 - THREADINFO_GFP,
19004 - THREAD_SIZE_ORDER));
19005 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
19006 - irqctx->tinfo.cpu = cpu;
19007 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
19008 -
19009 - per_cpu(softirq_ctx, cpu) = irqctx;
19010 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19011 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19012 +
19013 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19014 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19015
19016 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19017 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19018 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
19019 asmlinkage void do_softirq(void)
19020 {
19021 unsigned long flags;
19022 - struct thread_info *curctx;
19023 union irq_ctx *irqctx;
19024 u32 *isp;
19025
19026 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
19027 local_irq_save(flags);
19028
19029 if (local_softirq_pending()) {
19030 - curctx = current_thread_info();
19031 irqctx = __this_cpu_read(softirq_ctx);
19032 - irqctx->tinfo.task = curctx->task;
19033 - irqctx->tinfo.previous_esp = current_stack_pointer;
19034 + irqctx->previous_esp = current_stack_pointer;
19035
19036 /* build the stack frame on the softirq stack */
19037 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
19038 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
19039 +
19040 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19041 + __set_fs(MAKE_MM_SEG(0));
19042 +#endif
19043
19044 call_on_stack(__do_softirq, isp);
19045 +
19046 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19047 + __set_fs(current_thread_info()->addr_limit);
19048 +#endif
19049 +
19050 /*
19051 * Shouldn't happen, we returned above if in_interrupt():
19052 */
19053 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
19054 if (unlikely(!desc))
19055 return false;
19056
19057 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19058 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19059 if (unlikely(overflow))
19060 print_stack_overflow();
19061 desc->handle_irq(irq, desc);
19062 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
19063 index d04d3ec..ea4b374 100644
19064 --- a/arch/x86/kernel/irq_64.c
19065 +++ b/arch/x86/kernel/irq_64.c
19066 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
19067 u64 estack_top, estack_bottom;
19068 u64 curbase = (u64)task_stack_page(current);
19069
19070 - if (user_mode_vm(regs))
19071 + if (user_mode(regs))
19072 return;
19073
19074 if (regs->sp >= curbase + sizeof(struct thread_info) +
19075 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
19076 index dc1404b..bbc43e7 100644
19077 --- a/arch/x86/kernel/kdebugfs.c
19078 +++ b/arch/x86/kernel/kdebugfs.c
19079 @@ -27,7 +27,7 @@ struct setup_data_node {
19080 u32 len;
19081 };
19082
19083 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
19084 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
19085 size_t count, loff_t *ppos)
19086 {
19087 struct setup_data_node *node = file->private_data;
19088 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
19089 index 836f832..a8bda67 100644
19090 --- a/arch/x86/kernel/kgdb.c
19091 +++ b/arch/x86/kernel/kgdb.c
19092 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
19093 #ifdef CONFIG_X86_32
19094 switch (regno) {
19095 case GDB_SS:
19096 - if (!user_mode_vm(regs))
19097 + if (!user_mode(regs))
19098 *(unsigned long *)mem = __KERNEL_DS;
19099 break;
19100 case GDB_SP:
19101 - if (!user_mode_vm(regs))
19102 + if (!user_mode(regs))
19103 *(unsigned long *)mem = kernel_stack_pointer(regs);
19104 break;
19105 case GDB_GS:
19106 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
19107 bp->attr.bp_addr = breakinfo[breakno].addr;
19108 bp->attr.bp_len = breakinfo[breakno].len;
19109 bp->attr.bp_type = breakinfo[breakno].type;
19110 - info->address = breakinfo[breakno].addr;
19111 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
19112 + info->address = ktla_ktva(breakinfo[breakno].addr);
19113 + else
19114 + info->address = breakinfo[breakno].addr;
19115 info->len = breakinfo[breakno].len;
19116 info->type = breakinfo[breakno].type;
19117 val = arch_install_hw_breakpoint(bp);
19118 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
19119 case 'k':
19120 /* clear the trace bit */
19121 linux_regs->flags &= ~X86_EFLAGS_TF;
19122 - atomic_set(&kgdb_cpu_doing_single_step, -1);
19123 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
19124
19125 /* set the trace bit if we're stepping */
19126 if (remcomInBuffer[0] == 's') {
19127 linux_regs->flags |= X86_EFLAGS_TF;
19128 - atomic_set(&kgdb_cpu_doing_single_step,
19129 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
19130 raw_smp_processor_id());
19131 }
19132
19133 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
19134
19135 switch (cmd) {
19136 case DIE_DEBUG:
19137 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
19138 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
19139 if (user_mode(regs))
19140 return single_step_cont(regs, args);
19141 break;
19142 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19143 #endif /* CONFIG_DEBUG_RODATA */
19144
19145 bpt->type = BP_BREAKPOINT;
19146 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
19147 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
19148 BREAK_INSTR_SIZE);
19149 if (err)
19150 return err;
19151 - err = probe_kernel_write((char *)bpt->bpt_addr,
19152 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19153 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
19154 #ifdef CONFIG_DEBUG_RODATA
19155 if (!err)
19156 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19157 return -EBUSY;
19158 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
19159 BREAK_INSTR_SIZE);
19160 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19161 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19162 if (err)
19163 return err;
19164 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
19165 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
19166 if (mutex_is_locked(&text_mutex))
19167 goto knl_write;
19168 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
19169 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19170 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19171 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
19172 goto knl_write;
19173 return err;
19174 knl_write:
19175 #endif /* CONFIG_DEBUG_RODATA */
19176 - return probe_kernel_write((char *)bpt->bpt_addr,
19177 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19178 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
19179 }
19180
19181 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
19182 index c5e410e..ed5a7f0 100644
19183 --- a/arch/x86/kernel/kprobes-opt.c
19184 +++ b/arch/x86/kernel/kprobes-opt.c
19185 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19186 * Verify if the address gap is in 2GB range, because this uses
19187 * a relative jump.
19188 */
19189 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
19190 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
19191 if (abs(rel) > 0x7fffffff)
19192 return -ERANGE;
19193
19194 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19195 op->optinsn.size = ret;
19196
19197 /* Copy arch-dep-instance from template */
19198 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
19199 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
19200
19201 /* Set probe information */
19202 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
19203
19204 /* Set probe function call */
19205 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
19206 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
19207
19208 /* Set returning jmp instruction at the tail of out-of-line buffer */
19209 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
19210 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
19211 (u8 *)op->kp.addr + op->optinsn.size);
19212
19213 flush_icache_range((unsigned long) buf,
19214 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
19215 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
19216
19217 /* Backup instructions which will be replaced by jump address */
19218 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
19219 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
19220 RELATIVE_ADDR_SIZE);
19221
19222 insn_buf[0] = RELATIVEJUMP_OPCODE;
19223 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
19224 /* This kprobe is really able to run optimized path. */
19225 op = container_of(p, struct optimized_kprobe, kp);
19226 /* Detour through copied instructions */
19227 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
19228 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
19229 if (!reenter)
19230 reset_current_kprobe();
19231 preempt_enable_no_resched();
19232 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
19233 index 57916c0..9e0b9d0 100644
19234 --- a/arch/x86/kernel/kprobes.c
19235 +++ b/arch/x86/kernel/kprobes.c
19236 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
19237 s32 raddr;
19238 } __attribute__((packed)) *insn;
19239
19240 - insn = (struct __arch_relative_insn *)from;
19241 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
19242 +
19243 + pax_open_kernel();
19244 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
19245 insn->op = op;
19246 + pax_close_kernel();
19247 }
19248
19249 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19250 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19251 kprobe_opcode_t opcode;
19252 kprobe_opcode_t *orig_opcodes = opcodes;
19253
19254 - if (search_exception_tables((unsigned long)opcodes))
19255 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19256 return 0; /* Page fault may occur on this address. */
19257
19258 retry:
19259 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19260 * for the first byte, we can recover the original instruction
19261 * from it and kp->opcode.
19262 */
19263 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19264 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19265 buf[0] = kp->opcode;
19266 - return (unsigned long)buf;
19267 + return ktva_ktla((unsigned long)buf);
19268 }
19269
19270 /*
19271 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19272 /* Another subsystem puts a breakpoint, failed to recover */
19273 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19274 return 0;
19275 + pax_open_kernel();
19276 memcpy(dest, insn.kaddr, insn.length);
19277 + pax_close_kernel();
19278
19279 #ifdef CONFIG_X86_64
19280 if (insn_rip_relative(&insn)) {
19281 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19282 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19283 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19284 disp = (u8 *) dest + insn_offset_displacement(&insn);
19285 + pax_open_kernel();
19286 *(s32 *) disp = (s32) newdisp;
19287 + pax_close_kernel();
19288 }
19289 #endif
19290 return insn.length;
19291 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19292 * nor set current_kprobe, because it doesn't use single
19293 * stepping.
19294 */
19295 - regs->ip = (unsigned long)p->ainsn.insn;
19296 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19297 preempt_enable_no_resched();
19298 return;
19299 }
19300 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19301 regs->flags &= ~X86_EFLAGS_IF;
19302 /* single step inline if the instruction is an int3 */
19303 if (p->opcode == BREAKPOINT_INSTRUCTION)
19304 - regs->ip = (unsigned long)p->addr;
19305 + regs->ip = ktla_ktva((unsigned long)p->addr);
19306 else
19307 - regs->ip = (unsigned long)p->ainsn.insn;
19308 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19309 }
19310
19311 /*
19312 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19313 setup_singlestep(p, regs, kcb, 0);
19314 return 1;
19315 }
19316 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
19317 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19318 /*
19319 * The breakpoint instruction was removed right
19320 * after we hit it. Another cpu has removed
19321 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19322 " movq %rax, 152(%rsp)\n"
19323 RESTORE_REGS_STRING
19324 " popfq\n"
19325 +#ifdef KERNEXEC_PLUGIN
19326 + " btsq $63,(%rsp)\n"
19327 +#endif
19328 #else
19329 " pushf\n"
19330 SAVE_REGS_STRING
19331 @@ -788,7 +798,7 @@ static void __kprobes
19332 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19333 {
19334 unsigned long *tos = stack_addr(regs);
19335 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19336 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19337 unsigned long orig_ip = (unsigned long)p->addr;
19338 kprobe_opcode_t *insn = p->ainsn.insn;
19339
19340 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19341 struct die_args *args = data;
19342 int ret = NOTIFY_DONE;
19343
19344 - if (args->regs && user_mode_vm(args->regs))
19345 + if (args->regs && user_mode(args->regs))
19346 return ret;
19347
19348 switch (val) {
19349 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
19350 index 4180a87..4678e4f 100644
19351 --- a/arch/x86/kernel/kvm.c
19352 +++ b/arch/x86/kernel/kvm.c
19353 @@ -267,7 +267,7 @@ static void __init paravirt_ops_setup(void)
19354 pv_info.paravirt_enabled = 1;
19355
19356 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
19357 - pv_cpu_ops.io_delay = kvm_io_delay;
19358 + *(void **)&pv_cpu_ops.io_delay = kvm_io_delay;
19359
19360 #ifdef CONFIG_X86_IO_APIC
19361 no_timer_check = 1;
19362 @@ -461,18 +461,18 @@ void __init kvm_guest_init(void)
19363 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
19364 spin_lock_init(&async_pf_sleepers[i].lock);
19365 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
19366 - x86_init.irqs.trap_init = kvm_apf_trap_init;
19367 + *(void **)&x86_init.irqs.trap_init = kvm_apf_trap_init;
19368
19369 if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
19370 has_steal_clock = 1;
19371 - pv_time_ops.steal_clock = kvm_steal_clock;
19372 + *(void **)&pv_time_ops.steal_clock = kvm_steal_clock;
19373 }
19374
19375 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
19376 apic_set_eoi_write(kvm_guest_apic_eoi_write);
19377
19378 #ifdef CONFIG_SMP
19379 - smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19380 + *(void **)&smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19381 register_cpu_notifier(&kvm_cpu_notifier);
19382 #else
19383 kvm_guest_cpu_init();
19384 diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
19385 index f1b42b3..27ac4e7 100644
19386 --- a/arch/x86/kernel/kvmclock.c
19387 +++ b/arch/x86/kernel/kvmclock.c
19388 @@ -211,19 +211,19 @@ void __init kvmclock_init(void)
19389
19390 if (kvm_register_clock("boot clock"))
19391 return;
19392 - pv_time_ops.sched_clock = kvm_clock_read;
19393 - x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19394 - x86_platform.get_wallclock = kvm_get_wallclock;
19395 - x86_platform.set_wallclock = kvm_set_wallclock;
19396 + *(void **)&pv_time_ops.sched_clock = kvm_clock_read;
19397 + *(void **)&x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19398 + *(void **)&x86_platform.get_wallclock = kvm_get_wallclock;
19399 + *(void **)&x86_platform.set_wallclock = kvm_set_wallclock;
19400 #ifdef CONFIG_X86_LOCAL_APIC
19401 - x86_cpuinit.early_percpu_clock_init =
19402 + *(void **)&x86_cpuinit.early_percpu_clock_init =
19403 kvm_setup_secondary_clock;
19404 #endif
19405 - x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19406 - x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19407 - machine_ops.shutdown = kvm_shutdown;
19408 + *(void **)&x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19409 + *(void **)&x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19410 + *(void **)&machine_ops.shutdown = kvm_shutdown;
19411 #ifdef CONFIG_KEXEC
19412 - machine_ops.crash_shutdown = kvm_crash_shutdown;
19413 + *(void **)&machine_ops.crash_shutdown = kvm_crash_shutdown;
19414 #endif
19415 kvm_get_preset_lpj();
19416 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
19417 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19418 index ebc9873..1b9724b 100644
19419 --- a/arch/x86/kernel/ldt.c
19420 +++ b/arch/x86/kernel/ldt.c
19421 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19422 if (reload) {
19423 #ifdef CONFIG_SMP
19424 preempt_disable();
19425 - load_LDT(pc);
19426 + load_LDT_nolock(pc);
19427 if (!cpumask_equal(mm_cpumask(current->mm),
19428 cpumask_of(smp_processor_id())))
19429 smp_call_function(flush_ldt, current->mm, 1);
19430 preempt_enable();
19431 #else
19432 - load_LDT(pc);
19433 + load_LDT_nolock(pc);
19434 #endif
19435 }
19436 if (oldsize) {
19437 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19438 return err;
19439
19440 for (i = 0; i < old->size; i++)
19441 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19442 + write_ldt_entry(new->ldt, i, old->ldt + i);
19443 return 0;
19444 }
19445
19446 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19447 retval = copy_ldt(&mm->context, &old_mm->context);
19448 mutex_unlock(&old_mm->context.lock);
19449 }
19450 +
19451 + if (tsk == current) {
19452 + mm->context.vdso = 0;
19453 +
19454 +#ifdef CONFIG_X86_32
19455 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19456 + mm->context.user_cs_base = 0UL;
19457 + mm->context.user_cs_limit = ~0UL;
19458 +
19459 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19460 + cpus_clear(mm->context.cpu_user_cs_mask);
19461 +#endif
19462 +
19463 +#endif
19464 +#endif
19465 +
19466 + }
19467 +
19468 return retval;
19469 }
19470
19471 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19472 }
19473 }
19474
19475 +#ifdef CONFIG_PAX_SEGMEXEC
19476 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19477 + error = -EINVAL;
19478 + goto out_unlock;
19479 + }
19480 +#endif
19481 +
19482 fill_ldt(&ldt, &ldt_info);
19483 if (oldmode)
19484 ldt.avl = 0;
19485 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19486 index 5b19e4d..6476a76 100644
19487 --- a/arch/x86/kernel/machine_kexec_32.c
19488 +++ b/arch/x86/kernel/machine_kexec_32.c
19489 @@ -26,7 +26,7 @@
19490 #include <asm/cacheflush.h>
19491 #include <asm/debugreg.h>
19492
19493 -static void set_idt(void *newidt, __u16 limit)
19494 +static void set_idt(struct desc_struct *newidt, __u16 limit)
19495 {
19496 struct desc_ptr curidt;
19497
19498 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19499 }
19500
19501
19502 -static void set_gdt(void *newgdt, __u16 limit)
19503 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19504 {
19505 struct desc_ptr curgdt;
19506
19507 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19508 }
19509
19510 control_page = page_address(image->control_code_page);
19511 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19512 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19513
19514 relocate_kernel_ptr = control_page;
19515 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19516 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19517 index 3544aed..01ddc1c 100644
19518 --- a/arch/x86/kernel/microcode_intel.c
19519 +++ b/arch/x86/kernel/microcode_intel.c
19520 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19521
19522 static int get_ucode_user(void *to, const void *from, size_t n)
19523 {
19524 - return copy_from_user(to, from, n);
19525 + return copy_from_user(to, (const void __force_user *)from, n);
19526 }
19527
19528 static enum ucode_state
19529 request_microcode_user(int cpu, const void __user *buf, size_t size)
19530 {
19531 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19532 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19533 }
19534
19535 static void microcode_fini_cpu(int cpu)
19536 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19537 index 216a4d7..b328f09 100644
19538 --- a/arch/x86/kernel/module.c
19539 +++ b/arch/x86/kernel/module.c
19540 @@ -43,15 +43,60 @@ do { \
19541 } while (0)
19542 #endif
19543
19544 -void *module_alloc(unsigned long size)
19545 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19546 {
19547 - if (PAGE_ALIGN(size) > MODULES_LEN)
19548 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
19549 return NULL;
19550 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19551 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19552 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19553 -1, __builtin_return_address(0));
19554 }
19555
19556 +void *module_alloc(unsigned long size)
19557 +{
19558 +
19559 +#ifdef CONFIG_PAX_KERNEXEC
19560 + return __module_alloc(size, PAGE_KERNEL);
19561 +#else
19562 + return __module_alloc(size, PAGE_KERNEL_EXEC);
19563 +#endif
19564 +
19565 +}
19566 +
19567 +#ifdef CONFIG_PAX_KERNEXEC
19568 +#ifdef CONFIG_X86_32
19569 +void *module_alloc_exec(unsigned long size)
19570 +{
19571 + struct vm_struct *area;
19572 +
19573 + if (size == 0)
19574 + return NULL;
19575 +
19576 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19577 + return area ? area->addr : NULL;
19578 +}
19579 +EXPORT_SYMBOL(module_alloc_exec);
19580 +
19581 +void module_free_exec(struct module *mod, void *module_region)
19582 +{
19583 + vunmap(module_region);
19584 +}
19585 +EXPORT_SYMBOL(module_free_exec);
19586 +#else
19587 +void module_free_exec(struct module *mod, void *module_region)
19588 +{
19589 + module_free(mod, module_region);
19590 +}
19591 +EXPORT_SYMBOL(module_free_exec);
19592 +
19593 +void *module_alloc_exec(unsigned long size)
19594 +{
19595 + return __module_alloc(size, PAGE_KERNEL_RX);
19596 +}
19597 +EXPORT_SYMBOL(module_alloc_exec);
19598 +#endif
19599 +#endif
19600 +
19601 #ifdef CONFIG_X86_32
19602 int apply_relocate(Elf32_Shdr *sechdrs,
19603 const char *strtab,
19604 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19605 unsigned int i;
19606 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19607 Elf32_Sym *sym;
19608 - uint32_t *location;
19609 + uint32_t *plocation, location;
19610
19611 DEBUGP("Applying relocate section %u to %u\n",
19612 relsec, sechdrs[relsec].sh_info);
19613 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19614 /* This is where to make the change */
19615 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19616 - + rel[i].r_offset;
19617 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19618 + location = (uint32_t)plocation;
19619 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19620 + plocation = ktla_ktva((void *)plocation);
19621 /* This is the symbol it is referring to. Note that all
19622 undefined symbols have been resolved. */
19623 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19624 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19625 switch (ELF32_R_TYPE(rel[i].r_info)) {
19626 case R_386_32:
19627 /* We add the value into the location given */
19628 - *location += sym->st_value;
19629 + pax_open_kernel();
19630 + *plocation += sym->st_value;
19631 + pax_close_kernel();
19632 break;
19633 case R_386_PC32:
19634 /* Add the value, subtract its position */
19635 - *location += sym->st_value - (uint32_t)location;
19636 + pax_open_kernel();
19637 + *plocation += sym->st_value - location;
19638 + pax_close_kernel();
19639 break;
19640 default:
19641 pr_err("%s: Unknown relocation: %u\n",
19642 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19643 case R_X86_64_NONE:
19644 break;
19645 case R_X86_64_64:
19646 + pax_open_kernel();
19647 *(u64 *)loc = val;
19648 + pax_close_kernel();
19649 break;
19650 case R_X86_64_32:
19651 + pax_open_kernel();
19652 *(u32 *)loc = val;
19653 + pax_close_kernel();
19654 if (val != *(u32 *)loc)
19655 goto overflow;
19656 break;
19657 case R_X86_64_32S:
19658 + pax_open_kernel();
19659 *(s32 *)loc = val;
19660 + pax_close_kernel();
19661 if ((s64)val != *(s32 *)loc)
19662 goto overflow;
19663 break;
19664 case R_X86_64_PC32:
19665 val -= (u64)loc;
19666 + pax_open_kernel();
19667 *(u32 *)loc = val;
19668 + pax_close_kernel();
19669 +
19670 #if 0
19671 if ((s64)val != *(s32 *)loc)
19672 goto overflow;
19673 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19674 index f84f5c5..e27e54b 100644
19675 --- a/arch/x86/kernel/nmi.c
19676 +++ b/arch/x86/kernel/nmi.c
19677 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19678 dotraplinkage notrace __kprobes void
19679 do_nmi(struct pt_regs *regs, long error_code)
19680 {
19681 +
19682 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19683 + if (!user_mode(regs)) {
19684 + unsigned long cs = regs->cs & 0xFFFF;
19685 + unsigned long ip = ktva_ktla(regs->ip);
19686 +
19687 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19688 + regs->ip = ip;
19689 + }
19690 +#endif
19691 +
19692 nmi_nesting_preprocess(regs);
19693
19694 nmi_enter();
19695 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19696 index 676b8c7..870ba04 100644
19697 --- a/arch/x86/kernel/paravirt-spinlocks.c
19698 +++ b/arch/x86/kernel/paravirt-spinlocks.c
19699 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19700 arch_spin_lock(lock);
19701 }
19702
19703 -struct pv_lock_ops pv_lock_ops = {
19704 +struct pv_lock_ops pv_lock_ops __read_only = {
19705 #ifdef CONFIG_SMP
19706 .spin_is_locked = __ticket_spin_is_locked,
19707 .spin_is_contended = __ticket_spin_is_contended,
19708 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19709 index 17fff18..0f5f957 100644
19710 --- a/arch/x86/kernel/paravirt.c
19711 +++ b/arch/x86/kernel/paravirt.c
19712 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19713 {
19714 return x;
19715 }
19716 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19717 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19718 +#endif
19719
19720 void __init default_banner(void)
19721 {
19722 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19723 if (opfunc == NULL)
19724 /* If there's no function, patch it with a ud2a (BUG) */
19725 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19726 - else if (opfunc == _paravirt_nop)
19727 + else if (opfunc == (void *)_paravirt_nop)
19728 /* If the operation is a nop, then nop the callsite */
19729 ret = paravirt_patch_nop();
19730
19731 /* identity functions just return their single argument */
19732 - else if (opfunc == _paravirt_ident_32)
19733 + else if (opfunc == (void *)_paravirt_ident_32)
19734 ret = paravirt_patch_ident_32(insnbuf, len);
19735 - else if (opfunc == _paravirt_ident_64)
19736 + else if (opfunc == (void *)_paravirt_ident_64)
19737 ret = paravirt_patch_ident_64(insnbuf, len);
19738 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19739 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19740 + ret = paravirt_patch_ident_64(insnbuf, len);
19741 +#endif
19742
19743 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19744 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19745 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19746 if (insn_len > len || start == NULL)
19747 insn_len = len;
19748 else
19749 - memcpy(insnbuf, start, insn_len);
19750 + memcpy(insnbuf, ktla_ktva(start), insn_len);
19751
19752 return insn_len;
19753 }
19754 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19755 preempt_enable();
19756 }
19757
19758 -struct pv_info pv_info = {
19759 +struct pv_info pv_info __read_only = {
19760 .name = "bare hardware",
19761 .paravirt_enabled = 0,
19762 .kernel_rpl = 0,
19763 @@ -324,7 +331,7 @@ struct pv_time_ops pv_time_ops = {
19764 .steal_clock = native_steal_clock,
19765 };
19766
19767 -struct pv_irq_ops pv_irq_ops = {
19768 +struct pv_irq_ops pv_irq_ops __read_only = {
19769 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19770 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19771 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19772 @@ -401,15 +408,20 @@ struct pv_apic_ops pv_apic_ops = {
19773 #endif
19774 };
19775
19776 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19777 +#ifdef CONFIG_X86_32
19778 +#ifdef CONFIG_X86_PAE
19779 +/* 64-bit pagetable entries */
19780 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19781 +#else
19782 /* 32-bit pagetable entries */
19783 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19784 +#endif
19785 #else
19786 /* 64-bit pagetable entries */
19787 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19788 #endif
19789
19790 -struct pv_mmu_ops pv_mmu_ops = {
19791 +struct pv_mmu_ops pv_mmu_ops __read_only = {
19792
19793 .read_cr2 = native_read_cr2,
19794 .write_cr2 = native_write_cr2,
19795 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19796 .make_pud = PTE_IDENT,
19797
19798 .set_pgd = native_set_pgd,
19799 + .set_pgd_batched = native_set_pgd_batched,
19800 #endif
19801 #endif /* PAGETABLE_LEVELS >= 3 */
19802
19803 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19804 },
19805
19806 .set_fixmap = native_set_fixmap,
19807 +
19808 +#ifdef CONFIG_PAX_KERNEXEC
19809 + .pax_open_kernel = native_pax_open_kernel,
19810 + .pax_close_kernel = native_pax_close_kernel,
19811 +#endif
19812 +
19813 };
19814
19815 EXPORT_SYMBOL_GPL(pv_time_ops);
19816 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
19817 index 299d493..79c13dd 100644
19818 --- a/arch/x86/kernel/pci-calgary_64.c
19819 +++ b/arch/x86/kernel/pci-calgary_64.c
19820 @@ -1461,7 +1461,7 @@ int __init detect_calgary(void)
19821 printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d\n",
19822 specified_table_size);
19823
19824 - x86_init.iommu.iommu_init = calgary_iommu_init;
19825 + *(void **)&x86_init.iommu.iommu_init = calgary_iommu_init;
19826 }
19827 return calgary_found;
19828
19829 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19830 index 35ccf75..7a15747 100644
19831 --- a/arch/x86/kernel/pci-iommu_table.c
19832 +++ b/arch/x86/kernel/pci-iommu_table.c
19833 @@ -2,7 +2,7 @@
19834 #include <asm/iommu_table.h>
19835 #include <linux/string.h>
19836 #include <linux/kallsyms.h>
19837 -
19838 +#include <linux/sched.h>
19839
19840 #define DEBUG 1
19841
19842 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19843 index b644e1c..4a6d379 100644
19844 --- a/arch/x86/kernel/process.c
19845 +++ b/arch/x86/kernel/process.c
19846 @@ -36,7 +36,8 @@
19847 * section. Since TSS's are completely CPU-local, we want them
19848 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19849 */
19850 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19851 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19852 +EXPORT_SYMBOL(init_tss);
19853
19854 #ifdef CONFIG_X86_64
19855 static DEFINE_PER_CPU(unsigned char, is_idle);
19856 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19857 task_xstate_cachep =
19858 kmem_cache_create("task_xstate", xstate_size,
19859 __alignof__(union thread_xstate),
19860 - SLAB_PANIC | SLAB_NOTRACK, NULL);
19861 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19862 }
19863
19864 /*
19865 @@ -105,7 +106,7 @@ void exit_thread(void)
19866 unsigned long *bp = t->io_bitmap_ptr;
19867
19868 if (bp) {
19869 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19870 + struct tss_struct *tss = init_tss + get_cpu();
19871
19872 t->io_bitmap_ptr = NULL;
19873 clear_thread_flag(TIF_IO_BITMAP);
19874 @@ -136,7 +137,7 @@ void show_regs_common(void)
19875 board = dmi_get_system_info(DMI_BOARD_NAME);
19876
19877 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19878 - current->pid, current->comm, print_tainted(),
19879 + task_pid_nr(current), current->comm, print_tainted(),
19880 init_utsname()->release,
19881 (int)strcspn(init_utsname()->version, " "),
19882 init_utsname()->version,
19883 @@ -149,6 +150,9 @@ void flush_thread(void)
19884 {
19885 struct task_struct *tsk = current;
19886
19887 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19888 + loadsegment(gs, 0);
19889 +#endif
19890 flush_ptrace_hw_breakpoint(tsk);
19891 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19892 drop_init_fpu(tsk);
19893 @@ -336,7 +340,7 @@ static void __exit_idle(void)
19894 void exit_idle(void)
19895 {
19896 /* idle loop has pid 0 */
19897 - if (current->pid)
19898 + if (task_pid_nr(current))
19899 return;
19900 __exit_idle();
19901 }
19902 @@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19903
19904 return ret;
19905 }
19906 -void stop_this_cpu(void *dummy)
19907 +__noreturn void stop_this_cpu(void *dummy)
19908 {
19909 local_irq_disable();
19910 /*
19911 @@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19912 }
19913 early_param("idle", idle_setup);
19914
19915 -unsigned long arch_align_stack(unsigned long sp)
19916 +#ifdef CONFIG_PAX_RANDKSTACK
19917 +void pax_randomize_kstack(struct pt_regs *regs)
19918 {
19919 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19920 - sp -= get_random_int() % 8192;
19921 - return sp & ~0xf;
19922 -}
19923 + struct thread_struct *thread = &current->thread;
19924 + unsigned long time;
19925
19926 -unsigned long arch_randomize_brk(struct mm_struct *mm)
19927 -{
19928 - unsigned long range_end = mm->brk + 0x02000000;
19929 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19930 -}
19931 + if (!randomize_va_space)
19932 + return;
19933 +
19934 + if (v8086_mode(regs))
19935 + return;
19936
19937 + rdtscl(time);
19938 +
19939 + /* P4 seems to return a 0 LSB, ignore it */
19940 +#ifdef CONFIG_MPENTIUM4
19941 + time &= 0x3EUL;
19942 + time <<= 2;
19943 +#elif defined(CONFIG_X86_64)
19944 + time &= 0xFUL;
19945 + time <<= 4;
19946 +#else
19947 + time &= 0x1FUL;
19948 + time <<= 3;
19949 +#endif
19950 +
19951 + thread->sp0 ^= time;
19952 + load_sp0(init_tss + smp_processor_id(), thread);
19953 +
19954 +#ifdef CONFIG_X86_64
19955 + this_cpu_write(kernel_stack, thread->sp0);
19956 +#endif
19957 +}
19958 +#endif
19959 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
19960 index 44e0bff..5ceb99c 100644
19961 --- a/arch/x86/kernel/process_32.c
19962 +++ b/arch/x86/kernel/process_32.c
19963 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
19964 unsigned long thread_saved_pc(struct task_struct *tsk)
19965 {
19966 return ((unsigned long *)tsk->thread.sp)[3];
19967 +//XXX return tsk->thread.eip;
19968 }
19969
19970 void __show_regs(struct pt_regs *regs, int all)
19971 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
19972 unsigned long sp;
19973 unsigned short ss, gs;
19974
19975 - if (user_mode_vm(regs)) {
19976 + if (user_mode(regs)) {
19977 sp = regs->sp;
19978 ss = regs->ss & 0xffff;
19979 - gs = get_user_gs(regs);
19980 } else {
19981 sp = kernel_stack_pointer(regs);
19982 savesegment(ss, ss);
19983 - savesegment(gs, gs);
19984 }
19985 + gs = get_user_gs(regs);
19986
19987 show_regs_common();
19988
19989 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
19990 (u16)regs->cs, regs->ip, regs->flags,
19991 - smp_processor_id());
19992 + raw_smp_processor_id());
19993 print_symbol("EIP is at %s\n", regs->ip);
19994
19995 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
19996 @@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19997 unsigned long arg,
19998 struct task_struct *p, struct pt_regs *regs)
19999 {
20000 - struct pt_regs *childregs = task_pt_regs(p);
20001 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
20002 struct task_struct *tsk;
20003 int err;
20004
20005 p->thread.sp = (unsigned long) childregs;
20006 p->thread.sp0 = (unsigned long) (childregs+1);
20007 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20008
20009 if (unlikely(!regs)) {
20010 /* kernel thread */
20011 memset(childregs, 0, sizeof(struct pt_regs));
20012 p->thread.ip = (unsigned long) ret_from_kernel_thread;
20013 - task_user_gs(p) = __KERNEL_STACK_CANARY;
20014 - childregs->ds = __USER_DS;
20015 - childregs->es = __USER_DS;
20016 + savesegment(gs, childregs->gs);
20017 + childregs->ds = __KERNEL_DS;
20018 + childregs->es = __KERNEL_DS;
20019 childregs->fs = __KERNEL_PERCPU;
20020 childregs->bx = sp; /* function */
20021 childregs->bp = arg;
20022 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20023 struct thread_struct *prev = &prev_p->thread,
20024 *next = &next_p->thread;
20025 int cpu = smp_processor_id();
20026 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20027 + struct tss_struct *tss = init_tss + cpu;
20028 fpu_switch_t fpu;
20029
20030 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
20031 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20032 */
20033 lazy_save_gs(prev->gs);
20034
20035 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20036 + __set_fs(task_thread_info(next_p)->addr_limit);
20037 +#endif
20038 +
20039 /*
20040 * Load the per-thread Thread-Local Storage descriptor.
20041 */
20042 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20043 */
20044 arch_end_context_switch(next_p);
20045
20046 + this_cpu_write(current_task, next_p);
20047 + this_cpu_write(current_tinfo, &next_p->tinfo);
20048 +
20049 /*
20050 * Restore %gs if needed (which is common)
20051 */
20052 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20053
20054 switch_fpu_finish(next_p, fpu);
20055
20056 - this_cpu_write(current_task, next_p);
20057 -
20058 return prev_p;
20059 }
20060
20061 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
20062 } while (count++ < 16);
20063 return 0;
20064 }
20065 -
20066 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
20067 index 16c6365..5d32218 100644
20068 --- a/arch/x86/kernel/process_64.c
20069 +++ b/arch/x86/kernel/process_64.c
20070 @@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20071 struct pt_regs *childregs;
20072 struct task_struct *me = current;
20073
20074 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
20075 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
20076 childregs = task_pt_regs(p);
20077 p->thread.sp = (unsigned long) childregs;
20078 p->thread.usersp = me->thread.usersp;
20079 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20080 set_tsk_thread_flag(p, TIF_FORK);
20081 p->fpu_counter = 0;
20082 p->thread.io_bitmap_ptr = NULL;
20083 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20084 struct thread_struct *prev = &prev_p->thread;
20085 struct thread_struct *next = &next_p->thread;
20086 int cpu = smp_processor_id();
20087 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20088 + struct tss_struct *tss = init_tss + cpu;
20089 unsigned fsindex, gsindex;
20090 fpu_switch_t fpu;
20091
20092 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20093 prev->usersp = this_cpu_read(old_rsp);
20094 this_cpu_write(old_rsp, next->usersp);
20095 this_cpu_write(current_task, next_p);
20096 + this_cpu_write(current_tinfo, &next_p->tinfo);
20097
20098 - this_cpu_write(kernel_stack,
20099 - (unsigned long)task_stack_page(next_p) +
20100 - THREAD_SIZE - KERNEL_STACK_OFFSET);
20101 + this_cpu_write(kernel_stack, next->sp0);
20102
20103 /*
20104 * Now maybe reload the debug registers and handle I/O bitmaps
20105 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
20106 if (!p || p == current || p->state == TASK_RUNNING)
20107 return 0;
20108 stack = (unsigned long)task_stack_page(p);
20109 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
20110 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
20111 return 0;
20112 fp = *(u64 *)(p->thread.sp);
20113 do {
20114 - if (fp < (unsigned long)stack ||
20115 - fp >= (unsigned long)stack+THREAD_SIZE)
20116 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
20117 return 0;
20118 ip = *(u64 *)(fp+8);
20119 if (!in_sched_functions(ip))
20120 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
20121 index 974b67e..12cb2b5 100644
20122 --- a/arch/x86/kernel/ptrace.c
20123 +++ b/arch/x86/kernel/ptrace.c
20124 @@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
20125 {
20126 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
20127 unsigned long sp = (unsigned long)&regs->sp;
20128 - struct thread_info *tinfo;
20129
20130 - if (context == (sp & ~(THREAD_SIZE - 1)))
20131 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
20132 return sp;
20133
20134 - tinfo = (struct thread_info *)context;
20135 - if (tinfo->previous_esp)
20136 - return tinfo->previous_esp;
20137 + sp = *(unsigned long *)context;
20138 + if (sp)
20139 + return sp;
20140
20141 return (unsigned long)regs;
20142 }
20143 @@ -587,7 +586,7 @@ static void ptrace_triggered(struct perf_event *bp,
20144 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
20145 {
20146 int i;
20147 - int dr7 = 0;
20148 + unsigned long dr7 = 0;
20149 struct arch_hw_breakpoint *info;
20150
20151 for (i = 0; i < HBP_NUM; i++) {
20152 @@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
20153 unsigned long addr, unsigned long data)
20154 {
20155 int ret;
20156 - unsigned long __user *datap = (unsigned long __user *)data;
20157 + unsigned long __user *datap = (__force unsigned long __user *)data;
20158
20159 switch (request) {
20160 /* read the word at location addr in the USER area. */
20161 @@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
20162 if ((int) addr < 0)
20163 return -EIO;
20164 ret = do_get_thread_area(child, addr,
20165 - (struct user_desc __user *)data);
20166 + (__force struct user_desc __user *) data);
20167 break;
20168
20169 case PTRACE_SET_THREAD_AREA:
20170 if ((int) addr < 0)
20171 return -EIO;
20172 ret = do_set_thread_area(child, addr,
20173 - (struct user_desc __user *)data, 0);
20174 + (__force struct user_desc __user *) data, 0);
20175 break;
20176 #endif
20177
20178 @@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
20179
20180 #ifdef CONFIG_X86_64
20181
20182 -static struct user_regset x86_64_regsets[] __read_mostly = {
20183 +static struct user_regset x86_64_regsets[] = {
20184 [REGSET_GENERAL] = {
20185 .core_note_type = NT_PRSTATUS,
20186 .n = sizeof(struct user_regs_struct) / sizeof(long),
20187 @@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
20188 #endif /* CONFIG_X86_64 */
20189
20190 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20191 -static struct user_regset x86_32_regsets[] __read_mostly = {
20192 +static struct user_regset x86_32_regsets[] = {
20193 [REGSET_GENERAL] = {
20194 .core_note_type = NT_PRSTATUS,
20195 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
20196 @@ -1419,13 +1418,13 @@ static const struct user_regset_view user_x86_32_view = {
20197 */
20198 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
20199
20200 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20201 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20202 {
20203 #ifdef CONFIG_X86_64
20204 - x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20205 + *(unsigned int *)&x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20206 #endif
20207 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20208 - x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20209 + *(unsigned int *)&x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20210 #endif
20211 xstate_fx_sw_bytes[USER_XSTATE_XCR0_WORD] = xstate_mask;
20212 }
20213 @@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
20214 memset(info, 0, sizeof(*info));
20215 info->si_signo = SIGTRAP;
20216 info->si_code = si_code;
20217 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
20218 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
20219 }
20220
20221 void user_single_step_siginfo(struct task_struct *tsk,
20222 @@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
20223 # define IS_IA32 0
20224 #endif
20225
20226 +#ifdef CONFIG_GRKERNSEC_SETXID
20227 +extern void gr_delayed_cred_worker(void);
20228 +#endif
20229 +
20230 /*
20231 * We must return the syscall number to actually look up in the table.
20232 * This can be -1L to skip running any syscall at all.
20233 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
20234
20235 rcu_user_exit();
20236
20237 +#ifdef CONFIG_GRKERNSEC_SETXID
20238 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20239 + gr_delayed_cred_worker();
20240 +#endif
20241 +
20242 /*
20243 * If we stepped into a sysenter/syscall insn, it trapped in
20244 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
20245 @@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
20246 */
20247 rcu_user_exit();
20248
20249 +#ifdef CONFIG_GRKERNSEC_SETXID
20250 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20251 + gr_delayed_cred_worker();
20252 +#endif
20253 +
20254 audit_syscall_exit(regs);
20255
20256 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
20257 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
20258 index 42eb330..139955c 100644
20259 --- a/arch/x86/kernel/pvclock.c
20260 +++ b/arch/x86/kernel/pvclock.c
20261 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
20262 return pv_tsc_khz;
20263 }
20264
20265 -static atomic64_t last_value = ATOMIC64_INIT(0);
20266 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
20267
20268 void pvclock_resume(void)
20269 {
20270 - atomic64_set(&last_value, 0);
20271 + atomic64_set_unchecked(&last_value, 0);
20272 }
20273
20274 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20275 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20276 * updating at the same time, and one of them could be slightly behind,
20277 * making the assumption that last_value always go forward fail to hold.
20278 */
20279 - last = atomic64_read(&last_value);
20280 + last = atomic64_read_unchecked(&last_value);
20281 do {
20282 if (ret < last)
20283 return last;
20284 - last = atomic64_cmpxchg(&last_value, last, ret);
20285 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
20286 } while (unlikely(last != ret));
20287
20288 return ret;
20289 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
20290 index 76fa1e9..a93c759 100644
20291 --- a/arch/x86/kernel/reboot.c
20292 +++ b/arch/x86/kernel/reboot.c
20293 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
20294 EXPORT_SYMBOL(pm_power_off);
20295
20296 static const struct desc_ptr no_idt = {};
20297 -static int reboot_mode;
20298 +static unsigned short reboot_mode;
20299 enum reboot_type reboot_type = BOOT_ACPI;
20300 int reboot_force;
20301
20302 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
20303
20304 void __noreturn machine_real_restart(unsigned int type)
20305 {
20306 +
20307 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20308 + struct desc_struct *gdt;
20309 +#endif
20310 +
20311 local_irq_disable();
20312
20313 /*
20314 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20315
20316 /* Jump to the identity-mapped low memory code */
20317 #ifdef CONFIG_X86_32
20318 - asm volatile("jmpl *%0" : :
20319 +
20320 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20321 + gdt = get_cpu_gdt_table(smp_processor_id());
20322 + pax_open_kernel();
20323 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20324 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20325 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20326 + loadsegment(ds, __KERNEL_DS);
20327 + loadsegment(es, __KERNEL_DS);
20328 + loadsegment(ss, __KERNEL_DS);
20329 +#endif
20330 +#ifdef CONFIG_PAX_KERNEXEC
20331 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20332 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20333 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20334 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20335 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20336 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20337 +#endif
20338 + pax_close_kernel();
20339 +#endif
20340 +
20341 + asm volatile("ljmpl *%0" : :
20342 "rm" (real_mode_header->machine_real_restart_asm),
20343 "a" (type));
20344 #else
20345 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20346 * try to force a triple fault and then cycle between hitting the keyboard
20347 * controller and doing that
20348 */
20349 -static void native_machine_emergency_restart(void)
20350 +static void __noreturn native_machine_emergency_restart(void)
20351 {
20352 int i;
20353 int attempt = 0;
20354 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20355 #endif
20356 }
20357
20358 -static void __machine_emergency_restart(int emergency)
20359 +static void __noreturn __machine_emergency_restart(int emergency)
20360 {
20361 reboot_emergency = emergency;
20362 machine_ops.emergency_restart();
20363 }
20364
20365 -static void native_machine_restart(char *__unused)
20366 +static void __noreturn native_machine_restart(char *__unused)
20367 {
20368 pr_notice("machine restart\n");
20369
20370 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20371 __machine_emergency_restart(0);
20372 }
20373
20374 -static void native_machine_halt(void)
20375 +static void __noreturn native_machine_halt(void)
20376 {
20377 /* Stop other cpus and apics */
20378 machine_shutdown();
20379 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
20380 stop_this_cpu(NULL);
20381 }
20382
20383 -static void native_machine_power_off(void)
20384 +static void __noreturn native_machine_power_off(void)
20385 {
20386 if (pm_power_off) {
20387 if (!reboot_force)
20388 @@ -688,6 +715,7 @@ static void native_machine_power_off(void)
20389 }
20390 /* A fallback in case there is no PM info available */
20391 tboot_shutdown(TB_SHUTDOWN_HALT);
20392 + unreachable();
20393 }
20394
20395 struct machine_ops machine_ops = {
20396 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20397 index 7a6f3b3..bed145d7 100644
20398 --- a/arch/x86/kernel/relocate_kernel_64.S
20399 +++ b/arch/x86/kernel/relocate_kernel_64.S
20400 @@ -11,6 +11,7 @@
20401 #include <asm/kexec.h>
20402 #include <asm/processor-flags.h>
20403 #include <asm/pgtable_types.h>
20404 +#include <asm/alternative-asm.h>
20405
20406 /*
20407 * Must be relocatable PIC code callable as a C function
20408 @@ -160,13 +161,14 @@ identity_mapped:
20409 xorq %rbp, %rbp
20410 xorq %r8, %r8
20411 xorq %r9, %r9
20412 - xorq %r10, %r9
20413 + xorq %r10, %r10
20414 xorq %r11, %r11
20415 xorq %r12, %r12
20416 xorq %r13, %r13
20417 xorq %r14, %r14
20418 xorq %r15, %r15
20419
20420 + pax_force_retaddr 0, 1
20421 ret
20422
20423 1:
20424 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20425 index aeacb0e..f9d4c02 100644
20426 --- a/arch/x86/kernel/setup.c
20427 +++ b/arch/x86/kernel/setup.c
20428 @@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20429
20430 switch (data->type) {
20431 case SETUP_E820_EXT:
20432 - parse_e820_ext(data);
20433 + parse_e820_ext((struct setup_data __force_kernel *)data);
20434 break;
20435 case SETUP_DTB:
20436 add_dtb(pa_data);
20437 @@ -710,7 +710,7 @@ static void __init trim_bios_range(void)
20438 * area (640->1Mb) as ram even though it is not.
20439 * take them out.
20440 */
20441 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20442 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20443
20444 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20445 }
20446 @@ -834,14 +834,14 @@ void __init setup_arch(char **cmdline_p)
20447
20448 if (!boot_params.hdr.root_flags)
20449 root_mountflags &= ~MS_RDONLY;
20450 - init_mm.start_code = (unsigned long) _text;
20451 - init_mm.end_code = (unsigned long) _etext;
20452 + init_mm.start_code = ktla_ktva((unsigned long) _text);
20453 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
20454 init_mm.end_data = (unsigned long) _edata;
20455 init_mm.brk = _brk_end;
20456
20457 - code_resource.start = virt_to_phys(_text);
20458 - code_resource.end = virt_to_phys(_etext)-1;
20459 - data_resource.start = virt_to_phys(_etext);
20460 + code_resource.start = virt_to_phys(ktla_ktva(_text));
20461 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20462 + data_resource.start = virt_to_phys(_sdata);
20463 data_resource.end = virt_to_phys(_edata)-1;
20464 bss_resource.start = virt_to_phys(&__bss_start);
20465 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20466 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20467 index 5cdff03..5810740 100644
20468 --- a/arch/x86/kernel/setup_percpu.c
20469 +++ b/arch/x86/kernel/setup_percpu.c
20470 @@ -21,19 +21,17 @@
20471 #include <asm/cpu.h>
20472 #include <asm/stackprotector.h>
20473
20474 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20475 +#ifdef CONFIG_SMP
20476 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20477 EXPORT_PER_CPU_SYMBOL(cpu_number);
20478 +#endif
20479
20480 -#ifdef CONFIG_X86_64
20481 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20482 -#else
20483 -#define BOOT_PERCPU_OFFSET 0
20484 -#endif
20485
20486 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20487 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20488
20489 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20490 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20491 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20492 };
20493 EXPORT_SYMBOL(__per_cpu_offset);
20494 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20495 {
20496 #ifdef CONFIG_X86_32
20497 struct desc_struct gdt;
20498 + unsigned long base = per_cpu_offset(cpu);
20499
20500 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20501 - 0x2 | DESCTYPE_S, 0x8);
20502 - gdt.s = 1;
20503 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20504 + 0x83 | DESCTYPE_S, 0xC);
20505 write_gdt_entry(get_cpu_gdt_table(cpu),
20506 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20507 #endif
20508 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20509 /* alrighty, percpu areas up and running */
20510 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20511 for_each_possible_cpu(cpu) {
20512 +#ifdef CONFIG_CC_STACKPROTECTOR
20513 +#ifdef CONFIG_X86_32
20514 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
20515 +#endif
20516 +#endif
20517 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20518 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20519 per_cpu(cpu_number, cpu) = cpu;
20520 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20521 */
20522 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20523 #endif
20524 +#ifdef CONFIG_CC_STACKPROTECTOR
20525 +#ifdef CONFIG_X86_32
20526 + if (!cpu)
20527 + per_cpu(stack_canary.canary, cpu) = canary;
20528 +#endif
20529 +#endif
20530 /*
20531 * Up to this point, the boot CPU has been using .init.data
20532 * area. Reload any changed state for the boot CPU.
20533 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20534 index 70b27ee..fcf827f 100644
20535 --- a/arch/x86/kernel/signal.c
20536 +++ b/arch/x86/kernel/signal.c
20537 @@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20538 * Align the stack pointer according to the i386 ABI,
20539 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20540 */
20541 - sp = ((sp + 4) & -16ul) - 4;
20542 + sp = ((sp - 12) & -16ul) - 4;
20543 #else /* !CONFIG_X86_32 */
20544 sp = round_down(sp, 16) - 8;
20545 #endif
20546 @@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20547 }
20548
20549 if (current->mm->context.vdso)
20550 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20551 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20552 else
20553 - restorer = &frame->retcode;
20554 + restorer = (void __user *)&frame->retcode;
20555 if (ka->sa.sa_flags & SA_RESTORER)
20556 restorer = ka->sa.sa_restorer;
20557
20558 @@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20559 * reasons and because gdb uses it as a signature to notice
20560 * signal handler stack frames.
20561 */
20562 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20563 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20564
20565 if (err)
20566 return -EFAULT;
20567 @@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20568 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20569
20570 /* Set up to return from userspace. */
20571 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20572 + if (current->mm->context.vdso)
20573 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20574 + else
20575 + restorer = (void __user *)&frame->retcode;
20576 if (ka->sa.sa_flags & SA_RESTORER)
20577 restorer = ka->sa.sa_restorer;
20578 put_user_ex(restorer, &frame->pretcode);
20579 @@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20580 * reasons and because gdb uses it as a signature to notice
20581 * signal handler stack frames.
20582 */
20583 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20584 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20585 } put_user_catch(err);
20586
20587 err |= copy_siginfo_to_user(&frame->info, info);
20588 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20589 index f3e2ec8..ad5287a 100644
20590 --- a/arch/x86/kernel/smpboot.c
20591 +++ b/arch/x86/kernel/smpboot.c
20592 @@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20593 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20594 (THREAD_SIZE + task_stack_page(idle))) - 1);
20595 per_cpu(current_task, cpu) = idle;
20596 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
20597
20598 #ifdef CONFIG_X86_32
20599 /* Stack for startup_32 can be just as for start_secondary onwards */
20600 @@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20601 #else
20602 clear_tsk_thread_flag(idle, TIF_FORK);
20603 initial_gs = per_cpu_offset(cpu);
20604 - per_cpu(kernel_stack, cpu) =
20605 - (unsigned long)task_stack_page(idle) -
20606 - KERNEL_STACK_OFFSET + THREAD_SIZE;
20607 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20608 #endif
20609 +
20610 + pax_open_kernel();
20611 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20612 + pax_close_kernel();
20613 +
20614 initial_code = (unsigned long)start_secondary;
20615 stack_start = idle->thread.sp;
20616
20617 @@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20618 /* the FPU context is blank, nobody can own it */
20619 __cpu_disable_lazy_restore(cpu);
20620
20621 +#ifdef CONFIG_PAX_PER_CPU_PGD
20622 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20623 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20624 + KERNEL_PGD_PTRS);
20625 +#endif
20626 +
20627 + /* the FPU context is blank, nobody can own it */
20628 + __cpu_disable_lazy_restore(cpu);
20629 +
20630 err = do_boot_cpu(apicid, cpu, tidle);
20631 if (err) {
20632 pr_debug("do_boot_cpu failed %d\n", err);
20633 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20634 index 9b4d51d..5d28b58 100644
20635 --- a/arch/x86/kernel/step.c
20636 +++ b/arch/x86/kernel/step.c
20637 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20638 struct desc_struct *desc;
20639 unsigned long base;
20640
20641 - seg &= ~7UL;
20642 + seg >>= 3;
20643
20644 mutex_lock(&child->mm->context.lock);
20645 - if (unlikely((seg >> 3) >= child->mm->context.size))
20646 + if (unlikely(seg >= child->mm->context.size))
20647 addr = -1L; /* bogus selector, access would fault */
20648 else {
20649 desc = child->mm->context.ldt + seg;
20650 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20651 addr += base;
20652 }
20653 mutex_unlock(&child->mm->context.lock);
20654 - }
20655 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20656 + addr = ktla_ktva(addr);
20657
20658 return addr;
20659 }
20660 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20661 unsigned char opcode[15];
20662 unsigned long addr = convert_ip_to_linear(child, regs);
20663
20664 + if (addr == -EINVAL)
20665 + return 0;
20666 +
20667 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20668 for (i = 0; i < copied; i++) {
20669 switch (opcode[i]) {
20670 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20671 new file mode 100644
20672 index 0000000..26bb1af
20673 --- /dev/null
20674 +++ b/arch/x86/kernel/sys_i386_32.c
20675 @@ -0,0 +1,249 @@
20676 +/*
20677 + * This file contains various random system calls that
20678 + * have a non-standard calling sequence on the Linux/i386
20679 + * platform.
20680 + */
20681 +
20682 +#include <linux/errno.h>
20683 +#include <linux/sched.h>
20684 +#include <linux/mm.h>
20685 +#include <linux/fs.h>
20686 +#include <linux/smp.h>
20687 +#include <linux/sem.h>
20688 +#include <linux/msg.h>
20689 +#include <linux/shm.h>
20690 +#include <linux/stat.h>
20691 +#include <linux/syscalls.h>
20692 +#include <linux/mman.h>
20693 +#include <linux/file.h>
20694 +#include <linux/utsname.h>
20695 +#include <linux/ipc.h>
20696 +
20697 +#include <linux/uaccess.h>
20698 +#include <linux/unistd.h>
20699 +
20700 +#include <asm/syscalls.h>
20701 +
20702 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20703 +{
20704 + unsigned long pax_task_size = TASK_SIZE;
20705 +
20706 +#ifdef CONFIG_PAX_SEGMEXEC
20707 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20708 + pax_task_size = SEGMEXEC_TASK_SIZE;
20709 +#endif
20710 +
20711 + if (len > pax_task_size || addr > pax_task_size - len)
20712 + return -EINVAL;
20713 +
20714 + return 0;
20715 +}
20716 +
20717 +unsigned long
20718 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
20719 + unsigned long len, unsigned long pgoff, unsigned long flags)
20720 +{
20721 + struct mm_struct *mm = current->mm;
20722 + struct vm_area_struct *vma;
20723 + unsigned long start_addr, pax_task_size = TASK_SIZE;
20724 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20725 +
20726 +#ifdef CONFIG_PAX_SEGMEXEC
20727 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20728 + pax_task_size = SEGMEXEC_TASK_SIZE;
20729 +#endif
20730 +
20731 + pax_task_size -= PAGE_SIZE;
20732 +
20733 + if (len > pax_task_size)
20734 + return -ENOMEM;
20735 +
20736 + if (flags & MAP_FIXED)
20737 + return addr;
20738 +
20739 +#ifdef CONFIG_PAX_RANDMMAP
20740 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20741 +#endif
20742 +
20743 + if (addr) {
20744 + addr = PAGE_ALIGN(addr);
20745 + if (pax_task_size - len >= addr) {
20746 + vma = find_vma(mm, addr);
20747 + if (check_heap_stack_gap(vma, addr, len, offset))
20748 + return addr;
20749 + }
20750 + }
20751 + if (len > mm->cached_hole_size) {
20752 + start_addr = addr = mm->free_area_cache;
20753 + } else {
20754 + start_addr = addr = mm->mmap_base;
20755 + mm->cached_hole_size = 0;
20756 + }
20757 +
20758 +#ifdef CONFIG_PAX_PAGEEXEC
20759 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20760 + start_addr = 0x00110000UL;
20761 +
20762 +#ifdef CONFIG_PAX_RANDMMAP
20763 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20764 + start_addr += mm->delta_mmap & 0x03FFF000UL;
20765 +#endif
20766 +
20767 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20768 + start_addr = addr = mm->mmap_base;
20769 + else
20770 + addr = start_addr;
20771 + }
20772 +#endif
20773 +
20774 +full_search:
20775 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20776 + /* At this point: (!vma || addr < vma->vm_end). */
20777 + if (pax_task_size - len < addr) {
20778 + /*
20779 + * Start a new search - just in case we missed
20780 + * some holes.
20781 + */
20782 + if (start_addr != mm->mmap_base) {
20783 + start_addr = addr = mm->mmap_base;
20784 + mm->cached_hole_size = 0;
20785 + goto full_search;
20786 + }
20787 + return -ENOMEM;
20788 + }
20789 + if (check_heap_stack_gap(vma, addr, len, offset))
20790 + break;
20791 + if (addr + mm->cached_hole_size < vma->vm_start)
20792 + mm->cached_hole_size = vma->vm_start - addr;
20793 + addr = vma->vm_end;
20794 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
20795 + start_addr = addr = mm->mmap_base;
20796 + mm->cached_hole_size = 0;
20797 + goto full_search;
20798 + }
20799 + }
20800 +
20801 + /*
20802 + * Remember the place where we stopped the search:
20803 + */
20804 + mm->free_area_cache = addr + len;
20805 + return addr;
20806 +}
20807 +
20808 +unsigned long
20809 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20810 + const unsigned long len, const unsigned long pgoff,
20811 + const unsigned long flags)
20812 +{
20813 + struct vm_area_struct *vma;
20814 + struct mm_struct *mm = current->mm;
20815 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20816 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20817 +
20818 +#ifdef CONFIG_PAX_SEGMEXEC
20819 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20820 + pax_task_size = SEGMEXEC_TASK_SIZE;
20821 +#endif
20822 +
20823 + pax_task_size -= PAGE_SIZE;
20824 +
20825 + /* requested length too big for entire address space */
20826 + if (len > pax_task_size)
20827 + return -ENOMEM;
20828 +
20829 + if (flags & MAP_FIXED)
20830 + return addr;
20831 +
20832 +#ifdef CONFIG_PAX_PAGEEXEC
20833 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20834 + goto bottomup;
20835 +#endif
20836 +
20837 +#ifdef CONFIG_PAX_RANDMMAP
20838 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20839 +#endif
20840 +
20841 + /* requesting a specific address */
20842 + if (addr) {
20843 + addr = PAGE_ALIGN(addr);
20844 + if (pax_task_size - len >= addr) {
20845 + vma = find_vma(mm, addr);
20846 + if (check_heap_stack_gap(vma, addr, len, offset))
20847 + return addr;
20848 + }
20849 + }
20850 +
20851 + /* check if free_area_cache is useful for us */
20852 + if (len <= mm->cached_hole_size) {
20853 + mm->cached_hole_size = 0;
20854 + mm->free_area_cache = mm->mmap_base;
20855 + }
20856 +
20857 + /* either no address requested or can't fit in requested address hole */
20858 + addr = mm->free_area_cache;
20859 +
20860 + /* make sure it can fit in the remaining address space */
20861 + if (addr > len) {
20862 + vma = find_vma(mm, addr-len);
20863 + if (check_heap_stack_gap(vma, addr - len, len, offset))
20864 + /* remember the address as a hint for next time */
20865 + return (mm->free_area_cache = addr-len);
20866 + }
20867 +
20868 + if (mm->mmap_base < len)
20869 + goto bottomup;
20870 +
20871 + addr = mm->mmap_base-len;
20872 +
20873 + do {
20874 + /*
20875 + * Lookup failure means no vma is above this address,
20876 + * else if new region fits below vma->vm_start,
20877 + * return with success:
20878 + */
20879 + vma = find_vma(mm, addr);
20880 + if (check_heap_stack_gap(vma, addr, len, offset))
20881 + /* remember the address as a hint for next time */
20882 + return (mm->free_area_cache = addr);
20883 +
20884 + /* remember the largest hole we saw so far */
20885 + if (addr + mm->cached_hole_size < vma->vm_start)
20886 + mm->cached_hole_size = vma->vm_start - addr;
20887 +
20888 + /* try just below the current vma->vm_start */
20889 + addr = skip_heap_stack_gap(vma, len, offset);
20890 + } while (!IS_ERR_VALUE(addr));
20891 +
20892 +bottomup:
20893 + /*
20894 + * A failed mmap() very likely causes application failure,
20895 + * so fall back to the bottom-up function here. This scenario
20896 + * can happen with large stack limits and large mmap()
20897 + * allocations.
20898 + */
20899 +
20900 +#ifdef CONFIG_PAX_SEGMEXEC
20901 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20902 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20903 + else
20904 +#endif
20905 +
20906 + mm->mmap_base = TASK_UNMAPPED_BASE;
20907 +
20908 +#ifdef CONFIG_PAX_RANDMMAP
20909 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20910 + mm->mmap_base += mm->delta_mmap;
20911 +#endif
20912 +
20913 + mm->free_area_cache = mm->mmap_base;
20914 + mm->cached_hole_size = ~0UL;
20915 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20916 + /*
20917 + * Restore the topdown base:
20918 + */
20919 + mm->mmap_base = base;
20920 + mm->free_area_cache = base;
20921 + mm->cached_hole_size = ~0UL;
20922 +
20923 + return addr;
20924 +}
20925 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20926 index b4d3c39..d699d77 100644
20927 --- a/arch/x86/kernel/sys_x86_64.c
20928 +++ b/arch/x86/kernel/sys_x86_64.c
20929 @@ -95,8 +95,8 @@ out:
20930 return error;
20931 }
20932
20933 -static void find_start_end(unsigned long flags, unsigned long *begin,
20934 - unsigned long *end)
20935 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
20936 + unsigned long *begin, unsigned long *end)
20937 {
20938 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20939 unsigned long new_begin;
20940 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20941 *begin = new_begin;
20942 }
20943 } else {
20944 - *begin = TASK_UNMAPPED_BASE;
20945 + *begin = mm->mmap_base;
20946 *end = TASK_SIZE;
20947 }
20948 }
20949 @@ -128,20 +128,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20950 struct vm_area_struct *vma;
20951 unsigned long start_addr;
20952 unsigned long begin, end;
20953 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20954
20955 if (flags & MAP_FIXED)
20956 return addr;
20957
20958 - find_start_end(flags, &begin, &end);
20959 + find_start_end(mm, flags, &begin, &end);
20960
20961 if (len > end)
20962 return -ENOMEM;
20963
20964 +#ifdef CONFIG_PAX_RANDMMAP
20965 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20966 +#endif
20967 +
20968 if (addr) {
20969 addr = PAGE_ALIGN(addr);
20970 vma = find_vma(mm, addr);
20971 - if (end - len >= addr &&
20972 - (!vma || addr + len <= vma->vm_start))
20973 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
20974 return addr;
20975 }
20976 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
20977 @@ -172,7 +176,7 @@ full_search:
20978 }
20979 return -ENOMEM;
20980 }
20981 - if (!vma || addr + len <= vma->vm_start) {
20982 + if (check_heap_stack_gap(vma, addr, len, offset)) {
20983 /*
20984 * Remember the place where we stopped the search:
20985 */
20986 @@ -195,7 +199,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20987 {
20988 struct vm_area_struct *vma;
20989 struct mm_struct *mm = current->mm;
20990 - unsigned long addr = addr0, start_addr;
20991 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
20992 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20993
20994 /* requested length too big for entire address space */
20995 if (len > TASK_SIZE)
20996 @@ -208,13 +213,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20997 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
20998 goto bottomup;
20999
21000 +#ifdef CONFIG_PAX_RANDMMAP
21001 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
21002 +#endif
21003 +
21004 /* requesting a specific address */
21005 if (addr) {
21006 addr = PAGE_ALIGN(addr);
21007 - vma = find_vma(mm, addr);
21008 - if (TASK_SIZE - len >= addr &&
21009 - (!vma || addr + len <= vma->vm_start))
21010 - return addr;
21011 + if (TASK_SIZE - len >= addr) {
21012 + vma = find_vma(mm, addr);
21013 + if (check_heap_stack_gap(vma, addr, len, offset))
21014 + return addr;
21015 + }
21016 }
21017
21018 /* check if free_area_cache is useful for us */
21019 @@ -240,7 +250,7 @@ try_again:
21020 * return with success:
21021 */
21022 vma = find_vma(mm, addr);
21023 - if (!vma || addr+len <= vma->vm_start)
21024 + if (check_heap_stack_gap(vma, addr, len, offset))
21025 /* remember the address as a hint for next time */
21026 return mm->free_area_cache = addr;
21027
21028 @@ -249,8 +259,8 @@ try_again:
21029 mm->cached_hole_size = vma->vm_start - addr;
21030
21031 /* try just below the current vma->vm_start */
21032 - addr = vma->vm_start-len;
21033 - } while (len < vma->vm_start);
21034 + addr = skip_heap_stack_gap(vma, len, offset);
21035 + } while (!IS_ERR_VALUE(addr));
21036
21037 fail:
21038 /*
21039 @@ -270,13 +280,21 @@ bottomup:
21040 * can happen with large stack limits and large mmap()
21041 * allocations.
21042 */
21043 + mm->mmap_base = TASK_UNMAPPED_BASE;
21044 +
21045 +#ifdef CONFIG_PAX_RANDMMAP
21046 + if (mm->pax_flags & MF_PAX_RANDMMAP)
21047 + mm->mmap_base += mm->delta_mmap;
21048 +#endif
21049 +
21050 + mm->free_area_cache = mm->mmap_base;
21051 mm->cached_hole_size = ~0UL;
21052 - mm->free_area_cache = TASK_UNMAPPED_BASE;
21053 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
21054 /*
21055 * Restore the topdown base:
21056 */
21057 - mm->free_area_cache = mm->mmap_base;
21058 + mm->mmap_base = base;
21059 + mm->free_area_cache = base;
21060 mm->cached_hole_size = ~0UL;
21061
21062 return addr;
21063 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
21064 index f84fe00..93fe08f 100644
21065 --- a/arch/x86/kernel/tboot.c
21066 +++ b/arch/x86/kernel/tboot.c
21067 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
21068
21069 void tboot_shutdown(u32 shutdown_type)
21070 {
21071 - void (*shutdown)(void);
21072 + void (* __noreturn shutdown)(void);
21073
21074 if (!tboot_enabled())
21075 return;
21076 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
21077
21078 switch_to_tboot_pt();
21079
21080 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
21081 + shutdown = (void *)tboot->shutdown_entry;
21082 shutdown();
21083
21084 /* should not reach here */
21085 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
21086 return 0;
21087 }
21088
21089 -static atomic_t ap_wfs_count;
21090 +static atomic_unchecked_t ap_wfs_count;
21091
21092 static int tboot_wait_for_aps(int num_aps)
21093 {
21094 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
21095 {
21096 switch (action) {
21097 case CPU_DYING:
21098 - atomic_inc(&ap_wfs_count);
21099 + atomic_inc_unchecked(&ap_wfs_count);
21100 if (num_online_cpus() == 1)
21101 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
21102 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
21103 return NOTIFY_BAD;
21104 break;
21105 }
21106 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
21107
21108 tboot_create_trampoline();
21109
21110 - atomic_set(&ap_wfs_count, 0);
21111 + atomic_set_unchecked(&ap_wfs_count, 0);
21112 register_hotcpu_notifier(&tboot_cpu_notifier);
21113
21114 acpi_os_set_prepare_sleep(&tboot_sleep);
21115 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
21116 index 24d3c91..d06b473 100644
21117 --- a/arch/x86/kernel/time.c
21118 +++ b/arch/x86/kernel/time.c
21119 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
21120 {
21121 unsigned long pc = instruction_pointer(regs);
21122
21123 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
21124 + if (!user_mode(regs) && in_lock_functions(pc)) {
21125 #ifdef CONFIG_FRAME_POINTER
21126 - return *(unsigned long *)(regs->bp + sizeof(long));
21127 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
21128 #else
21129 unsigned long *sp =
21130 (unsigned long *)kernel_stack_pointer(regs);
21131 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
21132 * or above a saved flags. Eflags has bits 22-31 zero,
21133 * kernel addresses don't.
21134 */
21135 +
21136 +#ifdef CONFIG_PAX_KERNEXEC
21137 + return ktla_ktva(sp[0]);
21138 +#else
21139 if (sp[0] >> 22)
21140 return sp[0];
21141 if (sp[1] >> 22)
21142 return sp[1];
21143 #endif
21144 +
21145 +#endif
21146 }
21147 return pc;
21148 }
21149 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
21150 index 9d9d2f9..cad418a 100644
21151 --- a/arch/x86/kernel/tls.c
21152 +++ b/arch/x86/kernel/tls.c
21153 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
21154 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
21155 return -EINVAL;
21156
21157 +#ifdef CONFIG_PAX_SEGMEXEC
21158 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
21159 + return -EINVAL;
21160 +#endif
21161 +
21162 set_tls_desc(p, idx, &info, 1);
21163
21164 return 0;
21165 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
21166
21167 if (kbuf)
21168 info = kbuf;
21169 - else if (__copy_from_user(infobuf, ubuf, count))
21170 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
21171 return -EFAULT;
21172 else
21173 info = infobuf;
21174 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
21175 index 8276dc6..4ca48a2 100644
21176 --- a/arch/x86/kernel/traps.c
21177 +++ b/arch/x86/kernel/traps.c
21178 @@ -71,12 +71,6 @@ asmlinkage int system_call(void);
21179
21180 /* Do we ignore FPU interrupts ? */
21181 char ignore_fpu_irq;
21182 -
21183 -/*
21184 - * The IDT has to be page-aligned to simplify the Pentium
21185 - * F0 0F bug workaround.
21186 - */
21187 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
21188 #endif
21189
21190 DECLARE_BITMAP(used_vectors, NR_VECTORS);
21191 @@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
21192 }
21193
21194 static int __kprobes
21195 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21196 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
21197 struct pt_regs *regs, long error_code)
21198 {
21199 #ifdef CONFIG_X86_32
21200 - if (regs->flags & X86_VM_MASK) {
21201 + if (v8086_mode(regs)) {
21202 /*
21203 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
21204 * On nmi (interrupt 2), do_trap should not be called.
21205 @@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21206 return -1;
21207 }
21208 #endif
21209 - if (!user_mode(regs)) {
21210 + if (!user_mode_novm(regs)) {
21211 if (!fixup_exception(regs)) {
21212 tsk->thread.error_code = error_code;
21213 tsk->thread.trap_nr = trapnr;
21214 +
21215 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21216 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
21217 + str = "PAX: suspicious stack segment fault";
21218 +#endif
21219 +
21220 die(str, regs, error_code);
21221 }
21222 +
21223 +#ifdef CONFIG_PAX_REFCOUNT
21224 + if (trapnr == 4)
21225 + pax_report_refcount_overflow(regs);
21226 +#endif
21227 +
21228 return 0;
21229 }
21230
21231 @@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21232 }
21233
21234 static void __kprobes
21235 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21236 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
21237 long error_code, siginfo_t *info)
21238 {
21239 struct task_struct *tsk = current;
21240 @@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21241 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
21242 printk_ratelimit()) {
21243 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
21244 - tsk->comm, tsk->pid, str,
21245 + tsk->comm, task_pid_nr(tsk), str,
21246 regs->ip, regs->sp, error_code);
21247 print_vma_addr(" in ", regs->ip);
21248 pr_cont("\n");
21249 @@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
21250 conditional_sti(regs);
21251
21252 #ifdef CONFIG_X86_32
21253 - if (regs->flags & X86_VM_MASK) {
21254 + if (v8086_mode(regs)) {
21255 local_irq_enable();
21256 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
21257 goto exit;
21258 @@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
21259 #endif
21260
21261 tsk = current;
21262 - if (!user_mode(regs)) {
21263 + if (!user_mode_novm(regs)) {
21264 if (fixup_exception(regs))
21265 goto exit;
21266
21267 tsk->thread.error_code = error_code;
21268 tsk->thread.trap_nr = X86_TRAP_GP;
21269 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
21270 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
21271 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
21272 +
21273 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21274 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
21275 + die("PAX: suspicious general protection fault", regs, error_code);
21276 + else
21277 +#endif
21278 +
21279 die("general protection fault", regs, error_code);
21280 + }
21281 goto exit;
21282 }
21283
21284 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21285 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
21286 + struct mm_struct *mm = tsk->mm;
21287 + unsigned long limit;
21288 +
21289 + down_write(&mm->mmap_sem);
21290 + limit = mm->context.user_cs_limit;
21291 + if (limit < TASK_SIZE) {
21292 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
21293 + up_write(&mm->mmap_sem);
21294 + return;
21295 + }
21296 + up_write(&mm->mmap_sem);
21297 + }
21298 +#endif
21299 +
21300 tsk->thread.error_code = error_code;
21301 tsk->thread.trap_nr = X86_TRAP_GP;
21302
21303 @@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21304 /* It's safe to allow irq's after DR6 has been saved */
21305 preempt_conditional_sti(regs);
21306
21307 - if (regs->flags & X86_VM_MASK) {
21308 + if (v8086_mode(regs)) {
21309 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
21310 X86_TRAP_DB);
21311 preempt_conditional_cli(regs);
21312 @@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21313 * We already checked v86 mode above, so we can check for kernel mode
21314 * by just checking the CPL of CS.
21315 */
21316 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
21317 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21318 tsk->thread.debugreg6 &= ~DR_STEP;
21319 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21320 regs->flags &= ~X86_EFLAGS_TF;
21321 @@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21322 return;
21323 conditional_sti(regs);
21324
21325 - if (!user_mode_vm(regs))
21326 + if (!user_mode(regs))
21327 {
21328 if (!fixup_exception(regs)) {
21329 task->thread.error_code = error_code;
21330 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21331 index aafa555..a04691a 100644
21332 --- a/arch/x86/kernel/uprobes.c
21333 +++ b/arch/x86/kernel/uprobes.c
21334 @@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21335 int ret = NOTIFY_DONE;
21336
21337 /* We are only interested in userspace traps */
21338 - if (regs && !user_mode_vm(regs))
21339 + if (regs && !user_mode(regs))
21340 return NOTIFY_DONE;
21341
21342 switch (val) {
21343 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21344 index b9242ba..50c5edd 100644
21345 --- a/arch/x86/kernel/verify_cpu.S
21346 +++ b/arch/x86/kernel/verify_cpu.S
21347 @@ -20,6 +20,7 @@
21348 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21349 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21350 * arch/x86/kernel/head_32.S: processor startup
21351 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21352 *
21353 * verify_cpu, returns the status of longmode and SSE in register %eax.
21354 * 0: Success 1: Failure
21355 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21356 index 5c9687b..5f857d3 100644
21357 --- a/arch/x86/kernel/vm86_32.c
21358 +++ b/arch/x86/kernel/vm86_32.c
21359 @@ -43,6 +43,7 @@
21360 #include <linux/ptrace.h>
21361 #include <linux/audit.h>
21362 #include <linux/stddef.h>
21363 +#include <linux/grsecurity.h>
21364
21365 #include <asm/uaccess.h>
21366 #include <asm/io.h>
21367 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21368 do_exit(SIGSEGV);
21369 }
21370
21371 - tss = &per_cpu(init_tss, get_cpu());
21372 + tss = init_tss + get_cpu();
21373 current->thread.sp0 = current->thread.saved_sp0;
21374 current->thread.sysenter_cs = __KERNEL_CS;
21375 load_sp0(tss, &current->thread);
21376 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21377 struct task_struct *tsk;
21378 int tmp, ret = -EPERM;
21379
21380 +#ifdef CONFIG_GRKERNSEC_VM86
21381 + if (!capable(CAP_SYS_RAWIO)) {
21382 + gr_handle_vm86();
21383 + goto out;
21384 + }
21385 +#endif
21386 +
21387 tsk = current;
21388 if (tsk->thread.saved_sp0)
21389 goto out;
21390 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21391 int tmp, ret;
21392 struct vm86plus_struct __user *v86;
21393
21394 +#ifdef CONFIG_GRKERNSEC_VM86
21395 + if (!capable(CAP_SYS_RAWIO)) {
21396 + gr_handle_vm86();
21397 + ret = -EPERM;
21398 + goto out;
21399 + }
21400 +#endif
21401 +
21402 tsk = current;
21403 switch (cmd) {
21404 case VM86_REQUEST_IRQ:
21405 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21406 tsk->thread.saved_fs = info->regs32->fs;
21407 tsk->thread.saved_gs = get_user_gs(info->regs32);
21408
21409 - tss = &per_cpu(init_tss, get_cpu());
21410 + tss = init_tss + get_cpu();
21411 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21412 if (cpu_has_sep)
21413 tsk->thread.sysenter_cs = 0;
21414 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21415 goto cannot_handle;
21416 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21417 goto cannot_handle;
21418 - intr_ptr = (unsigned long __user *) (i << 2);
21419 + intr_ptr = (__force unsigned long __user *) (i << 2);
21420 if (get_user(segoffs, intr_ptr))
21421 goto cannot_handle;
21422 if ((segoffs >> 16) == BIOSSEG)
21423 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21424 index 22a1530..8fbaaad 100644
21425 --- a/arch/x86/kernel/vmlinux.lds.S
21426 +++ b/arch/x86/kernel/vmlinux.lds.S
21427 @@ -26,6 +26,13 @@
21428 #include <asm/page_types.h>
21429 #include <asm/cache.h>
21430 #include <asm/boot.h>
21431 +#include <asm/segment.h>
21432 +
21433 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21434 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21435 +#else
21436 +#define __KERNEL_TEXT_OFFSET 0
21437 +#endif
21438
21439 #undef i386 /* in case the preprocessor is a 32bit one */
21440
21441 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21442
21443 PHDRS {
21444 text PT_LOAD FLAGS(5); /* R_E */
21445 +#ifdef CONFIG_X86_32
21446 + module PT_LOAD FLAGS(5); /* R_E */
21447 +#endif
21448 +#ifdef CONFIG_XEN
21449 + rodata PT_LOAD FLAGS(5); /* R_E */
21450 +#else
21451 + rodata PT_LOAD FLAGS(4); /* R__ */
21452 +#endif
21453 data PT_LOAD FLAGS(6); /* RW_ */
21454 -#ifdef CONFIG_X86_64
21455 + init.begin PT_LOAD FLAGS(6); /* RW_ */
21456 #ifdef CONFIG_SMP
21457 percpu PT_LOAD FLAGS(6); /* RW_ */
21458 #endif
21459 + text.init PT_LOAD FLAGS(5); /* R_E */
21460 + text.exit PT_LOAD FLAGS(5); /* R_E */
21461 init PT_LOAD FLAGS(7); /* RWE */
21462 -#endif
21463 note PT_NOTE FLAGS(0); /* ___ */
21464 }
21465
21466 SECTIONS
21467 {
21468 #ifdef CONFIG_X86_32
21469 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21470 - phys_startup_32 = startup_32 - LOAD_OFFSET;
21471 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21472 #else
21473 - . = __START_KERNEL;
21474 - phys_startup_64 = startup_64 - LOAD_OFFSET;
21475 + . = __START_KERNEL;
21476 #endif
21477
21478 /* Text and read-only data */
21479 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
21480 - _text = .;
21481 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21482 /* bootstrapping code */
21483 +#ifdef CONFIG_X86_32
21484 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21485 +#else
21486 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21487 +#endif
21488 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21489 + _text = .;
21490 HEAD_TEXT
21491 #ifdef CONFIG_X86_32
21492 . = ALIGN(PAGE_SIZE);
21493 @@ -108,13 +128,48 @@ SECTIONS
21494 IRQENTRY_TEXT
21495 *(.fixup)
21496 *(.gnu.warning)
21497 - /* End of text section */
21498 - _etext = .;
21499 } :text = 0x9090
21500
21501 - NOTES :text :note
21502 + . += __KERNEL_TEXT_OFFSET;
21503
21504 - EXCEPTION_TABLE(16) :text = 0x9090
21505 +#ifdef CONFIG_X86_32
21506 + . = ALIGN(PAGE_SIZE);
21507 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21508 +
21509 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21510 + MODULES_EXEC_VADDR = .;
21511 + BYTE(0)
21512 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21513 + . = ALIGN(HPAGE_SIZE) - 1;
21514 + MODULES_EXEC_END = .;
21515 +#endif
21516 +
21517 + } :module
21518 +#endif
21519 +
21520 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21521 + /* End of text section */
21522 + BYTE(0)
21523 + _etext = . - __KERNEL_TEXT_OFFSET;
21524 + }
21525 +
21526 +#ifdef CONFIG_X86_32
21527 + . = ALIGN(PAGE_SIZE);
21528 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21529 + *(.idt)
21530 + . = ALIGN(PAGE_SIZE);
21531 + *(.empty_zero_page)
21532 + *(.initial_pg_fixmap)
21533 + *(.initial_pg_pmd)
21534 + *(.initial_page_table)
21535 + *(.swapper_pg_dir)
21536 + } :rodata
21537 +#endif
21538 +
21539 + . = ALIGN(PAGE_SIZE);
21540 + NOTES :rodata :note
21541 +
21542 + EXCEPTION_TABLE(16) :rodata
21543
21544 #if defined(CONFIG_DEBUG_RODATA)
21545 /* .text should occupy whole number of pages */
21546 @@ -126,16 +181,20 @@ SECTIONS
21547
21548 /* Data */
21549 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21550 +
21551 +#ifdef CONFIG_PAX_KERNEXEC
21552 + . = ALIGN(HPAGE_SIZE);
21553 +#else
21554 + . = ALIGN(PAGE_SIZE);
21555 +#endif
21556 +
21557 /* Start of data section */
21558 _sdata = .;
21559
21560 /* init_task */
21561 INIT_TASK_DATA(THREAD_SIZE)
21562
21563 -#ifdef CONFIG_X86_32
21564 - /* 32 bit has nosave before _edata */
21565 NOSAVE_DATA
21566 -#endif
21567
21568 PAGE_ALIGNED_DATA(PAGE_SIZE)
21569
21570 @@ -176,12 +235,19 @@ SECTIONS
21571 #endif /* CONFIG_X86_64 */
21572
21573 /* Init code and data - will be freed after init */
21574 - . = ALIGN(PAGE_SIZE);
21575 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21576 + BYTE(0)
21577 +
21578 +#ifdef CONFIG_PAX_KERNEXEC
21579 + . = ALIGN(HPAGE_SIZE);
21580 +#else
21581 + . = ALIGN(PAGE_SIZE);
21582 +#endif
21583 +
21584 __init_begin = .; /* paired with __init_end */
21585 - }
21586 + } :init.begin
21587
21588 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21589 +#ifdef CONFIG_SMP
21590 /*
21591 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21592 * output PHDR, so the next output section - .init.text - should
21593 @@ -190,12 +256,27 @@ SECTIONS
21594 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21595 #endif
21596
21597 - INIT_TEXT_SECTION(PAGE_SIZE)
21598 -#ifdef CONFIG_X86_64
21599 - :init
21600 -#endif
21601 + . = ALIGN(PAGE_SIZE);
21602 + init_begin = .;
21603 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21604 + VMLINUX_SYMBOL(_sinittext) = .;
21605 + INIT_TEXT
21606 + VMLINUX_SYMBOL(_einittext) = .;
21607 + . = ALIGN(PAGE_SIZE);
21608 + } :text.init
21609
21610 - INIT_DATA_SECTION(16)
21611 + /*
21612 + * .exit.text is discard at runtime, not link time, to deal with
21613 + * references from .altinstructions and .eh_frame
21614 + */
21615 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21616 + EXIT_TEXT
21617 + . = ALIGN(16);
21618 + } :text.exit
21619 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21620 +
21621 + . = ALIGN(PAGE_SIZE);
21622 + INIT_DATA_SECTION(16) :init
21623
21624 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21625 __x86_cpu_dev_start = .;
21626 @@ -257,19 +338,12 @@ SECTIONS
21627 }
21628
21629 . = ALIGN(8);
21630 - /*
21631 - * .exit.text is discard at runtime, not link time, to deal with
21632 - * references from .altinstructions and .eh_frame
21633 - */
21634 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21635 - EXIT_TEXT
21636 - }
21637
21638 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21639 EXIT_DATA
21640 }
21641
21642 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21643 +#ifndef CONFIG_SMP
21644 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21645 #endif
21646
21647 @@ -288,16 +362,10 @@ SECTIONS
21648 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21649 __smp_locks = .;
21650 *(.smp_locks)
21651 - . = ALIGN(PAGE_SIZE);
21652 __smp_locks_end = .;
21653 + . = ALIGN(PAGE_SIZE);
21654 }
21655
21656 -#ifdef CONFIG_X86_64
21657 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21658 - NOSAVE_DATA
21659 - }
21660 -#endif
21661 -
21662 /* BSS */
21663 . = ALIGN(PAGE_SIZE);
21664 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21665 @@ -313,6 +381,7 @@ SECTIONS
21666 __brk_base = .;
21667 . += 64 * 1024; /* 64k alignment slop space */
21668 *(.brk_reservation) /* areas brk users have reserved */
21669 + . = ALIGN(HPAGE_SIZE);
21670 __brk_limit = .;
21671 }
21672
21673 @@ -339,13 +408,12 @@ SECTIONS
21674 * for the boot processor.
21675 */
21676 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21677 -INIT_PER_CPU(gdt_page);
21678 INIT_PER_CPU(irq_stack_union);
21679
21680 /*
21681 * Build-time check on the image size:
21682 */
21683 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21684 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21685 "kernel image bigger than KERNEL_IMAGE_SIZE");
21686
21687 #ifdef CONFIG_SMP
21688 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
21689 index 992f890..0ab1aae 100644
21690 --- a/arch/x86/kernel/vsmp_64.c
21691 +++ b/arch/x86/kernel/vsmp_64.c
21692 @@ -114,7 +114,7 @@ static void __init set_vsmp_pv_ops(void)
21693 pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
21694 pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
21695 pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
21696 - pv_init_ops.patch = vsmp_patch;
21697 + *(void **)&pv_init_ops.patch = vsmp_patch;
21698 ctl &= ~(1 << 4);
21699 }
21700 writel(ctl, address + 4);
21701 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
21702 static void vsmp_apic_post_init(void)
21703 {
21704 /* need to update phys_pkg_id */
21705 - apic->phys_pkg_id = apicid_phys_pkg_id;
21706 - apic->vector_allocation_domain = fill_vector_allocation_domain;
21707 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
21708 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
21709 }
21710
21711 void __init vsmp_init(void)
21712 @@ -227,7 +227,7 @@ void __init vsmp_init(void)
21713 if (!is_vsmp_box())
21714 return;
21715
21716 - x86_platform.apic_post_init = vsmp_apic_post_init;
21717 + *(void **)&x86_platform.apic_post_init = vsmp_apic_post_init;
21718
21719 vsmp_cap_cpus();
21720
21721 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21722 index 3a3e8c9..1af9465 100644
21723 --- a/arch/x86/kernel/vsyscall_64.c
21724 +++ b/arch/x86/kernel/vsyscall_64.c
21725 @@ -56,15 +56,13 @@
21726 DEFINE_VVAR(int, vgetcpu_mode);
21727 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21728
21729 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21730 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21731
21732 static int __init vsyscall_setup(char *str)
21733 {
21734 if (str) {
21735 if (!strcmp("emulate", str))
21736 vsyscall_mode = EMULATE;
21737 - else if (!strcmp("native", str))
21738 - vsyscall_mode = NATIVE;
21739 else if (!strcmp("none", str))
21740 vsyscall_mode = NONE;
21741 else
21742 @@ -315,8 +313,7 @@ done:
21743 return true;
21744
21745 sigsegv:
21746 - force_sig(SIGSEGV, current);
21747 - return true;
21748 + do_group_exit(SIGKILL);
21749 }
21750
21751 /*
21752 @@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21753 extern char __vvar_page;
21754 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21755
21756 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21757 - vsyscall_mode == NATIVE
21758 - ? PAGE_KERNEL_VSYSCALL
21759 - : PAGE_KERNEL_VVAR);
21760 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21761 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21762 (unsigned long)VSYSCALL_START);
21763
21764 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21765 index 1330dd1..d220b99 100644
21766 --- a/arch/x86/kernel/x8664_ksyms_64.c
21767 +++ b/arch/x86/kernel/x8664_ksyms_64.c
21768 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21769 EXPORT_SYMBOL(copy_user_generic_unrolled);
21770 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21771 EXPORT_SYMBOL(__copy_user_nocache);
21772 -EXPORT_SYMBOL(_copy_from_user);
21773 -EXPORT_SYMBOL(_copy_to_user);
21774
21775 EXPORT_SYMBOL(copy_page);
21776 EXPORT_SYMBOL(clear_page);
21777 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21778 index ada87a3..afea76d 100644
21779 --- a/arch/x86/kernel/xsave.c
21780 +++ b/arch/x86/kernel/xsave.c
21781 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21782 {
21783 int err;
21784
21785 + buf = (struct xsave_struct __user *)____m(buf);
21786 if (use_xsave())
21787 err = xsave_user(buf);
21788 else if (use_fxsr())
21789 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21790 */
21791 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21792 {
21793 + buf = (void __user *)____m(buf);
21794 if (use_xsave()) {
21795 if ((unsigned long)buf % 64 || fx_only) {
21796 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21797 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21798 index ec79e77..420f5cc 100644
21799 --- a/arch/x86/kvm/cpuid.c
21800 +++ b/arch/x86/kvm/cpuid.c
21801 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21802 struct kvm_cpuid2 *cpuid,
21803 struct kvm_cpuid_entry2 __user *entries)
21804 {
21805 - int r;
21806 + int r, i;
21807
21808 r = -E2BIG;
21809 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21810 goto out;
21811 r = -EFAULT;
21812 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21813 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21814 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21815 goto out;
21816 + for (i = 0; i < cpuid->nent; ++i) {
21817 + struct kvm_cpuid_entry2 cpuid_entry;
21818 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21819 + goto out;
21820 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
21821 + }
21822 vcpu->arch.cpuid_nent = cpuid->nent;
21823 kvm_apic_set_version(vcpu);
21824 kvm_x86_ops->cpuid_update(vcpu);
21825 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21826 struct kvm_cpuid2 *cpuid,
21827 struct kvm_cpuid_entry2 __user *entries)
21828 {
21829 - int r;
21830 + int r, i;
21831
21832 r = -E2BIG;
21833 if (cpuid->nent < vcpu->arch.cpuid_nent)
21834 goto out;
21835 r = -EFAULT;
21836 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21837 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21838 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21839 goto out;
21840 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21841 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21842 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21843 + goto out;
21844 + }
21845 return 0;
21846
21847 out:
21848 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21849 index bba39bf..296540a 100644
21850 --- a/arch/x86/kvm/emulate.c
21851 +++ b/arch/x86/kvm/emulate.c
21852 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21853
21854 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21855 do { \
21856 + unsigned long _tmp; \
21857 __asm__ __volatile__ ( \
21858 _PRE_EFLAGS("0", "4", "2") \
21859 _op _suffix " %"_x"3,%1; " \
21860 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21861 /* Raw emulation: instruction has two explicit operands. */
21862 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21863 do { \
21864 - unsigned long _tmp; \
21865 - \
21866 switch ((ctxt)->dst.bytes) { \
21867 case 2: \
21868 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21869 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21870
21871 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21872 do { \
21873 - unsigned long _tmp; \
21874 switch ((ctxt)->dst.bytes) { \
21875 case 1: \
21876 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21877 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21878 index 43e9fad..3b7c059 100644
21879 --- a/arch/x86/kvm/lapic.c
21880 +++ b/arch/x86/kvm/lapic.c
21881 @@ -55,7 +55,7 @@
21882 #define APIC_BUS_CYCLE_NS 1
21883
21884 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21885 -#define apic_debug(fmt, arg...)
21886 +#define apic_debug(fmt, arg...) do {} while (0)
21887
21888 #define APIC_LVT_NUM 6
21889 /* 14 is the version for Xeon and Pentium 8.4.8*/
21890 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21891 index 714e2c0..3f7a086 100644
21892 --- a/arch/x86/kvm/paging_tmpl.h
21893 +++ b/arch/x86/kvm/paging_tmpl.h
21894 @@ -208,7 +208,7 @@ retry_walk:
21895 if (unlikely(kvm_is_error_hva(host_addr)))
21896 goto error;
21897
21898 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21899 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21900 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21901 goto error;
21902 walker->ptep_user[walker->level - 1] = ptep_user;
21903 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21904 index d017df3..61ae42e 100644
21905 --- a/arch/x86/kvm/svm.c
21906 +++ b/arch/x86/kvm/svm.c
21907 @@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21908 int cpu = raw_smp_processor_id();
21909
21910 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21911 +
21912 + pax_open_kernel();
21913 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21914 + pax_close_kernel();
21915 +
21916 load_TR_desc();
21917 }
21918
21919 @@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21920 #endif
21921 #endif
21922
21923 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21924 + __set_fs(current_thread_info()->addr_limit);
21925 +#endif
21926 +
21927 reload_tss(vcpu);
21928
21929 local_irq_disable();
21930 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21931 index f858159..4ab7dba 100644
21932 --- a/arch/x86/kvm/vmx.c
21933 +++ b/arch/x86/kvm/vmx.c
21934 @@ -1332,7 +1332,11 @@ static void reload_tss(void)
21935 struct desc_struct *descs;
21936
21937 descs = (void *)gdt->address;
21938 +
21939 + pax_open_kernel();
21940 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21941 + pax_close_kernel();
21942 +
21943 load_TR_desc();
21944 }
21945
21946 @@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21947 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
21948 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
21949
21950 +#ifdef CONFIG_PAX_PER_CPU_PGD
21951 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21952 +#endif
21953 +
21954 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21955 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21956 vmx->loaded_vmcs->cpu = cpu;
21957 @@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
21958 if (!cpu_has_vmx_flexpriority())
21959 flexpriority_enabled = 0;
21960
21961 - if (!cpu_has_vmx_tpr_shadow())
21962 - kvm_x86_ops->update_cr8_intercept = NULL;
21963 + if (!cpu_has_vmx_tpr_shadow()) {
21964 + pax_open_kernel();
21965 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21966 + pax_close_kernel();
21967 + }
21968
21969 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21970 kvm_disable_largepages();
21971 @@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
21972
21973 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
21974 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
21975 +
21976 +#ifndef CONFIG_PAX_PER_CPU_PGD
21977 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21978 +#endif
21979
21980 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
21981 #ifdef CONFIG_X86_64
21982 @@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
21983 native_store_idt(&dt);
21984 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
21985
21986 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
21987 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
21988
21989 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
21990 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
21991 @@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21992 "jmp 2f \n\t"
21993 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
21994 "2: "
21995 +
21996 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21997 + "ljmp %[cs],$3f\n\t"
21998 + "3: "
21999 +#endif
22000 +
22001 /* Save guest registers, load host registers, keep flags */
22002 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
22003 "pop %0 \n\t"
22004 @@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22005 #endif
22006 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
22007 [wordsize]"i"(sizeof(ulong))
22008 +
22009 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22010 + ,[cs]"i"(__KERNEL_CS)
22011 +#endif
22012 +
22013 : "cc", "memory"
22014 #ifdef CONFIG_X86_64
22015 , "rax", "rbx", "rdi", "rsi"
22016 @@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22017 if (debugctlmsr)
22018 update_debugctlmsr(debugctlmsr);
22019
22020 -#ifndef CONFIG_X86_64
22021 +#ifdef CONFIG_X86_32
22022 /*
22023 * The sysexit path does not restore ds/es, so we must set them to
22024 * a reasonable value ourselves.
22025 @@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22026 * may be executed in interrupt context, which saves and restore segments
22027 * around it, nullifying its effect.
22028 */
22029 - loadsegment(ds, __USER_DS);
22030 - loadsegment(es, __USER_DS);
22031 + loadsegment(ds, __KERNEL_DS);
22032 + loadsegment(es, __KERNEL_DS);
22033 + loadsegment(ss, __KERNEL_DS);
22034 +
22035 +#ifdef CONFIG_PAX_KERNEXEC
22036 + loadsegment(fs, __KERNEL_PERCPU);
22037 +#endif
22038 +
22039 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22040 + __set_fs(current_thread_info()->addr_limit);
22041 +#endif
22042 +
22043 #endif
22044
22045 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
22046 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
22047 index 4f76417..93429b5 100644
22048 --- a/arch/x86/kvm/x86.c
22049 +++ b/arch/x86/kvm/x86.c
22050 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
22051 {
22052 struct kvm *kvm = vcpu->kvm;
22053 int lm = is_long_mode(vcpu);
22054 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22055 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22056 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22057 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22058 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
22059 : kvm->arch.xen_hvm_config.blob_size_32;
22060 u32 page_num = data & ~PAGE_MASK;
22061 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
22062 if (n < msr_list.nmsrs)
22063 goto out;
22064 r = -EFAULT;
22065 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
22066 + goto out;
22067 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
22068 num_msrs_to_save * sizeof(u32)))
22069 goto out;
22070 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
22071 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
22072 struct kvm_interrupt *irq)
22073 {
22074 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
22075 + if (irq->irq >= KVM_NR_INTERRUPTS)
22076 return -EINVAL;
22077 if (irqchip_in_kernel(vcpu->kvm))
22078 return -ENXIO;
22079 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
22080 kvm_mmu_set_mmio_spte_mask(mask);
22081 }
22082
22083 -int kvm_arch_init(void *opaque)
22084 +int kvm_arch_init(const void *opaque)
22085 {
22086 int r;
22087 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
22088 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
22089 index 642d880..5dd034e 100644
22090 --- a/arch/x86/lguest/boot.c
22091 +++ b/arch/x86/lguest/boot.c
22092 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
22093
22094 static void set_lguest_basic_apic_ops(void)
22095 {
22096 - apic->read = lguest_apic_read;
22097 - apic->write = lguest_apic_write;
22098 - apic->icr_read = lguest_apic_icr_read;
22099 - apic->icr_write = lguest_apic_icr_write;
22100 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22101 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22102 + *(void **)&apic->read = lguest_apic_read;
22103 + *(void **)&apic->write = lguest_apic_write;
22104 + *(void **)&apic->icr_read = lguest_apic_icr_read;
22105 + *(void **)&apic->icr_write = lguest_apic_icr_write;
22106 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22107 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22108 };
22109 #endif
22110
22111 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
22112 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
22113 * Launcher to reboot us.
22114 */
22115 -static void lguest_restart(char *reason)
22116 +static __noreturn void lguest_restart(char *reason)
22117 {
22118 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
22119 + BUG();
22120 }
22121
22122 /*G:050
22123 @@ -1292,28 +1293,28 @@ __init void lguest_init(void)
22124 pv_irq_ops.safe_halt = lguest_safe_halt;
22125
22126 /* Setup operations */
22127 - pv_init_ops.patch = lguest_patch;
22128 + *(void **)&pv_init_ops.patch = lguest_patch;
22129
22130 /* Intercepts of various CPU instructions */
22131 - pv_cpu_ops.load_gdt = lguest_load_gdt;
22132 - pv_cpu_ops.cpuid = lguest_cpuid;
22133 - pv_cpu_ops.load_idt = lguest_load_idt;
22134 - pv_cpu_ops.iret = lguest_iret;
22135 - pv_cpu_ops.load_sp0 = lguest_load_sp0;
22136 - pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22137 - pv_cpu_ops.set_ldt = lguest_set_ldt;
22138 - pv_cpu_ops.load_tls = lguest_load_tls;
22139 - pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22140 - pv_cpu_ops.clts = lguest_clts;
22141 - pv_cpu_ops.read_cr0 = lguest_read_cr0;
22142 - pv_cpu_ops.write_cr0 = lguest_write_cr0;
22143 - pv_cpu_ops.read_cr4 = lguest_read_cr4;
22144 - pv_cpu_ops.write_cr4 = lguest_write_cr4;
22145 - pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22146 - pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22147 - pv_cpu_ops.wbinvd = lguest_wbinvd;
22148 - pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22149 - pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22150 + *(void **)&pv_cpu_ops.load_gdt = lguest_load_gdt;
22151 + *(void **)&pv_cpu_ops.cpuid = lguest_cpuid;
22152 + *(void **)&pv_cpu_ops.load_idt = lguest_load_idt;
22153 + *(void **)&pv_cpu_ops.iret = lguest_iret;
22154 + *(void **)&pv_cpu_ops.load_sp0 = lguest_load_sp0;
22155 + *(void **)&pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22156 + *(void **)&pv_cpu_ops.set_ldt = lguest_set_ldt;
22157 + *(void **)&pv_cpu_ops.load_tls = lguest_load_tls;
22158 + *(void **)&pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22159 + *(void **)&pv_cpu_ops.clts = lguest_clts;
22160 + *(void **)&pv_cpu_ops.read_cr0 = lguest_read_cr0;
22161 + *(void **)&pv_cpu_ops.write_cr0 = lguest_write_cr0;
22162 + *(void **)&pv_cpu_ops.read_cr4 = lguest_read_cr4;
22163 + *(void **)&pv_cpu_ops.write_cr4 = lguest_write_cr4;
22164 + *(void **)&pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22165 + *(void **)&pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22166 + *(void **)&pv_cpu_ops.wbinvd = lguest_wbinvd;
22167 + *(void **)&pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22168 + *(void **)&pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22169
22170 /* Pagetable management */
22171 pv_mmu_ops.write_cr3 = lguest_write_cr3;
22172 @@ -1341,11 +1342,11 @@ __init void lguest_init(void)
22173 set_lguest_basic_apic_ops();
22174 #endif
22175
22176 - x86_init.resources.memory_setup = lguest_memory_setup;
22177 - x86_init.irqs.intr_init = lguest_init_IRQ;
22178 - x86_init.timers.timer_init = lguest_time_init;
22179 - x86_platform.calibrate_tsc = lguest_tsc_khz;
22180 - x86_platform.get_wallclock = lguest_get_wallclock;
22181 + *(void **)&x86_init.resources.memory_setup = lguest_memory_setup;
22182 + *(void **)&x86_init.irqs.intr_init = lguest_init_IRQ;
22183 + *(void **)&x86_init.timers.timer_init = lguest_time_init;
22184 + *(void **)&x86_platform.calibrate_tsc = lguest_tsc_khz;
22185 + *(void **)&x86_platform.get_wallclock = lguest_get_wallclock;
22186
22187 /*
22188 * Now is a good time to look at the implementations of these functions
22189 @@ -1434,7 +1435,7 @@ __init void lguest_init(void)
22190 * routine.
22191 */
22192 pm_power_off = lguest_power_off;
22193 - machine_ops.restart = lguest_restart;
22194 + *(void **)&machine_ops.restart = lguest_restart;
22195
22196 /*
22197 * Now we're set up, call i386_start_kernel() in head32.c and we proceed
22198 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
22199 index 00933d5..3a64af9 100644
22200 --- a/arch/x86/lib/atomic64_386_32.S
22201 +++ b/arch/x86/lib/atomic64_386_32.S
22202 @@ -48,6 +48,10 @@ BEGIN(read)
22203 movl (v), %eax
22204 movl 4(v), %edx
22205 RET_ENDP
22206 +BEGIN(read_unchecked)
22207 + movl (v), %eax
22208 + movl 4(v), %edx
22209 +RET_ENDP
22210 #undef v
22211
22212 #define v %esi
22213 @@ -55,6 +59,10 @@ BEGIN(set)
22214 movl %ebx, (v)
22215 movl %ecx, 4(v)
22216 RET_ENDP
22217 +BEGIN(set_unchecked)
22218 + movl %ebx, (v)
22219 + movl %ecx, 4(v)
22220 +RET_ENDP
22221 #undef v
22222
22223 #define v %esi
22224 @@ -70,6 +78,20 @@ RET_ENDP
22225 BEGIN(add)
22226 addl %eax, (v)
22227 adcl %edx, 4(v)
22228 +
22229 +#ifdef CONFIG_PAX_REFCOUNT
22230 + jno 0f
22231 + subl %eax, (v)
22232 + sbbl %edx, 4(v)
22233 + int $4
22234 +0:
22235 + _ASM_EXTABLE(0b, 0b)
22236 +#endif
22237 +
22238 +RET_ENDP
22239 +BEGIN(add_unchecked)
22240 + addl %eax, (v)
22241 + adcl %edx, 4(v)
22242 RET_ENDP
22243 #undef v
22244
22245 @@ -77,6 +99,24 @@ RET_ENDP
22246 BEGIN(add_return)
22247 addl (v), %eax
22248 adcl 4(v), %edx
22249 +
22250 +#ifdef CONFIG_PAX_REFCOUNT
22251 + into
22252 +1234:
22253 + _ASM_EXTABLE(1234b, 2f)
22254 +#endif
22255 +
22256 + movl %eax, (v)
22257 + movl %edx, 4(v)
22258 +
22259 +#ifdef CONFIG_PAX_REFCOUNT
22260 +2:
22261 +#endif
22262 +
22263 +RET_ENDP
22264 +BEGIN(add_return_unchecked)
22265 + addl (v), %eax
22266 + adcl 4(v), %edx
22267 movl %eax, (v)
22268 movl %edx, 4(v)
22269 RET_ENDP
22270 @@ -86,6 +126,20 @@ RET_ENDP
22271 BEGIN(sub)
22272 subl %eax, (v)
22273 sbbl %edx, 4(v)
22274 +
22275 +#ifdef CONFIG_PAX_REFCOUNT
22276 + jno 0f
22277 + addl %eax, (v)
22278 + adcl %edx, 4(v)
22279 + int $4
22280 +0:
22281 + _ASM_EXTABLE(0b, 0b)
22282 +#endif
22283 +
22284 +RET_ENDP
22285 +BEGIN(sub_unchecked)
22286 + subl %eax, (v)
22287 + sbbl %edx, 4(v)
22288 RET_ENDP
22289 #undef v
22290
22291 @@ -96,6 +150,27 @@ BEGIN(sub_return)
22292 sbbl $0, %edx
22293 addl (v), %eax
22294 adcl 4(v), %edx
22295 +
22296 +#ifdef CONFIG_PAX_REFCOUNT
22297 + into
22298 +1234:
22299 + _ASM_EXTABLE(1234b, 2f)
22300 +#endif
22301 +
22302 + movl %eax, (v)
22303 + movl %edx, 4(v)
22304 +
22305 +#ifdef CONFIG_PAX_REFCOUNT
22306 +2:
22307 +#endif
22308 +
22309 +RET_ENDP
22310 +BEGIN(sub_return_unchecked)
22311 + negl %edx
22312 + negl %eax
22313 + sbbl $0, %edx
22314 + addl (v), %eax
22315 + adcl 4(v), %edx
22316 movl %eax, (v)
22317 movl %edx, 4(v)
22318 RET_ENDP
22319 @@ -105,6 +180,20 @@ RET_ENDP
22320 BEGIN(inc)
22321 addl $1, (v)
22322 adcl $0, 4(v)
22323 +
22324 +#ifdef CONFIG_PAX_REFCOUNT
22325 + jno 0f
22326 + subl $1, (v)
22327 + sbbl $0, 4(v)
22328 + int $4
22329 +0:
22330 + _ASM_EXTABLE(0b, 0b)
22331 +#endif
22332 +
22333 +RET_ENDP
22334 +BEGIN(inc_unchecked)
22335 + addl $1, (v)
22336 + adcl $0, 4(v)
22337 RET_ENDP
22338 #undef v
22339
22340 @@ -114,6 +203,26 @@ BEGIN(inc_return)
22341 movl 4(v), %edx
22342 addl $1, %eax
22343 adcl $0, %edx
22344 +
22345 +#ifdef CONFIG_PAX_REFCOUNT
22346 + into
22347 +1234:
22348 + _ASM_EXTABLE(1234b, 2f)
22349 +#endif
22350 +
22351 + movl %eax, (v)
22352 + movl %edx, 4(v)
22353 +
22354 +#ifdef CONFIG_PAX_REFCOUNT
22355 +2:
22356 +#endif
22357 +
22358 +RET_ENDP
22359 +BEGIN(inc_return_unchecked)
22360 + movl (v), %eax
22361 + movl 4(v), %edx
22362 + addl $1, %eax
22363 + adcl $0, %edx
22364 movl %eax, (v)
22365 movl %edx, 4(v)
22366 RET_ENDP
22367 @@ -123,6 +232,20 @@ RET_ENDP
22368 BEGIN(dec)
22369 subl $1, (v)
22370 sbbl $0, 4(v)
22371 +
22372 +#ifdef CONFIG_PAX_REFCOUNT
22373 + jno 0f
22374 + addl $1, (v)
22375 + adcl $0, 4(v)
22376 + int $4
22377 +0:
22378 + _ASM_EXTABLE(0b, 0b)
22379 +#endif
22380 +
22381 +RET_ENDP
22382 +BEGIN(dec_unchecked)
22383 + subl $1, (v)
22384 + sbbl $0, 4(v)
22385 RET_ENDP
22386 #undef v
22387
22388 @@ -132,6 +255,26 @@ BEGIN(dec_return)
22389 movl 4(v), %edx
22390 subl $1, %eax
22391 sbbl $0, %edx
22392 +
22393 +#ifdef CONFIG_PAX_REFCOUNT
22394 + into
22395 +1234:
22396 + _ASM_EXTABLE(1234b, 2f)
22397 +#endif
22398 +
22399 + movl %eax, (v)
22400 + movl %edx, 4(v)
22401 +
22402 +#ifdef CONFIG_PAX_REFCOUNT
22403 +2:
22404 +#endif
22405 +
22406 +RET_ENDP
22407 +BEGIN(dec_return_unchecked)
22408 + movl (v), %eax
22409 + movl 4(v), %edx
22410 + subl $1, %eax
22411 + sbbl $0, %edx
22412 movl %eax, (v)
22413 movl %edx, 4(v)
22414 RET_ENDP
22415 @@ -143,6 +286,13 @@ BEGIN(add_unless)
22416 adcl %edx, %edi
22417 addl (v), %eax
22418 adcl 4(v), %edx
22419 +
22420 +#ifdef CONFIG_PAX_REFCOUNT
22421 + into
22422 +1234:
22423 + _ASM_EXTABLE(1234b, 2f)
22424 +#endif
22425 +
22426 cmpl %eax, %ecx
22427 je 3f
22428 1:
22429 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22430 1:
22431 addl $1, %eax
22432 adcl $0, %edx
22433 +
22434 +#ifdef CONFIG_PAX_REFCOUNT
22435 + into
22436 +1234:
22437 + _ASM_EXTABLE(1234b, 2f)
22438 +#endif
22439 +
22440 movl %eax, (v)
22441 movl %edx, 4(v)
22442 movl $1, %eax
22443 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22444 movl 4(v), %edx
22445 subl $1, %eax
22446 sbbl $0, %edx
22447 +
22448 +#ifdef CONFIG_PAX_REFCOUNT
22449 + into
22450 +1234:
22451 + _ASM_EXTABLE(1234b, 1f)
22452 +#endif
22453 +
22454 js 1f
22455 movl %eax, (v)
22456 movl %edx, 4(v)
22457 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22458 index f5cc9eb..51fa319 100644
22459 --- a/arch/x86/lib/atomic64_cx8_32.S
22460 +++ b/arch/x86/lib/atomic64_cx8_32.S
22461 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22462 CFI_STARTPROC
22463
22464 read64 %ecx
22465 + pax_force_retaddr
22466 ret
22467 CFI_ENDPROC
22468 ENDPROC(atomic64_read_cx8)
22469
22470 +ENTRY(atomic64_read_unchecked_cx8)
22471 + CFI_STARTPROC
22472 +
22473 + read64 %ecx
22474 + pax_force_retaddr
22475 + ret
22476 + CFI_ENDPROC
22477 +ENDPROC(atomic64_read_unchecked_cx8)
22478 +
22479 ENTRY(atomic64_set_cx8)
22480 CFI_STARTPROC
22481
22482 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22483 cmpxchg8b (%esi)
22484 jne 1b
22485
22486 + pax_force_retaddr
22487 ret
22488 CFI_ENDPROC
22489 ENDPROC(atomic64_set_cx8)
22490
22491 +ENTRY(atomic64_set_unchecked_cx8)
22492 + CFI_STARTPROC
22493 +
22494 +1:
22495 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
22496 + * are atomic on 586 and newer */
22497 + cmpxchg8b (%esi)
22498 + jne 1b
22499 +
22500 + pax_force_retaddr
22501 + ret
22502 + CFI_ENDPROC
22503 +ENDPROC(atomic64_set_unchecked_cx8)
22504 +
22505 ENTRY(atomic64_xchg_cx8)
22506 CFI_STARTPROC
22507
22508 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22509 cmpxchg8b (%esi)
22510 jne 1b
22511
22512 + pax_force_retaddr
22513 ret
22514 CFI_ENDPROC
22515 ENDPROC(atomic64_xchg_cx8)
22516
22517 -.macro addsub_return func ins insc
22518 -ENTRY(atomic64_\func\()_return_cx8)
22519 +.macro addsub_return func ins insc unchecked=""
22520 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22521 CFI_STARTPROC
22522 SAVE ebp
22523 SAVE ebx
22524 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22525 movl %edx, %ecx
22526 \ins\()l %esi, %ebx
22527 \insc\()l %edi, %ecx
22528 +
22529 +.ifb \unchecked
22530 +#ifdef CONFIG_PAX_REFCOUNT
22531 + into
22532 +2:
22533 + _ASM_EXTABLE(2b, 3f)
22534 +#endif
22535 +.endif
22536 +
22537 LOCK_PREFIX
22538 cmpxchg8b (%ebp)
22539 jne 1b
22540 -
22541 -10:
22542 movl %ebx, %eax
22543 movl %ecx, %edx
22544 +
22545 +.ifb \unchecked
22546 +#ifdef CONFIG_PAX_REFCOUNT
22547 +3:
22548 +#endif
22549 +.endif
22550 +
22551 RESTORE edi
22552 RESTORE esi
22553 RESTORE ebx
22554 RESTORE ebp
22555 + pax_force_retaddr
22556 ret
22557 CFI_ENDPROC
22558 -ENDPROC(atomic64_\func\()_return_cx8)
22559 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22560 .endm
22561
22562 addsub_return add add adc
22563 addsub_return sub sub sbb
22564 +addsub_return add add adc _unchecked
22565 +addsub_return sub sub sbb _unchecked
22566
22567 -.macro incdec_return func ins insc
22568 -ENTRY(atomic64_\func\()_return_cx8)
22569 +.macro incdec_return func ins insc unchecked=""
22570 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22571 CFI_STARTPROC
22572 SAVE ebx
22573
22574 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22575 movl %edx, %ecx
22576 \ins\()l $1, %ebx
22577 \insc\()l $0, %ecx
22578 +
22579 +.ifb \unchecked
22580 +#ifdef CONFIG_PAX_REFCOUNT
22581 + into
22582 +2:
22583 + _ASM_EXTABLE(2b, 3f)
22584 +#endif
22585 +.endif
22586 +
22587 LOCK_PREFIX
22588 cmpxchg8b (%esi)
22589 jne 1b
22590
22591 -10:
22592 movl %ebx, %eax
22593 movl %ecx, %edx
22594 +
22595 +.ifb \unchecked
22596 +#ifdef CONFIG_PAX_REFCOUNT
22597 +3:
22598 +#endif
22599 +.endif
22600 +
22601 RESTORE ebx
22602 + pax_force_retaddr
22603 ret
22604 CFI_ENDPROC
22605 -ENDPROC(atomic64_\func\()_return_cx8)
22606 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22607 .endm
22608
22609 incdec_return inc add adc
22610 incdec_return dec sub sbb
22611 +incdec_return inc add adc _unchecked
22612 +incdec_return dec sub sbb _unchecked
22613
22614 ENTRY(atomic64_dec_if_positive_cx8)
22615 CFI_STARTPROC
22616 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22617 movl %edx, %ecx
22618 subl $1, %ebx
22619 sbb $0, %ecx
22620 +
22621 +#ifdef CONFIG_PAX_REFCOUNT
22622 + into
22623 +1234:
22624 + _ASM_EXTABLE(1234b, 2f)
22625 +#endif
22626 +
22627 js 2f
22628 LOCK_PREFIX
22629 cmpxchg8b (%esi)
22630 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22631 movl %ebx, %eax
22632 movl %ecx, %edx
22633 RESTORE ebx
22634 + pax_force_retaddr
22635 ret
22636 CFI_ENDPROC
22637 ENDPROC(atomic64_dec_if_positive_cx8)
22638 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22639 movl %edx, %ecx
22640 addl %ebp, %ebx
22641 adcl %edi, %ecx
22642 +
22643 +#ifdef CONFIG_PAX_REFCOUNT
22644 + into
22645 +1234:
22646 + _ASM_EXTABLE(1234b, 3f)
22647 +#endif
22648 +
22649 LOCK_PREFIX
22650 cmpxchg8b (%esi)
22651 jne 1b
22652 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22653 CFI_ADJUST_CFA_OFFSET -8
22654 RESTORE ebx
22655 RESTORE ebp
22656 + pax_force_retaddr
22657 ret
22658 4:
22659 cmpl %edx, 4(%esp)
22660 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22661 xorl %ecx, %ecx
22662 addl $1, %ebx
22663 adcl %edx, %ecx
22664 +
22665 +#ifdef CONFIG_PAX_REFCOUNT
22666 + into
22667 +1234:
22668 + _ASM_EXTABLE(1234b, 3f)
22669 +#endif
22670 +
22671 LOCK_PREFIX
22672 cmpxchg8b (%esi)
22673 jne 1b
22674 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22675 movl $1, %eax
22676 3:
22677 RESTORE ebx
22678 + pax_force_retaddr
22679 ret
22680 CFI_ENDPROC
22681 ENDPROC(atomic64_inc_not_zero_cx8)
22682 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22683 index 2af5df3..62b1a5a 100644
22684 --- a/arch/x86/lib/checksum_32.S
22685 +++ b/arch/x86/lib/checksum_32.S
22686 @@ -29,7 +29,8 @@
22687 #include <asm/dwarf2.h>
22688 #include <asm/errno.h>
22689 #include <asm/asm.h>
22690 -
22691 +#include <asm/segment.h>
22692 +
22693 /*
22694 * computes a partial checksum, e.g. for TCP/UDP fragments
22695 */
22696 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22697
22698 #define ARGBASE 16
22699 #define FP 12
22700 -
22701 -ENTRY(csum_partial_copy_generic)
22702 +
22703 +ENTRY(csum_partial_copy_generic_to_user)
22704 CFI_STARTPROC
22705 +
22706 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22707 + pushl_cfi %gs
22708 + popl_cfi %es
22709 + jmp csum_partial_copy_generic
22710 +#endif
22711 +
22712 +ENTRY(csum_partial_copy_generic_from_user)
22713 +
22714 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22715 + pushl_cfi %gs
22716 + popl_cfi %ds
22717 +#endif
22718 +
22719 +ENTRY(csum_partial_copy_generic)
22720 subl $4,%esp
22721 CFI_ADJUST_CFA_OFFSET 4
22722 pushl_cfi %edi
22723 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22724 jmp 4f
22725 SRC(1: movw (%esi), %bx )
22726 addl $2, %esi
22727 -DST( movw %bx, (%edi) )
22728 +DST( movw %bx, %es:(%edi) )
22729 addl $2, %edi
22730 addw %bx, %ax
22731 adcl $0, %eax
22732 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22733 SRC(1: movl (%esi), %ebx )
22734 SRC( movl 4(%esi), %edx )
22735 adcl %ebx, %eax
22736 -DST( movl %ebx, (%edi) )
22737 +DST( movl %ebx, %es:(%edi) )
22738 adcl %edx, %eax
22739 -DST( movl %edx, 4(%edi) )
22740 +DST( movl %edx, %es:4(%edi) )
22741
22742 SRC( movl 8(%esi), %ebx )
22743 SRC( movl 12(%esi), %edx )
22744 adcl %ebx, %eax
22745 -DST( movl %ebx, 8(%edi) )
22746 +DST( movl %ebx, %es:8(%edi) )
22747 adcl %edx, %eax
22748 -DST( movl %edx, 12(%edi) )
22749 +DST( movl %edx, %es:12(%edi) )
22750
22751 SRC( movl 16(%esi), %ebx )
22752 SRC( movl 20(%esi), %edx )
22753 adcl %ebx, %eax
22754 -DST( movl %ebx, 16(%edi) )
22755 +DST( movl %ebx, %es:16(%edi) )
22756 adcl %edx, %eax
22757 -DST( movl %edx, 20(%edi) )
22758 +DST( movl %edx, %es:20(%edi) )
22759
22760 SRC( movl 24(%esi), %ebx )
22761 SRC( movl 28(%esi), %edx )
22762 adcl %ebx, %eax
22763 -DST( movl %ebx, 24(%edi) )
22764 +DST( movl %ebx, %es:24(%edi) )
22765 adcl %edx, %eax
22766 -DST( movl %edx, 28(%edi) )
22767 +DST( movl %edx, %es:28(%edi) )
22768
22769 lea 32(%esi), %esi
22770 lea 32(%edi), %edi
22771 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22772 shrl $2, %edx # This clears CF
22773 SRC(3: movl (%esi), %ebx )
22774 adcl %ebx, %eax
22775 -DST( movl %ebx, (%edi) )
22776 +DST( movl %ebx, %es:(%edi) )
22777 lea 4(%esi), %esi
22778 lea 4(%edi), %edi
22779 dec %edx
22780 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22781 jb 5f
22782 SRC( movw (%esi), %cx )
22783 leal 2(%esi), %esi
22784 -DST( movw %cx, (%edi) )
22785 +DST( movw %cx, %es:(%edi) )
22786 leal 2(%edi), %edi
22787 je 6f
22788 shll $16,%ecx
22789 SRC(5: movb (%esi), %cl )
22790 -DST( movb %cl, (%edi) )
22791 +DST( movb %cl, %es:(%edi) )
22792 6: addl %ecx, %eax
22793 adcl $0, %eax
22794 7:
22795 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22796
22797 6001:
22798 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22799 - movl $-EFAULT, (%ebx)
22800 + movl $-EFAULT, %ss:(%ebx)
22801
22802 # zero the complete destination - computing the rest
22803 # is too much work
22804 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22805
22806 6002:
22807 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22808 - movl $-EFAULT,(%ebx)
22809 + movl $-EFAULT,%ss:(%ebx)
22810 jmp 5000b
22811
22812 .previous
22813
22814 + pushl_cfi %ss
22815 + popl_cfi %ds
22816 + pushl_cfi %ss
22817 + popl_cfi %es
22818 popl_cfi %ebx
22819 CFI_RESTORE ebx
22820 popl_cfi %esi
22821 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22822 popl_cfi %ecx # equivalent to addl $4,%esp
22823 ret
22824 CFI_ENDPROC
22825 -ENDPROC(csum_partial_copy_generic)
22826 +ENDPROC(csum_partial_copy_generic_to_user)
22827
22828 #else
22829
22830 /* Version for PentiumII/PPro */
22831
22832 #define ROUND1(x) \
22833 + nop; nop; nop; \
22834 SRC(movl x(%esi), %ebx ) ; \
22835 addl %ebx, %eax ; \
22836 - DST(movl %ebx, x(%edi) ) ;
22837 + DST(movl %ebx, %es:x(%edi)) ;
22838
22839 #define ROUND(x) \
22840 + nop; nop; nop; \
22841 SRC(movl x(%esi), %ebx ) ; \
22842 adcl %ebx, %eax ; \
22843 - DST(movl %ebx, x(%edi) ) ;
22844 + DST(movl %ebx, %es:x(%edi)) ;
22845
22846 #define ARGBASE 12
22847 -
22848 -ENTRY(csum_partial_copy_generic)
22849 +
22850 +ENTRY(csum_partial_copy_generic_to_user)
22851 CFI_STARTPROC
22852 +
22853 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22854 + pushl_cfi %gs
22855 + popl_cfi %es
22856 + jmp csum_partial_copy_generic
22857 +#endif
22858 +
22859 +ENTRY(csum_partial_copy_generic_from_user)
22860 +
22861 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22862 + pushl_cfi %gs
22863 + popl_cfi %ds
22864 +#endif
22865 +
22866 +ENTRY(csum_partial_copy_generic)
22867 pushl_cfi %ebx
22868 CFI_REL_OFFSET ebx, 0
22869 pushl_cfi %edi
22870 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22871 subl %ebx, %edi
22872 lea -1(%esi),%edx
22873 andl $-32,%edx
22874 - lea 3f(%ebx,%ebx), %ebx
22875 + lea 3f(%ebx,%ebx,2), %ebx
22876 testl %esi, %esi
22877 jmp *%ebx
22878 1: addl $64,%esi
22879 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22880 jb 5f
22881 SRC( movw (%esi), %dx )
22882 leal 2(%esi), %esi
22883 -DST( movw %dx, (%edi) )
22884 +DST( movw %dx, %es:(%edi) )
22885 leal 2(%edi), %edi
22886 je 6f
22887 shll $16,%edx
22888 5:
22889 SRC( movb (%esi), %dl )
22890 -DST( movb %dl, (%edi) )
22891 +DST( movb %dl, %es:(%edi) )
22892 6: addl %edx, %eax
22893 adcl $0, %eax
22894 7:
22895 .section .fixup, "ax"
22896 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22897 - movl $-EFAULT, (%ebx)
22898 + movl $-EFAULT, %ss:(%ebx)
22899 # zero the complete destination (computing the rest is too much work)
22900 movl ARGBASE+8(%esp),%edi # dst
22901 movl ARGBASE+12(%esp),%ecx # len
22902 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22903 rep; stosb
22904 jmp 7b
22905 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22906 - movl $-EFAULT, (%ebx)
22907 + movl $-EFAULT, %ss:(%ebx)
22908 jmp 7b
22909 .previous
22910
22911 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22912 + pushl_cfi %ss
22913 + popl_cfi %ds
22914 + pushl_cfi %ss
22915 + popl_cfi %es
22916 +#endif
22917 +
22918 popl_cfi %esi
22919 CFI_RESTORE esi
22920 popl_cfi %edi
22921 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22922 CFI_RESTORE ebx
22923 ret
22924 CFI_ENDPROC
22925 -ENDPROC(csum_partial_copy_generic)
22926 +ENDPROC(csum_partial_copy_generic_to_user)
22927
22928 #undef ROUND
22929 #undef ROUND1
22930 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22931 index f2145cf..cea889d 100644
22932 --- a/arch/x86/lib/clear_page_64.S
22933 +++ b/arch/x86/lib/clear_page_64.S
22934 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22935 movl $4096/8,%ecx
22936 xorl %eax,%eax
22937 rep stosq
22938 + pax_force_retaddr
22939 ret
22940 CFI_ENDPROC
22941 ENDPROC(clear_page_c)
22942 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22943 movl $4096,%ecx
22944 xorl %eax,%eax
22945 rep stosb
22946 + pax_force_retaddr
22947 ret
22948 CFI_ENDPROC
22949 ENDPROC(clear_page_c_e)
22950 @@ -43,6 +45,7 @@ ENTRY(clear_page)
22951 leaq 64(%rdi),%rdi
22952 jnz .Lloop
22953 nop
22954 + pax_force_retaddr
22955 ret
22956 CFI_ENDPROC
22957 .Lclear_page_end:
22958 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
22959
22960 #include <asm/cpufeature.h>
22961
22962 - .section .altinstr_replacement,"ax"
22963 + .section .altinstr_replacement,"a"
22964 1: .byte 0xeb /* jmp <disp8> */
22965 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22966 2: .byte 0xeb /* jmp <disp8> */
22967 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22968 index 1e572c5..2a162cd 100644
22969 --- a/arch/x86/lib/cmpxchg16b_emu.S
22970 +++ b/arch/x86/lib/cmpxchg16b_emu.S
22971 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22972
22973 popf
22974 mov $1, %al
22975 + pax_force_retaddr
22976 ret
22977
22978 not_same:
22979 popf
22980 xor %al,%al
22981 + pax_force_retaddr
22982 ret
22983
22984 CFI_ENDPROC
22985 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22986 index 6b34d04..dccb07f 100644
22987 --- a/arch/x86/lib/copy_page_64.S
22988 +++ b/arch/x86/lib/copy_page_64.S
22989 @@ -9,6 +9,7 @@ copy_page_c:
22990 CFI_STARTPROC
22991 movl $4096/8,%ecx
22992 rep movsq
22993 + pax_force_retaddr
22994 ret
22995 CFI_ENDPROC
22996 ENDPROC(copy_page_c)
22997 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22998
22999 ENTRY(copy_page)
23000 CFI_STARTPROC
23001 - subq $2*8,%rsp
23002 - CFI_ADJUST_CFA_OFFSET 2*8
23003 + subq $3*8,%rsp
23004 + CFI_ADJUST_CFA_OFFSET 3*8
23005 movq %rbx,(%rsp)
23006 CFI_REL_OFFSET rbx, 0
23007 movq %r12,1*8(%rsp)
23008 CFI_REL_OFFSET r12, 1*8
23009 + movq %r13,2*8(%rsp)
23010 + CFI_REL_OFFSET r13, 2*8
23011
23012 movl $(4096/64)-5,%ecx
23013 .p2align 4
23014 @@ -37,7 +40,7 @@ ENTRY(copy_page)
23015 movq 16 (%rsi), %rdx
23016 movq 24 (%rsi), %r8
23017 movq 32 (%rsi), %r9
23018 - movq 40 (%rsi), %r10
23019 + movq 40 (%rsi), %r13
23020 movq 48 (%rsi), %r11
23021 movq 56 (%rsi), %r12
23022
23023 @@ -48,7 +51,7 @@ ENTRY(copy_page)
23024 movq %rdx, 16 (%rdi)
23025 movq %r8, 24 (%rdi)
23026 movq %r9, 32 (%rdi)
23027 - movq %r10, 40 (%rdi)
23028 + movq %r13, 40 (%rdi)
23029 movq %r11, 48 (%rdi)
23030 movq %r12, 56 (%rdi)
23031
23032 @@ -67,7 +70,7 @@ ENTRY(copy_page)
23033 movq 16 (%rsi), %rdx
23034 movq 24 (%rsi), %r8
23035 movq 32 (%rsi), %r9
23036 - movq 40 (%rsi), %r10
23037 + movq 40 (%rsi), %r13
23038 movq 48 (%rsi), %r11
23039 movq 56 (%rsi), %r12
23040
23041 @@ -76,7 +79,7 @@ ENTRY(copy_page)
23042 movq %rdx, 16 (%rdi)
23043 movq %r8, 24 (%rdi)
23044 movq %r9, 32 (%rdi)
23045 - movq %r10, 40 (%rdi)
23046 + movq %r13, 40 (%rdi)
23047 movq %r11, 48 (%rdi)
23048 movq %r12, 56 (%rdi)
23049
23050 @@ -89,8 +92,11 @@ ENTRY(copy_page)
23051 CFI_RESTORE rbx
23052 movq 1*8(%rsp),%r12
23053 CFI_RESTORE r12
23054 - addq $2*8,%rsp
23055 - CFI_ADJUST_CFA_OFFSET -2*8
23056 + movq 2*8(%rsp),%r13
23057 + CFI_RESTORE r13
23058 + addq $3*8,%rsp
23059 + CFI_ADJUST_CFA_OFFSET -3*8
23060 + pax_force_retaddr
23061 ret
23062 .Lcopy_page_end:
23063 CFI_ENDPROC
23064 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
23065
23066 #include <asm/cpufeature.h>
23067
23068 - .section .altinstr_replacement,"ax"
23069 + .section .altinstr_replacement,"a"
23070 1: .byte 0xeb /* jmp <disp8> */
23071 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
23072 2:
23073 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
23074 index a30ca15..d25fab6 100644
23075 --- a/arch/x86/lib/copy_user_64.S
23076 +++ b/arch/x86/lib/copy_user_64.S
23077 @@ -18,6 +18,7 @@
23078 #include <asm/alternative-asm.h>
23079 #include <asm/asm.h>
23080 #include <asm/smap.h>
23081 +#include <asm/pgtable.h>
23082
23083 /*
23084 * By placing feature2 after feature1 in altinstructions section, we logically
23085 @@ -31,7 +32,7 @@
23086 .byte 0xe9 /* 32bit jump */
23087 .long \orig-1f /* by default jump to orig */
23088 1:
23089 - .section .altinstr_replacement,"ax"
23090 + .section .altinstr_replacement,"a"
23091 2: .byte 0xe9 /* near jump with 32bit immediate */
23092 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
23093 3: .byte 0xe9 /* near jump with 32bit immediate */
23094 @@ -70,47 +71,20 @@
23095 #endif
23096 .endm
23097
23098 -/* Standard copy_to_user with segment limit checking */
23099 -ENTRY(_copy_to_user)
23100 - CFI_STARTPROC
23101 - GET_THREAD_INFO(%rax)
23102 - movq %rdi,%rcx
23103 - addq %rdx,%rcx
23104 - jc bad_to_user
23105 - cmpq TI_addr_limit(%rax),%rcx
23106 - ja bad_to_user
23107 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23108 - copy_user_generic_unrolled,copy_user_generic_string, \
23109 - copy_user_enhanced_fast_string
23110 - CFI_ENDPROC
23111 -ENDPROC(_copy_to_user)
23112 -
23113 -/* Standard copy_from_user with segment limit checking */
23114 -ENTRY(_copy_from_user)
23115 - CFI_STARTPROC
23116 - GET_THREAD_INFO(%rax)
23117 - movq %rsi,%rcx
23118 - addq %rdx,%rcx
23119 - jc bad_from_user
23120 - cmpq TI_addr_limit(%rax),%rcx
23121 - ja bad_from_user
23122 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23123 - copy_user_generic_unrolled,copy_user_generic_string, \
23124 - copy_user_enhanced_fast_string
23125 - CFI_ENDPROC
23126 -ENDPROC(_copy_from_user)
23127 -
23128 .section .fixup,"ax"
23129 /* must zero dest */
23130 ENTRY(bad_from_user)
23131 bad_from_user:
23132 CFI_STARTPROC
23133 + testl %edx,%edx
23134 + js bad_to_user
23135 movl %edx,%ecx
23136 xorl %eax,%eax
23137 rep
23138 stosb
23139 bad_to_user:
23140 movl %edx,%eax
23141 + pax_force_retaddr
23142 ret
23143 CFI_ENDPROC
23144 ENDPROC(bad_from_user)
23145 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
23146 jz 17f
23147 1: movq (%rsi),%r8
23148 2: movq 1*8(%rsi),%r9
23149 -3: movq 2*8(%rsi),%r10
23150 +3: movq 2*8(%rsi),%rax
23151 4: movq 3*8(%rsi),%r11
23152 5: movq %r8,(%rdi)
23153 6: movq %r9,1*8(%rdi)
23154 -7: movq %r10,2*8(%rdi)
23155 +7: movq %rax,2*8(%rdi)
23156 8: movq %r11,3*8(%rdi)
23157 9: movq 4*8(%rsi),%r8
23158 10: movq 5*8(%rsi),%r9
23159 -11: movq 6*8(%rsi),%r10
23160 +11: movq 6*8(%rsi),%rax
23161 12: movq 7*8(%rsi),%r11
23162 13: movq %r8,4*8(%rdi)
23163 14: movq %r9,5*8(%rdi)
23164 -15: movq %r10,6*8(%rdi)
23165 +15: movq %rax,6*8(%rdi)
23166 16: movq %r11,7*8(%rdi)
23167 leaq 64(%rsi),%rsi
23168 leaq 64(%rdi),%rdi
23169 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
23170 jnz 21b
23171 23: xor %eax,%eax
23172 ASM_CLAC
23173 + pax_force_retaddr
23174 ret
23175
23176 .section .fixup,"ax"
23177 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
23178 movsb
23179 4: xorl %eax,%eax
23180 ASM_CLAC
23181 + pax_force_retaddr
23182 ret
23183
23184 .section .fixup,"ax"
23185 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
23186 movsb
23187 2: xorl %eax,%eax
23188 ASM_CLAC
23189 + pax_force_retaddr
23190 ret
23191
23192 .section .fixup,"ax"
23193 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
23194 index 6a4f43c..f5f9e26 100644
23195 --- a/arch/x86/lib/copy_user_nocache_64.S
23196 +++ b/arch/x86/lib/copy_user_nocache_64.S
23197 @@ -8,6 +8,7 @@
23198
23199 #include <linux/linkage.h>
23200 #include <asm/dwarf2.h>
23201 +#include <asm/alternative-asm.h>
23202
23203 #define FIX_ALIGNMENT 1
23204
23205 @@ -16,6 +17,7 @@
23206 #include <asm/thread_info.h>
23207 #include <asm/asm.h>
23208 #include <asm/smap.h>
23209 +#include <asm/pgtable.h>
23210
23211 .macro ALIGN_DESTINATION
23212 #ifdef FIX_ALIGNMENT
23213 @@ -49,6 +51,15 @@
23214 */
23215 ENTRY(__copy_user_nocache)
23216 CFI_STARTPROC
23217 +
23218 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23219 + mov $PAX_USER_SHADOW_BASE,%rcx
23220 + cmp %rcx,%rsi
23221 + jae 1f
23222 + add %rcx,%rsi
23223 +1:
23224 +#endif
23225 +
23226 ASM_STAC
23227 cmpl $8,%edx
23228 jb 20f /* less then 8 bytes, go to byte copy loop */
23229 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
23230 jz 17f
23231 1: movq (%rsi),%r8
23232 2: movq 1*8(%rsi),%r9
23233 -3: movq 2*8(%rsi),%r10
23234 +3: movq 2*8(%rsi),%rax
23235 4: movq 3*8(%rsi),%r11
23236 5: movnti %r8,(%rdi)
23237 6: movnti %r9,1*8(%rdi)
23238 -7: movnti %r10,2*8(%rdi)
23239 +7: movnti %rax,2*8(%rdi)
23240 8: movnti %r11,3*8(%rdi)
23241 9: movq 4*8(%rsi),%r8
23242 10: movq 5*8(%rsi),%r9
23243 -11: movq 6*8(%rsi),%r10
23244 +11: movq 6*8(%rsi),%rax
23245 12: movq 7*8(%rsi),%r11
23246 13: movnti %r8,4*8(%rdi)
23247 14: movnti %r9,5*8(%rdi)
23248 -15: movnti %r10,6*8(%rdi)
23249 +15: movnti %rax,6*8(%rdi)
23250 16: movnti %r11,7*8(%rdi)
23251 leaq 64(%rsi),%rsi
23252 leaq 64(%rdi),%rdi
23253 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
23254 23: xorl %eax,%eax
23255 ASM_CLAC
23256 sfence
23257 + pax_force_retaddr
23258 ret
23259
23260 .section .fixup,"ax"
23261 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
23262 index 2419d5f..953ee51 100644
23263 --- a/arch/x86/lib/csum-copy_64.S
23264 +++ b/arch/x86/lib/csum-copy_64.S
23265 @@ -9,6 +9,7 @@
23266 #include <asm/dwarf2.h>
23267 #include <asm/errno.h>
23268 #include <asm/asm.h>
23269 +#include <asm/alternative-asm.h>
23270
23271 /*
23272 * Checksum copy with exception handling.
23273 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
23274 CFI_RESTORE rbp
23275 addq $7*8, %rsp
23276 CFI_ADJUST_CFA_OFFSET -7*8
23277 + pax_force_retaddr 0, 1
23278 ret
23279 CFI_RESTORE_STATE
23280
23281 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
23282 index 25b7ae8..169fafc 100644
23283 --- a/arch/x86/lib/csum-wrappers_64.c
23284 +++ b/arch/x86/lib/csum-wrappers_64.c
23285 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
23286 len -= 2;
23287 }
23288 }
23289 - isum = csum_partial_copy_generic((__force const void *)src,
23290 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
23291 dst, len, isum, errp, NULL);
23292 if (unlikely(*errp))
23293 goto out_err;
23294 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
23295 }
23296
23297 *errp = 0;
23298 - return csum_partial_copy_generic(src, (void __force *)dst,
23299 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
23300 len, isum, NULL, errp);
23301 }
23302 EXPORT_SYMBOL(csum_partial_copy_to_user);
23303 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
23304 index 156b9c8..b144132 100644
23305 --- a/arch/x86/lib/getuser.S
23306 +++ b/arch/x86/lib/getuser.S
23307 @@ -34,17 +34,40 @@
23308 #include <asm/thread_info.h>
23309 #include <asm/asm.h>
23310 #include <asm/smap.h>
23311 +#include <asm/segment.h>
23312 +#include <asm/pgtable.h>
23313 +#include <asm/alternative-asm.h>
23314 +
23315 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23316 +#define __copyuser_seg gs;
23317 +#else
23318 +#define __copyuser_seg
23319 +#endif
23320
23321 .text
23322 ENTRY(__get_user_1)
23323 CFI_STARTPROC
23324 +
23325 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23326 GET_THREAD_INFO(%_ASM_DX)
23327 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23328 jae bad_get_user
23329 ASM_STAC
23330 -1: movzb (%_ASM_AX),%edx
23331 +
23332 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23333 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23334 + cmp %_ASM_DX,%_ASM_AX
23335 + jae 1234f
23336 + add %_ASM_DX,%_ASM_AX
23337 +1234:
23338 +#endif
23339 +
23340 +#endif
23341 +
23342 +1: __copyuser_seg movzb (%_ASM_AX),%edx
23343 xor %eax,%eax
23344 ASM_CLAC
23345 + pax_force_retaddr
23346 ret
23347 CFI_ENDPROC
23348 ENDPROC(__get_user_1)
23349 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23350 ENTRY(__get_user_2)
23351 CFI_STARTPROC
23352 add $1,%_ASM_AX
23353 +
23354 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23355 jc bad_get_user
23356 GET_THREAD_INFO(%_ASM_DX)
23357 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23358 jae bad_get_user
23359 ASM_STAC
23360 -2: movzwl -1(%_ASM_AX),%edx
23361 +
23362 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23363 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23364 + cmp %_ASM_DX,%_ASM_AX
23365 + jae 1234f
23366 + add %_ASM_DX,%_ASM_AX
23367 +1234:
23368 +#endif
23369 +
23370 +#endif
23371 +
23372 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23373 xor %eax,%eax
23374 ASM_CLAC
23375 + pax_force_retaddr
23376 ret
23377 CFI_ENDPROC
23378 ENDPROC(__get_user_2)
23379 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23380 ENTRY(__get_user_4)
23381 CFI_STARTPROC
23382 add $3,%_ASM_AX
23383 +
23384 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23385 jc bad_get_user
23386 GET_THREAD_INFO(%_ASM_DX)
23387 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23388 jae bad_get_user
23389 ASM_STAC
23390 -3: mov -3(%_ASM_AX),%edx
23391 +
23392 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23393 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23394 + cmp %_ASM_DX,%_ASM_AX
23395 + jae 1234f
23396 + add %_ASM_DX,%_ASM_AX
23397 +1234:
23398 +#endif
23399 +
23400 +#endif
23401 +
23402 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
23403 xor %eax,%eax
23404 ASM_CLAC
23405 + pax_force_retaddr
23406 ret
23407 CFI_ENDPROC
23408 ENDPROC(__get_user_4)
23409 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23410 GET_THREAD_INFO(%_ASM_DX)
23411 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23412 jae bad_get_user
23413 +
23414 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23415 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23416 + cmp %_ASM_DX,%_ASM_AX
23417 + jae 1234f
23418 + add %_ASM_DX,%_ASM_AX
23419 +1234:
23420 +#endif
23421 +
23422 ASM_STAC
23423 4: movq -7(%_ASM_AX),%_ASM_DX
23424 xor %eax,%eax
23425 ASM_CLAC
23426 + pax_force_retaddr
23427 ret
23428 CFI_ENDPROC
23429 ENDPROC(__get_user_8)
23430 @@ -101,6 +162,7 @@ bad_get_user:
23431 xor %edx,%edx
23432 mov $(-EFAULT),%_ASM_AX
23433 ASM_CLAC
23434 + pax_force_retaddr
23435 ret
23436 CFI_ENDPROC
23437 END(bad_get_user)
23438 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23439 index 54fcffe..7be149e 100644
23440 --- a/arch/x86/lib/insn.c
23441 +++ b/arch/x86/lib/insn.c
23442 @@ -20,8 +20,10 @@
23443
23444 #ifdef __KERNEL__
23445 #include <linux/string.h>
23446 +#include <asm/pgtable_types.h>
23447 #else
23448 #include <string.h>
23449 +#define ktla_ktva(addr) addr
23450 #endif
23451 #include <asm/inat.h>
23452 #include <asm/insn.h>
23453 @@ -53,8 +55,8 @@
23454 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23455 {
23456 memset(insn, 0, sizeof(*insn));
23457 - insn->kaddr = kaddr;
23458 - insn->next_byte = kaddr;
23459 + insn->kaddr = ktla_ktva(kaddr);
23460 + insn->next_byte = ktla_ktva(kaddr);
23461 insn->x86_64 = x86_64 ? 1 : 0;
23462 insn->opnd_bytes = 4;
23463 if (x86_64)
23464 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23465 index 05a95e7..326f2fa 100644
23466 --- a/arch/x86/lib/iomap_copy_64.S
23467 +++ b/arch/x86/lib/iomap_copy_64.S
23468 @@ -17,6 +17,7 @@
23469
23470 #include <linux/linkage.h>
23471 #include <asm/dwarf2.h>
23472 +#include <asm/alternative-asm.h>
23473
23474 /*
23475 * override generic version in lib/iomap_copy.c
23476 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23477 CFI_STARTPROC
23478 movl %edx,%ecx
23479 rep movsd
23480 + pax_force_retaddr
23481 ret
23482 CFI_ENDPROC
23483 ENDPROC(__iowrite32_copy)
23484 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23485 index 1c273be..da9cc0e 100644
23486 --- a/arch/x86/lib/memcpy_64.S
23487 +++ b/arch/x86/lib/memcpy_64.S
23488 @@ -33,6 +33,7 @@
23489 rep movsq
23490 movl %edx, %ecx
23491 rep movsb
23492 + pax_force_retaddr
23493 ret
23494 .Lmemcpy_e:
23495 .previous
23496 @@ -49,6 +50,7 @@
23497 movq %rdi, %rax
23498 movq %rdx, %rcx
23499 rep movsb
23500 + pax_force_retaddr
23501 ret
23502 .Lmemcpy_e_e:
23503 .previous
23504 @@ -76,13 +78,13 @@ ENTRY(memcpy)
23505 */
23506 movq 0*8(%rsi), %r8
23507 movq 1*8(%rsi), %r9
23508 - movq 2*8(%rsi), %r10
23509 + movq 2*8(%rsi), %rcx
23510 movq 3*8(%rsi), %r11
23511 leaq 4*8(%rsi), %rsi
23512
23513 movq %r8, 0*8(%rdi)
23514 movq %r9, 1*8(%rdi)
23515 - movq %r10, 2*8(%rdi)
23516 + movq %rcx, 2*8(%rdi)
23517 movq %r11, 3*8(%rdi)
23518 leaq 4*8(%rdi), %rdi
23519 jae .Lcopy_forward_loop
23520 @@ -105,12 +107,12 @@ ENTRY(memcpy)
23521 subq $0x20, %rdx
23522 movq -1*8(%rsi), %r8
23523 movq -2*8(%rsi), %r9
23524 - movq -3*8(%rsi), %r10
23525 + movq -3*8(%rsi), %rcx
23526 movq -4*8(%rsi), %r11
23527 leaq -4*8(%rsi), %rsi
23528 movq %r8, -1*8(%rdi)
23529 movq %r9, -2*8(%rdi)
23530 - movq %r10, -3*8(%rdi)
23531 + movq %rcx, -3*8(%rdi)
23532 movq %r11, -4*8(%rdi)
23533 leaq -4*8(%rdi), %rdi
23534 jae .Lcopy_backward_loop
23535 @@ -130,12 +132,13 @@ ENTRY(memcpy)
23536 */
23537 movq 0*8(%rsi), %r8
23538 movq 1*8(%rsi), %r9
23539 - movq -2*8(%rsi, %rdx), %r10
23540 + movq -2*8(%rsi, %rdx), %rcx
23541 movq -1*8(%rsi, %rdx), %r11
23542 movq %r8, 0*8(%rdi)
23543 movq %r9, 1*8(%rdi)
23544 - movq %r10, -2*8(%rdi, %rdx)
23545 + movq %rcx, -2*8(%rdi, %rdx)
23546 movq %r11, -1*8(%rdi, %rdx)
23547 + pax_force_retaddr
23548 retq
23549 .p2align 4
23550 .Lless_16bytes:
23551 @@ -148,6 +151,7 @@ ENTRY(memcpy)
23552 movq -1*8(%rsi, %rdx), %r9
23553 movq %r8, 0*8(%rdi)
23554 movq %r9, -1*8(%rdi, %rdx)
23555 + pax_force_retaddr
23556 retq
23557 .p2align 4
23558 .Lless_8bytes:
23559 @@ -161,6 +165,7 @@ ENTRY(memcpy)
23560 movl -4(%rsi, %rdx), %r8d
23561 movl %ecx, (%rdi)
23562 movl %r8d, -4(%rdi, %rdx)
23563 + pax_force_retaddr
23564 retq
23565 .p2align 4
23566 .Lless_3bytes:
23567 @@ -179,6 +184,7 @@ ENTRY(memcpy)
23568 movb %cl, (%rdi)
23569
23570 .Lend:
23571 + pax_force_retaddr
23572 retq
23573 CFI_ENDPROC
23574 ENDPROC(memcpy)
23575 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23576 index ee16461..c39c199 100644
23577 --- a/arch/x86/lib/memmove_64.S
23578 +++ b/arch/x86/lib/memmove_64.S
23579 @@ -61,13 +61,13 @@ ENTRY(memmove)
23580 5:
23581 sub $0x20, %rdx
23582 movq 0*8(%rsi), %r11
23583 - movq 1*8(%rsi), %r10
23584 + movq 1*8(%rsi), %rcx
23585 movq 2*8(%rsi), %r9
23586 movq 3*8(%rsi), %r8
23587 leaq 4*8(%rsi), %rsi
23588
23589 movq %r11, 0*8(%rdi)
23590 - movq %r10, 1*8(%rdi)
23591 + movq %rcx, 1*8(%rdi)
23592 movq %r9, 2*8(%rdi)
23593 movq %r8, 3*8(%rdi)
23594 leaq 4*8(%rdi), %rdi
23595 @@ -81,10 +81,10 @@ ENTRY(memmove)
23596 4:
23597 movq %rdx, %rcx
23598 movq -8(%rsi, %rdx), %r11
23599 - lea -8(%rdi, %rdx), %r10
23600 + lea -8(%rdi, %rdx), %r9
23601 shrq $3, %rcx
23602 rep movsq
23603 - movq %r11, (%r10)
23604 + movq %r11, (%r9)
23605 jmp 13f
23606 .Lmemmove_end_forward:
23607
23608 @@ -95,14 +95,14 @@ ENTRY(memmove)
23609 7:
23610 movq %rdx, %rcx
23611 movq (%rsi), %r11
23612 - movq %rdi, %r10
23613 + movq %rdi, %r9
23614 leaq -8(%rsi, %rdx), %rsi
23615 leaq -8(%rdi, %rdx), %rdi
23616 shrq $3, %rcx
23617 std
23618 rep movsq
23619 cld
23620 - movq %r11, (%r10)
23621 + movq %r11, (%r9)
23622 jmp 13f
23623
23624 /*
23625 @@ -127,13 +127,13 @@ ENTRY(memmove)
23626 8:
23627 subq $0x20, %rdx
23628 movq -1*8(%rsi), %r11
23629 - movq -2*8(%rsi), %r10
23630 + movq -2*8(%rsi), %rcx
23631 movq -3*8(%rsi), %r9
23632 movq -4*8(%rsi), %r8
23633 leaq -4*8(%rsi), %rsi
23634
23635 movq %r11, -1*8(%rdi)
23636 - movq %r10, -2*8(%rdi)
23637 + movq %rcx, -2*8(%rdi)
23638 movq %r9, -3*8(%rdi)
23639 movq %r8, -4*8(%rdi)
23640 leaq -4*8(%rdi), %rdi
23641 @@ -151,11 +151,11 @@ ENTRY(memmove)
23642 * Move data from 16 bytes to 31 bytes.
23643 */
23644 movq 0*8(%rsi), %r11
23645 - movq 1*8(%rsi), %r10
23646 + movq 1*8(%rsi), %rcx
23647 movq -2*8(%rsi, %rdx), %r9
23648 movq -1*8(%rsi, %rdx), %r8
23649 movq %r11, 0*8(%rdi)
23650 - movq %r10, 1*8(%rdi)
23651 + movq %rcx, 1*8(%rdi)
23652 movq %r9, -2*8(%rdi, %rdx)
23653 movq %r8, -1*8(%rdi, %rdx)
23654 jmp 13f
23655 @@ -167,9 +167,9 @@ ENTRY(memmove)
23656 * Move data from 8 bytes to 15 bytes.
23657 */
23658 movq 0*8(%rsi), %r11
23659 - movq -1*8(%rsi, %rdx), %r10
23660 + movq -1*8(%rsi, %rdx), %r9
23661 movq %r11, 0*8(%rdi)
23662 - movq %r10, -1*8(%rdi, %rdx)
23663 + movq %r9, -1*8(%rdi, %rdx)
23664 jmp 13f
23665 10:
23666 cmpq $4, %rdx
23667 @@ -178,9 +178,9 @@ ENTRY(memmove)
23668 * Move data from 4 bytes to 7 bytes.
23669 */
23670 movl (%rsi), %r11d
23671 - movl -4(%rsi, %rdx), %r10d
23672 + movl -4(%rsi, %rdx), %r9d
23673 movl %r11d, (%rdi)
23674 - movl %r10d, -4(%rdi, %rdx)
23675 + movl %r9d, -4(%rdi, %rdx)
23676 jmp 13f
23677 11:
23678 cmp $2, %rdx
23679 @@ -189,9 +189,9 @@ ENTRY(memmove)
23680 * Move data from 2 bytes to 3 bytes.
23681 */
23682 movw (%rsi), %r11w
23683 - movw -2(%rsi, %rdx), %r10w
23684 + movw -2(%rsi, %rdx), %r9w
23685 movw %r11w, (%rdi)
23686 - movw %r10w, -2(%rdi, %rdx)
23687 + movw %r9w, -2(%rdi, %rdx)
23688 jmp 13f
23689 12:
23690 cmp $1, %rdx
23691 @@ -202,6 +202,7 @@ ENTRY(memmove)
23692 movb (%rsi), %r11b
23693 movb %r11b, (%rdi)
23694 13:
23695 + pax_force_retaddr
23696 retq
23697 CFI_ENDPROC
23698
23699 @@ -210,6 +211,7 @@ ENTRY(memmove)
23700 /* Forward moving data. */
23701 movq %rdx, %rcx
23702 rep movsb
23703 + pax_force_retaddr
23704 retq
23705 .Lmemmove_end_forward_efs:
23706 .previous
23707 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23708 index 2dcb380..963660a 100644
23709 --- a/arch/x86/lib/memset_64.S
23710 +++ b/arch/x86/lib/memset_64.S
23711 @@ -30,6 +30,7 @@
23712 movl %edx,%ecx
23713 rep stosb
23714 movq %r9,%rax
23715 + pax_force_retaddr
23716 ret
23717 .Lmemset_e:
23718 .previous
23719 @@ -52,6 +53,7 @@
23720 movq %rdx,%rcx
23721 rep stosb
23722 movq %r9,%rax
23723 + pax_force_retaddr
23724 ret
23725 .Lmemset_e_e:
23726 .previous
23727 @@ -59,7 +61,7 @@
23728 ENTRY(memset)
23729 ENTRY(__memset)
23730 CFI_STARTPROC
23731 - movq %rdi,%r10
23732 + movq %rdi,%r11
23733
23734 /* expand byte value */
23735 movzbl %sil,%ecx
23736 @@ -117,7 +119,8 @@ ENTRY(__memset)
23737 jnz .Lloop_1
23738
23739 .Lende:
23740 - movq %r10,%rax
23741 + movq %r11,%rax
23742 + pax_force_retaddr
23743 ret
23744
23745 CFI_RESTORE_STATE
23746 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23747 index c9f2d9b..e7fd2c0 100644
23748 --- a/arch/x86/lib/mmx_32.c
23749 +++ b/arch/x86/lib/mmx_32.c
23750 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23751 {
23752 void *p;
23753 int i;
23754 + unsigned long cr0;
23755
23756 if (unlikely(in_interrupt()))
23757 return __memcpy(to, from, len);
23758 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23759 kernel_fpu_begin();
23760
23761 __asm__ __volatile__ (
23762 - "1: prefetch (%0)\n" /* This set is 28 bytes */
23763 - " prefetch 64(%0)\n"
23764 - " prefetch 128(%0)\n"
23765 - " prefetch 192(%0)\n"
23766 - " prefetch 256(%0)\n"
23767 + "1: prefetch (%1)\n" /* This set is 28 bytes */
23768 + " prefetch 64(%1)\n"
23769 + " prefetch 128(%1)\n"
23770 + " prefetch 192(%1)\n"
23771 + " prefetch 256(%1)\n"
23772 "2: \n"
23773 ".section .fixup, \"ax\"\n"
23774 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23775 + "3: \n"
23776 +
23777 +#ifdef CONFIG_PAX_KERNEXEC
23778 + " movl %%cr0, %0\n"
23779 + " movl %0, %%eax\n"
23780 + " andl $0xFFFEFFFF, %%eax\n"
23781 + " movl %%eax, %%cr0\n"
23782 +#endif
23783 +
23784 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23785 +
23786 +#ifdef CONFIG_PAX_KERNEXEC
23787 + " movl %0, %%cr0\n"
23788 +#endif
23789 +
23790 " jmp 2b\n"
23791 ".previous\n"
23792 _ASM_EXTABLE(1b, 3b)
23793 - : : "r" (from));
23794 + : "=&r" (cr0) : "r" (from) : "ax");
23795
23796 for ( ; i > 5; i--) {
23797 __asm__ __volatile__ (
23798 - "1: prefetch 320(%0)\n"
23799 - "2: movq (%0), %%mm0\n"
23800 - " movq 8(%0), %%mm1\n"
23801 - " movq 16(%0), %%mm2\n"
23802 - " movq 24(%0), %%mm3\n"
23803 - " movq %%mm0, (%1)\n"
23804 - " movq %%mm1, 8(%1)\n"
23805 - " movq %%mm2, 16(%1)\n"
23806 - " movq %%mm3, 24(%1)\n"
23807 - " movq 32(%0), %%mm0\n"
23808 - " movq 40(%0), %%mm1\n"
23809 - " movq 48(%0), %%mm2\n"
23810 - " movq 56(%0), %%mm3\n"
23811 - " movq %%mm0, 32(%1)\n"
23812 - " movq %%mm1, 40(%1)\n"
23813 - " movq %%mm2, 48(%1)\n"
23814 - " movq %%mm3, 56(%1)\n"
23815 + "1: prefetch 320(%1)\n"
23816 + "2: movq (%1), %%mm0\n"
23817 + " movq 8(%1), %%mm1\n"
23818 + " movq 16(%1), %%mm2\n"
23819 + " movq 24(%1), %%mm3\n"
23820 + " movq %%mm0, (%2)\n"
23821 + " movq %%mm1, 8(%2)\n"
23822 + " movq %%mm2, 16(%2)\n"
23823 + " movq %%mm3, 24(%2)\n"
23824 + " movq 32(%1), %%mm0\n"
23825 + " movq 40(%1), %%mm1\n"
23826 + " movq 48(%1), %%mm2\n"
23827 + " movq 56(%1), %%mm3\n"
23828 + " movq %%mm0, 32(%2)\n"
23829 + " movq %%mm1, 40(%2)\n"
23830 + " movq %%mm2, 48(%2)\n"
23831 + " movq %%mm3, 56(%2)\n"
23832 ".section .fixup, \"ax\"\n"
23833 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23834 + "3:\n"
23835 +
23836 +#ifdef CONFIG_PAX_KERNEXEC
23837 + " movl %%cr0, %0\n"
23838 + " movl %0, %%eax\n"
23839 + " andl $0xFFFEFFFF, %%eax\n"
23840 + " movl %%eax, %%cr0\n"
23841 +#endif
23842 +
23843 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23844 +
23845 +#ifdef CONFIG_PAX_KERNEXEC
23846 + " movl %0, %%cr0\n"
23847 +#endif
23848 +
23849 " jmp 2b\n"
23850 ".previous\n"
23851 _ASM_EXTABLE(1b, 3b)
23852 - : : "r" (from), "r" (to) : "memory");
23853 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23854
23855 from += 64;
23856 to += 64;
23857 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23858 static void fast_copy_page(void *to, void *from)
23859 {
23860 int i;
23861 + unsigned long cr0;
23862
23863 kernel_fpu_begin();
23864
23865 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23866 * but that is for later. -AV
23867 */
23868 __asm__ __volatile__(
23869 - "1: prefetch (%0)\n"
23870 - " prefetch 64(%0)\n"
23871 - " prefetch 128(%0)\n"
23872 - " prefetch 192(%0)\n"
23873 - " prefetch 256(%0)\n"
23874 + "1: prefetch (%1)\n"
23875 + " prefetch 64(%1)\n"
23876 + " prefetch 128(%1)\n"
23877 + " prefetch 192(%1)\n"
23878 + " prefetch 256(%1)\n"
23879 "2: \n"
23880 ".section .fixup, \"ax\"\n"
23881 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23882 + "3: \n"
23883 +
23884 +#ifdef CONFIG_PAX_KERNEXEC
23885 + " movl %%cr0, %0\n"
23886 + " movl %0, %%eax\n"
23887 + " andl $0xFFFEFFFF, %%eax\n"
23888 + " movl %%eax, %%cr0\n"
23889 +#endif
23890 +
23891 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23892 +
23893 +#ifdef CONFIG_PAX_KERNEXEC
23894 + " movl %0, %%cr0\n"
23895 +#endif
23896 +
23897 " jmp 2b\n"
23898 ".previous\n"
23899 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23900 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23901
23902 for (i = 0; i < (4096-320)/64; i++) {
23903 __asm__ __volatile__ (
23904 - "1: prefetch 320(%0)\n"
23905 - "2: movq (%0), %%mm0\n"
23906 - " movntq %%mm0, (%1)\n"
23907 - " movq 8(%0), %%mm1\n"
23908 - " movntq %%mm1, 8(%1)\n"
23909 - " movq 16(%0), %%mm2\n"
23910 - " movntq %%mm2, 16(%1)\n"
23911 - " movq 24(%0), %%mm3\n"
23912 - " movntq %%mm3, 24(%1)\n"
23913 - " movq 32(%0), %%mm4\n"
23914 - " movntq %%mm4, 32(%1)\n"
23915 - " movq 40(%0), %%mm5\n"
23916 - " movntq %%mm5, 40(%1)\n"
23917 - " movq 48(%0), %%mm6\n"
23918 - " movntq %%mm6, 48(%1)\n"
23919 - " movq 56(%0), %%mm7\n"
23920 - " movntq %%mm7, 56(%1)\n"
23921 + "1: prefetch 320(%1)\n"
23922 + "2: movq (%1), %%mm0\n"
23923 + " movntq %%mm0, (%2)\n"
23924 + " movq 8(%1), %%mm1\n"
23925 + " movntq %%mm1, 8(%2)\n"
23926 + " movq 16(%1), %%mm2\n"
23927 + " movntq %%mm2, 16(%2)\n"
23928 + " movq 24(%1), %%mm3\n"
23929 + " movntq %%mm3, 24(%2)\n"
23930 + " movq 32(%1), %%mm4\n"
23931 + " movntq %%mm4, 32(%2)\n"
23932 + " movq 40(%1), %%mm5\n"
23933 + " movntq %%mm5, 40(%2)\n"
23934 + " movq 48(%1), %%mm6\n"
23935 + " movntq %%mm6, 48(%2)\n"
23936 + " movq 56(%1), %%mm7\n"
23937 + " movntq %%mm7, 56(%2)\n"
23938 ".section .fixup, \"ax\"\n"
23939 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23940 + "3:\n"
23941 +
23942 +#ifdef CONFIG_PAX_KERNEXEC
23943 + " movl %%cr0, %0\n"
23944 + " movl %0, %%eax\n"
23945 + " andl $0xFFFEFFFF, %%eax\n"
23946 + " movl %%eax, %%cr0\n"
23947 +#endif
23948 +
23949 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23950 +
23951 +#ifdef CONFIG_PAX_KERNEXEC
23952 + " movl %0, %%cr0\n"
23953 +#endif
23954 +
23955 " jmp 2b\n"
23956 ".previous\n"
23957 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23958 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23959
23960 from += 64;
23961 to += 64;
23962 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23963 static void fast_copy_page(void *to, void *from)
23964 {
23965 int i;
23966 + unsigned long cr0;
23967
23968 kernel_fpu_begin();
23969
23970 __asm__ __volatile__ (
23971 - "1: prefetch (%0)\n"
23972 - " prefetch 64(%0)\n"
23973 - " prefetch 128(%0)\n"
23974 - " prefetch 192(%0)\n"
23975 - " prefetch 256(%0)\n"
23976 + "1: prefetch (%1)\n"
23977 + " prefetch 64(%1)\n"
23978 + " prefetch 128(%1)\n"
23979 + " prefetch 192(%1)\n"
23980 + " prefetch 256(%1)\n"
23981 "2: \n"
23982 ".section .fixup, \"ax\"\n"
23983 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23984 + "3: \n"
23985 +
23986 +#ifdef CONFIG_PAX_KERNEXEC
23987 + " movl %%cr0, %0\n"
23988 + " movl %0, %%eax\n"
23989 + " andl $0xFFFEFFFF, %%eax\n"
23990 + " movl %%eax, %%cr0\n"
23991 +#endif
23992 +
23993 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23994 +
23995 +#ifdef CONFIG_PAX_KERNEXEC
23996 + " movl %0, %%cr0\n"
23997 +#endif
23998 +
23999 " jmp 2b\n"
24000 ".previous\n"
24001 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
24002 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
24003
24004 for (i = 0; i < 4096/64; i++) {
24005 __asm__ __volatile__ (
24006 - "1: prefetch 320(%0)\n"
24007 - "2: movq (%0), %%mm0\n"
24008 - " movq 8(%0), %%mm1\n"
24009 - " movq 16(%0), %%mm2\n"
24010 - " movq 24(%0), %%mm3\n"
24011 - " movq %%mm0, (%1)\n"
24012 - " movq %%mm1, 8(%1)\n"
24013 - " movq %%mm2, 16(%1)\n"
24014 - " movq %%mm3, 24(%1)\n"
24015 - " movq 32(%0), %%mm0\n"
24016 - " movq 40(%0), %%mm1\n"
24017 - " movq 48(%0), %%mm2\n"
24018 - " movq 56(%0), %%mm3\n"
24019 - " movq %%mm0, 32(%1)\n"
24020 - " movq %%mm1, 40(%1)\n"
24021 - " movq %%mm2, 48(%1)\n"
24022 - " movq %%mm3, 56(%1)\n"
24023 + "1: prefetch 320(%1)\n"
24024 + "2: movq (%1), %%mm0\n"
24025 + " movq 8(%1), %%mm1\n"
24026 + " movq 16(%1), %%mm2\n"
24027 + " movq 24(%1), %%mm3\n"
24028 + " movq %%mm0, (%2)\n"
24029 + " movq %%mm1, 8(%2)\n"
24030 + " movq %%mm2, 16(%2)\n"
24031 + " movq %%mm3, 24(%2)\n"
24032 + " movq 32(%1), %%mm0\n"
24033 + " movq 40(%1), %%mm1\n"
24034 + " movq 48(%1), %%mm2\n"
24035 + " movq 56(%1), %%mm3\n"
24036 + " movq %%mm0, 32(%2)\n"
24037 + " movq %%mm1, 40(%2)\n"
24038 + " movq %%mm2, 48(%2)\n"
24039 + " movq %%mm3, 56(%2)\n"
24040 ".section .fixup, \"ax\"\n"
24041 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24042 + "3:\n"
24043 +
24044 +#ifdef CONFIG_PAX_KERNEXEC
24045 + " movl %%cr0, %0\n"
24046 + " movl %0, %%eax\n"
24047 + " andl $0xFFFEFFFF, %%eax\n"
24048 + " movl %%eax, %%cr0\n"
24049 +#endif
24050 +
24051 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24052 +
24053 +#ifdef CONFIG_PAX_KERNEXEC
24054 + " movl %0, %%cr0\n"
24055 +#endif
24056 +
24057 " jmp 2b\n"
24058 ".previous\n"
24059 _ASM_EXTABLE(1b, 3b)
24060 - : : "r" (from), "r" (to) : "memory");
24061 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
24062
24063 from += 64;
24064 to += 64;
24065 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
24066 index f6d13ee..aca5f0b 100644
24067 --- a/arch/x86/lib/msr-reg.S
24068 +++ b/arch/x86/lib/msr-reg.S
24069 @@ -3,6 +3,7 @@
24070 #include <asm/dwarf2.h>
24071 #include <asm/asm.h>
24072 #include <asm/msr.h>
24073 +#include <asm/alternative-asm.h>
24074
24075 #ifdef CONFIG_X86_64
24076 /*
24077 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
24078 CFI_STARTPROC
24079 pushq_cfi %rbx
24080 pushq_cfi %rbp
24081 - movq %rdi, %r10 /* Save pointer */
24082 + movq %rdi, %r9 /* Save pointer */
24083 xorl %r11d, %r11d /* Return value */
24084 movl (%rdi), %eax
24085 movl 4(%rdi), %ecx
24086 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
24087 movl 28(%rdi), %edi
24088 CFI_REMEMBER_STATE
24089 1: \op
24090 -2: movl %eax, (%r10)
24091 +2: movl %eax, (%r9)
24092 movl %r11d, %eax /* Return value */
24093 - movl %ecx, 4(%r10)
24094 - movl %edx, 8(%r10)
24095 - movl %ebx, 12(%r10)
24096 - movl %ebp, 20(%r10)
24097 - movl %esi, 24(%r10)
24098 - movl %edi, 28(%r10)
24099 + movl %ecx, 4(%r9)
24100 + movl %edx, 8(%r9)
24101 + movl %ebx, 12(%r9)
24102 + movl %ebp, 20(%r9)
24103 + movl %esi, 24(%r9)
24104 + movl %edi, 28(%r9)
24105 popq_cfi %rbp
24106 popq_cfi %rbx
24107 + pax_force_retaddr
24108 ret
24109 3:
24110 CFI_RESTORE_STATE
24111 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
24112 index fc6ba17..04471c5 100644
24113 --- a/arch/x86/lib/putuser.S
24114 +++ b/arch/x86/lib/putuser.S
24115 @@ -16,7 +16,9 @@
24116 #include <asm/errno.h>
24117 #include <asm/asm.h>
24118 #include <asm/smap.h>
24119 -
24120 +#include <asm/segment.h>
24121 +#include <asm/pgtable.h>
24122 +#include <asm/alternative-asm.h>
24123
24124 /*
24125 * __put_user_X
24126 @@ -30,57 +32,125 @@
24127 * as they get called from within inline assembly.
24128 */
24129
24130 -#define ENTER CFI_STARTPROC ; \
24131 - GET_THREAD_INFO(%_ASM_BX)
24132 -#define EXIT ASM_CLAC ; \
24133 - ret ; \
24134 +#define ENTER CFI_STARTPROC
24135 +#define EXIT ASM_CLAC ; \
24136 + pax_force_retaddr ; \
24137 + ret ; \
24138 CFI_ENDPROC
24139
24140 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24141 +#define _DEST %_ASM_CX,%_ASM_BX
24142 +#else
24143 +#define _DEST %_ASM_CX
24144 +#endif
24145 +
24146 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24147 +#define __copyuser_seg gs;
24148 +#else
24149 +#define __copyuser_seg
24150 +#endif
24151 +
24152 .text
24153 ENTRY(__put_user_1)
24154 ENTER
24155 +
24156 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24157 + GET_THREAD_INFO(%_ASM_BX)
24158 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
24159 jae bad_put_user
24160 ASM_STAC
24161 -1: movb %al,(%_ASM_CX)
24162 +
24163 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24164 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24165 + cmp %_ASM_BX,%_ASM_CX
24166 + jb 1234f
24167 + xor %ebx,%ebx
24168 +1234:
24169 +#endif
24170 +
24171 +#endif
24172 +
24173 +1: __copyuser_seg movb %al,(_DEST)
24174 xor %eax,%eax
24175 EXIT
24176 ENDPROC(__put_user_1)
24177
24178 ENTRY(__put_user_2)
24179 ENTER
24180 +
24181 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24182 + GET_THREAD_INFO(%_ASM_BX)
24183 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24184 sub $1,%_ASM_BX
24185 cmp %_ASM_BX,%_ASM_CX
24186 jae bad_put_user
24187 ASM_STAC
24188 -2: movw %ax,(%_ASM_CX)
24189 +
24190 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24191 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24192 + cmp %_ASM_BX,%_ASM_CX
24193 + jb 1234f
24194 + xor %ebx,%ebx
24195 +1234:
24196 +#endif
24197 +
24198 +#endif
24199 +
24200 +2: __copyuser_seg movw %ax,(_DEST)
24201 xor %eax,%eax
24202 EXIT
24203 ENDPROC(__put_user_2)
24204
24205 ENTRY(__put_user_4)
24206 ENTER
24207 +
24208 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24209 + GET_THREAD_INFO(%_ASM_BX)
24210 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24211 sub $3,%_ASM_BX
24212 cmp %_ASM_BX,%_ASM_CX
24213 jae bad_put_user
24214 ASM_STAC
24215 -3: movl %eax,(%_ASM_CX)
24216 +
24217 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24218 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24219 + cmp %_ASM_BX,%_ASM_CX
24220 + jb 1234f
24221 + xor %ebx,%ebx
24222 +1234:
24223 +#endif
24224 +
24225 +#endif
24226 +
24227 +3: __copyuser_seg movl %eax,(_DEST)
24228 xor %eax,%eax
24229 EXIT
24230 ENDPROC(__put_user_4)
24231
24232 ENTRY(__put_user_8)
24233 ENTER
24234 +
24235 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24236 + GET_THREAD_INFO(%_ASM_BX)
24237 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24238 sub $7,%_ASM_BX
24239 cmp %_ASM_BX,%_ASM_CX
24240 jae bad_put_user
24241 ASM_STAC
24242 -4: mov %_ASM_AX,(%_ASM_CX)
24243 +
24244 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24245 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24246 + cmp %_ASM_BX,%_ASM_CX
24247 + jb 1234f
24248 + xor %ebx,%ebx
24249 +1234:
24250 +#endif
24251 +
24252 +#endif
24253 +
24254 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
24255 #ifdef CONFIG_X86_32
24256 -5: movl %edx,4(%_ASM_CX)
24257 +5: __copyuser_seg movl %edx,4(_DEST)
24258 #endif
24259 xor %eax,%eax
24260 EXIT
24261 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
24262 index 1cad221..de671ee 100644
24263 --- a/arch/x86/lib/rwlock.S
24264 +++ b/arch/x86/lib/rwlock.S
24265 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
24266 FRAME
24267 0: LOCK_PREFIX
24268 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24269 +
24270 +#ifdef CONFIG_PAX_REFCOUNT
24271 + jno 1234f
24272 + LOCK_PREFIX
24273 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24274 + int $4
24275 +1234:
24276 + _ASM_EXTABLE(1234b, 1234b)
24277 +#endif
24278 +
24279 1: rep; nop
24280 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
24281 jne 1b
24282 LOCK_PREFIX
24283 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24284 +
24285 +#ifdef CONFIG_PAX_REFCOUNT
24286 + jno 1234f
24287 + LOCK_PREFIX
24288 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24289 + int $4
24290 +1234:
24291 + _ASM_EXTABLE(1234b, 1234b)
24292 +#endif
24293 +
24294 jnz 0b
24295 ENDFRAME
24296 + pax_force_retaddr
24297 ret
24298 CFI_ENDPROC
24299 END(__write_lock_failed)
24300 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
24301 FRAME
24302 0: LOCK_PREFIX
24303 READ_LOCK_SIZE(inc) (%__lock_ptr)
24304 +
24305 +#ifdef CONFIG_PAX_REFCOUNT
24306 + jno 1234f
24307 + LOCK_PREFIX
24308 + READ_LOCK_SIZE(dec) (%__lock_ptr)
24309 + int $4
24310 +1234:
24311 + _ASM_EXTABLE(1234b, 1234b)
24312 +#endif
24313 +
24314 1: rep; nop
24315 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24316 js 1b
24317 LOCK_PREFIX
24318 READ_LOCK_SIZE(dec) (%__lock_ptr)
24319 +
24320 +#ifdef CONFIG_PAX_REFCOUNT
24321 + jno 1234f
24322 + LOCK_PREFIX
24323 + READ_LOCK_SIZE(inc) (%__lock_ptr)
24324 + int $4
24325 +1234:
24326 + _ASM_EXTABLE(1234b, 1234b)
24327 +#endif
24328 +
24329 js 0b
24330 ENDFRAME
24331 + pax_force_retaddr
24332 ret
24333 CFI_ENDPROC
24334 END(__read_lock_failed)
24335 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24336 index 5dff5f0..cadebf4 100644
24337 --- a/arch/x86/lib/rwsem.S
24338 +++ b/arch/x86/lib/rwsem.S
24339 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24340 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24341 CFI_RESTORE __ASM_REG(dx)
24342 restore_common_regs
24343 + pax_force_retaddr
24344 ret
24345 CFI_ENDPROC
24346 ENDPROC(call_rwsem_down_read_failed)
24347 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24348 movq %rax,%rdi
24349 call rwsem_down_write_failed
24350 restore_common_regs
24351 + pax_force_retaddr
24352 ret
24353 CFI_ENDPROC
24354 ENDPROC(call_rwsem_down_write_failed)
24355 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24356 movq %rax,%rdi
24357 call rwsem_wake
24358 restore_common_regs
24359 -1: ret
24360 +1: pax_force_retaddr
24361 + ret
24362 CFI_ENDPROC
24363 ENDPROC(call_rwsem_wake)
24364
24365 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24366 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24367 CFI_RESTORE __ASM_REG(dx)
24368 restore_common_regs
24369 + pax_force_retaddr
24370 ret
24371 CFI_ENDPROC
24372 ENDPROC(call_rwsem_downgrade_wake)
24373 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24374 index a63efd6..ccecad8 100644
24375 --- a/arch/x86/lib/thunk_64.S
24376 +++ b/arch/x86/lib/thunk_64.S
24377 @@ -8,6 +8,7 @@
24378 #include <linux/linkage.h>
24379 #include <asm/dwarf2.h>
24380 #include <asm/calling.h>
24381 +#include <asm/alternative-asm.h>
24382
24383 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24384 .macro THUNK name, func, put_ret_addr_in_rdi=0
24385 @@ -41,5 +42,6 @@
24386 SAVE_ARGS
24387 restore:
24388 RESTORE_ARGS
24389 + pax_force_retaddr
24390 ret
24391 CFI_ENDPROC
24392 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24393 index 98f6d6b6..d27f045 100644
24394 --- a/arch/x86/lib/usercopy_32.c
24395 +++ b/arch/x86/lib/usercopy_32.c
24396 @@ -42,11 +42,13 @@ do { \
24397 int __d0; \
24398 might_fault(); \
24399 __asm__ __volatile__( \
24400 + __COPYUSER_SET_ES \
24401 ASM_STAC "\n" \
24402 "0: rep; stosl\n" \
24403 " movl %2,%0\n" \
24404 "1: rep; stosb\n" \
24405 "2: " ASM_CLAC "\n" \
24406 + __COPYUSER_RESTORE_ES \
24407 ".section .fixup,\"ax\"\n" \
24408 "3: lea 0(%2,%0,4),%0\n" \
24409 " jmp 2b\n" \
24410 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24411
24412 #ifdef CONFIG_X86_INTEL_USERCOPY
24413 static unsigned long
24414 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
24415 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24416 {
24417 int d0, d1;
24418 __asm__ __volatile__(
24419 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24420 " .align 2,0x90\n"
24421 "3: movl 0(%4), %%eax\n"
24422 "4: movl 4(%4), %%edx\n"
24423 - "5: movl %%eax, 0(%3)\n"
24424 - "6: movl %%edx, 4(%3)\n"
24425 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24426 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24427 "7: movl 8(%4), %%eax\n"
24428 "8: movl 12(%4),%%edx\n"
24429 - "9: movl %%eax, 8(%3)\n"
24430 - "10: movl %%edx, 12(%3)\n"
24431 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24432 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24433 "11: movl 16(%4), %%eax\n"
24434 "12: movl 20(%4), %%edx\n"
24435 - "13: movl %%eax, 16(%3)\n"
24436 - "14: movl %%edx, 20(%3)\n"
24437 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24438 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24439 "15: movl 24(%4), %%eax\n"
24440 "16: movl 28(%4), %%edx\n"
24441 - "17: movl %%eax, 24(%3)\n"
24442 - "18: movl %%edx, 28(%3)\n"
24443 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24444 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24445 "19: movl 32(%4), %%eax\n"
24446 "20: movl 36(%4), %%edx\n"
24447 - "21: movl %%eax, 32(%3)\n"
24448 - "22: movl %%edx, 36(%3)\n"
24449 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24450 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24451 "23: movl 40(%4), %%eax\n"
24452 "24: movl 44(%4), %%edx\n"
24453 - "25: movl %%eax, 40(%3)\n"
24454 - "26: movl %%edx, 44(%3)\n"
24455 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24456 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24457 "27: movl 48(%4), %%eax\n"
24458 "28: movl 52(%4), %%edx\n"
24459 - "29: movl %%eax, 48(%3)\n"
24460 - "30: movl %%edx, 52(%3)\n"
24461 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24462 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24463 "31: movl 56(%4), %%eax\n"
24464 "32: movl 60(%4), %%edx\n"
24465 - "33: movl %%eax, 56(%3)\n"
24466 - "34: movl %%edx, 60(%3)\n"
24467 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24468 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24469 " addl $-64, %0\n"
24470 " addl $64, %4\n"
24471 " addl $64, %3\n"
24472 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24473 " shrl $2, %0\n"
24474 " andl $3, %%eax\n"
24475 " cld\n"
24476 + __COPYUSER_SET_ES
24477 "99: rep; movsl\n"
24478 "36: movl %%eax, %0\n"
24479 "37: rep; movsb\n"
24480 "100:\n"
24481 + __COPYUSER_RESTORE_ES
24482 ".section .fixup,\"ax\"\n"
24483 "101: lea 0(%%eax,%0,4),%0\n"
24484 " jmp 100b\n"
24485 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24486 }
24487
24488 static unsigned long
24489 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24490 +{
24491 + int d0, d1;
24492 + __asm__ __volatile__(
24493 + " .align 2,0x90\n"
24494 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24495 + " cmpl $67, %0\n"
24496 + " jbe 3f\n"
24497 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24498 + " .align 2,0x90\n"
24499 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24500 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24501 + "5: movl %%eax, 0(%3)\n"
24502 + "6: movl %%edx, 4(%3)\n"
24503 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24504 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24505 + "9: movl %%eax, 8(%3)\n"
24506 + "10: movl %%edx, 12(%3)\n"
24507 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24508 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24509 + "13: movl %%eax, 16(%3)\n"
24510 + "14: movl %%edx, 20(%3)\n"
24511 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24512 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24513 + "17: movl %%eax, 24(%3)\n"
24514 + "18: movl %%edx, 28(%3)\n"
24515 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24516 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24517 + "21: movl %%eax, 32(%3)\n"
24518 + "22: movl %%edx, 36(%3)\n"
24519 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24520 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24521 + "25: movl %%eax, 40(%3)\n"
24522 + "26: movl %%edx, 44(%3)\n"
24523 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24524 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24525 + "29: movl %%eax, 48(%3)\n"
24526 + "30: movl %%edx, 52(%3)\n"
24527 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24528 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24529 + "33: movl %%eax, 56(%3)\n"
24530 + "34: movl %%edx, 60(%3)\n"
24531 + " addl $-64, %0\n"
24532 + " addl $64, %4\n"
24533 + " addl $64, %3\n"
24534 + " cmpl $63, %0\n"
24535 + " ja 1b\n"
24536 + "35: movl %0, %%eax\n"
24537 + " shrl $2, %0\n"
24538 + " andl $3, %%eax\n"
24539 + " cld\n"
24540 + "99: rep; "__copyuser_seg" movsl\n"
24541 + "36: movl %%eax, %0\n"
24542 + "37: rep; "__copyuser_seg" movsb\n"
24543 + "100:\n"
24544 + ".section .fixup,\"ax\"\n"
24545 + "101: lea 0(%%eax,%0,4),%0\n"
24546 + " jmp 100b\n"
24547 + ".previous\n"
24548 + _ASM_EXTABLE(1b,100b)
24549 + _ASM_EXTABLE(2b,100b)
24550 + _ASM_EXTABLE(3b,100b)
24551 + _ASM_EXTABLE(4b,100b)
24552 + _ASM_EXTABLE(5b,100b)
24553 + _ASM_EXTABLE(6b,100b)
24554 + _ASM_EXTABLE(7b,100b)
24555 + _ASM_EXTABLE(8b,100b)
24556 + _ASM_EXTABLE(9b,100b)
24557 + _ASM_EXTABLE(10b,100b)
24558 + _ASM_EXTABLE(11b,100b)
24559 + _ASM_EXTABLE(12b,100b)
24560 + _ASM_EXTABLE(13b,100b)
24561 + _ASM_EXTABLE(14b,100b)
24562 + _ASM_EXTABLE(15b,100b)
24563 + _ASM_EXTABLE(16b,100b)
24564 + _ASM_EXTABLE(17b,100b)
24565 + _ASM_EXTABLE(18b,100b)
24566 + _ASM_EXTABLE(19b,100b)
24567 + _ASM_EXTABLE(20b,100b)
24568 + _ASM_EXTABLE(21b,100b)
24569 + _ASM_EXTABLE(22b,100b)
24570 + _ASM_EXTABLE(23b,100b)
24571 + _ASM_EXTABLE(24b,100b)
24572 + _ASM_EXTABLE(25b,100b)
24573 + _ASM_EXTABLE(26b,100b)
24574 + _ASM_EXTABLE(27b,100b)
24575 + _ASM_EXTABLE(28b,100b)
24576 + _ASM_EXTABLE(29b,100b)
24577 + _ASM_EXTABLE(30b,100b)
24578 + _ASM_EXTABLE(31b,100b)
24579 + _ASM_EXTABLE(32b,100b)
24580 + _ASM_EXTABLE(33b,100b)
24581 + _ASM_EXTABLE(34b,100b)
24582 + _ASM_EXTABLE(35b,100b)
24583 + _ASM_EXTABLE(36b,100b)
24584 + _ASM_EXTABLE(37b,100b)
24585 + _ASM_EXTABLE(99b,101b)
24586 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
24587 + : "1"(to), "2"(from), "0"(size)
24588 + : "eax", "edx", "memory");
24589 + return size;
24590 +}
24591 +
24592 +static unsigned long __size_overflow(3)
24593 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24594 {
24595 int d0, d1;
24596 __asm__ __volatile__(
24597 " .align 2,0x90\n"
24598 - "0: movl 32(%4), %%eax\n"
24599 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24600 " cmpl $67, %0\n"
24601 " jbe 2f\n"
24602 - "1: movl 64(%4), %%eax\n"
24603 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24604 " .align 2,0x90\n"
24605 - "2: movl 0(%4), %%eax\n"
24606 - "21: movl 4(%4), %%edx\n"
24607 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24608 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24609 " movl %%eax, 0(%3)\n"
24610 " movl %%edx, 4(%3)\n"
24611 - "3: movl 8(%4), %%eax\n"
24612 - "31: movl 12(%4),%%edx\n"
24613 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24614 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24615 " movl %%eax, 8(%3)\n"
24616 " movl %%edx, 12(%3)\n"
24617 - "4: movl 16(%4), %%eax\n"
24618 - "41: movl 20(%4), %%edx\n"
24619 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24620 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24621 " movl %%eax, 16(%3)\n"
24622 " movl %%edx, 20(%3)\n"
24623 - "10: movl 24(%4), %%eax\n"
24624 - "51: movl 28(%4), %%edx\n"
24625 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24626 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24627 " movl %%eax, 24(%3)\n"
24628 " movl %%edx, 28(%3)\n"
24629 - "11: movl 32(%4), %%eax\n"
24630 - "61: movl 36(%4), %%edx\n"
24631 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24632 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24633 " movl %%eax, 32(%3)\n"
24634 " movl %%edx, 36(%3)\n"
24635 - "12: movl 40(%4), %%eax\n"
24636 - "71: movl 44(%4), %%edx\n"
24637 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24638 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24639 " movl %%eax, 40(%3)\n"
24640 " movl %%edx, 44(%3)\n"
24641 - "13: movl 48(%4), %%eax\n"
24642 - "81: movl 52(%4), %%edx\n"
24643 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24644 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24645 " movl %%eax, 48(%3)\n"
24646 " movl %%edx, 52(%3)\n"
24647 - "14: movl 56(%4), %%eax\n"
24648 - "91: movl 60(%4), %%edx\n"
24649 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24650 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24651 " movl %%eax, 56(%3)\n"
24652 " movl %%edx, 60(%3)\n"
24653 " addl $-64, %0\n"
24654 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24655 " shrl $2, %0\n"
24656 " andl $3, %%eax\n"
24657 " cld\n"
24658 - "6: rep; movsl\n"
24659 + "6: rep; "__copyuser_seg" movsl\n"
24660 " movl %%eax,%0\n"
24661 - "7: rep; movsb\n"
24662 + "7: rep; "__copyuser_seg" movsb\n"
24663 "8:\n"
24664 ".section .fixup,\"ax\"\n"
24665 "9: lea 0(%%eax,%0,4),%0\n"
24666 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24667 * hyoshiok@miraclelinux.com
24668 */
24669
24670 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24671 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24672 const void __user *from, unsigned long size)
24673 {
24674 int d0, d1;
24675
24676 __asm__ __volatile__(
24677 " .align 2,0x90\n"
24678 - "0: movl 32(%4), %%eax\n"
24679 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24680 " cmpl $67, %0\n"
24681 " jbe 2f\n"
24682 - "1: movl 64(%4), %%eax\n"
24683 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24684 " .align 2,0x90\n"
24685 - "2: movl 0(%4), %%eax\n"
24686 - "21: movl 4(%4), %%edx\n"
24687 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24688 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24689 " movnti %%eax, 0(%3)\n"
24690 " movnti %%edx, 4(%3)\n"
24691 - "3: movl 8(%4), %%eax\n"
24692 - "31: movl 12(%4),%%edx\n"
24693 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24694 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24695 " movnti %%eax, 8(%3)\n"
24696 " movnti %%edx, 12(%3)\n"
24697 - "4: movl 16(%4), %%eax\n"
24698 - "41: movl 20(%4), %%edx\n"
24699 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24700 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24701 " movnti %%eax, 16(%3)\n"
24702 " movnti %%edx, 20(%3)\n"
24703 - "10: movl 24(%4), %%eax\n"
24704 - "51: movl 28(%4), %%edx\n"
24705 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24706 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24707 " movnti %%eax, 24(%3)\n"
24708 " movnti %%edx, 28(%3)\n"
24709 - "11: movl 32(%4), %%eax\n"
24710 - "61: movl 36(%4), %%edx\n"
24711 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24712 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24713 " movnti %%eax, 32(%3)\n"
24714 " movnti %%edx, 36(%3)\n"
24715 - "12: movl 40(%4), %%eax\n"
24716 - "71: movl 44(%4), %%edx\n"
24717 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24718 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24719 " movnti %%eax, 40(%3)\n"
24720 " movnti %%edx, 44(%3)\n"
24721 - "13: movl 48(%4), %%eax\n"
24722 - "81: movl 52(%4), %%edx\n"
24723 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24724 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24725 " movnti %%eax, 48(%3)\n"
24726 " movnti %%edx, 52(%3)\n"
24727 - "14: movl 56(%4), %%eax\n"
24728 - "91: movl 60(%4), %%edx\n"
24729 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24730 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24731 " movnti %%eax, 56(%3)\n"
24732 " movnti %%edx, 60(%3)\n"
24733 " addl $-64, %0\n"
24734 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24735 " shrl $2, %0\n"
24736 " andl $3, %%eax\n"
24737 " cld\n"
24738 - "6: rep; movsl\n"
24739 + "6: rep; "__copyuser_seg" movsl\n"
24740 " movl %%eax,%0\n"
24741 - "7: rep; movsb\n"
24742 + "7: rep; "__copyuser_seg" movsb\n"
24743 "8:\n"
24744 ".section .fixup,\"ax\"\n"
24745 "9: lea 0(%%eax,%0,4),%0\n"
24746 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24747 return size;
24748 }
24749
24750 -static unsigned long __copy_user_intel_nocache(void *to,
24751 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24752 const void __user *from, unsigned long size)
24753 {
24754 int d0, d1;
24755
24756 __asm__ __volatile__(
24757 " .align 2,0x90\n"
24758 - "0: movl 32(%4), %%eax\n"
24759 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24760 " cmpl $67, %0\n"
24761 " jbe 2f\n"
24762 - "1: movl 64(%4), %%eax\n"
24763 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24764 " .align 2,0x90\n"
24765 - "2: movl 0(%4), %%eax\n"
24766 - "21: movl 4(%4), %%edx\n"
24767 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24768 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24769 " movnti %%eax, 0(%3)\n"
24770 " movnti %%edx, 4(%3)\n"
24771 - "3: movl 8(%4), %%eax\n"
24772 - "31: movl 12(%4),%%edx\n"
24773 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24774 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24775 " movnti %%eax, 8(%3)\n"
24776 " movnti %%edx, 12(%3)\n"
24777 - "4: movl 16(%4), %%eax\n"
24778 - "41: movl 20(%4), %%edx\n"
24779 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24780 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24781 " movnti %%eax, 16(%3)\n"
24782 " movnti %%edx, 20(%3)\n"
24783 - "10: movl 24(%4), %%eax\n"
24784 - "51: movl 28(%4), %%edx\n"
24785 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24786 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24787 " movnti %%eax, 24(%3)\n"
24788 " movnti %%edx, 28(%3)\n"
24789 - "11: movl 32(%4), %%eax\n"
24790 - "61: movl 36(%4), %%edx\n"
24791 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24792 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24793 " movnti %%eax, 32(%3)\n"
24794 " movnti %%edx, 36(%3)\n"
24795 - "12: movl 40(%4), %%eax\n"
24796 - "71: movl 44(%4), %%edx\n"
24797 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24798 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24799 " movnti %%eax, 40(%3)\n"
24800 " movnti %%edx, 44(%3)\n"
24801 - "13: movl 48(%4), %%eax\n"
24802 - "81: movl 52(%4), %%edx\n"
24803 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24804 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24805 " movnti %%eax, 48(%3)\n"
24806 " movnti %%edx, 52(%3)\n"
24807 - "14: movl 56(%4), %%eax\n"
24808 - "91: movl 60(%4), %%edx\n"
24809 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24810 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24811 " movnti %%eax, 56(%3)\n"
24812 " movnti %%edx, 60(%3)\n"
24813 " addl $-64, %0\n"
24814 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24815 " shrl $2, %0\n"
24816 " andl $3, %%eax\n"
24817 " cld\n"
24818 - "6: rep; movsl\n"
24819 + "6: rep; "__copyuser_seg" movsl\n"
24820 " movl %%eax,%0\n"
24821 - "7: rep; movsb\n"
24822 + "7: rep; "__copyuser_seg" movsb\n"
24823 "8:\n"
24824 ".section .fixup,\"ax\"\n"
24825 "9: lea 0(%%eax,%0,4),%0\n"
24826 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24827 */
24828 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24829 unsigned long size);
24830 -unsigned long __copy_user_intel(void __user *to, const void *from,
24831 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24832 + unsigned long size);
24833 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24834 unsigned long size);
24835 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24836 const void __user *from, unsigned long size);
24837 #endif /* CONFIG_X86_INTEL_USERCOPY */
24838
24839 /* Generic arbitrary sized copy. */
24840 -#define __copy_user(to, from, size) \
24841 +#define __copy_user(to, from, size, prefix, set, restore) \
24842 do { \
24843 int __d0, __d1, __d2; \
24844 __asm__ __volatile__( \
24845 + set \
24846 " cmp $7,%0\n" \
24847 " jbe 1f\n" \
24848 " movl %1,%0\n" \
24849 " negl %0\n" \
24850 " andl $7,%0\n" \
24851 " subl %0,%3\n" \
24852 - "4: rep; movsb\n" \
24853 + "4: rep; "prefix"movsb\n" \
24854 " movl %3,%0\n" \
24855 " shrl $2,%0\n" \
24856 " andl $3,%3\n" \
24857 " .align 2,0x90\n" \
24858 - "0: rep; movsl\n" \
24859 + "0: rep; "prefix"movsl\n" \
24860 " movl %3,%0\n" \
24861 - "1: rep; movsb\n" \
24862 + "1: rep; "prefix"movsb\n" \
24863 "2:\n" \
24864 + restore \
24865 ".section .fixup,\"ax\"\n" \
24866 "5: addl %3,%0\n" \
24867 " jmp 2b\n" \
24868 @@ -538,14 +650,14 @@ do { \
24869 " negl %0\n" \
24870 " andl $7,%0\n" \
24871 " subl %0,%3\n" \
24872 - "4: rep; movsb\n" \
24873 + "4: rep; "__copyuser_seg"movsb\n" \
24874 " movl %3,%0\n" \
24875 " shrl $2,%0\n" \
24876 " andl $3,%3\n" \
24877 " .align 2,0x90\n" \
24878 - "0: rep; movsl\n" \
24879 + "0: rep; "__copyuser_seg"movsl\n" \
24880 " movl %3,%0\n" \
24881 - "1: rep; movsb\n" \
24882 + "1: rep; "__copyuser_seg"movsb\n" \
24883 "2:\n" \
24884 ".section .fixup,\"ax\"\n" \
24885 "5: addl %3,%0\n" \
24886 @@ -629,9 +741,9 @@ survive:
24887 #endif
24888 stac();
24889 if (movsl_is_ok(to, from, n))
24890 - __copy_user(to, from, n);
24891 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24892 else
24893 - n = __copy_user_intel(to, from, n);
24894 + n = __generic_copy_to_user_intel(to, from, n);
24895 clac();
24896 return n;
24897 }
24898 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24899 {
24900 stac();
24901 if (movsl_is_ok(to, from, n))
24902 - __copy_user(to, from, n);
24903 + __copy_user(to, from, n, __copyuser_seg, "", "");
24904 else
24905 - n = __copy_user_intel((void __user *)to,
24906 - (const void *)from, n);
24907 + n = __generic_copy_from_user_intel(to, from, n);
24908 clac();
24909 return n;
24910 }
24911 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24912 if (n > 64 && cpu_has_xmm2)
24913 n = __copy_user_intel_nocache(to, from, n);
24914 else
24915 - __copy_user(to, from, n);
24916 + __copy_user(to, from, n, __copyuser_seg, "", "");
24917 #else
24918 - __copy_user(to, from, n);
24919 + __copy_user(to, from, n, __copyuser_seg, "", "");
24920 #endif
24921 clac();
24922 return n;
24923 }
24924 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24925
24926 -/**
24927 - * copy_to_user: - Copy a block of data into user space.
24928 - * @to: Destination address, in user space.
24929 - * @from: Source address, in kernel space.
24930 - * @n: Number of bytes to copy.
24931 - *
24932 - * Context: User context only. This function may sleep.
24933 - *
24934 - * Copy data from kernel space to user space.
24935 - *
24936 - * Returns number of bytes that could not be copied.
24937 - * On success, this will be zero.
24938 - */
24939 -unsigned long
24940 -copy_to_user(void __user *to, const void *from, unsigned long n)
24941 -{
24942 - if (access_ok(VERIFY_WRITE, to, n))
24943 - n = __copy_to_user(to, from, n);
24944 - return n;
24945 -}
24946 -EXPORT_SYMBOL(copy_to_user);
24947 -
24948 -/**
24949 - * copy_from_user: - Copy a block of data from user space.
24950 - * @to: Destination address, in kernel space.
24951 - * @from: Source address, in user space.
24952 - * @n: Number of bytes to copy.
24953 - *
24954 - * Context: User context only. This function may sleep.
24955 - *
24956 - * Copy data from user space to kernel space.
24957 - *
24958 - * Returns number of bytes that could not be copied.
24959 - * On success, this will be zero.
24960 - *
24961 - * If some data could not be copied, this function will pad the copied
24962 - * data to the requested size using zero bytes.
24963 - */
24964 -unsigned long
24965 -_copy_from_user(void *to, const void __user *from, unsigned long n)
24966 -{
24967 - if (access_ok(VERIFY_READ, from, n))
24968 - n = __copy_from_user(to, from, n);
24969 - else
24970 - memset(to, 0, n);
24971 - return n;
24972 -}
24973 -EXPORT_SYMBOL(_copy_from_user);
24974 -
24975 void copy_from_user_overflow(void)
24976 {
24977 WARN(1, "Buffer overflow detected!\n");
24978 }
24979 EXPORT_SYMBOL(copy_from_user_overflow);
24980 +
24981 +void copy_to_user_overflow(void)
24982 +{
24983 + WARN(1, "Buffer overflow detected!\n");
24984 +}
24985 +EXPORT_SYMBOL(copy_to_user_overflow);
24986 +
24987 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24988 +void __set_fs(mm_segment_t x)
24989 +{
24990 + switch (x.seg) {
24991 + case 0:
24992 + loadsegment(gs, 0);
24993 + break;
24994 + case TASK_SIZE_MAX:
24995 + loadsegment(gs, __USER_DS);
24996 + break;
24997 + case -1UL:
24998 + loadsegment(gs, __KERNEL_DS);
24999 + break;
25000 + default:
25001 + BUG();
25002 + }
25003 + return;
25004 +}
25005 +EXPORT_SYMBOL(__set_fs);
25006 +
25007 +void set_fs(mm_segment_t x)
25008 +{
25009 + current_thread_info()->addr_limit = x;
25010 + __set_fs(x);
25011 +}
25012 +EXPORT_SYMBOL(set_fs);
25013 +#endif
25014 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
25015 index 05928aa..b33dea1 100644
25016 --- a/arch/x86/lib/usercopy_64.c
25017 +++ b/arch/x86/lib/usercopy_64.c
25018 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
25019 _ASM_EXTABLE(0b,3b)
25020 _ASM_EXTABLE(1b,2b)
25021 : [size8] "=&c"(size), [dst] "=&D" (__d0)
25022 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
25023 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
25024 [zero] "r" (0UL), [eight] "r" (8UL));
25025 clac();
25026 return size;
25027 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
25028 }
25029 EXPORT_SYMBOL(clear_user);
25030
25031 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
25032 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
25033 {
25034 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
25035 - return copy_user_generic((__force void *)to, (__force void *)from, len);
25036 - }
25037 - return len;
25038 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
25039 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
25040 + return len;
25041 }
25042 EXPORT_SYMBOL(copy_in_user);
25043
25044 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
25045 * it is not necessary to optimize tail handling.
25046 */
25047 unsigned long
25048 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25049 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
25050 {
25051 char c;
25052 unsigned zero_len;
25053 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25054 clac();
25055 return len;
25056 }
25057 +
25058 +void copy_from_user_overflow(void)
25059 +{
25060 + WARN(1, "Buffer overflow detected!\n");
25061 +}
25062 +EXPORT_SYMBOL(copy_from_user_overflow);
25063 +
25064 +void copy_to_user_overflow(void)
25065 +{
25066 + WARN(1, "Buffer overflow detected!\n");
25067 +}
25068 +EXPORT_SYMBOL(copy_to_user_overflow);
25069 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
25070 index 903ec1e..c4166b2 100644
25071 --- a/arch/x86/mm/extable.c
25072 +++ b/arch/x86/mm/extable.c
25073 @@ -6,12 +6,24 @@
25074 static inline unsigned long
25075 ex_insn_addr(const struct exception_table_entry *x)
25076 {
25077 - return (unsigned long)&x->insn + x->insn;
25078 + unsigned long reloc = 0;
25079 +
25080 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25081 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25082 +#endif
25083 +
25084 + return (unsigned long)&x->insn + x->insn + reloc;
25085 }
25086 static inline unsigned long
25087 ex_fixup_addr(const struct exception_table_entry *x)
25088 {
25089 - return (unsigned long)&x->fixup + x->fixup;
25090 + unsigned long reloc = 0;
25091 +
25092 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25093 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25094 +#endif
25095 +
25096 + return (unsigned long)&x->fixup + x->fixup + reloc;
25097 }
25098
25099 int fixup_exception(struct pt_regs *regs)
25100 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
25101 unsigned long new_ip;
25102
25103 #ifdef CONFIG_PNPBIOS
25104 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
25105 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
25106 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
25107 extern u32 pnp_bios_is_utter_crap;
25108 pnp_bios_is_utter_crap = 1;
25109 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
25110 i += 4;
25111 p->fixup -= i;
25112 i += 4;
25113 +
25114 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25115 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
25116 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25117 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25118 +#endif
25119 +
25120 }
25121 }
25122
25123 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
25124 index 8e13ecb..60bf506 100644
25125 --- a/arch/x86/mm/fault.c
25126 +++ b/arch/x86/mm/fault.c
25127 @@ -13,12 +13,19 @@
25128 #include <linux/perf_event.h> /* perf_sw_event */
25129 #include <linux/hugetlb.h> /* hstate_index_to_shift */
25130 #include <linux/prefetch.h> /* prefetchw */
25131 +#include <linux/unistd.h>
25132 +#include <linux/compiler.h>
25133
25134 #include <asm/traps.h> /* dotraplinkage, ... */
25135 #include <asm/pgalloc.h> /* pgd_*(), ... */
25136 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
25137 #include <asm/fixmap.h> /* VSYSCALL_START */
25138 #include <asm/rcu.h> /* exception_enter(), ... */
25139 +#include <asm/tlbflush.h>
25140 +
25141 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25142 +#include <asm/stacktrace.h>
25143 +#endif
25144
25145 /*
25146 * Page fault error code bits:
25147 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
25148 int ret = 0;
25149
25150 /* kprobe_running() needs smp_processor_id() */
25151 - if (kprobes_built_in() && !user_mode_vm(regs)) {
25152 + if (kprobes_built_in() && !user_mode(regs)) {
25153 preempt_disable();
25154 if (kprobe_running() && kprobe_fault_handler(regs, 14))
25155 ret = 1;
25156 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
25157 return !instr_lo || (instr_lo>>1) == 1;
25158 case 0x00:
25159 /* Prefetch instruction is 0x0F0D or 0x0F18 */
25160 - if (probe_kernel_address(instr, opcode))
25161 + if (user_mode(regs)) {
25162 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25163 + return 0;
25164 + } else if (probe_kernel_address(instr, opcode))
25165 return 0;
25166
25167 *prefetch = (instr_lo == 0xF) &&
25168 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
25169 while (instr < max_instr) {
25170 unsigned char opcode;
25171
25172 - if (probe_kernel_address(instr, opcode))
25173 + if (user_mode(regs)) {
25174 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25175 + break;
25176 + } else if (probe_kernel_address(instr, opcode))
25177 break;
25178
25179 instr++;
25180 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
25181 force_sig_info(si_signo, &info, tsk);
25182 }
25183
25184 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25185 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
25186 +#endif
25187 +
25188 +#ifdef CONFIG_PAX_EMUTRAMP
25189 +static int pax_handle_fetch_fault(struct pt_regs *regs);
25190 +#endif
25191 +
25192 +#ifdef CONFIG_PAX_PAGEEXEC
25193 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
25194 +{
25195 + pgd_t *pgd;
25196 + pud_t *pud;
25197 + pmd_t *pmd;
25198 +
25199 + pgd = pgd_offset(mm, address);
25200 + if (!pgd_present(*pgd))
25201 + return NULL;
25202 + pud = pud_offset(pgd, address);
25203 + if (!pud_present(*pud))
25204 + return NULL;
25205 + pmd = pmd_offset(pud, address);
25206 + if (!pmd_present(*pmd))
25207 + return NULL;
25208 + return pmd;
25209 +}
25210 +#endif
25211 +
25212 DEFINE_SPINLOCK(pgd_lock);
25213 LIST_HEAD(pgd_list);
25214
25215 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
25216 for (address = VMALLOC_START & PMD_MASK;
25217 address >= TASK_SIZE && address < FIXADDR_TOP;
25218 address += PMD_SIZE) {
25219 +
25220 +#ifdef CONFIG_PAX_PER_CPU_PGD
25221 + unsigned long cpu;
25222 +#else
25223 struct page *page;
25224 +#endif
25225
25226 spin_lock(&pgd_lock);
25227 +
25228 +#ifdef CONFIG_PAX_PER_CPU_PGD
25229 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25230 + pgd_t *pgd = get_cpu_pgd(cpu);
25231 + pmd_t *ret;
25232 +#else
25233 list_for_each_entry(page, &pgd_list, lru) {
25234 + pgd_t *pgd = page_address(page);
25235 spinlock_t *pgt_lock;
25236 pmd_t *ret;
25237
25238 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
25239 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25240
25241 spin_lock(pgt_lock);
25242 - ret = vmalloc_sync_one(page_address(page), address);
25243 +#endif
25244 +
25245 + ret = vmalloc_sync_one(pgd, address);
25246 +
25247 +#ifndef CONFIG_PAX_PER_CPU_PGD
25248 spin_unlock(pgt_lock);
25249 +#endif
25250
25251 if (!ret)
25252 break;
25253 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25254 * an interrupt in the middle of a task switch..
25255 */
25256 pgd_paddr = read_cr3();
25257 +
25258 +#ifdef CONFIG_PAX_PER_CPU_PGD
25259 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
25260 +#endif
25261 +
25262 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
25263 if (!pmd_k)
25264 return -1;
25265 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25266 * happen within a race in page table update. In the later
25267 * case just flush:
25268 */
25269 +
25270 +#ifdef CONFIG_PAX_PER_CPU_PGD
25271 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
25272 + pgd = pgd_offset_cpu(smp_processor_id(), address);
25273 +#else
25274 pgd = pgd_offset(current->active_mm, address);
25275 +#endif
25276 +
25277 pgd_ref = pgd_offset_k(address);
25278 if (pgd_none(*pgd_ref))
25279 return -1;
25280 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
25281 static int is_errata100(struct pt_regs *regs, unsigned long address)
25282 {
25283 #ifdef CONFIG_X86_64
25284 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
25285 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
25286 return 1;
25287 #endif
25288 return 0;
25289 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
25290 }
25291
25292 static const char nx_warning[] = KERN_CRIT
25293 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
25294 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
25295
25296 static void
25297 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25298 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25299 if (!oops_may_print())
25300 return;
25301
25302 - if (error_code & PF_INSTR) {
25303 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
25304 unsigned int level;
25305
25306 pte_t *pte = lookup_address(address, &level);
25307
25308 if (pte && pte_present(*pte) && !pte_exec(*pte))
25309 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
25310 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
25311 }
25312
25313 +#ifdef CONFIG_PAX_KERNEXEC
25314 + if (init_mm.start_code <= address && address < init_mm.end_code) {
25315 + if (current->signal->curr_ip)
25316 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25317 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
25318 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25319 + else
25320 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
25321 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25322 + }
25323 +#endif
25324 +
25325 printk(KERN_ALERT "BUG: unable to handle kernel ");
25326 if (address < PAGE_SIZE)
25327 printk(KERN_CONT "NULL pointer dereference");
25328 @@ -749,12 +831,30 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25329 }
25330 #endif
25331
25332 - if (unlikely(show_unhandled_signals))
25333 - show_signal_msg(regs, error_code, address, tsk);
25334 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25335 + if (pax_is_fetch_fault(regs, error_code, address)) {
25336 +
25337 +#ifdef CONFIG_PAX_EMUTRAMP
25338 + switch (pax_handle_fetch_fault(regs)) {
25339 + case 2:
25340 + return;
25341 + }
25342 +#endif
25343 +
25344 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25345 + do_group_exit(SIGKILL);
25346 + }
25347 +#endif
25348
25349 /* Kernel addresses are always protection faults: */
25350 + if (address >= TASK_SIZE)
25351 + error_code |= PF_PROT;
25352 +
25353 + if (show_unhandled_signals)
25354 + show_signal_msg(regs, error_code, address, tsk);
25355 +
25356 tsk->thread.cr2 = address;
25357 - tsk->thread.error_code = error_code | (address >= TASK_SIZE);
25358 + tsk->thread.error_code = error_code;
25359 tsk->thread.trap_nr = X86_TRAP_PF;
25360
25361 force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);
25362 @@ -845,7 +945,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25363 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25364 printk(KERN_ERR
25365 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25366 - tsk->comm, tsk->pid, address);
25367 + tsk->comm, task_pid_nr(tsk), address);
25368 code = BUS_MCEERR_AR;
25369 }
25370 #endif
25371 @@ -901,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25372 return 1;
25373 }
25374
25375 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25376 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25377 +{
25378 + pte_t *pte;
25379 + pmd_t *pmd;
25380 + spinlock_t *ptl;
25381 + unsigned char pte_mask;
25382 +
25383 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25384 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
25385 + return 0;
25386 +
25387 + /* PaX: it's our fault, let's handle it if we can */
25388 +
25389 + /* PaX: take a look at read faults before acquiring any locks */
25390 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25391 + /* instruction fetch attempt from a protected page in user mode */
25392 + up_read(&mm->mmap_sem);
25393 +
25394 +#ifdef CONFIG_PAX_EMUTRAMP
25395 + switch (pax_handle_fetch_fault(regs)) {
25396 + case 2:
25397 + return 1;
25398 + }
25399 +#endif
25400 +
25401 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25402 + do_group_exit(SIGKILL);
25403 + }
25404 +
25405 + pmd = pax_get_pmd(mm, address);
25406 + if (unlikely(!pmd))
25407 + return 0;
25408 +
25409 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25410 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25411 + pte_unmap_unlock(pte, ptl);
25412 + return 0;
25413 + }
25414 +
25415 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25416 + /* write attempt to a protected page in user mode */
25417 + pte_unmap_unlock(pte, ptl);
25418 + return 0;
25419 + }
25420 +
25421 +#ifdef CONFIG_SMP
25422 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25423 +#else
25424 + if (likely(address > get_limit(regs->cs)))
25425 +#endif
25426 + {
25427 + set_pte(pte, pte_mkread(*pte));
25428 + __flush_tlb_one(address);
25429 + pte_unmap_unlock(pte, ptl);
25430 + up_read(&mm->mmap_sem);
25431 + return 1;
25432 + }
25433 +
25434 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25435 +
25436 + /*
25437 + * PaX: fill DTLB with user rights and retry
25438 + */
25439 + __asm__ __volatile__ (
25440 + "orb %2,(%1)\n"
25441 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25442 +/*
25443 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25444 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25445 + * page fault when examined during a TLB load attempt. this is true not only
25446 + * for PTEs holding a non-present entry but also present entries that will
25447 + * raise a page fault (such as those set up by PaX, or the copy-on-write
25448 + * mechanism). in effect it means that we do *not* need to flush the TLBs
25449 + * for our target pages since their PTEs are simply not in the TLBs at all.
25450 +
25451 + * the best thing in omitting it is that we gain around 15-20% speed in the
25452 + * fast path of the page fault handler and can get rid of tracing since we
25453 + * can no longer flush unintended entries.
25454 + */
25455 + "invlpg (%0)\n"
25456 +#endif
25457 + __copyuser_seg"testb $0,(%0)\n"
25458 + "xorb %3,(%1)\n"
25459 + :
25460 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25461 + : "memory", "cc");
25462 + pte_unmap_unlock(pte, ptl);
25463 + up_read(&mm->mmap_sem);
25464 + return 1;
25465 +}
25466 +#endif
25467 +
25468 /*
25469 * Handle a spurious fault caused by a stale TLB entry.
25470 *
25471 @@ -973,6 +1166,9 @@ int show_unhandled_signals = 1;
25472 static inline int
25473 access_error(unsigned long error_code, struct vm_area_struct *vma)
25474 {
25475 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25476 + return 1;
25477 +
25478 if (error_code & PF_WRITE) {
25479 /* write, present and write, not present: */
25480 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25481 @@ -1001,7 +1197,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25482 if (error_code & PF_USER)
25483 return false;
25484
25485 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25486 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25487 return false;
25488
25489 return true;
25490 @@ -1017,18 +1213,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25491 {
25492 struct vm_area_struct *vma;
25493 struct task_struct *tsk;
25494 - unsigned long address;
25495 struct mm_struct *mm;
25496 int fault;
25497 int write = error_code & PF_WRITE;
25498 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25499 (write ? FAULT_FLAG_WRITE : 0);
25500
25501 - tsk = current;
25502 - mm = tsk->mm;
25503 -
25504 /* Get the faulting address: */
25505 - address = read_cr2();
25506 + unsigned long address = read_cr2();
25507 +
25508 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25509 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25510 + if (!search_exception_tables(regs->ip)) {
25511 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25512 + bad_area_nosemaphore(regs, error_code, address);
25513 + return;
25514 + }
25515 + if (address < PAX_USER_SHADOW_BASE) {
25516 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25517 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25518 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25519 + } else
25520 + address -= PAX_USER_SHADOW_BASE;
25521 + }
25522 +#endif
25523 +
25524 + tsk = current;
25525 + mm = tsk->mm;
25526
25527 /*
25528 * Detect and handle instructions that would cause a page fault for
25529 @@ -1089,7 +1300,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25530 * User-mode registers count as a user access even for any
25531 * potential system fault or CPU buglet:
25532 */
25533 - if (user_mode_vm(regs)) {
25534 + if (user_mode(regs)) {
25535 local_irq_enable();
25536 error_code |= PF_USER;
25537 } else {
25538 @@ -1151,6 +1362,11 @@ retry:
25539 might_sleep();
25540 }
25541
25542 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25543 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25544 + return;
25545 +#endif
25546 +
25547 vma = find_vma(mm, address);
25548 if (unlikely(!vma)) {
25549 bad_area(regs, error_code, address);
25550 @@ -1162,18 +1378,24 @@ retry:
25551 bad_area(regs, error_code, address);
25552 return;
25553 }
25554 - if (error_code & PF_USER) {
25555 - /*
25556 - * Accessing the stack below %sp is always a bug.
25557 - * The large cushion allows instructions like enter
25558 - * and pusha to work. ("enter $65535, $31" pushes
25559 - * 32 pointers and then decrements %sp by 65535.)
25560 - */
25561 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25562 - bad_area(regs, error_code, address);
25563 - return;
25564 - }
25565 + /*
25566 + * Accessing the stack below %sp is always a bug.
25567 + * The large cushion allows instructions like enter
25568 + * and pusha to work. ("enter $65535, $31" pushes
25569 + * 32 pointers and then decrements %sp by 65535.)
25570 + */
25571 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25572 + bad_area(regs, error_code, address);
25573 + return;
25574 }
25575 +
25576 +#ifdef CONFIG_PAX_SEGMEXEC
25577 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25578 + bad_area(regs, error_code, address);
25579 + return;
25580 + }
25581 +#endif
25582 +
25583 if (unlikely(expand_stack(vma, address))) {
25584 bad_area(regs, error_code, address);
25585 return;
25586 @@ -1237,3 +1459,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25587 __do_page_fault(regs, error_code);
25588 exception_exit(regs);
25589 }
25590 +
25591 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25592 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25593 +{
25594 + struct mm_struct *mm = current->mm;
25595 + unsigned long ip = regs->ip;
25596 +
25597 + if (v8086_mode(regs))
25598 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25599 +
25600 +#ifdef CONFIG_PAX_PAGEEXEC
25601 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25602 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25603 + return true;
25604 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25605 + return true;
25606 + return false;
25607 + }
25608 +#endif
25609 +
25610 +#ifdef CONFIG_PAX_SEGMEXEC
25611 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25612 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25613 + return true;
25614 + return false;
25615 + }
25616 +#endif
25617 +
25618 + return false;
25619 +}
25620 +#endif
25621 +
25622 +#ifdef CONFIG_PAX_EMUTRAMP
25623 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25624 +{
25625 + int err;
25626 +
25627 + do { /* PaX: libffi trampoline emulation */
25628 + unsigned char mov, jmp;
25629 + unsigned int addr1, addr2;
25630 +
25631 +#ifdef CONFIG_X86_64
25632 + if ((regs->ip + 9) >> 32)
25633 + break;
25634 +#endif
25635 +
25636 + err = get_user(mov, (unsigned char __user *)regs->ip);
25637 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25638 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25639 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25640 +
25641 + if (err)
25642 + break;
25643 +
25644 + if (mov == 0xB8 && jmp == 0xE9) {
25645 + regs->ax = addr1;
25646 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25647 + return 2;
25648 + }
25649 + } while (0);
25650 +
25651 + do { /* PaX: gcc trampoline emulation #1 */
25652 + unsigned char mov1, mov2;
25653 + unsigned short jmp;
25654 + unsigned int addr1, addr2;
25655 +
25656 +#ifdef CONFIG_X86_64
25657 + if ((regs->ip + 11) >> 32)
25658 + break;
25659 +#endif
25660 +
25661 + err = get_user(mov1, (unsigned char __user *)regs->ip);
25662 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25663 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25664 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25665 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25666 +
25667 + if (err)
25668 + break;
25669 +
25670 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25671 + regs->cx = addr1;
25672 + regs->ax = addr2;
25673 + regs->ip = addr2;
25674 + return 2;
25675 + }
25676 + } while (0);
25677 +
25678 + do { /* PaX: gcc trampoline emulation #2 */
25679 + unsigned char mov, jmp;
25680 + unsigned int addr1, addr2;
25681 +
25682 +#ifdef CONFIG_X86_64
25683 + if ((regs->ip + 9) >> 32)
25684 + break;
25685 +#endif
25686 +
25687 + err = get_user(mov, (unsigned char __user *)regs->ip);
25688 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25689 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25690 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25691 +
25692 + if (err)
25693 + break;
25694 +
25695 + if (mov == 0xB9 && jmp == 0xE9) {
25696 + regs->cx = addr1;
25697 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25698 + return 2;
25699 + }
25700 + } while (0);
25701 +
25702 + return 1; /* PaX in action */
25703 +}
25704 +
25705 +#ifdef CONFIG_X86_64
25706 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25707 +{
25708 + int err;
25709 +
25710 + do { /* PaX: libffi trampoline emulation */
25711 + unsigned short mov1, mov2, jmp1;
25712 + unsigned char stcclc, jmp2;
25713 + unsigned long addr1, addr2;
25714 +
25715 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25716 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25717 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25718 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25719 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25720 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25721 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25722 +
25723 + if (err)
25724 + break;
25725 +
25726 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25727 + regs->r11 = addr1;
25728 + regs->r10 = addr2;
25729 + if (stcclc == 0xF8)
25730 + regs->flags &= ~X86_EFLAGS_CF;
25731 + else
25732 + regs->flags |= X86_EFLAGS_CF;
25733 + regs->ip = addr1;
25734 + return 2;
25735 + }
25736 + } while (0);
25737 +
25738 + do { /* PaX: gcc trampoline emulation #1 */
25739 + unsigned short mov1, mov2, jmp1;
25740 + unsigned char jmp2;
25741 + unsigned int addr1;
25742 + unsigned long addr2;
25743 +
25744 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25745 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25746 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25747 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25748 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25749 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25750 +
25751 + if (err)
25752 + break;
25753 +
25754 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25755 + regs->r11 = addr1;
25756 + regs->r10 = addr2;
25757 + regs->ip = addr1;
25758 + return 2;
25759 + }
25760 + } while (0);
25761 +
25762 + do { /* PaX: gcc trampoline emulation #2 */
25763 + unsigned short mov1, mov2, jmp1;
25764 + unsigned char jmp2;
25765 + unsigned long addr1, addr2;
25766 +
25767 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25768 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25769 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25770 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25771 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25772 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25773 +
25774 + if (err)
25775 + break;
25776 +
25777 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25778 + regs->r11 = addr1;
25779 + regs->r10 = addr2;
25780 + regs->ip = addr1;
25781 + return 2;
25782 + }
25783 + } while (0);
25784 +
25785 + return 1; /* PaX in action */
25786 +}
25787 +#endif
25788 +
25789 +/*
25790 + * PaX: decide what to do with offenders (regs->ip = fault address)
25791 + *
25792 + * returns 1 when task should be killed
25793 + * 2 when gcc trampoline was detected
25794 + */
25795 +static int pax_handle_fetch_fault(struct pt_regs *regs)
25796 +{
25797 + if (v8086_mode(regs))
25798 + return 1;
25799 +
25800 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25801 + return 1;
25802 +
25803 +#ifdef CONFIG_X86_32
25804 + return pax_handle_fetch_fault_32(regs);
25805 +#else
25806 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25807 + return pax_handle_fetch_fault_32(regs);
25808 + else
25809 + return pax_handle_fetch_fault_64(regs);
25810 +#endif
25811 +}
25812 +#endif
25813 +
25814 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25815 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25816 +{
25817 + long i;
25818 +
25819 + printk(KERN_ERR "PAX: bytes at PC: ");
25820 + for (i = 0; i < 20; i++) {
25821 + unsigned char c;
25822 + if (get_user(c, (unsigned char __force_user *)pc+i))
25823 + printk(KERN_CONT "?? ");
25824 + else
25825 + printk(KERN_CONT "%02x ", c);
25826 + }
25827 + printk("\n");
25828 +
25829 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25830 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
25831 + unsigned long c;
25832 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
25833 +#ifdef CONFIG_X86_32
25834 + printk(KERN_CONT "???????? ");
25835 +#else
25836 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25837 + printk(KERN_CONT "???????? ???????? ");
25838 + else
25839 + printk(KERN_CONT "???????????????? ");
25840 +#endif
25841 + } else {
25842 +#ifdef CONFIG_X86_64
25843 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25844 + printk(KERN_CONT "%08x ", (unsigned int)c);
25845 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25846 + } else
25847 +#endif
25848 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25849 + }
25850 + }
25851 + printk("\n");
25852 +}
25853 +#endif
25854 +
25855 +/**
25856 + * probe_kernel_write(): safely attempt to write to a location
25857 + * @dst: address to write to
25858 + * @src: pointer to the data that shall be written
25859 + * @size: size of the data chunk
25860 + *
25861 + * Safely write to address @dst from the buffer at @src. If a kernel fault
25862 + * happens, handle that and return -EFAULT.
25863 + */
25864 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25865 +{
25866 + long ret;
25867 + mm_segment_t old_fs = get_fs();
25868 +
25869 + set_fs(KERNEL_DS);
25870 + pagefault_disable();
25871 + pax_open_kernel();
25872 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25873 + pax_close_kernel();
25874 + pagefault_enable();
25875 + set_fs(old_fs);
25876 +
25877 + return ret ? -EFAULT : 0;
25878 +}
25879 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25880 index dd74e46..7d26398 100644
25881 --- a/arch/x86/mm/gup.c
25882 +++ b/arch/x86/mm/gup.c
25883 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25884 addr = start;
25885 len = (unsigned long) nr_pages << PAGE_SHIFT;
25886 end = start + len;
25887 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25888 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25889 (void __user *)start, len)))
25890 return 0;
25891
25892 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25893 index 6f31ee5..8ee4164 100644
25894 --- a/arch/x86/mm/highmem_32.c
25895 +++ b/arch/x86/mm/highmem_32.c
25896 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25897 idx = type + KM_TYPE_NR*smp_processor_id();
25898 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25899 BUG_ON(!pte_none(*(kmap_pte-idx)));
25900 +
25901 + pax_open_kernel();
25902 set_pte(kmap_pte-idx, mk_pte(page, prot));
25903 + pax_close_kernel();
25904 +
25905 arch_flush_lazy_mmu_mode();
25906
25907 return (void *)vaddr;
25908 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25909 index 937bff5..dce75ff 100644
25910 --- a/arch/x86/mm/hugetlbpage.c
25911 +++ b/arch/x86/mm/hugetlbpage.c
25912 @@ -276,13 +276,21 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25913 struct hstate *h = hstate_file(file);
25914 struct mm_struct *mm = current->mm;
25915 struct vm_area_struct *vma;
25916 - unsigned long start_addr;
25917 + unsigned long start_addr, pax_task_size = TASK_SIZE;
25918 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25919 +
25920 +#ifdef CONFIG_PAX_SEGMEXEC
25921 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25922 + pax_task_size = SEGMEXEC_TASK_SIZE;
25923 +#endif
25924 +
25925 + pax_task_size -= PAGE_SIZE;
25926
25927 if (len > mm->cached_hole_size) {
25928 - start_addr = mm->free_area_cache;
25929 + start_addr = mm->free_area_cache;
25930 } else {
25931 - start_addr = TASK_UNMAPPED_BASE;
25932 - mm->cached_hole_size = 0;
25933 + start_addr = mm->mmap_base;
25934 + mm->cached_hole_size = 0;
25935 }
25936
25937 full_search:
25938 @@ -290,26 +298,27 @@ full_search:
25939
25940 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25941 /* At this point: (!vma || addr < vma->vm_end). */
25942 - if (TASK_SIZE - len < addr) {
25943 + if (pax_task_size - len < addr) {
25944 /*
25945 * Start a new search - just in case we missed
25946 * some holes.
25947 */
25948 - if (start_addr != TASK_UNMAPPED_BASE) {
25949 - start_addr = TASK_UNMAPPED_BASE;
25950 + if (start_addr != mm->mmap_base) {
25951 + start_addr = mm->mmap_base;
25952 mm->cached_hole_size = 0;
25953 goto full_search;
25954 }
25955 return -ENOMEM;
25956 }
25957 - if (!vma || addr + len <= vma->vm_start) {
25958 - mm->free_area_cache = addr + len;
25959 - return addr;
25960 - }
25961 + if (check_heap_stack_gap(vma, addr, len, offset))
25962 + break;
25963 if (addr + mm->cached_hole_size < vma->vm_start)
25964 mm->cached_hole_size = vma->vm_start - addr;
25965 addr = ALIGN(vma->vm_end, huge_page_size(h));
25966 }
25967 +
25968 + mm->free_area_cache = addr + len;
25969 + return addr;
25970 }
25971
25972 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25973 @@ -320,9 +329,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25974 struct mm_struct *mm = current->mm;
25975 struct vm_area_struct *vma;
25976 unsigned long base = mm->mmap_base;
25977 - unsigned long addr = addr0;
25978 + unsigned long addr;
25979 unsigned long largest_hole = mm->cached_hole_size;
25980 - unsigned long start_addr;
25981 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25982
25983 /* don't allow allocations above current base */
25984 if (mm->free_area_cache > base)
25985 @@ -332,16 +341,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25986 largest_hole = 0;
25987 mm->free_area_cache = base;
25988 }
25989 -try_again:
25990 - start_addr = mm->free_area_cache;
25991
25992 /* make sure it can fit in the remaining address space */
25993 if (mm->free_area_cache < len)
25994 goto fail;
25995
25996 /* either no address requested or can't fit in requested address hole */
25997 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
25998 + addr = mm->free_area_cache - len;
25999 do {
26000 + addr &= huge_page_mask(h);
26001 /*
26002 * Lookup failure means no vma is above this address,
26003 * i.e. return with success:
26004 @@ -350,10 +358,10 @@ try_again:
26005 if (!vma)
26006 return addr;
26007
26008 - if (addr + len <= vma->vm_start) {
26009 + if (check_heap_stack_gap(vma, addr, len, offset)) {
26010 /* remember the address as a hint for next time */
26011 - mm->cached_hole_size = largest_hole;
26012 - return (mm->free_area_cache = addr);
26013 + mm->cached_hole_size = largest_hole;
26014 + return (mm->free_area_cache = addr);
26015 } else if (mm->free_area_cache == vma->vm_end) {
26016 /* pull free_area_cache down to the first hole */
26017 mm->free_area_cache = vma->vm_start;
26018 @@ -362,29 +370,34 @@ try_again:
26019
26020 /* remember the largest hole we saw so far */
26021 if (addr + largest_hole < vma->vm_start)
26022 - largest_hole = vma->vm_start - addr;
26023 + largest_hole = vma->vm_start - addr;
26024
26025 /* try just below the current vma->vm_start */
26026 - addr = (vma->vm_start - len) & huge_page_mask(h);
26027 - } while (len <= vma->vm_start);
26028 + addr = skip_heap_stack_gap(vma, len, offset);
26029 + } while (!IS_ERR_VALUE(addr));
26030
26031 fail:
26032 /*
26033 - * if hint left us with no space for the requested
26034 - * mapping then try again:
26035 - */
26036 - if (start_addr != base) {
26037 - mm->free_area_cache = base;
26038 - largest_hole = 0;
26039 - goto try_again;
26040 - }
26041 - /*
26042 * A failed mmap() very likely causes application failure,
26043 * so fall back to the bottom-up function here. This scenario
26044 * can happen with large stack limits and large mmap()
26045 * allocations.
26046 */
26047 - mm->free_area_cache = TASK_UNMAPPED_BASE;
26048 +
26049 +#ifdef CONFIG_PAX_SEGMEXEC
26050 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26051 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
26052 + else
26053 +#endif
26054 +
26055 + mm->mmap_base = TASK_UNMAPPED_BASE;
26056 +
26057 +#ifdef CONFIG_PAX_RANDMMAP
26058 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26059 + mm->mmap_base += mm->delta_mmap;
26060 +#endif
26061 +
26062 + mm->free_area_cache = mm->mmap_base;
26063 mm->cached_hole_size = ~0UL;
26064 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
26065 len, pgoff, flags);
26066 @@ -392,6 +405,7 @@ fail:
26067 /*
26068 * Restore the topdown base:
26069 */
26070 + mm->mmap_base = base;
26071 mm->free_area_cache = base;
26072 mm->cached_hole_size = ~0UL;
26073
26074 @@ -405,10 +419,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26075 struct hstate *h = hstate_file(file);
26076 struct mm_struct *mm = current->mm;
26077 struct vm_area_struct *vma;
26078 + unsigned long pax_task_size = TASK_SIZE;
26079 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
26080
26081 if (len & ~huge_page_mask(h))
26082 return -EINVAL;
26083 - if (len > TASK_SIZE)
26084 +
26085 +#ifdef CONFIG_PAX_SEGMEXEC
26086 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26087 + pax_task_size = SEGMEXEC_TASK_SIZE;
26088 +#endif
26089 +
26090 + pax_task_size -= PAGE_SIZE;
26091 +
26092 + if (len > pax_task_size)
26093 return -ENOMEM;
26094
26095 if (flags & MAP_FIXED) {
26096 @@ -417,11 +441,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26097 return addr;
26098 }
26099
26100 +#ifdef CONFIG_PAX_RANDMMAP
26101 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26102 +#endif
26103 +
26104 if (addr) {
26105 addr = ALIGN(addr, huge_page_size(h));
26106 vma = find_vma(mm, addr);
26107 - if (TASK_SIZE - len >= addr &&
26108 - (!vma || addr + len <= vma->vm_start))
26109 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26110 return addr;
26111 }
26112 if (mm->get_unmapped_area == arch_get_unmapped_area)
26113 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
26114 index d7aea41..0fc945b 100644
26115 --- a/arch/x86/mm/init.c
26116 +++ b/arch/x86/mm/init.c
26117 @@ -4,6 +4,7 @@
26118 #include <linux/swap.h>
26119 #include <linux/memblock.h>
26120 #include <linux/bootmem.h> /* for max_low_pfn */
26121 +#include <linux/tboot.h>
26122
26123 #include <asm/cacheflush.h>
26124 #include <asm/e820.h>
26125 @@ -16,6 +17,8 @@
26126 #include <asm/tlb.h>
26127 #include <asm/proto.h>
26128 #include <asm/dma.h> /* for MAX_DMA_PFN */
26129 +#include <asm/desc.h>
26130 +#include <asm/bios_ebda.h>
26131
26132 unsigned long __initdata pgt_buf_start;
26133 unsigned long __meminitdata pgt_buf_end;
26134 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
26135 {
26136 int i;
26137 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
26138 - unsigned long start = 0, good_end;
26139 + unsigned long start = 0x100000, good_end;
26140 phys_addr_t base;
26141
26142 for (i = 0; i < nr_range; i++) {
26143 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
26144 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
26145 * mmio resources as well as potential bios/acpi data regions.
26146 */
26147 +
26148 +#ifdef CONFIG_GRKERNSEC_KMEM
26149 +static unsigned int ebda_start __read_only;
26150 +static unsigned int ebda_end __read_only;
26151 +#endif
26152 +
26153 int devmem_is_allowed(unsigned long pagenr)
26154 {
26155 - if (pagenr < 256)
26156 +#ifdef CONFIG_GRKERNSEC_KMEM
26157 + /* allow BDA */
26158 + if (!pagenr)
26159 return 1;
26160 + /* allow EBDA */
26161 + if (pagenr >= ebda_start && pagenr < ebda_end)
26162 + return 1;
26163 + /* if tboot is in use, allow access to its hardcoded serial log range */
26164 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
26165 + return 1;
26166 +#else
26167 + if (!pagenr)
26168 + return 1;
26169 +#ifdef CONFIG_VM86
26170 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
26171 + return 1;
26172 +#endif
26173 +#endif
26174 +
26175 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
26176 + return 1;
26177 +#ifdef CONFIG_GRKERNSEC_KMEM
26178 + /* throw out everything else below 1MB */
26179 + if (pagenr <= 256)
26180 + return 0;
26181 +#endif
26182 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
26183 return 0;
26184 if (!page_is_ram(pagenr))
26185 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
26186 #endif
26187 }
26188
26189 +#ifdef CONFIG_GRKERNSEC_KMEM
26190 +static inline void gr_init_ebda(void)
26191 +{
26192 + unsigned int ebda_addr;
26193 + unsigned int ebda_size = 0;
26194 +
26195 + ebda_addr = get_bios_ebda();
26196 + if (ebda_addr) {
26197 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
26198 + ebda_size <<= 10;
26199 + }
26200 + if (ebda_addr && ebda_size) {
26201 + ebda_start = ebda_addr >> PAGE_SHIFT;
26202 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
26203 + } else {
26204 + ebda_start = 0x9f000 >> PAGE_SHIFT;
26205 + ebda_end = 0xa0000 >> PAGE_SHIFT;
26206 + }
26207 +}
26208 +#else
26209 +static inline void gr_init_ebda(void) { }
26210 +#endif
26211 +
26212 void free_initmem(void)
26213 {
26214 +#ifdef CONFIG_PAX_KERNEXEC
26215 +#ifdef CONFIG_X86_32
26216 + /* PaX: limit KERNEL_CS to actual size */
26217 + unsigned long addr, limit;
26218 + struct desc_struct d;
26219 + int cpu;
26220 +#else
26221 + pgd_t *pgd;
26222 + pud_t *pud;
26223 + pmd_t *pmd;
26224 + unsigned long addr, end;
26225 +#endif
26226 +#endif
26227 +
26228 + gr_init_ebda();
26229 +
26230 +#ifdef CONFIG_PAX_KERNEXEC
26231 +#ifdef CONFIG_X86_32
26232 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
26233 + limit = (limit - 1UL) >> PAGE_SHIFT;
26234 +
26235 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
26236 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26237 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
26238 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
26239 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
26240 + }
26241 +
26242 + /* PaX: make KERNEL_CS read-only */
26243 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
26244 + if (!paravirt_enabled())
26245 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
26246 +/*
26247 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
26248 + pgd = pgd_offset_k(addr);
26249 + pud = pud_offset(pgd, addr);
26250 + pmd = pmd_offset(pud, addr);
26251 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26252 + }
26253 +*/
26254 +#ifdef CONFIG_X86_PAE
26255 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
26256 +/*
26257 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
26258 + pgd = pgd_offset_k(addr);
26259 + pud = pud_offset(pgd, addr);
26260 + pmd = pmd_offset(pud, addr);
26261 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26262 + }
26263 +*/
26264 +#endif
26265 +
26266 +#ifdef CONFIG_MODULES
26267 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
26268 +#endif
26269 +
26270 +#else
26271 + /* PaX: make kernel code/rodata read-only, rest non-executable */
26272 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
26273 + pgd = pgd_offset_k(addr);
26274 + pud = pud_offset(pgd, addr);
26275 + pmd = pmd_offset(pud, addr);
26276 + if (!pmd_present(*pmd))
26277 + continue;
26278 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
26279 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26280 + else
26281 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26282 + }
26283 +
26284 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
26285 + end = addr + KERNEL_IMAGE_SIZE;
26286 + for (; addr < end; addr += PMD_SIZE) {
26287 + pgd = pgd_offset_k(addr);
26288 + pud = pud_offset(pgd, addr);
26289 + pmd = pmd_offset(pud, addr);
26290 + if (!pmd_present(*pmd))
26291 + continue;
26292 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
26293 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26294 + }
26295 +#endif
26296 +
26297 + flush_tlb_all();
26298 +#endif
26299 +
26300 free_init_pages("unused kernel memory",
26301 (unsigned long)(&__init_begin),
26302 (unsigned long)(&__init_end));
26303 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
26304 index 11a5800..4bd9977 100644
26305 --- a/arch/x86/mm/init_32.c
26306 +++ b/arch/x86/mm/init_32.c
26307 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
26308 }
26309
26310 /*
26311 - * Creates a middle page table and puts a pointer to it in the
26312 - * given global directory entry. This only returns the gd entry
26313 - * in non-PAE compilation mode, since the middle layer is folded.
26314 - */
26315 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
26316 -{
26317 - pud_t *pud;
26318 - pmd_t *pmd_table;
26319 -
26320 -#ifdef CONFIG_X86_PAE
26321 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
26322 - if (after_bootmem)
26323 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
26324 - else
26325 - pmd_table = (pmd_t *)alloc_low_page();
26326 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
26327 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
26328 - pud = pud_offset(pgd, 0);
26329 - BUG_ON(pmd_table != pmd_offset(pud, 0));
26330 -
26331 - return pmd_table;
26332 - }
26333 -#endif
26334 - pud = pud_offset(pgd, 0);
26335 - pmd_table = pmd_offset(pud, 0);
26336 -
26337 - return pmd_table;
26338 -}
26339 -
26340 -/*
26341 * Create a page table and place a pointer to it in a middle page
26342 * directory entry:
26343 */
26344 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26345 page_table = (pte_t *)alloc_low_page();
26346
26347 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26348 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26349 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26350 +#else
26351 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26352 +#endif
26353 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26354 }
26355
26356 return pte_offset_kernel(pmd, 0);
26357 }
26358
26359 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
26360 +{
26361 + pud_t *pud;
26362 + pmd_t *pmd_table;
26363 +
26364 + pud = pud_offset(pgd, 0);
26365 + pmd_table = pmd_offset(pud, 0);
26366 +
26367 + return pmd_table;
26368 +}
26369 +
26370 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26371 {
26372 int pgd_idx = pgd_index(vaddr);
26373 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26374 int pgd_idx, pmd_idx;
26375 unsigned long vaddr;
26376 pgd_t *pgd;
26377 + pud_t *pud;
26378 pmd_t *pmd;
26379 pte_t *pte = NULL;
26380
26381 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26382 pgd = pgd_base + pgd_idx;
26383
26384 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26385 - pmd = one_md_table_init(pgd);
26386 - pmd = pmd + pmd_index(vaddr);
26387 + pud = pud_offset(pgd, vaddr);
26388 + pmd = pmd_offset(pud, vaddr);
26389 +
26390 +#ifdef CONFIG_X86_PAE
26391 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26392 +#endif
26393 +
26394 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26395 pmd++, pmd_idx++) {
26396 pte = page_table_kmap_check(one_page_table_init(pmd),
26397 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26398 }
26399 }
26400
26401 -static inline int is_kernel_text(unsigned long addr)
26402 +static inline int is_kernel_text(unsigned long start, unsigned long end)
26403 {
26404 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26405 - return 1;
26406 - return 0;
26407 + if ((start > ktla_ktva((unsigned long)_etext) ||
26408 + end <= ktla_ktva((unsigned long)_stext)) &&
26409 + (start > ktla_ktva((unsigned long)_einittext) ||
26410 + end <= ktla_ktva((unsigned long)_sinittext)) &&
26411 +
26412 +#ifdef CONFIG_ACPI_SLEEP
26413 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26414 +#endif
26415 +
26416 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26417 + return 0;
26418 + return 1;
26419 }
26420
26421 /*
26422 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26423 unsigned long last_map_addr = end;
26424 unsigned long start_pfn, end_pfn;
26425 pgd_t *pgd_base = swapper_pg_dir;
26426 - int pgd_idx, pmd_idx, pte_ofs;
26427 + unsigned int pgd_idx, pmd_idx, pte_ofs;
26428 unsigned long pfn;
26429 pgd_t *pgd;
26430 + pud_t *pud;
26431 pmd_t *pmd;
26432 pte_t *pte;
26433 unsigned pages_2m, pages_4k;
26434 @@ -280,8 +281,13 @@ repeat:
26435 pfn = start_pfn;
26436 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26437 pgd = pgd_base + pgd_idx;
26438 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26439 - pmd = one_md_table_init(pgd);
26440 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26441 + pud = pud_offset(pgd, 0);
26442 + pmd = pmd_offset(pud, 0);
26443 +
26444 +#ifdef CONFIG_X86_PAE
26445 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26446 +#endif
26447
26448 if (pfn >= end_pfn)
26449 continue;
26450 @@ -293,14 +299,13 @@ repeat:
26451 #endif
26452 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26453 pmd++, pmd_idx++) {
26454 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26455 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26456
26457 /*
26458 * Map with big pages if possible, otherwise
26459 * create normal page tables:
26460 */
26461 if (use_pse) {
26462 - unsigned int addr2;
26463 pgprot_t prot = PAGE_KERNEL_LARGE;
26464 /*
26465 * first pass will use the same initial
26466 @@ -310,11 +315,7 @@ repeat:
26467 __pgprot(PTE_IDENT_ATTR |
26468 _PAGE_PSE);
26469
26470 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26471 - PAGE_OFFSET + PAGE_SIZE-1;
26472 -
26473 - if (is_kernel_text(addr) ||
26474 - is_kernel_text(addr2))
26475 + if (is_kernel_text(address, address + PMD_SIZE))
26476 prot = PAGE_KERNEL_LARGE_EXEC;
26477
26478 pages_2m++;
26479 @@ -331,7 +332,7 @@ repeat:
26480 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26481 pte += pte_ofs;
26482 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26483 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26484 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26485 pgprot_t prot = PAGE_KERNEL;
26486 /*
26487 * first pass will use the same initial
26488 @@ -339,7 +340,7 @@ repeat:
26489 */
26490 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26491
26492 - if (is_kernel_text(addr))
26493 + if (is_kernel_text(address, address + PAGE_SIZE))
26494 prot = PAGE_KERNEL_EXEC;
26495
26496 pages_4k++;
26497 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26498
26499 pud = pud_offset(pgd, va);
26500 pmd = pmd_offset(pud, va);
26501 - if (!pmd_present(*pmd))
26502 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
26503 break;
26504
26505 pte = pte_offset_kernel(pmd, va);
26506 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26507
26508 static void __init pagetable_init(void)
26509 {
26510 - pgd_t *pgd_base = swapper_pg_dir;
26511 -
26512 - permanent_kmaps_init(pgd_base);
26513 + permanent_kmaps_init(swapper_pg_dir);
26514 }
26515
26516 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26517 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26518 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26519
26520 /* user-defined highmem size */
26521 @@ -731,6 +730,12 @@ void __init mem_init(void)
26522
26523 pci_iommu_alloc();
26524
26525 +#ifdef CONFIG_PAX_PER_CPU_PGD
26526 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26527 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26528 + KERNEL_PGD_PTRS);
26529 +#endif
26530 +
26531 #ifdef CONFIG_FLATMEM
26532 BUG_ON(!mem_map);
26533 #endif
26534 @@ -757,7 +762,7 @@ void __init mem_init(void)
26535 reservedpages++;
26536
26537 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26538 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26539 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26540 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26541
26542 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26543 @@ -798,10 +803,10 @@ void __init mem_init(void)
26544 ((unsigned long)&__init_end -
26545 (unsigned long)&__init_begin) >> 10,
26546
26547 - (unsigned long)&_etext, (unsigned long)&_edata,
26548 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26549 + (unsigned long)&_sdata, (unsigned long)&_edata,
26550 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26551
26552 - (unsigned long)&_text, (unsigned long)&_etext,
26553 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26554 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26555
26556 /*
26557 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26558 if (!kernel_set_to_readonly)
26559 return;
26560
26561 + start = ktla_ktva(start);
26562 pr_debug("Set kernel text: %lx - %lx for read write\n",
26563 start, start+size);
26564
26565 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26566 if (!kernel_set_to_readonly)
26567 return;
26568
26569 + start = ktla_ktva(start);
26570 pr_debug("Set kernel text: %lx - %lx for read only\n",
26571 start, start+size);
26572
26573 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26574 unsigned long start = PFN_ALIGN(_text);
26575 unsigned long size = PFN_ALIGN(_etext) - start;
26576
26577 + start = ktla_ktva(start);
26578 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26579 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26580 size >> 10);
26581 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26582 index 3baff25..8b37564 100644
26583 --- a/arch/x86/mm/init_64.c
26584 +++ b/arch/x86/mm/init_64.c
26585 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26586 * around without checking the pgd every time.
26587 */
26588
26589 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26590 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26591 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26592
26593 int force_personality32;
26594 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26595
26596 for (address = start; address <= end; address += PGDIR_SIZE) {
26597 const pgd_t *pgd_ref = pgd_offset_k(address);
26598 +
26599 +#ifdef CONFIG_PAX_PER_CPU_PGD
26600 + unsigned long cpu;
26601 +#else
26602 struct page *page;
26603 +#endif
26604
26605 if (pgd_none(*pgd_ref))
26606 continue;
26607
26608 spin_lock(&pgd_lock);
26609 +
26610 +#ifdef CONFIG_PAX_PER_CPU_PGD
26611 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26612 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
26613 +#else
26614 list_for_each_entry(page, &pgd_list, lru) {
26615 pgd_t *pgd;
26616 spinlock_t *pgt_lock;
26617 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26618 /* the pgt_lock only for Xen */
26619 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26620 spin_lock(pgt_lock);
26621 +#endif
26622
26623 if (pgd_none(*pgd))
26624 set_pgd(pgd, *pgd_ref);
26625 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26626 BUG_ON(pgd_page_vaddr(*pgd)
26627 != pgd_page_vaddr(*pgd_ref));
26628
26629 +#ifndef CONFIG_PAX_PER_CPU_PGD
26630 spin_unlock(pgt_lock);
26631 +#endif
26632 +
26633 }
26634 spin_unlock(&pgd_lock);
26635 }
26636 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26637 {
26638 if (pgd_none(*pgd)) {
26639 pud_t *pud = (pud_t *)spp_getpage();
26640 - pgd_populate(&init_mm, pgd, pud);
26641 + pgd_populate_kernel(&init_mm, pgd, pud);
26642 if (pud != pud_offset(pgd, 0))
26643 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26644 pud, pud_offset(pgd, 0));
26645 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26646 {
26647 if (pud_none(*pud)) {
26648 pmd_t *pmd = (pmd_t *) spp_getpage();
26649 - pud_populate(&init_mm, pud, pmd);
26650 + pud_populate_kernel(&init_mm, pud, pmd);
26651 if (pmd != pmd_offset(pud, 0))
26652 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26653 pmd, pmd_offset(pud, 0));
26654 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26655 pmd = fill_pmd(pud, vaddr);
26656 pte = fill_pte(pmd, vaddr);
26657
26658 + pax_open_kernel();
26659 set_pte(pte, new_pte);
26660 + pax_close_kernel();
26661
26662 /*
26663 * It's enough to flush this one mapping.
26664 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26665 pgd = pgd_offset_k((unsigned long)__va(phys));
26666 if (pgd_none(*pgd)) {
26667 pud = (pud_t *) spp_getpage();
26668 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26669 - _PAGE_USER));
26670 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26671 }
26672 pud = pud_offset(pgd, (unsigned long)__va(phys));
26673 if (pud_none(*pud)) {
26674 pmd = (pmd_t *) spp_getpage();
26675 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26676 - _PAGE_USER));
26677 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26678 }
26679 pmd = pmd_offset(pud, phys);
26680 BUG_ON(!pmd_none(*pmd));
26681 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26682 if (pfn >= pgt_buf_top)
26683 panic("alloc_low_page: ran out of memory");
26684
26685 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26686 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26687 clear_page(adr);
26688 *phys = pfn * PAGE_SIZE;
26689 return adr;
26690 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26691
26692 phys = __pa(virt);
26693 left = phys & (PAGE_SIZE - 1);
26694 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26695 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26696 adr = (void *)(((unsigned long)adr) | left);
26697
26698 return adr;
26699 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26700 unmap_low_page(pmd);
26701
26702 spin_lock(&init_mm.page_table_lock);
26703 - pud_populate(&init_mm, pud, __va(pmd_phys));
26704 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26705 spin_unlock(&init_mm.page_table_lock);
26706 }
26707 __flush_tlb_all();
26708 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26709 unmap_low_page(pud);
26710
26711 spin_lock(&init_mm.page_table_lock);
26712 - pgd_populate(&init_mm, pgd, __va(pud_phys));
26713 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26714 spin_unlock(&init_mm.page_table_lock);
26715 pgd_changed = true;
26716 }
26717 @@ -691,6 +705,12 @@ void __init mem_init(void)
26718
26719 pci_iommu_alloc();
26720
26721 +#ifdef CONFIG_PAX_PER_CPU_PGD
26722 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26723 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26724 + KERNEL_PGD_PTRS);
26725 +#endif
26726 +
26727 /* clear_bss() already clear the empty_zero_page */
26728
26729 reservedpages = 0;
26730 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
26731 static struct vm_area_struct gate_vma = {
26732 .vm_start = VSYSCALL_START,
26733 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26734 - .vm_page_prot = PAGE_READONLY_EXEC,
26735 - .vm_flags = VM_READ | VM_EXEC
26736 + .vm_page_prot = PAGE_READONLY,
26737 + .vm_flags = VM_READ
26738 };
26739
26740 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26741 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
26742
26743 const char *arch_vma_name(struct vm_area_struct *vma)
26744 {
26745 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26746 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26747 return "[vdso]";
26748 if (vma == &gate_vma)
26749 return "[vsyscall]";
26750 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26751 index 7b179b4..6bd1777 100644
26752 --- a/arch/x86/mm/iomap_32.c
26753 +++ b/arch/x86/mm/iomap_32.c
26754 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26755 type = kmap_atomic_idx_push();
26756 idx = type + KM_TYPE_NR * smp_processor_id();
26757 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26758 +
26759 + pax_open_kernel();
26760 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26761 + pax_close_kernel();
26762 +
26763 arch_flush_lazy_mmu_mode();
26764
26765 return (void *)vaddr;
26766 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26767 index 78fe3f1..2f9433c 100644
26768 --- a/arch/x86/mm/ioremap.c
26769 +++ b/arch/x86/mm/ioremap.c
26770 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26771 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26772 int is_ram = page_is_ram(pfn);
26773
26774 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26775 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26776 return NULL;
26777 WARN_ON_ONCE(is_ram);
26778 }
26779 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26780 *
26781 * Caller must ensure there is only one unmapping for the same pointer.
26782 */
26783 -void iounmap(volatile void __iomem *addr)
26784 +void iounmap(const volatile void __iomem *addr)
26785 {
26786 struct vm_struct *p, *o;
26787
26788 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26789
26790 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26791 if (page_is_ram(start >> PAGE_SHIFT))
26792 +#ifdef CONFIG_HIGHMEM
26793 + if ((start >> PAGE_SHIFT) < max_low_pfn)
26794 +#endif
26795 return __va(phys);
26796
26797 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26798 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26799 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26800
26801 static __initdata int after_paging_init;
26802 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26803 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26804
26805 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26806 {
26807 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26808 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26809
26810 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26811 - memset(bm_pte, 0, sizeof(bm_pte));
26812 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
26813 + pmd_populate_user(&init_mm, pmd, bm_pte);
26814
26815 /*
26816 * The boot-ioremap range spans multiple pmds, for which
26817 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26818 index d87dd6d..bf3fa66 100644
26819 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
26820 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26821 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26822 * memory (e.g. tracked pages)? For now, we need this to avoid
26823 * invoking kmemcheck for PnP BIOS calls.
26824 */
26825 - if (regs->flags & X86_VM_MASK)
26826 + if (v8086_mode(regs))
26827 return false;
26828 - if (regs->cs != __KERNEL_CS)
26829 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26830 return false;
26831
26832 pte = kmemcheck_pte_lookup(address);
26833 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26834 index 845df68..1d8d29f 100644
26835 --- a/arch/x86/mm/mmap.c
26836 +++ b/arch/x86/mm/mmap.c
26837 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26838 * Leave an at least ~128 MB hole with possible stack randomization.
26839 */
26840 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26841 -#define MAX_GAP (TASK_SIZE/6*5)
26842 +#define MAX_GAP (pax_task_size/6*5)
26843
26844 static int mmap_is_legacy(void)
26845 {
26846 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26847 return rnd << PAGE_SHIFT;
26848 }
26849
26850 -static unsigned long mmap_base(void)
26851 +static unsigned long mmap_base(struct mm_struct *mm)
26852 {
26853 unsigned long gap = rlimit(RLIMIT_STACK);
26854 + unsigned long pax_task_size = TASK_SIZE;
26855 +
26856 +#ifdef CONFIG_PAX_SEGMEXEC
26857 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26858 + pax_task_size = SEGMEXEC_TASK_SIZE;
26859 +#endif
26860
26861 if (gap < MIN_GAP)
26862 gap = MIN_GAP;
26863 else if (gap > MAX_GAP)
26864 gap = MAX_GAP;
26865
26866 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26867 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26868 }
26869
26870 /*
26871 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26872 * does, but not when emulating X86_32
26873 */
26874 -static unsigned long mmap_legacy_base(void)
26875 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
26876 {
26877 - if (mmap_is_ia32())
26878 + if (mmap_is_ia32()) {
26879 +
26880 +#ifdef CONFIG_PAX_SEGMEXEC
26881 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26882 + return SEGMEXEC_TASK_UNMAPPED_BASE;
26883 + else
26884 +#endif
26885 +
26886 return TASK_UNMAPPED_BASE;
26887 - else
26888 + } else
26889 return TASK_UNMAPPED_BASE + mmap_rnd();
26890 }
26891
26892 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26893 void arch_pick_mmap_layout(struct mm_struct *mm)
26894 {
26895 if (mmap_is_legacy()) {
26896 - mm->mmap_base = mmap_legacy_base();
26897 + mm->mmap_base = mmap_legacy_base(mm);
26898 +
26899 +#ifdef CONFIG_PAX_RANDMMAP
26900 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26901 + mm->mmap_base += mm->delta_mmap;
26902 +#endif
26903 +
26904 mm->get_unmapped_area = arch_get_unmapped_area;
26905 mm->unmap_area = arch_unmap_area;
26906 } else {
26907 - mm->mmap_base = mmap_base();
26908 + mm->mmap_base = mmap_base(mm);
26909 +
26910 +#ifdef CONFIG_PAX_RANDMMAP
26911 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26912 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26913 +#endif
26914 +
26915 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26916 mm->unmap_area = arch_unmap_area_topdown;
26917 }
26918 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26919 index dc0b727..f612039 100644
26920 --- a/arch/x86/mm/mmio-mod.c
26921 +++ b/arch/x86/mm/mmio-mod.c
26922 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26923 break;
26924 default:
26925 {
26926 - unsigned char *ip = (unsigned char *)instptr;
26927 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26928 my_trace->opcode = MMIO_UNKNOWN_OP;
26929 my_trace->width = 0;
26930 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26931 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26932 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26933 void __iomem *addr)
26934 {
26935 - static atomic_t next_id;
26936 + static atomic_unchecked_t next_id;
26937 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26938 /* These are page-unaligned. */
26939 struct mmiotrace_map map = {
26940 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26941 .private = trace
26942 },
26943 .phys = offset,
26944 - .id = atomic_inc_return(&next_id)
26945 + .id = atomic_inc_return_unchecked(&next_id)
26946 };
26947 map.map_id = trace->id;
26948
26949 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26950 ioremap_trace_core(offset, size, addr);
26951 }
26952
26953 -static void iounmap_trace_core(volatile void __iomem *addr)
26954 +static void iounmap_trace_core(const volatile void __iomem *addr)
26955 {
26956 struct mmiotrace_map map = {
26957 .phys = 0,
26958 @@ -328,7 +328,7 @@ not_enabled:
26959 }
26960 }
26961
26962 -void mmiotrace_iounmap(volatile void __iomem *addr)
26963 +void mmiotrace_iounmap(const volatile void __iomem *addr)
26964 {
26965 might_sleep();
26966 if (is_enabled()) /* recheck and proper locking in *_core() */
26967 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26968 index b008656..773eac2 100644
26969 --- a/arch/x86/mm/pageattr-test.c
26970 +++ b/arch/x86/mm/pageattr-test.c
26971 @@ -36,7 +36,7 @@ enum {
26972
26973 static int pte_testbit(pte_t pte)
26974 {
26975 - return pte_flags(pte) & _PAGE_UNUSED1;
26976 + return pte_flags(pte) & _PAGE_CPA_TEST;
26977 }
26978
26979 struct split_state {
26980 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26981 index a718e0d..77419bc 100644
26982 --- a/arch/x86/mm/pageattr.c
26983 +++ b/arch/x86/mm/pageattr.c
26984 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26985 */
26986 #ifdef CONFIG_PCI_BIOS
26987 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26988 - pgprot_val(forbidden) |= _PAGE_NX;
26989 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26990 #endif
26991
26992 /*
26993 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26994 * Does not cover __inittext since that is gone later on. On
26995 * 64bit we do not enforce !NX on the low mapping
26996 */
26997 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
26998 - pgprot_val(forbidden) |= _PAGE_NX;
26999 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
27000 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27001
27002 +#ifdef CONFIG_DEBUG_RODATA
27003 /*
27004 * The .rodata section needs to be read-only. Using the pfn
27005 * catches all aliases.
27006 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27007 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
27008 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
27009 pgprot_val(forbidden) |= _PAGE_RW;
27010 +#endif
27011
27012 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
27013 /*
27014 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27015 }
27016 #endif
27017
27018 +#ifdef CONFIG_PAX_KERNEXEC
27019 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
27020 + pgprot_val(forbidden) |= _PAGE_RW;
27021 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27022 + }
27023 +#endif
27024 +
27025 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
27026
27027 return prot;
27028 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
27029 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
27030 {
27031 /* change init_mm */
27032 + pax_open_kernel();
27033 set_pte_atomic(kpte, pte);
27034 +
27035 #ifdef CONFIG_X86_32
27036 if (!SHARED_KERNEL_PMD) {
27037 +
27038 +#ifdef CONFIG_PAX_PER_CPU_PGD
27039 + unsigned long cpu;
27040 +#else
27041 struct page *page;
27042 +#endif
27043
27044 +#ifdef CONFIG_PAX_PER_CPU_PGD
27045 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27046 + pgd_t *pgd = get_cpu_pgd(cpu);
27047 +#else
27048 list_for_each_entry(page, &pgd_list, lru) {
27049 - pgd_t *pgd;
27050 + pgd_t *pgd = (pgd_t *)page_address(page);
27051 +#endif
27052 +
27053 pud_t *pud;
27054 pmd_t *pmd;
27055
27056 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
27057 + pgd += pgd_index(address);
27058 pud = pud_offset(pgd, address);
27059 pmd = pmd_offset(pud, address);
27060 set_pte_atomic((pte_t *)pmd, pte);
27061 }
27062 }
27063 #endif
27064 + pax_close_kernel();
27065 }
27066
27067 static int
27068 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
27069 index 0eb572e..92f5c1e 100644
27070 --- a/arch/x86/mm/pat.c
27071 +++ b/arch/x86/mm/pat.c
27072 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
27073
27074 if (!entry) {
27075 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
27076 - current->comm, current->pid, start, end - 1);
27077 + current->comm, task_pid_nr(current), start, end - 1);
27078 return -EINVAL;
27079 }
27080
27081 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27082
27083 while (cursor < to) {
27084 if (!devmem_is_allowed(pfn)) {
27085 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
27086 - current->comm, from, to - 1);
27087 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
27088 + current->comm, from, to - 1, cursor);
27089 return 0;
27090 }
27091 cursor += PAGE_SIZE;
27092 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
27093 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
27094 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
27095 "for [mem %#010Lx-%#010Lx]\n",
27096 - current->comm, current->pid,
27097 + current->comm, task_pid_nr(current),
27098 cattr_name(flags),
27099 base, (unsigned long long)(base + size-1));
27100 return -EINVAL;
27101 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27102 flags = lookup_memtype(paddr);
27103 if (want_flags != flags) {
27104 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
27105 - current->comm, current->pid,
27106 + current->comm, task_pid_nr(current),
27107 cattr_name(want_flags),
27108 (unsigned long long)paddr,
27109 (unsigned long long)(paddr + size - 1),
27110 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27111 free_memtype(paddr, paddr + size);
27112 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
27113 " for [mem %#010Lx-%#010Lx], got %s\n",
27114 - current->comm, current->pid,
27115 + current->comm, task_pid_nr(current),
27116 cattr_name(want_flags),
27117 (unsigned long long)paddr,
27118 (unsigned long long)(paddr + size - 1),
27119 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
27120 index 9f0614d..92ae64a 100644
27121 --- a/arch/x86/mm/pf_in.c
27122 +++ b/arch/x86/mm/pf_in.c
27123 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
27124 int i;
27125 enum reason_type rv = OTHERS;
27126
27127 - p = (unsigned char *)ins_addr;
27128 + p = (unsigned char *)ktla_ktva(ins_addr);
27129 p += skip_prefix(p, &prf);
27130 p += get_opcode(p, &opcode);
27131
27132 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
27133 struct prefix_bits prf;
27134 int i;
27135
27136 - p = (unsigned char *)ins_addr;
27137 + p = (unsigned char *)ktla_ktva(ins_addr);
27138 p += skip_prefix(p, &prf);
27139 p += get_opcode(p, &opcode);
27140
27141 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
27142 struct prefix_bits prf;
27143 int i;
27144
27145 - p = (unsigned char *)ins_addr;
27146 + p = (unsigned char *)ktla_ktva(ins_addr);
27147 p += skip_prefix(p, &prf);
27148 p += get_opcode(p, &opcode);
27149
27150 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
27151 struct prefix_bits prf;
27152 int i;
27153
27154 - p = (unsigned char *)ins_addr;
27155 + p = (unsigned char *)ktla_ktva(ins_addr);
27156 p += skip_prefix(p, &prf);
27157 p += get_opcode(p, &opcode);
27158 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
27159 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
27160 struct prefix_bits prf;
27161 int i;
27162
27163 - p = (unsigned char *)ins_addr;
27164 + p = (unsigned char *)ktla_ktva(ins_addr);
27165 p += skip_prefix(p, &prf);
27166 p += get_opcode(p, &opcode);
27167 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
27168 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
27169 index 8573b83..4f3ed7e 100644
27170 --- a/arch/x86/mm/pgtable.c
27171 +++ b/arch/x86/mm/pgtable.c
27172 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
27173 list_del(&page->lru);
27174 }
27175
27176 -#define UNSHARED_PTRS_PER_PGD \
27177 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27178 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27179 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
27180
27181 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
27182 +{
27183 + unsigned int count = USER_PGD_PTRS;
27184
27185 + while (count--)
27186 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
27187 +}
27188 +#endif
27189 +
27190 +#ifdef CONFIG_PAX_PER_CPU_PGD
27191 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
27192 +{
27193 + unsigned int count = USER_PGD_PTRS;
27194 +
27195 + while (count--) {
27196 + pgd_t pgd;
27197 +
27198 +#ifdef CONFIG_X86_64
27199 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
27200 +#else
27201 + pgd = *src++;
27202 +#endif
27203 +
27204 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27205 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
27206 +#endif
27207 +
27208 + *dst++ = pgd;
27209 + }
27210 +
27211 +}
27212 +#endif
27213 +
27214 +#ifdef CONFIG_X86_64
27215 +#define pxd_t pud_t
27216 +#define pyd_t pgd_t
27217 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
27218 +#define pxd_free(mm, pud) pud_free((mm), (pud))
27219 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
27220 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
27221 +#define PYD_SIZE PGDIR_SIZE
27222 +#else
27223 +#define pxd_t pmd_t
27224 +#define pyd_t pud_t
27225 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
27226 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
27227 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
27228 +#define pyd_offset(mm, address) pud_offset((mm), (address))
27229 +#define PYD_SIZE PUD_SIZE
27230 +#endif
27231 +
27232 +#ifdef CONFIG_PAX_PER_CPU_PGD
27233 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
27234 +static inline void pgd_dtor(pgd_t *pgd) {}
27235 +#else
27236 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
27237 {
27238 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
27239 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
27240 pgd_list_del(pgd);
27241 spin_unlock(&pgd_lock);
27242 }
27243 +#endif
27244
27245 /*
27246 * List of all pgd's needed for non-PAE so it can invalidate entries
27247 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
27248 * -- wli
27249 */
27250
27251 -#ifdef CONFIG_X86_PAE
27252 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27253 /*
27254 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
27255 * updating the top-level pagetable entries to guarantee the
27256 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
27257 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
27258 * and initialize the kernel pmds here.
27259 */
27260 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
27261 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27262
27263 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27264 {
27265 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27266 */
27267 flush_tlb_mm(mm);
27268 }
27269 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
27270 +#define PREALLOCATED_PXDS USER_PGD_PTRS
27271 #else /* !CONFIG_X86_PAE */
27272
27273 /* No need to prepopulate any pagetable entries in non-PAE modes. */
27274 -#define PREALLOCATED_PMDS 0
27275 +#define PREALLOCATED_PXDS 0
27276
27277 #endif /* CONFIG_X86_PAE */
27278
27279 -static void free_pmds(pmd_t *pmds[])
27280 +static void free_pxds(pxd_t *pxds[])
27281 {
27282 int i;
27283
27284 - for(i = 0; i < PREALLOCATED_PMDS; i++)
27285 - if (pmds[i])
27286 - free_page((unsigned long)pmds[i]);
27287 + for(i = 0; i < PREALLOCATED_PXDS; i++)
27288 + if (pxds[i])
27289 + free_page((unsigned long)pxds[i]);
27290 }
27291
27292 -static int preallocate_pmds(pmd_t *pmds[])
27293 +static int preallocate_pxds(pxd_t *pxds[])
27294 {
27295 int i;
27296 bool failed = false;
27297
27298 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27299 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
27300 - if (pmd == NULL)
27301 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27302 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
27303 + if (pxd == NULL)
27304 failed = true;
27305 - pmds[i] = pmd;
27306 + pxds[i] = pxd;
27307 }
27308
27309 if (failed) {
27310 - free_pmds(pmds);
27311 + free_pxds(pxds);
27312 return -ENOMEM;
27313 }
27314
27315 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
27316 * preallocate which never got a corresponding vma will need to be
27317 * freed manually.
27318 */
27319 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
27320 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
27321 {
27322 int i;
27323
27324 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27325 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27326 pgd_t pgd = pgdp[i];
27327
27328 if (pgd_val(pgd) != 0) {
27329 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
27330 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
27331
27332 - pgdp[i] = native_make_pgd(0);
27333 + set_pgd(pgdp + i, native_make_pgd(0));
27334
27335 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27336 - pmd_free(mm, pmd);
27337 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27338 + pxd_free(mm, pxd);
27339 }
27340 }
27341 }
27342
27343 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27344 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27345 {
27346 - pud_t *pud;
27347 + pyd_t *pyd;
27348 unsigned long addr;
27349 int i;
27350
27351 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27352 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27353 return;
27354
27355 - pud = pud_offset(pgd, 0);
27356 +#ifdef CONFIG_X86_64
27357 + pyd = pyd_offset(mm, 0L);
27358 +#else
27359 + pyd = pyd_offset(pgd, 0L);
27360 +#endif
27361
27362 - for (addr = i = 0; i < PREALLOCATED_PMDS;
27363 - i++, pud++, addr += PUD_SIZE) {
27364 - pmd_t *pmd = pmds[i];
27365 + for (addr = i = 0; i < PREALLOCATED_PXDS;
27366 + i++, pyd++, addr += PYD_SIZE) {
27367 + pxd_t *pxd = pxds[i];
27368
27369 if (i >= KERNEL_PGD_BOUNDARY)
27370 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27371 - sizeof(pmd_t) * PTRS_PER_PMD);
27372 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27373 + sizeof(pxd_t) * PTRS_PER_PMD);
27374
27375 - pud_populate(mm, pud, pmd);
27376 + pyd_populate(mm, pyd, pxd);
27377 }
27378 }
27379
27380 pgd_t *pgd_alloc(struct mm_struct *mm)
27381 {
27382 pgd_t *pgd;
27383 - pmd_t *pmds[PREALLOCATED_PMDS];
27384 + pxd_t *pxds[PREALLOCATED_PXDS];
27385
27386 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27387
27388 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27389
27390 mm->pgd = pgd;
27391
27392 - if (preallocate_pmds(pmds) != 0)
27393 + if (preallocate_pxds(pxds) != 0)
27394 goto out_free_pgd;
27395
27396 if (paravirt_pgd_alloc(mm) != 0)
27397 - goto out_free_pmds;
27398 + goto out_free_pxds;
27399
27400 /*
27401 * Make sure that pre-populating the pmds is atomic with
27402 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27403 spin_lock(&pgd_lock);
27404
27405 pgd_ctor(mm, pgd);
27406 - pgd_prepopulate_pmd(mm, pgd, pmds);
27407 + pgd_prepopulate_pxd(mm, pgd, pxds);
27408
27409 spin_unlock(&pgd_lock);
27410
27411 return pgd;
27412
27413 -out_free_pmds:
27414 - free_pmds(pmds);
27415 +out_free_pxds:
27416 + free_pxds(pxds);
27417 out_free_pgd:
27418 free_page((unsigned long)pgd);
27419 out:
27420 @@ -295,7 +356,7 @@ out:
27421
27422 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27423 {
27424 - pgd_mop_up_pmds(mm, pgd);
27425 + pgd_mop_up_pxds(mm, pgd);
27426 pgd_dtor(pgd);
27427 paravirt_pgd_free(mm, pgd);
27428 free_page((unsigned long)pgd);
27429 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27430 index a69bcb8..19068ab 100644
27431 --- a/arch/x86/mm/pgtable_32.c
27432 +++ b/arch/x86/mm/pgtable_32.c
27433 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27434 return;
27435 }
27436 pte = pte_offset_kernel(pmd, vaddr);
27437 +
27438 + pax_open_kernel();
27439 if (pte_val(pteval))
27440 set_pte_at(&init_mm, vaddr, pte, pteval);
27441 else
27442 pte_clear(&init_mm, vaddr, pte);
27443 + pax_close_kernel();
27444
27445 /*
27446 * It's enough to flush this one mapping.
27447 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27448 index 410531d..0f16030 100644
27449 --- a/arch/x86/mm/setup_nx.c
27450 +++ b/arch/x86/mm/setup_nx.c
27451 @@ -5,8 +5,10 @@
27452 #include <asm/pgtable.h>
27453 #include <asm/proto.h>
27454
27455 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27456 static int disable_nx __cpuinitdata;
27457
27458 +#ifndef CONFIG_PAX_PAGEEXEC
27459 /*
27460 * noexec = on|off
27461 *
27462 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27463 return 0;
27464 }
27465 early_param("noexec", noexec_setup);
27466 +#endif
27467 +
27468 +#endif
27469
27470 void __cpuinit x86_configure_nx(void)
27471 {
27472 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27473 if (cpu_has_nx && !disable_nx)
27474 __supported_pte_mask |= _PAGE_NX;
27475 else
27476 +#endif
27477 __supported_pte_mask &= ~_PAGE_NX;
27478 }
27479
27480 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27481 index 60f926c..a710970 100644
27482 --- a/arch/x86/mm/tlb.c
27483 +++ b/arch/x86/mm/tlb.c
27484 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
27485 BUG();
27486 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27487 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27488 +
27489 +#ifndef CONFIG_PAX_PER_CPU_PGD
27490 load_cr3(swapper_pg_dir);
27491 +#endif
27492 +
27493 }
27494 }
27495 EXPORT_SYMBOL_GPL(leave_mm);
27496 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27497 index 877b9a1..a8ecf42 100644
27498 --- a/arch/x86/net/bpf_jit.S
27499 +++ b/arch/x86/net/bpf_jit.S
27500 @@ -9,6 +9,7 @@
27501 */
27502 #include <linux/linkage.h>
27503 #include <asm/dwarf2.h>
27504 +#include <asm/alternative-asm.h>
27505
27506 /*
27507 * Calling convention :
27508 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27509 jle bpf_slow_path_word
27510 mov (SKBDATA,%rsi),%eax
27511 bswap %eax /* ntohl() */
27512 + pax_force_retaddr
27513 ret
27514
27515 sk_load_half:
27516 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27517 jle bpf_slow_path_half
27518 movzwl (SKBDATA,%rsi),%eax
27519 rol $8,%ax # ntohs()
27520 + pax_force_retaddr
27521 ret
27522
27523 sk_load_byte:
27524 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27525 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27526 jle bpf_slow_path_byte
27527 movzbl (SKBDATA,%rsi),%eax
27528 + pax_force_retaddr
27529 ret
27530
27531 /**
27532 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27533 movzbl (SKBDATA,%rsi),%ebx
27534 and $15,%bl
27535 shl $2,%bl
27536 + pax_force_retaddr
27537 ret
27538
27539 /* rsi contains offset and can be scratched */
27540 @@ -109,6 +114,7 @@ bpf_slow_path_word:
27541 js bpf_error
27542 mov -12(%rbp),%eax
27543 bswap %eax
27544 + pax_force_retaddr
27545 ret
27546
27547 bpf_slow_path_half:
27548 @@ -117,12 +123,14 @@ bpf_slow_path_half:
27549 mov -12(%rbp),%ax
27550 rol $8,%ax
27551 movzwl %ax,%eax
27552 + pax_force_retaddr
27553 ret
27554
27555 bpf_slow_path_byte:
27556 bpf_slow_path_common(1)
27557 js bpf_error
27558 movzbl -12(%rbp),%eax
27559 + pax_force_retaddr
27560 ret
27561
27562 bpf_slow_path_byte_msh:
27563 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27564 and $15,%al
27565 shl $2,%al
27566 xchg %eax,%ebx
27567 + pax_force_retaddr
27568 ret
27569
27570 #define sk_negative_common(SIZE) \
27571 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27572 sk_negative_common(4)
27573 mov (%rax), %eax
27574 bswap %eax
27575 + pax_force_retaddr
27576 ret
27577
27578 bpf_slow_path_half_neg:
27579 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27580 mov (%rax),%ax
27581 rol $8,%ax
27582 movzwl %ax,%eax
27583 + pax_force_retaddr
27584 ret
27585
27586 bpf_slow_path_byte_neg:
27587 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27588 .globl sk_load_byte_negative_offset
27589 sk_negative_common(1)
27590 movzbl (%rax), %eax
27591 + pax_force_retaddr
27592 ret
27593
27594 bpf_slow_path_byte_msh_neg:
27595 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27596 and $15,%al
27597 shl $2,%al
27598 xchg %eax,%ebx
27599 + pax_force_retaddr
27600 ret
27601
27602 bpf_error:
27603 @@ -197,4 +210,5 @@ bpf_error:
27604 xor %eax,%eax
27605 mov -8(%rbp),%rbx
27606 leaveq
27607 + pax_force_retaddr
27608 ret
27609 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27610 index 520d2bd..b895ef4 100644
27611 --- a/arch/x86/net/bpf_jit_comp.c
27612 +++ b/arch/x86/net/bpf_jit_comp.c
27613 @@ -11,6 +11,7 @@
27614 #include <asm/cacheflush.h>
27615 #include <linux/netdevice.h>
27616 #include <linux/filter.h>
27617 +#include <linux/random.h>
27618
27619 /*
27620 * Conventions :
27621 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27622 return ptr + len;
27623 }
27624
27625 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27626 +#define MAX_INSTR_CODE_SIZE 96
27627 +#else
27628 +#define MAX_INSTR_CODE_SIZE 64
27629 +#endif
27630 +
27631 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27632
27633 #define EMIT1(b1) EMIT(b1, 1)
27634 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27635 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27636 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27637 +
27638 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27639 +/* original constant will appear in ecx */
27640 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
27641 +do { \
27642 + /* mov ecx, randkey */ \
27643 + EMIT1(0xb9); \
27644 + EMIT(_key, 4); \
27645 + /* xor ecx, randkey ^ off */ \
27646 + EMIT2(0x81, 0xf1); \
27647 + EMIT((_key) ^ (_off), 4); \
27648 +} while (0)
27649 +
27650 +#define EMIT1_off32(b1, _off) \
27651 +do { \
27652 + switch (b1) { \
27653 + case 0x05: /* add eax, imm32 */ \
27654 + case 0x2d: /* sub eax, imm32 */ \
27655 + case 0x25: /* and eax, imm32 */ \
27656 + case 0x0d: /* or eax, imm32 */ \
27657 + case 0xb8: /* mov eax, imm32 */ \
27658 + case 0x3d: /* cmp eax, imm32 */ \
27659 + case 0xa9: /* test eax, imm32 */ \
27660 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27661 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27662 + break; \
27663 + case 0xbb: /* mov ebx, imm32 */ \
27664 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27665 + /* mov ebx, ecx */ \
27666 + EMIT2(0x89, 0xcb); \
27667 + break; \
27668 + case 0xbe: /* mov esi, imm32 */ \
27669 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27670 + /* mov esi, ecx */ \
27671 + EMIT2(0x89, 0xce); \
27672 + break; \
27673 + case 0xe9: /* jmp rel imm32 */ \
27674 + EMIT1(b1); \
27675 + EMIT(_off, 4); \
27676 + /* prevent fall-through, we're not called if off = 0 */ \
27677 + EMIT(0xcccccccc, 4); \
27678 + EMIT(0xcccccccc, 4); \
27679 + break; \
27680 + default: \
27681 + EMIT1(b1); \
27682 + EMIT(_off, 4); \
27683 + } \
27684 +} while (0)
27685 +
27686 +#define EMIT2_off32(b1, b2, _off) \
27687 +do { \
27688 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27689 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27690 + EMIT(randkey, 4); \
27691 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27692 + EMIT((_off) - randkey, 4); \
27693 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27694 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27695 + /* imul eax, ecx */ \
27696 + EMIT3(0x0f, 0xaf, 0xc1); \
27697 + } else { \
27698 + EMIT2(b1, b2); \
27699 + EMIT(_off, 4); \
27700 + } \
27701 +} while (0)
27702 +#else
27703 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27704 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27705 +#endif
27706
27707 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27708 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27709 @@ -89,6 +164,24 @@ do { \
27710 #define X86_JBE 0x76
27711 #define X86_JA 0x77
27712
27713 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27714 +#define APPEND_FLOW_VERIFY() \
27715 +do { \
27716 + /* mov ecx, randkey */ \
27717 + EMIT1(0xb9); \
27718 + EMIT(randkey, 4); \
27719 + /* cmp ecx, randkey */ \
27720 + EMIT2(0x81, 0xf9); \
27721 + EMIT(randkey, 4); \
27722 + /* jz after 8 int 3s */ \
27723 + EMIT2(0x74, 0x08); \
27724 + EMIT(0xcccccccc, 4); \
27725 + EMIT(0xcccccccc, 4); \
27726 +} while (0)
27727 +#else
27728 +#define APPEND_FLOW_VERIFY() do { } while (0)
27729 +#endif
27730 +
27731 #define EMIT_COND_JMP(op, offset) \
27732 do { \
27733 if (is_near(offset)) \
27734 @@ -96,6 +189,7 @@ do { \
27735 else { \
27736 EMIT2(0x0f, op + 0x10); \
27737 EMIT(offset, 4); /* jxx .+off32 */ \
27738 + APPEND_FLOW_VERIFY(); \
27739 } \
27740 } while (0)
27741
27742 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27743 set_fs(old_fs);
27744 }
27745
27746 +struct bpf_jit_work {
27747 + struct work_struct work;
27748 + void *image;
27749 +};
27750 +
27751 #define CHOOSE_LOAD_FUNC(K, func) \
27752 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27753
27754 void bpf_jit_compile(struct sk_filter *fp)
27755 {
27756 - u8 temp[64];
27757 + u8 temp[MAX_INSTR_CODE_SIZE];
27758 u8 *prog;
27759 unsigned int proglen, oldproglen = 0;
27760 int ilen, i;
27761 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27762 unsigned int *addrs;
27763 const struct sock_filter *filter = fp->insns;
27764 int flen = fp->len;
27765 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27766 + unsigned int randkey;
27767 +#endif
27768
27769 if (!bpf_jit_enable)
27770 return;
27771 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27772 if (addrs == NULL)
27773 return;
27774
27775 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27776 + if (!fp->work)
27777 + goto out;
27778 +
27779 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27780 + randkey = get_random_int();
27781 +#endif
27782 +
27783 /* Before first pass, make a rough estimation of addrs[]
27784 - * each bpf instruction is translated to less than 64 bytes
27785 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27786 */
27787 for (proglen = 0, i = 0; i < flen; i++) {
27788 - proglen += 64;
27789 + proglen += MAX_INSTR_CODE_SIZE;
27790 addrs[i] = proglen;
27791 }
27792 cleanup_addr = proglen; /* epilogue address */
27793 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27794 case BPF_S_ALU_MUL_K: /* A *= K */
27795 if (is_imm8(K))
27796 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27797 - else {
27798 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27799 - EMIT(K, 4);
27800 - }
27801 + else
27802 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27803 break;
27804 case BPF_S_ALU_DIV_X: /* A /= X; */
27805 seen |= SEEN_XREG;
27806 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27807 break;
27808 case BPF_S_ALU_MOD_K: /* A %= K; */
27809 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27810 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27811 + DILUTE_CONST_SEQUENCE(K, randkey);
27812 +#else
27813 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27814 +#endif
27815 EMIT2(0xf7, 0xf1); /* div %ecx */
27816 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27817 break;
27818 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27819 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27820 + DILUTE_CONST_SEQUENCE(K, randkey);
27821 + // imul rax, rcx
27822 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27823 +#else
27824 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27825 EMIT(K, 4);
27826 +#endif
27827 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27828 break;
27829 case BPF_S_ALU_AND_X:
27830 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27831 if (is_imm8(K)) {
27832 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27833 } else {
27834 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27835 - EMIT(K, 4);
27836 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27837 }
27838 } else {
27839 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27840 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27841 break;
27842 default:
27843 /* hmm, too complex filter, give up with jit compiler */
27844 - goto out;
27845 + goto error;
27846 }
27847 ilen = prog - temp;
27848 if (image) {
27849 if (unlikely(proglen + ilen > oldproglen)) {
27850 pr_err("bpb_jit_compile fatal error\n");
27851 - kfree(addrs);
27852 - module_free(NULL, image);
27853 - return;
27854 + module_free_exec(NULL, image);
27855 + goto error;
27856 }
27857 + pax_open_kernel();
27858 memcpy(image + proglen, temp, ilen);
27859 + pax_close_kernel();
27860 }
27861 proglen += ilen;
27862 addrs[i] = proglen;
27863 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27864 break;
27865 }
27866 if (proglen == oldproglen) {
27867 - image = module_alloc(max_t(unsigned int,
27868 - proglen,
27869 - sizeof(struct work_struct)));
27870 + image = module_alloc_exec(proglen);
27871 if (!image)
27872 - goto out;
27873 + goto error;
27874 }
27875 oldproglen = proglen;
27876 }
27877 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27878 bpf_flush_icache(image, image + proglen);
27879
27880 fp->bpf_func = (void *)image;
27881 - }
27882 + } else
27883 +error:
27884 + kfree(fp->work);
27885 +
27886 out:
27887 kfree(addrs);
27888 return;
27889 @@ -686,18 +805,20 @@ out:
27890
27891 static void jit_free_defer(struct work_struct *arg)
27892 {
27893 - module_free(NULL, arg);
27894 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27895 + kfree(arg);
27896 }
27897
27898 /* run from softirq, we must use a work_struct to call
27899 - * module_free() from process context
27900 + * module_free_exec() from process context
27901 */
27902 void bpf_jit_free(struct sk_filter *fp)
27903 {
27904 if (fp->bpf_func != sk_run_filter) {
27905 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
27906 + struct work_struct *work = &fp->work->work;
27907
27908 INIT_WORK(work, jit_free_defer);
27909 + fp->work->image = fp->bpf_func;
27910 schedule_work(work);
27911 }
27912 }
27913 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27914 index d6aa6e8..266395a 100644
27915 --- a/arch/x86/oprofile/backtrace.c
27916 +++ b/arch/x86/oprofile/backtrace.c
27917 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27918 struct stack_frame_ia32 *fp;
27919 unsigned long bytes;
27920
27921 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27922 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27923 if (bytes != sizeof(bufhead))
27924 return NULL;
27925
27926 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27927 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27928
27929 oprofile_add_trace(bufhead[0].return_address);
27930
27931 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27932 struct stack_frame bufhead[2];
27933 unsigned long bytes;
27934
27935 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27936 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27937 if (bytes != sizeof(bufhead))
27938 return NULL;
27939
27940 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27941 {
27942 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27943
27944 - if (!user_mode_vm(regs)) {
27945 + if (!user_mode(regs)) {
27946 unsigned long stack = kernel_stack_pointer(regs);
27947 if (depth)
27948 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27949 diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
27950 index 192397c..5ba6f9e 100644
27951 --- a/arch/x86/pci/acpi.c
27952 +++ b/arch/x86/pci/acpi.c
27953 @@ -568,7 +568,7 @@ int __init pci_acpi_init(void)
27954 acpi_irq_penalty_init();
27955 pcibios_enable_irq = acpi_pci_irq_enable;
27956 pcibios_disable_irq = acpi_pci_irq_disable;
27957 - x86_init.pci.init_irq = x86_init_noop;
27958 + *(void **)&x86_init.pci.init_irq = x86_init_noop;
27959
27960 if (pci_routeirq) {
27961 /*
27962 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27963 index e14a2ff..3fd6b58 100644
27964 --- a/arch/x86/pci/mrst.c
27965 +++ b/arch/x86/pci/mrst.c
27966 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27967 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27968 pci_mmcfg_late_init();
27969 pcibios_enable_irq = mrst_pci_irq_enable;
27970 - pci_root_ops = pci_mrst_ops;
27971 + pax_open_kernel();
27972 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27973 + pax_close_kernel();
27974 pci_soc_mode = 1;
27975 /* Continue with standard init */
27976 return 1;
27977 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27978 index da8fe05..7ee6704 100644
27979 --- a/arch/x86/pci/pcbios.c
27980 +++ b/arch/x86/pci/pcbios.c
27981 @@ -79,50 +79,93 @@ union bios32 {
27982 static struct {
27983 unsigned long address;
27984 unsigned short segment;
27985 -} bios32_indirect = { 0, __KERNEL_CS };
27986 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27987
27988 /*
27989 * Returns the entry point for the given service, NULL on error
27990 */
27991
27992 -static unsigned long bios32_service(unsigned long service)
27993 +static unsigned long __devinit bios32_service(unsigned long service)
27994 {
27995 unsigned char return_code; /* %al */
27996 unsigned long address; /* %ebx */
27997 unsigned long length; /* %ecx */
27998 unsigned long entry; /* %edx */
27999 unsigned long flags;
28000 + struct desc_struct d, *gdt;
28001
28002 local_irq_save(flags);
28003 - __asm__("lcall *(%%edi); cld"
28004 +
28005 + gdt = get_cpu_gdt_table(smp_processor_id());
28006 +
28007 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
28008 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28009 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
28010 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28011 +
28012 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
28013 : "=a" (return_code),
28014 "=b" (address),
28015 "=c" (length),
28016 "=d" (entry)
28017 : "0" (service),
28018 "1" (0),
28019 - "D" (&bios32_indirect));
28020 + "D" (&bios32_indirect),
28021 + "r"(__PCIBIOS_DS)
28022 + : "memory");
28023 +
28024 + pax_open_kernel();
28025 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
28026 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
28027 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
28028 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
28029 + pax_close_kernel();
28030 +
28031 local_irq_restore(flags);
28032
28033 switch (return_code) {
28034 - case 0:
28035 - return address + entry;
28036 - case 0x80: /* Not present */
28037 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28038 - return 0;
28039 - default: /* Shouldn't happen */
28040 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28041 - service, return_code);
28042 + case 0: {
28043 + int cpu;
28044 + unsigned char flags;
28045 +
28046 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
28047 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
28048 + printk(KERN_WARNING "bios32_service: not valid\n");
28049 return 0;
28050 + }
28051 + address = address + PAGE_OFFSET;
28052 + length += 16UL; /* some BIOSs underreport this... */
28053 + flags = 4;
28054 + if (length >= 64*1024*1024) {
28055 + length >>= PAGE_SHIFT;
28056 + flags |= 8;
28057 + }
28058 +
28059 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28060 + gdt = get_cpu_gdt_table(cpu);
28061 + pack_descriptor(&d, address, length, 0x9b, flags);
28062 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28063 + pack_descriptor(&d, address, length, 0x93, flags);
28064 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28065 + }
28066 + return entry;
28067 + }
28068 + case 0x80: /* Not present */
28069 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28070 + return 0;
28071 + default: /* Shouldn't happen */
28072 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28073 + service, return_code);
28074 + return 0;
28075 }
28076 }
28077
28078 static struct {
28079 unsigned long address;
28080 unsigned short segment;
28081 -} pci_indirect = { 0, __KERNEL_CS };
28082 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
28083
28084 -static int pci_bios_present;
28085 +static int pci_bios_present __read_only;
28086
28087 static int __devinit check_pcibios(void)
28088 {
28089 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
28090 unsigned long flags, pcibios_entry;
28091
28092 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
28093 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
28094 + pci_indirect.address = pcibios_entry;
28095
28096 local_irq_save(flags);
28097 - __asm__(
28098 - "lcall *(%%edi); cld\n\t"
28099 + __asm__("movw %w6, %%ds\n\t"
28100 + "lcall *%%ss:(%%edi); cld\n\t"
28101 + "push %%ss\n\t"
28102 + "pop %%ds\n\t"
28103 "jc 1f\n\t"
28104 "xor %%ah, %%ah\n"
28105 "1:"
28106 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
28107 "=b" (ebx),
28108 "=c" (ecx)
28109 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
28110 - "D" (&pci_indirect)
28111 + "D" (&pci_indirect),
28112 + "r" (__PCIBIOS_DS)
28113 : "memory");
28114 local_irq_restore(flags);
28115
28116 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28117
28118 switch (len) {
28119 case 1:
28120 - __asm__("lcall *(%%esi); cld\n\t"
28121 + __asm__("movw %w6, %%ds\n\t"
28122 + "lcall *%%ss:(%%esi); cld\n\t"
28123 + "push %%ss\n\t"
28124 + "pop %%ds\n\t"
28125 "jc 1f\n\t"
28126 "xor %%ah, %%ah\n"
28127 "1:"
28128 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28129 : "1" (PCIBIOS_READ_CONFIG_BYTE),
28130 "b" (bx),
28131 "D" ((long)reg),
28132 - "S" (&pci_indirect));
28133 + "S" (&pci_indirect),
28134 + "r" (__PCIBIOS_DS));
28135 /*
28136 * Zero-extend the result beyond 8 bits, do not trust the
28137 * BIOS having done it:
28138 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28139 *value &= 0xff;
28140 break;
28141 case 2:
28142 - __asm__("lcall *(%%esi); cld\n\t"
28143 + __asm__("movw %w6, %%ds\n\t"
28144 + "lcall *%%ss:(%%esi); cld\n\t"
28145 + "push %%ss\n\t"
28146 + "pop %%ds\n\t"
28147 "jc 1f\n\t"
28148 "xor %%ah, %%ah\n"
28149 "1:"
28150 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28151 : "1" (PCIBIOS_READ_CONFIG_WORD),
28152 "b" (bx),
28153 "D" ((long)reg),
28154 - "S" (&pci_indirect));
28155 + "S" (&pci_indirect),
28156 + "r" (__PCIBIOS_DS));
28157 /*
28158 * Zero-extend the result beyond 16 bits, do not trust the
28159 * BIOS having done it:
28160 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28161 *value &= 0xffff;
28162 break;
28163 case 4:
28164 - __asm__("lcall *(%%esi); cld\n\t"
28165 + __asm__("movw %w6, %%ds\n\t"
28166 + "lcall *%%ss:(%%esi); cld\n\t"
28167 + "push %%ss\n\t"
28168 + "pop %%ds\n\t"
28169 "jc 1f\n\t"
28170 "xor %%ah, %%ah\n"
28171 "1:"
28172 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28173 : "1" (PCIBIOS_READ_CONFIG_DWORD),
28174 "b" (bx),
28175 "D" ((long)reg),
28176 - "S" (&pci_indirect));
28177 + "S" (&pci_indirect),
28178 + "r" (__PCIBIOS_DS));
28179 break;
28180 }
28181
28182 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28183
28184 switch (len) {
28185 case 1:
28186 - __asm__("lcall *(%%esi); cld\n\t"
28187 + __asm__("movw %w6, %%ds\n\t"
28188 + "lcall *%%ss:(%%esi); cld\n\t"
28189 + "push %%ss\n\t"
28190 + "pop %%ds\n\t"
28191 "jc 1f\n\t"
28192 "xor %%ah, %%ah\n"
28193 "1:"
28194 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28195 "c" (value),
28196 "b" (bx),
28197 "D" ((long)reg),
28198 - "S" (&pci_indirect));
28199 + "S" (&pci_indirect),
28200 + "r" (__PCIBIOS_DS));
28201 break;
28202 case 2:
28203 - __asm__("lcall *(%%esi); cld\n\t"
28204 + __asm__("movw %w6, %%ds\n\t"
28205 + "lcall *%%ss:(%%esi); cld\n\t"
28206 + "push %%ss\n\t"
28207 + "pop %%ds\n\t"
28208 "jc 1f\n\t"
28209 "xor %%ah, %%ah\n"
28210 "1:"
28211 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28212 "c" (value),
28213 "b" (bx),
28214 "D" ((long)reg),
28215 - "S" (&pci_indirect));
28216 + "S" (&pci_indirect),
28217 + "r" (__PCIBIOS_DS));
28218 break;
28219 case 4:
28220 - __asm__("lcall *(%%esi); cld\n\t"
28221 + __asm__("movw %w6, %%ds\n\t"
28222 + "lcall *%%ss:(%%esi); cld\n\t"
28223 + "push %%ss\n\t"
28224 + "pop %%ds\n\t"
28225 "jc 1f\n\t"
28226 "xor %%ah, %%ah\n"
28227 "1:"
28228 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28229 "c" (value),
28230 "b" (bx),
28231 "D" ((long)reg),
28232 - "S" (&pci_indirect));
28233 + "S" (&pci_indirect),
28234 + "r" (__PCIBIOS_DS));
28235 break;
28236 }
28237
28238 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28239
28240 DBG("PCI: Fetching IRQ routing table... ");
28241 __asm__("push %%es\n\t"
28242 + "movw %w8, %%ds\n\t"
28243 "push %%ds\n\t"
28244 "pop %%es\n\t"
28245 - "lcall *(%%esi); cld\n\t"
28246 + "lcall *%%ss:(%%esi); cld\n\t"
28247 "pop %%es\n\t"
28248 + "push %%ss\n\t"
28249 + "pop %%ds\n"
28250 "jc 1f\n\t"
28251 "xor %%ah, %%ah\n"
28252 "1:"
28253 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28254 "1" (0),
28255 "D" ((long) &opt),
28256 "S" (&pci_indirect),
28257 - "m" (opt)
28258 + "m" (opt),
28259 + "r" (__PCIBIOS_DS)
28260 : "memory");
28261 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
28262 if (ret & 0xff00)
28263 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28264 {
28265 int ret;
28266
28267 - __asm__("lcall *(%%esi); cld\n\t"
28268 + __asm__("movw %w5, %%ds\n\t"
28269 + "lcall *%%ss:(%%esi); cld\n\t"
28270 + "push %%ss\n\t"
28271 + "pop %%ds\n"
28272 "jc 1f\n\t"
28273 "xor %%ah, %%ah\n"
28274 "1:"
28275 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28276 : "0" (PCIBIOS_SET_PCI_HW_INT),
28277 "b" ((dev->bus->number << 8) | dev->devfn),
28278 "c" ((irq << 8) | (pin + 10)),
28279 - "S" (&pci_indirect));
28280 + "S" (&pci_indirect),
28281 + "r" (__PCIBIOS_DS));
28282 return !(ret & 0xff00);
28283 }
28284 EXPORT_SYMBOL(pcibios_set_irq_routing);
28285 diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c
28286 index 56ab749..3cb792a 100644
28287 --- a/arch/x86/pci/xen.c
28288 +++ b/arch/x86/pci/xen.c
28289 @@ -395,9 +395,9 @@ int __init pci_xen_init(void)
28290 #endif
28291
28292 #ifdef CONFIG_PCI_MSI
28293 - x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28294 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28295 - x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28296 + *(void **)&x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28297 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28298 + *(void **)&x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28299 #endif
28300 return 0;
28301 }
28302 @@ -416,8 +416,8 @@ int __init pci_xen_hvm_init(void)
28303 #endif
28304
28305 #ifdef CONFIG_PCI_MSI
28306 - x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28307 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28308 + *(void **)&x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28309 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28310 #endif
28311 return 0;
28312 }
28313 @@ -474,9 +474,9 @@ int __init pci_xen_initial_domain(void)
28314 int irq;
28315
28316 #ifdef CONFIG_PCI_MSI
28317 - x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28318 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28319 - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28320 + *(void **)&x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28321 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28322 + *(void **)&x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28323 #endif
28324 xen_setup_acpi_sci();
28325 __acpi_register_gsi = acpi_register_gsi_xen;
28326 diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
28327 index 77cf009..7fe44c8 100644
28328 --- a/arch/x86/platform/efi/efi.c
28329 +++ b/arch/x86/platform/efi/efi.c
28330 @@ -746,8 +746,8 @@ void __init efi_init(void)
28331
28332 #ifdef CONFIG_X86_32
28333 if (efi_is_native()) {
28334 - x86_platform.get_wallclock = efi_get_time;
28335 - x86_platform.set_wallclock = efi_set_rtc_mmss;
28336 + *(void **)&x86_platform.get_wallclock = efi_get_time;
28337 + *(void **)&x86_platform.set_wallclock = efi_set_rtc_mmss;
28338 }
28339 #endif
28340
28341 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28342 index 40e4469..1ab536e 100644
28343 --- a/arch/x86/platform/efi/efi_32.c
28344 +++ b/arch/x86/platform/efi/efi_32.c
28345 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28346 {
28347 struct desc_ptr gdt_descr;
28348
28349 +#ifdef CONFIG_PAX_KERNEXEC
28350 + struct desc_struct d;
28351 +#endif
28352 +
28353 local_irq_save(efi_rt_eflags);
28354
28355 load_cr3(initial_page_table);
28356 __flush_tlb_all();
28357
28358 +#ifdef CONFIG_PAX_KERNEXEC
28359 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28360 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28361 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28362 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28363 +#endif
28364 +
28365 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28366 gdt_descr.size = GDT_SIZE - 1;
28367 load_gdt(&gdt_descr);
28368 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28369 {
28370 struct desc_ptr gdt_descr;
28371
28372 +#ifdef CONFIG_PAX_KERNEXEC
28373 + struct desc_struct d;
28374 +
28375 + memset(&d, 0, sizeof d);
28376 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28377 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28378 +#endif
28379 +
28380 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28381 gdt_descr.size = GDT_SIZE - 1;
28382 load_gdt(&gdt_descr);
28383 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28384 index fbe66e6..eae5e38 100644
28385 --- a/arch/x86/platform/efi/efi_stub_32.S
28386 +++ b/arch/x86/platform/efi/efi_stub_32.S
28387 @@ -6,7 +6,9 @@
28388 */
28389
28390 #include <linux/linkage.h>
28391 +#include <linux/init.h>
28392 #include <asm/page_types.h>
28393 +#include <asm/segment.h>
28394
28395 /*
28396 * efi_call_phys(void *, ...) is a function with variable parameters.
28397 @@ -20,7 +22,7 @@
28398 * service functions will comply with gcc calling convention, too.
28399 */
28400
28401 -.text
28402 +__INIT
28403 ENTRY(efi_call_phys)
28404 /*
28405 * 0. The function can only be called in Linux kernel. So CS has been
28406 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28407 * The mapping of lower virtual memory has been created in prelog and
28408 * epilog.
28409 */
28410 - movl $1f, %edx
28411 - subl $__PAGE_OFFSET, %edx
28412 - jmp *%edx
28413 +#ifdef CONFIG_PAX_KERNEXEC
28414 + movl $(__KERNEXEC_EFI_DS), %edx
28415 + mov %edx, %ds
28416 + mov %edx, %es
28417 + mov %edx, %ss
28418 + addl $2f,(1f)
28419 + ljmp *(1f)
28420 +
28421 +__INITDATA
28422 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28423 +.previous
28424 +
28425 +2:
28426 + subl $2b,(1b)
28427 +#else
28428 + jmp 1f-__PAGE_OFFSET
28429 1:
28430 +#endif
28431
28432 /*
28433 * 2. Now on the top of stack is the return
28434 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28435 * parameter 2, ..., param n. To make things easy, we save the return
28436 * address of efi_call_phys in a global variable.
28437 */
28438 - popl %edx
28439 - movl %edx, saved_return_addr
28440 - /* get the function pointer into ECX*/
28441 - popl %ecx
28442 - movl %ecx, efi_rt_function_ptr
28443 - movl $2f, %edx
28444 - subl $__PAGE_OFFSET, %edx
28445 - pushl %edx
28446 + popl (saved_return_addr)
28447 + popl (efi_rt_function_ptr)
28448
28449 /*
28450 * 3. Clear PG bit in %CR0.
28451 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28452 /*
28453 * 5. Call the physical function.
28454 */
28455 - jmp *%ecx
28456 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
28457
28458 -2:
28459 /*
28460 * 6. After EFI runtime service returns, control will return to
28461 * following instruction. We'd better readjust stack pointer first.
28462 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28463 movl %cr0, %edx
28464 orl $0x80000000, %edx
28465 movl %edx, %cr0
28466 - jmp 1f
28467 -1:
28468 +
28469 /*
28470 * 8. Now restore the virtual mode from flat mode by
28471 * adding EIP with PAGE_OFFSET.
28472 */
28473 - movl $1f, %edx
28474 - jmp *%edx
28475 +#ifdef CONFIG_PAX_KERNEXEC
28476 + movl $(__KERNEL_DS), %edx
28477 + mov %edx, %ds
28478 + mov %edx, %es
28479 + mov %edx, %ss
28480 + ljmp $(__KERNEL_CS),$1f
28481 +#else
28482 + jmp 1f+__PAGE_OFFSET
28483 +#endif
28484 1:
28485
28486 /*
28487 * 9. Balance the stack. And because EAX contain the return value,
28488 * we'd better not clobber it.
28489 */
28490 - leal efi_rt_function_ptr, %edx
28491 - movl (%edx), %ecx
28492 - pushl %ecx
28493 + pushl (efi_rt_function_ptr)
28494
28495 /*
28496 - * 10. Push the saved return address onto the stack and return.
28497 + * 10. Return to the saved return address.
28498 */
28499 - leal saved_return_addr, %edx
28500 - movl (%edx), %ecx
28501 - pushl %ecx
28502 - ret
28503 + jmpl *(saved_return_addr)
28504 ENDPROC(efi_call_phys)
28505 .previous
28506
28507 -.data
28508 +__INITDATA
28509 saved_return_addr:
28510 .long 0
28511 efi_rt_function_ptr:
28512 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28513 index 4c07cca..2c8427d 100644
28514 --- a/arch/x86/platform/efi/efi_stub_64.S
28515 +++ b/arch/x86/platform/efi/efi_stub_64.S
28516 @@ -7,6 +7,7 @@
28517 */
28518
28519 #include <linux/linkage.h>
28520 +#include <asm/alternative-asm.h>
28521
28522 #define SAVE_XMM \
28523 mov %rsp, %rax; \
28524 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
28525 call *%rdi
28526 addq $32, %rsp
28527 RESTORE_XMM
28528 + pax_force_retaddr 0, 1
28529 ret
28530 ENDPROC(efi_call0)
28531
28532 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
28533 call *%rdi
28534 addq $32, %rsp
28535 RESTORE_XMM
28536 + pax_force_retaddr 0, 1
28537 ret
28538 ENDPROC(efi_call1)
28539
28540 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
28541 call *%rdi
28542 addq $32, %rsp
28543 RESTORE_XMM
28544 + pax_force_retaddr 0, 1
28545 ret
28546 ENDPROC(efi_call2)
28547
28548 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
28549 call *%rdi
28550 addq $32, %rsp
28551 RESTORE_XMM
28552 + pax_force_retaddr 0, 1
28553 ret
28554 ENDPROC(efi_call3)
28555
28556 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
28557 call *%rdi
28558 addq $32, %rsp
28559 RESTORE_XMM
28560 + pax_force_retaddr 0, 1
28561 ret
28562 ENDPROC(efi_call4)
28563
28564 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
28565 call *%rdi
28566 addq $48, %rsp
28567 RESTORE_XMM
28568 + pax_force_retaddr 0, 1
28569 ret
28570 ENDPROC(efi_call5)
28571
28572 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
28573 call *%rdi
28574 addq $48, %rsp
28575 RESTORE_XMM
28576 + pax_force_retaddr 0, 1
28577 ret
28578 ENDPROC(efi_call6)
28579 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28580 index fd41a92..bc8091d 100644
28581 --- a/arch/x86/platform/mrst/mrst.c
28582 +++ b/arch/x86/platform/mrst/mrst.c
28583 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28584 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28585 int sfi_mrtc_num;
28586
28587 -static void mrst_power_off(void)
28588 +static __noreturn void mrst_power_off(void)
28589 {
28590 + BUG();
28591 }
28592
28593 -static void mrst_reboot(void)
28594 +static __noreturn void mrst_reboot(void)
28595 {
28596 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28597 + BUG();
28598 }
28599
28600 /* parse all the mtimer info to a static mtimer array */
28601 @@ -233,14 +235,14 @@ static void __init mrst_time_init(void)
28602 case MRST_TIMER_APBT_ONLY:
28603 break;
28604 case MRST_TIMER_LAPIC_APBT:
28605 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28606 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28607 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28608 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28609 break;
28610 default:
28611 if (!boot_cpu_has(X86_FEATURE_ARAT))
28612 break;
28613 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28614 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28615 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28616 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28617 return;
28618 }
28619 /* we need at least one APB timer */
28620 @@ -282,35 +284,35 @@ static unsigned char mrst_get_nmi_reason(void)
28621 */
28622 void __init x86_mrst_early_setup(void)
28623 {
28624 - x86_init.resources.probe_roms = x86_init_noop;
28625 - x86_init.resources.reserve_resources = x86_init_noop;
28626 + *(void **)&x86_init.resources.probe_roms = x86_init_noop;
28627 + *(void **)&x86_init.resources.reserve_resources = x86_init_noop;
28628
28629 - x86_init.timers.timer_init = mrst_time_init;
28630 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
28631 + *(void **)&x86_init.timers.timer_init = mrst_time_init;
28632 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
28633
28634 - x86_init.irqs.pre_vector_init = x86_init_noop;
28635 + *(void **)&x86_init.irqs.pre_vector_init = x86_init_noop;
28636
28637 - x86_init.oem.arch_setup = mrst_arch_setup;
28638 + *(void **)&x86_init.oem.arch_setup = mrst_arch_setup;
28639
28640 - x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28641 + *(void **)&x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28642
28643 - x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28644 - x86_platform.i8042_detect = mrst_i8042_detect;
28645 - x86_init.timers.wallclock_init = mrst_rtc_init;
28646 - x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28647 + *(void **)&x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28648 + *(void **)&x86_platform.i8042_detect = mrst_i8042_detect;
28649 + *(void **)&x86_init.timers.wallclock_init = mrst_rtc_init;
28650 + *(void **)&x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28651
28652 - x86_init.pci.init = pci_mrst_init;
28653 - x86_init.pci.fixup_irqs = x86_init_noop;
28654 + *(void **)&x86_init.pci.init = pci_mrst_init;
28655 + *(void **)&x86_init.pci.fixup_irqs = x86_init_noop;
28656
28657 legacy_pic = &null_legacy_pic;
28658
28659 /* Moorestown specific power_off/restart method */
28660 pm_power_off = mrst_power_off;
28661 - machine_ops.emergency_restart = mrst_reboot;
28662 + *(void **)&machine_ops.emergency_restart = mrst_reboot;
28663
28664 /* Avoid searching for BIOS MP tables */
28665 - x86_init.mpparse.find_smp_config = x86_init_noop;
28666 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28667 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
28668 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28669 set_bit(MP_BUS_ISA, mp_bus_not_pci);
28670 }
28671
28672 diff --git a/arch/x86/platform/mrst/vrtc.c b/arch/x86/platform/mrst/vrtc.c
28673 index 225bd0f..22e8086 100644
28674 --- a/arch/x86/platform/mrst/vrtc.c
28675 +++ b/arch/x86/platform/mrst/vrtc.c
28676 @@ -120,8 +120,8 @@ void __init mrst_rtc_init(void)
28677
28678 vrtc_virt_base = (void __iomem *)set_fixmap_offset_nocache(FIX_LNW_VRTC,
28679 vrtc_paddr);
28680 - x86_platform.get_wallclock = vrtc_get_time;
28681 - x86_platform.set_wallclock = vrtc_set_mmss;
28682 + *(void **)&x86_platform.get_wallclock = vrtc_get_time;
28683 + *(void **)&x86_platform.set_wallclock = vrtc_set_mmss;
28684 }
28685
28686 /*
28687 diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
28688 index 2737608..0d62cc2 100644
28689 --- a/arch/x86/platform/olpc/olpc.c
28690 +++ b/arch/x86/platform/olpc/olpc.c
28691 @@ -395,7 +395,7 @@ static int __init olpc_init(void)
28692 * XO-1 only. */
28693 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) &&
28694 !cs5535_has_vsa2())
28695 - x86_init.pci.arch_init = pci_olpc_init;
28696 + *(void **)&x86_init.pci.arch_init = pci_olpc_init;
28697 #endif
28698
28699 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */
28700 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28701 index d6ee929..3637cb5 100644
28702 --- a/arch/x86/platform/olpc/olpc_dt.c
28703 +++ b/arch/x86/platform/olpc/olpc_dt.c
28704 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28705 return res;
28706 }
28707
28708 -static struct of_pdt_ops prom_olpc_ops __initdata = {
28709 +static struct of_pdt_ops prom_olpc_ops __initconst = {
28710 .nextprop = olpc_dt_nextprop,
28711 .getproplen = olpc_dt_getproplen,
28712 .getproperty = olpc_dt_getproperty,
28713 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28714 index 218cdb1..c1178eb 100644
28715 --- a/arch/x86/power/cpu.c
28716 +++ b/arch/x86/power/cpu.c
28717 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
28718 static void fix_processor_context(void)
28719 {
28720 int cpu = smp_processor_id();
28721 - struct tss_struct *t = &per_cpu(init_tss, cpu);
28722 + struct tss_struct *t = init_tss + cpu;
28723
28724 set_tss_desc(cpu, t); /*
28725 * This just modifies memory; should not be
28726 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
28727 */
28728
28729 #ifdef CONFIG_X86_64
28730 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28731 -
28732 syscall_init(); /* This sets MSR_*STAR and related */
28733 #endif
28734 load_TR_desc(); /* This does ltr */
28735 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28736 index cbca565..bae7133 100644
28737 --- a/arch/x86/realmode/init.c
28738 +++ b/arch/x86/realmode/init.c
28739 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28740 __va(real_mode_header->trampoline_header);
28741
28742 #ifdef CONFIG_X86_32
28743 - trampoline_header->start = __pa(startup_32_smp);
28744 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28745 +
28746 +#ifdef CONFIG_PAX_KERNEXEC
28747 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28748 +#endif
28749 +
28750 + trampoline_header->boot_cs = __BOOT_CS;
28751 trampoline_header->gdt_limit = __BOOT_DS + 7;
28752 trampoline_header->gdt_base = __pa(boot_gdt);
28753 #else
28754 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28755 index 8869287..d577672 100644
28756 --- a/arch/x86/realmode/rm/Makefile
28757 +++ b/arch/x86/realmode/rm/Makefile
28758 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28759 $(call cc-option, -fno-unit-at-a-time)) \
28760 $(call cc-option, -fno-stack-protector) \
28761 $(call cc-option, -mpreferred-stack-boundary=2)
28762 +ifdef CONSTIFY_PLUGIN
28763 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28764 +endif
28765 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28766 GCOV_PROFILE := n
28767 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28768 index a28221d..93c40f1 100644
28769 --- a/arch/x86/realmode/rm/header.S
28770 +++ b/arch/x86/realmode/rm/header.S
28771 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28772 #endif
28773 /* APM/BIOS reboot */
28774 .long pa_machine_real_restart_asm
28775 -#ifdef CONFIG_X86_64
28776 +#ifdef CONFIG_X86_32
28777 + .long __KERNEL_CS
28778 +#else
28779 .long __KERNEL32_CS
28780 #endif
28781 END(real_mode_header)
28782 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28783 index c1b2791..f9e31c7 100644
28784 --- a/arch/x86/realmode/rm/trampoline_32.S
28785 +++ b/arch/x86/realmode/rm/trampoline_32.S
28786 @@ -25,6 +25,12 @@
28787 #include <asm/page_types.h>
28788 #include "realmode.h"
28789
28790 +#ifdef CONFIG_PAX_KERNEXEC
28791 +#define ta(X) (X)
28792 +#else
28793 +#define ta(X) (pa_ ## X)
28794 +#endif
28795 +
28796 .text
28797 .code16
28798
28799 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28800
28801 cli # We should be safe anyway
28802
28803 - movl tr_start, %eax # where we need to go
28804 -
28805 movl $0xA5A5A5A5, trampoline_status
28806 # write marker for master knows we're running
28807
28808 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28809 movw $1, %dx # protected mode (PE) bit
28810 lmsw %dx # into protected mode
28811
28812 - ljmpl $__BOOT_CS, $pa_startup_32
28813 + ljmpl *(trampoline_header)
28814
28815 .section ".text32","ax"
28816 .code32
28817 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28818 .balign 8
28819 GLOBAL(trampoline_header)
28820 tr_start: .space 4
28821 - tr_gdt_pad: .space 2
28822 + tr_boot_cs: .space 2
28823 tr_gdt: .space 6
28824 END(trampoline_header)
28825
28826 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28827 index bb360dc..3e5945f 100644
28828 --- a/arch/x86/realmode/rm/trampoline_64.S
28829 +++ b/arch/x86/realmode/rm/trampoline_64.S
28830 @@ -107,7 +107,7 @@ ENTRY(startup_32)
28831 wrmsr
28832
28833 # Enable paging and in turn activate Long Mode
28834 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28835 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
28836 movl %eax, %cr0
28837
28838 /*
28839 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28840 index 5a1847d..deccb30 100644
28841 --- a/arch/x86/tools/relocs.c
28842 +++ b/arch/x86/tools/relocs.c
28843 @@ -12,10 +12,13 @@
28844 #include <regex.h>
28845 #include <tools/le_byteshift.h>
28846
28847 +#include "../../../include/generated/autoconf.h"
28848 +
28849 static void die(char *fmt, ...);
28850
28851 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28852 static Elf32_Ehdr ehdr;
28853 +static Elf32_Phdr *phdr;
28854 static unsigned long reloc_count, reloc_idx;
28855 static unsigned long *relocs;
28856 static unsigned long reloc16_count, reloc16_idx;
28857 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28858 }
28859 }
28860
28861 +static void read_phdrs(FILE *fp)
28862 +{
28863 + unsigned int i;
28864 +
28865 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28866 + if (!phdr) {
28867 + die("Unable to allocate %d program headers\n",
28868 + ehdr.e_phnum);
28869 + }
28870 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28871 + die("Seek to %d failed: %s\n",
28872 + ehdr.e_phoff, strerror(errno));
28873 + }
28874 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28875 + die("Cannot read ELF program headers: %s\n",
28876 + strerror(errno));
28877 + }
28878 + for(i = 0; i < ehdr.e_phnum; i++) {
28879 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28880 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28881 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28882 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28883 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28884 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28885 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28886 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28887 + }
28888 +
28889 +}
28890 +
28891 static void read_shdrs(FILE *fp)
28892 {
28893 - int i;
28894 + unsigned int i;
28895 Elf32_Shdr shdr;
28896
28897 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28898 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28899
28900 static void read_strtabs(FILE *fp)
28901 {
28902 - int i;
28903 + unsigned int i;
28904 for (i = 0; i < ehdr.e_shnum; i++) {
28905 struct section *sec = &secs[i];
28906 if (sec->shdr.sh_type != SHT_STRTAB) {
28907 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28908
28909 static void read_symtabs(FILE *fp)
28910 {
28911 - int i,j;
28912 + unsigned int i,j;
28913 for (i = 0; i < ehdr.e_shnum; i++) {
28914 struct section *sec = &secs[i];
28915 if (sec->shdr.sh_type != SHT_SYMTAB) {
28916 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28917 }
28918
28919
28920 -static void read_relocs(FILE *fp)
28921 +static void read_relocs(FILE *fp, int use_real_mode)
28922 {
28923 - int i,j;
28924 + unsigned int i,j;
28925 + uint32_t base;
28926 +
28927 for (i = 0; i < ehdr.e_shnum; i++) {
28928 struct section *sec = &secs[i];
28929 if (sec->shdr.sh_type != SHT_REL) {
28930 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28931 die("Cannot read symbol table: %s\n",
28932 strerror(errno));
28933 }
28934 + base = 0;
28935 +
28936 +#ifdef CONFIG_X86_32
28937 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28938 + if (phdr[j].p_type != PT_LOAD )
28939 + continue;
28940 + 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)
28941 + continue;
28942 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28943 + break;
28944 + }
28945 +#endif
28946 +
28947 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28948 Elf32_Rel *rel = &sec->reltab[j];
28949 - rel->r_offset = elf32_to_cpu(rel->r_offset);
28950 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28951 rel->r_info = elf32_to_cpu(rel->r_info);
28952 }
28953 }
28954 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28955
28956 static void print_absolute_symbols(void)
28957 {
28958 - int i;
28959 + unsigned int i;
28960 printf("Absolute symbols\n");
28961 printf(" Num: Value Size Type Bind Visibility Name\n");
28962 for (i = 0; i < ehdr.e_shnum; i++) {
28963 struct section *sec = &secs[i];
28964 char *sym_strtab;
28965 - int j;
28966 + unsigned int j;
28967
28968 if (sec->shdr.sh_type != SHT_SYMTAB) {
28969 continue;
28970 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28971
28972 static void print_absolute_relocs(void)
28973 {
28974 - int i, printed = 0;
28975 + unsigned int i, printed = 0;
28976
28977 for (i = 0; i < ehdr.e_shnum; i++) {
28978 struct section *sec = &secs[i];
28979 struct section *sec_applies, *sec_symtab;
28980 char *sym_strtab;
28981 Elf32_Sym *sh_symtab;
28982 - int j;
28983 + unsigned int j;
28984 if (sec->shdr.sh_type != SHT_REL) {
28985 continue;
28986 }
28987 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28988 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28989 int use_real_mode)
28990 {
28991 - int i;
28992 + unsigned int i;
28993 /* Walk through the relocations */
28994 for (i = 0; i < ehdr.e_shnum; i++) {
28995 char *sym_strtab;
28996 Elf32_Sym *sh_symtab;
28997 struct section *sec_applies, *sec_symtab;
28998 - int j;
28999 + unsigned int j;
29000 struct section *sec = &secs[i];
29001
29002 if (sec->shdr.sh_type != SHT_REL) {
29003 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29004 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
29005 r_type = ELF32_R_TYPE(rel->r_info);
29006
29007 + if (!use_real_mode) {
29008 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
29009 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
29010 + continue;
29011 +
29012 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
29013 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
29014 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
29015 + continue;
29016 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
29017 + continue;
29018 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
29019 + continue;
29020 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
29021 + continue;
29022 +#endif
29023 + }
29024 +
29025 shn_abs = sym->st_shndx == SHN_ABS;
29026
29027 switch (r_type) {
29028 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
29029
29030 static void emit_relocs(int as_text, int use_real_mode)
29031 {
29032 - int i;
29033 + unsigned int i;
29034 /* Count how many relocations I have and allocate space for them. */
29035 reloc_count = 0;
29036 walk_relocs(count_reloc, use_real_mode);
29037 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
29038 fname, strerror(errno));
29039 }
29040 read_ehdr(fp);
29041 + read_phdrs(fp);
29042 read_shdrs(fp);
29043 read_strtabs(fp);
29044 read_symtabs(fp);
29045 - read_relocs(fp);
29046 + read_relocs(fp, use_real_mode);
29047 if (show_absolute_syms) {
29048 print_absolute_symbols();
29049 return 0;
29050 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
29051 index fd14be1..e3c79c0 100644
29052 --- a/arch/x86/vdso/Makefile
29053 +++ b/arch/x86/vdso/Makefile
29054 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
29055 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
29056 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
29057
29058 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29059 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29060 GCOV_PROFILE := n
29061
29062 #
29063 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
29064 index 0faad64..39ef157 100644
29065 --- a/arch/x86/vdso/vdso32-setup.c
29066 +++ b/arch/x86/vdso/vdso32-setup.c
29067 @@ -25,6 +25,7 @@
29068 #include <asm/tlbflush.h>
29069 #include <asm/vdso.h>
29070 #include <asm/proto.h>
29071 +#include <asm/mman.h>
29072
29073 enum {
29074 VDSO_DISABLED = 0,
29075 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29076 void enable_sep_cpu(void)
29077 {
29078 int cpu = get_cpu();
29079 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
29080 + struct tss_struct *tss = init_tss + cpu;
29081
29082 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29083 put_cpu();
29084 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29085 gate_vma.vm_start = FIXADDR_USER_START;
29086 gate_vma.vm_end = FIXADDR_USER_END;
29087 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29088 - gate_vma.vm_page_prot = __P101;
29089 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29090
29091 return 0;
29092 }
29093 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29094 if (compat)
29095 addr = VDSO_HIGH_BASE;
29096 else {
29097 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29098 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29099 if (IS_ERR_VALUE(addr)) {
29100 ret = addr;
29101 goto up_fail;
29102 }
29103 }
29104
29105 - current->mm->context.vdso = (void *)addr;
29106 + current->mm->context.vdso = addr;
29107
29108 if (compat_uses_vma || !compat) {
29109 /*
29110 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29111 }
29112
29113 current_thread_info()->sysenter_return =
29114 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29115 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29116
29117 up_fail:
29118 if (ret)
29119 - current->mm->context.vdso = NULL;
29120 + current->mm->context.vdso = 0;
29121
29122 up_write(&mm->mmap_sem);
29123
29124 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
29125
29126 const char *arch_vma_name(struct vm_area_struct *vma)
29127 {
29128 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29129 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29130 return "[vdso]";
29131 +
29132 +#ifdef CONFIG_PAX_SEGMEXEC
29133 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
29134 + return "[vdso]";
29135 +#endif
29136 +
29137 return NULL;
29138 }
29139
29140 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
29141 * Check to see if the corresponding task was created in compat vdso
29142 * mode.
29143 */
29144 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
29145 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
29146 return &gate_vma;
29147 return NULL;
29148 }
29149 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
29150 index 00aaf04..4a26505 100644
29151 --- a/arch/x86/vdso/vma.c
29152 +++ b/arch/x86/vdso/vma.c
29153 @@ -16,8 +16,6 @@
29154 #include <asm/vdso.h>
29155 #include <asm/page.h>
29156
29157 -unsigned int __read_mostly vdso_enabled = 1;
29158 -
29159 extern char vdso_start[], vdso_end[];
29160 extern unsigned short vdso_sync_cpuid;
29161
29162 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
29163 * unaligned here as a result of stack start randomization.
29164 */
29165 addr = PAGE_ALIGN(addr);
29166 - addr = align_addr(addr, NULL, ALIGN_VDSO);
29167
29168 return addr;
29169 }
29170 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
29171 unsigned size)
29172 {
29173 struct mm_struct *mm = current->mm;
29174 - unsigned long addr;
29175 + unsigned long addr = 0;
29176 int ret;
29177
29178 - if (!vdso_enabled)
29179 - return 0;
29180 -
29181 down_write(&mm->mmap_sem);
29182 +
29183 +#ifdef CONFIG_PAX_RANDMMAP
29184 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
29185 +#endif
29186 +
29187 addr = vdso_addr(mm->start_stack, size);
29188 + addr = align_addr(addr, NULL, ALIGN_VDSO);
29189 addr = get_unmapped_area(NULL, addr, size, 0, 0);
29190 if (IS_ERR_VALUE(addr)) {
29191 ret = addr;
29192 goto up_fail;
29193 }
29194
29195 - current->mm->context.vdso = (void *)addr;
29196 + mm->context.vdso = addr;
29197
29198 ret = install_special_mapping(mm, addr, size,
29199 VM_READ|VM_EXEC|
29200 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
29201 pages);
29202 - if (ret) {
29203 - current->mm->context.vdso = NULL;
29204 - goto up_fail;
29205 - }
29206 + if (ret)
29207 + mm->context.vdso = 0;
29208
29209 up_fail:
29210 up_write(&mm->mmap_sem);
29211 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29212 vdsox32_size);
29213 }
29214 #endif
29215 -
29216 -static __init int vdso_setup(char *s)
29217 -{
29218 - vdso_enabled = simple_strtoul(s, NULL, 0);
29219 - return 0;
29220 -}
29221 -__setup("vdso=", vdso_setup);
29222 diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c
29223 index 7005ced..530d6eb 100644
29224 --- a/arch/x86/xen/apic.c
29225 +++ b/arch/x86/xen/apic.c
29226 @@ -30,5 +30,5 @@ static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
29227
29228 void __init xen_init_apic(void)
29229 {
29230 - x86_io_apic_ops.read = xen_io_apic_read;
29231 + *(void **)&x86_io_apic_ops.read = xen_io_apic_read;
29232 }
29233 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
29234 index 586d838..9181904 100644
29235 --- a/arch/x86/xen/enlighten.c
29236 +++ b/arch/x86/xen/enlighten.c
29237 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
29238
29239 struct shared_info xen_dummy_shared_info;
29240
29241 -void *xen_initial_gdt;
29242 -
29243 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
29244 __read_mostly int xen_have_vector_callback;
29245 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
29246 @@ -473,8 +471,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
29247 {
29248 unsigned long va = dtr->address;
29249 unsigned int size = dtr->size + 1;
29250 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29251 - unsigned long frames[pages];
29252 + unsigned long frames[65536 / PAGE_SIZE];
29253 int f;
29254
29255 /*
29256 @@ -522,8 +519,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
29257 {
29258 unsigned long va = dtr->address;
29259 unsigned int size = dtr->size + 1;
29260 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29261 - unsigned long frames[pages];
29262 + unsigned long frames[65536 / PAGE_SIZE];
29263 int f;
29264
29265 /*
29266 @@ -918,21 +914,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
29267
29268 static void set_xen_basic_apic_ops(void)
29269 {
29270 - apic->read = xen_apic_read;
29271 - apic->write = xen_apic_write;
29272 - apic->icr_read = xen_apic_icr_read;
29273 - apic->icr_write = xen_apic_icr_write;
29274 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
29275 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29276 - apic->set_apic_id = xen_set_apic_id;
29277 - apic->get_apic_id = xen_get_apic_id;
29278 + *(void **)&apic->read = xen_apic_read;
29279 + *(void **)&apic->write = xen_apic_write;
29280 + *(void **)&apic->icr_read = xen_apic_icr_read;
29281 + *(void **)&apic->icr_write = xen_apic_icr_write;
29282 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
29283 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29284 + *(void **)&apic->set_apic_id = xen_set_apic_id;
29285 + *(void **)&apic->get_apic_id = xen_get_apic_id;
29286
29287 #ifdef CONFIG_SMP
29288 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29289 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29290 - apic->send_IPI_mask = xen_send_IPI_mask;
29291 - apic->send_IPI_all = xen_send_IPI_all;
29292 - apic->send_IPI_self = xen_send_IPI_self;
29293 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29294 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29295 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
29296 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
29297 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
29298 #endif
29299 }
29300
29301 @@ -1222,30 +1218,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
29302 #endif
29303 };
29304
29305 -static void xen_reboot(int reason)
29306 +static __noreturn void xen_reboot(int reason)
29307 {
29308 struct sched_shutdown r = { .reason = reason };
29309
29310 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
29311 - BUG();
29312 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
29313 + BUG();
29314 }
29315
29316 -static void xen_restart(char *msg)
29317 +static __noreturn void xen_restart(char *msg)
29318 {
29319 xen_reboot(SHUTDOWN_reboot);
29320 }
29321
29322 -static void xen_emergency_restart(void)
29323 +static __noreturn void xen_emergency_restart(void)
29324 {
29325 xen_reboot(SHUTDOWN_reboot);
29326 }
29327
29328 -static void xen_machine_halt(void)
29329 +static __noreturn void xen_machine_halt(void)
29330 {
29331 xen_reboot(SHUTDOWN_poweroff);
29332 }
29333
29334 -static void xen_machine_power_off(void)
29335 +static __noreturn void xen_machine_power_off(void)
29336 {
29337 if (pm_power_off)
29338 pm_power_off();
29339 @@ -1290,14 +1286,14 @@ static const struct machine_ops xen_machine_ops __initconst = {
29340 */
29341 static void __init xen_setup_stackprotector(void)
29342 {
29343 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29344 - pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29345 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29346 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29347
29348 setup_stack_canary_segment(0);
29349 switch_to_new_gdt(0);
29350
29351 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29352 - pv_cpu_ops.load_gdt = xen_load_gdt;
29353 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29354 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt;
29355 }
29356
29357 /* First C function to be called on Xen boot */
29358 @@ -1315,13 +1311,13 @@ asmlinkage void __init xen_start_kernel(void)
29359
29360 /* Install Xen paravirt ops */
29361 pv_info = xen_info;
29362 - pv_init_ops = xen_init_ops;
29363 - pv_cpu_ops = xen_cpu_ops;
29364 - pv_apic_ops = xen_apic_ops;
29365 + memcpy((void *)&pv_init_ops, &xen_init_ops, sizeof pv_init_ops);
29366 + memcpy((void *)&pv_cpu_ops, &xen_cpu_ops, sizeof pv_cpu_ops);
29367 + memcpy((void *)&pv_apic_ops, &xen_apic_ops, sizeof pv_apic_ops);
29368
29369 - x86_init.resources.memory_setup = xen_memory_setup;
29370 - x86_init.oem.arch_setup = xen_arch_setup;
29371 - x86_init.oem.banner = xen_banner;
29372 + *(void **)&x86_init.resources.memory_setup = xen_memory_setup;
29373 + *(void **)&x86_init.oem.arch_setup = xen_arch_setup;
29374 + *(void **)&x86_init.oem.banner = xen_banner;
29375
29376 xen_init_time_ops();
29377
29378 @@ -1347,7 +1343,17 @@ asmlinkage void __init xen_start_kernel(void)
29379 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29380
29381 /* Work out if we support NX */
29382 - x86_configure_nx();
29383 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29384 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29385 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29386 + unsigned l, h;
29387 +
29388 + __supported_pte_mask |= _PAGE_NX;
29389 + rdmsr(MSR_EFER, l, h);
29390 + l |= EFER_NX;
29391 + wrmsr(MSR_EFER, l, h);
29392 + }
29393 +#endif
29394
29395 xen_setup_features();
29396
29397 @@ -1376,14 +1382,7 @@ asmlinkage void __init xen_start_kernel(void)
29398 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29399 }
29400
29401 - machine_ops = xen_machine_ops;
29402 -
29403 - /*
29404 - * The only reliable way to retain the initial address of the
29405 - * percpu gdt_page is to remember it here, so we can go and
29406 - * mark it RW later, when the initial percpu area is freed.
29407 - */
29408 - xen_initial_gdt = &per_cpu(gdt_page, 0);
29409 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29410
29411 xen_smp_init();
29412
29413 @@ -1450,7 +1449,7 @@ asmlinkage void __init xen_start_kernel(void)
29414 add_preferred_console("tty", 0, NULL);
29415 add_preferred_console("hvc", 0, NULL);
29416 if (pci_xen)
29417 - x86_init.pci.arch_init = pci_xen_init;
29418 + *(void **)&x86_init.pci.arch_init = pci_xen_init;
29419 } else {
29420 const struct dom0_vga_console_info *info =
29421 (void *)((char *)xen_start_info +
29422 @@ -1476,8 +1475,8 @@ asmlinkage void __init xen_start_kernel(void)
29423 xen_acpi_sleep_register();
29424
29425 /* Avoid searching for BIOS MP tables */
29426 - x86_init.mpparse.find_smp_config = x86_init_noop;
29427 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29428 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
29429 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29430 }
29431 #ifdef CONFIG_PCI
29432 /* PCI BIOS service won't work from a PV guest. */
29433 @@ -1583,7 +1582,7 @@ static void __init xen_hvm_guest_init(void)
29434 xen_hvm_smp_init();
29435 register_cpu_notifier(&xen_hvm_cpu_notifier);
29436 xen_unplug_emulated_devices();
29437 - x86_init.irqs.intr_init = xen_init_IRQ;
29438 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29439 xen_hvm_init_time_ops();
29440 xen_hvm_init_mmu_ops();
29441 }
29442 diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c
29443 index 01a4dc0..3ca0cc9 100644
29444 --- a/arch/x86/xen/irq.c
29445 +++ b/arch/x86/xen/irq.c
29446 @@ -130,5 +130,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {
29447 void __init xen_init_irq_ops(void)
29448 {
29449 pv_irq_ops = xen_irq_ops;
29450 - x86_init.irqs.intr_init = xen_init_IRQ;
29451 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29452 }
29453 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29454 index dcf5f2d..5f72fe7 100644
29455 --- a/arch/x86/xen/mmu.c
29456 +++ b/arch/x86/xen/mmu.c
29457 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29458 /* L3_k[510] -> level2_kernel_pgt
29459 * L3_i[511] -> level2_fixmap_pgt */
29460 convert_pfn_mfn(level3_kernel_pgt);
29461 + convert_pfn_mfn(level3_vmalloc_start_pgt);
29462 + convert_pfn_mfn(level3_vmalloc_end_pgt);
29463 + convert_pfn_mfn(level3_vmemmap_pgt);
29464
29465 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29466 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29467 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29468 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29469 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29470 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29471 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29472 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29473 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29474 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29475 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29476 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29477 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29478 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29479
29480 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29481 pv_mmu_ops.set_pud = xen_set_pud;
29482 #if PAGETABLE_LEVELS == 4
29483 pv_mmu_ops.set_pgd = xen_set_pgd;
29484 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29485 #endif
29486
29487 /* This will work as long as patching hasn't happened yet
29488 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29489 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29490 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29491 .set_pgd = xen_set_pgd_hyper,
29492 + .set_pgd_batched = xen_set_pgd_hyper,
29493
29494 .alloc_pud = xen_alloc_pmd_init,
29495 .release_pud = xen_release_pmd_init,
29496 @@ -2197,8 +2206,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29497
29498 void __init xen_init_mmu_ops(void)
29499 {
29500 - x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29501 - x86_init.paging.pagetable_init = xen_pagetable_init;
29502 + *(void **)&x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29503 + *(void **)&x86_init.paging.pagetable_init = xen_pagetable_init;
29504 pv_mmu_ops = xen_mmu_ops;
29505
29506 memset(dummy_mapping, 0xff, PAGE_SIZE);
29507 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29508 index 353c50f..a0b9b0d 100644
29509 --- a/arch/x86/xen/smp.c
29510 +++ b/arch/x86/xen/smp.c
29511 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29512 {
29513 BUG_ON(smp_processor_id() != 0);
29514 native_smp_prepare_boot_cpu();
29515 -
29516 - /* We've switched to the "real" per-cpu gdt, so make sure the
29517 - old memory can be recycled */
29518 - make_lowmem_page_readwrite(xen_initial_gdt);
29519 -
29520 xen_filter_cpu_maps();
29521 xen_setup_vcpu_info_placement();
29522 }
29523 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29524 gdt = get_cpu_gdt_table(cpu);
29525
29526 ctxt->flags = VGCF_IN_KERNEL;
29527 - ctxt->user_regs.ds = __USER_DS;
29528 - ctxt->user_regs.es = __USER_DS;
29529 + ctxt->user_regs.ds = __KERNEL_DS;
29530 + ctxt->user_regs.es = __KERNEL_DS;
29531 ctxt->user_regs.ss = __KERNEL_DS;
29532 #ifdef CONFIG_X86_32
29533 ctxt->user_regs.fs = __KERNEL_PERCPU;
29534 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29535 + savesegment(gs, ctxt->user_regs.gs);
29536 #else
29537 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29538 #endif
29539 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29540 int rc;
29541
29542 per_cpu(current_task, cpu) = idle;
29543 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
29544 #ifdef CONFIG_X86_32
29545 irq_ctx_init(cpu);
29546 #else
29547 clear_tsk_thread_flag(idle, TIF_FORK);
29548 - per_cpu(kernel_stack, cpu) =
29549 - (unsigned long)task_stack_page(idle) -
29550 - KERNEL_STACK_OFFSET + THREAD_SIZE;
29551 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29552 #endif
29553 xen_setup_runstate_info(cpu);
29554 xen_setup_timer(cpu);
29555 @@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29556
29557 void __init xen_smp_init(void)
29558 {
29559 - smp_ops = xen_smp_ops;
29560 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29561 xen_fill_possible_map();
29562 xen_init_spinlocks();
29563 }
29564 @@ -672,10 +666,10 @@ void __init xen_hvm_smp_init(void)
29565 {
29566 if (!xen_have_vector_callback)
29567 return;
29568 - smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29569 - smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29570 - smp_ops.cpu_up = xen_hvm_cpu_up;
29571 - smp_ops.cpu_die = xen_hvm_cpu_die;
29572 - smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29573 - smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29574 + *(void **)&smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29575 + *(void **)&smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29576 + *(void **)&smp_ops.cpu_up = xen_hvm_cpu_up;
29577 + *(void **)&smp_ops.cpu_die = xen_hvm_cpu_die;
29578 + *(void **)&smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29579 + *(void **)&smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29580 }
29581 diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
29582 index 83e866d..ef60385 100644
29583 --- a/arch/x86/xen/spinlock.c
29584 +++ b/arch/x86/xen/spinlock.c
29585 @@ -390,12 +390,12 @@ void __init xen_init_spinlocks(void)
29586 {
29587 BUILD_BUG_ON(sizeof(struct xen_spinlock) > sizeof(arch_spinlock_t));
29588
29589 - pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29590 - pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29591 - pv_lock_ops.spin_lock = xen_spin_lock;
29592 - pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29593 - pv_lock_ops.spin_trylock = xen_spin_trylock;
29594 - pv_lock_ops.spin_unlock = xen_spin_unlock;
29595 + *(void **)&pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29596 + *(void **)&pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29597 + *(void **)&pv_lock_ops.spin_lock = xen_spin_lock;
29598 + *(void **)&pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29599 + *(void **)&pv_lock_ops.spin_trylock = xen_spin_trylock;
29600 + *(void **)&pv_lock_ops.spin_unlock = xen_spin_unlock;
29601 }
29602
29603 #ifdef CONFIG_XEN_DEBUG_FS
29604 diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
29605 index 0296a95..3c51a2d 100644
29606 --- a/arch/x86/xen/time.c
29607 +++ b/arch/x86/xen/time.c
29608 @@ -481,15 +481,15 @@ static void __init xen_time_init(void)
29609
29610 void __init xen_init_time_ops(void)
29611 {
29612 - pv_time_ops = xen_time_ops;
29613 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29614
29615 - x86_init.timers.timer_init = xen_time_init;
29616 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
29617 - x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29618 + *(void **)&x86_init.timers.timer_init = xen_time_init;
29619 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
29620 + *(void **)&x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29621
29622 - x86_platform.calibrate_tsc = xen_tsc_khz;
29623 - x86_platform.get_wallclock = xen_get_wallclock;
29624 - x86_platform.set_wallclock = xen_set_wallclock;
29625 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29626 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29627 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29628 }
29629
29630 #ifdef CONFIG_XEN_PVHVM
29631 @@ -514,12 +514,12 @@ void __init xen_hvm_init_time_ops(void)
29632 return;
29633 }
29634
29635 - pv_time_ops = xen_time_ops;
29636 - x86_init.timers.setup_percpu_clockev = xen_time_init;
29637 - x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29638 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29639 + *(void **)&x86_init.timers.setup_percpu_clockev = xen_time_init;
29640 + *(void **)&x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29641
29642 - x86_platform.calibrate_tsc = xen_tsc_khz;
29643 - x86_platform.get_wallclock = xen_get_wallclock;
29644 - x86_platform.set_wallclock = xen_set_wallclock;
29645 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29646 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29647 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29648 }
29649 #endif
29650 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29651 index f9643fc..602e8af 100644
29652 --- a/arch/x86/xen/xen-asm_32.S
29653 +++ b/arch/x86/xen/xen-asm_32.S
29654 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
29655 ESP_OFFSET=4 # bytes pushed onto stack
29656
29657 /*
29658 - * Store vcpu_info pointer for easy access. Do it this way to
29659 - * avoid having to reload %fs
29660 + * Store vcpu_info pointer for easy access.
29661 */
29662 #ifdef CONFIG_SMP
29663 - GET_THREAD_INFO(%eax)
29664 - movl TI_cpu(%eax), %eax
29665 - movl __per_cpu_offset(,%eax,4), %eax
29666 - mov xen_vcpu(%eax), %eax
29667 + push %fs
29668 + mov $(__KERNEL_PERCPU), %eax
29669 + mov %eax, %fs
29670 + mov PER_CPU_VAR(xen_vcpu), %eax
29671 + pop %fs
29672 #else
29673 movl xen_vcpu, %eax
29674 #endif
29675 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29676 index 7faed58..ba4427c 100644
29677 --- a/arch/x86/xen/xen-head.S
29678 +++ b/arch/x86/xen/xen-head.S
29679 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
29680 #ifdef CONFIG_X86_32
29681 mov %esi,xen_start_info
29682 mov $init_thread_union+THREAD_SIZE,%esp
29683 +#ifdef CONFIG_SMP
29684 + movl $cpu_gdt_table,%edi
29685 + movl $__per_cpu_load,%eax
29686 + movw %ax,__KERNEL_PERCPU + 2(%edi)
29687 + rorl $16,%eax
29688 + movb %al,__KERNEL_PERCPU + 4(%edi)
29689 + movb %ah,__KERNEL_PERCPU + 7(%edi)
29690 + movl $__per_cpu_end - 1,%eax
29691 + subl $__per_cpu_start,%eax
29692 + movw %ax,__KERNEL_PERCPU + 0(%edi)
29693 +#endif
29694 #else
29695 mov %rsi,xen_start_info
29696 mov $init_thread_union+THREAD_SIZE,%rsp
29697 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29698 index a95b417..b6dbd0b 100644
29699 --- a/arch/x86/xen/xen-ops.h
29700 +++ b/arch/x86/xen/xen-ops.h
29701 @@ -10,8 +10,6 @@
29702 extern const char xen_hypervisor_callback[];
29703 extern const char xen_failsafe_callback[];
29704
29705 -extern void *xen_initial_gdt;
29706 -
29707 struct trap_info;
29708 void xen_copy_trap_info(struct trap_info *traps);
29709
29710 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29711 index 525bd3d..ef888b1 100644
29712 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
29713 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29714 @@ -119,9 +119,9 @@
29715 ----------------------------------------------------------------------*/
29716
29717 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29718 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29719 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29720 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
29721 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29722
29723 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
29724 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29725 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29726 index 2f33760..835e50a 100644
29727 --- a/arch/xtensa/variants/fsf/include/variant/core.h
29728 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
29729 @@ -11,6 +11,7 @@
29730 #ifndef _XTENSA_CORE_H
29731 #define _XTENSA_CORE_H
29732
29733 +#include <linux/const.h>
29734
29735 /****************************************************************************
29736 Parameters Useful for Any Code, USER or PRIVILEGED
29737 @@ -112,9 +113,9 @@
29738 ----------------------------------------------------------------------*/
29739
29740 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29741 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29742 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29743 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29744 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29745
29746 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29747 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29748 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29749 index af00795..2bb8105 100644
29750 --- a/arch/xtensa/variants/s6000/include/variant/core.h
29751 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
29752 @@ -11,6 +11,7 @@
29753 #ifndef _XTENSA_CORE_CONFIGURATION_H
29754 #define _XTENSA_CORE_CONFIGURATION_H
29755
29756 +#include <linux/const.h>
29757
29758 /****************************************************************************
29759 Parameters Useful for Any Code, USER or PRIVILEGED
29760 @@ -118,9 +119,9 @@
29761 ----------------------------------------------------------------------*/
29762
29763 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29764 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29765 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29766 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29767 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29768
29769 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29770 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29771 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29772 index 58916af..9cb880b 100644
29773 --- a/block/blk-iopoll.c
29774 +++ b/block/blk-iopoll.c
29775 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29776 }
29777 EXPORT_SYMBOL(blk_iopoll_complete);
29778
29779 -static void blk_iopoll_softirq(struct softirq_action *h)
29780 +static void blk_iopoll_softirq(void)
29781 {
29782 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29783 int rearm = 0, budget = blk_iopoll_budget;
29784 diff --git a/block/blk-map.c b/block/blk-map.c
29785 index 623e1cd..ca1e109 100644
29786 --- a/block/blk-map.c
29787 +++ b/block/blk-map.c
29788 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29789 if (!len || !kbuf)
29790 return -EINVAL;
29791
29792 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29793 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29794 if (do_copy)
29795 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29796 else
29797 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29798 index 467c8de..4bddc6d 100644
29799 --- a/block/blk-softirq.c
29800 +++ b/block/blk-softirq.c
29801 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29802 * Softirq action handler - move entries to local list and loop over them
29803 * while passing them to the queue registered handler.
29804 */
29805 -static void blk_done_softirq(struct softirq_action *h)
29806 +static void blk_done_softirq(void)
29807 {
29808 struct list_head *cpu_list, local_list;
29809
29810 diff --git a/block/bsg.c b/block/bsg.c
29811 index ff64ae3..593560c 100644
29812 --- a/block/bsg.c
29813 +++ b/block/bsg.c
29814 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29815 struct sg_io_v4 *hdr, struct bsg_device *bd,
29816 fmode_t has_write_perm)
29817 {
29818 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29819 + unsigned char *cmdptr;
29820 +
29821 if (hdr->request_len > BLK_MAX_CDB) {
29822 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29823 if (!rq->cmd)
29824 return -ENOMEM;
29825 - }
29826 + cmdptr = rq->cmd;
29827 + } else
29828 + cmdptr = tmpcmd;
29829
29830 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29831 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29832 hdr->request_len))
29833 return -EFAULT;
29834
29835 + if (cmdptr != rq->cmd)
29836 + memcpy(rq->cmd, cmdptr, hdr->request_len);
29837 +
29838 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29839 if (blk_verify_command(rq->cmd, has_write_perm))
29840 return -EPERM;
29841 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29842 index 7c668c8..db3521c 100644
29843 --- a/block/compat_ioctl.c
29844 +++ b/block/compat_ioctl.c
29845 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29846 err |= __get_user(f->spec1, &uf->spec1);
29847 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29848 err |= __get_user(name, &uf->name);
29849 - f->name = compat_ptr(name);
29850 + f->name = (void __force_kernel *)compat_ptr(name);
29851 if (err) {
29852 err = -EFAULT;
29853 goto out;
29854 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29855 index 6296b40..417c00f 100644
29856 --- a/block/partitions/efi.c
29857 +++ b/block/partitions/efi.c
29858 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29859 if (!gpt)
29860 return NULL;
29861
29862 + if (!le32_to_cpu(gpt->num_partition_entries))
29863 + return NULL;
29864 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29865 + if (!pte)
29866 + return NULL;
29867 +
29868 count = le32_to_cpu(gpt->num_partition_entries) *
29869 le32_to_cpu(gpt->sizeof_partition_entry);
29870 - if (!count)
29871 - return NULL;
29872 - pte = kzalloc(count, GFP_KERNEL);
29873 - if (!pte)
29874 - return NULL;
29875 -
29876 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29877 (u8 *) pte,
29878 count) < count) {
29879 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29880 index 9a87daa..fb17486 100644
29881 --- a/block/scsi_ioctl.c
29882 +++ b/block/scsi_ioctl.c
29883 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29884 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29885 struct sg_io_hdr *hdr, fmode_t mode)
29886 {
29887 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29888 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29889 + unsigned char *cmdptr;
29890 +
29891 + if (rq->cmd != rq->__cmd)
29892 + cmdptr = rq->cmd;
29893 + else
29894 + cmdptr = tmpcmd;
29895 +
29896 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29897 return -EFAULT;
29898 +
29899 + if (cmdptr != rq->cmd)
29900 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29901 +
29902 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29903 return -EPERM;
29904
29905 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29906 int err;
29907 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29908 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29909 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29910 + unsigned char *cmdptr;
29911
29912 if (!sic)
29913 return -EINVAL;
29914 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29915 */
29916 err = -EFAULT;
29917 rq->cmd_len = cmdlen;
29918 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
29919 +
29920 + if (rq->cmd != rq->__cmd)
29921 + cmdptr = rq->cmd;
29922 + else
29923 + cmdptr = tmpcmd;
29924 +
29925 + if (copy_from_user(cmdptr, sic->data, cmdlen))
29926 goto error;
29927
29928 + if (rq->cmd != cmdptr)
29929 + memcpy(rq->cmd, cmdptr, cmdlen);
29930 +
29931 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29932 goto error;
29933
29934 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29935 index 7bdd61b..afec999 100644
29936 --- a/crypto/cryptd.c
29937 +++ b/crypto/cryptd.c
29938 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29939
29940 struct cryptd_blkcipher_request_ctx {
29941 crypto_completion_t complete;
29942 -};
29943 +} __no_const;
29944
29945 struct cryptd_hash_ctx {
29946 struct crypto_shash *child;
29947 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29948
29949 struct cryptd_aead_request_ctx {
29950 crypto_completion_t complete;
29951 -};
29952 +} __no_const;
29953
29954 static void cryptd_queue_worker(struct work_struct *work);
29955
29956 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29957 index e6defd8..c26a225 100644
29958 --- a/drivers/acpi/apei/cper.c
29959 +++ b/drivers/acpi/apei/cper.c
29960 @@ -38,12 +38,12 @@
29961 */
29962 u64 cper_next_record_id(void)
29963 {
29964 - static atomic64_t seq;
29965 + static atomic64_unchecked_t seq;
29966
29967 - if (!atomic64_read(&seq))
29968 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
29969 + if (!atomic64_read_unchecked(&seq))
29970 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29971
29972 - return atomic64_inc_return(&seq);
29973 + return atomic64_inc_return_unchecked(&seq);
29974 }
29975 EXPORT_SYMBOL_GPL(cper_next_record_id);
29976
29977 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29978 index 7586544..636a2f0 100644
29979 --- a/drivers/acpi/ec_sys.c
29980 +++ b/drivers/acpi/ec_sys.c
29981 @@ -12,6 +12,7 @@
29982 #include <linux/acpi.h>
29983 #include <linux/debugfs.h>
29984 #include <linux/module.h>
29985 +#include <linux/uaccess.h>
29986 #include "internal.h"
29987
29988 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29989 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29990 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29991 */
29992 unsigned int size = EC_SPACE_SIZE;
29993 - u8 *data = (u8 *) buf;
29994 + u8 data;
29995 loff_t init_off = *off;
29996 int err = 0;
29997
29998 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29999 size = count;
30000
30001 while (size) {
30002 - err = ec_read(*off, &data[*off - init_off]);
30003 + err = ec_read(*off, &data);
30004 if (err)
30005 return err;
30006 + if (put_user(data, &buf[*off - init_off]))
30007 + return -EFAULT;
30008 *off += 1;
30009 size--;
30010 }
30011 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30012
30013 unsigned int size = count;
30014 loff_t init_off = *off;
30015 - u8 *data = (u8 *) buf;
30016 int err = 0;
30017
30018 if (*off >= EC_SPACE_SIZE)
30019 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30020 }
30021
30022 while (size) {
30023 - u8 byte_write = data[*off - init_off];
30024 + u8 byte_write;
30025 + if (get_user(byte_write, &buf[*off - init_off]))
30026 + return -EFAULT;
30027 err = ec_write(*off, byte_write);
30028 if (err)
30029 return err;
30030 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
30031 index 27adb09..ef98796b 100644
30032 --- a/drivers/acpi/proc.c
30033 +++ b/drivers/acpi/proc.c
30034 @@ -362,16 +362,13 @@ acpi_system_write_wakeup_device(struct file *file,
30035 struct list_head *node, *next;
30036 char strbuf[5];
30037 char str[5] = "";
30038 - unsigned int len = count;
30039
30040 - if (len > 4)
30041 - len = 4;
30042 - if (len < 0)
30043 - return -EFAULT;
30044 + if (count > 4)
30045 + count = 4;
30046
30047 - if (copy_from_user(strbuf, buffer, len))
30048 + if (copy_from_user(strbuf, buffer, count))
30049 return -EFAULT;
30050 - strbuf[len] = '\0';
30051 + strbuf[count] = '\0';
30052 sscanf(strbuf, "%s", str);
30053
30054 mutex_lock(&acpi_device_lock);
30055 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30056 index bd4e5dc..0497b66 100644
30057 --- a/drivers/acpi/processor_driver.c
30058 +++ b/drivers/acpi/processor_driver.c
30059 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30060 return 0;
30061 #endif
30062
30063 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30064 + BUG_ON(pr->id >= nr_cpu_ids);
30065
30066 /*
30067 * Buggy BIOS check
30068 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30069 index c8ac4fe..631818e 100644
30070 --- a/drivers/ata/libata-core.c
30071 +++ b/drivers/ata/libata-core.c
30072 @@ -4779,7 +4779,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30073 struct ata_port *ap;
30074 unsigned int tag;
30075
30076 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30077 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30078 ap = qc->ap;
30079
30080 qc->flags = 0;
30081 @@ -4795,7 +4795,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30082 struct ata_port *ap;
30083 struct ata_link *link;
30084
30085 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30086 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30087 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
30088 ap = qc->ap;
30089 link = qc->dev->link;
30090 @@ -5891,6 +5891,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30091 return;
30092
30093 spin_lock(&lock);
30094 + pax_open_kernel();
30095
30096 for (cur = ops->inherits; cur; cur = cur->inherits) {
30097 void **inherit = (void **)cur;
30098 @@ -5904,8 +5905,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30099 if (IS_ERR(*pp))
30100 *pp = NULL;
30101
30102 - ops->inherits = NULL;
30103 + *(struct ata_port_operations **)&ops->inherits = NULL;
30104
30105 + pax_close_kernel();
30106 spin_unlock(&lock);
30107 }
30108
30109 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
30110 index 371fd2c..0836c78 100644
30111 --- a/drivers/ata/pata_arasan_cf.c
30112 +++ b/drivers/ata/pata_arasan_cf.c
30113 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
30114 /* Handle platform specific quirks */
30115 if (pdata->quirk) {
30116 if (pdata->quirk & CF_BROKEN_PIO) {
30117 - ap->ops->set_piomode = NULL;
30118 + pax_open_kernel();
30119 + *(void **)&ap->ops->set_piomode = NULL;
30120 + pax_close_kernel();
30121 ap->pio_mask = 0;
30122 }
30123 if (pdata->quirk & CF_BROKEN_MWDMA)
30124 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
30125 index f9b983a..887b9d8 100644
30126 --- a/drivers/atm/adummy.c
30127 +++ b/drivers/atm/adummy.c
30128 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
30129 vcc->pop(vcc, skb);
30130 else
30131 dev_kfree_skb_any(skb);
30132 - atomic_inc(&vcc->stats->tx);
30133 + atomic_inc_unchecked(&vcc->stats->tx);
30134
30135 return 0;
30136 }
30137 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
30138 index ff7bb8a..568fc0b 100644
30139 --- a/drivers/atm/ambassador.c
30140 +++ b/drivers/atm/ambassador.c
30141 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
30142 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
30143
30144 // VC layer stats
30145 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30146 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30147
30148 // free the descriptor
30149 kfree (tx_descr);
30150 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30151 dump_skb ("<<<", vc, skb);
30152
30153 // VC layer stats
30154 - atomic_inc(&atm_vcc->stats->rx);
30155 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30156 __net_timestamp(skb);
30157 // end of our responsibility
30158 atm_vcc->push (atm_vcc, skb);
30159 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30160 } else {
30161 PRINTK (KERN_INFO, "dropped over-size frame");
30162 // should we count this?
30163 - atomic_inc(&atm_vcc->stats->rx_drop);
30164 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30165 }
30166
30167 } else {
30168 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
30169 }
30170
30171 if (check_area (skb->data, skb->len)) {
30172 - atomic_inc(&atm_vcc->stats->tx_err);
30173 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
30174 return -ENOMEM; // ?
30175 }
30176
30177 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
30178 index b22d71c..d6e1049 100644
30179 --- a/drivers/atm/atmtcp.c
30180 +++ b/drivers/atm/atmtcp.c
30181 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30182 if (vcc->pop) vcc->pop(vcc,skb);
30183 else dev_kfree_skb(skb);
30184 if (dev_data) return 0;
30185 - atomic_inc(&vcc->stats->tx_err);
30186 + atomic_inc_unchecked(&vcc->stats->tx_err);
30187 return -ENOLINK;
30188 }
30189 size = skb->len+sizeof(struct atmtcp_hdr);
30190 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30191 if (!new_skb) {
30192 if (vcc->pop) vcc->pop(vcc,skb);
30193 else dev_kfree_skb(skb);
30194 - atomic_inc(&vcc->stats->tx_err);
30195 + atomic_inc_unchecked(&vcc->stats->tx_err);
30196 return -ENOBUFS;
30197 }
30198 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
30199 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30200 if (vcc->pop) vcc->pop(vcc,skb);
30201 else dev_kfree_skb(skb);
30202 out_vcc->push(out_vcc,new_skb);
30203 - atomic_inc(&vcc->stats->tx);
30204 - atomic_inc(&out_vcc->stats->rx);
30205 + atomic_inc_unchecked(&vcc->stats->tx);
30206 + atomic_inc_unchecked(&out_vcc->stats->rx);
30207 return 0;
30208 }
30209
30210 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30211 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
30212 read_unlock(&vcc_sklist_lock);
30213 if (!out_vcc) {
30214 - atomic_inc(&vcc->stats->tx_err);
30215 + atomic_inc_unchecked(&vcc->stats->tx_err);
30216 goto done;
30217 }
30218 skb_pull(skb,sizeof(struct atmtcp_hdr));
30219 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30220 __net_timestamp(new_skb);
30221 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
30222 out_vcc->push(out_vcc,new_skb);
30223 - atomic_inc(&vcc->stats->tx);
30224 - atomic_inc(&out_vcc->stats->rx);
30225 + atomic_inc_unchecked(&vcc->stats->tx);
30226 + atomic_inc_unchecked(&out_vcc->stats->rx);
30227 done:
30228 if (vcc->pop) vcc->pop(vcc,skb);
30229 else dev_kfree_skb(skb);
30230 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
30231 index 81e44f7..498ea36 100644
30232 --- a/drivers/atm/eni.c
30233 +++ b/drivers/atm/eni.c
30234 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
30235 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
30236 vcc->dev->number);
30237 length = 0;
30238 - atomic_inc(&vcc->stats->rx_err);
30239 + atomic_inc_unchecked(&vcc->stats->rx_err);
30240 }
30241 else {
30242 length = ATM_CELL_SIZE-1; /* no HEC */
30243 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30244 size);
30245 }
30246 eff = length = 0;
30247 - atomic_inc(&vcc->stats->rx_err);
30248 + atomic_inc_unchecked(&vcc->stats->rx_err);
30249 }
30250 else {
30251 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
30252 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30253 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
30254 vcc->dev->number,vcc->vci,length,size << 2,descr);
30255 length = eff = 0;
30256 - atomic_inc(&vcc->stats->rx_err);
30257 + atomic_inc_unchecked(&vcc->stats->rx_err);
30258 }
30259 }
30260 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
30261 @@ -767,7 +767,7 @@ rx_dequeued++;
30262 vcc->push(vcc,skb);
30263 pushed++;
30264 }
30265 - atomic_inc(&vcc->stats->rx);
30266 + atomic_inc_unchecked(&vcc->stats->rx);
30267 }
30268 wake_up(&eni_dev->rx_wait);
30269 }
30270 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
30271 PCI_DMA_TODEVICE);
30272 if (vcc->pop) vcc->pop(vcc,skb);
30273 else dev_kfree_skb_irq(skb);
30274 - atomic_inc(&vcc->stats->tx);
30275 + atomic_inc_unchecked(&vcc->stats->tx);
30276 wake_up(&eni_dev->tx_wait);
30277 dma_complete++;
30278 }
30279 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
30280 index 86fed1b..6dc4721 100644
30281 --- a/drivers/atm/firestream.c
30282 +++ b/drivers/atm/firestream.c
30283 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
30284 }
30285 }
30286
30287 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30288 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30289
30290 fs_dprintk (FS_DEBUG_TXMEM, "i");
30291 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
30292 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30293 #endif
30294 skb_put (skb, qe->p1 & 0xffff);
30295 ATM_SKB(skb)->vcc = atm_vcc;
30296 - atomic_inc(&atm_vcc->stats->rx);
30297 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30298 __net_timestamp(skb);
30299 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
30300 atm_vcc->push (atm_vcc, skb);
30301 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30302 kfree (pe);
30303 }
30304 if (atm_vcc)
30305 - atomic_inc(&atm_vcc->stats->rx_drop);
30306 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30307 break;
30308 case 0x1f: /* Reassembly abort: no buffers. */
30309 /* Silently increment error counter. */
30310 if (atm_vcc)
30311 - atomic_inc(&atm_vcc->stats->rx_drop);
30312 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30313 break;
30314 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
30315 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
30316 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
30317 index 361f5ae..7fc552d 100644
30318 --- a/drivers/atm/fore200e.c
30319 +++ b/drivers/atm/fore200e.c
30320 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
30321 #endif
30322 /* check error condition */
30323 if (*entry->status & STATUS_ERROR)
30324 - atomic_inc(&vcc->stats->tx_err);
30325 + atomic_inc_unchecked(&vcc->stats->tx_err);
30326 else
30327 - atomic_inc(&vcc->stats->tx);
30328 + atomic_inc_unchecked(&vcc->stats->tx);
30329 }
30330 }
30331
30332 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30333 if (skb == NULL) {
30334 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
30335
30336 - atomic_inc(&vcc->stats->rx_drop);
30337 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30338 return -ENOMEM;
30339 }
30340
30341 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30342
30343 dev_kfree_skb_any(skb);
30344
30345 - atomic_inc(&vcc->stats->rx_drop);
30346 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30347 return -ENOMEM;
30348 }
30349
30350 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30351
30352 vcc->push(vcc, skb);
30353 - atomic_inc(&vcc->stats->rx);
30354 + atomic_inc_unchecked(&vcc->stats->rx);
30355
30356 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30357
30358 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
30359 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
30360 fore200e->atm_dev->number,
30361 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
30362 - atomic_inc(&vcc->stats->rx_err);
30363 + atomic_inc_unchecked(&vcc->stats->rx_err);
30364 }
30365 }
30366
30367 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
30368 goto retry_here;
30369 }
30370
30371 - atomic_inc(&vcc->stats->tx_err);
30372 + atomic_inc_unchecked(&vcc->stats->tx_err);
30373
30374 fore200e->tx_sat++;
30375 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
30376 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
30377 index b182c2f..1c6fa8a 100644
30378 --- a/drivers/atm/he.c
30379 +++ b/drivers/atm/he.c
30380 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30381
30382 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
30383 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
30384 - atomic_inc(&vcc->stats->rx_drop);
30385 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30386 goto return_host_buffers;
30387 }
30388
30389 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30390 RBRQ_LEN_ERR(he_dev->rbrq_head)
30391 ? "LEN_ERR" : "",
30392 vcc->vpi, vcc->vci);
30393 - atomic_inc(&vcc->stats->rx_err);
30394 + atomic_inc_unchecked(&vcc->stats->rx_err);
30395 goto return_host_buffers;
30396 }
30397
30398 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30399 vcc->push(vcc, skb);
30400 spin_lock(&he_dev->global_lock);
30401
30402 - atomic_inc(&vcc->stats->rx);
30403 + atomic_inc_unchecked(&vcc->stats->rx);
30404
30405 return_host_buffers:
30406 ++pdus_assembled;
30407 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30408 tpd->vcc->pop(tpd->vcc, tpd->skb);
30409 else
30410 dev_kfree_skb_any(tpd->skb);
30411 - atomic_inc(&tpd->vcc->stats->tx_err);
30412 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30413 }
30414 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30415 return;
30416 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30417 vcc->pop(vcc, skb);
30418 else
30419 dev_kfree_skb_any(skb);
30420 - atomic_inc(&vcc->stats->tx_err);
30421 + atomic_inc_unchecked(&vcc->stats->tx_err);
30422 return -EINVAL;
30423 }
30424
30425 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30426 vcc->pop(vcc, skb);
30427 else
30428 dev_kfree_skb_any(skb);
30429 - atomic_inc(&vcc->stats->tx_err);
30430 + atomic_inc_unchecked(&vcc->stats->tx_err);
30431 return -EINVAL;
30432 }
30433 #endif
30434 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30435 vcc->pop(vcc, skb);
30436 else
30437 dev_kfree_skb_any(skb);
30438 - atomic_inc(&vcc->stats->tx_err);
30439 + atomic_inc_unchecked(&vcc->stats->tx_err);
30440 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30441 return -ENOMEM;
30442 }
30443 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30444 vcc->pop(vcc, skb);
30445 else
30446 dev_kfree_skb_any(skb);
30447 - atomic_inc(&vcc->stats->tx_err);
30448 + atomic_inc_unchecked(&vcc->stats->tx_err);
30449 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30450 return -ENOMEM;
30451 }
30452 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30453 __enqueue_tpd(he_dev, tpd, cid);
30454 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30455
30456 - atomic_inc(&vcc->stats->tx);
30457 + atomic_inc_unchecked(&vcc->stats->tx);
30458
30459 return 0;
30460 }
30461 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30462 index 7d01c2a..4e3ac01 100644
30463 --- a/drivers/atm/horizon.c
30464 +++ b/drivers/atm/horizon.c
30465 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30466 {
30467 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30468 // VC layer stats
30469 - atomic_inc(&vcc->stats->rx);
30470 + atomic_inc_unchecked(&vcc->stats->rx);
30471 __net_timestamp(skb);
30472 // end of our responsibility
30473 vcc->push (vcc, skb);
30474 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30475 dev->tx_iovec = NULL;
30476
30477 // VC layer stats
30478 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30479 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30480
30481 // free the skb
30482 hrz_kfree_skb (skb);
30483 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30484 index 8974bd2..b856f85 100644
30485 --- a/drivers/atm/idt77252.c
30486 +++ b/drivers/atm/idt77252.c
30487 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30488 else
30489 dev_kfree_skb(skb);
30490
30491 - atomic_inc(&vcc->stats->tx);
30492 + atomic_inc_unchecked(&vcc->stats->tx);
30493 }
30494
30495 atomic_dec(&scq->used);
30496 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30497 if ((sb = dev_alloc_skb(64)) == NULL) {
30498 printk("%s: Can't allocate buffers for aal0.\n",
30499 card->name);
30500 - atomic_add(i, &vcc->stats->rx_drop);
30501 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30502 break;
30503 }
30504 if (!atm_charge(vcc, sb->truesize)) {
30505 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30506 card->name);
30507 - atomic_add(i - 1, &vcc->stats->rx_drop);
30508 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30509 dev_kfree_skb(sb);
30510 break;
30511 }
30512 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30513 ATM_SKB(sb)->vcc = vcc;
30514 __net_timestamp(sb);
30515 vcc->push(vcc, sb);
30516 - atomic_inc(&vcc->stats->rx);
30517 + atomic_inc_unchecked(&vcc->stats->rx);
30518
30519 cell += ATM_CELL_PAYLOAD;
30520 }
30521 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30522 "(CDC: %08x)\n",
30523 card->name, len, rpp->len, readl(SAR_REG_CDC));
30524 recycle_rx_pool_skb(card, rpp);
30525 - atomic_inc(&vcc->stats->rx_err);
30526 + atomic_inc_unchecked(&vcc->stats->rx_err);
30527 return;
30528 }
30529 if (stat & SAR_RSQE_CRC) {
30530 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30531 recycle_rx_pool_skb(card, rpp);
30532 - atomic_inc(&vcc->stats->rx_err);
30533 + atomic_inc_unchecked(&vcc->stats->rx_err);
30534 return;
30535 }
30536 if (skb_queue_len(&rpp->queue) > 1) {
30537 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30538 RXPRINTK("%s: Can't alloc RX skb.\n",
30539 card->name);
30540 recycle_rx_pool_skb(card, rpp);
30541 - atomic_inc(&vcc->stats->rx_err);
30542 + atomic_inc_unchecked(&vcc->stats->rx_err);
30543 return;
30544 }
30545 if (!atm_charge(vcc, skb->truesize)) {
30546 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30547 __net_timestamp(skb);
30548
30549 vcc->push(vcc, skb);
30550 - atomic_inc(&vcc->stats->rx);
30551 + atomic_inc_unchecked(&vcc->stats->rx);
30552
30553 return;
30554 }
30555 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30556 __net_timestamp(skb);
30557
30558 vcc->push(vcc, skb);
30559 - atomic_inc(&vcc->stats->rx);
30560 + atomic_inc_unchecked(&vcc->stats->rx);
30561
30562 if (skb->truesize > SAR_FB_SIZE_3)
30563 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30564 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30565 if (vcc->qos.aal != ATM_AAL0) {
30566 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30567 card->name, vpi, vci);
30568 - atomic_inc(&vcc->stats->rx_drop);
30569 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30570 goto drop;
30571 }
30572
30573 if ((sb = dev_alloc_skb(64)) == NULL) {
30574 printk("%s: Can't allocate buffers for AAL0.\n",
30575 card->name);
30576 - atomic_inc(&vcc->stats->rx_err);
30577 + atomic_inc_unchecked(&vcc->stats->rx_err);
30578 goto drop;
30579 }
30580
30581 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30582 ATM_SKB(sb)->vcc = vcc;
30583 __net_timestamp(sb);
30584 vcc->push(vcc, sb);
30585 - atomic_inc(&vcc->stats->rx);
30586 + atomic_inc_unchecked(&vcc->stats->rx);
30587
30588 drop:
30589 skb_pull(queue, 64);
30590 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30591
30592 if (vc == NULL) {
30593 printk("%s: NULL connection in send().\n", card->name);
30594 - atomic_inc(&vcc->stats->tx_err);
30595 + atomic_inc_unchecked(&vcc->stats->tx_err);
30596 dev_kfree_skb(skb);
30597 return -EINVAL;
30598 }
30599 if (!test_bit(VCF_TX, &vc->flags)) {
30600 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30601 - atomic_inc(&vcc->stats->tx_err);
30602 + atomic_inc_unchecked(&vcc->stats->tx_err);
30603 dev_kfree_skb(skb);
30604 return -EINVAL;
30605 }
30606 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30607 break;
30608 default:
30609 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30610 - atomic_inc(&vcc->stats->tx_err);
30611 + atomic_inc_unchecked(&vcc->stats->tx_err);
30612 dev_kfree_skb(skb);
30613 return -EINVAL;
30614 }
30615
30616 if (skb_shinfo(skb)->nr_frags != 0) {
30617 printk("%s: No scatter-gather yet.\n", card->name);
30618 - atomic_inc(&vcc->stats->tx_err);
30619 + atomic_inc_unchecked(&vcc->stats->tx_err);
30620 dev_kfree_skb(skb);
30621 return -EINVAL;
30622 }
30623 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30624
30625 err = queue_skb(card, vc, skb, oam);
30626 if (err) {
30627 - atomic_inc(&vcc->stats->tx_err);
30628 + atomic_inc_unchecked(&vcc->stats->tx_err);
30629 dev_kfree_skb(skb);
30630 return err;
30631 }
30632 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30633 skb = dev_alloc_skb(64);
30634 if (!skb) {
30635 printk("%s: Out of memory in send_oam().\n", card->name);
30636 - atomic_inc(&vcc->stats->tx_err);
30637 + atomic_inc_unchecked(&vcc->stats->tx_err);
30638 return -ENOMEM;
30639 }
30640 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30641 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30642 index 96cce6d..62c3ec5 100644
30643 --- a/drivers/atm/iphase.c
30644 +++ b/drivers/atm/iphase.c
30645 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30646 status = (u_short) (buf_desc_ptr->desc_mode);
30647 if (status & (RX_CER | RX_PTE | RX_OFL))
30648 {
30649 - atomic_inc(&vcc->stats->rx_err);
30650 + atomic_inc_unchecked(&vcc->stats->rx_err);
30651 IF_ERR(printk("IA: bad packet, dropping it");)
30652 if (status & RX_CER) {
30653 IF_ERR(printk(" cause: packet CRC error\n");)
30654 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30655 len = dma_addr - buf_addr;
30656 if (len > iadev->rx_buf_sz) {
30657 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30658 - atomic_inc(&vcc->stats->rx_err);
30659 + atomic_inc_unchecked(&vcc->stats->rx_err);
30660 goto out_free_desc;
30661 }
30662
30663 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30664 ia_vcc = INPH_IA_VCC(vcc);
30665 if (ia_vcc == NULL)
30666 {
30667 - atomic_inc(&vcc->stats->rx_err);
30668 + atomic_inc_unchecked(&vcc->stats->rx_err);
30669 atm_return(vcc, skb->truesize);
30670 dev_kfree_skb_any(skb);
30671 goto INCR_DLE;
30672 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30673 if ((length > iadev->rx_buf_sz) || (length >
30674 (skb->len - sizeof(struct cpcs_trailer))))
30675 {
30676 - atomic_inc(&vcc->stats->rx_err);
30677 + atomic_inc_unchecked(&vcc->stats->rx_err);
30678 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30679 length, skb->len);)
30680 atm_return(vcc, skb->truesize);
30681 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30682
30683 IF_RX(printk("rx_dle_intr: skb push");)
30684 vcc->push(vcc,skb);
30685 - atomic_inc(&vcc->stats->rx);
30686 + atomic_inc_unchecked(&vcc->stats->rx);
30687 iadev->rx_pkt_cnt++;
30688 }
30689 INCR_DLE:
30690 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30691 {
30692 struct k_sonet_stats *stats;
30693 stats = &PRIV(_ia_dev[board])->sonet_stats;
30694 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30695 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30696 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30697 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30698 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30699 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30700 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30701 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30702 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30703 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30704 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30705 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30706 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30707 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30708 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30709 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30710 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30711 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30712 }
30713 ia_cmds.status = 0;
30714 break;
30715 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30716 if ((desc == 0) || (desc > iadev->num_tx_desc))
30717 {
30718 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30719 - atomic_inc(&vcc->stats->tx);
30720 + atomic_inc_unchecked(&vcc->stats->tx);
30721 if (vcc->pop)
30722 vcc->pop(vcc, skb);
30723 else
30724 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30725 ATM_DESC(skb) = vcc->vci;
30726 skb_queue_tail(&iadev->tx_dma_q, skb);
30727
30728 - atomic_inc(&vcc->stats->tx);
30729 + atomic_inc_unchecked(&vcc->stats->tx);
30730 iadev->tx_pkt_cnt++;
30731 /* Increment transaction counter */
30732 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30733
30734 #if 0
30735 /* add flow control logic */
30736 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30737 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30738 if (iavcc->vc_desc_cnt > 10) {
30739 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30740 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30741 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30742 index 68c7588..7036683 100644
30743 --- a/drivers/atm/lanai.c
30744 +++ b/drivers/atm/lanai.c
30745 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30746 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30747 lanai_endtx(lanai, lvcc);
30748 lanai_free_skb(lvcc->tx.atmvcc, skb);
30749 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30750 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30751 }
30752
30753 /* Try to fill the buffer - don't call unless there is backlog */
30754 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30755 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30756 __net_timestamp(skb);
30757 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30758 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30759 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30760 out:
30761 lvcc->rx.buf.ptr = end;
30762 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30763 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30764 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30765 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30766 lanai->stats.service_rxnotaal5++;
30767 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30768 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30769 return 0;
30770 }
30771 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30772 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30773 int bytes;
30774 read_unlock(&vcc_sklist_lock);
30775 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30776 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30777 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30778 lvcc->stats.x.aal5.service_trash++;
30779 bytes = (SERVICE_GET_END(s) * 16) -
30780 (((unsigned long) lvcc->rx.buf.ptr) -
30781 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30782 }
30783 if (s & SERVICE_STREAM) {
30784 read_unlock(&vcc_sklist_lock);
30785 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30786 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30787 lvcc->stats.x.aal5.service_stream++;
30788 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30789 "PDU on VCI %d!\n", lanai->number, vci);
30790 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30791 return 0;
30792 }
30793 DPRINTK("got rx crc error on vci %d\n", vci);
30794 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30795 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30796 lvcc->stats.x.aal5.service_rxcrc++;
30797 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30798 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30799 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30800 index 1c70c45..300718d 100644
30801 --- a/drivers/atm/nicstar.c
30802 +++ b/drivers/atm/nicstar.c
30803 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30804 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30805 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30806 card->index);
30807 - atomic_inc(&vcc->stats->tx_err);
30808 + atomic_inc_unchecked(&vcc->stats->tx_err);
30809 dev_kfree_skb_any(skb);
30810 return -EINVAL;
30811 }
30812 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30813 if (!vc->tx) {
30814 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30815 card->index);
30816 - atomic_inc(&vcc->stats->tx_err);
30817 + atomic_inc_unchecked(&vcc->stats->tx_err);
30818 dev_kfree_skb_any(skb);
30819 return -EINVAL;
30820 }
30821 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30822 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30823 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30824 card->index);
30825 - atomic_inc(&vcc->stats->tx_err);
30826 + atomic_inc_unchecked(&vcc->stats->tx_err);
30827 dev_kfree_skb_any(skb);
30828 return -EINVAL;
30829 }
30830
30831 if (skb_shinfo(skb)->nr_frags != 0) {
30832 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30833 - atomic_inc(&vcc->stats->tx_err);
30834 + atomic_inc_unchecked(&vcc->stats->tx_err);
30835 dev_kfree_skb_any(skb);
30836 return -EINVAL;
30837 }
30838 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30839 }
30840
30841 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30842 - atomic_inc(&vcc->stats->tx_err);
30843 + atomic_inc_unchecked(&vcc->stats->tx_err);
30844 dev_kfree_skb_any(skb);
30845 return -EIO;
30846 }
30847 - atomic_inc(&vcc->stats->tx);
30848 + atomic_inc_unchecked(&vcc->stats->tx);
30849
30850 return 0;
30851 }
30852 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30853 printk
30854 ("nicstar%d: Can't allocate buffers for aal0.\n",
30855 card->index);
30856 - atomic_add(i, &vcc->stats->rx_drop);
30857 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30858 break;
30859 }
30860 if (!atm_charge(vcc, sb->truesize)) {
30861 RXPRINTK
30862 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30863 card->index);
30864 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30865 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30866 dev_kfree_skb_any(sb);
30867 break;
30868 }
30869 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30870 ATM_SKB(sb)->vcc = vcc;
30871 __net_timestamp(sb);
30872 vcc->push(vcc, sb);
30873 - atomic_inc(&vcc->stats->rx);
30874 + atomic_inc_unchecked(&vcc->stats->rx);
30875 cell += ATM_CELL_PAYLOAD;
30876 }
30877
30878 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30879 if (iovb == NULL) {
30880 printk("nicstar%d: Out of iovec buffers.\n",
30881 card->index);
30882 - atomic_inc(&vcc->stats->rx_drop);
30883 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30884 recycle_rx_buf(card, skb);
30885 return;
30886 }
30887 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30888 small or large buffer itself. */
30889 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30890 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30891 - atomic_inc(&vcc->stats->rx_err);
30892 + atomic_inc_unchecked(&vcc->stats->rx_err);
30893 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30894 NS_MAX_IOVECS);
30895 NS_PRV_IOVCNT(iovb) = 0;
30896 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30897 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30898 card->index);
30899 which_list(card, skb);
30900 - atomic_inc(&vcc->stats->rx_err);
30901 + atomic_inc_unchecked(&vcc->stats->rx_err);
30902 recycle_rx_buf(card, skb);
30903 vc->rx_iov = NULL;
30904 recycle_iov_buf(card, iovb);
30905 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30906 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30907 card->index);
30908 which_list(card, skb);
30909 - atomic_inc(&vcc->stats->rx_err);
30910 + atomic_inc_unchecked(&vcc->stats->rx_err);
30911 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30912 NS_PRV_IOVCNT(iovb));
30913 vc->rx_iov = NULL;
30914 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30915 printk(" - PDU size mismatch.\n");
30916 else
30917 printk(".\n");
30918 - atomic_inc(&vcc->stats->rx_err);
30919 + atomic_inc_unchecked(&vcc->stats->rx_err);
30920 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30921 NS_PRV_IOVCNT(iovb));
30922 vc->rx_iov = NULL;
30923 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30924 /* skb points to a small buffer */
30925 if (!atm_charge(vcc, skb->truesize)) {
30926 push_rxbufs(card, skb);
30927 - atomic_inc(&vcc->stats->rx_drop);
30928 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30929 } else {
30930 skb_put(skb, len);
30931 dequeue_sm_buf(card, skb);
30932 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30933 ATM_SKB(skb)->vcc = vcc;
30934 __net_timestamp(skb);
30935 vcc->push(vcc, skb);
30936 - atomic_inc(&vcc->stats->rx);
30937 + atomic_inc_unchecked(&vcc->stats->rx);
30938 }
30939 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30940 struct sk_buff *sb;
30941 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30942 if (len <= NS_SMBUFSIZE) {
30943 if (!atm_charge(vcc, sb->truesize)) {
30944 push_rxbufs(card, sb);
30945 - atomic_inc(&vcc->stats->rx_drop);
30946 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30947 } else {
30948 skb_put(sb, len);
30949 dequeue_sm_buf(card, sb);
30950 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30951 ATM_SKB(sb)->vcc = vcc;
30952 __net_timestamp(sb);
30953 vcc->push(vcc, sb);
30954 - atomic_inc(&vcc->stats->rx);
30955 + atomic_inc_unchecked(&vcc->stats->rx);
30956 }
30957
30958 push_rxbufs(card, skb);
30959 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30960
30961 if (!atm_charge(vcc, skb->truesize)) {
30962 push_rxbufs(card, skb);
30963 - atomic_inc(&vcc->stats->rx_drop);
30964 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30965 } else {
30966 dequeue_lg_buf(card, skb);
30967 #ifdef NS_USE_DESTRUCTORS
30968 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30969 ATM_SKB(skb)->vcc = vcc;
30970 __net_timestamp(skb);
30971 vcc->push(vcc, skb);
30972 - atomic_inc(&vcc->stats->rx);
30973 + atomic_inc_unchecked(&vcc->stats->rx);
30974 }
30975
30976 push_rxbufs(card, sb);
30977 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30978 printk
30979 ("nicstar%d: Out of huge buffers.\n",
30980 card->index);
30981 - atomic_inc(&vcc->stats->rx_drop);
30982 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30983 recycle_iovec_rx_bufs(card,
30984 (struct iovec *)
30985 iovb->data,
30986 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30987 card->hbpool.count++;
30988 } else
30989 dev_kfree_skb_any(hb);
30990 - atomic_inc(&vcc->stats->rx_drop);
30991 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30992 } else {
30993 /* Copy the small buffer to the huge buffer */
30994 sb = (struct sk_buff *)iov->iov_base;
30995 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30996 #endif /* NS_USE_DESTRUCTORS */
30997 __net_timestamp(hb);
30998 vcc->push(vcc, hb);
30999 - atomic_inc(&vcc->stats->rx);
31000 + atomic_inc_unchecked(&vcc->stats->rx);
31001 }
31002 }
31003
31004 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
31005 index 1853a45..cf2426d 100644
31006 --- a/drivers/atm/solos-pci.c
31007 +++ b/drivers/atm/solos-pci.c
31008 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
31009 }
31010 atm_charge(vcc, skb->truesize);
31011 vcc->push(vcc, skb);
31012 - atomic_inc(&vcc->stats->rx);
31013 + atomic_inc_unchecked(&vcc->stats->rx);
31014 break;
31015
31016 case PKT_STATUS:
31017 @@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
31018 vcc = SKB_CB(oldskb)->vcc;
31019
31020 if (vcc) {
31021 - atomic_inc(&vcc->stats->tx);
31022 + atomic_inc_unchecked(&vcc->stats->tx);
31023 solos_pop(vcc, oldskb);
31024 } else
31025 dev_kfree_skb_irq(oldskb);
31026 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
31027 index 0215934..ce9f5b1 100644
31028 --- a/drivers/atm/suni.c
31029 +++ b/drivers/atm/suni.c
31030 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
31031
31032
31033 #define ADD_LIMITED(s,v) \
31034 - atomic_add((v),&stats->s); \
31035 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
31036 + atomic_add_unchecked((v),&stats->s); \
31037 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
31038
31039
31040 static void suni_hz(unsigned long from_timer)
31041 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
31042 index 5120a96..e2572bd 100644
31043 --- a/drivers/atm/uPD98402.c
31044 +++ b/drivers/atm/uPD98402.c
31045 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
31046 struct sonet_stats tmp;
31047 int error = 0;
31048
31049 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31050 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31051 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
31052 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31053 if (zero && !error) {
31054 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31055
31056
31057 #define ADD_LIMITED(s,v) \
31058 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31059 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31060 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31061 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31062 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31063 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31064
31065
31066 static void stat_event(struct atm_dev *dev)
31067 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31068 if (reason & uPD98402_INT_PFM) stat_event(dev);
31069 if (reason & uPD98402_INT_PCO) {
31070 (void) GET(PCOCR); /* clear interrupt cause */
31071 - atomic_add(GET(HECCT),
31072 + atomic_add_unchecked(GET(HECCT),
31073 &PRIV(dev)->sonet_stats.uncorr_hcs);
31074 }
31075 if ((reason & uPD98402_INT_RFO) &&
31076 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31077 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31078 uPD98402_INT_LOS),PIMR); /* enable them */
31079 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31080 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31081 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31082 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31083 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31084 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31085 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
31086 return 0;
31087 }
31088
31089 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
31090 index abe4e20..83c4727 100644
31091 --- a/drivers/atm/zatm.c
31092 +++ b/drivers/atm/zatm.c
31093 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31094 }
31095 if (!size) {
31096 dev_kfree_skb_irq(skb);
31097 - if (vcc) atomic_inc(&vcc->stats->rx_err);
31098 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
31099 continue;
31100 }
31101 if (!atm_charge(vcc,skb->truesize)) {
31102 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31103 skb->len = size;
31104 ATM_SKB(skb)->vcc = vcc;
31105 vcc->push(vcc,skb);
31106 - atomic_inc(&vcc->stats->rx);
31107 + atomic_inc_unchecked(&vcc->stats->rx);
31108 }
31109 zout(pos & 0xffff,MTA(mbx));
31110 #if 0 /* probably a stupid idea */
31111 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
31112 skb_queue_head(&zatm_vcc->backlog,skb);
31113 break;
31114 }
31115 - atomic_inc(&vcc->stats->tx);
31116 + atomic_inc_unchecked(&vcc->stats->tx);
31117 wake_up(&zatm_vcc->tx_wait);
31118 }
31119
31120 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
31121 index 147d1a4..d0fd4b0 100644
31122 --- a/drivers/base/devtmpfs.c
31123 +++ b/drivers/base/devtmpfs.c
31124 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
31125 if (!thread)
31126 return 0;
31127
31128 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
31129 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
31130 if (err)
31131 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
31132 else
31133 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
31134 index e6ee5e8..98ad7fc 100644
31135 --- a/drivers/base/power/wakeup.c
31136 +++ b/drivers/base/power/wakeup.c
31137 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
31138 * They need to be modified together atomically, so it's better to use one
31139 * atomic variable to hold them both.
31140 */
31141 -static atomic_t combined_event_count = ATOMIC_INIT(0);
31142 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
31143
31144 #define IN_PROGRESS_BITS (sizeof(int) * 4)
31145 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
31146
31147 static void split_counters(unsigned int *cnt, unsigned int *inpr)
31148 {
31149 - unsigned int comb = atomic_read(&combined_event_count);
31150 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
31151
31152 *cnt = (comb >> IN_PROGRESS_BITS);
31153 *inpr = comb & MAX_IN_PROGRESS;
31154 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
31155 ws->start_prevent_time = ws->last_time;
31156
31157 /* Increment the counter of events in progress. */
31158 - cec = atomic_inc_return(&combined_event_count);
31159 + cec = atomic_inc_return_unchecked(&combined_event_count);
31160
31161 trace_wakeup_source_activate(ws->name, cec);
31162 }
31163 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
31164 * Increment the counter of registered wakeup events and decrement the
31165 * couter of wakeup events in progress simultaneously.
31166 */
31167 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
31168 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
31169 trace_wakeup_source_deactivate(ws->name, cec);
31170
31171 split_counters(&cnt, &inpr);
31172 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
31173 index ca83f96..69d4ea9 100644
31174 --- a/drivers/block/cciss.c
31175 +++ b/drivers/block/cciss.c
31176 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
31177 int err;
31178 u32 cp;
31179
31180 + memset(&arg64, 0, sizeof(arg64));
31181 +
31182 err = 0;
31183 err |=
31184 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
31185 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
31186 while (!list_empty(&h->reqQ)) {
31187 c = list_entry(h->reqQ.next, CommandList_struct, list);
31188 /* can't do anything if fifo is full */
31189 - if ((h->access.fifo_full(h))) {
31190 + if ((h->access->fifo_full(h))) {
31191 dev_warn(&h->pdev->dev, "fifo full\n");
31192 break;
31193 }
31194 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
31195 h->Qdepth--;
31196
31197 /* Tell the controller execute command */
31198 - h->access.submit_command(h, c);
31199 + h->access->submit_command(h, c);
31200
31201 /* Put job onto the completed Q */
31202 addQ(&h->cmpQ, c);
31203 @@ -3443,17 +3445,17 @@ startio:
31204
31205 static inline unsigned long get_next_completion(ctlr_info_t *h)
31206 {
31207 - return h->access.command_completed(h);
31208 + return h->access->command_completed(h);
31209 }
31210
31211 static inline int interrupt_pending(ctlr_info_t *h)
31212 {
31213 - return h->access.intr_pending(h);
31214 + return h->access->intr_pending(h);
31215 }
31216
31217 static inline long interrupt_not_for_us(ctlr_info_t *h)
31218 {
31219 - return ((h->access.intr_pending(h) == 0) ||
31220 + return ((h->access->intr_pending(h) == 0) ||
31221 (h->interrupts_enabled == 0));
31222 }
31223
31224 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
31225 u32 a;
31226
31227 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
31228 - return h->access.command_completed(h);
31229 + return h->access->command_completed(h);
31230
31231 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
31232 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
31233 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
31234 trans_support & CFGTBL_Trans_use_short_tags);
31235
31236 /* Change the access methods to the performant access methods */
31237 - h->access = SA5_performant_access;
31238 + h->access = &SA5_performant_access;
31239 h->transMethod = CFGTBL_Trans_Performant;
31240
31241 return;
31242 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
31243 if (prod_index < 0)
31244 return -ENODEV;
31245 h->product_name = products[prod_index].product_name;
31246 - h->access = *(products[prod_index].access);
31247 + h->access = products[prod_index].access;
31248
31249 if (cciss_board_disabled(h)) {
31250 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
31251 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
31252 }
31253
31254 /* make sure the board interrupts are off */
31255 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31256 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31257 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
31258 if (rc)
31259 goto clean2;
31260 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
31261 * fake ones to scoop up any residual completions.
31262 */
31263 spin_lock_irqsave(&h->lock, flags);
31264 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31265 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31266 spin_unlock_irqrestore(&h->lock, flags);
31267 free_irq(h->intr[h->intr_mode], h);
31268 rc = cciss_request_irq(h, cciss_msix_discard_completions,
31269 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
31270 dev_info(&h->pdev->dev, "Board READY.\n");
31271 dev_info(&h->pdev->dev,
31272 "Waiting for stale completions to drain.\n");
31273 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31274 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31275 msleep(10000);
31276 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31277 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31278
31279 rc = controller_reset_failed(h->cfgtable);
31280 if (rc)
31281 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
31282 cciss_scsi_setup(h);
31283
31284 /* Turn the interrupts on so we can service requests */
31285 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31286 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31287
31288 /* Get the firmware version */
31289 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
31290 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
31291 kfree(flush_buf);
31292 if (return_code != IO_OK)
31293 dev_warn(&h->pdev->dev, "Error flushing cache\n");
31294 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31295 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31296 free_irq(h->intr[h->intr_mode], h);
31297 }
31298
31299 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
31300 index 7fda30e..eb5dfe0 100644
31301 --- a/drivers/block/cciss.h
31302 +++ b/drivers/block/cciss.h
31303 @@ -101,7 +101,7 @@ struct ctlr_info
31304 /* information about each logical volume */
31305 drive_info_struct *drv[CISS_MAX_LUN];
31306
31307 - struct access_method access;
31308 + struct access_method *access;
31309
31310 /* queue and queue Info */
31311 struct list_head reqQ;
31312 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
31313 index 9125bbe..eede5c8 100644
31314 --- a/drivers/block/cpqarray.c
31315 +++ b/drivers/block/cpqarray.c
31316 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31317 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
31318 goto Enomem4;
31319 }
31320 - hba[i]->access.set_intr_mask(hba[i], 0);
31321 + hba[i]->access->set_intr_mask(hba[i], 0);
31322 if (request_irq(hba[i]->intr, do_ida_intr,
31323 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
31324 {
31325 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31326 add_timer(&hba[i]->timer);
31327
31328 /* Enable IRQ now that spinlock and rate limit timer are set up */
31329 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31330 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31331
31332 for(j=0; j<NWD; j++) {
31333 struct gendisk *disk = ida_gendisk[i][j];
31334 @@ -694,7 +694,7 @@ DBGINFO(
31335 for(i=0; i<NR_PRODUCTS; i++) {
31336 if (board_id == products[i].board_id) {
31337 c->product_name = products[i].product_name;
31338 - c->access = *(products[i].access);
31339 + c->access = products[i].access;
31340 break;
31341 }
31342 }
31343 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
31344 hba[ctlr]->intr = intr;
31345 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
31346 hba[ctlr]->product_name = products[j].product_name;
31347 - hba[ctlr]->access = *(products[j].access);
31348 + hba[ctlr]->access = products[j].access;
31349 hba[ctlr]->ctlr = ctlr;
31350 hba[ctlr]->board_id = board_id;
31351 hba[ctlr]->pci_dev = NULL; /* not PCI */
31352 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
31353
31354 while((c = h->reqQ) != NULL) {
31355 /* Can't do anything if we're busy */
31356 - if (h->access.fifo_full(h) == 0)
31357 + if (h->access->fifo_full(h) == 0)
31358 return;
31359
31360 /* Get the first entry from the request Q */
31361 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
31362 h->Qdepth--;
31363
31364 /* Tell the controller to do our bidding */
31365 - h->access.submit_command(h, c);
31366 + h->access->submit_command(h, c);
31367
31368 /* Get onto the completion Q */
31369 addQ(&h->cmpQ, c);
31370 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31371 unsigned long flags;
31372 __u32 a,a1;
31373
31374 - istat = h->access.intr_pending(h);
31375 + istat = h->access->intr_pending(h);
31376 /* Is this interrupt for us? */
31377 if (istat == 0)
31378 return IRQ_NONE;
31379 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31380 */
31381 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
31382 if (istat & FIFO_NOT_EMPTY) {
31383 - while((a = h->access.command_completed(h))) {
31384 + while((a = h->access->command_completed(h))) {
31385 a1 = a; a &= ~3;
31386 if ((c = h->cmpQ) == NULL)
31387 {
31388 @@ -1449,11 +1449,11 @@ static int sendcmd(
31389 /*
31390 * Disable interrupt
31391 */
31392 - info_p->access.set_intr_mask(info_p, 0);
31393 + info_p->access->set_intr_mask(info_p, 0);
31394 /* Make sure there is room in the command FIFO */
31395 /* Actually it should be completely empty at this time. */
31396 for (i = 200000; i > 0; i--) {
31397 - temp = info_p->access.fifo_full(info_p);
31398 + temp = info_p->access->fifo_full(info_p);
31399 if (temp != 0) {
31400 break;
31401 }
31402 @@ -1466,7 +1466,7 @@ DBG(
31403 /*
31404 * Send the cmd
31405 */
31406 - info_p->access.submit_command(info_p, c);
31407 + info_p->access->submit_command(info_p, c);
31408 complete = pollcomplete(ctlr);
31409
31410 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31411 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31412 * we check the new geometry. Then turn interrupts back on when
31413 * we're done.
31414 */
31415 - host->access.set_intr_mask(host, 0);
31416 + host->access->set_intr_mask(host, 0);
31417 getgeometry(ctlr);
31418 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31419 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31420
31421 for(i=0; i<NWD; i++) {
31422 struct gendisk *disk = ida_gendisk[ctlr][i];
31423 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31424 /* Wait (up to 2 seconds) for a command to complete */
31425
31426 for (i = 200000; i > 0; i--) {
31427 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
31428 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
31429 if (done == 0) {
31430 udelay(10); /* a short fixed delay */
31431 } else
31432 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31433 index be73e9d..7fbf140 100644
31434 --- a/drivers/block/cpqarray.h
31435 +++ b/drivers/block/cpqarray.h
31436 @@ -99,7 +99,7 @@ struct ctlr_info {
31437 drv_info_t drv[NWD];
31438 struct proc_dir_entry *proc;
31439
31440 - struct access_method access;
31441 + struct access_method *access;
31442
31443 cmdlist_t *reqQ;
31444 cmdlist_t *cmpQ;
31445 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31446 index b953cc7..e3dc580 100644
31447 --- a/drivers/block/drbd/drbd_int.h
31448 +++ b/drivers/block/drbd/drbd_int.h
31449 @@ -735,7 +735,7 @@ struct drbd_request;
31450 struct drbd_epoch {
31451 struct list_head list;
31452 unsigned int barrier_nr;
31453 - atomic_t epoch_size; /* increased on every request added. */
31454 + atomic_unchecked_t epoch_size; /* increased on every request added. */
31455 atomic_t active; /* increased on every req. added, and dec on every finished. */
31456 unsigned long flags;
31457 };
31458 @@ -1116,7 +1116,7 @@ struct drbd_conf {
31459 void *int_dig_in;
31460 void *int_dig_vv;
31461 wait_queue_head_t seq_wait;
31462 - atomic_t packet_seq;
31463 + atomic_unchecked_t packet_seq;
31464 unsigned int peer_seq;
31465 spinlock_t peer_seq_lock;
31466 unsigned int minor;
31467 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31468
31469 static inline void drbd_tcp_cork(struct socket *sock)
31470 {
31471 - int __user val = 1;
31472 + int val = 1;
31473 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31474 - (char __user *)&val, sizeof(val));
31475 + (char __force_user *)&val, sizeof(val));
31476 }
31477
31478 static inline void drbd_tcp_uncork(struct socket *sock)
31479 {
31480 - int __user val = 0;
31481 + int val = 0;
31482 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31483 - (char __user *)&val, sizeof(val));
31484 + (char __force_user *)&val, sizeof(val));
31485 }
31486
31487 static inline void drbd_tcp_nodelay(struct socket *sock)
31488 {
31489 - int __user val = 1;
31490 + int val = 1;
31491 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31492 - (char __user *)&val, sizeof(val));
31493 + (char __force_user *)&val, sizeof(val));
31494 }
31495
31496 static inline void drbd_tcp_quickack(struct socket *sock)
31497 {
31498 - int __user val = 2;
31499 + int val = 2;
31500 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31501 - (char __user *)&val, sizeof(val));
31502 + (char __force_user *)&val, sizeof(val));
31503 }
31504
31505 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31506 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31507 index f55683a..2101b96 100644
31508 --- a/drivers/block/drbd/drbd_main.c
31509 +++ b/drivers/block/drbd/drbd_main.c
31510 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31511 p.sector = sector;
31512 p.block_id = block_id;
31513 p.blksize = blksize;
31514 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31515 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31516
31517 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31518 return false;
31519 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31520
31521 p.sector = cpu_to_be64(req->sector);
31522 p.block_id = (unsigned long)req;
31523 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31524 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31525
31526 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31527
31528 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31529 atomic_set(&mdev->unacked_cnt, 0);
31530 atomic_set(&mdev->local_cnt, 0);
31531 atomic_set(&mdev->net_cnt, 0);
31532 - atomic_set(&mdev->packet_seq, 0);
31533 + atomic_set_unchecked(&mdev->packet_seq, 0);
31534 atomic_set(&mdev->pp_in_use, 0);
31535 atomic_set(&mdev->pp_in_use_by_net, 0);
31536 atomic_set(&mdev->rs_sect_in, 0);
31537 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31538 mdev->receiver.t_state);
31539
31540 /* no need to lock it, I'm the only thread alive */
31541 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31542 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31543 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31544 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31545 mdev->al_writ_cnt =
31546 mdev->bm_writ_cnt =
31547 mdev->read_cnt =
31548 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31549 index edb490a..ecd69da 100644
31550 --- a/drivers/block/drbd/drbd_nl.c
31551 +++ b/drivers/block/drbd/drbd_nl.c
31552 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31553 module_put(THIS_MODULE);
31554 }
31555
31556 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31557 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31558
31559 static unsigned short *
31560 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31561 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31562 cn_reply->id.idx = CN_IDX_DRBD;
31563 cn_reply->id.val = CN_VAL_DRBD;
31564
31565 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31566 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31567 cn_reply->ack = 0; /* not used here. */
31568 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31569 (int)((char *)tl - (char *)reply->tag_list);
31570 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31571 cn_reply->id.idx = CN_IDX_DRBD;
31572 cn_reply->id.val = CN_VAL_DRBD;
31573
31574 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31575 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31576 cn_reply->ack = 0; /* not used here. */
31577 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31578 (int)((char *)tl - (char *)reply->tag_list);
31579 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31580 cn_reply->id.idx = CN_IDX_DRBD;
31581 cn_reply->id.val = CN_VAL_DRBD;
31582
31583 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31584 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31585 cn_reply->ack = 0; // not used here.
31586 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31587 (int)((char*)tl - (char*)reply->tag_list);
31588 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31589 cn_reply->id.idx = CN_IDX_DRBD;
31590 cn_reply->id.val = CN_VAL_DRBD;
31591
31592 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31593 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31594 cn_reply->ack = 0; /* not used here. */
31595 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31596 (int)((char *)tl - (char *)reply->tag_list);
31597 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31598 index c74ca2d..860c819 100644
31599 --- a/drivers/block/drbd/drbd_receiver.c
31600 +++ b/drivers/block/drbd/drbd_receiver.c
31601 @@ -898,7 +898,7 @@ retry:
31602 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31603 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31604
31605 - atomic_set(&mdev->packet_seq, 0);
31606 + atomic_set_unchecked(&mdev->packet_seq, 0);
31607 mdev->peer_seq = 0;
31608
31609 if (drbd_send_protocol(mdev) == -1)
31610 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31611 do {
31612 next_epoch = NULL;
31613
31614 - epoch_size = atomic_read(&epoch->epoch_size);
31615 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31616
31617 switch (ev & ~EV_CLEANUP) {
31618 case EV_PUT:
31619 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31620 rv = FE_DESTROYED;
31621 } else {
31622 epoch->flags = 0;
31623 - atomic_set(&epoch->epoch_size, 0);
31624 + atomic_set_unchecked(&epoch->epoch_size, 0);
31625 /* atomic_set(&epoch->active, 0); is already zero */
31626 if (rv == FE_STILL_LIVE)
31627 rv = FE_RECYCLED;
31628 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31629 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31630 drbd_flush(mdev);
31631
31632 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31633 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31634 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31635 if (epoch)
31636 break;
31637 }
31638
31639 epoch = mdev->current_epoch;
31640 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31641 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31642
31643 D_ASSERT(atomic_read(&epoch->active) == 0);
31644 D_ASSERT(epoch->flags == 0);
31645 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31646 }
31647
31648 epoch->flags = 0;
31649 - atomic_set(&epoch->epoch_size, 0);
31650 + atomic_set_unchecked(&epoch->epoch_size, 0);
31651 atomic_set(&epoch->active, 0);
31652
31653 spin_lock(&mdev->epoch_lock);
31654 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31655 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31656 list_add(&epoch->list, &mdev->current_epoch->list);
31657 mdev->current_epoch = epoch;
31658 mdev->epochs++;
31659 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31660 spin_unlock(&mdev->peer_seq_lock);
31661
31662 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31663 - atomic_inc(&mdev->current_epoch->epoch_size);
31664 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31665 return drbd_drain_block(mdev, data_size);
31666 }
31667
31668 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31669
31670 spin_lock(&mdev->epoch_lock);
31671 e->epoch = mdev->current_epoch;
31672 - atomic_inc(&e->epoch->epoch_size);
31673 + atomic_inc_unchecked(&e->epoch->epoch_size);
31674 atomic_inc(&e->epoch->active);
31675 spin_unlock(&mdev->epoch_lock);
31676
31677 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31678 D_ASSERT(list_empty(&mdev->done_ee));
31679
31680 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31681 - atomic_set(&mdev->current_epoch->epoch_size, 0);
31682 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31683 D_ASSERT(list_empty(&mdev->current_epoch->list));
31684 }
31685
31686 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31687 index 54046e5..7759c55 100644
31688 --- a/drivers/block/loop.c
31689 +++ b/drivers/block/loop.c
31690 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31691 mm_segment_t old_fs = get_fs();
31692
31693 set_fs(get_ds());
31694 - bw = file->f_op->write(file, buf, len, &pos);
31695 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31696 set_fs(old_fs);
31697 if (likely(bw == len))
31698 return 0;
31699 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31700 index d620b44..587561e 100644
31701 --- a/drivers/cdrom/cdrom.c
31702 +++ b/drivers/cdrom/cdrom.c
31703 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31704 ENSURE(reset, CDC_RESET);
31705 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31706 cdi->mc_flags = 0;
31707 - cdo->n_minors = 0;
31708 cdi->options = CDO_USE_FFLAGS;
31709
31710 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31711 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31712 else
31713 cdi->cdda_method = CDDA_OLD;
31714
31715 - if (!cdo->generic_packet)
31716 - cdo->generic_packet = cdrom_dummy_generic_packet;
31717 + if (!cdo->generic_packet) {
31718 + pax_open_kernel();
31719 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31720 + pax_close_kernel();
31721 + }
31722
31723 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31724 mutex_lock(&cdrom_mutex);
31725 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31726 if (cdi->exit)
31727 cdi->exit(cdi);
31728
31729 - cdi->ops->n_minors--;
31730 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31731 }
31732
31733 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31734 index 75d485a..2809958 100644
31735 --- a/drivers/cdrom/gdrom.c
31736 +++ b/drivers/cdrom/gdrom.c
31737 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31738 .audio_ioctl = gdrom_audio_ioctl,
31739 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31740 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31741 - .n_minors = 1,
31742 };
31743
31744 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31745 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31746 index 72bedad..8181ce1 100644
31747 --- a/drivers/char/Kconfig
31748 +++ b/drivers/char/Kconfig
31749 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31750
31751 config DEVKMEM
31752 bool "/dev/kmem virtual device support"
31753 - default y
31754 + default n
31755 + depends on !GRKERNSEC_KMEM
31756 help
31757 Say Y here if you want to support the /dev/kmem device. The
31758 /dev/kmem device is rarely used, but can be used for certain
31759 @@ -581,6 +582,7 @@ config DEVPORT
31760 bool
31761 depends on !M68K
31762 depends on ISA || PCI
31763 + depends on !GRKERNSEC_KMEM
31764 default y
31765
31766 source "drivers/s390/char/Kconfig"
31767 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31768 index 2e04433..22afc64 100644
31769 --- a/drivers/char/agp/frontend.c
31770 +++ b/drivers/char/agp/frontend.c
31771 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31772 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31773 return -EFAULT;
31774
31775 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31776 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31777 return -EFAULT;
31778
31779 client = agp_find_client_by_pid(reserve.pid);
31780 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31781 index 21cb980..f15107c 100644
31782 --- a/drivers/char/genrtc.c
31783 +++ b/drivers/char/genrtc.c
31784 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31785 switch (cmd) {
31786
31787 case RTC_PLL_GET:
31788 + memset(&pll, 0, sizeof(pll));
31789 if (get_rtc_pll(&pll))
31790 return -EINVAL;
31791 else
31792 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31793 index dfd7876..c0b0885 100644
31794 --- a/drivers/char/hpet.c
31795 +++ b/drivers/char/hpet.c
31796 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31797 }
31798
31799 static int
31800 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31801 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31802 struct hpet_info *info)
31803 {
31804 struct hpet_timer __iomem *timer;
31805 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31806 index a0c84bb..9edcf60 100644
31807 --- a/drivers/char/ipmi/ipmi_msghandler.c
31808 +++ b/drivers/char/ipmi/ipmi_msghandler.c
31809 @@ -420,7 +420,7 @@ struct ipmi_smi {
31810 struct proc_dir_entry *proc_dir;
31811 char proc_dir_name[10];
31812
31813 - atomic_t stats[IPMI_NUM_STATS];
31814 + atomic_unchecked_t stats[IPMI_NUM_STATS];
31815
31816 /*
31817 * run_to_completion duplicate of smb_info, smi_info
31818 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31819
31820
31821 #define ipmi_inc_stat(intf, stat) \
31822 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31823 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31824 #define ipmi_get_stat(intf, stat) \
31825 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31826 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31827
31828 static int is_lan_addr(struct ipmi_addr *addr)
31829 {
31830 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31831 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31832 init_waitqueue_head(&intf->waitq);
31833 for (i = 0; i < IPMI_NUM_STATS; i++)
31834 - atomic_set(&intf->stats[i], 0);
31835 + atomic_set_unchecked(&intf->stats[i], 0);
31836
31837 intf->proc_dir = NULL;
31838
31839 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31840 index 32a6c7e..f6966a9 100644
31841 --- a/drivers/char/ipmi/ipmi_si_intf.c
31842 +++ b/drivers/char/ipmi/ipmi_si_intf.c
31843 @@ -275,7 +275,7 @@ struct smi_info {
31844 unsigned char slave_addr;
31845
31846 /* Counters and things for the proc filesystem. */
31847 - atomic_t stats[SI_NUM_STATS];
31848 + atomic_unchecked_t stats[SI_NUM_STATS];
31849
31850 struct task_struct *thread;
31851
31852 @@ -284,9 +284,9 @@ struct smi_info {
31853 };
31854
31855 #define smi_inc_stat(smi, stat) \
31856 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31857 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31858 #define smi_get_stat(smi, stat) \
31859 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31860 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31861
31862 #define SI_MAX_PARMS 4
31863
31864 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31865 atomic_set(&new_smi->req_events, 0);
31866 new_smi->run_to_completion = 0;
31867 for (i = 0; i < SI_NUM_STATS; i++)
31868 - atomic_set(&new_smi->stats[i], 0);
31869 + atomic_set_unchecked(&new_smi->stats[i], 0);
31870
31871 new_smi->interrupt_disabled = 1;
31872 atomic_set(&new_smi->stop_operation, 0);
31873 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31874 index 0537903..121c699 100644
31875 --- a/drivers/char/mem.c
31876 +++ b/drivers/char/mem.c
31877 @@ -18,6 +18,7 @@
31878 #include <linux/raw.h>
31879 #include <linux/tty.h>
31880 #include <linux/capability.h>
31881 +#include <linux/security.h>
31882 #include <linux/ptrace.h>
31883 #include <linux/device.h>
31884 #include <linux/highmem.h>
31885 @@ -37,6 +38,10 @@
31886
31887 #define DEVPORT_MINOR 4
31888
31889 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31890 +extern const struct file_operations grsec_fops;
31891 +#endif
31892 +
31893 static inline unsigned long size_inside_page(unsigned long start,
31894 unsigned long size)
31895 {
31896 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31897
31898 while (cursor < to) {
31899 if (!devmem_is_allowed(pfn)) {
31900 +#ifdef CONFIG_GRKERNSEC_KMEM
31901 + gr_handle_mem_readwrite(from, to);
31902 +#else
31903 printk(KERN_INFO
31904 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31905 current->comm, from, to);
31906 +#endif
31907 return 0;
31908 }
31909 cursor += PAGE_SIZE;
31910 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31911 }
31912 return 1;
31913 }
31914 +#elif defined(CONFIG_GRKERNSEC_KMEM)
31915 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31916 +{
31917 + return 0;
31918 +}
31919 #else
31920 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31921 {
31922 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31923
31924 while (count > 0) {
31925 unsigned long remaining;
31926 + char *temp;
31927
31928 sz = size_inside_page(p, count);
31929
31930 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31931 if (!ptr)
31932 return -EFAULT;
31933
31934 - remaining = copy_to_user(buf, ptr, sz);
31935 +#ifdef CONFIG_PAX_USERCOPY
31936 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31937 + if (!temp) {
31938 + unxlate_dev_mem_ptr(p, ptr);
31939 + return -ENOMEM;
31940 + }
31941 + memcpy(temp, ptr, sz);
31942 +#else
31943 + temp = ptr;
31944 +#endif
31945 +
31946 + remaining = copy_to_user(buf, temp, sz);
31947 +
31948 +#ifdef CONFIG_PAX_USERCOPY
31949 + kfree(temp);
31950 +#endif
31951 +
31952 unxlate_dev_mem_ptr(p, ptr);
31953 if (remaining)
31954 return -EFAULT;
31955 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31956 size_t count, loff_t *ppos)
31957 {
31958 unsigned long p = *ppos;
31959 - ssize_t low_count, read, sz;
31960 + ssize_t low_count, read, sz, err = 0;
31961 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31962 - int err = 0;
31963
31964 read = 0;
31965 if (p < (unsigned long) high_memory) {
31966 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31967 }
31968 #endif
31969 while (low_count > 0) {
31970 + char *temp;
31971 +
31972 sz = size_inside_page(p, low_count);
31973
31974 /*
31975 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31976 */
31977 kbuf = xlate_dev_kmem_ptr((char *)p);
31978
31979 - if (copy_to_user(buf, kbuf, sz))
31980 +#ifdef CONFIG_PAX_USERCOPY
31981 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31982 + if (!temp)
31983 + return -ENOMEM;
31984 + memcpy(temp, kbuf, sz);
31985 +#else
31986 + temp = kbuf;
31987 +#endif
31988 +
31989 + err = copy_to_user(buf, temp, sz);
31990 +
31991 +#ifdef CONFIG_PAX_USERCOPY
31992 + kfree(temp);
31993 +#endif
31994 +
31995 + if (err)
31996 return -EFAULT;
31997 buf += sz;
31998 p += sz;
31999 @@ -833,6 +880,9 @@ static const struct memdev {
32000 #ifdef CONFIG_CRASH_DUMP
32001 [12] = { "oldmem", 0, &oldmem_fops, NULL },
32002 #endif
32003 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32004 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
32005 +#endif
32006 };
32007
32008 static int memory_open(struct inode *inode, struct file *filp)
32009 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
32010 index 9df78e2..01ba9ae 100644
32011 --- a/drivers/char/nvram.c
32012 +++ b/drivers/char/nvram.c
32013 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32014
32015 spin_unlock_irq(&rtc_lock);
32016
32017 - if (copy_to_user(buf, contents, tmp - contents))
32018 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32019 return -EFAULT;
32020
32021 *ppos = i;
32022 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32023 index 21721d2..4e98777 100644
32024 --- a/drivers/char/pcmcia/synclink_cs.c
32025 +++ b/drivers/char/pcmcia/synclink_cs.c
32026 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32027
32028 if (debug_level >= DEBUG_LEVEL_INFO)
32029 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32030 - __FILE__,__LINE__, info->device_name, port->count);
32031 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32032
32033 - WARN_ON(!port->count);
32034 + WARN_ON(!atomic_read(&port->count));
32035
32036 if (tty_port_close_start(port, tty, filp) == 0)
32037 goto cleanup;
32038 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32039 cleanup:
32040 if (debug_level >= DEBUG_LEVEL_INFO)
32041 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32042 - tty->driver->name, port->count);
32043 + tty->driver->name, atomic_read(&port->count));
32044 }
32045
32046 /* Wait until the transmitter is empty.
32047 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32048
32049 if (debug_level >= DEBUG_LEVEL_INFO)
32050 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32051 - __FILE__,__LINE__,tty->driver->name, port->count);
32052 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32053
32054 /* If port is closing, signal caller to try again */
32055 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32056 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32057 goto cleanup;
32058 }
32059 spin_lock(&port->lock);
32060 - port->count++;
32061 + atomic_inc(&port->count);
32062 spin_unlock(&port->lock);
32063 spin_unlock_irqrestore(&info->netlock, flags);
32064
32065 - if (port->count == 1) {
32066 + if (atomic_read(&port->count) == 1) {
32067 /* 1st open on this device, init hardware */
32068 retval = startup(info, tty);
32069 if (retval < 0)
32070 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32071 unsigned short new_crctype;
32072
32073 /* return error if TTY interface open */
32074 - if (info->port.count)
32075 + if (atomic_read(&info->port.count))
32076 return -EBUSY;
32077
32078 switch (encoding)
32079 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
32080
32081 /* arbitrate between network and tty opens */
32082 spin_lock_irqsave(&info->netlock, flags);
32083 - if (info->port.count != 0 || info->netcount != 0) {
32084 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32085 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32086 spin_unlock_irqrestore(&info->netlock, flags);
32087 return -EBUSY;
32088 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32089 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32090
32091 /* return error if TTY interface open */
32092 - if (info->port.count)
32093 + if (atomic_read(&info->port.count))
32094 return -EBUSY;
32095
32096 if (cmd != SIOCWANDEV)
32097 diff --git a/drivers/char/random.c b/drivers/char/random.c
32098 index b86eae9..b9c2ed7 100644
32099 --- a/drivers/char/random.c
32100 +++ b/drivers/char/random.c
32101 @@ -272,8 +272,13 @@
32102 /*
32103 * Configuration information
32104 */
32105 +#ifdef CONFIG_GRKERNSEC_RANDNET
32106 +#define INPUT_POOL_WORDS 512
32107 +#define OUTPUT_POOL_WORDS 128
32108 +#else
32109 #define INPUT_POOL_WORDS 128
32110 #define OUTPUT_POOL_WORDS 32
32111 +#endif
32112 #define SEC_XFER_SIZE 512
32113 #define EXTRACT_SIZE 10
32114
32115 @@ -313,10 +318,17 @@ static struct poolinfo {
32116 int poolwords;
32117 int tap1, tap2, tap3, tap4, tap5;
32118 } poolinfo_table[] = {
32119 +#ifdef CONFIG_GRKERNSEC_RANDNET
32120 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32121 + { 512, 411, 308, 208, 104, 1 },
32122 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32123 + { 128, 103, 76, 51, 25, 1 },
32124 +#else
32125 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32126 { 128, 103, 76, 51, 25, 1 },
32127 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32128 { 32, 26, 20, 14, 7, 1 },
32129 +#endif
32130 #if 0
32131 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32132 { 2048, 1638, 1231, 819, 411, 1 },
32133 @@ -437,6 +449,7 @@ struct entropy_store {
32134 int entropy_count;
32135 int entropy_total;
32136 unsigned int initialized:1;
32137 + bool last_data_init;
32138 __u8 last_data[EXTRACT_SIZE];
32139 };
32140
32141 @@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32142 input_rotate += i ? 7 : 14;
32143 }
32144
32145 - ACCESS_ONCE(r->input_rotate) = input_rotate;
32146 - ACCESS_ONCE(r->add_ptr) = i;
32147 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32148 + ACCESS_ONCE_RW(r->add_ptr) = i;
32149 smp_wmb();
32150
32151 if (out)
32152 @@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32153 ssize_t ret = 0, i;
32154 __u8 tmp[EXTRACT_SIZE];
32155
32156 + /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
32157 + if (fips_enabled && !r->last_data_init)
32158 + nbytes += EXTRACT_SIZE;
32159 +
32160 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
32161 xfer_secondary_pool(r, nbytes);
32162 nbytes = account(r, nbytes, min, reserved);
32163 @@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32164 if (fips_enabled) {
32165 unsigned long flags;
32166
32167 +
32168 + /* prime last_data value if need be, per fips 140-2 */
32169 + if (!r->last_data_init) {
32170 + spin_lock_irqsave(&r->lock, flags);
32171 + memcpy(r->last_data, tmp, EXTRACT_SIZE);
32172 + r->last_data_init = true;
32173 + nbytes -= EXTRACT_SIZE;
32174 + spin_unlock_irqrestore(&r->lock, flags);
32175 + extract_buf(r, tmp);
32176 + }
32177 +
32178 spin_lock_irqsave(&r->lock, flags);
32179 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
32180 panic("Hardware RNG duplicated output!\n");
32181 @@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32182
32183 extract_buf(r, tmp);
32184 i = min_t(int, nbytes, EXTRACT_SIZE);
32185 - if (copy_to_user(buf, tmp, i)) {
32186 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32187 ret = -EFAULT;
32188 break;
32189 }
32190 @@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
32191
32192 r->entropy_count = 0;
32193 r->entropy_total = 0;
32194 + r->last_data_init = false;
32195 mix_pool_bytes(r, &now, sizeof(now), NULL);
32196 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
32197 if (!arch_get_random_long(&rv))
32198 @@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32199 #include <linux/sysctl.h>
32200
32201 static int min_read_thresh = 8, min_write_thresh;
32202 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
32203 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32204 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32205 static char sysctl_bootid[16];
32206
32207 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32208 index 9b4f011..b7e0a1a 100644
32209 --- a/drivers/char/sonypi.c
32210 +++ b/drivers/char/sonypi.c
32211 @@ -54,6 +54,7 @@
32212
32213 #include <asm/uaccess.h>
32214 #include <asm/io.h>
32215 +#include <asm/local.h>
32216
32217 #include <linux/sonypi.h>
32218
32219 @@ -490,7 +491,7 @@ static struct sonypi_device {
32220 spinlock_t fifo_lock;
32221 wait_queue_head_t fifo_proc_list;
32222 struct fasync_struct *fifo_async;
32223 - int open_count;
32224 + local_t open_count;
32225 int model;
32226 struct input_dev *input_jog_dev;
32227 struct input_dev *input_key_dev;
32228 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
32229 static int sonypi_misc_release(struct inode *inode, struct file *file)
32230 {
32231 mutex_lock(&sonypi_device.lock);
32232 - sonypi_device.open_count--;
32233 + local_dec(&sonypi_device.open_count);
32234 mutex_unlock(&sonypi_device.lock);
32235 return 0;
32236 }
32237 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
32238 {
32239 mutex_lock(&sonypi_device.lock);
32240 /* Flush input queue on first open */
32241 - if (!sonypi_device.open_count)
32242 + if (!local_read(&sonypi_device.open_count))
32243 kfifo_reset(&sonypi_device.fifo);
32244 - sonypi_device.open_count++;
32245 + local_inc(&sonypi_device.open_count);
32246 mutex_unlock(&sonypi_device.lock);
32247
32248 return 0;
32249 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
32250 index 93211df..c7805f7 100644
32251 --- a/drivers/char/tpm/tpm.c
32252 +++ b/drivers/char/tpm/tpm.c
32253 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
32254 chip->vendor.req_complete_val)
32255 goto out_recv;
32256
32257 - if ((status == chip->vendor.req_canceled)) {
32258 + if (status == chip->vendor.req_canceled) {
32259 dev_err(chip->dev, "Operation Canceled\n");
32260 rc = -ECANCELED;
32261 goto out;
32262 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
32263 index 56051d0..11cf3b7 100644
32264 --- a/drivers/char/tpm/tpm_acpi.c
32265 +++ b/drivers/char/tpm/tpm_acpi.c
32266 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
32267 virt = acpi_os_map_memory(start, len);
32268 if (!virt) {
32269 kfree(log->bios_event_log);
32270 + log->bios_event_log = NULL;
32271 printk("%s: ERROR - Unable to map memory\n", __func__);
32272 return -EIO;
32273 }
32274
32275 - memcpy_fromio(log->bios_event_log, virt, len);
32276 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
32277
32278 acpi_os_unmap_memory(virt, len);
32279 return 0;
32280 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
32281 index 84ddc55..1d32f1e 100644
32282 --- a/drivers/char/tpm/tpm_eventlog.c
32283 +++ b/drivers/char/tpm/tpm_eventlog.c
32284 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
32285 event = addr;
32286
32287 if ((event->event_type == 0 && event->event_size == 0) ||
32288 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
32289 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
32290 return NULL;
32291
32292 return addr;
32293 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
32294 return NULL;
32295
32296 if ((event->event_type == 0 && event->event_size == 0) ||
32297 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
32298 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
32299 return NULL;
32300
32301 (*pos)++;
32302 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
32303 int i;
32304
32305 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
32306 - seq_putc(m, data[i]);
32307 + if (!seq_putc(m, data[i]))
32308 + return -EFAULT;
32309
32310 return 0;
32311 }
32312 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
32313 index 8ab9c3d..c3e65d3 100644
32314 --- a/drivers/char/virtio_console.c
32315 +++ b/drivers/char/virtio_console.c
32316 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
32317 if (to_user) {
32318 ssize_t ret;
32319
32320 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
32321 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
32322 if (ret)
32323 return -EFAULT;
32324 } else {
32325 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
32326 if (!port_has_data(port) && !port->host_connected)
32327 return 0;
32328
32329 - return fill_readbuf(port, ubuf, count, true);
32330 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
32331 }
32332
32333 static int wait_port_writable(struct port *port, bool nonblock)
32334 diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
32335 index 75c0a1a..96ba8f6 100644
32336 --- a/drivers/edac/edac_mc.c
32337 +++ b/drivers/edac/edac_mc.c
32338 @@ -340,7 +340,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32339 /*
32340 * Alocate and fill the csrow/channels structs
32341 */
32342 - mci->csrows = kcalloc(sizeof(*mci->csrows), tot_csrows, GFP_KERNEL);
32343 + mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
32344 if (!mci->csrows)
32345 goto error;
32346 for (row = 0; row < tot_csrows; row++) {
32347 @@ -351,7 +351,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32348 csr->csrow_idx = row;
32349 csr->mci = mci;
32350 csr->nr_channels = tot_channels;
32351 - csr->channels = kcalloc(sizeof(*csr->channels), tot_channels,
32352 + csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
32353 GFP_KERNEL);
32354 if (!csr->channels)
32355 goto error;
32356 @@ -369,7 +369,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32357 /*
32358 * Allocate and fill the dimm structs
32359 */
32360 - mci->dimms = kcalloc(sizeof(*mci->dimms), tot_dimms, GFP_KERNEL);
32361 + mci->dimms = kcalloc(tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
32362 if (!mci->dimms)
32363 goto error;
32364
32365 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32366 index 1bfb207..0d059c2 100644
32367 --- a/drivers/edac/edac_pci_sysfs.c
32368 +++ b/drivers/edac/edac_pci_sysfs.c
32369 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32370 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32371 static int edac_pci_poll_msec = 1000; /* one second workq period */
32372
32373 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
32374 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32375 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32376 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32377
32378 static struct kobject *edac_pci_top_main_kobj;
32379 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32380 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32381 edac_printk(KERN_CRIT, EDAC_PCI,
32382 "Signaled System Error on %s\n",
32383 pci_name(dev));
32384 - atomic_inc(&pci_nonparity_count);
32385 + atomic_inc_unchecked(&pci_nonparity_count);
32386 }
32387
32388 if (status & (PCI_STATUS_PARITY)) {
32389 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32390 "Master Data Parity Error on %s\n",
32391 pci_name(dev));
32392
32393 - atomic_inc(&pci_parity_count);
32394 + atomic_inc_unchecked(&pci_parity_count);
32395 }
32396
32397 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32398 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32399 "Detected Parity Error on %s\n",
32400 pci_name(dev));
32401
32402 - atomic_inc(&pci_parity_count);
32403 + atomic_inc_unchecked(&pci_parity_count);
32404 }
32405 }
32406
32407 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32408 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32409 "Signaled System Error on %s\n",
32410 pci_name(dev));
32411 - atomic_inc(&pci_nonparity_count);
32412 + atomic_inc_unchecked(&pci_nonparity_count);
32413 }
32414
32415 if (status & (PCI_STATUS_PARITY)) {
32416 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32417 "Master Data Parity Error on "
32418 "%s\n", pci_name(dev));
32419
32420 - atomic_inc(&pci_parity_count);
32421 + atomic_inc_unchecked(&pci_parity_count);
32422 }
32423
32424 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32425 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32426 "Detected Parity Error on %s\n",
32427 pci_name(dev));
32428
32429 - atomic_inc(&pci_parity_count);
32430 + atomic_inc_unchecked(&pci_parity_count);
32431 }
32432 }
32433 }
32434 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32435 if (!check_pci_errors)
32436 return;
32437
32438 - before_count = atomic_read(&pci_parity_count);
32439 + before_count = atomic_read_unchecked(&pci_parity_count);
32440
32441 /* scan all PCI devices looking for a Parity Error on devices and
32442 * bridges.
32443 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32444 /* Only if operator has selected panic on PCI Error */
32445 if (edac_pci_get_panic_on_pe()) {
32446 /* If the count is different 'after' from 'before' */
32447 - if (before_count != atomic_read(&pci_parity_count))
32448 + if (before_count != atomic_read_unchecked(&pci_parity_count))
32449 panic("EDAC: PCI Parity Error");
32450 }
32451 }
32452 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32453 index 8c87a5e..a19cbd7 100644
32454 --- a/drivers/edac/mce_amd.h
32455 +++ b/drivers/edac/mce_amd.h
32456 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32457 struct amd_decoder_ops {
32458 bool (*dc_mce)(u16, u8);
32459 bool (*ic_mce)(u16, u8);
32460 -};
32461 +} __no_const;
32462
32463 void amd_report_gart_errors(bool);
32464 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32465 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32466 index 57ea7f4..789e3c3 100644
32467 --- a/drivers/firewire/core-card.c
32468 +++ b/drivers/firewire/core-card.c
32469 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32470
32471 void fw_core_remove_card(struct fw_card *card)
32472 {
32473 - struct fw_card_driver dummy_driver = dummy_driver_template;
32474 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
32475
32476 card->driver->update_phy_reg(card, 4,
32477 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32478 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32479 index f8d2287..5aaf4db 100644
32480 --- a/drivers/firewire/core-cdev.c
32481 +++ b/drivers/firewire/core-cdev.c
32482 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32483 int ret;
32484
32485 if ((request->channels == 0 && request->bandwidth == 0) ||
32486 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32487 - request->bandwidth < 0)
32488 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32489 return -EINVAL;
32490
32491 r = kmalloc(sizeof(*r), GFP_KERNEL);
32492 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32493 index 28a94c7..58da63a 100644
32494 --- a/drivers/firewire/core-transaction.c
32495 +++ b/drivers/firewire/core-transaction.c
32496 @@ -38,6 +38,7 @@
32497 #include <linux/timer.h>
32498 #include <linux/types.h>
32499 #include <linux/workqueue.h>
32500 +#include <linux/sched.h>
32501
32502 #include <asm/byteorder.h>
32503
32504 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32505 index 515a42c..5ecf3ba 100644
32506 --- a/drivers/firewire/core.h
32507 +++ b/drivers/firewire/core.h
32508 @@ -111,6 +111,7 @@ struct fw_card_driver {
32509
32510 int (*stop_iso)(struct fw_iso_context *ctx);
32511 };
32512 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32513
32514 void fw_card_initialize(struct fw_card *card,
32515 const struct fw_card_driver *driver, struct device *device);
32516 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32517 index 982f1f5..d21e5da 100644
32518 --- a/drivers/firmware/dmi_scan.c
32519 +++ b/drivers/firmware/dmi_scan.c
32520 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
32521 }
32522 }
32523 else {
32524 - /*
32525 - * no iounmap() for that ioremap(); it would be a no-op, but
32526 - * it's so early in setup that sucker gets confused into doing
32527 - * what it shouldn't if we actually call it.
32528 - */
32529 p = dmi_ioremap(0xF0000, 0x10000);
32530 if (p == NULL)
32531 goto error;
32532 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32533 if (buf == NULL)
32534 return -1;
32535
32536 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32537 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32538
32539 iounmap(buf);
32540 return 0;
32541 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32542 index bfd8f43..133189c 100644
32543 --- a/drivers/firmware/efivars.c
32544 +++ b/drivers/firmware/efivars.c
32545 @@ -1234,9 +1234,9 @@ efivars_init(void)
32546 return -ENOMEM;
32547 }
32548
32549 - ops.get_variable = efi.get_variable;
32550 - ops.set_variable = efi.set_variable;
32551 - ops.get_next_variable = efi.get_next_variable;
32552 + *(void **)&ops.get_variable = efi.get_variable;
32553 + *(void **)&ops.set_variable = efi.set_variable;
32554 + *(void **)&ops.get_next_variable = efi.get_next_variable;
32555 error = register_efivars(&__efivars, &ops, efi_kobj);
32556 if (error)
32557 goto err_put;
32558 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32559 index 82d5c20..44a7177 100644
32560 --- a/drivers/gpio/gpio-vr41xx.c
32561 +++ b/drivers/gpio/gpio-vr41xx.c
32562 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32563 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32564 maskl, pendl, maskh, pendh);
32565
32566 - atomic_inc(&irq_err_count);
32567 + atomic_inc_unchecked(&irq_err_count);
32568
32569 return -EINVAL;
32570 }
32571 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32572 index 1227adf..f2301c2 100644
32573 --- a/drivers/gpu/drm/drm_crtc_helper.c
32574 +++ b/drivers/gpu/drm/drm_crtc_helper.c
32575 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32576 struct drm_crtc *tmp;
32577 int crtc_mask = 1;
32578
32579 - WARN(!crtc, "checking null crtc?\n");
32580 + BUG_ON(!crtc);
32581
32582 dev = crtc->dev;
32583
32584 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32585 index be174ca..0bcbb71 100644
32586 --- a/drivers/gpu/drm/drm_drv.c
32587 +++ b/drivers/gpu/drm/drm_drv.c
32588 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32589 /**
32590 * Copy and IOCTL return string to user space
32591 */
32592 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32593 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32594 {
32595 int len;
32596
32597 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32598 return -ENODEV;
32599
32600 atomic_inc(&dev->ioctl_count);
32601 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32602 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32603 ++file_priv->ioctl_count;
32604
32605 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32606 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32607 index 133b413..fd68225 100644
32608 --- a/drivers/gpu/drm/drm_fops.c
32609 +++ b/drivers/gpu/drm/drm_fops.c
32610 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32611 }
32612
32613 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32614 - atomic_set(&dev->counts[i], 0);
32615 + atomic_set_unchecked(&dev->counts[i], 0);
32616
32617 dev->sigdata.lock = NULL;
32618
32619 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32620 if (drm_device_is_unplugged(dev))
32621 return -ENODEV;
32622
32623 - if (!dev->open_count++)
32624 + if (local_inc_return(&dev->open_count) == 1)
32625 need_setup = 1;
32626 mutex_lock(&dev->struct_mutex);
32627 old_mapping = dev->dev_mapping;
32628 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32629 retcode = drm_open_helper(inode, filp, dev);
32630 if (retcode)
32631 goto err_undo;
32632 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32633 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32634 if (need_setup) {
32635 retcode = drm_setup(dev);
32636 if (retcode)
32637 @@ -164,7 +164,7 @@ err_undo:
32638 iput(container_of(dev->dev_mapping, struct inode, i_data));
32639 dev->dev_mapping = old_mapping;
32640 mutex_unlock(&dev->struct_mutex);
32641 - dev->open_count--;
32642 + local_dec(&dev->open_count);
32643 return retcode;
32644 }
32645 EXPORT_SYMBOL(drm_open);
32646 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32647
32648 mutex_lock(&drm_global_mutex);
32649
32650 - DRM_DEBUG("open_count = %d\n", dev->open_count);
32651 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32652
32653 if (dev->driver->preclose)
32654 dev->driver->preclose(dev, file_priv);
32655 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32656 * Begin inline drm_release
32657 */
32658
32659 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32660 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32661 task_pid_nr(current),
32662 (long)old_encode_dev(file_priv->minor->device),
32663 - dev->open_count);
32664 + local_read(&dev->open_count));
32665
32666 /* Release any auth tokens that might point to this file_priv,
32667 (do that under the drm_global_mutex) */
32668 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32669 * End inline drm_release
32670 */
32671
32672 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32673 - if (!--dev->open_count) {
32674 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32675 + if (local_dec_and_test(&dev->open_count)) {
32676 if (atomic_read(&dev->ioctl_count)) {
32677 DRM_ERROR("Device busy: %d\n",
32678 atomic_read(&dev->ioctl_count));
32679 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32680 index f731116..629842c 100644
32681 --- a/drivers/gpu/drm/drm_global.c
32682 +++ b/drivers/gpu/drm/drm_global.c
32683 @@ -36,7 +36,7 @@
32684 struct drm_global_item {
32685 struct mutex mutex;
32686 void *object;
32687 - int refcount;
32688 + atomic_t refcount;
32689 };
32690
32691 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32692 @@ -49,7 +49,7 @@ void drm_global_init(void)
32693 struct drm_global_item *item = &glob[i];
32694 mutex_init(&item->mutex);
32695 item->object = NULL;
32696 - item->refcount = 0;
32697 + atomic_set(&item->refcount, 0);
32698 }
32699 }
32700
32701 @@ -59,7 +59,7 @@ void drm_global_release(void)
32702 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32703 struct drm_global_item *item = &glob[i];
32704 BUG_ON(item->object != NULL);
32705 - BUG_ON(item->refcount != 0);
32706 + BUG_ON(atomic_read(&item->refcount) != 0);
32707 }
32708 }
32709
32710 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32711 void *object;
32712
32713 mutex_lock(&item->mutex);
32714 - if (item->refcount == 0) {
32715 + if (atomic_read(&item->refcount) == 0) {
32716 item->object = kzalloc(ref->size, GFP_KERNEL);
32717 if (unlikely(item->object == NULL)) {
32718 ret = -ENOMEM;
32719 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32720 goto out_err;
32721
32722 }
32723 - ++item->refcount;
32724 + atomic_inc(&item->refcount);
32725 ref->object = item->object;
32726 object = item->object;
32727 mutex_unlock(&item->mutex);
32728 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32729 struct drm_global_item *item = &glob[ref->global_type];
32730
32731 mutex_lock(&item->mutex);
32732 - BUG_ON(item->refcount == 0);
32733 + BUG_ON(atomic_read(&item->refcount) == 0);
32734 BUG_ON(ref->object != item->object);
32735 - if (--item->refcount == 0) {
32736 + if (atomic_dec_and_test(&item->refcount)) {
32737 ref->release(ref);
32738 item->object = NULL;
32739 }
32740 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32741 index d4b20ce..77a8d41 100644
32742 --- a/drivers/gpu/drm/drm_info.c
32743 +++ b/drivers/gpu/drm/drm_info.c
32744 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32745 struct drm_local_map *map;
32746 struct drm_map_list *r_list;
32747
32748 - /* Hardcoded from _DRM_FRAME_BUFFER,
32749 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32750 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32751 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32752 + static const char * const types[] = {
32753 + [_DRM_FRAME_BUFFER] = "FB",
32754 + [_DRM_REGISTERS] = "REG",
32755 + [_DRM_SHM] = "SHM",
32756 + [_DRM_AGP] = "AGP",
32757 + [_DRM_SCATTER_GATHER] = "SG",
32758 + [_DRM_CONSISTENT] = "PCI",
32759 + [_DRM_GEM] = "GEM" };
32760 const char *type;
32761 int i;
32762
32763 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32764 map = r_list->map;
32765 if (!map)
32766 continue;
32767 - if (map->type < 0 || map->type > 5)
32768 + if (map->type >= ARRAY_SIZE(types))
32769 type = "??";
32770 else
32771 type = types[map->type];
32772 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32773 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32774 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32775 vma->vm_flags & VM_IO ? 'i' : '-',
32776 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32777 + 0);
32778 +#else
32779 vma->vm_pgoff);
32780 +#endif
32781
32782 #if defined(__i386__)
32783 pgprot = pgprot_val(vma->vm_page_prot);
32784 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32785 index 2f4c434..764794b 100644
32786 --- a/drivers/gpu/drm/drm_ioc32.c
32787 +++ b/drivers/gpu/drm/drm_ioc32.c
32788 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32789 request = compat_alloc_user_space(nbytes);
32790 if (!access_ok(VERIFY_WRITE, request, nbytes))
32791 return -EFAULT;
32792 - list = (struct drm_buf_desc *) (request + 1);
32793 + list = (struct drm_buf_desc __user *) (request + 1);
32794
32795 if (__put_user(count, &request->count)
32796 || __put_user(list, &request->list))
32797 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32798 request = compat_alloc_user_space(nbytes);
32799 if (!access_ok(VERIFY_WRITE, request, nbytes))
32800 return -EFAULT;
32801 - list = (struct drm_buf_pub *) (request + 1);
32802 + list = (struct drm_buf_pub __user *) (request + 1);
32803
32804 if (__put_user(count, &request->count)
32805 || __put_user(list, &request->list))
32806 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32807 index 23dd975..63e9801 100644
32808 --- a/drivers/gpu/drm/drm_ioctl.c
32809 +++ b/drivers/gpu/drm/drm_ioctl.c
32810 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32811 stats->data[i].value =
32812 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32813 else
32814 - stats->data[i].value = atomic_read(&dev->counts[i]);
32815 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32816 stats->data[i].type = dev->types[i];
32817 }
32818
32819 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32820 index d752c96..fe08455 100644
32821 --- a/drivers/gpu/drm/drm_lock.c
32822 +++ b/drivers/gpu/drm/drm_lock.c
32823 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32824 if (drm_lock_take(&master->lock, lock->context)) {
32825 master->lock.file_priv = file_priv;
32826 master->lock.lock_time = jiffies;
32827 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32828 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32829 break; /* Got lock */
32830 }
32831
32832 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32833 return -EINVAL;
32834 }
32835
32836 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32837 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32838
32839 if (drm_lock_free(&master->lock, lock->context)) {
32840 /* FIXME: Should really bail out here. */
32841 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32842 index c236fd2..6b5f2e7 100644
32843 --- a/drivers/gpu/drm/drm_stub.c
32844 +++ b/drivers/gpu/drm/drm_stub.c
32845 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32846
32847 drm_device_set_unplugged(dev);
32848
32849 - if (dev->open_count == 0) {
32850 + if (local_read(&dev->open_count) == 0) {
32851 drm_put_dev(dev);
32852 }
32853 mutex_unlock(&drm_global_mutex);
32854 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32855 index 004ecdf..db1f6e0 100644
32856 --- a/drivers/gpu/drm/i810/i810_dma.c
32857 +++ b/drivers/gpu/drm/i810/i810_dma.c
32858 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32859 dma->buflist[vertex->idx],
32860 vertex->discard, vertex->used);
32861
32862 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32863 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32864 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32865 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32866 sarea_priv->last_enqueue = dev_priv->counter - 1;
32867 sarea_priv->last_dispatch = (int)hw_status[5];
32868
32869 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32870 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32871 mc->last_render);
32872
32873 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32874 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32875 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32876 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32877 sarea_priv->last_enqueue = dev_priv->counter - 1;
32878 sarea_priv->last_dispatch = (int)hw_status[5];
32879
32880 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32881 index 6e0acad..93c8289 100644
32882 --- a/drivers/gpu/drm/i810/i810_drv.h
32883 +++ b/drivers/gpu/drm/i810/i810_drv.h
32884 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32885 int page_flipping;
32886
32887 wait_queue_head_t irq_queue;
32888 - atomic_t irq_received;
32889 - atomic_t irq_emitted;
32890 + atomic_unchecked_t irq_received;
32891 + atomic_unchecked_t irq_emitted;
32892
32893 int front_offset;
32894 } drm_i810_private_t;
32895 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32896 index 3a1a495..995c093 100644
32897 --- a/drivers/gpu/drm/i915/i915_debugfs.c
32898 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
32899 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32900 I915_READ(GTIMR));
32901 }
32902 seq_printf(m, "Interrupts received: %d\n",
32903 - atomic_read(&dev_priv->irq_received));
32904 + atomic_read_unchecked(&dev_priv->irq_received));
32905 for_each_ring(ring, dev_priv, i) {
32906 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32907 seq_printf(m,
32908 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32909 index 61ae104..f8a4bc1 100644
32910 --- a/drivers/gpu/drm/i915/i915_dma.c
32911 +++ b/drivers/gpu/drm/i915/i915_dma.c
32912 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32913 bool can_switch;
32914
32915 spin_lock(&dev->count_lock);
32916 - can_switch = (dev->open_count == 0);
32917 + can_switch = (local_read(&dev->open_count) == 0);
32918 spin_unlock(&dev->count_lock);
32919 return can_switch;
32920 }
32921 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32922 index 92f1750..3beba74 100644
32923 --- a/drivers/gpu/drm/i915/i915_drv.h
32924 +++ b/drivers/gpu/drm/i915/i915_drv.h
32925 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32926
32927 struct resource mch_res;
32928
32929 - atomic_t irq_received;
32930 + atomic_unchecked_t irq_received;
32931
32932 /* protects the irq masks */
32933 spinlock_t irq_lock;
32934 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32935 * will be page flipped away on the next vblank. When it
32936 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32937 */
32938 - atomic_t pending_flip;
32939 + atomic_unchecked_t pending_flip;
32940 };
32941
32942 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32943 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32944 struct drm_i915_private *dev_priv, unsigned port);
32945 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32946 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32947 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32948 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32949 {
32950 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32951 }
32952 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32953 index 67036e9..b9f1357 100644
32954 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32955 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32956 @@ -681,7 +681,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32957 i915_gem_clflush_object(obj);
32958
32959 if (obj->base.pending_write_domain)
32960 - flips |= atomic_read(&obj->pending_flip);
32961 + flips |= atomic_read_unchecked(&obj->pending_flip);
32962
32963 flush_domains |= obj->base.write_domain;
32964 }
32965 @@ -712,9 +712,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32966
32967 static int
32968 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32969 - int count)
32970 + unsigned int count)
32971 {
32972 - int i;
32973 + unsigned int i;
32974
32975 for (i = 0; i < count; i++) {
32976 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32977 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32978 index dc29ace..137d83a 100644
32979 --- a/drivers/gpu/drm/i915/i915_irq.c
32980 +++ b/drivers/gpu/drm/i915/i915_irq.c
32981 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32982 u32 pipe_stats[I915_MAX_PIPES];
32983 bool blc_event;
32984
32985 - atomic_inc(&dev_priv->irq_received);
32986 + atomic_inc_unchecked(&dev_priv->irq_received);
32987
32988 while (true) {
32989 iir = I915_READ(VLV_IIR);
32990 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32991 irqreturn_t ret = IRQ_NONE;
32992 int i;
32993
32994 - atomic_inc(&dev_priv->irq_received);
32995 + atomic_inc_unchecked(&dev_priv->irq_received);
32996
32997 /* disable master interrupt before clearing iir */
32998 de_ier = I915_READ(DEIER);
32999 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
33000 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
33001 u32 hotplug_mask;
33002
33003 - atomic_inc(&dev_priv->irq_received);
33004 + atomic_inc_unchecked(&dev_priv->irq_received);
33005
33006 /* disable master interrupt before clearing iir */
33007 de_ier = I915_READ(DEIER);
33008 @@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
33009 {
33010 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33011
33012 - atomic_set(&dev_priv->irq_received, 0);
33013 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33014
33015 I915_WRITE(HWSTAM, 0xeffe);
33016
33017 @@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33018 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33019 int pipe;
33020
33021 - atomic_set(&dev_priv->irq_received, 0);
33022 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33023
33024 /* VLV magic */
33025 I915_WRITE(VLV_IMR, 0);
33026 @@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33027 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33028 int pipe;
33029
33030 - atomic_set(&dev_priv->irq_received, 0);
33031 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33032
33033 for_each_pipe(pipe)
33034 I915_WRITE(PIPESTAT(pipe), 0);
33035 @@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
33036 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33037 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33038
33039 - atomic_inc(&dev_priv->irq_received);
33040 + atomic_inc_unchecked(&dev_priv->irq_received);
33041
33042 iir = I915_READ16(IIR);
33043 if (iir == 0)
33044 @@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33045 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33046 int pipe;
33047
33048 - atomic_set(&dev_priv->irq_received, 0);
33049 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33050
33051 if (I915_HAS_HOTPLUG(dev)) {
33052 I915_WRITE(PORT_HOTPLUG_EN, 0);
33053 @@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
33054 };
33055 int pipe, ret = IRQ_NONE;
33056
33057 - atomic_inc(&dev_priv->irq_received);
33058 + atomic_inc_unchecked(&dev_priv->irq_received);
33059
33060 iir = I915_READ(IIR);
33061 do {
33062 @@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33063 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33064 int pipe;
33065
33066 - atomic_set(&dev_priv->irq_received, 0);
33067 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33068
33069 I915_WRITE(PORT_HOTPLUG_EN, 0);
33070 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33071 @@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
33072 int irq_received;
33073 int ret = IRQ_NONE, pipe;
33074
33075 - atomic_inc(&dev_priv->irq_received);
33076 + atomic_inc_unchecked(&dev_priv->irq_received);
33077
33078 iir = I915_READ(IIR);
33079
33080 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33081 index 4d3c7c6..eaac87b 100644
33082 --- a/drivers/gpu/drm/i915/intel_display.c
33083 +++ b/drivers/gpu/drm/i915/intel_display.c
33084 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33085
33086 wait_event(dev_priv->pending_flip_queue,
33087 atomic_read(&dev_priv->mm.wedged) ||
33088 - atomic_read(&obj->pending_flip) == 0);
33089 + atomic_read_unchecked(&obj->pending_flip) == 0);
33090
33091 /* Big Hammer, we also need to ensure that any pending
33092 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33093 @@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33094
33095 obj = work->old_fb_obj;
33096
33097 - atomic_clear_mask(1 << intel_crtc->plane,
33098 - &obj->pending_flip.counter);
33099 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33100 wake_up(&dev_priv->pending_flip_queue);
33101
33102 queue_work(dev_priv->wq, &work->work);
33103 @@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33104 /* Block clients from rendering to the new back buffer until
33105 * the flip occurs and the object is no longer visible.
33106 */
33107 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33108 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33109 atomic_inc(&intel_crtc->unpin_work_count);
33110
33111 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33112 @@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33113
33114 cleanup_pending:
33115 atomic_dec(&intel_crtc->unpin_work_count);
33116 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33117 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33118 drm_gem_object_unreference(&work->old_fb_obj->base);
33119 drm_gem_object_unreference(&obj->base);
33120 mutex_unlock(&dev->struct_mutex);
33121 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33122 index 54558a0..2d97005 100644
33123 --- a/drivers/gpu/drm/mga/mga_drv.h
33124 +++ b/drivers/gpu/drm/mga/mga_drv.h
33125 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33126 u32 clear_cmd;
33127 u32 maccess;
33128
33129 - atomic_t vbl_received; /**< Number of vblanks received. */
33130 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33131 wait_queue_head_t fence_queue;
33132 - atomic_t last_fence_retired;
33133 + atomic_unchecked_t last_fence_retired;
33134 u32 next_fence_to_post;
33135
33136 unsigned int fb_cpp;
33137 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33138 index 598c281..60d590e 100644
33139 --- a/drivers/gpu/drm/mga/mga_irq.c
33140 +++ b/drivers/gpu/drm/mga/mga_irq.c
33141 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33142 if (crtc != 0)
33143 return 0;
33144
33145 - return atomic_read(&dev_priv->vbl_received);
33146 + return atomic_read_unchecked(&dev_priv->vbl_received);
33147 }
33148
33149
33150 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33151 /* VBLANK interrupt */
33152 if (status & MGA_VLINEPEN) {
33153 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33154 - atomic_inc(&dev_priv->vbl_received);
33155 + atomic_inc_unchecked(&dev_priv->vbl_received);
33156 drm_handle_vblank(dev, 0);
33157 handled = 1;
33158 }
33159 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33160 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33161 MGA_WRITE(MGA_PRIMEND, prim_end);
33162
33163 - atomic_inc(&dev_priv->last_fence_retired);
33164 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
33165 DRM_WAKEUP(&dev_priv->fence_queue);
33166 handled = 1;
33167 }
33168 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33169 * using fences.
33170 */
33171 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33172 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33173 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33174 - *sequence) <= (1 << 23)));
33175
33176 *sequence = cur_fence;
33177 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33178 index 09fdef2..57f5c3b 100644
33179 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33180 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33181 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33182 struct bit_table {
33183 const char id;
33184 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33185 -};
33186 +} __no_const;
33187
33188 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33189
33190 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33191 index a101699..a163f0a 100644
33192 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33193 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33194 @@ -80,7 +80,7 @@ struct nouveau_drm {
33195 struct drm_global_reference mem_global_ref;
33196 struct ttm_bo_global_ref bo_global_ref;
33197 struct ttm_bo_device bdev;
33198 - atomic_t validate_sequence;
33199 + atomic_unchecked_t validate_sequence;
33200 int (*move)(struct nouveau_channel *,
33201 struct ttm_buffer_object *,
33202 struct ttm_mem_reg *, struct ttm_mem_reg *);
33203 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33204 index cdb83ac..27f0a16 100644
33205 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33206 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33207 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33208 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33209 struct nouveau_channel *);
33210 u32 (*read)(struct nouveau_channel *);
33211 -};
33212 +} __no_const;
33213
33214 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
33215
33216 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
33217 index 5e2f521..0d21436 100644
33218 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
33219 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
33220 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
33221 int trycnt = 0;
33222 int ret, i;
33223
33224 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
33225 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
33226 retry:
33227 if (++trycnt > 100000) {
33228 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
33229 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
33230 index 6f0ac64..9c2dfb4 100644
33231 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
33232 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
33233 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
33234 bool can_switch;
33235
33236 spin_lock(&dev->count_lock);
33237 - can_switch = (dev->open_count == 0);
33238 + can_switch = (local_read(&dev->open_count) == 0);
33239 spin_unlock(&dev->count_lock);
33240 return can_switch;
33241 }
33242 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
33243 index 9f6f55c..30e3a29 100644
33244 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
33245 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
33246 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
33247 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
33248 evo->object->oclass->ofuncs =
33249 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
33250 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33251 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33252 - evo->object->oclass->ofuncs->rd08 =
33253 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33254 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33255 + *(void**)&evo->object->oclass->ofuncs->rd08 =
33256 ioremap(pci_resource_start(dev->pdev, 0) +
33257 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
33258 return 0;
33259 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
33260 index b562b59..9d725a8 100644
33261 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
33262 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
33263 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
33264 }
33265
33266 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33267 - struct dp_train_func func = {
33268 + static struct dp_train_func func = {
33269 .link_set = nv50_sor_dp_link_set,
33270 .train_set = nv50_sor_dp_train_set,
33271 .train_adj = nv50_sor_dp_train_adj
33272 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
33273 index c402fca..f1d694b 100644
33274 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
33275 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
33276 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
33277 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
33278
33279 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33280 - struct dp_train_func func = {
33281 + static struct dp_train_func func = {
33282 .link_set = nvd0_sor_dp_link_set,
33283 .train_set = nvd0_sor_dp_train_set,
33284 .train_adj = nvd0_sor_dp_train_adj
33285 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33286 index d4660cf..70dbe65 100644
33287 --- a/drivers/gpu/drm/r128/r128_cce.c
33288 +++ b/drivers/gpu/drm/r128/r128_cce.c
33289 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
33290
33291 /* GH: Simple idle check.
33292 */
33293 - atomic_set(&dev_priv->idle_count, 0);
33294 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33295
33296 /* We don't support anything other than bus-mastering ring mode,
33297 * but the ring can be in either AGP or PCI space for the ring
33298 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33299 index 930c71b..499aded 100644
33300 --- a/drivers/gpu/drm/r128/r128_drv.h
33301 +++ b/drivers/gpu/drm/r128/r128_drv.h
33302 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33303 int is_pci;
33304 unsigned long cce_buffers_offset;
33305
33306 - atomic_t idle_count;
33307 + atomic_unchecked_t idle_count;
33308
33309 int page_flipping;
33310 int current_page;
33311 u32 crtc_offset;
33312 u32 crtc_offset_cntl;
33313
33314 - atomic_t vbl_received;
33315 + atomic_unchecked_t vbl_received;
33316
33317 u32 color_fmt;
33318 unsigned int front_offset;
33319 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33320 index 2ea4f09..d391371 100644
33321 --- a/drivers/gpu/drm/r128/r128_irq.c
33322 +++ b/drivers/gpu/drm/r128/r128_irq.c
33323 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33324 if (crtc != 0)
33325 return 0;
33326
33327 - return atomic_read(&dev_priv->vbl_received);
33328 + return atomic_read_unchecked(&dev_priv->vbl_received);
33329 }
33330
33331 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33332 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33333 /* VBLANK interrupt */
33334 if (status & R128_CRTC_VBLANK_INT) {
33335 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33336 - atomic_inc(&dev_priv->vbl_received);
33337 + atomic_inc_unchecked(&dev_priv->vbl_received);
33338 drm_handle_vblank(dev, 0);
33339 return IRQ_HANDLED;
33340 }
33341 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33342 index 19bb7e6..de7e2a2 100644
33343 --- a/drivers/gpu/drm/r128/r128_state.c
33344 +++ b/drivers/gpu/drm/r128/r128_state.c
33345 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
33346
33347 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
33348 {
33349 - if (atomic_read(&dev_priv->idle_count) == 0)
33350 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
33351 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33352 else
33353 - atomic_set(&dev_priv->idle_count, 0);
33354 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33355 }
33356
33357 #endif
33358 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33359 index 5a82b6b..9e69c73 100644
33360 --- a/drivers/gpu/drm/radeon/mkregtable.c
33361 +++ b/drivers/gpu/drm/radeon/mkregtable.c
33362 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33363 regex_t mask_rex;
33364 regmatch_t match[4];
33365 char buf[1024];
33366 - size_t end;
33367 + long end;
33368 int len;
33369 int done = 0;
33370 int r;
33371 unsigned o;
33372 struct offset *offset;
33373 char last_reg_s[10];
33374 - int last_reg;
33375 + unsigned long last_reg;
33376
33377 if (regcomp
33378 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33379 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
33380 index 008d645..de03849 100644
33381 --- a/drivers/gpu/drm/radeon/radeon_device.c
33382 +++ b/drivers/gpu/drm/radeon/radeon_device.c
33383 @@ -941,7 +941,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
33384 bool can_switch;
33385
33386 spin_lock(&dev->count_lock);
33387 - can_switch = (dev->open_count == 0);
33388 + can_switch = (local_read(&dev->open_count) == 0);
33389 spin_unlock(&dev->count_lock);
33390 return can_switch;
33391 }
33392 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33393 index a1b59ca..86f2d44 100644
33394 --- a/drivers/gpu/drm/radeon/radeon_drv.h
33395 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
33396 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
33397
33398 /* SW interrupt */
33399 wait_queue_head_t swi_queue;
33400 - atomic_t swi_emitted;
33401 + atomic_unchecked_t swi_emitted;
33402 int vblank_crtc;
33403 uint32_t irq_enable_reg;
33404 uint32_t r500_disp_irq_reg;
33405 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33406 index c180df8..cd80dd2d 100644
33407 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33408 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33409 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33410 request = compat_alloc_user_space(sizeof(*request));
33411 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33412 || __put_user(req32.param, &request->param)
33413 - || __put_user((void __user *)(unsigned long)req32.value,
33414 + || __put_user((unsigned long)req32.value,
33415 &request->value))
33416 return -EFAULT;
33417
33418 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33419 index e771033..a0bc6b3 100644
33420 --- a/drivers/gpu/drm/radeon/radeon_irq.c
33421 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
33422 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33423 unsigned int ret;
33424 RING_LOCALS;
33425
33426 - atomic_inc(&dev_priv->swi_emitted);
33427 - ret = atomic_read(&dev_priv->swi_emitted);
33428 + atomic_inc_unchecked(&dev_priv->swi_emitted);
33429 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33430
33431 BEGIN_RING(4);
33432 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33433 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33434 drm_radeon_private_t *dev_priv =
33435 (drm_radeon_private_t *) dev->dev_private;
33436
33437 - atomic_set(&dev_priv->swi_emitted, 0);
33438 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33439 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33440
33441 dev->max_vblank_count = 0x001fffff;
33442 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33443 index 8e9057b..af6dacb 100644
33444 --- a/drivers/gpu/drm/radeon/radeon_state.c
33445 +++ b/drivers/gpu/drm/radeon/radeon_state.c
33446 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33447 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33448 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33449
33450 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33451 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33452 sarea_priv->nbox * sizeof(depth_boxes[0])))
33453 return -EFAULT;
33454
33455 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33456 {
33457 drm_radeon_private_t *dev_priv = dev->dev_private;
33458 drm_radeon_getparam_t *param = data;
33459 - int value;
33460 + int value = 0;
33461
33462 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33463
33464 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33465 index 5ebe1b3..1ed9426 100644
33466 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
33467 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33468 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33469 }
33470 if (unlikely(ttm_vm_ops == NULL)) {
33471 ttm_vm_ops = vma->vm_ops;
33472 - radeon_ttm_vm_ops = *ttm_vm_ops;
33473 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33474 + pax_open_kernel();
33475 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
33476 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33477 + pax_close_kernel();
33478 }
33479 vma->vm_ops = &radeon_ttm_vm_ops;
33480 return 0;
33481 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33482 index 5706d2a..17aedaa 100644
33483 --- a/drivers/gpu/drm/radeon/rs690.c
33484 +++ b/drivers/gpu/drm/radeon/rs690.c
33485 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33486 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33487 rdev->pm.sideport_bandwidth.full)
33488 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33489 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33490 + read_delay_latency.full = dfixed_const(800 * 1000);
33491 read_delay_latency.full = dfixed_div(read_delay_latency,
33492 rdev->pm.igp_sideport_mclk);
33493 + a.full = dfixed_const(370);
33494 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33495 } else {
33496 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33497 rdev->pm.k8_bandwidth.full)
33498 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33499 index bd2a3b4..122d9ad 100644
33500 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33501 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33502 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33503 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33504 struct shrink_control *sc)
33505 {
33506 - static atomic_t start_pool = ATOMIC_INIT(0);
33507 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33508 unsigned i;
33509 - unsigned pool_offset = atomic_add_return(1, &start_pool);
33510 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33511 struct ttm_page_pool *pool;
33512 int shrink_pages = sc->nr_to_scan;
33513
33514 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33515 index 893a650..6190d3b 100644
33516 --- a/drivers/gpu/drm/via/via_drv.h
33517 +++ b/drivers/gpu/drm/via/via_drv.h
33518 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33519 typedef uint32_t maskarray_t[5];
33520
33521 typedef struct drm_via_irq {
33522 - atomic_t irq_received;
33523 + atomic_unchecked_t irq_received;
33524 uint32_t pending_mask;
33525 uint32_t enable_mask;
33526 wait_queue_head_t irq_queue;
33527 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
33528 struct timeval last_vblank;
33529 int last_vblank_valid;
33530 unsigned usec_per_vblank;
33531 - atomic_t vbl_received;
33532 + atomic_unchecked_t vbl_received;
33533 drm_via_state_t hc_state;
33534 char pci_buf[VIA_PCI_BUF_SIZE];
33535 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33536 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33537 index ac98964..5dbf512 100644
33538 --- a/drivers/gpu/drm/via/via_irq.c
33539 +++ b/drivers/gpu/drm/via/via_irq.c
33540 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33541 if (crtc != 0)
33542 return 0;
33543
33544 - return atomic_read(&dev_priv->vbl_received);
33545 + return atomic_read_unchecked(&dev_priv->vbl_received);
33546 }
33547
33548 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33549 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33550
33551 status = VIA_READ(VIA_REG_INTERRUPT);
33552 if (status & VIA_IRQ_VBLANK_PENDING) {
33553 - atomic_inc(&dev_priv->vbl_received);
33554 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33555 + atomic_inc_unchecked(&dev_priv->vbl_received);
33556 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33557 do_gettimeofday(&cur_vblank);
33558 if (dev_priv->last_vblank_valid) {
33559 dev_priv->usec_per_vblank =
33560 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33561 dev_priv->last_vblank = cur_vblank;
33562 dev_priv->last_vblank_valid = 1;
33563 }
33564 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33565 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33566 DRM_DEBUG("US per vblank is: %u\n",
33567 dev_priv->usec_per_vblank);
33568 }
33569 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33570
33571 for (i = 0; i < dev_priv->num_irqs; ++i) {
33572 if (status & cur_irq->pending_mask) {
33573 - atomic_inc(&cur_irq->irq_received);
33574 + atomic_inc_unchecked(&cur_irq->irq_received);
33575 DRM_WAKEUP(&cur_irq->irq_queue);
33576 handled = 1;
33577 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33578 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33579 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33580 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33581 masks[irq][4]));
33582 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33583 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33584 } else {
33585 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33586 (((cur_irq_sequence =
33587 - atomic_read(&cur_irq->irq_received)) -
33588 + atomic_read_unchecked(&cur_irq->irq_received)) -
33589 *sequence) <= (1 << 23)));
33590 }
33591 *sequence = cur_irq_sequence;
33592 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33593 }
33594
33595 for (i = 0; i < dev_priv->num_irqs; ++i) {
33596 - atomic_set(&cur_irq->irq_received, 0);
33597 + atomic_set_unchecked(&cur_irq->irq_received, 0);
33598 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33599 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33600 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33601 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33602 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33603 case VIA_IRQ_RELATIVE:
33604 irqwait->request.sequence +=
33605 - atomic_read(&cur_irq->irq_received);
33606 + atomic_read_unchecked(&cur_irq->irq_received);
33607 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33608 case VIA_IRQ_ABSOLUTE:
33609 break;
33610 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33611 index 88a179e..57fe50481c 100644
33612 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33613 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33614 @@ -263,7 +263,7 @@ struct vmw_private {
33615 * Fencing and IRQs.
33616 */
33617
33618 - atomic_t marker_seq;
33619 + atomic_unchecked_t marker_seq;
33620 wait_queue_head_t fence_queue;
33621 wait_queue_head_t fifo_queue;
33622 int fence_queue_waiters; /* Protected by hw_mutex */
33623 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33624 index 3eb1486..0a47ee9 100644
33625 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33626 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33627 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33628 (unsigned int) min,
33629 (unsigned int) fifo->capabilities);
33630
33631 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33632 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33633 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33634 vmw_marker_queue_init(&fifo->marker_queue);
33635 return vmw_fifo_send_fence(dev_priv, &dummy);
33636 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33637 if (reserveable)
33638 iowrite32(bytes, fifo_mem +
33639 SVGA_FIFO_RESERVED);
33640 - return fifo_mem + (next_cmd >> 2);
33641 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33642 } else {
33643 need_bounce = true;
33644 }
33645 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33646
33647 fm = vmw_fifo_reserve(dev_priv, bytes);
33648 if (unlikely(fm == NULL)) {
33649 - *seqno = atomic_read(&dev_priv->marker_seq);
33650 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33651 ret = -ENOMEM;
33652 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33653 false, 3*HZ);
33654 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33655 }
33656
33657 do {
33658 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33659 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33660 } while (*seqno == 0);
33661
33662 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33663 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33664 index 4640adb..e1384ed 100644
33665 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33666 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33667 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33668 * emitted. Then the fence is stale and signaled.
33669 */
33670
33671 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33672 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33673 > VMW_FENCE_WRAP);
33674
33675 return ret;
33676 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33677
33678 if (fifo_idle)
33679 down_read(&fifo_state->rwsem);
33680 - signal_seq = atomic_read(&dev_priv->marker_seq);
33681 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33682 ret = 0;
33683
33684 for (;;) {
33685 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33686 index 8a8725c..afed796 100644
33687 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33688 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33689 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33690 while (!vmw_lag_lt(queue, us)) {
33691 spin_lock(&queue->lock);
33692 if (list_empty(&queue->head))
33693 - seqno = atomic_read(&dev_priv->marker_seq);
33694 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33695 else {
33696 marker = list_first_entry(&queue->head,
33697 struct vmw_marker, head);
33698 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33699 index 52146db..ae33762 100644
33700 --- a/drivers/hid/hid-core.c
33701 +++ b/drivers/hid/hid-core.c
33702 @@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33703
33704 int hid_add_device(struct hid_device *hdev)
33705 {
33706 - static atomic_t id = ATOMIC_INIT(0);
33707 + static atomic_unchecked_t id = ATOMIC_INIT(0);
33708 int ret;
33709
33710 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33711 @@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33712 /* XXX hack, any other cleaner solution after the driver core
33713 * is converted to allow more than 20 bytes as the device name? */
33714 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33715 - hdev->vendor, hdev->product, atomic_inc_return(&id));
33716 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33717
33718 hid_debug_register(hdev, dev_name(&hdev->dev));
33719 ret = device_add(&hdev->dev);
33720 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33721 index eec3291..8ed706b 100644
33722 --- a/drivers/hid/hid-wiimote-debug.c
33723 +++ b/drivers/hid/hid-wiimote-debug.c
33724 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33725 else if (size == 0)
33726 return -EIO;
33727
33728 - if (copy_to_user(u, buf, size))
33729 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
33730 return -EFAULT;
33731
33732 *off += size;
33733 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33734 index 14599e2..711c965 100644
33735 --- a/drivers/hid/usbhid/hiddev.c
33736 +++ b/drivers/hid/usbhid/hiddev.c
33737 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33738 break;
33739
33740 case HIDIOCAPPLICATION:
33741 - if (arg < 0 || arg >= hid->maxapplication)
33742 + if (arg >= hid->maxapplication)
33743 break;
33744
33745 for (i = 0; i < hid->maxcollection; i++)
33746 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33747 index f4c3d28..82f45a9 100644
33748 --- a/drivers/hv/channel.c
33749 +++ b/drivers/hv/channel.c
33750 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33751 int ret = 0;
33752 int t;
33753
33754 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33755 - atomic_inc(&vmbus_connection.next_gpadl_handle);
33756 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33757 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33758
33759 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33760 if (ret)
33761 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33762 index 3648f8f..30ef30d 100644
33763 --- a/drivers/hv/hv.c
33764 +++ b/drivers/hv/hv.c
33765 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33766 u64 output_address = (output) ? virt_to_phys(output) : 0;
33767 u32 output_address_hi = output_address >> 32;
33768 u32 output_address_lo = output_address & 0xFFFFFFFF;
33769 - void *hypercall_page = hv_context.hypercall_page;
33770 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33771
33772 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33773 "=a"(hv_status_lo) : "d" (control_hi),
33774 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33775 index d8d1fad..b91caf7 100644
33776 --- a/drivers/hv/hyperv_vmbus.h
33777 +++ b/drivers/hv/hyperv_vmbus.h
33778 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
33779 struct vmbus_connection {
33780 enum vmbus_connect_state conn_state;
33781
33782 - atomic_t next_gpadl_handle;
33783 + atomic_unchecked_t next_gpadl_handle;
33784
33785 /*
33786 * Represents channel interrupts. Each bit position represents a
33787 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33788 index 8e1a9ec..4687821 100644
33789 --- a/drivers/hv/vmbus_drv.c
33790 +++ b/drivers/hv/vmbus_drv.c
33791 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33792 {
33793 int ret = 0;
33794
33795 - static atomic_t device_num = ATOMIC_INIT(0);
33796 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33797
33798 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33799 - atomic_inc_return(&device_num));
33800 + atomic_inc_return_unchecked(&device_num));
33801
33802 child_device_obj->device.bus = &hv_bus;
33803 child_device_obj->device.parent = &hv_acpi_dev->dev;
33804 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33805 index 07a0c1a..0cac334 100644
33806 --- a/drivers/hwmon/sht15.c
33807 +++ b/drivers/hwmon/sht15.c
33808 @@ -169,7 +169,7 @@ struct sht15_data {
33809 int supply_uV;
33810 bool supply_uV_valid;
33811 struct work_struct update_supply_work;
33812 - atomic_t interrupt_handled;
33813 + atomic_unchecked_t interrupt_handled;
33814 };
33815
33816 /**
33817 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33818 return ret;
33819
33820 gpio_direction_input(data->pdata->gpio_data);
33821 - atomic_set(&data->interrupt_handled, 0);
33822 + atomic_set_unchecked(&data->interrupt_handled, 0);
33823
33824 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33825 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33826 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33827 /* Only relevant if the interrupt hasn't occurred. */
33828 - if (!atomic_read(&data->interrupt_handled))
33829 + if (!atomic_read_unchecked(&data->interrupt_handled))
33830 schedule_work(&data->read_work);
33831 }
33832 ret = wait_event_timeout(data->wait_queue,
33833 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33834
33835 /* First disable the interrupt */
33836 disable_irq_nosync(irq);
33837 - atomic_inc(&data->interrupt_handled);
33838 + atomic_inc_unchecked(&data->interrupt_handled);
33839 /* Then schedule a reading work struct */
33840 if (data->state != SHT15_READING_NOTHING)
33841 schedule_work(&data->read_work);
33842 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33843 * If not, then start the interrupt again - care here as could
33844 * have gone low in meantime so verify it hasn't!
33845 */
33846 - atomic_set(&data->interrupt_handled, 0);
33847 + atomic_set_unchecked(&data->interrupt_handled, 0);
33848 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33849 /* If still not occurred or another handler was scheduled */
33850 if (gpio_get_value(data->pdata->gpio_data)
33851 - || atomic_read(&data->interrupt_handled))
33852 + || atomic_read_unchecked(&data->interrupt_handled))
33853 return;
33854 }
33855
33856 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33857 index 378fcb5..5e91fa8 100644
33858 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
33859 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33860 @@ -43,7 +43,7 @@
33861 extern struct i2c_adapter amd756_smbus;
33862
33863 static struct i2c_adapter *s4882_adapter;
33864 -static struct i2c_algorithm *s4882_algo;
33865 +static i2c_algorithm_no_const *s4882_algo;
33866
33867 /* Wrapper access functions for multiplexed SMBus */
33868 static DEFINE_MUTEX(amd756_lock);
33869 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33870 index 29015eb..af2d8e9 100644
33871 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33872 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33873 @@ -41,7 +41,7 @@
33874 extern struct i2c_adapter *nforce2_smbus;
33875
33876 static struct i2c_adapter *s4985_adapter;
33877 -static struct i2c_algorithm *s4985_algo;
33878 +static i2c_algorithm_no_const *s4985_algo;
33879
33880 /* Wrapper access functions for multiplexed SMBus */
33881 static DEFINE_MUTEX(nforce2_lock);
33882 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33883 index 8126824..55a2798 100644
33884 --- a/drivers/ide/ide-cd.c
33885 +++ b/drivers/ide/ide-cd.c
33886 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33887 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33888 if ((unsigned long)buf & alignment
33889 || blk_rq_bytes(rq) & q->dma_pad_mask
33890 - || object_is_on_stack(buf))
33891 + || object_starts_on_stack(buf))
33892 drive->dma = 0;
33893 }
33894 }
33895 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33896 index 394fea2..c833880 100644
33897 --- a/drivers/infiniband/core/cm.c
33898 +++ b/drivers/infiniband/core/cm.c
33899 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33900
33901 struct cm_counter_group {
33902 struct kobject obj;
33903 - atomic_long_t counter[CM_ATTR_COUNT];
33904 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33905 };
33906
33907 struct cm_counter_attribute {
33908 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33909 struct ib_mad_send_buf *msg = NULL;
33910 int ret;
33911
33912 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33913 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33914 counter[CM_REQ_COUNTER]);
33915
33916 /* Quick state check to discard duplicate REQs. */
33917 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33918 if (!cm_id_priv)
33919 return;
33920
33921 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33922 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33923 counter[CM_REP_COUNTER]);
33924 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33925 if (ret)
33926 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33927 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33928 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33929 spin_unlock_irq(&cm_id_priv->lock);
33930 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33931 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33932 counter[CM_RTU_COUNTER]);
33933 goto out;
33934 }
33935 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33936 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33937 dreq_msg->local_comm_id);
33938 if (!cm_id_priv) {
33939 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33940 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33941 counter[CM_DREQ_COUNTER]);
33942 cm_issue_drep(work->port, work->mad_recv_wc);
33943 return -EINVAL;
33944 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33945 case IB_CM_MRA_REP_RCVD:
33946 break;
33947 case IB_CM_TIMEWAIT:
33948 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33949 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33950 counter[CM_DREQ_COUNTER]);
33951 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33952 goto unlock;
33953 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33954 cm_free_msg(msg);
33955 goto deref;
33956 case IB_CM_DREQ_RCVD:
33957 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33958 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33959 counter[CM_DREQ_COUNTER]);
33960 goto unlock;
33961 default:
33962 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33963 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33964 cm_id_priv->msg, timeout)) {
33965 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33966 - atomic_long_inc(&work->port->
33967 + atomic_long_inc_unchecked(&work->port->
33968 counter_group[CM_RECV_DUPLICATES].
33969 counter[CM_MRA_COUNTER]);
33970 goto out;
33971 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33972 break;
33973 case IB_CM_MRA_REQ_RCVD:
33974 case IB_CM_MRA_REP_RCVD:
33975 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33976 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33977 counter[CM_MRA_COUNTER]);
33978 /* fall through */
33979 default:
33980 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33981 case IB_CM_LAP_IDLE:
33982 break;
33983 case IB_CM_MRA_LAP_SENT:
33984 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33985 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33986 counter[CM_LAP_COUNTER]);
33987 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33988 goto unlock;
33989 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33990 cm_free_msg(msg);
33991 goto deref;
33992 case IB_CM_LAP_RCVD:
33993 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33994 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33995 counter[CM_LAP_COUNTER]);
33996 goto unlock;
33997 default:
33998 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33999 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34000 if (cur_cm_id_priv) {
34001 spin_unlock_irq(&cm.lock);
34002 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34003 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34004 counter[CM_SIDR_REQ_COUNTER]);
34005 goto out; /* Duplicate message. */
34006 }
34007 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34008 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34009 msg->retries = 1;
34010
34011 - atomic_long_add(1 + msg->retries,
34012 + atomic_long_add_unchecked(1 + msg->retries,
34013 &port->counter_group[CM_XMIT].counter[attr_index]);
34014 if (msg->retries)
34015 - atomic_long_add(msg->retries,
34016 + atomic_long_add_unchecked(msg->retries,
34017 &port->counter_group[CM_XMIT_RETRIES].
34018 counter[attr_index]);
34019
34020 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34021 }
34022
34023 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34024 - atomic_long_inc(&port->counter_group[CM_RECV].
34025 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34026 counter[attr_id - CM_ATTR_ID_OFFSET]);
34027
34028 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34029 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34030 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34031
34032 return sprintf(buf, "%ld\n",
34033 - atomic_long_read(&group->counter[cm_attr->index]));
34034 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34035 }
34036
34037 static const struct sysfs_ops cm_counter_ops = {
34038 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34039 index 176c8f9..2627b62 100644
34040 --- a/drivers/infiniband/core/fmr_pool.c
34041 +++ b/drivers/infiniband/core/fmr_pool.c
34042 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
34043
34044 struct task_struct *thread;
34045
34046 - atomic_t req_ser;
34047 - atomic_t flush_ser;
34048 + atomic_unchecked_t req_ser;
34049 + atomic_unchecked_t flush_ser;
34050
34051 wait_queue_head_t force_wait;
34052 };
34053 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34054 struct ib_fmr_pool *pool = pool_ptr;
34055
34056 do {
34057 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34058 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34059 ib_fmr_batch_release(pool);
34060
34061 - atomic_inc(&pool->flush_ser);
34062 + atomic_inc_unchecked(&pool->flush_ser);
34063 wake_up_interruptible(&pool->force_wait);
34064
34065 if (pool->flush_function)
34066 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34067 }
34068
34069 set_current_state(TASK_INTERRUPTIBLE);
34070 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34071 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34072 !kthread_should_stop())
34073 schedule();
34074 __set_current_state(TASK_RUNNING);
34075 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34076 pool->dirty_watermark = params->dirty_watermark;
34077 pool->dirty_len = 0;
34078 spin_lock_init(&pool->pool_lock);
34079 - atomic_set(&pool->req_ser, 0);
34080 - atomic_set(&pool->flush_ser, 0);
34081 + atomic_set_unchecked(&pool->req_ser, 0);
34082 + atomic_set_unchecked(&pool->flush_ser, 0);
34083 init_waitqueue_head(&pool->force_wait);
34084
34085 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34086 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34087 }
34088 spin_unlock_irq(&pool->pool_lock);
34089
34090 - serial = atomic_inc_return(&pool->req_ser);
34091 + serial = atomic_inc_return_unchecked(&pool->req_ser);
34092 wake_up_process(pool->thread);
34093
34094 if (wait_event_interruptible(pool->force_wait,
34095 - atomic_read(&pool->flush_ser) - serial >= 0))
34096 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34097 return -EINTR;
34098
34099 return 0;
34100 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34101 } else {
34102 list_add_tail(&fmr->list, &pool->dirty_list);
34103 if (++pool->dirty_len >= pool->dirty_watermark) {
34104 - atomic_inc(&pool->req_ser);
34105 + atomic_inc_unchecked(&pool->req_ser);
34106 wake_up_process(pool->thread);
34107 }
34108 }
34109 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34110 index afd8179..598063f 100644
34111 --- a/drivers/infiniband/hw/cxgb4/mem.c
34112 +++ b/drivers/infiniband/hw/cxgb4/mem.c
34113 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34114 int err;
34115 struct fw_ri_tpte tpt;
34116 u32 stag_idx;
34117 - static atomic_t key;
34118 + static atomic_unchecked_t key;
34119
34120 if (c4iw_fatal_error(rdev))
34121 return -EIO;
34122 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34123 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34124 rdev->stats.stag.max = rdev->stats.stag.cur;
34125 mutex_unlock(&rdev->stats.lock);
34126 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34127 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34128 }
34129 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34130 __func__, stag_state, type, pdid, stag_idx);
34131 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34132 index 79b3dbc..96e5fcc 100644
34133 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
34134 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34135 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34136 struct ib_atomic_eth *ateth;
34137 struct ipath_ack_entry *e;
34138 u64 vaddr;
34139 - atomic64_t *maddr;
34140 + atomic64_unchecked_t *maddr;
34141 u64 sdata;
34142 u32 rkey;
34143 u8 next;
34144 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34145 IB_ACCESS_REMOTE_ATOMIC)))
34146 goto nack_acc_unlck;
34147 /* Perform atomic OP and save result. */
34148 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34149 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34150 sdata = be64_to_cpu(ateth->swap_data);
34151 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34152 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34153 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34154 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34155 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34156 be64_to_cpu(ateth->compare_data),
34157 sdata);
34158 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34159 index 1f95bba..9530f87 100644
34160 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34161 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34162 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34163 unsigned long flags;
34164 struct ib_wc wc;
34165 u64 sdata;
34166 - atomic64_t *maddr;
34167 + atomic64_unchecked_t *maddr;
34168 enum ib_wc_status send_status;
34169
34170 /*
34171 @@ -382,11 +382,11 @@ again:
34172 IB_ACCESS_REMOTE_ATOMIC)))
34173 goto acc_err;
34174 /* Perform atomic OP and save result. */
34175 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34176 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34177 sdata = wqe->wr.wr.atomic.compare_add;
34178 *(u64 *) sqp->s_sge.sge.vaddr =
34179 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34180 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34181 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34182 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34183 sdata, wqe->wr.wr.atomic.swap);
34184 goto send_comp;
34185 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34186 index 748db2d..5f75cc3 100644
34187 --- a/drivers/infiniband/hw/nes/nes.c
34188 +++ b/drivers/infiniband/hw/nes/nes.c
34189 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34190 LIST_HEAD(nes_adapter_list);
34191 static LIST_HEAD(nes_dev_list);
34192
34193 -atomic_t qps_destroyed;
34194 +atomic_unchecked_t qps_destroyed;
34195
34196 static unsigned int ee_flsh_adapter;
34197 static unsigned int sysfs_nonidx_addr;
34198 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34199 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34200 struct nes_adapter *nesadapter = nesdev->nesadapter;
34201
34202 - atomic_inc(&qps_destroyed);
34203 + atomic_inc_unchecked(&qps_destroyed);
34204
34205 /* Free the control structures */
34206
34207 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34208 index 33cc589..3bd6538 100644
34209 --- a/drivers/infiniband/hw/nes/nes.h
34210 +++ b/drivers/infiniband/hw/nes/nes.h
34211 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34212 extern unsigned int wqm_quanta;
34213 extern struct list_head nes_adapter_list;
34214
34215 -extern atomic_t cm_connects;
34216 -extern atomic_t cm_accepts;
34217 -extern atomic_t cm_disconnects;
34218 -extern atomic_t cm_closes;
34219 -extern atomic_t cm_connecteds;
34220 -extern atomic_t cm_connect_reqs;
34221 -extern atomic_t cm_rejects;
34222 -extern atomic_t mod_qp_timouts;
34223 -extern atomic_t qps_created;
34224 -extern atomic_t qps_destroyed;
34225 -extern atomic_t sw_qps_destroyed;
34226 +extern atomic_unchecked_t cm_connects;
34227 +extern atomic_unchecked_t cm_accepts;
34228 +extern atomic_unchecked_t cm_disconnects;
34229 +extern atomic_unchecked_t cm_closes;
34230 +extern atomic_unchecked_t cm_connecteds;
34231 +extern atomic_unchecked_t cm_connect_reqs;
34232 +extern atomic_unchecked_t cm_rejects;
34233 +extern atomic_unchecked_t mod_qp_timouts;
34234 +extern atomic_unchecked_t qps_created;
34235 +extern atomic_unchecked_t qps_destroyed;
34236 +extern atomic_unchecked_t sw_qps_destroyed;
34237 extern u32 mh_detected;
34238 extern u32 mh_pauses_sent;
34239 extern u32 cm_packets_sent;
34240 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
34241 extern u32 cm_packets_received;
34242 extern u32 cm_packets_dropped;
34243 extern u32 cm_packets_retrans;
34244 -extern atomic_t cm_listens_created;
34245 -extern atomic_t cm_listens_destroyed;
34246 +extern atomic_unchecked_t cm_listens_created;
34247 +extern atomic_unchecked_t cm_listens_destroyed;
34248 extern u32 cm_backlog_drops;
34249 -extern atomic_t cm_loopbacks;
34250 -extern atomic_t cm_nodes_created;
34251 -extern atomic_t cm_nodes_destroyed;
34252 -extern atomic_t cm_accel_dropped_pkts;
34253 -extern atomic_t cm_resets_recvd;
34254 -extern atomic_t pau_qps_created;
34255 -extern atomic_t pau_qps_destroyed;
34256 +extern atomic_unchecked_t cm_loopbacks;
34257 +extern atomic_unchecked_t cm_nodes_created;
34258 +extern atomic_unchecked_t cm_nodes_destroyed;
34259 +extern atomic_unchecked_t cm_accel_dropped_pkts;
34260 +extern atomic_unchecked_t cm_resets_recvd;
34261 +extern atomic_unchecked_t pau_qps_created;
34262 +extern atomic_unchecked_t pau_qps_destroyed;
34263
34264 extern u32 int_mod_timer_init;
34265 extern u32 int_mod_cq_depth_256;
34266 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34267 index cfaacaf..fa0722e 100644
34268 --- a/drivers/infiniband/hw/nes/nes_cm.c
34269 +++ b/drivers/infiniband/hw/nes/nes_cm.c
34270 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
34271 u32 cm_packets_retrans;
34272 u32 cm_packets_created;
34273 u32 cm_packets_received;
34274 -atomic_t cm_listens_created;
34275 -atomic_t cm_listens_destroyed;
34276 +atomic_unchecked_t cm_listens_created;
34277 +atomic_unchecked_t cm_listens_destroyed;
34278 u32 cm_backlog_drops;
34279 -atomic_t cm_loopbacks;
34280 -atomic_t cm_nodes_created;
34281 -atomic_t cm_nodes_destroyed;
34282 -atomic_t cm_accel_dropped_pkts;
34283 -atomic_t cm_resets_recvd;
34284 +atomic_unchecked_t cm_loopbacks;
34285 +atomic_unchecked_t cm_nodes_created;
34286 +atomic_unchecked_t cm_nodes_destroyed;
34287 +atomic_unchecked_t cm_accel_dropped_pkts;
34288 +atomic_unchecked_t cm_resets_recvd;
34289
34290 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
34291 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
34292 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
34293
34294 static struct nes_cm_core *g_cm_core;
34295
34296 -atomic_t cm_connects;
34297 -atomic_t cm_accepts;
34298 -atomic_t cm_disconnects;
34299 -atomic_t cm_closes;
34300 -atomic_t cm_connecteds;
34301 -atomic_t cm_connect_reqs;
34302 -atomic_t cm_rejects;
34303 +atomic_unchecked_t cm_connects;
34304 +atomic_unchecked_t cm_accepts;
34305 +atomic_unchecked_t cm_disconnects;
34306 +atomic_unchecked_t cm_closes;
34307 +atomic_unchecked_t cm_connecteds;
34308 +atomic_unchecked_t cm_connect_reqs;
34309 +atomic_unchecked_t cm_rejects;
34310
34311 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
34312 {
34313 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
34314 kfree(listener);
34315 listener = NULL;
34316 ret = 0;
34317 - atomic_inc(&cm_listens_destroyed);
34318 + atomic_inc_unchecked(&cm_listens_destroyed);
34319 } else {
34320 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
34321 }
34322 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34323 cm_node->rem_mac);
34324
34325 add_hte_node(cm_core, cm_node);
34326 - atomic_inc(&cm_nodes_created);
34327 + atomic_inc_unchecked(&cm_nodes_created);
34328
34329 return cm_node;
34330 }
34331 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34332 }
34333
34334 atomic_dec(&cm_core->node_cnt);
34335 - atomic_inc(&cm_nodes_destroyed);
34336 + atomic_inc_unchecked(&cm_nodes_destroyed);
34337 nesqp = cm_node->nesqp;
34338 if (nesqp) {
34339 nesqp->cm_node = NULL;
34340 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34341
34342 static void drop_packet(struct sk_buff *skb)
34343 {
34344 - atomic_inc(&cm_accel_dropped_pkts);
34345 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34346 dev_kfree_skb_any(skb);
34347 }
34348
34349 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34350 {
34351
34352 int reset = 0; /* whether to send reset in case of err.. */
34353 - atomic_inc(&cm_resets_recvd);
34354 + atomic_inc_unchecked(&cm_resets_recvd);
34355 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
34356 " refcnt=%d\n", cm_node, cm_node->state,
34357 atomic_read(&cm_node->ref_count));
34358 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
34359 rem_ref_cm_node(cm_node->cm_core, cm_node);
34360 return NULL;
34361 }
34362 - atomic_inc(&cm_loopbacks);
34363 + atomic_inc_unchecked(&cm_loopbacks);
34364 loopbackremotenode->loopbackpartner = cm_node;
34365 loopbackremotenode->tcp_cntxt.rcv_wscale =
34366 NES_CM_DEFAULT_RCV_WND_SCALE;
34367 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
34368 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
34369 else {
34370 rem_ref_cm_node(cm_core, cm_node);
34371 - atomic_inc(&cm_accel_dropped_pkts);
34372 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34373 dev_kfree_skb_any(skb);
34374 }
34375 break;
34376 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34377
34378 if ((cm_id) && (cm_id->event_handler)) {
34379 if (issue_disconn) {
34380 - atomic_inc(&cm_disconnects);
34381 + atomic_inc_unchecked(&cm_disconnects);
34382 cm_event.event = IW_CM_EVENT_DISCONNECT;
34383 cm_event.status = disconn_status;
34384 cm_event.local_addr = cm_id->local_addr;
34385 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34386 }
34387
34388 if (issue_close) {
34389 - atomic_inc(&cm_closes);
34390 + atomic_inc_unchecked(&cm_closes);
34391 nes_disconnect(nesqp, 1);
34392
34393 cm_id->provider_data = nesqp;
34394 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34395
34396 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
34397 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
34398 - atomic_inc(&cm_accepts);
34399 + atomic_inc_unchecked(&cm_accepts);
34400
34401 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
34402 netdev_refcnt_read(nesvnic->netdev));
34403 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
34404 struct nes_cm_core *cm_core;
34405 u8 *start_buff;
34406
34407 - atomic_inc(&cm_rejects);
34408 + atomic_inc_unchecked(&cm_rejects);
34409 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34410 loopback = cm_node->loopbackpartner;
34411 cm_core = cm_node->cm_core;
34412 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34413 ntohl(cm_id->local_addr.sin_addr.s_addr),
34414 ntohs(cm_id->local_addr.sin_port));
34415
34416 - atomic_inc(&cm_connects);
34417 + atomic_inc_unchecked(&cm_connects);
34418 nesqp->active_conn = 1;
34419
34420 /* cache the cm_id in the qp */
34421 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34422 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34423 return err;
34424 }
34425 - atomic_inc(&cm_listens_created);
34426 + atomic_inc_unchecked(&cm_listens_created);
34427 }
34428
34429 cm_id->add_ref(cm_id);
34430 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34431
34432 if (nesqp->destroyed)
34433 return;
34434 - atomic_inc(&cm_connecteds);
34435 + atomic_inc_unchecked(&cm_connecteds);
34436 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34437 " local port 0x%04X. jiffies = %lu.\n",
34438 nesqp->hwqp.qp_id,
34439 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34440
34441 cm_id->add_ref(cm_id);
34442 ret = cm_id->event_handler(cm_id, &cm_event);
34443 - atomic_inc(&cm_closes);
34444 + atomic_inc_unchecked(&cm_closes);
34445 cm_event.event = IW_CM_EVENT_CLOSE;
34446 cm_event.status = 0;
34447 cm_event.provider_data = cm_id->provider_data;
34448 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34449 return;
34450 cm_id = cm_node->cm_id;
34451
34452 - atomic_inc(&cm_connect_reqs);
34453 + atomic_inc_unchecked(&cm_connect_reqs);
34454 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34455 cm_node, cm_id, jiffies);
34456
34457 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34458 return;
34459 cm_id = cm_node->cm_id;
34460
34461 - atomic_inc(&cm_connect_reqs);
34462 + atomic_inc_unchecked(&cm_connect_reqs);
34463 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34464 cm_node, cm_id, jiffies);
34465
34466 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34467 index 3ba7be3..c81f6ff 100644
34468 --- a/drivers/infiniband/hw/nes/nes_mgt.c
34469 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
34470 @@ -40,8 +40,8 @@
34471 #include "nes.h"
34472 #include "nes_mgt.h"
34473
34474 -atomic_t pau_qps_created;
34475 -atomic_t pau_qps_destroyed;
34476 +atomic_unchecked_t pau_qps_created;
34477 +atomic_unchecked_t pau_qps_destroyed;
34478
34479 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34480 {
34481 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34482 {
34483 struct sk_buff *skb;
34484 unsigned long flags;
34485 - atomic_inc(&pau_qps_destroyed);
34486 + atomic_inc_unchecked(&pau_qps_destroyed);
34487
34488 /* Free packets that have not yet been forwarded */
34489 /* Lock is acquired by skb_dequeue when removing the skb */
34490 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34491 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34492 skb_queue_head_init(&nesqp->pau_list);
34493 spin_lock_init(&nesqp->pau_lock);
34494 - atomic_inc(&pau_qps_created);
34495 + atomic_inc_unchecked(&pau_qps_created);
34496 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34497 }
34498
34499 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34500 index 0564be7..f68b0f1 100644
34501 --- a/drivers/infiniband/hw/nes/nes_nic.c
34502 +++ b/drivers/infiniband/hw/nes/nes_nic.c
34503 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34504 target_stat_values[++index] = mh_detected;
34505 target_stat_values[++index] = mh_pauses_sent;
34506 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34507 - target_stat_values[++index] = atomic_read(&cm_connects);
34508 - target_stat_values[++index] = atomic_read(&cm_accepts);
34509 - target_stat_values[++index] = atomic_read(&cm_disconnects);
34510 - target_stat_values[++index] = atomic_read(&cm_connecteds);
34511 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34512 - target_stat_values[++index] = atomic_read(&cm_rejects);
34513 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34514 - target_stat_values[++index] = atomic_read(&qps_created);
34515 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34516 - target_stat_values[++index] = atomic_read(&qps_destroyed);
34517 - target_stat_values[++index] = atomic_read(&cm_closes);
34518 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34519 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34520 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34521 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34522 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34523 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34524 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34525 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34526 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34527 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34528 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34529 target_stat_values[++index] = cm_packets_sent;
34530 target_stat_values[++index] = cm_packets_bounced;
34531 target_stat_values[++index] = cm_packets_created;
34532 target_stat_values[++index] = cm_packets_received;
34533 target_stat_values[++index] = cm_packets_dropped;
34534 target_stat_values[++index] = cm_packets_retrans;
34535 - target_stat_values[++index] = atomic_read(&cm_listens_created);
34536 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34537 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34538 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34539 target_stat_values[++index] = cm_backlog_drops;
34540 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
34541 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
34542 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34543 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34544 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34545 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34546 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34547 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34548 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34549 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34550 target_stat_values[++index] = nesadapter->free_4kpbl;
34551 target_stat_values[++index] = nesadapter->free_256pbl;
34552 target_stat_values[++index] = int_mod_timer_init;
34553 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34554 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34555 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34556 - target_stat_values[++index] = atomic_read(&pau_qps_created);
34557 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34558 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34559 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34560 }
34561
34562 /**
34563 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34564 index 07e4fba..685f041 100644
34565 --- a/drivers/infiniband/hw/nes/nes_verbs.c
34566 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
34567 @@ -46,9 +46,9 @@
34568
34569 #include <rdma/ib_umem.h>
34570
34571 -atomic_t mod_qp_timouts;
34572 -atomic_t qps_created;
34573 -atomic_t sw_qps_destroyed;
34574 +atomic_unchecked_t mod_qp_timouts;
34575 +atomic_unchecked_t qps_created;
34576 +atomic_unchecked_t sw_qps_destroyed;
34577
34578 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34579
34580 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34581 if (init_attr->create_flags)
34582 return ERR_PTR(-EINVAL);
34583
34584 - atomic_inc(&qps_created);
34585 + atomic_inc_unchecked(&qps_created);
34586 switch (init_attr->qp_type) {
34587 case IB_QPT_RC:
34588 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34589 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34590 struct iw_cm_event cm_event;
34591 int ret = 0;
34592
34593 - atomic_inc(&sw_qps_destroyed);
34594 + atomic_inc_unchecked(&sw_qps_destroyed);
34595 nesqp->destroyed = 1;
34596
34597 /* Blow away the connection if it exists. */
34598 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34599 index 4d11575..3e890e5 100644
34600 --- a/drivers/infiniband/hw/qib/qib.h
34601 +++ b/drivers/infiniband/hw/qib/qib.h
34602 @@ -51,6 +51,7 @@
34603 #include <linux/completion.h>
34604 #include <linux/kref.h>
34605 #include <linux/sched.h>
34606 +#include <linux/slab.h>
34607
34608 #include "qib_common.h"
34609 #include "qib_verbs.h"
34610 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34611 index da739d9..da1c7f4 100644
34612 --- a/drivers/input/gameport/gameport.c
34613 +++ b/drivers/input/gameport/gameport.c
34614 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34615 */
34616 static void gameport_init_port(struct gameport *gameport)
34617 {
34618 - static atomic_t gameport_no = ATOMIC_INIT(0);
34619 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34620
34621 __module_get(THIS_MODULE);
34622
34623 mutex_init(&gameport->drv_mutex);
34624 device_initialize(&gameport->dev);
34625 dev_set_name(&gameport->dev, "gameport%lu",
34626 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
34627 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34628 gameport->dev.bus = &gameport_bus;
34629 gameport->dev.release = gameport_release_port;
34630 if (gameport->parent)
34631 diff --git a/drivers/input/input.c b/drivers/input/input.c
34632 index 53a0dde..abffda7 100644
34633 --- a/drivers/input/input.c
34634 +++ b/drivers/input/input.c
34635 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34636 */
34637 int input_register_device(struct input_dev *dev)
34638 {
34639 - static atomic_t input_no = ATOMIC_INIT(0);
34640 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34641 struct input_handler *handler;
34642 unsigned int packet_size;
34643 const char *path;
34644 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34645 dev->setkeycode = input_default_setkeycode;
34646
34647 dev_set_name(&dev->dev, "input%ld",
34648 - (unsigned long) atomic_inc_return(&input_no) - 1);
34649 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34650
34651 error = device_add(&dev->dev);
34652 if (error)
34653 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34654 index 04c69af..5f92d00 100644
34655 --- a/drivers/input/joystick/sidewinder.c
34656 +++ b/drivers/input/joystick/sidewinder.c
34657 @@ -30,6 +30,7 @@
34658 #include <linux/kernel.h>
34659 #include <linux/module.h>
34660 #include <linux/slab.h>
34661 +#include <linux/sched.h>
34662 #include <linux/init.h>
34663 #include <linux/input.h>
34664 #include <linux/gameport.h>
34665 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34666 index 83811e4..0822b90 100644
34667 --- a/drivers/input/joystick/xpad.c
34668 +++ b/drivers/input/joystick/xpad.c
34669 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34670
34671 static int xpad_led_probe(struct usb_xpad *xpad)
34672 {
34673 - static atomic_t led_seq = ATOMIC_INIT(0);
34674 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34675 long led_no;
34676 struct xpad_led *led;
34677 struct led_classdev *led_cdev;
34678 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34679 if (!led)
34680 return -ENOMEM;
34681
34682 - led_no = (long)atomic_inc_return(&led_seq) - 1;
34683 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34684
34685 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34686 led->xpad = xpad;
34687 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34688 index 4c842c3..590b0bf 100644
34689 --- a/drivers/input/mousedev.c
34690 +++ b/drivers/input/mousedev.c
34691 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34692
34693 spin_unlock_irq(&client->packet_lock);
34694
34695 - if (copy_to_user(buffer, data, count))
34696 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
34697 return -EFAULT;
34698
34699 return count;
34700 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34701 index d0f7533..fb8215b 100644
34702 --- a/drivers/input/serio/serio.c
34703 +++ b/drivers/input/serio/serio.c
34704 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34705 */
34706 static void serio_init_port(struct serio *serio)
34707 {
34708 - static atomic_t serio_no = ATOMIC_INIT(0);
34709 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34710
34711 __module_get(THIS_MODULE);
34712
34713 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34714 mutex_init(&serio->drv_mutex);
34715 device_initialize(&serio->dev);
34716 dev_set_name(&serio->dev, "serio%ld",
34717 - (long)atomic_inc_return(&serio_no) - 1);
34718 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
34719 serio->dev.bus = &serio_bus;
34720 serio->dev.release = serio_release_port;
34721 serio->dev.groups = serio_device_attr_groups;
34722 diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
34723 index faf10ba..7cfaba9 100644
34724 --- a/drivers/iommu/amd_iommu_init.c
34725 +++ b/drivers/iommu/amd_iommu_init.c
34726 @@ -1922,7 +1922,7 @@ static int __init state_next(void)
34727 case IOMMU_ACPI_FINISHED:
34728 early_enable_iommus();
34729 register_syscore_ops(&amd_iommu_syscore_ops);
34730 - x86_platform.iommu_shutdown = disable_iommus;
34731 + *(void **)&x86_platform.iommu_shutdown = disable_iommus;
34732 init_state = IOMMU_ENABLED;
34733 break;
34734 case IOMMU_ENABLED:
34735 @@ -2064,7 +2064,7 @@ int __init amd_iommu_detect(void)
34736
34737 amd_iommu_detected = true;
34738 iommu_detected = 1;
34739 - x86_init.iommu.iommu_init = amd_iommu_init;
34740 + *(void **)&x86_init.iommu.iommu_init = amd_iommu_init;
34741
34742 return 0;
34743 }
34744 diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
34745 index 86e2f4a..d1cec5d 100644
34746 --- a/drivers/iommu/dmar.c
34747 +++ b/drivers/iommu/dmar.c
34748 @@ -555,7 +555,7 @@ int __init detect_intel_iommu(void)
34749
34750 #ifdef CONFIG_X86
34751 if (ret)
34752 - x86_init.iommu.iommu_init = intel_iommu_init;
34753 + *(void **)&x86_init.iommu.iommu_init = intel_iommu_init;
34754 #endif
34755 }
34756 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
34757 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34758 index c679867..6e2e34d 100644
34759 --- a/drivers/isdn/capi/capi.c
34760 +++ b/drivers/isdn/capi/capi.c
34761 @@ -83,8 +83,8 @@ struct capiminor {
34762
34763 struct capi20_appl *ap;
34764 u32 ncci;
34765 - atomic_t datahandle;
34766 - atomic_t msgid;
34767 + atomic_unchecked_t datahandle;
34768 + atomic_unchecked_t msgid;
34769
34770 struct tty_port port;
34771 int ttyinstop;
34772 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34773 capimsg_setu16(s, 2, mp->ap->applid);
34774 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34775 capimsg_setu8 (s, 5, CAPI_RESP);
34776 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34777 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34778 capimsg_setu32(s, 8, mp->ncci);
34779 capimsg_setu16(s, 12, datahandle);
34780 }
34781 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34782 mp->outbytes -= len;
34783 spin_unlock_bh(&mp->outlock);
34784
34785 - datahandle = atomic_inc_return(&mp->datahandle);
34786 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34787 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34788 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34789 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34790 capimsg_setu16(skb->data, 2, mp->ap->applid);
34791 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34792 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34793 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34794 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34795 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34796 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34797 capimsg_setu16(skb->data, 16, len); /* Data length */
34798 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34799 index 67abf3f..076b3a6 100644
34800 --- a/drivers/isdn/gigaset/interface.c
34801 +++ b/drivers/isdn/gigaset/interface.c
34802 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34803 }
34804 tty->driver_data = cs;
34805
34806 - ++cs->port.count;
34807 + atomic_inc(&cs->port.count);
34808
34809 - if (cs->port.count == 1) {
34810 + if (atomic_read(&cs->port.count) == 1) {
34811 tty_port_tty_set(&cs->port, tty);
34812 tty->low_latency = 1;
34813 }
34814 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34815
34816 if (!cs->connected)
34817 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34818 - else if (!cs->port.count)
34819 + else if (!atomic_read(&cs->port.count))
34820 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34821 - else if (!--cs->port.count)
34822 + else if (!atomic_dec_return(&cs->port.count))
34823 tty_port_tty_set(&cs->port, NULL);
34824
34825 mutex_unlock(&cs->mutex);
34826 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34827 index 821f7ac..28d4030 100644
34828 --- a/drivers/isdn/hardware/avm/b1.c
34829 +++ b/drivers/isdn/hardware/avm/b1.c
34830 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34831 }
34832 if (left) {
34833 if (t4file->user) {
34834 - if (copy_from_user(buf, dp, left))
34835 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34836 return -EFAULT;
34837 } else {
34838 memcpy(buf, dp, left);
34839 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34840 }
34841 if (left) {
34842 if (config->user) {
34843 - if (copy_from_user(buf, dp, left))
34844 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34845 return -EFAULT;
34846 } else {
34847 memcpy(buf, dp, left);
34848 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34849 index b817809..409caff 100644
34850 --- a/drivers/isdn/i4l/isdn_tty.c
34851 +++ b/drivers/isdn/i4l/isdn_tty.c
34852 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34853
34854 #ifdef ISDN_DEBUG_MODEM_OPEN
34855 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34856 - port->count);
34857 + atomic_read(&port->count));
34858 #endif
34859 - port->count++;
34860 + atomic_inc(&port->count);
34861 port->tty = tty;
34862 /*
34863 * Start up serial port
34864 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34865 #endif
34866 return;
34867 }
34868 - if ((tty->count == 1) && (port->count != 1)) {
34869 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34870 /*
34871 * Uh, oh. tty->count is 1, which means that the tty
34872 * structure will be freed. Info->count should always
34873 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34874 * serial port won't be shutdown.
34875 */
34876 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34877 - "info->count is %d\n", port->count);
34878 - port->count = 1;
34879 + "info->count is %d\n", atomic_read(&port->count));
34880 + atomic_set(&port->count, 1);
34881 }
34882 - if (--port->count < 0) {
34883 + if (atomic_dec_return(&port->count) < 0) {
34884 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34885 - info->line, port->count);
34886 - port->count = 0;
34887 + info->line, atomic_read(&port->count));
34888 + atomic_set(&port->count, 0);
34889 }
34890 - if (port->count) {
34891 + if (atomic_read(&port->count)) {
34892 #ifdef ISDN_DEBUG_MODEM_OPEN
34893 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34894 #endif
34895 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34896 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34897 return;
34898 isdn_tty_shutdown(info);
34899 - port->count = 0;
34900 + atomic_set(&port->count, 0);
34901 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34902 port->tty = NULL;
34903 wake_up_interruptible(&port->open_wait);
34904 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34905 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34906 modem_info *info = &dev->mdm.info[i];
34907
34908 - if (info->port.count == 0)
34909 + if (atomic_read(&info->port.count) == 0)
34910 continue;
34911 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34912 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34913 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34914 index e74df7c..03a03ba 100644
34915 --- a/drivers/isdn/icn/icn.c
34916 +++ b/drivers/isdn/icn/icn.c
34917 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34918 if (count > len)
34919 count = len;
34920 if (user) {
34921 - if (copy_from_user(msg, buf, count))
34922 + if (count > sizeof msg || copy_from_user(msg, buf, count))
34923 return -EFAULT;
34924 } else
34925 memcpy(msg, buf, count);
34926 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34927 index b5fdcb7..5b6c59f 100644
34928 --- a/drivers/lguest/core.c
34929 +++ b/drivers/lguest/core.c
34930 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
34931 * it's worked so far. The end address needs +1 because __get_vm_area
34932 * allocates an extra guard page, so we need space for that.
34933 */
34934 +
34935 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34936 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34937 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34938 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34939 +#else
34940 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34941 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34942 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34943 +#endif
34944 +
34945 if (!switcher_vma) {
34946 err = -ENOMEM;
34947 printk("lguest: could not map switcher pages high\n");
34948 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
34949 * Now the Switcher is mapped at the right address, we can't fail!
34950 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34951 */
34952 - memcpy(switcher_vma->addr, start_switcher_text,
34953 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34954 end_switcher_text - start_switcher_text);
34955
34956 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34957 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34958 index 4af12e1..0e89afe 100644
34959 --- a/drivers/lguest/x86/core.c
34960 +++ b/drivers/lguest/x86/core.c
34961 @@ -59,7 +59,7 @@ static struct {
34962 /* Offset from where switcher.S was compiled to where we've copied it */
34963 static unsigned long switcher_offset(void)
34964 {
34965 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34966 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34967 }
34968
34969 /* This cpu's struct lguest_pages. */
34970 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34971 * These copies are pretty cheap, so we do them unconditionally: */
34972 /* Save the current Host top-level page directory.
34973 */
34974 +
34975 +#ifdef CONFIG_PAX_PER_CPU_PGD
34976 + pages->state.host_cr3 = read_cr3();
34977 +#else
34978 pages->state.host_cr3 = __pa(current->mm->pgd);
34979 +#endif
34980 +
34981 /*
34982 * Set up the Guest's page tables to see this CPU's pages (and no
34983 * other CPU's pages).
34984 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34985 * compiled-in switcher code and the high-mapped copy we just made.
34986 */
34987 for (i = 0; i < IDT_ENTRIES; i++)
34988 - default_idt_entries[i] += switcher_offset();
34989 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34990
34991 /*
34992 * Set up the Switcher's per-cpu areas.
34993 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34994 * it will be undisturbed when we switch. To change %cs and jump we
34995 * need this structure to feed to Intel's "lcall" instruction.
34996 */
34997 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34998 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34999 lguest_entry.segment = LGUEST_CS;
35000
35001 /*
35002 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35003 index 40634b0..4f5855e 100644
35004 --- a/drivers/lguest/x86/switcher_32.S
35005 +++ b/drivers/lguest/x86/switcher_32.S
35006 @@ -87,6 +87,7 @@
35007 #include <asm/page.h>
35008 #include <asm/segment.h>
35009 #include <asm/lguest.h>
35010 +#include <asm/processor-flags.h>
35011
35012 // We mark the start of the code to copy
35013 // It's placed in .text tho it's never run here
35014 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35015 // Changes type when we load it: damn Intel!
35016 // For after we switch over our page tables
35017 // That entry will be read-only: we'd crash.
35018 +
35019 +#ifdef CONFIG_PAX_KERNEXEC
35020 + mov %cr0, %edx
35021 + xor $X86_CR0_WP, %edx
35022 + mov %edx, %cr0
35023 +#endif
35024 +
35025 movl $(GDT_ENTRY_TSS*8), %edx
35026 ltr %dx
35027
35028 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35029 // Let's clear it again for our return.
35030 // The GDT descriptor of the Host
35031 // Points to the table after two "size" bytes
35032 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35033 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35034 // Clear "used" from type field (byte 5, bit 2)
35035 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35036 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35037 +
35038 +#ifdef CONFIG_PAX_KERNEXEC
35039 + mov %cr0, %eax
35040 + xor $X86_CR0_WP, %eax
35041 + mov %eax, %cr0
35042 +#endif
35043
35044 // Once our page table's switched, the Guest is live!
35045 // The Host fades as we run this final step.
35046 @@ -295,13 +309,12 @@ deliver_to_host:
35047 // I consulted gcc, and it gave
35048 // These instructions, which I gladly credit:
35049 leal (%edx,%ebx,8), %eax
35050 - movzwl (%eax),%edx
35051 - movl 4(%eax), %eax
35052 - xorw %ax, %ax
35053 - orl %eax, %edx
35054 + movl 4(%eax), %edx
35055 + movw (%eax), %dx
35056 // Now the address of the handler's in %edx
35057 // We call it now: its "iret" drops us home.
35058 - jmp *%edx
35059 + ljmp $__KERNEL_CS, $1f
35060 +1: jmp *%edx
35061
35062 // Every interrupt can come to us here
35063 // But we must truly tell each apart.
35064 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35065 index 7155945..4bcc562 100644
35066 --- a/drivers/md/bitmap.c
35067 +++ b/drivers/md/bitmap.c
35068 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35069 chunk_kb ? "KB" : "B");
35070 if (bitmap->storage.file) {
35071 seq_printf(seq, ", file: ");
35072 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35073 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35074 }
35075
35076 seq_printf(seq, "\n");
35077 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35078 index a651d52..82f8a95 100644
35079 --- a/drivers/md/dm-ioctl.c
35080 +++ b/drivers/md/dm-ioctl.c
35081 @@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35082 cmd == DM_LIST_VERSIONS_CMD)
35083 return 0;
35084
35085 - if ((cmd == DM_DEV_CREATE_CMD)) {
35086 + if (cmd == DM_DEV_CREATE_CMD) {
35087 if (!*param->name) {
35088 DMWARN("name not supplied when creating device");
35089 return -EINVAL;
35090 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35091 index fd61f98..8050783 100644
35092 --- a/drivers/md/dm-raid1.c
35093 +++ b/drivers/md/dm-raid1.c
35094 @@ -40,7 +40,7 @@ enum dm_raid1_error {
35095
35096 struct mirror {
35097 struct mirror_set *ms;
35098 - atomic_t error_count;
35099 + atomic_unchecked_t error_count;
35100 unsigned long error_type;
35101 struct dm_dev *dev;
35102 sector_t offset;
35103 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35104 struct mirror *m;
35105
35106 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35107 - if (!atomic_read(&m->error_count))
35108 + if (!atomic_read_unchecked(&m->error_count))
35109 return m;
35110
35111 return NULL;
35112 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35113 * simple way to tell if a device has encountered
35114 * errors.
35115 */
35116 - atomic_inc(&m->error_count);
35117 + atomic_inc_unchecked(&m->error_count);
35118
35119 if (test_and_set_bit(error_type, &m->error_type))
35120 return;
35121 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35122 struct mirror *m = get_default_mirror(ms);
35123
35124 do {
35125 - if (likely(!atomic_read(&m->error_count)))
35126 + if (likely(!atomic_read_unchecked(&m->error_count)))
35127 return m;
35128
35129 if (m-- == ms->mirror)
35130 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
35131 {
35132 struct mirror *default_mirror = get_default_mirror(m->ms);
35133
35134 - return !atomic_read(&default_mirror->error_count);
35135 + return !atomic_read_unchecked(&default_mirror->error_count);
35136 }
35137
35138 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35139 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35140 */
35141 if (likely(region_in_sync(ms, region, 1)))
35142 m = choose_mirror(ms, bio->bi_sector);
35143 - else if (m && atomic_read(&m->error_count))
35144 + else if (m && atomic_read_unchecked(&m->error_count))
35145 m = NULL;
35146
35147 if (likely(m))
35148 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35149 }
35150
35151 ms->mirror[mirror].ms = ms;
35152 - atomic_set(&(ms->mirror[mirror].error_count), 0);
35153 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35154 ms->mirror[mirror].error_type = 0;
35155 ms->mirror[mirror].offset = offset;
35156
35157 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
35158 */
35159 static char device_status_char(struct mirror *m)
35160 {
35161 - if (!atomic_read(&(m->error_count)))
35162 + if (!atomic_read_unchecked(&(m->error_count)))
35163 return 'A';
35164
35165 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35166 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35167 index e2f87653..f279abe 100644
35168 --- a/drivers/md/dm-stripe.c
35169 +++ b/drivers/md/dm-stripe.c
35170 @@ -20,7 +20,7 @@ struct stripe {
35171 struct dm_dev *dev;
35172 sector_t physical_start;
35173
35174 - atomic_t error_count;
35175 + atomic_unchecked_t error_count;
35176 };
35177
35178 struct stripe_c {
35179 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35180 kfree(sc);
35181 return r;
35182 }
35183 - atomic_set(&(sc->stripe[i].error_count), 0);
35184 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35185 }
35186
35187 ti->private = sc;
35188 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35189 DMEMIT("%d ", sc->stripes);
35190 for (i = 0; i < sc->stripes; i++) {
35191 DMEMIT("%s ", sc->stripe[i].dev->name);
35192 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35193 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35194 'D' : 'A';
35195 }
35196 buffer[i] = '\0';
35197 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35198 */
35199 for (i = 0; i < sc->stripes; i++)
35200 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35201 - atomic_inc(&(sc->stripe[i].error_count));
35202 - if (atomic_read(&(sc->stripe[i].error_count)) <
35203 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
35204 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35205 DM_IO_ERROR_THRESHOLD)
35206 schedule_work(&sc->trigger_event);
35207 }
35208 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35209 index fa29557..d24a5b7 100644
35210 --- a/drivers/md/dm-table.c
35211 +++ b/drivers/md/dm-table.c
35212 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35213 if (!dev_size)
35214 return 0;
35215
35216 - if ((start >= dev_size) || (start + len > dev_size)) {
35217 + if ((start >= dev_size) || (len > dev_size - start)) {
35218 DMWARN("%s: %s too small for target: "
35219 "start=%llu, len=%llu, dev_size=%llu",
35220 dm_device_name(ti->table->md), bdevname(bdev, b),
35221 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35222 index 693e149..b7e0fde 100644
35223 --- a/drivers/md/dm-thin-metadata.c
35224 +++ b/drivers/md/dm-thin-metadata.c
35225 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35226 {
35227 pmd->info.tm = pmd->tm;
35228 pmd->info.levels = 2;
35229 - pmd->info.value_type.context = pmd->data_sm;
35230 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35231 pmd->info.value_type.size = sizeof(__le64);
35232 pmd->info.value_type.inc = data_block_inc;
35233 pmd->info.value_type.dec = data_block_dec;
35234 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35235
35236 pmd->bl_info.tm = pmd->tm;
35237 pmd->bl_info.levels = 1;
35238 - pmd->bl_info.value_type.context = pmd->data_sm;
35239 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35240 pmd->bl_info.value_type.size = sizeof(__le64);
35241 pmd->bl_info.value_type.inc = data_block_inc;
35242 pmd->bl_info.value_type.dec = data_block_dec;
35243 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35244 index 77e6eff..913d695 100644
35245 --- a/drivers/md/dm.c
35246 +++ b/drivers/md/dm.c
35247 @@ -182,9 +182,9 @@ struct mapped_device {
35248 /*
35249 * Event handling.
35250 */
35251 - atomic_t event_nr;
35252 + atomic_unchecked_t event_nr;
35253 wait_queue_head_t eventq;
35254 - atomic_t uevent_seq;
35255 + atomic_unchecked_t uevent_seq;
35256 struct list_head uevent_list;
35257 spinlock_t uevent_lock; /* Protect access to uevent_list */
35258
35259 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
35260 rwlock_init(&md->map_lock);
35261 atomic_set(&md->holders, 1);
35262 atomic_set(&md->open_count, 0);
35263 - atomic_set(&md->event_nr, 0);
35264 - atomic_set(&md->uevent_seq, 0);
35265 + atomic_set_unchecked(&md->event_nr, 0);
35266 + atomic_set_unchecked(&md->uevent_seq, 0);
35267 INIT_LIST_HEAD(&md->uevent_list);
35268 spin_lock_init(&md->uevent_lock);
35269
35270 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
35271
35272 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
35273
35274 - atomic_inc(&md->event_nr);
35275 + atomic_inc_unchecked(&md->event_nr);
35276 wake_up(&md->eventq);
35277 }
35278
35279 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
35280
35281 uint32_t dm_next_uevent_seq(struct mapped_device *md)
35282 {
35283 - return atomic_add_return(1, &md->uevent_seq);
35284 + return atomic_add_return_unchecked(1, &md->uevent_seq);
35285 }
35286
35287 uint32_t dm_get_event_nr(struct mapped_device *md)
35288 {
35289 - return atomic_read(&md->event_nr);
35290 + return atomic_read_unchecked(&md->event_nr);
35291 }
35292
35293 int dm_wait_event(struct mapped_device *md, int event_nr)
35294 {
35295 return wait_event_interruptible(md->eventq,
35296 - (event_nr != atomic_read(&md->event_nr)));
35297 + (event_nr != atomic_read_unchecked(&md->event_nr)));
35298 }
35299
35300 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
35301 diff --git a/drivers/md/md.c b/drivers/md/md.c
35302 index 6120071..31d9be2 100644
35303 --- a/drivers/md/md.c
35304 +++ b/drivers/md/md.c
35305 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
35306 * start build, activate spare
35307 */
35308 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
35309 -static atomic_t md_event_count;
35310 +static atomic_unchecked_t md_event_count;
35311 void md_new_event(struct mddev *mddev)
35312 {
35313 - atomic_inc(&md_event_count);
35314 + atomic_inc_unchecked(&md_event_count);
35315 wake_up(&md_event_waiters);
35316 }
35317 EXPORT_SYMBOL_GPL(md_new_event);
35318 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
35319 */
35320 static void md_new_event_inintr(struct mddev *mddev)
35321 {
35322 - atomic_inc(&md_event_count);
35323 + atomic_inc_unchecked(&md_event_count);
35324 wake_up(&md_event_waiters);
35325 }
35326
35327 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
35328 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
35329 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
35330 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
35331 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35332 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35333
35334 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
35335 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
35336 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
35337 else
35338 sb->resync_offset = cpu_to_le64(0);
35339
35340 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
35341 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
35342
35343 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
35344 sb->size = cpu_to_le64(mddev->dev_sectors);
35345 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
35346 static ssize_t
35347 errors_show(struct md_rdev *rdev, char *page)
35348 {
35349 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
35350 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
35351 }
35352
35353 static ssize_t
35354 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
35355 char *e;
35356 unsigned long n = simple_strtoul(buf, &e, 10);
35357 if (*buf && (*e == 0 || *e == '\n')) {
35358 - atomic_set(&rdev->corrected_errors, n);
35359 + atomic_set_unchecked(&rdev->corrected_errors, n);
35360 return len;
35361 }
35362 return -EINVAL;
35363 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
35364 rdev->sb_loaded = 0;
35365 rdev->bb_page = NULL;
35366 atomic_set(&rdev->nr_pending, 0);
35367 - atomic_set(&rdev->read_errors, 0);
35368 - atomic_set(&rdev->corrected_errors, 0);
35369 + atomic_set_unchecked(&rdev->read_errors, 0);
35370 + atomic_set_unchecked(&rdev->corrected_errors, 0);
35371
35372 INIT_LIST_HEAD(&rdev->same_set);
35373 init_waitqueue_head(&rdev->blocked_wait);
35374 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
35375
35376 spin_unlock(&pers_lock);
35377 seq_printf(seq, "\n");
35378 - seq->poll_event = atomic_read(&md_event_count);
35379 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35380 return 0;
35381 }
35382 if (v == (void*)2) {
35383 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
35384 return error;
35385
35386 seq = file->private_data;
35387 - seq->poll_event = atomic_read(&md_event_count);
35388 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35389 return error;
35390 }
35391
35392 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
35393 /* always allow read */
35394 mask = POLLIN | POLLRDNORM;
35395
35396 - if (seq->poll_event != atomic_read(&md_event_count))
35397 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
35398 mask |= POLLERR | POLLPRI;
35399 return mask;
35400 }
35401 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
35402 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
35403 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
35404 (int)part_stat_read(&disk->part0, sectors[1]) -
35405 - atomic_read(&disk->sync_io);
35406 + atomic_read_unchecked(&disk->sync_io);
35407 /* sync IO will cause sync_io to increase before the disk_stats
35408 * as sync_io is counted when a request starts, and
35409 * disk_stats is counted when it completes.
35410 diff --git a/drivers/md/md.h b/drivers/md/md.h
35411 index af443ab..0f93be3 100644
35412 --- a/drivers/md/md.h
35413 +++ b/drivers/md/md.h
35414 @@ -94,13 +94,13 @@ struct md_rdev {
35415 * only maintained for arrays that
35416 * support hot removal
35417 */
35418 - atomic_t read_errors; /* number of consecutive read errors that
35419 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
35420 * we have tried to ignore.
35421 */
35422 struct timespec last_read_error; /* monotonic time since our
35423 * last read error
35424 */
35425 - atomic_t corrected_errors; /* number of corrected read errors,
35426 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
35427 * for reporting to userspace and storing
35428 * in superblock.
35429 */
35430 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
35431
35432 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
35433 {
35434 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35435 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35436 }
35437
35438 struct md_personality
35439 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
35440 index 1cbfc6b..56e1dbb 100644
35441 --- a/drivers/md/persistent-data/dm-space-map.h
35442 +++ b/drivers/md/persistent-data/dm-space-map.h
35443 @@ -60,6 +60,7 @@ struct dm_space_map {
35444 int (*root_size)(struct dm_space_map *sm, size_t *result);
35445 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35446 };
35447 +typedef struct dm_space_map __no_const dm_space_map_no_const;
35448
35449 /*----------------------------------------------------------------*/
35450
35451 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35452 index a0f7309..5599dbc 100644
35453 --- a/drivers/md/raid1.c
35454 +++ b/drivers/md/raid1.c
35455 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35456 if (r1_sync_page_io(rdev, sect, s,
35457 bio->bi_io_vec[idx].bv_page,
35458 READ) != 0)
35459 - atomic_add(s, &rdev->corrected_errors);
35460 + atomic_add_unchecked(s, &rdev->corrected_errors);
35461 }
35462 sectors -= s;
35463 sect += s;
35464 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35465 test_bit(In_sync, &rdev->flags)) {
35466 if (r1_sync_page_io(rdev, sect, s,
35467 conf->tmppage, READ)) {
35468 - atomic_add(s, &rdev->corrected_errors);
35469 + atomic_add_unchecked(s, &rdev->corrected_errors);
35470 printk(KERN_INFO
35471 "md/raid1:%s: read error corrected "
35472 "(%d sectors at %llu on %s)\n",
35473 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35474 index c9acbd7..386cd3e 100644
35475 --- a/drivers/md/raid10.c
35476 +++ b/drivers/md/raid10.c
35477 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35478 /* The write handler will notice the lack of
35479 * R10BIO_Uptodate and record any errors etc
35480 */
35481 - atomic_add(r10_bio->sectors,
35482 + atomic_add_unchecked(r10_bio->sectors,
35483 &conf->mirrors[d].rdev->corrected_errors);
35484
35485 /* for reconstruct, we always reschedule after a read.
35486 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35487 {
35488 struct timespec cur_time_mon;
35489 unsigned long hours_since_last;
35490 - unsigned int read_errors = atomic_read(&rdev->read_errors);
35491 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35492
35493 ktime_get_ts(&cur_time_mon);
35494
35495 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35496 * overflowing the shift of read_errors by hours_since_last.
35497 */
35498 if (hours_since_last >= 8 * sizeof(read_errors))
35499 - atomic_set(&rdev->read_errors, 0);
35500 + atomic_set_unchecked(&rdev->read_errors, 0);
35501 else
35502 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35503 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35504 }
35505
35506 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35507 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35508 return;
35509
35510 check_decay_read_errors(mddev, rdev);
35511 - atomic_inc(&rdev->read_errors);
35512 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
35513 + atomic_inc_unchecked(&rdev->read_errors);
35514 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35515 char b[BDEVNAME_SIZE];
35516 bdevname(rdev->bdev, b);
35517
35518 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35519 "md/raid10:%s: %s: Raid device exceeded "
35520 "read_error threshold [cur %d:max %d]\n",
35521 mdname(mddev), b,
35522 - atomic_read(&rdev->read_errors), max_read_errors);
35523 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35524 printk(KERN_NOTICE
35525 "md/raid10:%s: %s: Failing raid device\n",
35526 mdname(mddev), b);
35527 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35528 sect +
35529 choose_data_offset(r10_bio, rdev)),
35530 bdevname(rdev->bdev, b));
35531 - atomic_add(s, &rdev->corrected_errors);
35532 + atomic_add_unchecked(s, &rdev->corrected_errors);
35533 }
35534
35535 rdev_dec_pending(rdev, mddev);
35536 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35537 index a450268..c4168a9 100644
35538 --- a/drivers/md/raid5.c
35539 +++ b/drivers/md/raid5.c
35540 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35541 mdname(conf->mddev), STRIPE_SECTORS,
35542 (unsigned long long)s,
35543 bdevname(rdev->bdev, b));
35544 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35545 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35546 clear_bit(R5_ReadError, &sh->dev[i].flags);
35547 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35548 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35549 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35550
35551 - if (atomic_read(&rdev->read_errors))
35552 - atomic_set(&rdev->read_errors, 0);
35553 + if (atomic_read_unchecked(&rdev->read_errors))
35554 + atomic_set_unchecked(&rdev->read_errors, 0);
35555 } else {
35556 const char *bdn = bdevname(rdev->bdev, b);
35557 int retry = 0;
35558 int set_bad = 0;
35559
35560 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35561 - atomic_inc(&rdev->read_errors);
35562 + atomic_inc_unchecked(&rdev->read_errors);
35563 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35564 printk_ratelimited(
35565 KERN_WARNING
35566 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35567 mdname(conf->mddev),
35568 (unsigned long long)s,
35569 bdn);
35570 - } else if (atomic_read(&rdev->read_errors)
35571 + } else if (atomic_read_unchecked(&rdev->read_errors)
35572 > conf->max_nr_stripes)
35573 printk(KERN_WARNING
35574 "md/raid:%s: Too many read errors, failing device %s.\n",
35575 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35576 index d33101a..6b13069 100644
35577 --- a/drivers/media/dvb-core/dvbdev.c
35578 +++ b/drivers/media/dvb-core/dvbdev.c
35579 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35580 const struct dvb_device *template, void *priv, int type)
35581 {
35582 struct dvb_device *dvbdev;
35583 - struct file_operations *dvbdevfops;
35584 + file_operations_no_const *dvbdevfops;
35585 struct device *clsdev;
35586 int minor;
35587 int id;
35588 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35589 index 404f63a..4796533 100644
35590 --- a/drivers/media/dvb-frontends/dib3000.h
35591 +++ b/drivers/media/dvb-frontends/dib3000.h
35592 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35593 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35594 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35595 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35596 -};
35597 +} __no_const;
35598
35599 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35600 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35601 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35602 index 3aa6856..435ad25 100644
35603 --- a/drivers/media/pci/cx88/cx88-alsa.c
35604 +++ b/drivers/media/pci/cx88/cx88-alsa.c
35605 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35606 * Only boards with eeprom and byte 1 at eeprom=1 have it
35607 */
35608
35609 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35610 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35611 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35612 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35613 {0, }
35614 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35615 index feff57e..66a2c67 100644
35616 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
35617 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35618 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35619 .subvendor = _subvend, .subdevice = _subdev, \
35620 .driver_data = (unsigned long)&_driverdata }
35621
35622 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35623 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35624 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35625 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35626 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35627 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35628 index 96a13ed..6df45b4 100644
35629 --- a/drivers/media/pci/ngene/ngene-cards.c
35630 +++ b/drivers/media/pci/ngene/ngene-cards.c
35631 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35632
35633 /****************************************************************************/
35634
35635 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35636 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35637 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35638 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35639 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35640 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35641 index a3b1a34..71ce0e3 100644
35642 --- a/drivers/media/platform/omap/omap_vout.c
35643 +++ b/drivers/media/platform/omap/omap_vout.c
35644 @@ -65,7 +65,6 @@ enum omap_vout_channels {
35645 OMAP_VIDEO2,
35646 };
35647
35648 -static struct videobuf_queue_ops video_vbq_ops;
35649 /* Variables configurable through module params*/
35650 static u32 video1_numbuffers = 3;
35651 static u32 video2_numbuffers = 3;
35652 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35653 {
35654 struct videobuf_queue *q;
35655 struct omap_vout_device *vout = NULL;
35656 + static struct videobuf_queue_ops video_vbq_ops = {
35657 + .buf_setup = omap_vout_buffer_setup,
35658 + .buf_prepare = omap_vout_buffer_prepare,
35659 + .buf_release = omap_vout_buffer_release,
35660 + .buf_queue = omap_vout_buffer_queue,
35661 + };
35662
35663 vout = video_drvdata(file);
35664 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35665 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35666 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35667
35668 q = &vout->vbq;
35669 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35670 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35671 - video_vbq_ops.buf_release = omap_vout_buffer_release;
35672 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35673 spin_lock_init(&vout->vbq_lock);
35674
35675 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35676 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
35677 index ddb422e..8cf008e 100644
35678 --- a/drivers/media/platform/s5p-tv/mixer.h
35679 +++ b/drivers/media/platform/s5p-tv/mixer.h
35680 @@ -155,7 +155,7 @@ struct mxr_layer {
35681 /** layer index (unique identifier) */
35682 int idx;
35683 /** callbacks for layer methods */
35684 - struct mxr_layer_ops ops;
35685 + struct mxr_layer_ops *ops;
35686 /** format array */
35687 const struct mxr_format **fmt_array;
35688 /** size of format array */
35689 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35690 index b93a21f..2535195 100644
35691 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35692 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35693 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
35694 {
35695 struct mxr_layer *layer;
35696 int ret;
35697 - struct mxr_layer_ops ops = {
35698 + static struct mxr_layer_ops ops = {
35699 .release = mxr_graph_layer_release,
35700 .buffer_set = mxr_graph_buffer_set,
35701 .stream_set = mxr_graph_stream_set,
35702 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
35703 index 3b1670a..595c939 100644
35704 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
35705 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
35706 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
35707 layer->update_buf = next;
35708 }
35709
35710 - layer->ops.buffer_set(layer, layer->update_buf);
35711 + layer->ops->buffer_set(layer, layer->update_buf);
35712
35713 if (done && done != layer->shadow_buf)
35714 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
35715 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
35716 index 0c1cd89..6574647 100644
35717 --- a/drivers/media/platform/s5p-tv/mixer_video.c
35718 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
35719 @@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
35720 layer->geo.src.height = layer->geo.src.full_height;
35721
35722 mxr_geometry_dump(mdev, &layer->geo);
35723 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35724 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35725 mxr_geometry_dump(mdev, &layer->geo);
35726 }
35727
35728 @@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
35729 layer->geo.dst.full_width = mbus_fmt.width;
35730 layer->geo.dst.full_height = mbus_fmt.height;
35731 layer->geo.dst.field = mbus_fmt.field;
35732 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35733 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35734
35735 mxr_geometry_dump(mdev, &layer->geo);
35736 }
35737 @@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
35738 /* set source size to highest accepted value */
35739 geo->src.full_width = max(geo->dst.full_width, pix->width);
35740 geo->src.full_height = max(geo->dst.full_height, pix->height);
35741 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35742 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35743 mxr_geometry_dump(mdev, &layer->geo);
35744 /* set cropping to total visible screen */
35745 geo->src.width = pix->width;
35746 @@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
35747 geo->src.x_offset = 0;
35748 geo->src.y_offset = 0;
35749 /* assure consistency of geometry */
35750 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35751 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35752 mxr_geometry_dump(mdev, &layer->geo);
35753 /* set full size to lowest possible value */
35754 geo->src.full_width = 0;
35755 geo->src.full_height = 0;
35756 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35757 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35758 mxr_geometry_dump(mdev, &layer->geo);
35759
35760 /* returning results */
35761 @@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
35762 target->width = s->r.width;
35763 target->height = s->r.height;
35764
35765 - layer->ops.fix_geometry(layer, stage, s->flags);
35766 + layer->ops->fix_geometry(layer, stage, s->flags);
35767
35768 /* retrieve update selection rectangle */
35769 res.left = target->x_offset;
35770 @@ -928,13 +928,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
35771 mxr_output_get(mdev);
35772
35773 mxr_layer_update_output(layer);
35774 - layer->ops.format_set(layer);
35775 + layer->ops->format_set(layer);
35776 /* enabling layer in hardware */
35777 spin_lock_irqsave(&layer->enq_slock, flags);
35778 layer->state = MXR_LAYER_STREAMING;
35779 spin_unlock_irqrestore(&layer->enq_slock, flags);
35780
35781 - layer->ops.stream_set(layer, MXR_ENABLE);
35782 + layer->ops->stream_set(layer, MXR_ENABLE);
35783 mxr_streamer_get(mdev);
35784
35785 return 0;
35786 @@ -1004,7 +1004,7 @@ static int stop_streaming(struct vb2_queue *vq)
35787 spin_unlock_irqrestore(&layer->enq_slock, flags);
35788
35789 /* disabling layer in hardware */
35790 - layer->ops.stream_set(layer, MXR_DISABLE);
35791 + layer->ops->stream_set(layer, MXR_DISABLE);
35792 /* remove one streamer */
35793 mxr_streamer_put(mdev);
35794 /* allow changes in output configuration */
35795 @@ -1043,8 +1043,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
35796
35797 void mxr_layer_release(struct mxr_layer *layer)
35798 {
35799 - if (layer->ops.release)
35800 - layer->ops.release(layer);
35801 + if (layer->ops->release)
35802 + layer->ops->release(layer);
35803 }
35804
35805 void mxr_base_layer_release(struct mxr_layer *layer)
35806 @@ -1070,7 +1070,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
35807
35808 layer->mdev = mdev;
35809 layer->idx = idx;
35810 - layer->ops = *ops;
35811 + layer->ops = ops;
35812
35813 spin_lock_init(&layer->enq_slock);
35814 INIT_LIST_HEAD(&layer->enq_list);
35815 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35816 index 3d13a63..da31bf1 100644
35817 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35818 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35819 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
35820 {
35821 struct mxr_layer *layer;
35822 int ret;
35823 - struct mxr_layer_ops ops = {
35824 + static struct mxr_layer_ops ops = {
35825 .release = mxr_vp_layer_release,
35826 .buffer_set = mxr_vp_buffer_set,
35827 .stream_set = mxr_vp_stream_set,
35828 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35829 index 02194c0..36d69c1 100644
35830 --- a/drivers/media/platform/timblogiw.c
35831 +++ b/drivers/media/platform/timblogiw.c
35832 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35833
35834 /* Platform device functions */
35835
35836 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35837 +static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35838 .vidioc_querycap = timblogiw_querycap,
35839 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35840 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35841 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35842 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35843 };
35844
35845 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35846 +static struct v4l2_file_operations timblogiw_fops = {
35847 .owner = THIS_MODULE,
35848 .open = timblogiw_open,
35849 .release = timblogiw_close,
35850 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35851 index 697a421..16c5a5f 100644
35852 --- a/drivers/media/radio/radio-cadet.c
35853 +++ b/drivers/media/radio/radio-cadet.c
35854 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35855 unsigned char readbuf[RDS_BUFFER];
35856 int i = 0;
35857
35858 + if (count > RDS_BUFFER)
35859 + return -EFAULT;
35860 mutex_lock(&dev->lock);
35861 if (dev->rdsstat == 0)
35862 cadet_start_rds(dev);
35863 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35864 while (i < count && dev->rdsin != dev->rdsout)
35865 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35866
35867 - if (i && copy_to_user(data, readbuf, i))
35868 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35869 i = -EFAULT;
35870 unlock:
35871 mutex_unlock(&dev->lock);
35872 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35873 index 3940bb0..fb3952a 100644
35874 --- a/drivers/media/usb/dvb-usb/cxusb.c
35875 +++ b/drivers/media/usb/dvb-usb/cxusb.c
35876 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35877
35878 struct dib0700_adapter_state {
35879 int (*set_param_save) (struct dvb_frontend *);
35880 -};
35881 +} __no_const;
35882
35883 static int dib7070_set_param_override(struct dvb_frontend *fe)
35884 {
35885 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35886 index 9382895..ac8093c 100644
35887 --- a/drivers/media/usb/dvb-usb/dw2102.c
35888 +++ b/drivers/media/usb/dvb-usb/dw2102.c
35889 @@ -95,7 +95,7 @@ struct su3000_state {
35890
35891 struct s6x0_state {
35892 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35893 -};
35894 +} __no_const;
35895
35896 /* debug */
35897 static int dvb_usb_dw2102_debug;
35898 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35899 index fb69baa..cf7ad22 100644
35900 --- a/drivers/message/fusion/mptbase.c
35901 +++ b/drivers/message/fusion/mptbase.c
35902 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35903 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35904 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35905
35906 +#ifdef CONFIG_GRKERNSEC_HIDESYM
35907 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35908 +#else
35909 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35910 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35911 +#endif
35912 +
35913 /*
35914 * Rounding UP to nearest 4-kB boundary here...
35915 */
35916 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35917 index 551262e..7551198 100644
35918 --- a/drivers/message/fusion/mptsas.c
35919 +++ b/drivers/message/fusion/mptsas.c
35920 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35921 return 0;
35922 }
35923
35924 +static inline void
35925 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35926 +{
35927 + if (phy_info->port_details) {
35928 + phy_info->port_details->rphy = rphy;
35929 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35930 + ioc->name, rphy));
35931 + }
35932 +
35933 + if (rphy) {
35934 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35935 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35936 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35937 + ioc->name, rphy, rphy->dev.release));
35938 + }
35939 +}
35940 +
35941 /* no mutex */
35942 static void
35943 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35944 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35945 return NULL;
35946 }
35947
35948 -static inline void
35949 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35950 -{
35951 - if (phy_info->port_details) {
35952 - phy_info->port_details->rphy = rphy;
35953 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35954 - ioc->name, rphy));
35955 - }
35956 -
35957 - if (rphy) {
35958 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35959 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35960 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35961 - ioc->name, rphy, rphy->dev.release));
35962 - }
35963 -}
35964 -
35965 static inline struct sas_port *
35966 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35967 {
35968 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35969 index 0c3ced7..1fe34ec 100644
35970 --- a/drivers/message/fusion/mptscsih.c
35971 +++ b/drivers/message/fusion/mptscsih.c
35972 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35973
35974 h = shost_priv(SChost);
35975
35976 - if (h) {
35977 - if (h->info_kbuf == NULL)
35978 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35979 - return h->info_kbuf;
35980 - h->info_kbuf[0] = '\0';
35981 + if (!h)
35982 + return NULL;
35983
35984 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35985 - h->info_kbuf[size-1] = '\0';
35986 - }
35987 + if (h->info_kbuf == NULL)
35988 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35989 + return h->info_kbuf;
35990 + h->info_kbuf[0] = '\0';
35991 +
35992 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35993 + h->info_kbuf[size-1] = '\0';
35994
35995 return h->info_kbuf;
35996 }
35997 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35998 index 8001aa6..b137580 100644
35999 --- a/drivers/message/i2o/i2o_proc.c
36000 +++ b/drivers/message/i2o/i2o_proc.c
36001 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
36002 "Array Controller Device"
36003 };
36004
36005 -static char *chtostr(char *tmp, u8 *chars, int n)
36006 -{
36007 - tmp[0] = 0;
36008 - return strncat(tmp, (char *)chars, n);
36009 -}
36010 -
36011 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36012 char *group)
36013 {
36014 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36015 } *result;
36016
36017 i2o_exec_execute_ddm_table ddm_table;
36018 - char tmp[28 + 1];
36019
36020 result = kmalloc(sizeof(*result), GFP_KERNEL);
36021 if (!result)
36022 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36023
36024 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36025 seq_printf(seq, "%-#8x", ddm_table.module_id);
36026 - seq_printf(seq, "%-29s",
36027 - chtostr(tmp, ddm_table.module_name_version, 28));
36028 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36029 seq_printf(seq, "%9d ", ddm_table.data_size);
36030 seq_printf(seq, "%8d", ddm_table.code_size);
36031
36032 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36033
36034 i2o_driver_result_table *result;
36035 i2o_driver_store_table *dst;
36036 - char tmp[28 + 1];
36037
36038 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36039 if (result == NULL)
36040 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36041
36042 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36043 seq_printf(seq, "%-#8x", dst->module_id);
36044 - seq_printf(seq, "%-29s",
36045 - chtostr(tmp, dst->module_name_version, 28));
36046 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36047 + seq_printf(seq, "%-.28s", dst->module_name_version);
36048 + seq_printf(seq, "%-.8s", dst->date);
36049 seq_printf(seq, "%8d ", dst->module_size);
36050 seq_printf(seq, "%8d ", dst->mpb_size);
36051 seq_printf(seq, "0x%04x", dst->module_flags);
36052 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36053 // == (allow) 512d bytes (max)
36054 static u16 *work16 = (u16 *) work32;
36055 int token;
36056 - char tmp[16 + 1];
36057
36058 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36059
36060 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36061 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36062 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36063 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36064 - seq_printf(seq, "Vendor info : %s\n",
36065 - chtostr(tmp, (u8 *) (work32 + 2), 16));
36066 - seq_printf(seq, "Product info : %s\n",
36067 - chtostr(tmp, (u8 *) (work32 + 6), 16));
36068 - seq_printf(seq, "Description : %s\n",
36069 - chtostr(tmp, (u8 *) (work32 + 10), 16));
36070 - seq_printf(seq, "Product rev. : %s\n",
36071 - chtostr(tmp, (u8 *) (work32 + 14), 8));
36072 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36073 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36074 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36075 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36076
36077 seq_printf(seq, "Serial number : ");
36078 print_serial_number(seq, (u8 *) (work32 + 16),
36079 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36080 u8 pad[256]; // allow up to 256 byte (max) serial number
36081 } result;
36082
36083 - char tmp[24 + 1];
36084 -
36085 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36086
36087 if (token < 0) {
36088 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36089 }
36090
36091 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36092 - seq_printf(seq, "Module name : %s\n",
36093 - chtostr(tmp, result.module_name, 24));
36094 - seq_printf(seq, "Module revision : %s\n",
36095 - chtostr(tmp, result.module_rev, 8));
36096 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
36097 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36098
36099 seq_printf(seq, "Serial number : ");
36100 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36101 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36102 u8 instance_number[4];
36103 } result;
36104
36105 - char tmp[64 + 1];
36106 -
36107 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36108
36109 if (token < 0) {
36110 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36111 return 0;
36112 }
36113
36114 - seq_printf(seq, "Device name : %s\n",
36115 - chtostr(tmp, result.device_name, 64));
36116 - seq_printf(seq, "Service name : %s\n",
36117 - chtostr(tmp, result.service_name, 64));
36118 - seq_printf(seq, "Physical name : %s\n",
36119 - chtostr(tmp, result.physical_location, 64));
36120 - seq_printf(seq, "Instance number : %s\n",
36121 - chtostr(tmp, result.instance_number, 4));
36122 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
36123 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
36124 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36125 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36126
36127 return 0;
36128 }
36129 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36130 index a8c08f3..155fe3d 100644
36131 --- a/drivers/message/i2o/iop.c
36132 +++ b/drivers/message/i2o/iop.c
36133 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36134
36135 spin_lock_irqsave(&c->context_list_lock, flags);
36136
36137 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36138 - atomic_inc(&c->context_list_counter);
36139 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36140 + atomic_inc_unchecked(&c->context_list_counter);
36141
36142 - entry->context = atomic_read(&c->context_list_counter);
36143 + entry->context = atomic_read_unchecked(&c->context_list_counter);
36144
36145 list_add(&entry->list, &c->context_list);
36146
36147 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36148
36149 #if BITS_PER_LONG == 64
36150 spin_lock_init(&c->context_list_lock);
36151 - atomic_set(&c->context_list_counter, 0);
36152 + atomic_set_unchecked(&c->context_list_counter, 0);
36153 INIT_LIST_HEAD(&c->context_list);
36154 #endif
36155
36156 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36157 index 965c480..71f2db9 100644
36158 --- a/drivers/mfd/janz-cmodio.c
36159 +++ b/drivers/mfd/janz-cmodio.c
36160 @@ -13,6 +13,7 @@
36161
36162 #include <linux/kernel.h>
36163 #include <linux/module.h>
36164 +#include <linux/slab.h>
36165 #include <linux/init.h>
36166 #include <linux/pci.h>
36167 #include <linux/interrupt.h>
36168 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36169 index 3aa9a96..59cf685 100644
36170 --- a/drivers/misc/kgdbts.c
36171 +++ b/drivers/misc/kgdbts.c
36172 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36173 char before[BREAK_INSTR_SIZE];
36174 char after[BREAK_INSTR_SIZE];
36175
36176 - probe_kernel_read(before, (char *)kgdbts_break_test,
36177 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36178 BREAK_INSTR_SIZE);
36179 init_simple_test();
36180 ts.tst = plant_and_detach_test;
36181 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36182 /* Activate test with initial breakpoint */
36183 if (!is_early)
36184 kgdb_breakpoint();
36185 - probe_kernel_read(after, (char *)kgdbts_break_test,
36186 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36187 BREAK_INSTR_SIZE);
36188 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36189 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36190 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36191 index 4a87e5c..76bdf5c 100644
36192 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
36193 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36194 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36195 * the lid is closed. This leads to interrupts as soon as a little move
36196 * is done.
36197 */
36198 - atomic_inc(&lis3->count);
36199 + atomic_inc_unchecked(&lis3->count);
36200
36201 wake_up_interruptible(&lis3->misc_wait);
36202 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36203 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36204 if (lis3->pm_dev)
36205 pm_runtime_get_sync(lis3->pm_dev);
36206
36207 - atomic_set(&lis3->count, 0);
36208 + atomic_set_unchecked(&lis3->count, 0);
36209 return 0;
36210 }
36211
36212 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36213 add_wait_queue(&lis3->misc_wait, &wait);
36214 while (true) {
36215 set_current_state(TASK_INTERRUPTIBLE);
36216 - data = atomic_xchg(&lis3->count, 0);
36217 + data = atomic_xchg_unchecked(&lis3->count, 0);
36218 if (data)
36219 break;
36220
36221 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36222 struct lis3lv02d, miscdev);
36223
36224 poll_wait(file, &lis3->misc_wait, wait);
36225 - if (atomic_read(&lis3->count))
36226 + if (atomic_read_unchecked(&lis3->count))
36227 return POLLIN | POLLRDNORM;
36228 return 0;
36229 }
36230 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36231 index c439c82..1f20f57 100644
36232 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
36233 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36234 @@ -297,7 +297,7 @@ struct lis3lv02d {
36235 struct input_polled_dev *idev; /* input device */
36236 struct platform_device *pdev; /* platform device */
36237 struct regulator_bulk_data regulators[2];
36238 - atomic_t count; /* interrupt count after last read */
36239 + atomic_unchecked_t count; /* interrupt count after last read */
36240 union axis_conversion ac; /* hw -> logical axis */
36241 int mapped_btns[3];
36242
36243 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36244 index 2f30bad..c4c13d0 100644
36245 --- a/drivers/misc/sgi-gru/gruhandles.c
36246 +++ b/drivers/misc/sgi-gru/gruhandles.c
36247 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36248 unsigned long nsec;
36249
36250 nsec = CLKS2NSEC(clks);
36251 - atomic_long_inc(&mcs_op_statistics[op].count);
36252 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
36253 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36254 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36255 if (mcs_op_statistics[op].max < nsec)
36256 mcs_op_statistics[op].max = nsec;
36257 }
36258 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36259 index 950dbe9..eeef0f8 100644
36260 --- a/drivers/misc/sgi-gru/gruprocfs.c
36261 +++ b/drivers/misc/sgi-gru/gruprocfs.c
36262 @@ -32,9 +32,9 @@
36263
36264 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36265
36266 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36267 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36268 {
36269 - unsigned long val = atomic_long_read(v);
36270 + unsigned long val = atomic_long_read_unchecked(v);
36271
36272 seq_printf(s, "%16lu %s\n", val, id);
36273 }
36274 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36275
36276 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36277 for (op = 0; op < mcsop_last; op++) {
36278 - count = atomic_long_read(&mcs_op_statistics[op].count);
36279 - total = atomic_long_read(&mcs_op_statistics[op].total);
36280 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36281 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36282 max = mcs_op_statistics[op].max;
36283 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36284 count ? total / count : 0, max);
36285 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36286 index 5c3ce24..4915ccb 100644
36287 --- a/drivers/misc/sgi-gru/grutables.h
36288 +++ b/drivers/misc/sgi-gru/grutables.h
36289 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36290 * GRU statistics.
36291 */
36292 struct gru_stats_s {
36293 - atomic_long_t vdata_alloc;
36294 - atomic_long_t vdata_free;
36295 - atomic_long_t gts_alloc;
36296 - atomic_long_t gts_free;
36297 - atomic_long_t gms_alloc;
36298 - atomic_long_t gms_free;
36299 - atomic_long_t gts_double_allocate;
36300 - atomic_long_t assign_context;
36301 - atomic_long_t assign_context_failed;
36302 - atomic_long_t free_context;
36303 - atomic_long_t load_user_context;
36304 - atomic_long_t load_kernel_context;
36305 - atomic_long_t lock_kernel_context;
36306 - atomic_long_t unlock_kernel_context;
36307 - atomic_long_t steal_user_context;
36308 - atomic_long_t steal_kernel_context;
36309 - atomic_long_t steal_context_failed;
36310 - atomic_long_t nopfn;
36311 - atomic_long_t asid_new;
36312 - atomic_long_t asid_next;
36313 - atomic_long_t asid_wrap;
36314 - atomic_long_t asid_reuse;
36315 - atomic_long_t intr;
36316 - atomic_long_t intr_cbr;
36317 - atomic_long_t intr_tfh;
36318 - atomic_long_t intr_spurious;
36319 - atomic_long_t intr_mm_lock_failed;
36320 - atomic_long_t call_os;
36321 - atomic_long_t call_os_wait_queue;
36322 - atomic_long_t user_flush_tlb;
36323 - atomic_long_t user_unload_context;
36324 - atomic_long_t user_exception;
36325 - atomic_long_t set_context_option;
36326 - atomic_long_t check_context_retarget_intr;
36327 - atomic_long_t check_context_unload;
36328 - atomic_long_t tlb_dropin;
36329 - atomic_long_t tlb_preload_page;
36330 - atomic_long_t tlb_dropin_fail_no_asid;
36331 - atomic_long_t tlb_dropin_fail_upm;
36332 - atomic_long_t tlb_dropin_fail_invalid;
36333 - atomic_long_t tlb_dropin_fail_range_active;
36334 - atomic_long_t tlb_dropin_fail_idle;
36335 - atomic_long_t tlb_dropin_fail_fmm;
36336 - atomic_long_t tlb_dropin_fail_no_exception;
36337 - atomic_long_t tfh_stale_on_fault;
36338 - atomic_long_t mmu_invalidate_range;
36339 - atomic_long_t mmu_invalidate_page;
36340 - atomic_long_t flush_tlb;
36341 - atomic_long_t flush_tlb_gru;
36342 - atomic_long_t flush_tlb_gru_tgh;
36343 - atomic_long_t flush_tlb_gru_zero_asid;
36344 + atomic_long_unchecked_t vdata_alloc;
36345 + atomic_long_unchecked_t vdata_free;
36346 + atomic_long_unchecked_t gts_alloc;
36347 + atomic_long_unchecked_t gts_free;
36348 + atomic_long_unchecked_t gms_alloc;
36349 + atomic_long_unchecked_t gms_free;
36350 + atomic_long_unchecked_t gts_double_allocate;
36351 + atomic_long_unchecked_t assign_context;
36352 + atomic_long_unchecked_t assign_context_failed;
36353 + atomic_long_unchecked_t free_context;
36354 + atomic_long_unchecked_t load_user_context;
36355 + atomic_long_unchecked_t load_kernel_context;
36356 + atomic_long_unchecked_t lock_kernel_context;
36357 + atomic_long_unchecked_t unlock_kernel_context;
36358 + atomic_long_unchecked_t steal_user_context;
36359 + atomic_long_unchecked_t steal_kernel_context;
36360 + atomic_long_unchecked_t steal_context_failed;
36361 + atomic_long_unchecked_t nopfn;
36362 + atomic_long_unchecked_t asid_new;
36363 + atomic_long_unchecked_t asid_next;
36364 + atomic_long_unchecked_t asid_wrap;
36365 + atomic_long_unchecked_t asid_reuse;
36366 + atomic_long_unchecked_t intr;
36367 + atomic_long_unchecked_t intr_cbr;
36368 + atomic_long_unchecked_t intr_tfh;
36369 + atomic_long_unchecked_t intr_spurious;
36370 + atomic_long_unchecked_t intr_mm_lock_failed;
36371 + atomic_long_unchecked_t call_os;
36372 + atomic_long_unchecked_t call_os_wait_queue;
36373 + atomic_long_unchecked_t user_flush_tlb;
36374 + atomic_long_unchecked_t user_unload_context;
36375 + atomic_long_unchecked_t user_exception;
36376 + atomic_long_unchecked_t set_context_option;
36377 + atomic_long_unchecked_t check_context_retarget_intr;
36378 + atomic_long_unchecked_t check_context_unload;
36379 + atomic_long_unchecked_t tlb_dropin;
36380 + atomic_long_unchecked_t tlb_preload_page;
36381 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
36382 + atomic_long_unchecked_t tlb_dropin_fail_upm;
36383 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
36384 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
36385 + atomic_long_unchecked_t tlb_dropin_fail_idle;
36386 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
36387 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
36388 + atomic_long_unchecked_t tfh_stale_on_fault;
36389 + atomic_long_unchecked_t mmu_invalidate_range;
36390 + atomic_long_unchecked_t mmu_invalidate_page;
36391 + atomic_long_unchecked_t flush_tlb;
36392 + atomic_long_unchecked_t flush_tlb_gru;
36393 + atomic_long_unchecked_t flush_tlb_gru_tgh;
36394 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
36395
36396 - atomic_long_t copy_gpa;
36397 - atomic_long_t read_gpa;
36398 + atomic_long_unchecked_t copy_gpa;
36399 + atomic_long_unchecked_t read_gpa;
36400
36401 - atomic_long_t mesq_receive;
36402 - atomic_long_t mesq_receive_none;
36403 - atomic_long_t mesq_send;
36404 - atomic_long_t mesq_send_failed;
36405 - atomic_long_t mesq_noop;
36406 - atomic_long_t mesq_send_unexpected_error;
36407 - atomic_long_t mesq_send_lb_overflow;
36408 - atomic_long_t mesq_send_qlimit_reached;
36409 - atomic_long_t mesq_send_amo_nacked;
36410 - atomic_long_t mesq_send_put_nacked;
36411 - atomic_long_t mesq_page_overflow;
36412 - atomic_long_t mesq_qf_locked;
36413 - atomic_long_t mesq_qf_noop_not_full;
36414 - atomic_long_t mesq_qf_switch_head_failed;
36415 - atomic_long_t mesq_qf_unexpected_error;
36416 - atomic_long_t mesq_noop_unexpected_error;
36417 - atomic_long_t mesq_noop_lb_overflow;
36418 - atomic_long_t mesq_noop_qlimit_reached;
36419 - atomic_long_t mesq_noop_amo_nacked;
36420 - atomic_long_t mesq_noop_put_nacked;
36421 - atomic_long_t mesq_noop_page_overflow;
36422 + atomic_long_unchecked_t mesq_receive;
36423 + atomic_long_unchecked_t mesq_receive_none;
36424 + atomic_long_unchecked_t mesq_send;
36425 + atomic_long_unchecked_t mesq_send_failed;
36426 + atomic_long_unchecked_t mesq_noop;
36427 + atomic_long_unchecked_t mesq_send_unexpected_error;
36428 + atomic_long_unchecked_t mesq_send_lb_overflow;
36429 + atomic_long_unchecked_t mesq_send_qlimit_reached;
36430 + atomic_long_unchecked_t mesq_send_amo_nacked;
36431 + atomic_long_unchecked_t mesq_send_put_nacked;
36432 + atomic_long_unchecked_t mesq_page_overflow;
36433 + atomic_long_unchecked_t mesq_qf_locked;
36434 + atomic_long_unchecked_t mesq_qf_noop_not_full;
36435 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
36436 + atomic_long_unchecked_t mesq_qf_unexpected_error;
36437 + atomic_long_unchecked_t mesq_noop_unexpected_error;
36438 + atomic_long_unchecked_t mesq_noop_lb_overflow;
36439 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
36440 + atomic_long_unchecked_t mesq_noop_amo_nacked;
36441 + atomic_long_unchecked_t mesq_noop_put_nacked;
36442 + atomic_long_unchecked_t mesq_noop_page_overflow;
36443
36444 };
36445
36446 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
36447 tghop_invalidate, mcsop_last};
36448
36449 struct mcs_op_statistic {
36450 - atomic_long_t count;
36451 - atomic_long_t total;
36452 + atomic_long_unchecked_t count;
36453 + atomic_long_unchecked_t total;
36454 unsigned long max;
36455 };
36456
36457 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
36458
36459 #define STAT(id) do { \
36460 if (gru_options & OPT_STATS) \
36461 - atomic_long_inc(&gru_stats.id); \
36462 + atomic_long_inc_unchecked(&gru_stats.id); \
36463 } while (0)
36464
36465 #ifdef CONFIG_SGI_GRU_DEBUG
36466 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
36467 index c862cd4..0d176fe 100644
36468 --- a/drivers/misc/sgi-xp/xp.h
36469 +++ b/drivers/misc/sgi-xp/xp.h
36470 @@ -288,7 +288,7 @@ struct xpc_interface {
36471 xpc_notify_func, void *);
36472 void (*received) (short, int, void *);
36473 enum xp_retval (*partid_to_nasids) (short, void *);
36474 -};
36475 +} __no_const;
36476
36477 extern struct xpc_interface xpc_interface;
36478
36479 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
36480 index b94d5f7..7f494c5 100644
36481 --- a/drivers/misc/sgi-xp/xpc.h
36482 +++ b/drivers/misc/sgi-xp/xpc.h
36483 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
36484 void (*received_payload) (struct xpc_channel *, void *);
36485 void (*notify_senders_of_disconnect) (struct xpc_channel *);
36486 };
36487 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
36488
36489 /* struct xpc_partition act_state values (for XPC HB) */
36490
36491 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
36492 /* found in xpc_main.c */
36493 extern struct device *xpc_part;
36494 extern struct device *xpc_chan;
36495 -extern struct xpc_arch_operations xpc_arch_ops;
36496 +extern xpc_arch_operations_no_const xpc_arch_ops;
36497 extern int xpc_disengage_timelimit;
36498 extern int xpc_disengage_timedout;
36499 extern int xpc_activate_IRQ_rcvd;
36500 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
36501 index d971817..33bdca5 100644
36502 --- a/drivers/misc/sgi-xp/xpc_main.c
36503 +++ b/drivers/misc/sgi-xp/xpc_main.c
36504 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
36505 .notifier_call = xpc_system_die,
36506 };
36507
36508 -struct xpc_arch_operations xpc_arch_ops;
36509 +xpc_arch_operations_no_const xpc_arch_ops;
36510
36511 /*
36512 * Timer function to enforce the timelimit on the partition disengage.
36513 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
36514
36515 if (((die_args->trapnr == X86_TRAP_MF) ||
36516 (die_args->trapnr == X86_TRAP_XF)) &&
36517 - !user_mode_vm(die_args->regs))
36518 + !user_mode(die_args->regs))
36519 xpc_die_deactivate();
36520
36521 break;
36522 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
36523 index a0e1720..ee63d0b 100644
36524 --- a/drivers/mmc/core/mmc_ops.c
36525 +++ b/drivers/mmc/core/mmc_ops.c
36526 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
36527 void *data_buf;
36528 int is_on_stack;
36529
36530 - is_on_stack = object_is_on_stack(buf);
36531 + is_on_stack = object_starts_on_stack(buf);
36532 if (is_on_stack) {
36533 /*
36534 * dma onto stack is unsafe/nonportable, but callers to this
36535 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36536 index 53b8fd9..615b462 100644
36537 --- a/drivers/mmc/host/dw_mmc.h
36538 +++ b/drivers/mmc/host/dw_mmc.h
36539 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36540 int (*parse_dt)(struct dw_mci *host);
36541 int (*setup_bus)(struct dw_mci *host,
36542 struct device_node *slot_np, u8 bus_width);
36543 -};
36544 +} __do_const;
36545 #endif /* _DW_MMC_H_ */
36546 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
36547 index c9ec725..178e79a 100644
36548 --- a/drivers/mmc/host/sdhci-s3c.c
36549 +++ b/drivers/mmc/host/sdhci-s3c.c
36550 @@ -719,9 +719,11 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
36551 * we can use overriding functions instead of default.
36552 */
36553 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
36554 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36555 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36556 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36557 + pax_open_kernel();
36558 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36559 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36560 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36561 + pax_close_kernel();
36562 }
36563
36564 /* It supports additional host capabilities if needed */
36565 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36566 index a4eb8b5..8c0628f 100644
36567 --- a/drivers/mtd/devices/doc2000.c
36568 +++ b/drivers/mtd/devices/doc2000.c
36569 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36570
36571 /* The ECC will not be calculated correctly if less than 512 is written */
36572 /* DBB-
36573 - if (len != 0x200 && eccbuf)
36574 + if (len != 0x200)
36575 printk(KERN_WARNING
36576 "ECC needs a full sector write (adr: %lx size %lx)\n",
36577 (long) to, (long) len);
36578 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36579 index e706a23..b3d262f 100644
36580 --- a/drivers/mtd/nand/denali.c
36581 +++ b/drivers/mtd/nand/denali.c
36582 @@ -26,6 +26,7 @@
36583 #include <linux/pci.h>
36584 #include <linux/mtd/mtd.h>
36585 #include <linux/module.h>
36586 +#include <linux/slab.h>
36587
36588 #include "denali.h"
36589
36590 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36591 index 51b9d6a..52af9a7 100644
36592 --- a/drivers/mtd/nftlmount.c
36593 +++ b/drivers/mtd/nftlmount.c
36594 @@ -24,6 +24,7 @@
36595 #include <asm/errno.h>
36596 #include <linux/delay.h>
36597 #include <linux/slab.h>
36598 +#include <linux/sched.h>
36599 #include <linux/mtd/mtd.h>
36600 #include <linux/mtd/nand.h>
36601 #include <linux/mtd/nftl.h>
36602 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36603 index 203ff9d..0968ca8 100644
36604 --- a/drivers/net/ethernet/8390/ax88796.c
36605 +++ b/drivers/net/ethernet/8390/ax88796.c
36606 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36607 if (ax->plat->reg_offsets)
36608 ei_local->reg_offset = ax->plat->reg_offsets;
36609 else {
36610 + resource_size_t _mem_size = mem_size;
36611 + do_div(_mem_size, 0x18);
36612 ei_local->reg_offset = ax->reg_offsets;
36613 for (ret = 0; ret < 0x18; ret++)
36614 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36615 + ax->reg_offsets[ret] = _mem_size * ret;
36616 }
36617
36618 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36619 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36620 index 9c5ea6c..eaad276 100644
36621 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36622 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36623 @@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36624 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36625 {
36626 /* RX_MODE controlling object */
36627 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36628 + bnx2x_init_rx_mode_obj(bp);
36629
36630 /* multicast configuration controlling object */
36631 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36632 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36633 index 614981c..11216c7 100644
36634 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36635 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36636 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36637 return rc;
36638 }
36639
36640 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36641 - struct bnx2x_rx_mode_obj *o)
36642 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36643 {
36644 if (CHIP_IS_E1x(bp)) {
36645 - o->wait_comp = bnx2x_empty_rx_mode_wait;
36646 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36647 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36648 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36649 } else {
36650 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36651 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
36652 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36653 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36654 }
36655 }
36656
36657 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36658 index acf2fe4..efb96df 100644
36659 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36660 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36661 @@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36662
36663 /********************* RX MODE ****************/
36664
36665 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36666 - struct bnx2x_rx_mode_obj *o);
36667 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36668
36669 /**
36670 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36671 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36672 index d9308c32..d87b824 100644
36673 --- a/drivers/net/ethernet/broadcom/tg3.h
36674 +++ b/drivers/net/ethernet/broadcom/tg3.h
36675 @@ -140,6 +140,7 @@
36676 #define CHIPREV_ID_5750_A0 0x4000
36677 #define CHIPREV_ID_5750_A1 0x4001
36678 #define CHIPREV_ID_5750_A3 0x4003
36679 +#define CHIPREV_ID_5750_C1 0x4201
36680 #define CHIPREV_ID_5750_C2 0x4202
36681 #define CHIPREV_ID_5752_A0_HW 0x5000
36682 #define CHIPREV_ID_5752_A0 0x6000
36683 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36684 index 8cffcdf..aadf043 100644
36685 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36686 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36687 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36688 */
36689 struct l2t_skb_cb {
36690 arp_failure_handler_func arp_failure_handler;
36691 -};
36692 +} __no_const;
36693
36694 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36695
36696 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36697 index f879e92..726f20f 100644
36698 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
36699 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36700 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36701 for (i=0; i<ETH_ALEN; i++) {
36702 tmp.addr[i] = dev->dev_addr[i];
36703 }
36704 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36705 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36706 break;
36707
36708 case DE4X5_SET_HWADDR: /* Set the hardware address */
36709 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36710 spin_lock_irqsave(&lp->lock, flags);
36711 memcpy(&statbuf, &lp->pktStats, ioc->len);
36712 spin_unlock_irqrestore(&lp->lock, flags);
36713 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
36714 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36715 return -EFAULT;
36716 break;
36717 }
36718 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36719 index d1b6cc5..cde0d97 100644
36720 --- a/drivers/net/ethernet/emulex/benet/be_main.c
36721 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
36722 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36723
36724 if (wrapped)
36725 newacc += 65536;
36726 - ACCESS_ONCE(*acc) = newacc;
36727 + ACCESS_ONCE_RW(*acc) = newacc;
36728 }
36729
36730 void be_parse_stats(struct be_adapter *adapter)
36731 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36732 index 74d749e..eefb1bd 100644
36733 --- a/drivers/net/ethernet/faraday/ftgmac100.c
36734 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
36735 @@ -31,6 +31,8 @@
36736 #include <linux/netdevice.h>
36737 #include <linux/phy.h>
36738 #include <linux/platform_device.h>
36739 +#include <linux/interrupt.h>
36740 +#include <linux/irqreturn.h>
36741 #include <net/ip.h>
36742
36743 #include "ftgmac100.h"
36744 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36745 index b901a01..1ff32ee 100644
36746 --- a/drivers/net/ethernet/faraday/ftmac100.c
36747 +++ b/drivers/net/ethernet/faraday/ftmac100.c
36748 @@ -31,6 +31,8 @@
36749 #include <linux/module.h>
36750 #include <linux/netdevice.h>
36751 #include <linux/platform_device.h>
36752 +#include <linux/interrupt.h>
36753 +#include <linux/irqreturn.h>
36754
36755 #include "ftmac100.h"
36756
36757 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36758 index d929131..aed108f 100644
36759 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36760 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36761 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36762 /* store the new cycle speed */
36763 adapter->cycle_speed = cycle_speed;
36764
36765 - ACCESS_ONCE(adapter->base_incval) = incval;
36766 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
36767 smp_mb();
36768
36769 /* grab the ptp lock */
36770 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36771 index c2e420a..26a75e0 100644
36772 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36773 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36774 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36775 struct __vxge_hw_fifo *fifo;
36776 struct vxge_hw_fifo_config *config;
36777 u32 txdl_size, txdl_per_memblock;
36778 - struct vxge_hw_mempool_cbs fifo_mp_callback;
36779 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36780 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36781 + };
36782 +
36783 struct __vxge_hw_virtualpath *vpath;
36784
36785 if ((vp == NULL) || (attr == NULL)) {
36786 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36787 goto exit;
36788 }
36789
36790 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36791 -
36792 fifo->mempool =
36793 __vxge_hw_mempool_create(vpath->hldev,
36794 fifo->config->memblock_size,
36795 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36796 index 927aa33..a6c2518 100644
36797 --- a/drivers/net/ethernet/realtek/r8169.c
36798 +++ b/drivers/net/ethernet/realtek/r8169.c
36799 @@ -747,22 +747,22 @@ struct rtl8169_private {
36800 struct mdio_ops {
36801 void (*write)(struct rtl8169_private *, int, int);
36802 int (*read)(struct rtl8169_private *, int);
36803 - } mdio_ops;
36804 + } __no_const mdio_ops;
36805
36806 struct pll_power_ops {
36807 void (*down)(struct rtl8169_private *);
36808 void (*up)(struct rtl8169_private *);
36809 - } pll_power_ops;
36810 + } __no_const pll_power_ops;
36811
36812 struct jumbo_ops {
36813 void (*enable)(struct rtl8169_private *);
36814 void (*disable)(struct rtl8169_private *);
36815 - } jumbo_ops;
36816 + } __no_const jumbo_ops;
36817
36818 struct csi_ops {
36819 void (*write)(struct rtl8169_private *, int, int);
36820 u32 (*read)(struct rtl8169_private *, int);
36821 - } csi_ops;
36822 + } __no_const csi_ops;
36823
36824 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36825 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36826 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36827 index 0767043f..08c2553 100644
36828 --- a/drivers/net/ethernet/sfc/ptp.c
36829 +++ b/drivers/net/ethernet/sfc/ptp.c
36830 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36831 (u32)((u64)ptp->start.dma_addr >> 32));
36832
36833 /* Clear flag that signals MC ready */
36834 - ACCESS_ONCE(*start) = 0;
36835 + ACCESS_ONCE_RW(*start) = 0;
36836 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36837 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36838
36839 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36840 index 0c74a70..3bc6f68 100644
36841 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36842 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36843 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36844
36845 writel(value, ioaddr + MMC_CNTRL);
36846
36847 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36848 - MMC_CNTRL, value);
36849 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36850 +// MMC_CNTRL, value);
36851 }
36852
36853 /* To mask all all interrupts.*/
36854 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36855 index 5fd6f46..ee1f265 100644
36856 --- a/drivers/net/hyperv/hyperv_net.h
36857 +++ b/drivers/net/hyperv/hyperv_net.h
36858 @@ -101,7 +101,7 @@ struct rndis_device {
36859
36860 enum rndis_device_state state;
36861 bool link_state;
36862 - atomic_t new_req_id;
36863 + atomic_unchecked_t new_req_id;
36864
36865 spinlock_t request_lock;
36866 struct list_head req_list;
36867 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36868 index 928148c..d83298e 100644
36869 --- a/drivers/net/hyperv/rndis_filter.c
36870 +++ b/drivers/net/hyperv/rndis_filter.c
36871 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36872 * template
36873 */
36874 set = &rndis_msg->msg.set_req;
36875 - set->req_id = atomic_inc_return(&dev->new_req_id);
36876 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36877
36878 /* Add to the request list */
36879 spin_lock_irqsave(&dev->request_lock, flags);
36880 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36881
36882 /* Setup the rndis set */
36883 halt = &request->request_msg.msg.halt_req;
36884 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36885 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36886
36887 /* Ignore return since this msg is optional. */
36888 rndis_filter_send_request(dev, request);
36889 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36890 index 7d39add..037e1da 100644
36891 --- a/drivers/net/ieee802154/fakehard.c
36892 +++ b/drivers/net/ieee802154/fakehard.c
36893 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36894 phy->transmit_power = 0xbf;
36895
36896 dev->netdev_ops = &fake_ops;
36897 - dev->ml_priv = &fake_mlme;
36898 + dev->ml_priv = (void *)&fake_mlme;
36899
36900 priv = netdev_priv(dev);
36901 priv->phy = phy;
36902 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36903 index 0f0f9ce..0ca5819 100644
36904 --- a/drivers/net/macvtap.c
36905 +++ b/drivers/net/macvtap.c
36906 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36907 return NOTIFY_DONE;
36908 }
36909
36910 -static struct notifier_block macvtap_notifier_block __read_mostly = {
36911 +static struct notifier_block macvtap_notifier_block = {
36912 .notifier_call = macvtap_device_event,
36913 };
36914
36915 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36916 index daec9b0..6428fcb 100644
36917 --- a/drivers/net/phy/mdio-bitbang.c
36918 +++ b/drivers/net/phy/mdio-bitbang.c
36919 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36920 struct mdiobb_ctrl *ctrl = bus->priv;
36921
36922 module_put(ctrl->ops->owner);
36923 + mdiobus_unregister(bus);
36924 mdiobus_free(bus);
36925 }
36926 EXPORT_SYMBOL(free_mdio_bitbang);
36927 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36928 index eb3f5ce..d773730 100644
36929 --- a/drivers/net/ppp/ppp_generic.c
36930 +++ b/drivers/net/ppp/ppp_generic.c
36931 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36932 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36933 struct ppp_stats stats;
36934 struct ppp_comp_stats cstats;
36935 - char *vers;
36936
36937 switch (cmd) {
36938 case SIOCGPPPSTATS:
36939 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36940 break;
36941
36942 case SIOCGPPPVER:
36943 - vers = PPP_VERSION;
36944 - if (copy_to_user(addr, vers, strlen(vers) + 1))
36945 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36946 break;
36947 err = 0;
36948 break;
36949 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36950 index ad86660..9fd0884 100644
36951 --- a/drivers/net/team/team.c
36952 +++ b/drivers/net/team/team.c
36953 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36954 return NOTIFY_DONE;
36955 }
36956
36957 -static struct notifier_block team_notifier_block __read_mostly = {
36958 +static struct notifier_block team_notifier_block = {
36959 .notifier_call = team_device_event,
36960 };
36961
36962 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36963 index 0873cdc..ddb178e 100644
36964 --- a/drivers/net/tun.c
36965 +++ b/drivers/net/tun.c
36966 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36967 }
36968
36969 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36970 - unsigned long arg, int ifreq_len)
36971 + unsigned long arg, size_t ifreq_len)
36972 {
36973 struct tun_file *tfile = file->private_data;
36974 struct tun_struct *tun;
36975 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36976 int vnet_hdr_sz;
36977 int ret;
36978
36979 + if (ifreq_len > sizeof ifr)
36980 + return -EFAULT;
36981 +
36982 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36983 if (copy_from_user(&ifr, argp, ifreq_len))
36984 return -EFAULT;
36985 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36986 index 605a4ba..a883dd1 100644
36987 --- a/drivers/net/usb/hso.c
36988 +++ b/drivers/net/usb/hso.c
36989 @@ -71,7 +71,7 @@
36990 #include <asm/byteorder.h>
36991 #include <linux/serial_core.h>
36992 #include <linux/serial.h>
36993 -
36994 +#include <asm/local.h>
36995
36996 #define MOD_AUTHOR "Option Wireless"
36997 #define MOD_DESCRIPTION "USB High Speed Option driver"
36998 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36999 struct urb *urb;
37000
37001 urb = serial->rx_urb[0];
37002 - if (serial->port.count > 0) {
37003 + if (atomic_read(&serial->port.count) > 0) {
37004 count = put_rxbuf_data(urb, serial);
37005 if (count == -1)
37006 return;
37007 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
37008 DUMP1(urb->transfer_buffer, urb->actual_length);
37009
37010 /* Anyone listening? */
37011 - if (serial->port.count == 0)
37012 + if (atomic_read(&serial->port.count) == 0)
37013 return;
37014
37015 if (status == 0) {
37016 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37017 tty_port_tty_set(&serial->port, tty);
37018
37019 /* check for port already opened, if not set the termios */
37020 - serial->port.count++;
37021 - if (serial->port.count == 1) {
37022 + if (atomic_inc_return(&serial->port.count) == 1) {
37023 serial->rx_state = RX_IDLE;
37024 /* Force default termio settings */
37025 _hso_serial_set_termios(tty, NULL);
37026 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37027 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37028 if (result) {
37029 hso_stop_serial_device(serial->parent);
37030 - serial->port.count--;
37031 + atomic_dec(&serial->port.count);
37032 kref_put(&serial->parent->ref, hso_serial_ref_free);
37033 }
37034 } else {
37035 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37036
37037 /* reset the rts and dtr */
37038 /* do the actual close */
37039 - serial->port.count--;
37040 + atomic_dec(&serial->port.count);
37041
37042 - if (serial->port.count <= 0) {
37043 - serial->port.count = 0;
37044 + if (atomic_read(&serial->port.count) <= 0) {
37045 + atomic_set(&serial->port.count, 0);
37046 tty_port_tty_set(&serial->port, NULL);
37047 if (!usb_gone)
37048 hso_stop_serial_device(serial->parent);
37049 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37050
37051 /* the actual setup */
37052 spin_lock_irqsave(&serial->serial_lock, flags);
37053 - if (serial->port.count)
37054 + if (atomic_read(&serial->port.count))
37055 _hso_serial_set_termios(tty, old);
37056 else
37057 tty->termios = *old;
37058 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37059 D1("Pending read interrupt on port %d\n", i);
37060 spin_lock(&serial->serial_lock);
37061 if (serial->rx_state == RX_IDLE &&
37062 - serial->port.count > 0) {
37063 + atomic_read(&serial->port.count) > 0) {
37064 /* Setup and send a ctrl req read on
37065 * port i */
37066 if (!serial->rx_urb_filled[0]) {
37067 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
37068 /* Start all serial ports */
37069 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37070 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37071 - if (dev2ser(serial_table[i])->port.count) {
37072 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37073 result =
37074 hso_start_serial_device(serial_table[i], GFP_NOIO);
37075 hso_kick_transmit(dev2ser(serial_table[i]));
37076 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37077 index 8d78253..bebbb68 100644
37078 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37079 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37080 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37081 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37082 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37083
37084 - ACCESS_ONCE(ads->ds_link) = i->link;
37085 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37086 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
37087 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37088
37089 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37090 ctl6 = SM(i->keytype, AR_EncrType);
37091 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37092
37093 if ((i->is_first || i->is_last) &&
37094 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37095 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37096 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37097 | set11nTries(i->rates, 1)
37098 | set11nTries(i->rates, 2)
37099 | set11nTries(i->rates, 3)
37100 | (i->dur_update ? AR_DurUpdateEna : 0)
37101 | SM(0, AR_BurstDur);
37102
37103 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37104 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37105 | set11nRate(i->rates, 1)
37106 | set11nRate(i->rates, 2)
37107 | set11nRate(i->rates, 3);
37108 } else {
37109 - ACCESS_ONCE(ads->ds_ctl2) = 0;
37110 - ACCESS_ONCE(ads->ds_ctl3) = 0;
37111 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37112 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37113 }
37114
37115 if (!i->is_first) {
37116 - ACCESS_ONCE(ads->ds_ctl0) = 0;
37117 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37118 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37119 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37120 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37121 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37122 return;
37123 }
37124
37125 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37126 break;
37127 }
37128
37129 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37130 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37131 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37132 | SM(i->txpower, AR_XmitPower)
37133 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37134 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37135 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37136 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37137
37138 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37139 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37140 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37141 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37142
37143 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37144 return;
37145
37146 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37147 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37148 | set11nPktDurRTSCTS(i->rates, 1);
37149
37150 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37151 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37152 | set11nPktDurRTSCTS(i->rates, 3);
37153
37154 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37155 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37156 | set11nRateFlags(i->rates, 1)
37157 | set11nRateFlags(i->rates, 2)
37158 | set11nRateFlags(i->rates, 3)
37159 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37160 index 301bf72..3f5654f 100644
37161 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37162 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37163 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37164 (i->qcu << AR_TxQcuNum_S) | desc_len;
37165
37166 checksum += val;
37167 - ACCESS_ONCE(ads->info) = val;
37168 + ACCESS_ONCE_RW(ads->info) = val;
37169
37170 checksum += i->link;
37171 - ACCESS_ONCE(ads->link) = i->link;
37172 + ACCESS_ONCE_RW(ads->link) = i->link;
37173
37174 checksum += i->buf_addr[0];
37175 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37176 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37177 checksum += i->buf_addr[1];
37178 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37179 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37180 checksum += i->buf_addr[2];
37181 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37182 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37183 checksum += i->buf_addr[3];
37184 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37185 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37186
37187 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37188 - ACCESS_ONCE(ads->ctl3) = val;
37189 + ACCESS_ONCE_RW(ads->ctl3) = val;
37190 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37191 - ACCESS_ONCE(ads->ctl5) = val;
37192 + ACCESS_ONCE_RW(ads->ctl5) = val;
37193 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37194 - ACCESS_ONCE(ads->ctl7) = val;
37195 + ACCESS_ONCE_RW(ads->ctl7) = val;
37196 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37197 - ACCESS_ONCE(ads->ctl9) = val;
37198 + ACCESS_ONCE_RW(ads->ctl9) = val;
37199
37200 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37201 - ACCESS_ONCE(ads->ctl10) = checksum;
37202 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
37203
37204 if (i->is_first || i->is_last) {
37205 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37206 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37207 | set11nTries(i->rates, 1)
37208 | set11nTries(i->rates, 2)
37209 | set11nTries(i->rates, 3)
37210 | (i->dur_update ? AR_DurUpdateEna : 0)
37211 | SM(0, AR_BurstDur);
37212
37213 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37214 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37215 | set11nRate(i->rates, 1)
37216 | set11nRate(i->rates, 2)
37217 | set11nRate(i->rates, 3);
37218 } else {
37219 - ACCESS_ONCE(ads->ctl13) = 0;
37220 - ACCESS_ONCE(ads->ctl14) = 0;
37221 + ACCESS_ONCE_RW(ads->ctl13) = 0;
37222 + ACCESS_ONCE_RW(ads->ctl14) = 0;
37223 }
37224
37225 ads->ctl20 = 0;
37226 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37227
37228 ctl17 = SM(i->keytype, AR_EncrType);
37229 if (!i->is_first) {
37230 - ACCESS_ONCE(ads->ctl11) = 0;
37231 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37232 - ACCESS_ONCE(ads->ctl15) = 0;
37233 - ACCESS_ONCE(ads->ctl16) = 0;
37234 - ACCESS_ONCE(ads->ctl17) = ctl17;
37235 - ACCESS_ONCE(ads->ctl18) = 0;
37236 - ACCESS_ONCE(ads->ctl19) = 0;
37237 + ACCESS_ONCE_RW(ads->ctl11) = 0;
37238 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37239 + ACCESS_ONCE_RW(ads->ctl15) = 0;
37240 + ACCESS_ONCE_RW(ads->ctl16) = 0;
37241 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37242 + ACCESS_ONCE_RW(ads->ctl18) = 0;
37243 + ACCESS_ONCE_RW(ads->ctl19) = 0;
37244 return;
37245 }
37246
37247 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37248 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37249 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37250 | SM(i->txpower, AR_XmitPower)
37251 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37252 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37253 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37254 ctl12 |= SM(val, AR_PAPRDChainMask);
37255
37256 - ACCESS_ONCE(ads->ctl12) = ctl12;
37257 - ACCESS_ONCE(ads->ctl17) = ctl17;
37258 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37259 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37260
37261 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37262 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37263 | set11nPktDurRTSCTS(i->rates, 1);
37264
37265 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37266 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37267 | set11nPktDurRTSCTS(i->rates, 3);
37268
37269 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37270 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37271 | set11nRateFlags(i->rates, 1)
37272 | set11nRateFlags(i->rates, 2)
37273 | set11nRateFlags(i->rates, 3)
37274 | SM(i->rtscts_rate, AR_RTSCTSRate);
37275
37276 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37277 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37278 }
37279
37280 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37281 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37282 index dbc1b7a..67e2ca2 100644
37283 --- a/drivers/net/wireless/ath/ath9k/hw.h
37284 +++ b/drivers/net/wireless/ath/ath9k/hw.h
37285 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
37286
37287 /* ANI */
37288 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37289 -};
37290 +} __no_const;
37291
37292 /**
37293 * struct ath_hw_ops - callbacks used by hardware code and driver code
37294 @@ -687,7 +687,7 @@ struct ath_hw_ops {
37295 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37296 struct ath_hw_antcomb_conf *antconf);
37297 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37298 -};
37299 +} __no_const;
37300
37301 struct ath_nf_limits {
37302 s16 max;
37303 diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37304 index 71ced17..cd82b12 100644
37305 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37306 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37307 @@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
37308 struct net_device *ndev,
37309 const struct brcmf_event_msg *e,
37310 void *data);
37311 -};
37312 +} __no_const;
37313
37314 /* basic structure of scan request */
37315 struct brcmf_cfg80211_scan_req {
37316 @@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
37317 struct brcmf_cfg80211_iscan_eloop {
37318 s32 (*handler[WL_SCAN_ERSULTS_LAST])
37319 (struct brcmf_cfg80211_info *cfg);
37320 -};
37321 +} __no_const;
37322
37323 /* dongle iscan controller */
37324 struct brcmf_cfg80211_iscan_ctrl {
37325 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37326 index e252acb..6ad1e65 100644
37327 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
37328 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37329 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37330 */
37331 if (il3945_mod_params.disable_hw_scan) {
37332 D_INFO("Disabling hw_scan\n");
37333 - il3945_mac_ops.hw_scan = NULL;
37334 + pax_open_kernel();
37335 + *(void **)&il3945_mac_ops.hw_scan = NULL;
37336 + pax_close_kernel();
37337 }
37338
37339 D_INFO("*** LOAD DRIVER ***\n");
37340 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37341 index 1a98fa3..51e6661 100644
37342 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37343 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37344 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
37345 {
37346 struct iwl_priv *priv = file->private_data;
37347 char buf[64];
37348 - int buf_size;
37349 + size_t buf_size;
37350 u32 offset, len;
37351
37352 memset(buf, 0, sizeof(buf));
37353 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
37354 struct iwl_priv *priv = file->private_data;
37355
37356 char buf[8];
37357 - int buf_size;
37358 + size_t buf_size;
37359 u32 reset_flag;
37360
37361 memset(buf, 0, sizeof(buf));
37362 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
37363 {
37364 struct iwl_priv *priv = file->private_data;
37365 char buf[8];
37366 - int buf_size;
37367 + size_t buf_size;
37368 int ht40;
37369
37370 memset(buf, 0, sizeof(buf));
37371 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
37372 {
37373 struct iwl_priv *priv = file->private_data;
37374 char buf[8];
37375 - int buf_size;
37376 + size_t buf_size;
37377 int value;
37378
37379 memset(buf, 0, sizeof(buf));
37380 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
37381 {
37382 struct iwl_priv *priv = file->private_data;
37383 char buf[8];
37384 - int buf_size;
37385 + size_t buf_size;
37386 int clear;
37387
37388 memset(buf, 0, sizeof(buf));
37389 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
37390 {
37391 struct iwl_priv *priv = file->private_data;
37392 char buf[8];
37393 - int buf_size;
37394 + size_t buf_size;
37395 int trace;
37396
37397 memset(buf, 0, sizeof(buf));
37398 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
37399 {
37400 struct iwl_priv *priv = file->private_data;
37401 char buf[8];
37402 - int buf_size;
37403 + size_t buf_size;
37404 int missed;
37405
37406 memset(buf, 0, sizeof(buf));
37407 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
37408
37409 struct iwl_priv *priv = file->private_data;
37410 char buf[8];
37411 - int buf_size;
37412 + size_t buf_size;
37413 int plcp;
37414
37415 memset(buf, 0, sizeof(buf));
37416 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
37417
37418 struct iwl_priv *priv = file->private_data;
37419 char buf[8];
37420 - int buf_size;
37421 + size_t buf_size;
37422 int flush;
37423
37424 memset(buf, 0, sizeof(buf));
37425 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
37426
37427 struct iwl_priv *priv = file->private_data;
37428 char buf[8];
37429 - int buf_size;
37430 + size_t buf_size;
37431 int rts;
37432
37433 if (!priv->cfg->ht_params)
37434 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
37435 {
37436 struct iwl_priv *priv = file->private_data;
37437 char buf[8];
37438 - int buf_size;
37439 + size_t buf_size;
37440
37441 memset(buf, 0, sizeof(buf));
37442 buf_size = min(count, sizeof(buf) - 1);
37443 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
37444 struct iwl_priv *priv = file->private_data;
37445 u32 event_log_flag;
37446 char buf[8];
37447 - int buf_size;
37448 + size_t buf_size;
37449
37450 /* check that the interface is up */
37451 if (!iwl_is_ready(priv))
37452 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
37453 struct iwl_priv *priv = file->private_data;
37454 char buf[8];
37455 u32 calib_disabled;
37456 - int buf_size;
37457 + size_t buf_size;
37458
37459 memset(buf, 0, sizeof(buf));
37460 buf_size = min(count, sizeof(buf) - 1);
37461 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
37462 index fe0fffd..b4c5724 100644
37463 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
37464 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
37465 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
37466 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
37467
37468 char buf[8];
37469 - int buf_size;
37470 + size_t buf_size;
37471 u32 reset_flag;
37472
37473 memset(buf, 0, sizeof(buf));
37474 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
37475 {
37476 struct iwl_trans *trans = file->private_data;
37477 char buf[8];
37478 - int buf_size;
37479 + size_t buf_size;
37480 int csr;
37481
37482 memset(buf, 0, sizeof(buf));
37483 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
37484 index 429ca32..f86236b 100644
37485 --- a/drivers/net/wireless/mac80211_hwsim.c
37486 +++ b/drivers/net/wireless/mac80211_hwsim.c
37487 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
37488 return -EINVAL;
37489
37490 if (fake_hw_scan) {
37491 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37492 - mac80211_hwsim_ops.sw_scan_start = NULL;
37493 - mac80211_hwsim_ops.sw_scan_complete = NULL;
37494 + pax_open_kernel();
37495 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37496 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37497 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37498 + pax_close_kernel();
37499 }
37500
37501 spin_lock_init(&hwsim_radio_lock);
37502 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37503 index bd1f0cb..db85ab0 100644
37504 --- a/drivers/net/wireless/rndis_wlan.c
37505 +++ b/drivers/net/wireless/rndis_wlan.c
37506 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37507
37508 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37509
37510 - if (rts_threshold < 0 || rts_threshold > 2347)
37511 + if (rts_threshold > 2347)
37512 rts_threshold = 2347;
37513
37514 tmp = cpu_to_le32(rts_threshold);
37515 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37516 index 0751b35..246ba3e 100644
37517 --- a/drivers/net/wireless/rt2x00/rt2x00.h
37518 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
37519 @@ -398,7 +398,7 @@ struct rt2x00_intf {
37520 * for hardware which doesn't support hardware
37521 * sequence counting.
37522 */
37523 - atomic_t seqno;
37524 + atomic_unchecked_t seqno;
37525 };
37526
37527 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37528 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37529 index e488b94..14b6a0c 100644
37530 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37531 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37532 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37533 * sequence counter given by mac80211.
37534 */
37535 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37536 - seqno = atomic_add_return(0x10, &intf->seqno);
37537 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37538 else
37539 - seqno = atomic_read(&intf->seqno);
37540 + seqno = atomic_read_unchecked(&intf->seqno);
37541
37542 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37543 hdr->seq_ctrl |= cpu_to_le16(seqno);
37544 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
37545 index e2750a1..797e179 100644
37546 --- a/drivers/net/wireless/ti/wl1251/sdio.c
37547 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
37548 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
37549
37550 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
37551
37552 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37553 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37554 + pax_open_kernel();
37555 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37556 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37557 + pax_close_kernel();
37558
37559 wl1251_info("using dedicated interrupt line");
37560 } else {
37561 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37562 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37563 + pax_open_kernel();
37564 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37565 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37566 + pax_close_kernel();
37567
37568 wl1251_info("using SDIO interrupt");
37569 }
37570 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37571 index dadf1db..d9db7a7 100644
37572 --- a/drivers/net/wireless/ti/wl12xx/main.c
37573 +++ b/drivers/net/wireless/ti/wl12xx/main.c
37574 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37575 sizeof(wl->conf.mem));
37576
37577 /* read data preparation is only needed by wl127x */
37578 - wl->ops->prepare_read = wl127x_prepare_read;
37579 + pax_open_kernel();
37580 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37581 + pax_close_kernel();
37582
37583 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37584 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37585 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37586 sizeof(wl->conf.mem));
37587
37588 /* read data preparation is only needed by wl127x */
37589 - wl->ops->prepare_read = wl127x_prepare_read;
37590 + pax_open_kernel();
37591 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37592 + pax_close_kernel();
37593
37594 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37595 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37596 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37597 index a39682a..1e8220c 100644
37598 --- a/drivers/net/wireless/ti/wl18xx/main.c
37599 +++ b/drivers/net/wireless/ti/wl18xx/main.c
37600 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37601 }
37602
37603 if (!checksum_param) {
37604 - wl18xx_ops.set_rx_csum = NULL;
37605 - wl18xx_ops.init_vif = NULL;
37606 + pax_open_kernel();
37607 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
37608 + *(void **)&wl18xx_ops.init_vif = NULL;
37609 + pax_close_kernel();
37610 }
37611
37612 /* Enable 11a Band only if we have 5G antennas */
37613 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37614 index d93b2b6..ae50401 100644
37615 --- a/drivers/oprofile/buffer_sync.c
37616 +++ b/drivers/oprofile/buffer_sync.c
37617 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37618 if (cookie == NO_COOKIE)
37619 offset = pc;
37620 if (cookie == INVALID_COOKIE) {
37621 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37622 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37623 offset = pc;
37624 }
37625 if (cookie != last_cookie) {
37626 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37627 /* add userspace sample */
37628
37629 if (!mm) {
37630 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
37631 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37632 return 0;
37633 }
37634
37635 cookie = lookup_dcookie(mm, s->eip, &offset);
37636
37637 if (cookie == INVALID_COOKIE) {
37638 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37639 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37640 return 0;
37641 }
37642
37643 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37644 /* ignore backtraces if failed to add a sample */
37645 if (state == sb_bt_start) {
37646 state = sb_bt_ignore;
37647 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37648 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37649 }
37650 }
37651 release_mm(mm);
37652 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37653 index c0cc4e7..44d4e54 100644
37654 --- a/drivers/oprofile/event_buffer.c
37655 +++ b/drivers/oprofile/event_buffer.c
37656 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37657 }
37658
37659 if (buffer_pos == buffer_size) {
37660 - atomic_inc(&oprofile_stats.event_lost_overflow);
37661 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37662 return;
37663 }
37664
37665 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37666 index ed2c3ec..deda85a 100644
37667 --- a/drivers/oprofile/oprof.c
37668 +++ b/drivers/oprofile/oprof.c
37669 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37670 if (oprofile_ops.switch_events())
37671 return;
37672
37673 - atomic_inc(&oprofile_stats.multiplex_counter);
37674 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37675 start_switch_worker();
37676 }
37677
37678 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37679 index 917d28e..d62d981 100644
37680 --- a/drivers/oprofile/oprofile_stats.c
37681 +++ b/drivers/oprofile/oprofile_stats.c
37682 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37683 cpu_buf->sample_invalid_eip = 0;
37684 }
37685
37686 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37687 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37688 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
37689 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37690 - atomic_set(&oprofile_stats.multiplex_counter, 0);
37691 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37692 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37693 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37694 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37695 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37696 }
37697
37698
37699 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37700 index 38b6fc0..b5cbfce 100644
37701 --- a/drivers/oprofile/oprofile_stats.h
37702 +++ b/drivers/oprofile/oprofile_stats.h
37703 @@ -13,11 +13,11 @@
37704 #include <linux/atomic.h>
37705
37706 struct oprofile_stat_struct {
37707 - atomic_t sample_lost_no_mm;
37708 - atomic_t sample_lost_no_mapping;
37709 - atomic_t bt_lost_no_mapping;
37710 - atomic_t event_lost_overflow;
37711 - atomic_t multiplex_counter;
37712 + atomic_unchecked_t sample_lost_no_mm;
37713 + atomic_unchecked_t sample_lost_no_mapping;
37714 + atomic_unchecked_t bt_lost_no_mapping;
37715 + atomic_unchecked_t event_lost_overflow;
37716 + atomic_unchecked_t multiplex_counter;
37717 };
37718
37719 extern struct oprofile_stat_struct oprofile_stats;
37720 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37721 index 849357c..b83c1e0 100644
37722 --- a/drivers/oprofile/oprofilefs.c
37723 +++ b/drivers/oprofile/oprofilefs.c
37724 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37725
37726
37727 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37728 - char const *name, atomic_t *val)
37729 + char const *name, atomic_unchecked_t *val)
37730 {
37731 return __oprofilefs_create_file(sb, root, name,
37732 &atomic_ro_fops, 0444, val);
37733 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37734 index 3f56bc0..707d642 100644
37735 --- a/drivers/parport/procfs.c
37736 +++ b/drivers/parport/procfs.c
37737 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37738
37739 *ppos += len;
37740
37741 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37742 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37743 }
37744
37745 #ifdef CONFIG_PARPORT_1284
37746 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37747
37748 *ppos += len;
37749
37750 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37751 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37752 }
37753 #endif /* IEEE1284.3 support. */
37754
37755 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37756 index a6a71c4..c91097b 100644
37757 --- a/drivers/pci/hotplug/cpcihp_generic.c
37758 +++ b/drivers/pci/hotplug/cpcihp_generic.c
37759 @@ -73,7 +73,6 @@ static u16 port;
37760 static unsigned int enum_bit;
37761 static u8 enum_mask;
37762
37763 -static struct cpci_hp_controller_ops generic_hpc_ops;
37764 static struct cpci_hp_controller generic_hpc;
37765
37766 static int __init validate_parameters(void)
37767 @@ -139,6 +138,10 @@ static int query_enum(void)
37768 return ((value & enum_mask) == enum_mask);
37769 }
37770
37771 +static struct cpci_hp_controller_ops generic_hpc_ops = {
37772 + .query_enum = query_enum,
37773 +};
37774 +
37775 static int __init cpcihp_generic_init(void)
37776 {
37777 int status;
37778 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37779 pci_dev_put(dev);
37780
37781 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37782 - generic_hpc_ops.query_enum = query_enum;
37783 generic_hpc.ops = &generic_hpc_ops;
37784
37785 status = cpci_hp_register_controller(&generic_hpc);
37786 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37787 index 6bf8d2a..9711ce0 100644
37788 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
37789 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37790 @@ -59,7 +59,6 @@
37791 /* local variables */
37792 static bool debug;
37793 static bool poll;
37794 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
37795 static struct cpci_hp_controller zt5550_hpc;
37796
37797 /* Primary cPCI bus bridge device */
37798 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37799 return 0;
37800 }
37801
37802 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37803 + .query_enum = zt5550_hc_query_enum,
37804 +};
37805 +
37806 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37807 {
37808 int status;
37809 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37810 dbg("returned from zt5550_hc_config");
37811
37812 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37813 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37814 zt5550_hpc.ops = &zt5550_hpc_ops;
37815 if(!poll) {
37816 zt5550_hpc.irq = hc_dev->irq;
37817 zt5550_hpc.irq_flags = IRQF_SHARED;
37818 zt5550_hpc.dev_id = hc_dev;
37819
37820 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37821 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37822 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37823 + pax_open_kernel();
37824 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37825 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37826 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37827 + pax_open_kernel();
37828 } else {
37829 info("using ENUM# polling mode");
37830 }
37831 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37832 index 76ba8a1..20ca857 100644
37833 --- a/drivers/pci/hotplug/cpqphp_nvram.c
37834 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
37835 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37836
37837 void compaq_nvram_init (void __iomem *rom_start)
37838 {
37839 +
37840 +#ifndef CONFIG_PAX_KERNEXEC
37841 if (rom_start) {
37842 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37843 }
37844 +#endif
37845 +
37846 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37847
37848 /* initialize our int15 lock */
37849 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37850 index 449f257..0731e96 100644
37851 --- a/drivers/pci/pcie/aspm.c
37852 +++ b/drivers/pci/pcie/aspm.c
37853 @@ -27,9 +27,9 @@
37854 #define MODULE_PARAM_PREFIX "pcie_aspm."
37855
37856 /* Note: those are not register definitions */
37857 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37858 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37859 -#define ASPM_STATE_L1 (4) /* L1 state */
37860 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37861 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37862 +#define ASPM_STATE_L1 (4U) /* L1 state */
37863 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37864 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37865
37866 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37867 index ec909af..e7517f3 100644
37868 --- a/drivers/pci/probe.c
37869 +++ b/drivers/pci/probe.c
37870 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37871 struct pci_bus_region region;
37872 bool bar_too_big = false, bar_disabled = false;
37873
37874 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37875 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37876
37877 /* No printks while decoding is disabled! */
37878 if (!dev->mmio_always_on) {
37879 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37880 index 9b8505c..f00870a 100644
37881 --- a/drivers/pci/proc.c
37882 +++ b/drivers/pci/proc.c
37883 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37884 static int __init pci_proc_init(void)
37885 {
37886 struct pci_dev *dev = NULL;
37887 +
37888 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
37889 +#ifdef CONFIG_GRKERNSEC_PROC_USER
37890 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37891 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37892 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37893 +#endif
37894 +#else
37895 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37896 +#endif
37897 proc_create("devices", 0, proc_bus_pci_dir,
37898 &proc_bus_pci_dev_operations);
37899 proc_initialized = 1;
37900 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37901 index 75dd651..2af4c9a 100644
37902 --- a/drivers/platform/x86/thinkpad_acpi.c
37903 +++ b/drivers/platform/x86/thinkpad_acpi.c
37904 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37905 return 0;
37906 }
37907
37908 -void static hotkey_mask_warn_incomplete_mask(void)
37909 +static void hotkey_mask_warn_incomplete_mask(void)
37910 {
37911 /* log only what the user can fix... */
37912 const u32 wantedmask = hotkey_driver_mask &
37913 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37914 }
37915 }
37916
37917 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37918 - struct tp_nvram_state *newn,
37919 - const u32 event_mask)
37920 -{
37921 -
37922 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37923 do { \
37924 if ((event_mask & (1 << __scancode)) && \
37925 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37926 tpacpi_hotkey_send_key(__scancode); \
37927 } while (0)
37928
37929 - void issue_volchange(const unsigned int oldvol,
37930 - const unsigned int newvol)
37931 - {
37932 - unsigned int i = oldvol;
37933 +static void issue_volchange(const unsigned int oldvol,
37934 + const unsigned int newvol,
37935 + const u32 event_mask)
37936 +{
37937 + unsigned int i = oldvol;
37938
37939 - while (i > newvol) {
37940 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37941 - i--;
37942 - }
37943 - while (i < newvol) {
37944 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37945 - i++;
37946 - }
37947 + while (i > newvol) {
37948 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37949 + i--;
37950 }
37951 + while (i < newvol) {
37952 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37953 + i++;
37954 + }
37955 +}
37956
37957 - void issue_brightnesschange(const unsigned int oldbrt,
37958 - const unsigned int newbrt)
37959 - {
37960 - unsigned int i = oldbrt;
37961 +static void issue_brightnesschange(const unsigned int oldbrt,
37962 + const unsigned int newbrt,
37963 + const u32 event_mask)
37964 +{
37965 + unsigned int i = oldbrt;
37966
37967 - while (i > newbrt) {
37968 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37969 - i--;
37970 - }
37971 - while (i < newbrt) {
37972 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37973 - i++;
37974 - }
37975 + while (i > newbrt) {
37976 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37977 + i--;
37978 + }
37979 + while (i < newbrt) {
37980 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37981 + i++;
37982 }
37983 +}
37984
37985 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37986 + struct tp_nvram_state *newn,
37987 + const u32 event_mask)
37988 +{
37989 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37990 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37991 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37992 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37993 oldn->volume_level != newn->volume_level) {
37994 /* recently muted, or repeated mute keypress, or
37995 * multiple presses ending in mute */
37996 - issue_volchange(oldn->volume_level, newn->volume_level);
37997 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37998 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37999 }
38000 } else {
38001 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38002 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38003 }
38004 if (oldn->volume_level != newn->volume_level) {
38005 - issue_volchange(oldn->volume_level, newn->volume_level);
38006 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38007 } else if (oldn->volume_toggle != newn->volume_toggle) {
38008 /* repeated vol up/down keypress at end of scale ? */
38009 if (newn->volume_level == 0)
38010 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38011 /* handle brightness */
38012 if (oldn->brightness_level != newn->brightness_level) {
38013 issue_brightnesschange(oldn->brightness_level,
38014 - newn->brightness_level);
38015 + newn->brightness_level,
38016 + event_mask);
38017 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38018 /* repeated key presses that didn't change state */
38019 if (newn->brightness_level == 0)
38020 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38021 && !tp_features.bright_unkfw)
38022 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38023 }
38024 +}
38025
38026 #undef TPACPI_COMPARE_KEY
38027 #undef TPACPI_MAY_SEND_KEY
38028 -}
38029
38030 /*
38031 * Polling driver
38032 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38033 index 769d265..a3a05ca 100644
38034 --- a/drivers/pnp/pnpbios/bioscalls.c
38035 +++ b/drivers/pnp/pnpbios/bioscalls.c
38036 @@ -58,7 +58,7 @@ do { \
38037 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38038 } while(0)
38039
38040 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38041 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38042 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38043
38044 /*
38045 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38046
38047 cpu = get_cpu();
38048 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38049 +
38050 + pax_open_kernel();
38051 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38052 + pax_close_kernel();
38053
38054 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38055 spin_lock_irqsave(&pnp_bios_lock, flags);
38056 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38057 :"memory");
38058 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38059
38060 + pax_open_kernel();
38061 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38062 + pax_close_kernel();
38063 +
38064 put_cpu();
38065
38066 /* If we get here and this is set then the PnP BIOS faulted on us. */
38067 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38068 return status;
38069 }
38070
38071 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
38072 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38073 {
38074 int i;
38075
38076 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38077 pnp_bios_callpoint.offset = header->fields.pm16offset;
38078 pnp_bios_callpoint.segment = PNP_CS16;
38079
38080 + pax_open_kernel();
38081 +
38082 for_each_possible_cpu(i) {
38083 struct desc_struct *gdt = get_cpu_gdt_table(i);
38084 if (!gdt)
38085 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38086 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38087 (unsigned long)__va(header->fields.pm16dseg));
38088 }
38089 +
38090 + pax_close_kernel();
38091 }
38092 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38093 index b0ecacb..7c9da2e 100644
38094 --- a/drivers/pnp/resource.c
38095 +++ b/drivers/pnp/resource.c
38096 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38097 return 1;
38098
38099 /* check if the resource is valid */
38100 - if (*irq < 0 || *irq > 15)
38101 + if (*irq > 15)
38102 return 0;
38103
38104 /* check if the resource is reserved */
38105 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38106 return 1;
38107
38108 /* check if the resource is valid */
38109 - if (*dma < 0 || *dma == 4 || *dma > 7)
38110 + if (*dma == 4 || *dma > 7)
38111 return 0;
38112
38113 /* check if the resource is reserved */
38114 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38115 index 7df7c5f..bd48c47 100644
38116 --- a/drivers/power/pda_power.c
38117 +++ b/drivers/power/pda_power.c
38118 @@ -37,7 +37,11 @@ static int polling;
38119
38120 #ifdef CONFIG_USB_OTG_UTILS
38121 static struct usb_phy *transceiver;
38122 -static struct notifier_block otg_nb;
38123 +static int otg_handle_notification(struct notifier_block *nb,
38124 + unsigned long event, void *unused);
38125 +static struct notifier_block otg_nb = {
38126 + .notifier_call = otg_handle_notification
38127 +};
38128 #endif
38129
38130 static struct regulator *ac_draw;
38131 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38132
38133 #ifdef CONFIG_USB_OTG_UTILS
38134 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38135 - otg_nb.notifier_call = otg_handle_notification;
38136 ret = usb_register_notifier(transceiver, &otg_nb);
38137 if (ret) {
38138 dev_err(dev, "failure to register otg notifier\n");
38139 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38140 index 8d53174..04c65de 100644
38141 --- a/drivers/regulator/max8660.c
38142 +++ b/drivers/regulator/max8660.c
38143 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
38144 max8660->shadow_regs[MAX8660_OVER1] = 5;
38145 } else {
38146 /* Otherwise devices can be toggled via software */
38147 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
38148 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
38149 + pax_open_kernel();
38150 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38151 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38152 + pax_close_kernel();
38153 }
38154
38155 /*
38156 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38157 index 1fa6381..f58834e 100644
38158 --- a/drivers/regulator/mc13892-regulator.c
38159 +++ b/drivers/regulator/mc13892-regulator.c
38160 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
38161 }
38162 mc13xxx_unlock(mc13892);
38163
38164 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38165 + pax_open_kernel();
38166 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38167 = mc13892_vcam_set_mode;
38168 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38169 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38170 = mc13892_vcam_get_mode;
38171 + pax_close_kernel();
38172
38173 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38174 ARRAY_SIZE(mc13892_regulators));
38175 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38176 index cace6d3..f623fda 100644
38177 --- a/drivers/rtc/rtc-dev.c
38178 +++ b/drivers/rtc/rtc-dev.c
38179 @@ -14,6 +14,7 @@
38180 #include <linux/module.h>
38181 #include <linux/rtc.h>
38182 #include <linux/sched.h>
38183 +#include <linux/grsecurity.h>
38184 #include "rtc-core.h"
38185
38186 static dev_t rtc_devt;
38187 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38188 if (copy_from_user(&tm, uarg, sizeof(tm)))
38189 return -EFAULT;
38190
38191 + gr_log_timechange();
38192 +
38193 return rtc_set_time(rtc, &tm);
38194
38195 case RTC_PIE_ON:
38196 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38197 index 4ad7e36..d004679 100644
38198 --- a/drivers/scsi/bfa/bfa.h
38199 +++ b/drivers/scsi/bfa/bfa.h
38200 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
38201 u32 *end);
38202 int cpe_vec_q0;
38203 int rme_vec_q0;
38204 -};
38205 +} __no_const;
38206 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38207
38208 struct bfa_faa_cbfn_s {
38209 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38210 index e693af6..2e525b6 100644
38211 --- a/drivers/scsi/bfa/bfa_fcpim.h
38212 +++ b/drivers/scsi/bfa/bfa_fcpim.h
38213 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
38214
38215 struct bfa_itn_s {
38216 bfa_isr_func_t isr;
38217 -};
38218 +} __no_const;
38219
38220 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38221 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38222 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38223 index 23a90e7..9cf04ee 100644
38224 --- a/drivers/scsi/bfa/bfa_ioc.h
38225 +++ b/drivers/scsi/bfa/bfa_ioc.h
38226 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38227 bfa_ioc_disable_cbfn_t disable_cbfn;
38228 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38229 bfa_ioc_reset_cbfn_t reset_cbfn;
38230 -};
38231 +} __no_const;
38232
38233 /*
38234 * IOC event notification mechanism.
38235 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38236 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38237 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38238 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38239 -};
38240 +} __no_const;
38241
38242 /*
38243 * Queue element to wait for room in request queue. FIFO order is
38244 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38245 index 593085a..47aa999 100644
38246 --- a/drivers/scsi/hosts.c
38247 +++ b/drivers/scsi/hosts.c
38248 @@ -42,7 +42,7 @@
38249 #include "scsi_logging.h"
38250
38251
38252 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38253 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38254
38255
38256 static void scsi_host_cls_release(struct device *dev)
38257 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38258 * subtract one because we increment first then return, but we need to
38259 * know what the next host number was before increment
38260 */
38261 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38262 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38263 shost->dma_channel = 0xff;
38264
38265 /* These three are default values which can be overridden */
38266 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38267 index 4217e49..9c77e3e 100644
38268 --- a/drivers/scsi/hpsa.c
38269 +++ b/drivers/scsi/hpsa.c
38270 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38271 unsigned long flags;
38272
38273 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38274 - return h->access.command_completed(h, q);
38275 + return h->access->command_completed(h, q);
38276
38277 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38278 a = rq->head[rq->current_entry];
38279 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38280 while (!list_empty(&h->reqQ)) {
38281 c = list_entry(h->reqQ.next, struct CommandList, list);
38282 /* can't do anything if fifo is full */
38283 - if ((h->access.fifo_full(h))) {
38284 + if ((h->access->fifo_full(h))) {
38285 dev_warn(&h->pdev->dev, "fifo full\n");
38286 break;
38287 }
38288 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
38289
38290 /* Tell the controller execute command */
38291 spin_unlock_irqrestore(&h->lock, flags);
38292 - h->access.submit_command(h, c);
38293 + h->access->submit_command(h, c);
38294 spin_lock_irqsave(&h->lock, flags);
38295 }
38296 spin_unlock_irqrestore(&h->lock, flags);
38297 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
38298
38299 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
38300 {
38301 - return h->access.command_completed(h, q);
38302 + return h->access->command_completed(h, q);
38303 }
38304
38305 static inline bool interrupt_pending(struct ctlr_info *h)
38306 {
38307 - return h->access.intr_pending(h);
38308 + return h->access->intr_pending(h);
38309 }
38310
38311 static inline long interrupt_not_for_us(struct ctlr_info *h)
38312 {
38313 - return (h->access.intr_pending(h) == 0) ||
38314 + return (h->access->intr_pending(h) == 0) ||
38315 (h->interrupts_enabled == 0);
38316 }
38317
38318 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
38319 if (prod_index < 0)
38320 return -ENODEV;
38321 h->product_name = products[prod_index].product_name;
38322 - h->access = *(products[prod_index].access);
38323 + h->access = products[prod_index].access;
38324
38325 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
38326 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
38327 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
38328
38329 assert_spin_locked(&lockup_detector_lock);
38330 remove_ctlr_from_lockup_detector_list(h);
38331 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38332 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38333 spin_lock_irqsave(&h->lock, flags);
38334 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
38335 spin_unlock_irqrestore(&h->lock, flags);
38336 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
38337 }
38338
38339 /* make sure the board interrupts are off */
38340 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38341 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38342
38343 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
38344 goto clean2;
38345 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
38346 * fake ones to scoop up any residual completions.
38347 */
38348 spin_lock_irqsave(&h->lock, flags);
38349 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38350 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38351 spin_unlock_irqrestore(&h->lock, flags);
38352 free_irqs(h);
38353 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
38354 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
38355 dev_info(&h->pdev->dev, "Board READY.\n");
38356 dev_info(&h->pdev->dev,
38357 "Waiting for stale completions to drain.\n");
38358 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38359 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38360 msleep(10000);
38361 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38362 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38363
38364 rc = controller_reset_failed(h->cfgtable);
38365 if (rc)
38366 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
38367 }
38368
38369 /* Turn the interrupts on so we can service requests */
38370 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38371 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38372
38373 hpsa_hba_inquiry(h);
38374 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
38375 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
38376 * To write all data in the battery backed cache to disks
38377 */
38378 hpsa_flush_cache(h);
38379 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38380 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38381 hpsa_free_irqs_and_disable_msix(h);
38382 }
38383
38384 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
38385 return;
38386 }
38387 /* Change the access methods to the performant access methods */
38388 - h->access = SA5_performant_access;
38389 + h->access = &SA5_performant_access;
38390 h->transMethod = CFGTBL_Trans_Performant;
38391 }
38392
38393 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
38394 index 9816479..c5d4e97 100644
38395 --- a/drivers/scsi/hpsa.h
38396 +++ b/drivers/scsi/hpsa.h
38397 @@ -79,7 +79,7 @@ struct ctlr_info {
38398 unsigned int msix_vector;
38399 unsigned int msi_vector;
38400 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
38401 - struct access_method access;
38402 + struct access_method *access;
38403
38404 /* queue and queue Info */
38405 struct list_head reqQ;
38406 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
38407 index c772d8d..35c362c 100644
38408 --- a/drivers/scsi/libfc/fc_exch.c
38409 +++ b/drivers/scsi/libfc/fc_exch.c
38410 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
38411 u16 pool_max_index;
38412
38413 struct {
38414 - atomic_t no_free_exch;
38415 - atomic_t no_free_exch_xid;
38416 - atomic_t xid_not_found;
38417 - atomic_t xid_busy;
38418 - atomic_t seq_not_found;
38419 - atomic_t non_bls_resp;
38420 + atomic_unchecked_t no_free_exch;
38421 + atomic_unchecked_t no_free_exch_xid;
38422 + atomic_unchecked_t xid_not_found;
38423 + atomic_unchecked_t xid_busy;
38424 + atomic_unchecked_t seq_not_found;
38425 + atomic_unchecked_t non_bls_resp;
38426 } stats;
38427 };
38428
38429 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
38430 /* allocate memory for exchange */
38431 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38432 if (!ep) {
38433 - atomic_inc(&mp->stats.no_free_exch);
38434 + atomic_inc_unchecked(&mp->stats.no_free_exch);
38435 goto out;
38436 }
38437 memset(ep, 0, sizeof(*ep));
38438 @@ -786,7 +786,7 @@ out:
38439 return ep;
38440 err:
38441 spin_unlock_bh(&pool->lock);
38442 - atomic_inc(&mp->stats.no_free_exch_xid);
38443 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38444 mempool_free(ep, mp->ep_pool);
38445 return NULL;
38446 }
38447 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38448 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38449 ep = fc_exch_find(mp, xid);
38450 if (!ep) {
38451 - atomic_inc(&mp->stats.xid_not_found);
38452 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38453 reject = FC_RJT_OX_ID;
38454 goto out;
38455 }
38456 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38457 ep = fc_exch_find(mp, xid);
38458 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38459 if (ep) {
38460 - atomic_inc(&mp->stats.xid_busy);
38461 + atomic_inc_unchecked(&mp->stats.xid_busy);
38462 reject = FC_RJT_RX_ID;
38463 goto rel;
38464 }
38465 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38466 }
38467 xid = ep->xid; /* get our XID */
38468 } else if (!ep) {
38469 - atomic_inc(&mp->stats.xid_not_found);
38470 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38471 reject = FC_RJT_RX_ID; /* XID not found */
38472 goto out;
38473 }
38474 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38475 } else {
38476 sp = &ep->seq;
38477 if (sp->id != fh->fh_seq_id) {
38478 - atomic_inc(&mp->stats.seq_not_found);
38479 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38480 if (f_ctl & FC_FC_END_SEQ) {
38481 /*
38482 * Update sequence_id based on incoming last
38483 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38484
38485 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38486 if (!ep) {
38487 - atomic_inc(&mp->stats.xid_not_found);
38488 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38489 goto out;
38490 }
38491 if (ep->esb_stat & ESB_ST_COMPLETE) {
38492 - atomic_inc(&mp->stats.xid_not_found);
38493 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38494 goto rel;
38495 }
38496 if (ep->rxid == FC_XID_UNKNOWN)
38497 ep->rxid = ntohs(fh->fh_rx_id);
38498 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38499 - atomic_inc(&mp->stats.xid_not_found);
38500 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38501 goto rel;
38502 }
38503 if (ep->did != ntoh24(fh->fh_s_id) &&
38504 ep->did != FC_FID_FLOGI) {
38505 - atomic_inc(&mp->stats.xid_not_found);
38506 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38507 goto rel;
38508 }
38509 sof = fr_sof(fp);
38510 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38511 sp->ssb_stat |= SSB_ST_RESP;
38512 sp->id = fh->fh_seq_id;
38513 } else if (sp->id != fh->fh_seq_id) {
38514 - atomic_inc(&mp->stats.seq_not_found);
38515 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38516 goto rel;
38517 }
38518
38519 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38520 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38521
38522 if (!sp)
38523 - atomic_inc(&mp->stats.xid_not_found);
38524 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38525 else
38526 - atomic_inc(&mp->stats.non_bls_resp);
38527 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
38528
38529 fc_frame_free(fp);
38530 }
38531 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38532
38533 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38534 mp = ema->mp;
38535 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38536 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38537 st->fc_no_free_exch_xid +=
38538 - atomic_read(&mp->stats.no_free_exch_xid);
38539 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38540 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38541 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38542 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38543 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38544 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38545 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38546 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38547 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38548 }
38549 }
38550 EXPORT_SYMBOL(fc_exch_update_stats);
38551 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38552 index bdb81cd..d3c7c2c 100644
38553 --- a/drivers/scsi/libsas/sas_ata.c
38554 +++ b/drivers/scsi/libsas/sas_ata.c
38555 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38556 .postreset = ata_std_postreset,
38557 .error_handler = ata_std_error_handler,
38558 .post_internal_cmd = sas_ata_post_internal,
38559 - .qc_defer = ata_std_qc_defer,
38560 + .qc_defer = ata_std_qc_defer,
38561 .qc_prep = ata_noop_qc_prep,
38562 .qc_issue = sas_ata_qc_issue,
38563 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38564 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38565 index 69b5993..1ac9dce 100644
38566 --- a/drivers/scsi/lpfc/lpfc.h
38567 +++ b/drivers/scsi/lpfc/lpfc.h
38568 @@ -424,7 +424,7 @@ struct lpfc_vport {
38569 struct dentry *debug_nodelist;
38570 struct dentry *vport_debugfs_root;
38571 struct lpfc_debugfs_trc *disc_trc;
38572 - atomic_t disc_trc_cnt;
38573 + atomic_unchecked_t disc_trc_cnt;
38574 #endif
38575 uint8_t stat_data_enabled;
38576 uint8_t stat_data_blocked;
38577 @@ -840,8 +840,8 @@ struct lpfc_hba {
38578 struct timer_list fabric_block_timer;
38579 unsigned long bit_flags;
38580 #define FABRIC_COMANDS_BLOCKED 0
38581 - atomic_t num_rsrc_err;
38582 - atomic_t num_cmd_success;
38583 + atomic_unchecked_t num_rsrc_err;
38584 + atomic_unchecked_t num_cmd_success;
38585 unsigned long last_rsrc_error_time;
38586 unsigned long last_ramp_down_time;
38587 unsigned long last_ramp_up_time;
38588 @@ -877,7 +877,7 @@ struct lpfc_hba {
38589
38590 struct dentry *debug_slow_ring_trc;
38591 struct lpfc_debugfs_trc *slow_ring_trc;
38592 - atomic_t slow_ring_trc_cnt;
38593 + atomic_unchecked_t slow_ring_trc_cnt;
38594 /* iDiag debugfs sub-directory */
38595 struct dentry *idiag_root;
38596 struct dentry *idiag_pci_cfg;
38597 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38598 index f63f5ff..de29189 100644
38599 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
38600 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38601 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38602
38603 #include <linux/debugfs.h>
38604
38605 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38606 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38607 static unsigned long lpfc_debugfs_start_time = 0L;
38608
38609 /* iDiag */
38610 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38611 lpfc_debugfs_enable = 0;
38612
38613 len = 0;
38614 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38615 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38616 (lpfc_debugfs_max_disc_trc - 1);
38617 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38618 dtp = vport->disc_trc + i;
38619 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38620 lpfc_debugfs_enable = 0;
38621
38622 len = 0;
38623 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38624 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38625 (lpfc_debugfs_max_slow_ring_trc - 1);
38626 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38627 dtp = phba->slow_ring_trc + i;
38628 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38629 !vport || !vport->disc_trc)
38630 return;
38631
38632 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38633 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38634 (lpfc_debugfs_max_disc_trc - 1);
38635 dtp = vport->disc_trc + index;
38636 dtp->fmt = fmt;
38637 dtp->data1 = data1;
38638 dtp->data2 = data2;
38639 dtp->data3 = data3;
38640 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38641 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38642 dtp->jif = jiffies;
38643 #endif
38644 return;
38645 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38646 !phba || !phba->slow_ring_trc)
38647 return;
38648
38649 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38650 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38651 (lpfc_debugfs_max_slow_ring_trc - 1);
38652 dtp = phba->slow_ring_trc + index;
38653 dtp->fmt = fmt;
38654 dtp->data1 = data1;
38655 dtp->data2 = data2;
38656 dtp->data3 = data3;
38657 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38658 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38659 dtp->jif = jiffies;
38660 #endif
38661 return;
38662 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38663 "slow_ring buffer\n");
38664 goto debug_failed;
38665 }
38666 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38667 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38668 memset(phba->slow_ring_trc, 0,
38669 (sizeof(struct lpfc_debugfs_trc) *
38670 lpfc_debugfs_max_slow_ring_trc));
38671 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38672 "buffer\n");
38673 goto debug_failed;
38674 }
38675 - atomic_set(&vport->disc_trc_cnt, 0);
38676 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38677
38678 snprintf(name, sizeof(name), "discovery_trace");
38679 vport->debug_disc_trc =
38680 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38681 index 7dc4218..3436f08 100644
38682 --- a/drivers/scsi/lpfc/lpfc_init.c
38683 +++ b/drivers/scsi/lpfc/lpfc_init.c
38684 @@ -10589,8 +10589,10 @@ lpfc_init(void)
38685 "misc_register returned with status %d", error);
38686
38687 if (lpfc_enable_npiv) {
38688 - lpfc_transport_functions.vport_create = lpfc_vport_create;
38689 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38690 + pax_open_kernel();
38691 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38692 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38693 + pax_close_kernel();
38694 }
38695 lpfc_transport_template =
38696 fc_attach_transport(&lpfc_transport_functions);
38697 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38698 index 7f45ac9..cf62eda 100644
38699 --- a/drivers/scsi/lpfc/lpfc_scsi.c
38700 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
38701 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38702 uint32_t evt_posted;
38703
38704 spin_lock_irqsave(&phba->hbalock, flags);
38705 - atomic_inc(&phba->num_rsrc_err);
38706 + atomic_inc_unchecked(&phba->num_rsrc_err);
38707 phba->last_rsrc_error_time = jiffies;
38708
38709 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38710 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38711 unsigned long flags;
38712 struct lpfc_hba *phba = vport->phba;
38713 uint32_t evt_posted;
38714 - atomic_inc(&phba->num_cmd_success);
38715 + atomic_inc_unchecked(&phba->num_cmd_success);
38716
38717 if (vport->cfg_lun_queue_depth <= queue_depth)
38718 return;
38719 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38720 unsigned long num_rsrc_err, num_cmd_success;
38721 int i;
38722
38723 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38724 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38725 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38726 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38727
38728 /*
38729 * The error and success command counters are global per
38730 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38731 }
38732 }
38733 lpfc_destroy_vport_work_array(phba, vports);
38734 - atomic_set(&phba->num_rsrc_err, 0);
38735 - atomic_set(&phba->num_cmd_success, 0);
38736 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38737 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38738 }
38739
38740 /**
38741 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38742 }
38743 }
38744 lpfc_destroy_vport_work_array(phba, vports);
38745 - atomic_set(&phba->num_rsrc_err, 0);
38746 - atomic_set(&phba->num_cmd_success, 0);
38747 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38748 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38749 }
38750
38751 /**
38752 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38753 index af763ea..41904f7 100644
38754 --- a/drivers/scsi/pmcraid.c
38755 +++ b/drivers/scsi/pmcraid.c
38756 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38757 res->scsi_dev = scsi_dev;
38758 scsi_dev->hostdata = res;
38759 res->change_detected = 0;
38760 - atomic_set(&res->read_failures, 0);
38761 - atomic_set(&res->write_failures, 0);
38762 + atomic_set_unchecked(&res->read_failures, 0);
38763 + atomic_set_unchecked(&res->write_failures, 0);
38764 rc = 0;
38765 }
38766 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38767 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38768
38769 /* If this was a SCSI read/write command keep count of errors */
38770 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38771 - atomic_inc(&res->read_failures);
38772 + atomic_inc_unchecked(&res->read_failures);
38773 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38774 - atomic_inc(&res->write_failures);
38775 + atomic_inc_unchecked(&res->write_failures);
38776
38777 if (!RES_IS_GSCSI(res->cfg_entry) &&
38778 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38779 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38780 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38781 * hrrq_id assigned here in queuecommand
38782 */
38783 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38784 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38785 pinstance->num_hrrq;
38786 cmd->cmd_done = pmcraid_io_done;
38787
38788 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38789 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38790 * hrrq_id assigned here in queuecommand
38791 */
38792 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38793 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38794 pinstance->num_hrrq;
38795
38796 if (request_size) {
38797 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38798
38799 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38800 /* add resources only after host is added into system */
38801 - if (!atomic_read(&pinstance->expose_resources))
38802 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38803 return;
38804
38805 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38806 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38807 init_waitqueue_head(&pinstance->reset_wait_q);
38808
38809 atomic_set(&pinstance->outstanding_cmds, 0);
38810 - atomic_set(&pinstance->last_message_id, 0);
38811 - atomic_set(&pinstance->expose_resources, 0);
38812 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38813 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38814
38815 INIT_LIST_HEAD(&pinstance->free_res_q);
38816 INIT_LIST_HEAD(&pinstance->used_res_q);
38817 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38818 /* Schedule worker thread to handle CCN and take care of adding and
38819 * removing devices to OS
38820 */
38821 - atomic_set(&pinstance->expose_resources, 1);
38822 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38823 schedule_work(&pinstance->worker_q);
38824 return rc;
38825
38826 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38827 index e1d150f..6c6df44 100644
38828 --- a/drivers/scsi/pmcraid.h
38829 +++ b/drivers/scsi/pmcraid.h
38830 @@ -748,7 +748,7 @@ struct pmcraid_instance {
38831 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38832
38833 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38834 - atomic_t last_message_id;
38835 + atomic_unchecked_t last_message_id;
38836
38837 /* configuration table */
38838 struct pmcraid_config_table *cfg_table;
38839 @@ -777,7 +777,7 @@ struct pmcraid_instance {
38840 atomic_t outstanding_cmds;
38841
38842 /* should add/delete resources to mid-layer now ?*/
38843 - atomic_t expose_resources;
38844 + atomic_unchecked_t expose_resources;
38845
38846
38847
38848 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38849 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38850 };
38851 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38852 - atomic_t read_failures; /* count of failed READ commands */
38853 - atomic_t write_failures; /* count of failed WRITE commands */
38854 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38855 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38856
38857 /* To indicate add/delete/modify during CCN */
38858 u8 change_detected;
38859 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38860 index 83d7984..a27d947 100644
38861 --- a/drivers/scsi/qla2xxx/qla_attr.c
38862 +++ b/drivers/scsi/qla2xxx/qla_attr.c
38863 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38864 return 0;
38865 }
38866
38867 -struct fc_function_template qla2xxx_transport_functions = {
38868 +fc_function_template_no_const qla2xxx_transport_functions = {
38869
38870 .show_host_node_name = 1,
38871 .show_host_port_name = 1,
38872 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38873 .bsg_timeout = qla24xx_bsg_timeout,
38874 };
38875
38876 -struct fc_function_template qla2xxx_transport_vport_functions = {
38877 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
38878
38879 .show_host_node_name = 1,
38880 .show_host_port_name = 1,
38881 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38882 index 6acb397..d86e3e0 100644
38883 --- a/drivers/scsi/qla2xxx/qla_gbl.h
38884 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
38885 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38886 struct device_attribute;
38887 extern struct device_attribute *qla2x00_host_attrs[];
38888 struct fc_function_template;
38889 -extern struct fc_function_template qla2xxx_transport_functions;
38890 -extern struct fc_function_template qla2xxx_transport_vport_functions;
38891 +extern fc_function_template_no_const qla2xxx_transport_functions;
38892 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38893 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38894 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38895 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38896 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38897 index f4b1fc8..a1ce4dd 100644
38898 --- a/drivers/scsi/qla2xxx/qla_os.c
38899 +++ b/drivers/scsi/qla2xxx/qla_os.c
38900 @@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38901 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38902 /* Ok, a 64bit DMA mask is applicable. */
38903 ha->flags.enable_64bit_addressing = 1;
38904 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38905 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38906 + pax_open_kernel();
38907 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38908 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38909 + pax_close_kernel();
38910 return;
38911 }
38912 }
38913 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38914 index 329d553..f20d31d 100644
38915 --- a/drivers/scsi/qla4xxx/ql4_def.h
38916 +++ b/drivers/scsi/qla4xxx/ql4_def.h
38917 @@ -273,7 +273,7 @@ struct ddb_entry {
38918 * (4000 only) */
38919 atomic_t relogin_timer; /* Max Time to wait for
38920 * relogin to complete */
38921 - atomic_t relogin_retry_count; /* Num of times relogin has been
38922 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38923 * retried */
38924 uint32_t default_time2wait; /* Default Min time between
38925 * relogins (+aens) */
38926 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38927 index fbc546e..c7d1b48 100644
38928 --- a/drivers/scsi/qla4xxx/ql4_os.c
38929 +++ b/drivers/scsi/qla4xxx/ql4_os.c
38930 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38931 */
38932 if (!iscsi_is_session_online(cls_sess)) {
38933 /* Reset retry relogin timer */
38934 - atomic_inc(&ddb_entry->relogin_retry_count);
38935 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38936 DEBUG2(ql4_printk(KERN_INFO, ha,
38937 "%s: index[%d] relogin timed out-retrying"
38938 " relogin (%d), retry (%d)\n", __func__,
38939 ddb_entry->fw_ddb_index,
38940 - atomic_read(&ddb_entry->relogin_retry_count),
38941 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38942 ddb_entry->default_time2wait + 4));
38943 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38944 atomic_set(&ddb_entry->retry_relogin_timer,
38945 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38946
38947 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38948 atomic_set(&ddb_entry->relogin_timer, 0);
38949 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38950 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38951 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38952 ddb_entry->default_relogin_timeout =
38953 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38954 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38955 index 2c0d0ec..4e8681a 100644
38956 --- a/drivers/scsi/scsi.c
38957 +++ b/drivers/scsi/scsi.c
38958 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38959 unsigned long timeout;
38960 int rtn = 0;
38961
38962 - atomic_inc(&cmd->device->iorequest_cnt);
38963 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38964
38965 /* check if the device is still usable */
38966 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38967 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38968 index 9032e91..7a805d0 100644
38969 --- a/drivers/scsi/scsi_lib.c
38970 +++ b/drivers/scsi/scsi_lib.c
38971 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38972 shost = sdev->host;
38973 scsi_init_cmd_errh(cmd);
38974 cmd->result = DID_NO_CONNECT << 16;
38975 - atomic_inc(&cmd->device->iorequest_cnt);
38976 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38977
38978 /*
38979 * SCSI request completion path will do scsi_device_unbusy(),
38980 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
38981
38982 INIT_LIST_HEAD(&cmd->eh_entry);
38983
38984 - atomic_inc(&cmd->device->iodone_cnt);
38985 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
38986 if (cmd->result)
38987 - atomic_inc(&cmd->device->ioerr_cnt);
38988 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38989
38990 disposition = scsi_decide_disposition(cmd);
38991 if (disposition != SUCCESS &&
38992 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38993 index 931a7d9..0c2a754 100644
38994 --- a/drivers/scsi/scsi_sysfs.c
38995 +++ b/drivers/scsi/scsi_sysfs.c
38996 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38997 char *buf) \
38998 { \
38999 struct scsi_device *sdev = to_scsi_device(dev); \
39000 - unsigned long long count = atomic_read(&sdev->field); \
39001 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
39002 return snprintf(buf, 20, "0x%llx\n", count); \
39003 } \
39004 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39005 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
39006 index 84a1fdf..693b0d6 100644
39007 --- a/drivers/scsi/scsi_tgt_lib.c
39008 +++ b/drivers/scsi/scsi_tgt_lib.c
39009 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
39010 int err;
39011
39012 dprintk("%lx %u\n", uaddr, len);
39013 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39014 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39015 if (err) {
39016 /*
39017 * TODO: need to fixup sg_tablesize, max_segment_size,
39018 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39019 index e894ca7..de9d7660 100644
39020 --- a/drivers/scsi/scsi_transport_fc.c
39021 +++ b/drivers/scsi/scsi_transport_fc.c
39022 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39023 * Netlink Infrastructure
39024 */
39025
39026 -static atomic_t fc_event_seq;
39027 +static atomic_unchecked_t fc_event_seq;
39028
39029 /**
39030 * fc_get_event_number - Obtain the next sequential FC event number
39031 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39032 u32
39033 fc_get_event_number(void)
39034 {
39035 - return atomic_add_return(1, &fc_event_seq);
39036 + return atomic_add_return_unchecked(1, &fc_event_seq);
39037 }
39038 EXPORT_SYMBOL(fc_get_event_number);
39039
39040 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39041 {
39042 int error;
39043
39044 - atomic_set(&fc_event_seq, 0);
39045 + atomic_set_unchecked(&fc_event_seq, 0);
39046
39047 error = transport_class_register(&fc_host_class);
39048 if (error)
39049 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39050 char *cp;
39051
39052 *val = simple_strtoul(buf, &cp, 0);
39053 - if ((*cp && (*cp != '\n')) || (*val < 0))
39054 + if (*cp && (*cp != '\n'))
39055 return -EINVAL;
39056 /*
39057 * Check for overflow; dev_loss_tmo is u32
39058 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39059 index 31969f2..2b348f0 100644
39060 --- a/drivers/scsi/scsi_transport_iscsi.c
39061 +++ b/drivers/scsi/scsi_transport_iscsi.c
39062 @@ -79,7 +79,7 @@ struct iscsi_internal {
39063 struct transport_container session_cont;
39064 };
39065
39066 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39067 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39068 static struct workqueue_struct *iscsi_eh_timer_workq;
39069
39070 static DEFINE_IDA(iscsi_sess_ida);
39071 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39072 int err;
39073
39074 ihost = shost->shost_data;
39075 - session->sid = atomic_add_return(1, &iscsi_session_nr);
39076 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39077
39078 if (target_id == ISCSI_MAX_TARGET) {
39079 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39080 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39081 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39082 ISCSI_TRANSPORT_VERSION);
39083
39084 - atomic_set(&iscsi_session_nr, 0);
39085 + atomic_set_unchecked(&iscsi_session_nr, 0);
39086
39087 err = class_register(&iscsi_transport_class);
39088 if (err)
39089 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39090 index 21a045e..ec89e03 100644
39091 --- a/drivers/scsi/scsi_transport_srp.c
39092 +++ b/drivers/scsi/scsi_transport_srp.c
39093 @@ -33,7 +33,7 @@
39094 #include "scsi_transport_srp_internal.h"
39095
39096 struct srp_host_attrs {
39097 - atomic_t next_port_id;
39098 + atomic_unchecked_t next_port_id;
39099 };
39100 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39101
39102 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39103 struct Scsi_Host *shost = dev_to_shost(dev);
39104 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39105
39106 - atomic_set(&srp_host->next_port_id, 0);
39107 + atomic_set_unchecked(&srp_host->next_port_id, 0);
39108 return 0;
39109 }
39110
39111 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39112 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39113 rport->roles = ids->roles;
39114
39115 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39116 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39117 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39118
39119 transport_setup_device(&rport->dev);
39120 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39121 index a45e12a..d9120cb 100644
39122 --- a/drivers/scsi/sd.c
39123 +++ b/drivers/scsi/sd.c
39124 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
39125 sdkp->disk = gd;
39126 sdkp->index = index;
39127 atomic_set(&sdkp->openers, 0);
39128 - atomic_set(&sdkp->device->ioerr_cnt, 0);
39129 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39130
39131 if (!sdp->request_queue->rq_timeout) {
39132 if (sdp->type != TYPE_MOD)
39133 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39134 index be2c9a6..275525c 100644
39135 --- a/drivers/scsi/sg.c
39136 +++ b/drivers/scsi/sg.c
39137 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39138 sdp->disk->disk_name,
39139 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39140 NULL,
39141 - (char *)arg);
39142 + (char __user *)arg);
39143 case BLKTRACESTART:
39144 return blk_trace_startstop(sdp->device->request_queue, 1);
39145 case BLKTRACESTOP:
39146 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39147 index 84c2861..ece0a31 100644
39148 --- a/drivers/spi/spi.c
39149 +++ b/drivers/spi/spi.c
39150 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
39151 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39152
39153 /* portable code must never pass more than 32 bytes */
39154 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39155 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39156
39157 static u8 *buf;
39158
39159 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39160 index 34afc16..ffe44dd 100644
39161 --- a/drivers/staging/octeon/ethernet-rx.c
39162 +++ b/drivers/staging/octeon/ethernet-rx.c
39163 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39164 /* Increment RX stats for virtual ports */
39165 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39166 #ifdef CONFIG_64BIT
39167 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39168 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39169 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39170 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39171 #else
39172 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39173 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39174 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39175 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39176 #endif
39177 }
39178 netif_receive_skb(skb);
39179 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39180 dev->name);
39181 */
39182 #ifdef CONFIG_64BIT
39183 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39184 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39185 #else
39186 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39187 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39188 #endif
39189 dev_kfree_skb_irq(skb);
39190 }
39191 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39192 index 683bedc..86dba9a 100644
39193 --- a/drivers/staging/octeon/ethernet.c
39194 +++ b/drivers/staging/octeon/ethernet.c
39195 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39196 * since the RX tasklet also increments it.
39197 */
39198 #ifdef CONFIG_64BIT
39199 - atomic64_add(rx_status.dropped_packets,
39200 - (atomic64_t *)&priv->stats.rx_dropped);
39201 + atomic64_add_unchecked(rx_status.dropped_packets,
39202 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39203 #else
39204 - atomic_add(rx_status.dropped_packets,
39205 - (atomic_t *)&priv->stats.rx_dropped);
39206 + atomic_add_unchecked(rx_status.dropped_packets,
39207 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39208 #endif
39209 }
39210
39211 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39212 index a2b7e03..aaf3630 100644
39213 --- a/drivers/staging/ramster/tmem.c
39214 +++ b/drivers/staging/ramster/tmem.c
39215 @@ -50,25 +50,25 @@
39216 * A tmem host implementation must use this function to register callbacks
39217 * for memory allocation.
39218 */
39219 -static struct tmem_hostops tmem_hostops;
39220 +static struct tmem_hostops *tmem_hostops;
39221
39222 static void tmem_objnode_tree_init(void);
39223
39224 void tmem_register_hostops(struct tmem_hostops *m)
39225 {
39226 tmem_objnode_tree_init();
39227 - tmem_hostops = *m;
39228 + tmem_hostops = m;
39229 }
39230
39231 /*
39232 * A tmem host implementation must use this function to register
39233 * callbacks for a page-accessible memory (PAM) implementation.
39234 */
39235 -static struct tmem_pamops tmem_pamops;
39236 +static struct tmem_pamops *tmem_pamops;
39237
39238 void tmem_register_pamops(struct tmem_pamops *m)
39239 {
39240 - tmem_pamops = *m;
39241 + tmem_pamops = m;
39242 }
39243
39244 /*
39245 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39246 obj->pampd_count = 0;
39247 #ifdef CONFIG_RAMSTER
39248 if (tmem_pamops.new_obj != NULL)
39249 - (*tmem_pamops.new_obj)(obj);
39250 + (tmem_pamops->new_obj)(obj);
39251 #endif
39252 SET_SENTINEL(obj, OBJ);
39253
39254 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39255 rbnode = rb_next(rbnode);
39256 tmem_pampd_destroy_all_in_obj(obj, true);
39257 tmem_obj_free(obj, hb);
39258 - (*tmem_hostops.obj_free)(obj, pool);
39259 + (tmem_hostops->obj_free)(obj, pool);
39260 }
39261 spin_unlock(&hb->lock);
39262 }
39263 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39264 ASSERT_SENTINEL(obj, OBJ);
39265 BUG_ON(obj->pool == NULL);
39266 ASSERT_SENTINEL(obj->pool, POOL);
39267 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39268 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39269 if (unlikely(objnode == NULL))
39270 goto out;
39271 objnode->obj = obj;
39272 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39273 ASSERT_SENTINEL(pool, POOL);
39274 objnode->obj->objnode_count--;
39275 objnode->obj = NULL;
39276 - (*tmem_hostops.objnode_free)(objnode, pool);
39277 + (tmem_hostops->objnode_free)(objnode, pool);
39278 }
39279
39280 /*
39281 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
39282 void *old_pampd = *(void **)slot;
39283 *(void **)slot = new_pampd;
39284 if (!no_free)
39285 - (*tmem_pamops.free)(old_pampd, obj->pool,
39286 + (tmem_pamops->free)(old_pampd, obj->pool,
39287 NULL, 0, false);
39288 ret = new_pampd;
39289 }
39290 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
39291 if (objnode->slots[i]) {
39292 if (ht == 1) {
39293 obj->pampd_count--;
39294 - (*tmem_pamops.free)(objnode->slots[i],
39295 + (tmem_pamops->free)(objnode->slots[i],
39296 obj->pool, NULL, 0, true);
39297 objnode->slots[i] = NULL;
39298 continue;
39299 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39300 return;
39301 if (obj->objnode_tree_height == 0) {
39302 obj->pampd_count--;
39303 - (*tmem_pamops.free)(obj->objnode_tree_root,
39304 + (tmem_pamops->free)(obj->objnode_tree_root,
39305 obj->pool, NULL, 0, true);
39306 } else {
39307 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
39308 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39309 obj->objnode_tree_root = NULL;
39310 #ifdef CONFIG_RAMSTER
39311 if (tmem_pamops.free_obj != NULL)
39312 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
39313 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
39314 #endif
39315 }
39316
39317 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39318 /* if found, is a dup put, flush the old one */
39319 pampd_del = tmem_pampd_delete_from_obj(obj, index);
39320 BUG_ON(pampd_del != pampd);
39321 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39322 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39323 if (obj->pampd_count == 0) {
39324 objnew = obj;
39325 objfound = NULL;
39326 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39327 pampd = NULL;
39328 }
39329 } else {
39330 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
39331 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
39332 if (unlikely(obj == NULL)) {
39333 ret = -ENOMEM;
39334 goto out;
39335 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39336 if (unlikely(ret == -ENOMEM))
39337 /* may have partially built objnode tree ("stump") */
39338 goto delete_and_free;
39339 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
39340 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
39341 goto out;
39342
39343 delete_and_free:
39344 (void)tmem_pampd_delete_from_obj(obj, index);
39345 if (pampd)
39346 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
39347 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
39348 if (objnew) {
39349 tmem_obj_free(objnew, hb);
39350 - (*tmem_hostops.obj_free)(objnew, pool);
39351 + (tmem_hostops->obj_free)(objnew, pool);
39352 }
39353 out:
39354 spin_unlock(&hb->lock);
39355 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
39356 if (pampd != NULL) {
39357 BUG_ON(obj == NULL);
39358 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
39359 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
39360 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
39361 } else if (delete) {
39362 BUG_ON(obj == NULL);
39363 (void)tmem_pampd_delete_from_obj(obj, index);
39364 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39365 int ret = 0;
39366
39367 if (!is_ephemeral(pool))
39368 - new_pampd = (*tmem_pamops.repatriate_preload)(
39369 + new_pampd = (tmem_pamops->repatriate_preload)(
39370 old_pampd, pool, oidp, index, &intransit);
39371 if (intransit)
39372 ret = -EAGAIN;
39373 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39374 /* must release the hb->lock else repatriate can't sleep */
39375 spin_unlock(&hb->lock);
39376 if (!intransit)
39377 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
39378 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
39379 oidp, index, free, data);
39380 if (ret == -EAGAIN) {
39381 /* rare I think, but should cond_resched()??? */
39382 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
39383 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
39384 /* if we bug here, pamops wasn't properly set up for ramster */
39385 BUG_ON(tmem_pamops.replace_in_obj == NULL);
39386 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
39387 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
39388 out:
39389 spin_unlock(&hb->lock);
39390 return ret;
39391 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39392 if (free) {
39393 if (obj->pampd_count == 0) {
39394 tmem_obj_free(obj, hb);
39395 - (*tmem_hostops.obj_free)(obj, pool);
39396 + (tmem_hostops->obj_free)(obj, pool);
39397 obj = NULL;
39398 }
39399 }
39400 if (free)
39401 - ret = (*tmem_pamops.get_data_and_free)(
39402 + ret = (tmem_pamops->get_data_and_free)(
39403 data, sizep, raw, pampd, pool, oidp, index);
39404 else
39405 - ret = (*tmem_pamops.get_data)(
39406 + ret = (tmem_pamops->get_data)(
39407 data, sizep, raw, pampd, pool, oidp, index);
39408 if (ret < 0)
39409 goto out;
39410 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
39411 pampd = tmem_pampd_delete_from_obj(obj, index);
39412 if (pampd == NULL)
39413 goto out;
39414 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39415 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39416 if (obj->pampd_count == 0) {
39417 tmem_obj_free(obj, hb);
39418 - (*tmem_hostops.obj_free)(obj, pool);
39419 + (tmem_hostops->obj_free)(obj, pool);
39420 }
39421 ret = 0;
39422
39423 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
39424 goto out;
39425 tmem_pampd_destroy_all_in_obj(obj, false);
39426 tmem_obj_free(obj, hb);
39427 - (*tmem_hostops.obj_free)(obj, pool);
39428 + (tmem_hostops->obj_free)(obj, pool);
39429 ret = 0;
39430
39431 out:
39432 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
39433 index dc23395..cf7e9b1 100644
39434 --- a/drivers/staging/rtl8712/rtl871x_io.h
39435 +++ b/drivers/staging/rtl8712/rtl871x_io.h
39436 @@ -108,7 +108,7 @@ struct _io_ops {
39437 u8 *pmem);
39438 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
39439 u8 *pmem);
39440 -};
39441 +} __no_const;
39442
39443 struct io_req {
39444 struct list_head list;
39445 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
39446 index 180c963..1f18377 100644
39447 --- a/drivers/staging/sbe-2t3e3/netdev.c
39448 +++ b/drivers/staging/sbe-2t3e3/netdev.c
39449 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39450 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39451
39452 if (rlen)
39453 - if (copy_to_user(data, &resp, rlen))
39454 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39455 return -EFAULT;
39456
39457 return 0;
39458 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39459 index c66b8b3..a4a035b 100644
39460 --- a/drivers/staging/usbip/vhci.h
39461 +++ b/drivers/staging/usbip/vhci.h
39462 @@ -83,7 +83,7 @@ struct vhci_hcd {
39463 unsigned resuming:1;
39464 unsigned long re_timeout;
39465
39466 - atomic_t seqnum;
39467 + atomic_unchecked_t seqnum;
39468
39469 /*
39470 * NOTE:
39471 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39472 index 620d1be..1cd6711 100644
39473 --- a/drivers/staging/usbip/vhci_hcd.c
39474 +++ b/drivers/staging/usbip/vhci_hcd.c
39475 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39476 return;
39477 }
39478
39479 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39480 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39481 if (priv->seqnum == 0xffff)
39482 dev_info(&urb->dev->dev, "seqnum max\n");
39483
39484 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39485 return -ENOMEM;
39486 }
39487
39488 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39489 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39490 if (unlink->seqnum == 0xffff)
39491 pr_info("seqnum max\n");
39492
39493 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39494 vdev->rhport = rhport;
39495 }
39496
39497 - atomic_set(&vhci->seqnum, 0);
39498 + atomic_set_unchecked(&vhci->seqnum, 0);
39499 spin_lock_init(&vhci->lock);
39500
39501 hcd->power_budget = 0; /* no limit */
39502 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39503 index f0eaf04..5a82e06 100644
39504 --- a/drivers/staging/usbip/vhci_rx.c
39505 +++ b/drivers/staging/usbip/vhci_rx.c
39506 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39507 if (!urb) {
39508 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39509 pr_info("max seqnum %d\n",
39510 - atomic_read(&the_controller->seqnum));
39511 + atomic_read_unchecked(&the_controller->seqnum));
39512 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39513 return;
39514 }
39515 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39516 index 67b1b88..6392fe9 100644
39517 --- a/drivers/staging/vt6655/hostap.c
39518 +++ b/drivers/staging/vt6655/hostap.c
39519 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39520 *
39521 */
39522
39523 +static net_device_ops_no_const apdev_netdev_ops;
39524 +
39525 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39526 {
39527 PSDevice apdev_priv;
39528 struct net_device *dev = pDevice->dev;
39529 int ret;
39530 - const struct net_device_ops apdev_netdev_ops = {
39531 - .ndo_start_xmit = pDevice->tx_80211,
39532 - };
39533
39534 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39535
39536 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39537 *apdev_priv = *pDevice;
39538 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39539
39540 + /* only half broken now */
39541 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39542 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39543
39544 pDevice->apdev->type = ARPHRD_IEEE80211;
39545 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39546 index 0a73d40..6fda560 100644
39547 --- a/drivers/staging/vt6656/hostap.c
39548 +++ b/drivers/staging/vt6656/hostap.c
39549 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39550 *
39551 */
39552
39553 +static net_device_ops_no_const apdev_netdev_ops;
39554 +
39555 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39556 {
39557 PSDevice apdev_priv;
39558 struct net_device *dev = pDevice->dev;
39559 int ret;
39560 - const struct net_device_ops apdev_netdev_ops = {
39561 - .ndo_start_xmit = pDevice->tx_80211,
39562 - };
39563
39564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39565
39566 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39567 *apdev_priv = *pDevice;
39568 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39569
39570 + /* only half broken now */
39571 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39572 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39573
39574 pDevice->apdev->type = ARPHRD_IEEE80211;
39575 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39576 index 56c8e60..1920c63 100644
39577 --- a/drivers/staging/zcache/tmem.c
39578 +++ b/drivers/staging/zcache/tmem.c
39579 @@ -39,7 +39,7 @@
39580 * A tmem host implementation must use this function to register callbacks
39581 * for memory allocation.
39582 */
39583 -static struct tmem_hostops tmem_hostops;
39584 +static tmem_hostops_no_const tmem_hostops;
39585
39586 static void tmem_objnode_tree_init(void);
39587
39588 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39589 * A tmem host implementation must use this function to register
39590 * callbacks for a page-accessible memory (PAM) implementation
39591 */
39592 -static struct tmem_pamops tmem_pamops;
39593 +static tmem_pamops_no_const tmem_pamops;
39594
39595 void tmem_register_pamops(struct tmem_pamops *m)
39596 {
39597 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39598 index 0d4aa82..f7832d4 100644
39599 --- a/drivers/staging/zcache/tmem.h
39600 +++ b/drivers/staging/zcache/tmem.h
39601 @@ -180,6 +180,7 @@ struct tmem_pamops {
39602 void (*new_obj)(struct tmem_obj *);
39603 int (*replace_in_obj)(void *, struct tmem_obj *);
39604 };
39605 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39606 extern void tmem_register_pamops(struct tmem_pamops *m);
39607
39608 /* memory allocation methods provided by the host implementation */
39609 @@ -189,6 +190,7 @@ struct tmem_hostops {
39610 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39611 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39612 };
39613 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39614 extern void tmem_register_hostops(struct tmem_hostops *m);
39615
39616 /* core tmem accessor functions */
39617 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39618 index 13fe16c..cbdc39a 100644
39619 --- a/drivers/target/target_core_transport.c
39620 +++ b/drivers/target/target_core_transport.c
39621 @@ -1085,7 +1085,7 @@ struct se_device *transport_add_device_to_core_hba(
39622 spin_lock_init(&dev->se_port_lock);
39623 spin_lock_init(&dev->se_tmr_lock);
39624 spin_lock_init(&dev->qf_cmd_lock);
39625 - atomic_set(&dev->dev_ordered_id, 0);
39626 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
39627
39628 se_dev_set_default_attribs(dev, dev_limits);
39629
39630 @@ -1275,7 +1275,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39631 * Used to determine when ORDERED commands should go from
39632 * Dormant to Active status.
39633 */
39634 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39635 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39636 smp_mb__after_atomic_inc();
39637 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39638 cmd->se_ordered_id, cmd->sam_task_attr,
39639 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39640 index 0a6a0bc..5501b06 100644
39641 --- a/drivers/tty/cyclades.c
39642 +++ b/drivers/tty/cyclades.c
39643 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39644 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39645 info->port.count);
39646 #endif
39647 - info->port.count++;
39648 + atomic_inc(&info->port.count);
39649 #ifdef CY_DEBUG_COUNT
39650 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39651 - current->pid, info->port.count);
39652 + current->pid, atomic_read(&info->port.count));
39653 #endif
39654
39655 /*
39656 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39657 for (j = 0; j < cy_card[i].nports; j++) {
39658 info = &cy_card[i].ports[j];
39659
39660 - if (info->port.count) {
39661 + if (atomic_read(&info->port.count)) {
39662 /* XXX is the ldisc num worth this? */
39663 struct tty_struct *tty;
39664 struct tty_ldisc *ld;
39665 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39666 index 13ee53b..418d164 100644
39667 --- a/drivers/tty/hvc/hvc_console.c
39668 +++ b/drivers/tty/hvc/hvc_console.c
39669 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39670
39671 spin_lock_irqsave(&hp->port.lock, flags);
39672 /* Check and then increment for fast path open. */
39673 - if (hp->port.count++ > 0) {
39674 + if (atomic_inc_return(&hp->port.count) > 1) {
39675 spin_unlock_irqrestore(&hp->port.lock, flags);
39676 hvc_kick();
39677 return 0;
39678 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39679
39680 spin_lock_irqsave(&hp->port.lock, flags);
39681
39682 - if (--hp->port.count == 0) {
39683 + if (atomic_dec_return(&hp->port.count) == 0) {
39684 spin_unlock_irqrestore(&hp->port.lock, flags);
39685 /* We are done with the tty pointer now. */
39686 tty_port_tty_set(&hp->port, NULL);
39687 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39688 */
39689 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39690 } else {
39691 - if (hp->port.count < 0)
39692 + if (atomic_read(&hp->port.count) < 0)
39693 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39694 - hp->vtermno, hp->port.count);
39695 + hp->vtermno, atomic_read(&hp->port.count));
39696 spin_unlock_irqrestore(&hp->port.lock, flags);
39697 }
39698 }
39699 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39700 * open->hangup case this can be called after the final close so prevent
39701 * that from happening for now.
39702 */
39703 - if (hp->port.count <= 0) {
39704 + if (atomic_read(&hp->port.count) <= 0) {
39705 spin_unlock_irqrestore(&hp->port.lock, flags);
39706 return;
39707 }
39708
39709 - hp->port.count = 0;
39710 + atomic_set(&hp->port.count, 0);
39711 spin_unlock_irqrestore(&hp->port.lock, flags);
39712 tty_port_tty_set(&hp->port, NULL);
39713
39714 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39715 return -EPIPE;
39716
39717 /* FIXME what's this (unprotected) check for? */
39718 - if (hp->port.count <= 0)
39719 + if (atomic_read(&hp->port.count) <= 0)
39720 return -EIO;
39721
39722 spin_lock_irqsave(&hp->lock, flags);
39723 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39724 index cab5c7a..4cc66ea 100644
39725 --- a/drivers/tty/hvc/hvcs.c
39726 +++ b/drivers/tty/hvc/hvcs.c
39727 @@ -83,6 +83,7 @@
39728 #include <asm/hvcserver.h>
39729 #include <asm/uaccess.h>
39730 #include <asm/vio.h>
39731 +#include <asm/local.h>
39732
39733 /*
39734 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39735 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39736
39737 spin_lock_irqsave(&hvcsd->lock, flags);
39738
39739 - if (hvcsd->port.count > 0) {
39740 + if (atomic_read(&hvcsd->port.count) > 0) {
39741 spin_unlock_irqrestore(&hvcsd->lock, flags);
39742 printk(KERN_INFO "HVCS: vterm state unchanged. "
39743 "The hvcs device node is still in use.\n");
39744 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39745 }
39746 }
39747
39748 - hvcsd->port.count = 0;
39749 + atomic_set(&hvcsd->port.count, 0);
39750 hvcsd->port.tty = tty;
39751 tty->driver_data = hvcsd;
39752
39753 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39754 unsigned long flags;
39755
39756 spin_lock_irqsave(&hvcsd->lock, flags);
39757 - hvcsd->port.count++;
39758 + atomic_inc(&hvcsd->port.count);
39759 hvcsd->todo_mask |= HVCS_SCHED_READ;
39760 spin_unlock_irqrestore(&hvcsd->lock, flags);
39761
39762 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39763 hvcsd = tty->driver_data;
39764
39765 spin_lock_irqsave(&hvcsd->lock, flags);
39766 - if (--hvcsd->port.count == 0) {
39767 + if (atomic_dec_and_test(&hvcsd->port.count)) {
39768
39769 vio_disable_interrupts(hvcsd->vdev);
39770
39771 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39772
39773 free_irq(irq, hvcsd);
39774 return;
39775 - } else if (hvcsd->port.count < 0) {
39776 + } else if (atomic_read(&hvcsd->port.count) < 0) {
39777 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39778 " is missmanaged.\n",
39779 - hvcsd->vdev->unit_address, hvcsd->port.count);
39780 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39781 }
39782
39783 spin_unlock_irqrestore(&hvcsd->lock, flags);
39784 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39785
39786 spin_lock_irqsave(&hvcsd->lock, flags);
39787 /* Preserve this so that we know how many kref refs to put */
39788 - temp_open_count = hvcsd->port.count;
39789 + temp_open_count = atomic_read(&hvcsd->port.count);
39790
39791 /*
39792 * Don't kref put inside the spinlock because the destruction
39793 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39794 tty->driver_data = NULL;
39795 hvcsd->port.tty = NULL;
39796
39797 - hvcsd->port.count = 0;
39798 + atomic_set(&hvcsd->port.count, 0);
39799
39800 /* This will drop any buffered data on the floor which is OK in a hangup
39801 * scenario. */
39802 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39803 * the middle of a write operation? This is a crummy place to do this
39804 * but we want to keep it all in the spinlock.
39805 */
39806 - if (hvcsd->port.count <= 0) {
39807 + if (atomic_read(&hvcsd->port.count) <= 0) {
39808 spin_unlock_irqrestore(&hvcsd->lock, flags);
39809 return -ENODEV;
39810 }
39811 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39812 {
39813 struct hvcs_struct *hvcsd = tty->driver_data;
39814
39815 - if (!hvcsd || hvcsd->port.count <= 0)
39816 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39817 return 0;
39818
39819 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39820 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39821 index 160f0ad..588b853 100644
39822 --- a/drivers/tty/ipwireless/tty.c
39823 +++ b/drivers/tty/ipwireless/tty.c
39824 @@ -29,6 +29,7 @@
39825 #include <linux/tty_driver.h>
39826 #include <linux/tty_flip.h>
39827 #include <linux/uaccess.h>
39828 +#include <asm/local.h>
39829
39830 #include "tty.h"
39831 #include "network.h"
39832 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39833 mutex_unlock(&tty->ipw_tty_mutex);
39834 return -ENODEV;
39835 }
39836 - if (tty->port.count == 0)
39837 + if (atomic_read(&tty->port.count) == 0)
39838 tty->tx_bytes_queued = 0;
39839
39840 - tty->port.count++;
39841 + atomic_inc(&tty->port.count);
39842
39843 tty->port.tty = linux_tty;
39844 linux_tty->driver_data = tty;
39845 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39846
39847 static void do_ipw_close(struct ipw_tty *tty)
39848 {
39849 - tty->port.count--;
39850 -
39851 - if (tty->port.count == 0) {
39852 + if (atomic_dec_return(&tty->port.count) == 0) {
39853 struct tty_struct *linux_tty = tty->port.tty;
39854
39855 if (linux_tty != NULL) {
39856 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39857 return;
39858
39859 mutex_lock(&tty->ipw_tty_mutex);
39860 - if (tty->port.count == 0) {
39861 + if (atomic_read(&tty->port.count) == 0) {
39862 mutex_unlock(&tty->ipw_tty_mutex);
39863 return;
39864 }
39865 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39866 return;
39867 }
39868
39869 - if (!tty->port.count) {
39870 + if (!atomic_read(&tty->port.count)) {
39871 mutex_unlock(&tty->ipw_tty_mutex);
39872 return;
39873 }
39874 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39875 return -ENODEV;
39876
39877 mutex_lock(&tty->ipw_tty_mutex);
39878 - if (!tty->port.count) {
39879 + if (!atomic_read(&tty->port.count)) {
39880 mutex_unlock(&tty->ipw_tty_mutex);
39881 return -EINVAL;
39882 }
39883 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39884 if (!tty)
39885 return -ENODEV;
39886
39887 - if (!tty->port.count)
39888 + if (!atomic_read(&tty->port.count))
39889 return -EINVAL;
39890
39891 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39892 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39893 if (!tty)
39894 return 0;
39895
39896 - if (!tty->port.count)
39897 + if (!atomic_read(&tty->port.count))
39898 return 0;
39899
39900 return tty->tx_bytes_queued;
39901 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39902 if (!tty)
39903 return -ENODEV;
39904
39905 - if (!tty->port.count)
39906 + if (!atomic_read(&tty->port.count))
39907 return -EINVAL;
39908
39909 return get_control_lines(tty);
39910 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39911 if (!tty)
39912 return -ENODEV;
39913
39914 - if (!tty->port.count)
39915 + if (!atomic_read(&tty->port.count))
39916 return -EINVAL;
39917
39918 return set_control_lines(tty, set, clear);
39919 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39920 if (!tty)
39921 return -ENODEV;
39922
39923 - if (!tty->port.count)
39924 + if (!atomic_read(&tty->port.count))
39925 return -EINVAL;
39926
39927 /* FIXME: Exactly how is the tty object locked here .. */
39928 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39929 * are gone */
39930 mutex_lock(&ttyj->ipw_tty_mutex);
39931 }
39932 - while (ttyj->port.count)
39933 + while (atomic_read(&ttyj->port.count))
39934 do_ipw_close(ttyj);
39935 ipwireless_disassociate_network_ttys(network,
39936 ttyj->channel_idx);
39937 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39938 index 56e616b..9d9f10a 100644
39939 --- a/drivers/tty/moxa.c
39940 +++ b/drivers/tty/moxa.c
39941 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39942 }
39943
39944 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
39945 - ch->port.count++;
39946 + atomic_inc(&ch->port.count);
39947 tty->driver_data = ch;
39948 tty_port_tty_set(&ch->port, tty);
39949 mutex_lock(&ch->port.mutex);
39950 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
39951 index 1e8e8ce..a9efc93 100644
39952 --- a/drivers/tty/n_gsm.c
39953 +++ b/drivers/tty/n_gsm.c
39954 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
39955 kref_init(&dlci->ref);
39956 mutex_init(&dlci->mutex);
39957 dlci->fifo = &dlci->_fifo;
39958 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
39959 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
39960 kfree(dlci);
39961 return NULL;
39962 }
39963 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
39964 struct gsm_dlci *dlci = tty->driver_data;
39965 struct tty_port *port = &dlci->port;
39966
39967 - port->count++;
39968 + atomic_inc(&port->count);
39969 dlci_get(dlci);
39970 dlci_get(dlci->gsm->dlci[0]);
39971 mux_get(dlci->gsm);
39972 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39973 index 8c0b7b4..e88f052 100644
39974 --- a/drivers/tty/n_tty.c
39975 +++ b/drivers/tty/n_tty.c
39976 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39977 {
39978 *ops = tty_ldisc_N_TTY;
39979 ops->owner = NULL;
39980 - ops->refcount = ops->flags = 0;
39981 + atomic_set(&ops->refcount, 0);
39982 + ops->flags = 0;
39983 }
39984 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39985 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39986 index 8cf8d0a..4ef9ed0 100644
39987 --- a/drivers/tty/pty.c
39988 +++ b/drivers/tty/pty.c
39989 @@ -730,8 +730,10 @@ static void __init unix98_pty_init(void)
39990 panic("Couldn't register Unix98 pts driver");
39991
39992 /* Now create the /dev/ptmx special device */
39993 + pax_open_kernel();
39994 tty_default_fops(&ptmx_fops);
39995 - ptmx_fops.open = ptmx_open;
39996 + *(void **)&ptmx_fops.open = ptmx_open;
39997 + pax_close_kernel();
39998
39999 cdev_init(&ptmx_cdev, &ptmx_fops);
40000 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40001 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
40002 index 9700d34..df7520c 100644
40003 --- a/drivers/tty/rocket.c
40004 +++ b/drivers/tty/rocket.c
40005 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40006 tty->driver_data = info;
40007 tty_port_tty_set(port, tty);
40008
40009 - if (port->count++ == 0) {
40010 + if (atomic_inc_return(&port->count) == 1) {
40011 atomic_inc(&rp_num_ports_open);
40012
40013 #ifdef ROCKET_DEBUG_OPEN
40014 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40015 #endif
40016 }
40017 #ifdef ROCKET_DEBUG_OPEN
40018 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40019 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40020 #endif
40021
40022 /*
40023 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
40024 spin_unlock_irqrestore(&info->port.lock, flags);
40025 return;
40026 }
40027 - if (info->port.count)
40028 + if (atomic_read(&info->port.count))
40029 atomic_dec(&rp_num_ports_open);
40030 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40031 spin_unlock_irqrestore(&info->port.lock, flags);
40032 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40033 index 1002054..dd644a8 100644
40034 --- a/drivers/tty/serial/kgdboc.c
40035 +++ b/drivers/tty/serial/kgdboc.c
40036 @@ -24,8 +24,9 @@
40037 #define MAX_CONFIG_LEN 40
40038
40039 static struct kgdb_io kgdboc_io_ops;
40040 +static struct kgdb_io kgdboc_io_ops_console;
40041
40042 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40043 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40044 static int configured = -1;
40045
40046 static char config[MAX_CONFIG_LEN];
40047 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40048 kgdboc_unregister_kbd();
40049 if (configured == 1)
40050 kgdb_unregister_io_module(&kgdboc_io_ops);
40051 + else if (configured == 2)
40052 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
40053 }
40054
40055 static int configure_kgdboc(void)
40056 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40057 int err;
40058 char *cptr = config;
40059 struct console *cons;
40060 + int is_console = 0;
40061
40062 err = kgdboc_option_setup(config);
40063 if (err || !strlen(config) || isspace(config[0]))
40064 goto noconfig;
40065
40066 err = -ENODEV;
40067 - kgdboc_io_ops.is_console = 0;
40068 kgdb_tty_driver = NULL;
40069
40070 kgdboc_use_kms = 0;
40071 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40072 int idx;
40073 if (cons->device && cons->device(cons, &idx) == p &&
40074 idx == tty_line) {
40075 - kgdboc_io_ops.is_console = 1;
40076 + is_console = 1;
40077 break;
40078 }
40079 cons = cons->next;
40080 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40081 kgdb_tty_line = tty_line;
40082
40083 do_register:
40084 - err = kgdb_register_io_module(&kgdboc_io_ops);
40085 + if (is_console) {
40086 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
40087 + configured = 2;
40088 + } else {
40089 + err = kgdb_register_io_module(&kgdboc_io_ops);
40090 + configured = 1;
40091 + }
40092 if (err)
40093 goto noconfig;
40094
40095 @@ -205,8 +214,6 @@ do_register:
40096 if (err)
40097 goto nmi_con_failed;
40098
40099 - configured = 1;
40100 -
40101 return 0;
40102
40103 nmi_con_failed:
40104 @@ -223,7 +230,7 @@ noconfig:
40105 static int __init init_kgdboc(void)
40106 {
40107 /* Already configured? */
40108 - if (configured == 1)
40109 + if (configured >= 1)
40110 return 0;
40111
40112 return configure_kgdboc();
40113 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40114 if (config[len - 1] == '\n')
40115 config[len - 1] = '\0';
40116
40117 - if (configured == 1)
40118 + if (configured >= 1)
40119 cleanup_kgdboc();
40120
40121 /* Go and configure with the new params. */
40122 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40123 .post_exception = kgdboc_post_exp_handler,
40124 };
40125
40126 +static struct kgdb_io kgdboc_io_ops_console = {
40127 + .name = "kgdboc",
40128 + .read_char = kgdboc_get_char,
40129 + .write_char = kgdboc_put_char,
40130 + .pre_exception = kgdboc_pre_exp_handler,
40131 + .post_exception = kgdboc_post_exp_handler,
40132 + .is_console = 1
40133 +};
40134 +
40135 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40136 /* This is only available if kgdboc is a built in for early debugging */
40137 static int __init kgdboc_early_init(char *opt)
40138 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40139 index 7f04717..0f3794f 100644
40140 --- a/drivers/tty/serial/samsung.c
40141 +++ b/drivers/tty/serial/samsung.c
40142 @@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40143 }
40144 }
40145
40146 +static int s3c64xx_serial_startup(struct uart_port *port);
40147 static int s3c24xx_serial_startup(struct uart_port *port)
40148 {
40149 struct s3c24xx_uart_port *ourport = to_ourport(port);
40150 int ret;
40151
40152 + /* Startup sequence is different for s3c64xx and higher SoC's */
40153 + if (s3c24xx_serial_has_interrupt_mask(port))
40154 + return s3c64xx_serial_startup(port);
40155 +
40156 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40157 port->mapbase, port->membase);
40158
40159 @@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40160 /* setup info for port */
40161 port->dev = &platdev->dev;
40162
40163 - /* Startup sequence is different for s3c64xx and higher SoC's */
40164 - if (s3c24xx_serial_has_interrupt_mask(port))
40165 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40166 -
40167 port->uartclk = 1;
40168
40169 if (cfg->uart_flags & UPF_CONS_FLOW) {
40170 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40171 index 0fcfd98..8244fce 100644
40172 --- a/drivers/tty/serial/serial_core.c
40173 +++ b/drivers/tty/serial/serial_core.c
40174 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
40175 uart_flush_buffer(tty);
40176 uart_shutdown(tty, state);
40177 spin_lock_irqsave(&port->lock, flags);
40178 - port->count = 0;
40179 + atomic_set(&port->count, 0);
40180 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40181 spin_unlock_irqrestore(&port->lock, flags);
40182 tty_port_tty_set(port, NULL);
40183 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40184 goto end;
40185 }
40186
40187 - port->count++;
40188 + atomic_inc(&port->count);
40189 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40190 retval = -ENXIO;
40191 goto err_dec_count;
40192 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40193 /*
40194 * Make sure the device is in D0 state.
40195 */
40196 - if (port->count == 1)
40197 + if (atomic_read(&port->count) == 1)
40198 uart_change_pm(state, 0);
40199
40200 /*
40201 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40202 end:
40203 return retval;
40204 err_dec_count:
40205 - port->count--;
40206 + atomic_inc(&port->count);
40207 mutex_unlock(&port->mutex);
40208 goto end;
40209 }
40210 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40211 index 70e3a52..5742052 100644
40212 --- a/drivers/tty/synclink.c
40213 +++ b/drivers/tty/synclink.c
40214 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40215
40216 if (debug_level >= DEBUG_LEVEL_INFO)
40217 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40218 - __FILE__,__LINE__, info->device_name, info->port.count);
40219 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40220
40221 if (tty_port_close_start(&info->port, tty, filp) == 0)
40222 goto cleanup;
40223 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40224 cleanup:
40225 if (debug_level >= DEBUG_LEVEL_INFO)
40226 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40227 - tty->driver->name, info->port.count);
40228 + tty->driver->name, atomic_read(&info->port.count));
40229
40230 } /* end of mgsl_close() */
40231
40232 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40233
40234 mgsl_flush_buffer(tty);
40235 shutdown(info);
40236 -
40237 - info->port.count = 0;
40238 +
40239 + atomic_set(&info->port.count, 0);
40240 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40241 info->port.tty = NULL;
40242
40243 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40244
40245 if (debug_level >= DEBUG_LEVEL_INFO)
40246 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40247 - __FILE__,__LINE__, tty->driver->name, port->count );
40248 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40249
40250 spin_lock_irqsave(&info->irq_spinlock, flags);
40251 if (!tty_hung_up_p(filp)) {
40252 extra_count = true;
40253 - port->count--;
40254 + atomic_dec(&port->count);
40255 }
40256 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40257 port->blocked_open++;
40258 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40259
40260 if (debug_level >= DEBUG_LEVEL_INFO)
40261 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40262 - __FILE__,__LINE__, tty->driver->name, port->count );
40263 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40264
40265 tty_unlock(tty);
40266 schedule();
40267 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40268
40269 /* FIXME: Racy on hangup during close wait */
40270 if (extra_count)
40271 - port->count++;
40272 + atomic_inc(&port->count);
40273 port->blocked_open--;
40274
40275 if (debug_level >= DEBUG_LEVEL_INFO)
40276 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40277 - __FILE__,__LINE__, tty->driver->name, port->count );
40278 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40279
40280 if (!retval)
40281 port->flags |= ASYNC_NORMAL_ACTIVE;
40282 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40283
40284 if (debug_level >= DEBUG_LEVEL_INFO)
40285 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
40286 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40287 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40288
40289 /* If port is closing, signal caller to try again */
40290 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40291 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40292 spin_unlock_irqrestore(&info->netlock, flags);
40293 goto cleanup;
40294 }
40295 - info->port.count++;
40296 + atomic_inc(&info->port.count);
40297 spin_unlock_irqrestore(&info->netlock, flags);
40298
40299 - if (info->port.count == 1) {
40300 + if (atomic_read(&info->port.count) == 1) {
40301 /* 1st open on this device, init hardware */
40302 retval = startup(info);
40303 if (retval < 0)
40304 @@ -3451,8 +3451,8 @@ cleanup:
40305 if (retval) {
40306 if (tty->count == 1)
40307 info->port.tty = NULL; /* tty layer will release tty struct */
40308 - if(info->port.count)
40309 - info->port.count--;
40310 + if (atomic_read(&info->port.count))
40311 + atomic_dec(&info->port.count);
40312 }
40313
40314 return retval;
40315 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40316 unsigned short new_crctype;
40317
40318 /* return error if TTY interface open */
40319 - if (info->port.count)
40320 + if (atomic_read(&info->port.count))
40321 return -EBUSY;
40322
40323 switch (encoding)
40324 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
40325
40326 /* arbitrate between network and tty opens */
40327 spin_lock_irqsave(&info->netlock, flags);
40328 - if (info->port.count != 0 || info->netcount != 0) {
40329 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40330 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40331 spin_unlock_irqrestore(&info->netlock, flags);
40332 return -EBUSY;
40333 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40334 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40335
40336 /* return error if TTY interface open */
40337 - if (info->port.count)
40338 + if (atomic_read(&info->port.count))
40339 return -EBUSY;
40340
40341 if (cmd != SIOCWANDEV)
40342 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
40343 index b38e954..ce45b38 100644
40344 --- a/drivers/tty/synclink_gt.c
40345 +++ b/drivers/tty/synclink_gt.c
40346 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40347 tty->driver_data = info;
40348 info->port.tty = tty;
40349
40350 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
40351 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
40352
40353 /* If port is closing, signal caller to try again */
40354 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40355 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40356 mutex_unlock(&info->port.mutex);
40357 goto cleanup;
40358 }
40359 - info->port.count++;
40360 + atomic_inc(&info->port.count);
40361 spin_unlock_irqrestore(&info->netlock, flags);
40362
40363 - if (info->port.count == 1) {
40364 + if (atomic_read(&info->port.count) == 1) {
40365 /* 1st open on this device, init hardware */
40366 retval = startup(info);
40367 if (retval < 0) {
40368 @@ -716,8 +716,8 @@ cleanup:
40369 if (retval) {
40370 if (tty->count == 1)
40371 info->port.tty = NULL; /* tty layer will release tty struct */
40372 - if(info->port.count)
40373 - info->port.count--;
40374 + if(atomic_read(&info->port.count))
40375 + atomic_dec(&info->port.count);
40376 }
40377
40378 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
40379 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40380
40381 if (sanity_check(info, tty->name, "close"))
40382 return;
40383 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
40384 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
40385
40386 if (tty_port_close_start(&info->port, tty, filp) == 0)
40387 goto cleanup;
40388 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40389 tty_port_close_end(&info->port, tty);
40390 info->port.tty = NULL;
40391 cleanup:
40392 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
40393 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
40394 }
40395
40396 static void hangup(struct tty_struct *tty)
40397 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
40398 shutdown(info);
40399
40400 spin_lock_irqsave(&info->port.lock, flags);
40401 - info->port.count = 0;
40402 + atomic_set(&info->port.count, 0);
40403 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40404 info->port.tty = NULL;
40405 spin_unlock_irqrestore(&info->port.lock, flags);
40406 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40407 unsigned short new_crctype;
40408
40409 /* return error if TTY interface open */
40410 - if (info->port.count)
40411 + if (atomic_read(&info->port.count))
40412 return -EBUSY;
40413
40414 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
40415 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
40416
40417 /* arbitrate between network and tty opens */
40418 spin_lock_irqsave(&info->netlock, flags);
40419 - if (info->port.count != 0 || info->netcount != 0) {
40420 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40421 DBGINFO(("%s hdlc_open busy\n", dev->name));
40422 spin_unlock_irqrestore(&info->netlock, flags);
40423 return -EBUSY;
40424 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40425 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40426
40427 /* return error if TTY interface open */
40428 - if (info->port.count)
40429 + if (atomic_read(&info->port.count))
40430 return -EBUSY;
40431
40432 if (cmd != SIOCWANDEV)
40433 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40434 if (port == NULL)
40435 continue;
40436 spin_lock(&port->lock);
40437 - if ((port->port.count || port->netcount) &&
40438 + if ((atomic_read(&port->port.count) || port->netcount) &&
40439 port->pending_bh && !port->bh_running &&
40440 !port->bh_requested) {
40441 DBGISR(("%s bh queued\n", port->device_name));
40442 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40443 spin_lock_irqsave(&info->lock, flags);
40444 if (!tty_hung_up_p(filp)) {
40445 extra_count = true;
40446 - port->count--;
40447 + atomic_dec(&port->count);
40448 }
40449 spin_unlock_irqrestore(&info->lock, flags);
40450 port->blocked_open++;
40451 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40452 remove_wait_queue(&port->open_wait, &wait);
40453
40454 if (extra_count)
40455 - port->count++;
40456 + atomic_inc(&port->count);
40457 port->blocked_open--;
40458
40459 if (!retval)
40460 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40461 index f17d9f3..27a041b 100644
40462 --- a/drivers/tty/synclinkmp.c
40463 +++ b/drivers/tty/synclinkmp.c
40464 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40465
40466 if (debug_level >= DEBUG_LEVEL_INFO)
40467 printk("%s(%d):%s open(), old ref count = %d\n",
40468 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40469 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40470
40471 /* If port is closing, signal caller to try again */
40472 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40473 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40474 spin_unlock_irqrestore(&info->netlock, flags);
40475 goto cleanup;
40476 }
40477 - info->port.count++;
40478 + atomic_inc(&info->port.count);
40479 spin_unlock_irqrestore(&info->netlock, flags);
40480
40481 - if (info->port.count == 1) {
40482 + if (atomic_read(&info->port.count) == 1) {
40483 /* 1st open on this device, init hardware */
40484 retval = startup(info);
40485 if (retval < 0)
40486 @@ -797,8 +797,8 @@ cleanup:
40487 if (retval) {
40488 if (tty->count == 1)
40489 info->port.tty = NULL; /* tty layer will release tty struct */
40490 - if(info->port.count)
40491 - info->port.count--;
40492 + if(atomic_read(&info->port.count))
40493 + atomic_dec(&info->port.count);
40494 }
40495
40496 return retval;
40497 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40498
40499 if (debug_level >= DEBUG_LEVEL_INFO)
40500 printk("%s(%d):%s close() entry, count=%d\n",
40501 - __FILE__,__LINE__, info->device_name, info->port.count);
40502 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40503
40504 if (tty_port_close_start(&info->port, tty, filp) == 0)
40505 goto cleanup;
40506 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40507 cleanup:
40508 if (debug_level >= DEBUG_LEVEL_INFO)
40509 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40510 - tty->driver->name, info->port.count);
40511 + tty->driver->name, atomic_read(&info->port.count));
40512 }
40513
40514 /* Called by tty_hangup() when a hangup is signaled.
40515 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40516 shutdown(info);
40517
40518 spin_lock_irqsave(&info->port.lock, flags);
40519 - info->port.count = 0;
40520 + atomic_set(&info->port.count, 0);
40521 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40522 info->port.tty = NULL;
40523 spin_unlock_irqrestore(&info->port.lock, flags);
40524 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40525 unsigned short new_crctype;
40526
40527 /* return error if TTY interface open */
40528 - if (info->port.count)
40529 + if (atomic_read(&info->port.count))
40530 return -EBUSY;
40531
40532 switch (encoding)
40533 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40534
40535 /* arbitrate between network and tty opens */
40536 spin_lock_irqsave(&info->netlock, flags);
40537 - if (info->port.count != 0 || info->netcount != 0) {
40538 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40539 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40540 spin_unlock_irqrestore(&info->netlock, flags);
40541 return -EBUSY;
40542 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40543 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40544
40545 /* return error if TTY interface open */
40546 - if (info->port.count)
40547 + if (atomic_read(&info->port.count))
40548 return -EBUSY;
40549
40550 if (cmd != SIOCWANDEV)
40551 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40552 * do not request bottom half processing if the
40553 * device is not open in a normal mode.
40554 */
40555 - if ( port && (port->port.count || port->netcount) &&
40556 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40557 port->pending_bh && !port->bh_running &&
40558 !port->bh_requested ) {
40559 if ( debug_level >= DEBUG_LEVEL_ISR )
40560 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40561
40562 if (debug_level >= DEBUG_LEVEL_INFO)
40563 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40564 - __FILE__,__LINE__, tty->driver->name, port->count );
40565 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40566
40567 spin_lock_irqsave(&info->lock, flags);
40568 if (!tty_hung_up_p(filp)) {
40569 extra_count = true;
40570 - port->count--;
40571 + atomic_dec(&port->count);
40572 }
40573 spin_unlock_irqrestore(&info->lock, flags);
40574 port->blocked_open++;
40575 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40576
40577 if (debug_level >= DEBUG_LEVEL_INFO)
40578 printk("%s(%d):%s block_til_ready() count=%d\n",
40579 - __FILE__,__LINE__, tty->driver->name, port->count );
40580 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40581
40582 tty_unlock(tty);
40583 schedule();
40584 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40585 remove_wait_queue(&port->open_wait, &wait);
40586
40587 if (extra_count)
40588 - port->count++;
40589 + atomic_inc(&port->count);
40590 port->blocked_open--;
40591
40592 if (debug_level >= DEBUG_LEVEL_INFO)
40593 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40594 - __FILE__,__LINE__, tty->driver->name, port->count );
40595 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40596
40597 if (!retval)
40598 port->flags |= ASYNC_NORMAL_ACTIVE;
40599 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40600 index 16ee6ce..bfcac57 100644
40601 --- a/drivers/tty/sysrq.c
40602 +++ b/drivers/tty/sysrq.c
40603 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40604 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40605 size_t count, loff_t *ppos)
40606 {
40607 - if (count) {
40608 + if (count && capable(CAP_SYS_ADMIN)) {
40609 char c;
40610
40611 if (get_user(c, buf))
40612 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40613 index 2ea176b..2877bc8 100644
40614 --- a/drivers/tty/tty_io.c
40615 +++ b/drivers/tty/tty_io.c
40616 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40617
40618 void tty_default_fops(struct file_operations *fops)
40619 {
40620 - *fops = tty_fops;
40621 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40622 }
40623
40624 /*
40625 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40626 index 0f2a2c5..471e228 100644
40627 --- a/drivers/tty/tty_ldisc.c
40628 +++ b/drivers/tty/tty_ldisc.c
40629 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40630 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40631 struct tty_ldisc_ops *ldo = ld->ops;
40632
40633 - ldo->refcount--;
40634 + atomic_dec(&ldo->refcount);
40635 module_put(ldo->owner);
40636 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40637
40638 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40639 spin_lock_irqsave(&tty_ldisc_lock, flags);
40640 tty_ldiscs[disc] = new_ldisc;
40641 new_ldisc->num = disc;
40642 - new_ldisc->refcount = 0;
40643 + atomic_set(&new_ldisc->refcount, 0);
40644 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40645
40646 return ret;
40647 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40648 return -EINVAL;
40649
40650 spin_lock_irqsave(&tty_ldisc_lock, flags);
40651 - if (tty_ldiscs[disc]->refcount)
40652 + if (atomic_read(&tty_ldiscs[disc]->refcount))
40653 ret = -EBUSY;
40654 else
40655 tty_ldiscs[disc] = NULL;
40656 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40657 if (ldops) {
40658 ret = ERR_PTR(-EAGAIN);
40659 if (try_module_get(ldops->owner)) {
40660 - ldops->refcount++;
40661 + atomic_inc(&ldops->refcount);
40662 ret = ldops;
40663 }
40664 }
40665 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40666 unsigned long flags;
40667
40668 spin_lock_irqsave(&tty_ldisc_lock, flags);
40669 - ldops->refcount--;
40670 + atomic_dec(&ldops->refcount);
40671 module_put(ldops->owner);
40672 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40673 }
40674 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40675 index d7bdd8d..feaef30 100644
40676 --- a/drivers/tty/tty_port.c
40677 +++ b/drivers/tty/tty_port.c
40678 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40679 unsigned long flags;
40680
40681 spin_lock_irqsave(&port->lock, flags);
40682 - port->count = 0;
40683 + atomic_set(&port->count, 0);
40684 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40685 if (port->tty) {
40686 set_bit(TTY_IO_ERROR, &port->tty->flags);
40687 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40688 /* The port lock protects the port counts */
40689 spin_lock_irqsave(&port->lock, flags);
40690 if (!tty_hung_up_p(filp))
40691 - port->count--;
40692 + atomic_dec(&port->count);
40693 port->blocked_open++;
40694 spin_unlock_irqrestore(&port->lock, flags);
40695
40696 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40697 we must not mess that up further */
40698 spin_lock_irqsave(&port->lock, flags);
40699 if (!tty_hung_up_p(filp))
40700 - port->count++;
40701 + atomic_inc(&port->count);
40702 port->blocked_open--;
40703 if (retval == 0)
40704 port->flags |= ASYNC_NORMAL_ACTIVE;
40705 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40706 return 0;
40707 }
40708
40709 - if (tty->count == 1 && port->count != 1) {
40710 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
40711 printk(KERN_WARNING
40712 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40713 - port->count);
40714 - port->count = 1;
40715 + atomic_read(&port->count));
40716 + atomic_set(&port->count, 1);
40717 }
40718 - if (--port->count < 0) {
40719 + if (atomic_dec_return(&port->count) < 0) {
40720 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40721 - port->count);
40722 - port->count = 0;
40723 + atomic_read(&port->count));
40724 + atomic_set(&port->count, 0);
40725 }
40726
40727 - if (port->count) {
40728 + if (atomic_read(&port->count)) {
40729 spin_unlock_irqrestore(&port->lock, flags);
40730 if (port->ops->drop)
40731 port->ops->drop(port);
40732 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40733 {
40734 spin_lock_irq(&port->lock);
40735 if (!tty_hung_up_p(filp))
40736 - ++port->count;
40737 + atomic_inc(&port->count);
40738 spin_unlock_irq(&port->lock);
40739 tty_port_tty_set(port, tty);
40740
40741 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40742 index 681765b..d3ccdf2 100644
40743 --- a/drivers/tty/vt/keyboard.c
40744 +++ b/drivers/tty/vt/keyboard.c
40745 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40746 kbd->kbdmode == VC_OFF) &&
40747 value != KVAL(K_SAK))
40748 return; /* SAK is allowed even in raw mode */
40749 +
40750 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40751 + {
40752 + void *func = fn_handler[value];
40753 + if (func == fn_show_state || func == fn_show_ptregs ||
40754 + func == fn_show_mem)
40755 + return;
40756 + }
40757 +#endif
40758 +
40759 fn_handler[value](vc);
40760 }
40761
40762 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40763 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40764 return -EFAULT;
40765
40766 - if (!capable(CAP_SYS_TTY_CONFIG))
40767 - perm = 0;
40768 -
40769 switch (cmd) {
40770 case KDGKBENT:
40771 /* Ensure another thread doesn't free it under us */
40772 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40773 spin_unlock_irqrestore(&kbd_event_lock, flags);
40774 return put_user(val, &user_kbe->kb_value);
40775 case KDSKBENT:
40776 + if (!capable(CAP_SYS_TTY_CONFIG))
40777 + perm = 0;
40778 +
40779 if (!perm)
40780 return -EPERM;
40781 if (!i && v == K_NOSUCHMAP) {
40782 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40783 int i, j, k;
40784 int ret;
40785
40786 - if (!capable(CAP_SYS_TTY_CONFIG))
40787 - perm = 0;
40788 -
40789 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40790 if (!kbs) {
40791 ret = -ENOMEM;
40792 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40793 kfree(kbs);
40794 return ((p && *p) ? -EOVERFLOW : 0);
40795 case KDSKBSENT:
40796 + if (!capable(CAP_SYS_TTY_CONFIG))
40797 + perm = 0;
40798 +
40799 if (!perm) {
40800 ret = -EPERM;
40801 goto reterr;
40802 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40803 index 5110f36..8dc0a74 100644
40804 --- a/drivers/uio/uio.c
40805 +++ b/drivers/uio/uio.c
40806 @@ -25,6 +25,7 @@
40807 #include <linux/kobject.h>
40808 #include <linux/cdev.h>
40809 #include <linux/uio_driver.h>
40810 +#include <asm/local.h>
40811
40812 #define UIO_MAX_DEVICES (1U << MINORBITS)
40813
40814 @@ -32,10 +33,10 @@ struct uio_device {
40815 struct module *owner;
40816 struct device *dev;
40817 int minor;
40818 - atomic_t event;
40819 + atomic_unchecked_t event;
40820 struct fasync_struct *async_queue;
40821 wait_queue_head_t wait;
40822 - int vma_count;
40823 + local_t vma_count;
40824 struct uio_info *info;
40825 struct kobject *map_dir;
40826 struct kobject *portio_dir;
40827 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40828 struct device_attribute *attr, char *buf)
40829 {
40830 struct uio_device *idev = dev_get_drvdata(dev);
40831 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40832 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40833 }
40834
40835 static struct device_attribute uio_class_attributes[] = {
40836 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40837 {
40838 struct uio_device *idev = info->uio_dev;
40839
40840 - atomic_inc(&idev->event);
40841 + atomic_inc_unchecked(&idev->event);
40842 wake_up_interruptible(&idev->wait);
40843 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40844 }
40845 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40846 }
40847
40848 listener->dev = idev;
40849 - listener->event_count = atomic_read(&idev->event);
40850 + listener->event_count = atomic_read_unchecked(&idev->event);
40851 filep->private_data = listener;
40852
40853 if (idev->info->open) {
40854 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40855 return -EIO;
40856
40857 poll_wait(filep, &idev->wait, wait);
40858 - if (listener->event_count != atomic_read(&idev->event))
40859 + if (listener->event_count != atomic_read_unchecked(&idev->event))
40860 return POLLIN | POLLRDNORM;
40861 return 0;
40862 }
40863 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40864 do {
40865 set_current_state(TASK_INTERRUPTIBLE);
40866
40867 - event_count = atomic_read(&idev->event);
40868 + event_count = atomic_read_unchecked(&idev->event);
40869 if (event_count != listener->event_count) {
40870 if (copy_to_user(buf, &event_count, count))
40871 retval = -EFAULT;
40872 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40873 static void uio_vma_open(struct vm_area_struct *vma)
40874 {
40875 struct uio_device *idev = vma->vm_private_data;
40876 - idev->vma_count++;
40877 + local_inc(&idev->vma_count);
40878 }
40879
40880 static void uio_vma_close(struct vm_area_struct *vma)
40881 {
40882 struct uio_device *idev = vma->vm_private_data;
40883 - idev->vma_count--;
40884 + local_dec(&idev->vma_count);
40885 }
40886
40887 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40888 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40889 idev->owner = owner;
40890 idev->info = info;
40891 init_waitqueue_head(&idev->wait);
40892 - atomic_set(&idev->event, 0);
40893 + atomic_set_unchecked(&idev->event, 0);
40894
40895 ret = uio_get_minor(idev);
40896 if (ret)
40897 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40898 index b7eb86a..36d28af 100644
40899 --- a/drivers/usb/atm/cxacru.c
40900 +++ b/drivers/usb/atm/cxacru.c
40901 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40902 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40903 if (ret < 2)
40904 return -EINVAL;
40905 - if (index < 0 || index > 0x7f)
40906 + if (index > 0x7f)
40907 return -EINVAL;
40908 pos += tmp;
40909
40910 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40911 index 35f10bf..6a38a0b 100644
40912 --- a/drivers/usb/atm/usbatm.c
40913 +++ b/drivers/usb/atm/usbatm.c
40914 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40915 if (printk_ratelimit())
40916 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40917 __func__, vpi, vci);
40918 - atomic_inc(&vcc->stats->rx_err);
40919 + atomic_inc_unchecked(&vcc->stats->rx_err);
40920 return;
40921 }
40922
40923 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40924 if (length > ATM_MAX_AAL5_PDU) {
40925 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40926 __func__, length, vcc);
40927 - atomic_inc(&vcc->stats->rx_err);
40928 + atomic_inc_unchecked(&vcc->stats->rx_err);
40929 goto out;
40930 }
40931
40932 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40933 if (sarb->len < pdu_length) {
40934 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40935 __func__, pdu_length, sarb->len, vcc);
40936 - atomic_inc(&vcc->stats->rx_err);
40937 + atomic_inc_unchecked(&vcc->stats->rx_err);
40938 goto out;
40939 }
40940
40941 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40942 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
40943 __func__, vcc);
40944 - atomic_inc(&vcc->stats->rx_err);
40945 + atomic_inc_unchecked(&vcc->stats->rx_err);
40946 goto out;
40947 }
40948
40949 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40950 if (printk_ratelimit())
40951 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
40952 __func__, length);
40953 - atomic_inc(&vcc->stats->rx_drop);
40954 + atomic_inc_unchecked(&vcc->stats->rx_drop);
40955 goto out;
40956 }
40957
40958 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40959
40960 vcc->push(vcc, skb);
40961
40962 - atomic_inc(&vcc->stats->rx);
40963 + atomic_inc_unchecked(&vcc->stats->rx);
40964 out:
40965 skb_trim(sarb, 0);
40966 }
40967 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
40968 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
40969
40970 usbatm_pop(vcc, skb);
40971 - atomic_inc(&vcc->stats->tx);
40972 + atomic_inc_unchecked(&vcc->stats->tx);
40973
40974 skb = skb_dequeue(&instance->sndqueue);
40975 }
40976 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
40977 if (!left--)
40978 return sprintf(page,
40979 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
40980 - atomic_read(&atm_dev->stats.aal5.tx),
40981 - atomic_read(&atm_dev->stats.aal5.tx_err),
40982 - atomic_read(&atm_dev->stats.aal5.rx),
40983 - atomic_read(&atm_dev->stats.aal5.rx_err),
40984 - atomic_read(&atm_dev->stats.aal5.rx_drop));
40985 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
40986 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
40987 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
40988 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
40989 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
40990
40991 if (!left--) {
40992 if (instance->disconnected)
40993 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
40994 index f460de3..95ba1f6 100644
40995 --- a/drivers/usb/core/devices.c
40996 +++ b/drivers/usb/core/devices.c
40997 @@ -126,7 +126,7 @@ static const char format_endpt[] =
40998 * time it gets called.
40999 */
41000 static struct device_connect_event {
41001 - atomic_t count;
41002 + atomic_unchecked_t count;
41003 wait_queue_head_t wait;
41004 } device_event = {
41005 .count = ATOMIC_INIT(1),
41006 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41007
41008 void usbfs_conn_disc_event(void)
41009 {
41010 - atomic_add(2, &device_event.count);
41011 + atomic_add_unchecked(2, &device_event.count);
41012 wake_up(&device_event.wait);
41013 }
41014
41015 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
41016
41017 poll_wait(file, &device_event.wait, wait);
41018
41019 - event_count = atomic_read(&device_event.count);
41020 + event_count = atomic_read_unchecked(&device_event.count);
41021 if (file->f_version != event_count) {
41022 file->f_version = event_count;
41023 return POLLIN | POLLRDNORM;
41024 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41025 index f034716..aed0368 100644
41026 --- a/drivers/usb/core/hcd.c
41027 +++ b/drivers/usb/core/hcd.c
41028 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41029 */
41030 usb_get_urb(urb);
41031 atomic_inc(&urb->use_count);
41032 - atomic_inc(&urb->dev->urbnum);
41033 + atomic_inc_unchecked(&urb->dev->urbnum);
41034 usbmon_urb_submit(&hcd->self, urb);
41035
41036 /* NOTE requirements on root-hub callers (usbfs and the hub
41037 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41038 urb->hcpriv = NULL;
41039 INIT_LIST_HEAD(&urb->urb_list);
41040 atomic_dec(&urb->use_count);
41041 - atomic_dec(&urb->dev->urbnum);
41042 + atomic_dec_unchecked(&urb->dev->urbnum);
41043 if (atomic_read(&urb->reject))
41044 wake_up(&usb_kill_urb_queue);
41045 usb_put_urb(urb);
41046 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41047 index 818e4a0..0fc9589 100644
41048 --- a/drivers/usb/core/sysfs.c
41049 +++ b/drivers/usb/core/sysfs.c
41050 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41051 struct usb_device *udev;
41052
41053 udev = to_usb_device(dev);
41054 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41055 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41056 }
41057 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41058
41059 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41060 index cd8fb44..17fbe0c 100644
41061 --- a/drivers/usb/core/usb.c
41062 +++ b/drivers/usb/core/usb.c
41063 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41064 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41065 dev->state = USB_STATE_ATTACHED;
41066 dev->lpm_disable_count = 1;
41067 - atomic_set(&dev->urbnum, 0);
41068 + atomic_set_unchecked(&dev->urbnum, 0);
41069
41070 INIT_LIST_HEAD(&dev->ep0.urb_list);
41071 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41072 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41073 index 4bfa78a..902bfbd 100644
41074 --- a/drivers/usb/early/ehci-dbgp.c
41075 +++ b/drivers/usb/early/ehci-dbgp.c
41076 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41077
41078 #ifdef CONFIG_KGDB
41079 static struct kgdb_io kgdbdbgp_io_ops;
41080 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41081 +static struct kgdb_io kgdbdbgp_io_ops_console;
41082 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41083 #else
41084 #define dbgp_kgdb_mode (0)
41085 #endif
41086 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41087 .write_char = kgdbdbgp_write_char,
41088 };
41089
41090 +static struct kgdb_io kgdbdbgp_io_ops_console = {
41091 + .name = "kgdbdbgp",
41092 + .read_char = kgdbdbgp_read_char,
41093 + .write_char = kgdbdbgp_write_char,
41094 + .is_console = 1
41095 +};
41096 +
41097 static int kgdbdbgp_wait_time;
41098
41099 static int __init kgdbdbgp_parse_config(char *str)
41100 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41101 ptr++;
41102 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41103 }
41104 - kgdb_register_io_module(&kgdbdbgp_io_ops);
41105 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41106 + if (early_dbgp_console.index != -1)
41107 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41108 + else
41109 + kgdb_register_io_module(&kgdbdbgp_io_ops);
41110
41111 return 0;
41112 }
41113 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41114 index f173952..83d6ec0 100644
41115 --- a/drivers/usb/gadget/u_serial.c
41116 +++ b/drivers/usb/gadget/u_serial.c
41117 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41118 spin_lock_irq(&port->port_lock);
41119
41120 /* already open? Great. */
41121 - if (port->port.count) {
41122 + if (atomic_read(&port->port.count)) {
41123 status = 0;
41124 - port->port.count++;
41125 + atomic_inc(&port->port.count);
41126
41127 /* currently opening/closing? wait ... */
41128 } else if (port->openclose) {
41129 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41130 tty->driver_data = port;
41131 port->port.tty = tty;
41132
41133 - port->port.count = 1;
41134 + atomic_set(&port->port.count, 1);
41135 port->openclose = false;
41136
41137 /* if connected, start the I/O stream */
41138 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41139
41140 spin_lock_irq(&port->port_lock);
41141
41142 - if (port->port.count != 1) {
41143 - if (port->port.count == 0)
41144 + if (atomic_read(&port->port.count) != 1) {
41145 + if (atomic_read(&port->port.count) == 0)
41146 WARN_ON(1);
41147 else
41148 - --port->port.count;
41149 + atomic_dec(&port->port.count);
41150 goto exit;
41151 }
41152
41153 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41154 * and sleep if necessary
41155 */
41156 port->openclose = true;
41157 - port->port.count = 0;
41158 + atomic_set(&port->port.count, 0);
41159
41160 gser = port->port_usb;
41161 if (gser && gser->disconnect)
41162 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
41163 int cond;
41164
41165 spin_lock_irq(&port->port_lock);
41166 - cond = (port->port.count == 0) && !port->openclose;
41167 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41168 spin_unlock_irq(&port->port_lock);
41169 return cond;
41170 }
41171 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41172 /* if it's already open, start I/O ... and notify the serial
41173 * protocol about open/close status (connect/disconnect).
41174 */
41175 - if (port->port.count) {
41176 + if (atomic_read(&port->port.count)) {
41177 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41178 gs_start_io(port);
41179 if (gser->connect)
41180 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
41181
41182 port->port_usb = NULL;
41183 gser->ioport = NULL;
41184 - if (port->port.count > 0 || port->openclose) {
41185 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
41186 wake_up_interruptible(&port->drain_wait);
41187 if (port->port.tty)
41188 tty_hangup(port->port.tty);
41189 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
41190
41191 /* finally, free any unused/unusable I/O buffers */
41192 spin_lock_irqsave(&port->port_lock, flags);
41193 - if (port->port.count == 0 && !port->openclose)
41194 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
41195 gs_buf_free(&port->port_write_buf);
41196 gs_free_requests(gser->out, &port->read_pool, NULL);
41197 gs_free_requests(gser->out, &port->read_queue, NULL);
41198 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41199 index 5f3bcd3..bfca43f 100644
41200 --- a/drivers/usb/serial/console.c
41201 +++ b/drivers/usb/serial/console.c
41202 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41203
41204 info->port = port;
41205
41206 - ++port->port.count;
41207 + atomic_inc(&port->port.count);
41208 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41209 if (serial->type->set_termios) {
41210 /*
41211 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41212 }
41213 /* Now that any required fake tty operations are completed restore
41214 * the tty port count */
41215 - --port->port.count;
41216 + atomic_dec(&port->port.count);
41217 /* The console is special in terms of closing the device so
41218 * indicate this port is now acting as a system console. */
41219 port->port.console = 1;
41220 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41221 free_tty:
41222 kfree(tty);
41223 reset_open_count:
41224 - port->port.count = 0;
41225 + atomic_set(&port->port.count, 0);
41226 usb_autopm_put_interface(serial->interface);
41227 error_get_interface:
41228 usb_serial_put(serial);
41229 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41230 index d6bea3e..60b250e 100644
41231 --- a/drivers/usb/wusbcore/wa-hc.h
41232 +++ b/drivers/usb/wusbcore/wa-hc.h
41233 @@ -192,7 +192,7 @@ struct wahc {
41234 struct list_head xfer_delayed_list;
41235 spinlock_t xfer_list_lock;
41236 struct work_struct xfer_work;
41237 - atomic_t xfer_id_count;
41238 + atomic_unchecked_t xfer_id_count;
41239 };
41240
41241
41242 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41243 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41244 spin_lock_init(&wa->xfer_list_lock);
41245 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41246 - atomic_set(&wa->xfer_id_count, 1);
41247 + atomic_set_unchecked(&wa->xfer_id_count, 1);
41248 }
41249
41250 /**
41251 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41252 index 57c01ab..8a05959 100644
41253 --- a/drivers/usb/wusbcore/wa-xfer.c
41254 +++ b/drivers/usb/wusbcore/wa-xfer.c
41255 @@ -296,7 +296,7 @@ out:
41256 */
41257 static void wa_xfer_id_init(struct wa_xfer *xfer)
41258 {
41259 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41260 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41261 }
41262
41263 /*
41264 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
41265 index dedaf81..b0f11ab 100644
41266 --- a/drivers/vhost/vhost.c
41267 +++ b/drivers/vhost/vhost.c
41268 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
41269 return 0;
41270 }
41271
41272 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
41273 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
41274 {
41275 struct file *eventfp, *filep = NULL;
41276 bool pollstart = false, pollstop = false;
41277 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41278 index 0fefa84..7a9d581 100644
41279 --- a/drivers/video/aty/aty128fb.c
41280 +++ b/drivers/video/aty/aty128fb.c
41281 @@ -149,7 +149,7 @@ enum {
41282 };
41283
41284 /* Must match above enum */
41285 -static char * const r128_family[] __devinitconst = {
41286 +static const char * const r128_family[] __devinitconst = {
41287 "AGP",
41288 "PCI",
41289 "PRO AGP",
41290 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
41291 index 5c3960d..15cf8fc 100644
41292 --- a/drivers/video/fbcmap.c
41293 +++ b/drivers/video/fbcmap.c
41294 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
41295 rc = -ENODEV;
41296 goto out;
41297 }
41298 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
41299 - !info->fbops->fb_setcmap)) {
41300 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
41301 rc = -EINVAL;
41302 goto out1;
41303 }
41304 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
41305 index 3ff0105..7589d98 100644
41306 --- a/drivers/video/fbmem.c
41307 +++ b/drivers/video/fbmem.c
41308 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41309 image->dx += image->width + 8;
41310 }
41311 } else if (rotate == FB_ROTATE_UD) {
41312 - for (x = 0; x < num && image->dx >= 0; x++) {
41313 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
41314 info->fbops->fb_imageblit(info, image);
41315 image->dx -= image->width + 8;
41316 }
41317 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41318 image->dy += image->height + 8;
41319 }
41320 } else if (rotate == FB_ROTATE_CCW) {
41321 - for (x = 0; x < num && image->dy >= 0; x++) {
41322 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
41323 info->fbops->fb_imageblit(info, image);
41324 image->dy -= image->height + 8;
41325 }
41326 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
41327 return -EFAULT;
41328 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
41329 return -EINVAL;
41330 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
41331 + if (con2fb.framebuffer >= FB_MAX)
41332 return -EINVAL;
41333 if (!registered_fb[con2fb.framebuffer])
41334 request_module("fb%d", con2fb.framebuffer);
41335 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
41336 index 7672d2e..b56437f 100644
41337 --- a/drivers/video/i810/i810_accel.c
41338 +++ b/drivers/video/i810/i810_accel.c
41339 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
41340 }
41341 }
41342 printk("ringbuffer lockup!!!\n");
41343 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
41344 i810_report_error(mmio);
41345 par->dev_flags |= LOCKUP;
41346 info->pixmap.scan_align = 1;
41347 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
41348 index 3c14e43..eafa544 100644
41349 --- a/drivers/video/logo/logo_linux_clut224.ppm
41350 +++ b/drivers/video/logo/logo_linux_clut224.ppm
41351 @@ -1,1604 +1,1123 @@
41352 P3
41353 -# Standard 224-color Linux logo
41354 80 80
41355 255
41356 - 0 0 0 0 0 0 0 0 0 0 0 0
41357 - 0 0 0 0 0 0 0 0 0 0 0 0
41358 - 0 0 0 0 0 0 0 0 0 0 0 0
41359 - 0 0 0 0 0 0 0 0 0 0 0 0
41360 - 0 0 0 0 0 0 0 0 0 0 0 0
41361 - 0 0 0 0 0 0 0 0 0 0 0 0
41362 - 0 0 0 0 0 0 0 0 0 0 0 0
41363 - 0 0 0 0 0 0 0 0 0 0 0 0
41364 - 0 0 0 0 0 0 0 0 0 0 0 0
41365 - 6 6 6 6 6 6 10 10 10 10 10 10
41366 - 10 10 10 6 6 6 6 6 6 6 6 6
41367 - 0 0 0 0 0 0 0 0 0 0 0 0
41368 - 0 0 0 0 0 0 0 0 0 0 0 0
41369 - 0 0 0 0 0 0 0 0 0 0 0 0
41370 - 0 0 0 0 0 0 0 0 0 0 0 0
41371 - 0 0 0 0 0 0 0 0 0 0 0 0
41372 - 0 0 0 0 0 0 0 0 0 0 0 0
41373 - 0 0 0 0 0 0 0 0 0 0 0 0
41374 - 0 0 0 0 0 0 0 0 0 0 0 0
41375 - 0 0 0 0 0 0 0 0 0 0 0 0
41376 - 0 0 0 0 0 0 0 0 0 0 0 0
41377 - 0 0 0 0 0 0 0 0 0 0 0 0
41378 - 0 0 0 0 0 0 0 0 0 0 0 0
41379 - 0 0 0 0 0 0 0 0 0 0 0 0
41380 - 0 0 0 0 0 0 0 0 0 0 0 0
41381 - 0 0 0 0 0 0 0 0 0 0 0 0
41382 - 0 0 0 0 0 0 0 0 0 0 0 0
41383 - 0 0 0 0 0 0 0 0 0 0 0 0
41384 - 0 0 0 6 6 6 10 10 10 14 14 14
41385 - 22 22 22 26 26 26 30 30 30 34 34 34
41386 - 30 30 30 30 30 30 26 26 26 18 18 18
41387 - 14 14 14 10 10 10 6 6 6 0 0 0
41388 - 0 0 0 0 0 0 0 0 0 0 0 0
41389 - 0 0 0 0 0 0 0 0 0 0 0 0
41390 - 0 0 0 0 0 0 0 0 0 0 0 0
41391 - 0 0 0 0 0 0 0 0 0 0 0 0
41392 - 0 0 0 0 0 0 0 0 0 0 0 0
41393 - 0 0 0 0 0 0 0 0 0 0 0 0
41394 - 0 0 0 0 0 0 0 0 0 0 0 0
41395 - 0 0 0 0 0 0 0 0 0 0 0 0
41396 - 0 0 0 0 0 0 0 0 0 0 0 0
41397 - 0 0 0 0 0 1 0 0 1 0 0 0
41398 - 0 0 0 0 0 0 0 0 0 0 0 0
41399 - 0 0 0 0 0 0 0 0 0 0 0 0
41400 - 0 0 0 0 0 0 0 0 0 0 0 0
41401 - 0 0 0 0 0 0 0 0 0 0 0 0
41402 - 0 0 0 0 0 0 0 0 0 0 0 0
41403 - 0 0 0 0 0 0 0 0 0 0 0 0
41404 - 6 6 6 14 14 14 26 26 26 42 42 42
41405 - 54 54 54 66 66 66 78 78 78 78 78 78
41406 - 78 78 78 74 74 74 66 66 66 54 54 54
41407 - 42 42 42 26 26 26 18 18 18 10 10 10
41408 - 6 6 6 0 0 0 0 0 0 0 0 0
41409 - 0 0 0 0 0 0 0 0 0 0 0 0
41410 - 0 0 0 0 0 0 0 0 0 0 0 0
41411 - 0 0 0 0 0 0 0 0 0 0 0 0
41412 - 0 0 0 0 0 0 0 0 0 0 0 0
41413 - 0 0 0 0 0 0 0 0 0 0 0 0
41414 - 0 0 0 0 0 0 0 0 0 0 0 0
41415 - 0 0 0 0 0 0 0 0 0 0 0 0
41416 - 0 0 0 0 0 0 0 0 0 0 0 0
41417 - 0 0 1 0 0 0 0 0 0 0 0 0
41418 - 0 0 0 0 0 0 0 0 0 0 0 0
41419 - 0 0 0 0 0 0 0 0 0 0 0 0
41420 - 0 0 0 0 0 0 0 0 0 0 0 0
41421 - 0 0 0 0 0 0 0 0 0 0 0 0
41422 - 0 0 0 0 0 0 0 0 0 0 0 0
41423 - 0 0 0 0 0 0 0 0 0 10 10 10
41424 - 22 22 22 42 42 42 66 66 66 86 86 86
41425 - 66 66 66 38 38 38 38 38 38 22 22 22
41426 - 26 26 26 34 34 34 54 54 54 66 66 66
41427 - 86 86 86 70 70 70 46 46 46 26 26 26
41428 - 14 14 14 6 6 6 0 0 0 0 0 0
41429 - 0 0 0 0 0 0 0 0 0 0 0 0
41430 - 0 0 0 0 0 0 0 0 0 0 0 0
41431 - 0 0 0 0 0 0 0 0 0 0 0 0
41432 - 0 0 0 0 0 0 0 0 0 0 0 0
41433 - 0 0 0 0 0 0 0 0 0 0 0 0
41434 - 0 0 0 0 0 0 0 0 0 0 0 0
41435 - 0 0 0 0 0 0 0 0 0 0 0 0
41436 - 0 0 0 0 0 0 0 0 0 0 0 0
41437 - 0 0 1 0 0 1 0 0 1 0 0 0
41438 - 0 0 0 0 0 0 0 0 0 0 0 0
41439 - 0 0 0 0 0 0 0 0 0 0 0 0
41440 - 0 0 0 0 0 0 0 0 0 0 0 0
41441 - 0 0 0 0 0 0 0 0 0 0 0 0
41442 - 0 0 0 0 0 0 0 0 0 0 0 0
41443 - 0 0 0 0 0 0 10 10 10 26 26 26
41444 - 50 50 50 82 82 82 58 58 58 6 6 6
41445 - 2 2 6 2 2 6 2 2 6 2 2 6
41446 - 2 2 6 2 2 6 2 2 6 2 2 6
41447 - 6 6 6 54 54 54 86 86 86 66 66 66
41448 - 38 38 38 18 18 18 6 6 6 0 0 0
41449 - 0 0 0 0 0 0 0 0 0 0 0 0
41450 - 0 0 0 0 0 0 0 0 0 0 0 0
41451 - 0 0 0 0 0 0 0 0 0 0 0 0
41452 - 0 0 0 0 0 0 0 0 0 0 0 0
41453 - 0 0 0 0 0 0 0 0 0 0 0 0
41454 - 0 0 0 0 0 0 0 0 0 0 0 0
41455 - 0 0 0 0 0 0 0 0 0 0 0 0
41456 - 0 0 0 0 0 0 0 0 0 0 0 0
41457 - 0 0 0 0 0 0 0 0 0 0 0 0
41458 - 0 0 0 0 0 0 0 0 0 0 0 0
41459 - 0 0 0 0 0 0 0 0 0 0 0 0
41460 - 0 0 0 0 0 0 0 0 0 0 0 0
41461 - 0 0 0 0 0 0 0 0 0 0 0 0
41462 - 0 0 0 0 0 0 0 0 0 0 0 0
41463 - 0 0 0 6 6 6 22 22 22 50 50 50
41464 - 78 78 78 34 34 34 2 2 6 2 2 6
41465 - 2 2 6 2 2 6 2 2 6 2 2 6
41466 - 2 2 6 2 2 6 2 2 6 2 2 6
41467 - 2 2 6 2 2 6 6 6 6 70 70 70
41468 - 78 78 78 46 46 46 22 22 22 6 6 6
41469 - 0 0 0 0 0 0 0 0 0 0 0 0
41470 - 0 0 0 0 0 0 0 0 0 0 0 0
41471 - 0 0 0 0 0 0 0 0 0 0 0 0
41472 - 0 0 0 0 0 0 0 0 0 0 0 0
41473 - 0 0 0 0 0 0 0 0 0 0 0 0
41474 - 0 0 0 0 0 0 0 0 0 0 0 0
41475 - 0 0 0 0 0 0 0 0 0 0 0 0
41476 - 0 0 0 0 0 0 0 0 0 0 0 0
41477 - 0 0 1 0 0 1 0 0 1 0 0 0
41478 - 0 0 0 0 0 0 0 0 0 0 0 0
41479 - 0 0 0 0 0 0 0 0 0 0 0 0
41480 - 0 0 0 0 0 0 0 0 0 0 0 0
41481 - 0 0 0 0 0 0 0 0 0 0 0 0
41482 - 0 0 0 0 0 0 0 0 0 0 0 0
41483 - 6 6 6 18 18 18 42 42 42 82 82 82
41484 - 26 26 26 2 2 6 2 2 6 2 2 6
41485 - 2 2 6 2 2 6 2 2 6 2 2 6
41486 - 2 2 6 2 2 6 2 2 6 14 14 14
41487 - 46 46 46 34 34 34 6 6 6 2 2 6
41488 - 42 42 42 78 78 78 42 42 42 18 18 18
41489 - 6 6 6 0 0 0 0 0 0 0 0 0
41490 - 0 0 0 0 0 0 0 0 0 0 0 0
41491 - 0 0 0 0 0 0 0 0 0 0 0 0
41492 - 0 0 0 0 0 0 0 0 0 0 0 0
41493 - 0 0 0 0 0 0 0 0 0 0 0 0
41494 - 0 0 0 0 0 0 0 0 0 0 0 0
41495 - 0 0 0 0 0 0 0 0 0 0 0 0
41496 - 0 0 0 0 0 0 0 0 0 0 0 0
41497 - 0 0 1 0 0 0 0 0 1 0 0 0
41498 - 0 0 0 0 0 0 0 0 0 0 0 0
41499 - 0 0 0 0 0 0 0 0 0 0 0 0
41500 - 0 0 0 0 0 0 0 0 0 0 0 0
41501 - 0 0 0 0 0 0 0 0 0 0 0 0
41502 - 0 0 0 0 0 0 0 0 0 0 0 0
41503 - 10 10 10 30 30 30 66 66 66 58 58 58
41504 - 2 2 6 2 2 6 2 2 6 2 2 6
41505 - 2 2 6 2 2 6 2 2 6 2 2 6
41506 - 2 2 6 2 2 6 2 2 6 26 26 26
41507 - 86 86 86 101 101 101 46 46 46 10 10 10
41508 - 2 2 6 58 58 58 70 70 70 34 34 34
41509 - 10 10 10 0 0 0 0 0 0 0 0 0
41510 - 0 0 0 0 0 0 0 0 0 0 0 0
41511 - 0 0 0 0 0 0 0 0 0 0 0 0
41512 - 0 0 0 0 0 0 0 0 0 0 0 0
41513 - 0 0 0 0 0 0 0 0 0 0 0 0
41514 - 0 0 0 0 0 0 0 0 0 0 0 0
41515 - 0 0 0 0 0 0 0 0 0 0 0 0
41516 - 0 0 0 0 0 0 0 0 0 0 0 0
41517 - 0 0 1 0 0 1 0 0 1 0 0 0
41518 - 0 0 0 0 0 0 0 0 0 0 0 0
41519 - 0 0 0 0 0 0 0 0 0 0 0 0
41520 - 0 0 0 0 0 0 0 0 0 0 0 0
41521 - 0 0 0 0 0 0 0 0 0 0 0 0
41522 - 0 0 0 0 0 0 0 0 0 0 0 0
41523 - 14 14 14 42 42 42 86 86 86 10 10 10
41524 - 2 2 6 2 2 6 2 2 6 2 2 6
41525 - 2 2 6 2 2 6 2 2 6 2 2 6
41526 - 2 2 6 2 2 6 2 2 6 30 30 30
41527 - 94 94 94 94 94 94 58 58 58 26 26 26
41528 - 2 2 6 6 6 6 78 78 78 54 54 54
41529 - 22 22 22 6 6 6 0 0 0 0 0 0
41530 - 0 0 0 0 0 0 0 0 0 0 0 0
41531 - 0 0 0 0 0 0 0 0 0 0 0 0
41532 - 0 0 0 0 0 0 0 0 0 0 0 0
41533 - 0 0 0 0 0 0 0 0 0 0 0 0
41534 - 0 0 0 0 0 0 0 0 0 0 0 0
41535 - 0 0 0 0 0 0 0 0 0 0 0 0
41536 - 0 0 0 0 0 0 0 0 0 0 0 0
41537 - 0 0 0 0 0 0 0 0 0 0 0 0
41538 - 0 0 0 0 0 0 0 0 0 0 0 0
41539 - 0 0 0 0 0 0 0 0 0 0 0 0
41540 - 0 0 0 0 0 0 0 0 0 0 0 0
41541 - 0 0 0 0 0 0 0 0 0 0 0 0
41542 - 0 0 0 0 0 0 0 0 0 6 6 6
41543 - 22 22 22 62 62 62 62 62 62 2 2 6
41544 - 2 2 6 2 2 6 2 2 6 2 2 6
41545 - 2 2 6 2 2 6 2 2 6 2 2 6
41546 - 2 2 6 2 2 6 2 2 6 26 26 26
41547 - 54 54 54 38 38 38 18 18 18 10 10 10
41548 - 2 2 6 2 2 6 34 34 34 82 82 82
41549 - 38 38 38 14 14 14 0 0 0 0 0 0
41550 - 0 0 0 0 0 0 0 0 0 0 0 0
41551 - 0 0 0 0 0 0 0 0 0 0 0 0
41552 - 0 0 0 0 0 0 0 0 0 0 0 0
41553 - 0 0 0 0 0 0 0 0 0 0 0 0
41554 - 0 0 0 0 0 0 0 0 0 0 0 0
41555 - 0 0 0 0 0 0 0 0 0 0 0 0
41556 - 0 0 0 0 0 0 0 0 0 0 0 0
41557 - 0 0 0 0 0 1 0 0 1 0 0 0
41558 - 0 0 0 0 0 0 0 0 0 0 0 0
41559 - 0 0 0 0 0 0 0 0 0 0 0 0
41560 - 0 0 0 0 0 0 0 0 0 0 0 0
41561 - 0 0 0 0 0 0 0 0 0 0 0 0
41562 - 0 0 0 0 0 0 0 0 0 6 6 6
41563 - 30 30 30 78 78 78 30 30 30 2 2 6
41564 - 2 2 6 2 2 6 2 2 6 2 2 6
41565 - 2 2 6 2 2 6 2 2 6 2 2 6
41566 - 2 2 6 2 2 6 2 2 6 10 10 10
41567 - 10 10 10 2 2 6 2 2 6 2 2 6
41568 - 2 2 6 2 2 6 2 2 6 78 78 78
41569 - 50 50 50 18 18 18 6 6 6 0 0 0
41570 - 0 0 0 0 0 0 0 0 0 0 0 0
41571 - 0 0 0 0 0 0 0 0 0 0 0 0
41572 - 0 0 0 0 0 0 0 0 0 0 0 0
41573 - 0 0 0 0 0 0 0 0 0 0 0 0
41574 - 0 0 0 0 0 0 0 0 0 0 0 0
41575 - 0 0 0 0 0 0 0 0 0 0 0 0
41576 - 0 0 0 0 0 0 0 0 0 0 0 0
41577 - 0 0 1 0 0 0 0 0 0 0 0 0
41578 - 0 0 0 0 0 0 0 0 0 0 0 0
41579 - 0 0 0 0 0 0 0 0 0 0 0 0
41580 - 0 0 0 0 0 0 0 0 0 0 0 0
41581 - 0 0 0 0 0 0 0 0 0 0 0 0
41582 - 0 0 0 0 0 0 0 0 0 10 10 10
41583 - 38 38 38 86 86 86 14 14 14 2 2 6
41584 - 2 2 6 2 2 6 2 2 6 2 2 6
41585 - 2 2 6 2 2 6 2 2 6 2 2 6
41586 - 2 2 6 2 2 6 2 2 6 2 2 6
41587 - 2 2 6 2 2 6 2 2 6 2 2 6
41588 - 2 2 6 2 2 6 2 2 6 54 54 54
41589 - 66 66 66 26 26 26 6 6 6 0 0 0
41590 - 0 0 0 0 0 0 0 0 0 0 0 0
41591 - 0 0 0 0 0 0 0 0 0 0 0 0
41592 - 0 0 0 0 0 0 0 0 0 0 0 0
41593 - 0 0 0 0 0 0 0 0 0 0 0 0
41594 - 0 0 0 0 0 0 0 0 0 0 0 0
41595 - 0 0 0 0 0 0 0 0 0 0 0 0
41596 - 0 0 0 0 0 0 0 0 0 0 0 0
41597 - 0 0 0 0 0 1 0 0 1 0 0 0
41598 - 0 0 0 0 0 0 0 0 0 0 0 0
41599 - 0 0 0 0 0 0 0 0 0 0 0 0
41600 - 0 0 0 0 0 0 0 0 0 0 0 0
41601 - 0 0 0 0 0 0 0 0 0 0 0 0
41602 - 0 0 0 0 0 0 0 0 0 14 14 14
41603 - 42 42 42 82 82 82 2 2 6 2 2 6
41604 - 2 2 6 6 6 6 10 10 10 2 2 6
41605 - 2 2 6 2 2 6 2 2 6 2 2 6
41606 - 2 2 6 2 2 6 2 2 6 6 6 6
41607 - 14 14 14 10 10 10 2 2 6 2 2 6
41608 - 2 2 6 2 2 6 2 2 6 18 18 18
41609 - 82 82 82 34 34 34 10 10 10 0 0 0
41610 - 0 0 0 0 0 0 0 0 0 0 0 0
41611 - 0 0 0 0 0 0 0 0 0 0 0 0
41612 - 0 0 0 0 0 0 0 0 0 0 0 0
41613 - 0 0 0 0 0 0 0 0 0 0 0 0
41614 - 0 0 0 0 0 0 0 0 0 0 0 0
41615 - 0 0 0 0 0 0 0 0 0 0 0 0
41616 - 0 0 0 0 0 0 0 0 0 0 0 0
41617 - 0 0 1 0 0 0 0 0 0 0 0 0
41618 - 0 0 0 0 0 0 0 0 0 0 0 0
41619 - 0 0 0 0 0 0 0 0 0 0 0 0
41620 - 0 0 0 0 0 0 0 0 0 0 0 0
41621 - 0 0 0 0 0 0 0 0 0 0 0 0
41622 - 0 0 0 0 0 0 0 0 0 14 14 14
41623 - 46 46 46 86 86 86 2 2 6 2 2 6
41624 - 6 6 6 6 6 6 22 22 22 34 34 34
41625 - 6 6 6 2 2 6 2 2 6 2 2 6
41626 - 2 2 6 2 2 6 18 18 18 34 34 34
41627 - 10 10 10 50 50 50 22 22 22 2 2 6
41628 - 2 2 6 2 2 6 2 2 6 10 10 10
41629 - 86 86 86 42 42 42 14 14 14 0 0 0
41630 - 0 0 0 0 0 0 0 0 0 0 0 0
41631 - 0 0 0 0 0 0 0 0 0 0 0 0
41632 - 0 0 0 0 0 0 0 0 0 0 0 0
41633 - 0 0 0 0 0 0 0 0 0 0 0 0
41634 - 0 0 0 0 0 0 0 0 0 0 0 0
41635 - 0 0 0 0 0 0 0 0 0 0 0 0
41636 - 0 0 0 0 0 0 0 0 0 0 0 0
41637 - 0 0 1 0 0 1 0 0 1 0 0 0
41638 - 0 0 0 0 0 0 0 0 0 0 0 0
41639 - 0 0 0 0 0 0 0 0 0 0 0 0
41640 - 0 0 0 0 0 0 0 0 0 0 0 0
41641 - 0 0 0 0 0 0 0 0 0 0 0 0
41642 - 0 0 0 0 0 0 0 0 0 14 14 14
41643 - 46 46 46 86 86 86 2 2 6 2 2 6
41644 - 38 38 38 116 116 116 94 94 94 22 22 22
41645 - 22 22 22 2 2 6 2 2 6 2 2 6
41646 - 14 14 14 86 86 86 138 138 138 162 162 162
41647 -154 154 154 38 38 38 26 26 26 6 6 6
41648 - 2 2 6 2 2 6 2 2 6 2 2 6
41649 - 86 86 86 46 46 46 14 14 14 0 0 0
41650 - 0 0 0 0 0 0 0 0 0 0 0 0
41651 - 0 0 0 0 0 0 0 0 0 0 0 0
41652 - 0 0 0 0 0 0 0 0 0 0 0 0
41653 - 0 0 0 0 0 0 0 0 0 0 0 0
41654 - 0 0 0 0 0 0 0 0 0 0 0 0
41655 - 0 0 0 0 0 0 0 0 0 0 0 0
41656 - 0 0 0 0 0 0 0 0 0 0 0 0
41657 - 0 0 0 0 0 0 0 0 0 0 0 0
41658 - 0 0 0 0 0 0 0 0 0 0 0 0
41659 - 0 0 0 0 0 0 0 0 0 0 0 0
41660 - 0 0 0 0 0 0 0 0 0 0 0 0
41661 - 0 0 0 0 0 0 0 0 0 0 0 0
41662 - 0 0 0 0 0 0 0 0 0 14 14 14
41663 - 46 46 46 86 86 86 2 2 6 14 14 14
41664 -134 134 134 198 198 198 195 195 195 116 116 116
41665 - 10 10 10 2 2 6 2 2 6 6 6 6
41666 -101 98 89 187 187 187 210 210 210 218 218 218
41667 -214 214 214 134 134 134 14 14 14 6 6 6
41668 - 2 2 6 2 2 6 2 2 6 2 2 6
41669 - 86 86 86 50 50 50 18 18 18 6 6 6
41670 - 0 0 0 0 0 0 0 0 0 0 0 0
41671 - 0 0 0 0 0 0 0 0 0 0 0 0
41672 - 0 0 0 0 0 0 0 0 0 0 0 0
41673 - 0 0 0 0 0 0 0 0 0 0 0 0
41674 - 0 0 0 0 0 0 0 0 0 0 0 0
41675 - 0 0 0 0 0 0 0 0 0 0 0 0
41676 - 0 0 0 0 0 0 0 0 1 0 0 0
41677 - 0 0 1 0 0 1 0 0 1 0 0 0
41678 - 0 0 0 0 0 0 0 0 0 0 0 0
41679 - 0 0 0 0 0 0 0 0 0 0 0 0
41680 - 0 0 0 0 0 0 0 0 0 0 0 0
41681 - 0 0 0 0 0 0 0 0 0 0 0 0
41682 - 0 0 0 0 0 0 0 0 0 14 14 14
41683 - 46 46 46 86 86 86 2 2 6 54 54 54
41684 -218 218 218 195 195 195 226 226 226 246 246 246
41685 - 58 58 58 2 2 6 2 2 6 30 30 30
41686 -210 210 210 253 253 253 174 174 174 123 123 123
41687 -221 221 221 234 234 234 74 74 74 2 2 6
41688 - 2 2 6 2 2 6 2 2 6 2 2 6
41689 - 70 70 70 58 58 58 22 22 22 6 6 6
41690 - 0 0 0 0 0 0 0 0 0 0 0 0
41691 - 0 0 0 0 0 0 0 0 0 0 0 0
41692 - 0 0 0 0 0 0 0 0 0 0 0 0
41693 - 0 0 0 0 0 0 0 0 0 0 0 0
41694 - 0 0 0 0 0 0 0 0 0 0 0 0
41695 - 0 0 0 0 0 0 0 0 0 0 0 0
41696 - 0 0 0 0 0 0 0 0 0 0 0 0
41697 - 0 0 0 0 0 0 0 0 0 0 0 0
41698 - 0 0 0 0 0 0 0 0 0 0 0 0
41699 - 0 0 0 0 0 0 0 0 0 0 0 0
41700 - 0 0 0 0 0 0 0 0 0 0 0 0
41701 - 0 0 0 0 0 0 0 0 0 0 0 0
41702 - 0 0 0 0 0 0 0 0 0 14 14 14
41703 - 46 46 46 82 82 82 2 2 6 106 106 106
41704 -170 170 170 26 26 26 86 86 86 226 226 226
41705 -123 123 123 10 10 10 14 14 14 46 46 46
41706 -231 231 231 190 190 190 6 6 6 70 70 70
41707 - 90 90 90 238 238 238 158 158 158 2 2 6
41708 - 2 2 6 2 2 6 2 2 6 2 2 6
41709 - 70 70 70 58 58 58 22 22 22 6 6 6
41710 - 0 0 0 0 0 0 0 0 0 0 0 0
41711 - 0 0 0 0 0 0 0 0 0 0 0 0
41712 - 0 0 0 0 0 0 0 0 0 0 0 0
41713 - 0 0 0 0 0 0 0 0 0 0 0 0
41714 - 0 0 0 0 0 0 0 0 0 0 0 0
41715 - 0 0 0 0 0 0 0 0 0 0 0 0
41716 - 0 0 0 0 0 0 0 0 1 0 0 0
41717 - 0 0 1 0 0 1 0 0 1 0 0 0
41718 - 0 0 0 0 0 0 0 0 0 0 0 0
41719 - 0 0 0 0 0 0 0 0 0 0 0 0
41720 - 0 0 0 0 0 0 0 0 0 0 0 0
41721 - 0 0 0 0 0 0 0 0 0 0 0 0
41722 - 0 0 0 0 0 0 0 0 0 14 14 14
41723 - 42 42 42 86 86 86 6 6 6 116 116 116
41724 -106 106 106 6 6 6 70 70 70 149 149 149
41725 -128 128 128 18 18 18 38 38 38 54 54 54
41726 -221 221 221 106 106 106 2 2 6 14 14 14
41727 - 46 46 46 190 190 190 198 198 198 2 2 6
41728 - 2 2 6 2 2 6 2 2 6 2 2 6
41729 - 74 74 74 62 62 62 22 22 22 6 6 6
41730 - 0 0 0 0 0 0 0 0 0 0 0 0
41731 - 0 0 0 0 0 0 0 0 0 0 0 0
41732 - 0 0 0 0 0 0 0 0 0 0 0 0
41733 - 0 0 0 0 0 0 0 0 0 0 0 0
41734 - 0 0 0 0 0 0 0 0 0 0 0 0
41735 - 0 0 0 0 0 0 0 0 0 0 0 0
41736 - 0 0 0 0 0 0 0 0 1 0 0 0
41737 - 0 0 1 0 0 0 0 0 1 0 0 0
41738 - 0 0 0 0 0 0 0 0 0 0 0 0
41739 - 0 0 0 0 0 0 0 0 0 0 0 0
41740 - 0 0 0 0 0 0 0 0 0 0 0 0
41741 - 0 0 0 0 0 0 0 0 0 0 0 0
41742 - 0 0 0 0 0 0 0 0 0 14 14 14
41743 - 42 42 42 94 94 94 14 14 14 101 101 101
41744 -128 128 128 2 2 6 18 18 18 116 116 116
41745 -118 98 46 121 92 8 121 92 8 98 78 10
41746 -162 162 162 106 106 106 2 2 6 2 2 6
41747 - 2 2 6 195 195 195 195 195 195 6 6 6
41748 - 2 2 6 2 2 6 2 2 6 2 2 6
41749 - 74 74 74 62 62 62 22 22 22 6 6 6
41750 - 0 0 0 0 0 0 0 0 0 0 0 0
41751 - 0 0 0 0 0 0 0 0 0 0 0 0
41752 - 0 0 0 0 0 0 0 0 0 0 0 0
41753 - 0 0 0 0 0 0 0 0 0 0 0 0
41754 - 0 0 0 0 0 0 0 0 0 0 0 0
41755 - 0 0 0 0 0 0 0 0 0 0 0 0
41756 - 0 0 0 0 0 0 0 0 1 0 0 1
41757 - 0 0 1 0 0 0 0 0 1 0 0 0
41758 - 0 0 0 0 0 0 0 0 0 0 0 0
41759 - 0 0 0 0 0 0 0 0 0 0 0 0
41760 - 0 0 0 0 0 0 0 0 0 0 0 0
41761 - 0 0 0 0 0 0 0 0 0 0 0 0
41762 - 0 0 0 0 0 0 0 0 0 10 10 10
41763 - 38 38 38 90 90 90 14 14 14 58 58 58
41764 -210 210 210 26 26 26 54 38 6 154 114 10
41765 -226 170 11 236 186 11 225 175 15 184 144 12
41766 -215 174 15 175 146 61 37 26 9 2 2 6
41767 - 70 70 70 246 246 246 138 138 138 2 2 6
41768 - 2 2 6 2 2 6 2 2 6 2 2 6
41769 - 70 70 70 66 66 66 26 26 26 6 6 6
41770 - 0 0 0 0 0 0 0 0 0 0 0 0
41771 - 0 0 0 0 0 0 0 0 0 0 0 0
41772 - 0 0 0 0 0 0 0 0 0 0 0 0
41773 - 0 0 0 0 0 0 0 0 0 0 0 0
41774 - 0 0 0 0 0 0 0 0 0 0 0 0
41775 - 0 0 0 0 0 0 0 0 0 0 0 0
41776 - 0 0 0 0 0 0 0 0 0 0 0 0
41777 - 0 0 0 0 0 0 0 0 0 0 0 0
41778 - 0 0 0 0 0 0 0 0 0 0 0 0
41779 - 0 0 0 0 0 0 0 0 0 0 0 0
41780 - 0 0 0 0 0 0 0 0 0 0 0 0
41781 - 0 0 0 0 0 0 0 0 0 0 0 0
41782 - 0 0 0 0 0 0 0 0 0 10 10 10
41783 - 38 38 38 86 86 86 14 14 14 10 10 10
41784 -195 195 195 188 164 115 192 133 9 225 175 15
41785 -239 182 13 234 190 10 232 195 16 232 200 30
41786 -245 207 45 241 208 19 232 195 16 184 144 12
41787 -218 194 134 211 206 186 42 42 42 2 2 6
41788 - 2 2 6 2 2 6 2 2 6 2 2 6
41789 - 50 50 50 74 74 74 30 30 30 6 6 6
41790 - 0 0 0 0 0 0 0 0 0 0 0 0
41791 - 0 0 0 0 0 0 0 0 0 0 0 0
41792 - 0 0 0 0 0 0 0 0 0 0 0 0
41793 - 0 0 0 0 0 0 0 0 0 0 0 0
41794 - 0 0 0 0 0 0 0 0 0 0 0 0
41795 - 0 0 0 0 0 0 0 0 0 0 0 0
41796 - 0 0 0 0 0 0 0 0 0 0 0 0
41797 - 0 0 0 0 0 0 0 0 0 0 0 0
41798 - 0 0 0 0 0 0 0 0 0 0 0 0
41799 - 0 0 0 0 0 0 0 0 0 0 0 0
41800 - 0 0 0 0 0 0 0 0 0 0 0 0
41801 - 0 0 0 0 0 0 0 0 0 0 0 0
41802 - 0 0 0 0 0 0 0 0 0 10 10 10
41803 - 34 34 34 86 86 86 14 14 14 2 2 6
41804 -121 87 25 192 133 9 219 162 10 239 182 13
41805 -236 186 11 232 195 16 241 208 19 244 214 54
41806 -246 218 60 246 218 38 246 215 20 241 208 19
41807 -241 208 19 226 184 13 121 87 25 2 2 6
41808 - 2 2 6 2 2 6 2 2 6 2 2 6
41809 - 50 50 50 82 82 82 34 34 34 10 10 10
41810 - 0 0 0 0 0 0 0 0 0 0 0 0
41811 - 0 0 0 0 0 0 0 0 0 0 0 0
41812 - 0 0 0 0 0 0 0 0 0 0 0 0
41813 - 0 0 0 0 0 0 0 0 0 0 0 0
41814 - 0 0 0 0 0 0 0 0 0 0 0 0
41815 - 0 0 0 0 0 0 0 0 0 0 0 0
41816 - 0 0 0 0 0 0 0 0 0 0 0 0
41817 - 0 0 0 0 0 0 0 0 0 0 0 0
41818 - 0 0 0 0 0 0 0 0 0 0 0 0
41819 - 0 0 0 0 0 0 0 0 0 0 0 0
41820 - 0 0 0 0 0 0 0 0 0 0 0 0
41821 - 0 0 0 0 0 0 0 0 0 0 0 0
41822 - 0 0 0 0 0 0 0 0 0 10 10 10
41823 - 34 34 34 82 82 82 30 30 30 61 42 6
41824 -180 123 7 206 145 10 230 174 11 239 182 13
41825 -234 190 10 238 202 15 241 208 19 246 218 74
41826 -246 218 38 246 215 20 246 215 20 246 215 20
41827 -226 184 13 215 174 15 184 144 12 6 6 6
41828 - 2 2 6 2 2 6 2 2 6 2 2 6
41829 - 26 26 26 94 94 94 42 42 42 14 14 14
41830 - 0 0 0 0 0 0 0 0 0 0 0 0
41831 - 0 0 0 0 0 0 0 0 0 0 0 0
41832 - 0 0 0 0 0 0 0 0 0 0 0 0
41833 - 0 0 0 0 0 0 0 0 0 0 0 0
41834 - 0 0 0 0 0 0 0 0 0 0 0 0
41835 - 0 0 0 0 0 0 0 0 0 0 0 0
41836 - 0 0 0 0 0 0 0 0 0 0 0 0
41837 - 0 0 0 0 0 0 0 0 0 0 0 0
41838 - 0 0 0 0 0 0 0 0 0 0 0 0
41839 - 0 0 0 0 0 0 0 0 0 0 0 0
41840 - 0 0 0 0 0 0 0 0 0 0 0 0
41841 - 0 0 0 0 0 0 0 0 0 0 0 0
41842 - 0 0 0 0 0 0 0 0 0 10 10 10
41843 - 30 30 30 78 78 78 50 50 50 104 69 6
41844 -192 133 9 216 158 10 236 178 12 236 186 11
41845 -232 195 16 241 208 19 244 214 54 245 215 43
41846 -246 215 20 246 215 20 241 208 19 198 155 10
41847 -200 144 11 216 158 10 156 118 10 2 2 6
41848 - 2 2 6 2 2 6 2 2 6 2 2 6
41849 - 6 6 6 90 90 90 54 54 54 18 18 18
41850 - 6 6 6 0 0 0 0 0 0 0 0 0
41851 - 0 0 0 0 0 0 0 0 0 0 0 0
41852 - 0 0 0 0 0 0 0 0 0 0 0 0
41853 - 0 0 0 0 0 0 0 0 0 0 0 0
41854 - 0 0 0 0 0 0 0 0 0 0 0 0
41855 - 0 0 0 0 0 0 0 0 0 0 0 0
41856 - 0 0 0 0 0 0 0 0 0 0 0 0
41857 - 0 0 0 0 0 0 0 0 0 0 0 0
41858 - 0 0 0 0 0 0 0 0 0 0 0 0
41859 - 0 0 0 0 0 0 0 0 0 0 0 0
41860 - 0 0 0 0 0 0 0 0 0 0 0 0
41861 - 0 0 0 0 0 0 0 0 0 0 0 0
41862 - 0 0 0 0 0 0 0 0 0 10 10 10
41863 - 30 30 30 78 78 78 46 46 46 22 22 22
41864 -137 92 6 210 162 10 239 182 13 238 190 10
41865 -238 202 15 241 208 19 246 215 20 246 215 20
41866 -241 208 19 203 166 17 185 133 11 210 150 10
41867 -216 158 10 210 150 10 102 78 10 2 2 6
41868 - 6 6 6 54 54 54 14 14 14 2 2 6
41869 - 2 2 6 62 62 62 74 74 74 30 30 30
41870 - 10 10 10 0 0 0 0 0 0 0 0 0
41871 - 0 0 0 0 0 0 0 0 0 0 0 0
41872 - 0 0 0 0 0 0 0 0 0 0 0 0
41873 - 0 0 0 0 0 0 0 0 0 0 0 0
41874 - 0 0 0 0 0 0 0 0 0 0 0 0
41875 - 0 0 0 0 0 0 0 0 0 0 0 0
41876 - 0 0 0 0 0 0 0 0 0 0 0 0
41877 - 0 0 0 0 0 0 0 0 0 0 0 0
41878 - 0 0 0 0 0 0 0 0 0 0 0 0
41879 - 0 0 0 0 0 0 0 0 0 0 0 0
41880 - 0 0 0 0 0 0 0 0 0 0 0 0
41881 - 0 0 0 0 0 0 0 0 0 0 0 0
41882 - 0 0 0 0 0 0 0 0 0 10 10 10
41883 - 34 34 34 78 78 78 50 50 50 6 6 6
41884 - 94 70 30 139 102 15 190 146 13 226 184 13
41885 -232 200 30 232 195 16 215 174 15 190 146 13
41886 -168 122 10 192 133 9 210 150 10 213 154 11
41887 -202 150 34 182 157 106 101 98 89 2 2 6
41888 - 2 2 6 78 78 78 116 116 116 58 58 58
41889 - 2 2 6 22 22 22 90 90 90 46 46 46
41890 - 18 18 18 6 6 6 0 0 0 0 0 0
41891 - 0 0 0 0 0 0 0 0 0 0 0 0
41892 - 0 0 0 0 0 0 0 0 0 0 0 0
41893 - 0 0 0 0 0 0 0 0 0 0 0 0
41894 - 0 0 0 0 0 0 0 0 0 0 0 0
41895 - 0 0 0 0 0 0 0 0 0 0 0 0
41896 - 0 0 0 0 0 0 0 0 0 0 0 0
41897 - 0 0 0 0 0 0 0 0 0 0 0 0
41898 - 0 0 0 0 0 0 0 0 0 0 0 0
41899 - 0 0 0 0 0 0 0 0 0 0 0 0
41900 - 0 0 0 0 0 0 0 0 0 0 0 0
41901 - 0 0 0 0 0 0 0 0 0 0 0 0
41902 - 0 0 0 0 0 0 0 0 0 10 10 10
41903 - 38 38 38 86 86 86 50 50 50 6 6 6
41904 -128 128 128 174 154 114 156 107 11 168 122 10
41905 -198 155 10 184 144 12 197 138 11 200 144 11
41906 -206 145 10 206 145 10 197 138 11 188 164 115
41907 -195 195 195 198 198 198 174 174 174 14 14 14
41908 - 2 2 6 22 22 22 116 116 116 116 116 116
41909 - 22 22 22 2 2 6 74 74 74 70 70 70
41910 - 30 30 30 10 10 10 0 0 0 0 0 0
41911 - 0 0 0 0 0 0 0 0 0 0 0 0
41912 - 0 0 0 0 0 0 0 0 0 0 0 0
41913 - 0 0 0 0 0 0 0 0 0 0 0 0
41914 - 0 0 0 0 0 0 0 0 0 0 0 0
41915 - 0 0 0 0 0 0 0 0 0 0 0 0
41916 - 0 0 0 0 0 0 0 0 0 0 0 0
41917 - 0 0 0 0 0 0 0 0 0 0 0 0
41918 - 0 0 0 0 0 0 0 0 0 0 0 0
41919 - 0 0 0 0 0 0 0 0 0 0 0 0
41920 - 0 0 0 0 0 0 0 0 0 0 0 0
41921 - 0 0 0 0 0 0 0 0 0 0 0 0
41922 - 0 0 0 0 0 0 6 6 6 18 18 18
41923 - 50 50 50 101 101 101 26 26 26 10 10 10
41924 -138 138 138 190 190 190 174 154 114 156 107 11
41925 -197 138 11 200 144 11 197 138 11 192 133 9
41926 -180 123 7 190 142 34 190 178 144 187 187 187
41927 -202 202 202 221 221 221 214 214 214 66 66 66
41928 - 2 2 6 2 2 6 50 50 50 62 62 62
41929 - 6 6 6 2 2 6 10 10 10 90 90 90
41930 - 50 50 50 18 18 18 6 6 6 0 0 0
41931 - 0 0 0 0 0 0 0 0 0 0 0 0
41932 - 0 0 0 0 0 0 0 0 0 0 0 0
41933 - 0 0 0 0 0 0 0 0 0 0 0 0
41934 - 0 0 0 0 0 0 0 0 0 0 0 0
41935 - 0 0 0 0 0 0 0 0 0 0 0 0
41936 - 0 0 0 0 0 0 0 0 0 0 0 0
41937 - 0 0 0 0 0 0 0 0 0 0 0 0
41938 - 0 0 0 0 0 0 0 0 0 0 0 0
41939 - 0 0 0 0 0 0 0 0 0 0 0 0
41940 - 0 0 0 0 0 0 0 0 0 0 0 0
41941 - 0 0 0 0 0 0 0 0 0 0 0 0
41942 - 0 0 0 0 0 0 10 10 10 34 34 34
41943 - 74 74 74 74 74 74 2 2 6 6 6 6
41944 -144 144 144 198 198 198 190 190 190 178 166 146
41945 -154 121 60 156 107 11 156 107 11 168 124 44
41946 -174 154 114 187 187 187 190 190 190 210 210 210
41947 -246 246 246 253 253 253 253 253 253 182 182 182
41948 - 6 6 6 2 2 6 2 2 6 2 2 6
41949 - 2 2 6 2 2 6 2 2 6 62 62 62
41950 - 74 74 74 34 34 34 14 14 14 0 0 0
41951 - 0 0 0 0 0 0 0 0 0 0 0 0
41952 - 0 0 0 0 0 0 0 0 0 0 0 0
41953 - 0 0 0 0 0 0 0 0 0 0 0 0
41954 - 0 0 0 0 0 0 0 0 0 0 0 0
41955 - 0 0 0 0 0 0 0 0 0 0 0 0
41956 - 0 0 0 0 0 0 0 0 0 0 0 0
41957 - 0 0 0 0 0 0 0 0 0 0 0 0
41958 - 0 0 0 0 0 0 0 0 0 0 0 0
41959 - 0 0 0 0 0 0 0 0 0 0 0 0
41960 - 0 0 0 0 0 0 0 0 0 0 0 0
41961 - 0 0 0 0 0 0 0 0 0 0 0 0
41962 - 0 0 0 10 10 10 22 22 22 54 54 54
41963 - 94 94 94 18 18 18 2 2 6 46 46 46
41964 -234 234 234 221 221 221 190 190 190 190 190 190
41965 -190 190 190 187 187 187 187 187 187 190 190 190
41966 -190 190 190 195 195 195 214 214 214 242 242 242
41967 -253 253 253 253 253 253 253 253 253 253 253 253
41968 - 82 82 82 2 2 6 2 2 6 2 2 6
41969 - 2 2 6 2 2 6 2 2 6 14 14 14
41970 - 86 86 86 54 54 54 22 22 22 6 6 6
41971 - 0 0 0 0 0 0 0 0 0 0 0 0
41972 - 0 0 0 0 0 0 0 0 0 0 0 0
41973 - 0 0 0 0 0 0 0 0 0 0 0 0
41974 - 0 0 0 0 0 0 0 0 0 0 0 0
41975 - 0 0 0 0 0 0 0 0 0 0 0 0
41976 - 0 0 0 0 0 0 0 0 0 0 0 0
41977 - 0 0 0 0 0 0 0 0 0 0 0 0
41978 - 0 0 0 0 0 0 0 0 0 0 0 0
41979 - 0 0 0 0 0 0 0 0 0 0 0 0
41980 - 0 0 0 0 0 0 0 0 0 0 0 0
41981 - 0 0 0 0 0 0 0 0 0 0 0 0
41982 - 6 6 6 18 18 18 46 46 46 90 90 90
41983 - 46 46 46 18 18 18 6 6 6 182 182 182
41984 -253 253 253 246 246 246 206 206 206 190 190 190
41985 -190 190 190 190 190 190 190 190 190 190 190 190
41986 -206 206 206 231 231 231 250 250 250 253 253 253
41987 -253 253 253 253 253 253 253 253 253 253 253 253
41988 -202 202 202 14 14 14 2 2 6 2 2 6
41989 - 2 2 6 2 2 6 2 2 6 2 2 6
41990 - 42 42 42 86 86 86 42 42 42 18 18 18
41991 - 6 6 6 0 0 0 0 0 0 0 0 0
41992 - 0 0 0 0 0 0 0 0 0 0 0 0
41993 - 0 0 0 0 0 0 0 0 0 0 0 0
41994 - 0 0 0 0 0 0 0 0 0 0 0 0
41995 - 0 0 0 0 0 0 0 0 0 0 0 0
41996 - 0 0 0 0 0 0 0 0 0 0 0 0
41997 - 0 0 0 0 0 0 0 0 0 0 0 0
41998 - 0 0 0 0 0 0 0 0 0 0 0 0
41999 - 0 0 0 0 0 0 0 0 0 0 0 0
42000 - 0 0 0 0 0 0 0 0 0 0 0 0
42001 - 0 0 0 0 0 0 0 0 0 6 6 6
42002 - 14 14 14 38 38 38 74 74 74 66 66 66
42003 - 2 2 6 6 6 6 90 90 90 250 250 250
42004 -253 253 253 253 253 253 238 238 238 198 198 198
42005 -190 190 190 190 190 190 195 195 195 221 221 221
42006 -246 246 246 253 253 253 253 253 253 253 253 253
42007 -253 253 253 253 253 253 253 253 253 253 253 253
42008 -253 253 253 82 82 82 2 2 6 2 2 6
42009 - 2 2 6 2 2 6 2 2 6 2 2 6
42010 - 2 2 6 78 78 78 70 70 70 34 34 34
42011 - 14 14 14 6 6 6 0 0 0 0 0 0
42012 - 0 0 0 0 0 0 0 0 0 0 0 0
42013 - 0 0 0 0 0 0 0 0 0 0 0 0
42014 - 0 0 0 0 0 0 0 0 0 0 0 0
42015 - 0 0 0 0 0 0 0 0 0 0 0 0
42016 - 0 0 0 0 0 0 0 0 0 0 0 0
42017 - 0 0 0 0 0 0 0 0 0 0 0 0
42018 - 0 0 0 0 0 0 0 0 0 0 0 0
42019 - 0 0 0 0 0 0 0 0 0 0 0 0
42020 - 0 0 0 0 0 0 0 0 0 0 0 0
42021 - 0 0 0 0 0 0 0 0 0 14 14 14
42022 - 34 34 34 66 66 66 78 78 78 6 6 6
42023 - 2 2 6 18 18 18 218 218 218 253 253 253
42024 -253 253 253 253 253 253 253 253 253 246 246 246
42025 -226 226 226 231 231 231 246 246 246 253 253 253
42026 -253 253 253 253 253 253 253 253 253 253 253 253
42027 -253 253 253 253 253 253 253 253 253 253 253 253
42028 -253 253 253 178 178 178 2 2 6 2 2 6
42029 - 2 2 6 2 2 6 2 2 6 2 2 6
42030 - 2 2 6 18 18 18 90 90 90 62 62 62
42031 - 30 30 30 10 10 10 0 0 0 0 0 0
42032 - 0 0 0 0 0 0 0 0 0 0 0 0
42033 - 0 0 0 0 0 0 0 0 0 0 0 0
42034 - 0 0 0 0 0 0 0 0 0 0 0 0
42035 - 0 0 0 0 0 0 0 0 0 0 0 0
42036 - 0 0 0 0 0 0 0 0 0 0 0 0
42037 - 0 0 0 0 0 0 0 0 0 0 0 0
42038 - 0 0 0 0 0 0 0 0 0 0 0 0
42039 - 0 0 0 0 0 0 0 0 0 0 0 0
42040 - 0 0 0 0 0 0 0 0 0 0 0 0
42041 - 0 0 0 0 0 0 10 10 10 26 26 26
42042 - 58 58 58 90 90 90 18 18 18 2 2 6
42043 - 2 2 6 110 110 110 253 253 253 253 253 253
42044 -253 253 253 253 253 253 253 253 253 253 253 253
42045 -250 250 250 253 253 253 253 253 253 253 253 253
42046 -253 253 253 253 253 253 253 253 253 253 253 253
42047 -253 253 253 253 253 253 253 253 253 253 253 253
42048 -253 253 253 231 231 231 18 18 18 2 2 6
42049 - 2 2 6 2 2 6 2 2 6 2 2 6
42050 - 2 2 6 2 2 6 18 18 18 94 94 94
42051 - 54 54 54 26 26 26 10 10 10 0 0 0
42052 - 0 0 0 0 0 0 0 0 0 0 0 0
42053 - 0 0 0 0 0 0 0 0 0 0 0 0
42054 - 0 0 0 0 0 0 0 0 0 0 0 0
42055 - 0 0 0 0 0 0 0 0 0 0 0 0
42056 - 0 0 0 0 0 0 0 0 0 0 0 0
42057 - 0 0 0 0 0 0 0 0 0 0 0 0
42058 - 0 0 0 0 0 0 0 0 0 0 0 0
42059 - 0 0 0 0 0 0 0 0 0 0 0 0
42060 - 0 0 0 0 0 0 0 0 0 0 0 0
42061 - 0 0 0 6 6 6 22 22 22 50 50 50
42062 - 90 90 90 26 26 26 2 2 6 2 2 6
42063 - 14 14 14 195 195 195 250 250 250 253 253 253
42064 -253 253 253 253 253 253 253 253 253 253 253 253
42065 -253 253 253 253 253 253 253 253 253 253 253 253
42066 -253 253 253 253 253 253 253 253 253 253 253 253
42067 -253 253 253 253 253 253 253 253 253 253 253 253
42068 -250 250 250 242 242 242 54 54 54 2 2 6
42069 - 2 2 6 2 2 6 2 2 6 2 2 6
42070 - 2 2 6 2 2 6 2 2 6 38 38 38
42071 - 86 86 86 50 50 50 22 22 22 6 6 6
42072 - 0 0 0 0 0 0 0 0 0 0 0 0
42073 - 0 0 0 0 0 0 0 0 0 0 0 0
42074 - 0 0 0 0 0 0 0 0 0 0 0 0
42075 - 0 0 0 0 0 0 0 0 0 0 0 0
42076 - 0 0 0 0 0 0 0 0 0 0 0 0
42077 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 14 14 14 38 38 38 82 82 82
42082 - 34 34 34 2 2 6 2 2 6 2 2 6
42083 - 42 42 42 195 195 195 246 246 246 253 253 253
42084 -253 253 253 253 253 253 253 253 253 250 250 250
42085 -242 242 242 242 242 242 250 250 250 253 253 253
42086 -253 253 253 253 253 253 253 253 253 253 253 253
42087 -253 253 253 250 250 250 246 246 246 238 238 238
42088 -226 226 226 231 231 231 101 101 101 6 6 6
42089 - 2 2 6 2 2 6 2 2 6 2 2 6
42090 - 2 2 6 2 2 6 2 2 6 2 2 6
42091 - 38 38 38 82 82 82 42 42 42 14 14 14
42092 - 6 6 6 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 - 10 10 10 26 26 26 62 62 62 66 66 66
42102 - 2 2 6 2 2 6 2 2 6 6 6 6
42103 - 70 70 70 170 170 170 206 206 206 234 234 234
42104 -246 246 246 250 250 250 250 250 250 238 238 238
42105 -226 226 226 231 231 231 238 238 238 250 250 250
42106 -250 250 250 250 250 250 246 246 246 231 231 231
42107 -214 214 214 206 206 206 202 202 202 202 202 202
42108 -198 198 198 202 202 202 182 182 182 18 18 18
42109 - 2 2 6 2 2 6 2 2 6 2 2 6
42110 - 2 2 6 2 2 6 2 2 6 2 2 6
42111 - 2 2 6 62 62 62 66 66 66 30 30 30
42112 - 10 10 10 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 0 0 0 0 0 0 0
42120 - 0 0 0 0 0 0 0 0 0 0 0 0
42121 - 14 14 14 42 42 42 82 82 82 18 18 18
42122 - 2 2 6 2 2 6 2 2 6 10 10 10
42123 - 94 94 94 182 182 182 218 218 218 242 242 242
42124 -250 250 250 253 253 253 253 253 253 250 250 250
42125 -234 234 234 253 253 253 253 253 253 253 253 253
42126 -253 253 253 253 253 253 253 253 253 246 246 246
42127 -238 238 238 226 226 226 210 210 210 202 202 202
42128 -195 195 195 195 195 195 210 210 210 158 158 158
42129 - 6 6 6 14 14 14 50 50 50 14 14 14
42130 - 2 2 6 2 2 6 2 2 6 2 2 6
42131 - 2 2 6 6 6 6 86 86 86 46 46 46
42132 - 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
42140 - 0 0 0 0 0 0 0 0 0 6 6 6
42141 - 22 22 22 54 54 54 70 70 70 2 2 6
42142 - 2 2 6 10 10 10 2 2 6 22 22 22
42143 -166 166 166 231 231 231 250 250 250 253 253 253
42144 -253 253 253 253 253 253 253 253 253 250 250 250
42145 -242 242 242 253 253 253 253 253 253 253 253 253
42146 -253 253 253 253 253 253 253 253 253 253 253 253
42147 -253 253 253 253 253 253 253 253 253 246 246 246
42148 -231 231 231 206 206 206 198 198 198 226 226 226
42149 - 94 94 94 2 2 6 6 6 6 38 38 38
42150 - 30 30 30 2 2 6 2 2 6 2 2 6
42151 - 2 2 6 2 2 6 62 62 62 66 66 66
42152 - 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0 0
42160 - 0 0 0 0 0 0 0 0 0 10 10 10
42161 - 30 30 30 74 74 74 50 50 50 2 2 6
42162 - 26 26 26 26 26 26 2 2 6 106 106 106
42163 -238 238 238 253 253 253 253 253 253 253 253 253
42164 -253 253 253 253 253 253 253 253 253 253 253 253
42165 -253 253 253 253 253 253 253 253 253 253 253 253
42166 -253 253 253 253 253 253 253 253 253 253 253 253
42167 -253 253 253 253 253 253 253 253 253 253 253 253
42168 -253 253 253 246 246 246 218 218 218 202 202 202
42169 -210 210 210 14 14 14 2 2 6 2 2 6
42170 - 30 30 30 22 22 22 2 2 6 2 2 6
42171 - 2 2 6 2 2 6 18 18 18 86 86 86
42172 - 42 42 42 14 14 14 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 14 14 14
42181 - 42 42 42 90 90 90 22 22 22 2 2 6
42182 - 42 42 42 2 2 6 18 18 18 218 218 218
42183 -253 253 253 253 253 253 253 253 253 253 253 253
42184 -253 253 253 253 253 253 253 253 253 253 253 253
42185 -253 253 253 253 253 253 253 253 253 253 253 253
42186 -253 253 253 253 253 253 253 253 253 253 253 253
42187 -253 253 253 253 253 253 253 253 253 253 253 253
42188 -253 253 253 253 253 253 250 250 250 221 221 221
42189 -218 218 218 101 101 101 2 2 6 14 14 14
42190 - 18 18 18 38 38 38 10 10 10 2 2 6
42191 - 2 2 6 2 2 6 2 2 6 78 78 78
42192 - 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0 0
42200 - 0 0 0 0 0 0 6 6 6 18 18 18
42201 - 54 54 54 82 82 82 2 2 6 26 26 26
42202 - 22 22 22 2 2 6 123 123 123 253 253 253
42203 -253 253 253 253 253 253 253 253 253 253 253 253
42204 -253 253 253 253 253 253 253 253 253 253 253 253
42205 -253 253 253 253 253 253 253 253 253 253 253 253
42206 -253 253 253 253 253 253 253 253 253 253 253 253
42207 -253 253 253 253 253 253 253 253 253 253 253 253
42208 -253 253 253 253 253 253 253 253 253 250 250 250
42209 -238 238 238 198 198 198 6 6 6 38 38 38
42210 - 58 58 58 26 26 26 38 38 38 2 2 6
42211 - 2 2 6 2 2 6 2 2 6 46 46 46
42212 - 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0 0
42220 - 0 0 0 0 0 0 10 10 10 30 30 30
42221 - 74 74 74 58 58 58 2 2 6 42 42 42
42222 - 2 2 6 22 22 22 231 231 231 253 253 253
42223 -253 253 253 253 253 253 253 253 253 253 253 253
42224 -253 253 253 253 253 253 253 253 253 250 250 250
42225 -253 253 253 253 253 253 253 253 253 253 253 253
42226 -253 253 253 253 253 253 253 253 253 253 253 253
42227 -253 253 253 253 253 253 253 253 253 253 253 253
42228 -253 253 253 253 253 253 253 253 253 253 253 253
42229 -253 253 253 246 246 246 46 46 46 38 38 38
42230 - 42 42 42 14 14 14 38 38 38 14 14 14
42231 - 2 2 6 2 2 6 2 2 6 6 6 6
42232 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0 0 0 0
42240 - 0 0 0 6 6 6 14 14 14 42 42 42
42241 - 90 90 90 18 18 18 18 18 18 26 26 26
42242 - 2 2 6 116 116 116 253 253 253 253 253 253
42243 -253 253 253 253 253 253 253 253 253 253 253 253
42244 -253 253 253 253 253 253 250 250 250 238 238 238
42245 -253 253 253 253 253 253 253 253 253 253 253 253
42246 -253 253 253 253 253 253 253 253 253 253 253 253
42247 -253 253 253 253 253 253 253 253 253 253 253 253
42248 -253 253 253 253 253 253 253 253 253 253 253 253
42249 -253 253 253 253 253 253 94 94 94 6 6 6
42250 - 2 2 6 2 2 6 10 10 10 34 34 34
42251 - 2 2 6 2 2 6 2 2 6 2 2 6
42252 - 74 74 74 58 58 58 22 22 22 6 6 6
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 10 10 10 26 26 26 66 66 66
42261 - 82 82 82 2 2 6 38 38 38 6 6 6
42262 - 14 14 14 210 210 210 253 253 253 253 253 253
42263 -253 253 253 253 253 253 253 253 253 253 253 253
42264 -253 253 253 253 253 253 246 246 246 242 242 242
42265 -253 253 253 253 253 253 253 253 253 253 253 253
42266 -253 253 253 253 253 253 253 253 253 253 253 253
42267 -253 253 253 253 253 253 253 253 253 253 253 253
42268 -253 253 253 253 253 253 253 253 253 253 253 253
42269 -253 253 253 253 253 253 144 144 144 2 2 6
42270 - 2 2 6 2 2 6 2 2 6 46 46 46
42271 - 2 2 6 2 2 6 2 2 6 2 2 6
42272 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0 0 0 0 0
42280 - 6 6 6 14 14 14 42 42 42 90 90 90
42281 - 26 26 26 6 6 6 42 42 42 2 2 6
42282 - 74 74 74 250 250 250 253 253 253 253 253 253
42283 -253 253 253 253 253 253 253 253 253 253 253 253
42284 -253 253 253 253 253 253 242 242 242 242 242 242
42285 -253 253 253 253 253 253 253 253 253 253 253 253
42286 -253 253 253 253 253 253 253 253 253 253 253 253
42287 -253 253 253 253 253 253 253 253 253 253 253 253
42288 -253 253 253 253 253 253 253 253 253 253 253 253
42289 -253 253 253 253 253 253 182 182 182 2 2 6
42290 - 2 2 6 2 2 6 2 2 6 46 46 46
42291 - 2 2 6 2 2 6 2 2 6 2 2 6
42292 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0 0 0 0 0
42300 - 10 10 10 26 26 26 66 66 66 82 82 82
42301 - 2 2 6 22 22 22 18 18 18 2 2 6
42302 -149 149 149 253 253 253 253 253 253 253 253 253
42303 -253 253 253 253 253 253 253 253 253 253 253 253
42304 -253 253 253 253 253 253 234 234 234 242 242 242
42305 -253 253 253 253 253 253 253 253 253 253 253 253
42306 -253 253 253 253 253 253 253 253 253 253 253 253
42307 -253 253 253 253 253 253 253 253 253 253 253 253
42308 -253 253 253 253 253 253 253 253 253 253 253 253
42309 -253 253 253 253 253 253 206 206 206 2 2 6
42310 - 2 2 6 2 2 6 2 2 6 38 38 38
42311 - 2 2 6 2 2 6 2 2 6 2 2 6
42312 - 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 0 6 6 6
42320 - 18 18 18 46 46 46 86 86 86 18 18 18
42321 - 2 2 6 34 34 34 10 10 10 6 6 6
42322 -210 210 210 253 253 253 253 253 253 253 253 253
42323 -253 253 253 253 253 253 253 253 253 253 253 253
42324 -253 253 253 253 253 253 234 234 234 242 242 242
42325 -253 253 253 253 253 253 253 253 253 253 253 253
42326 -253 253 253 253 253 253 253 253 253 253 253 253
42327 -253 253 253 253 253 253 253 253 253 253 253 253
42328 -253 253 253 253 253 253 253 253 253 253 253 253
42329 -253 253 253 253 253 253 221 221 221 6 6 6
42330 - 2 2 6 2 2 6 6 6 6 30 30 30
42331 - 2 2 6 2 2 6 2 2 6 2 2 6
42332 - 2 2 6 82 82 82 54 54 54 18 18 18
42333 - 6 6 6 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 0 0 0 0 0 0 0 10 10 10
42340 - 26 26 26 66 66 66 62 62 62 2 2 6
42341 - 2 2 6 38 38 38 10 10 10 26 26 26
42342 -238 238 238 253 253 253 253 253 253 253 253 253
42343 -253 253 253 253 253 253 253 253 253 253 253 253
42344 -253 253 253 253 253 253 231 231 231 238 238 238
42345 -253 253 253 253 253 253 253 253 253 253 253 253
42346 -253 253 253 253 253 253 253 253 253 253 253 253
42347 -253 253 253 253 253 253 253 253 253 253 253 253
42348 -253 253 253 253 253 253 253 253 253 253 253 253
42349 -253 253 253 253 253 253 231 231 231 6 6 6
42350 - 2 2 6 2 2 6 10 10 10 30 30 30
42351 - 2 2 6 2 2 6 2 2 6 2 2 6
42352 - 2 2 6 66 66 66 58 58 58 22 22 22
42353 - 6 6 6 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 0 0 0 0 0 0 0 10 10 10
42360 - 38 38 38 78 78 78 6 6 6 2 2 6
42361 - 2 2 6 46 46 46 14 14 14 42 42 42
42362 -246 246 246 253 253 253 253 253 253 253 253 253
42363 -253 253 253 253 253 253 253 253 253 253 253 253
42364 -253 253 253 253 253 253 231 231 231 242 242 242
42365 -253 253 253 253 253 253 253 253 253 253 253 253
42366 -253 253 253 253 253 253 253 253 253 253 253 253
42367 -253 253 253 253 253 253 253 253 253 253 253 253
42368 -253 253 253 253 253 253 253 253 253 253 253 253
42369 -253 253 253 253 253 253 234 234 234 10 10 10
42370 - 2 2 6 2 2 6 22 22 22 14 14 14
42371 - 2 2 6 2 2 6 2 2 6 2 2 6
42372 - 2 2 6 66 66 66 62 62 62 22 22 22
42373 - 6 6 6 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 6 6 6 18 18 18
42380 - 50 50 50 74 74 74 2 2 6 2 2 6
42381 - 14 14 14 70 70 70 34 34 34 62 62 62
42382 -250 250 250 253 253 253 253 253 253 253 253 253
42383 -253 253 253 253 253 253 253 253 253 253 253 253
42384 -253 253 253 253 253 253 231 231 231 246 246 246
42385 -253 253 253 253 253 253 253 253 253 253 253 253
42386 -253 253 253 253 253 253 253 253 253 253 253 253
42387 -253 253 253 253 253 253 253 253 253 253 253 253
42388 -253 253 253 253 253 253 253 253 253 253 253 253
42389 -253 253 253 253 253 253 234 234 234 14 14 14
42390 - 2 2 6 2 2 6 30 30 30 2 2 6
42391 - 2 2 6 2 2 6 2 2 6 2 2 6
42392 - 2 2 6 66 66 66 62 62 62 22 22 22
42393 - 6 6 6 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 0 0 0 0
42399 - 0 0 0 0 0 0 6 6 6 18 18 18
42400 - 54 54 54 62 62 62 2 2 6 2 2 6
42401 - 2 2 6 30 30 30 46 46 46 70 70 70
42402 -250 250 250 253 253 253 253 253 253 253 253 253
42403 -253 253 253 253 253 253 253 253 253 253 253 253
42404 -253 253 253 253 253 253 231 231 231 246 246 246
42405 -253 253 253 253 253 253 253 253 253 253 253 253
42406 -253 253 253 253 253 253 253 253 253 253 253 253
42407 -253 253 253 253 253 253 253 253 253 253 253 253
42408 -253 253 253 253 253 253 253 253 253 253 253 253
42409 -253 253 253 253 253 253 226 226 226 10 10 10
42410 - 2 2 6 6 6 6 30 30 30 2 2 6
42411 - 2 2 6 2 2 6 2 2 6 2 2 6
42412 - 2 2 6 66 66 66 58 58 58 22 22 22
42413 - 6 6 6 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 6 6 6 22 22 22
42420 - 58 58 58 62 62 62 2 2 6 2 2 6
42421 - 2 2 6 2 2 6 30 30 30 78 78 78
42422 -250 250 250 253 253 253 253 253 253 253 253 253
42423 -253 253 253 253 253 253 253 253 253 253 253 253
42424 -253 253 253 253 253 253 231 231 231 246 246 246
42425 -253 253 253 253 253 253 253 253 253 253 253 253
42426 -253 253 253 253 253 253 253 253 253 253 253 253
42427 -253 253 253 253 253 253 253 253 253 253 253 253
42428 -253 253 253 253 253 253 253 253 253 253 253 253
42429 -253 253 253 253 253 253 206 206 206 2 2 6
42430 - 22 22 22 34 34 34 18 14 6 22 22 22
42431 - 26 26 26 18 18 18 6 6 6 2 2 6
42432 - 2 2 6 82 82 82 54 54 54 18 18 18
42433 - 6 6 6 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 0 0 0 0
42439 - 0 0 0 0 0 0 6 6 6 26 26 26
42440 - 62 62 62 106 106 106 74 54 14 185 133 11
42441 -210 162 10 121 92 8 6 6 6 62 62 62
42442 -238 238 238 253 253 253 253 253 253 253 253 253
42443 -253 253 253 253 253 253 253 253 253 253 253 253
42444 -253 253 253 253 253 253 231 231 231 246 246 246
42445 -253 253 253 253 253 253 253 253 253 253 253 253
42446 -253 253 253 253 253 253 253 253 253 253 253 253
42447 -253 253 253 253 253 253 253 253 253 253 253 253
42448 -253 253 253 253 253 253 253 253 253 253 253 253
42449 -253 253 253 253 253 253 158 158 158 18 18 18
42450 - 14 14 14 2 2 6 2 2 6 2 2 6
42451 - 6 6 6 18 18 18 66 66 66 38 38 38
42452 - 6 6 6 94 94 94 50 50 50 18 18 18
42453 - 6 6 6 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 0 6 6 6
42459 - 10 10 10 10 10 10 18 18 18 38 38 38
42460 - 78 78 78 142 134 106 216 158 10 242 186 14
42461 -246 190 14 246 190 14 156 118 10 10 10 10
42462 - 90 90 90 238 238 238 253 253 253 253 253 253
42463 -253 253 253 253 253 253 253 253 253 253 253 253
42464 -253 253 253 253 253 253 231 231 231 250 250 250
42465 -253 253 253 253 253 253 253 253 253 253 253 253
42466 -253 253 253 253 253 253 253 253 253 253 253 253
42467 -253 253 253 253 253 253 253 253 253 253 253 253
42468 -253 253 253 253 253 253 253 253 253 246 230 190
42469 -238 204 91 238 204 91 181 142 44 37 26 9
42470 - 2 2 6 2 2 6 2 2 6 2 2 6
42471 - 2 2 6 2 2 6 38 38 38 46 46 46
42472 - 26 26 26 106 106 106 54 54 54 18 18 18
42473 - 6 6 6 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 6 6 6 14 14 14 22 22 22
42479 - 30 30 30 38 38 38 50 50 50 70 70 70
42480 -106 106 106 190 142 34 226 170 11 242 186 14
42481 -246 190 14 246 190 14 246 190 14 154 114 10
42482 - 6 6 6 74 74 74 226 226 226 253 253 253
42483 -253 253 253 253 253 253 253 253 253 253 253 253
42484 -253 253 253 253 253 253 231 231 231 250 250 250
42485 -253 253 253 253 253 253 253 253 253 253 253 253
42486 -253 253 253 253 253 253 253 253 253 253 253 253
42487 -253 253 253 253 253 253 253 253 253 253 253 253
42488 -253 253 253 253 253 253 253 253 253 228 184 62
42489 -241 196 14 241 208 19 232 195 16 38 30 10
42490 - 2 2 6 2 2 6 2 2 6 2 2 6
42491 - 2 2 6 6 6 6 30 30 30 26 26 26
42492 -203 166 17 154 142 90 66 66 66 26 26 26
42493 - 6 6 6 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 - 6 6 6 18 18 18 38 38 38 58 58 58
42499 - 78 78 78 86 86 86 101 101 101 123 123 123
42500 -175 146 61 210 150 10 234 174 13 246 186 14
42501 -246 190 14 246 190 14 246 190 14 238 190 10
42502 -102 78 10 2 2 6 46 46 46 198 198 198
42503 -253 253 253 253 253 253 253 253 253 253 253 253
42504 -253 253 253 253 253 253 234 234 234 242 242 242
42505 -253 253 253 253 253 253 253 253 253 253 253 253
42506 -253 253 253 253 253 253 253 253 253 253 253 253
42507 -253 253 253 253 253 253 253 253 253 253 253 253
42508 -253 253 253 253 253 253 253 253 253 224 178 62
42509 -242 186 14 241 196 14 210 166 10 22 18 6
42510 - 2 2 6 2 2 6 2 2 6 2 2 6
42511 - 2 2 6 2 2 6 6 6 6 121 92 8
42512 -238 202 15 232 195 16 82 82 82 34 34 34
42513 - 10 10 10 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 - 14 14 14 38 38 38 70 70 70 154 122 46
42519 -190 142 34 200 144 11 197 138 11 197 138 11
42520 -213 154 11 226 170 11 242 186 14 246 190 14
42521 -246 190 14 246 190 14 246 190 14 246 190 14
42522 -225 175 15 46 32 6 2 2 6 22 22 22
42523 -158 158 158 250 250 250 253 253 253 253 253 253
42524 -253 253 253 253 253 253 253 253 253 253 253 253
42525 -253 253 253 253 253 253 253 253 253 253 253 253
42526 -253 253 253 253 253 253 253 253 253 253 253 253
42527 -253 253 253 253 253 253 253 253 253 253 253 253
42528 -253 253 253 250 250 250 242 242 242 224 178 62
42529 -239 182 13 236 186 11 213 154 11 46 32 6
42530 - 2 2 6 2 2 6 2 2 6 2 2 6
42531 - 2 2 6 2 2 6 61 42 6 225 175 15
42532 -238 190 10 236 186 11 112 100 78 42 42 42
42533 - 14 14 14 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 6 6 6
42538 - 22 22 22 54 54 54 154 122 46 213 154 11
42539 -226 170 11 230 174 11 226 170 11 226 170 11
42540 -236 178 12 242 186 14 246 190 14 246 190 14
42541 -246 190 14 246 190 14 246 190 14 246 190 14
42542 -241 196 14 184 144 12 10 10 10 2 2 6
42543 - 6 6 6 116 116 116 242 242 242 253 253 253
42544 -253 253 253 253 253 253 253 253 253 253 253 253
42545 -253 253 253 253 253 253 253 253 253 253 253 253
42546 -253 253 253 253 253 253 253 253 253 253 253 253
42547 -253 253 253 253 253 253 253 253 253 253 253 253
42548 -253 253 253 231 231 231 198 198 198 214 170 54
42549 -236 178 12 236 178 12 210 150 10 137 92 6
42550 - 18 14 6 2 2 6 2 2 6 2 2 6
42551 - 6 6 6 70 47 6 200 144 11 236 178 12
42552 -239 182 13 239 182 13 124 112 88 58 58 58
42553 - 22 22 22 6 6 6 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 10 10 10
42558 - 30 30 30 70 70 70 180 133 36 226 170 11
42559 -239 182 13 242 186 14 242 186 14 246 186 14
42560 -246 190 14 246 190 14 246 190 14 246 190 14
42561 -246 190 14 246 190 14 246 190 14 246 190 14
42562 -246 190 14 232 195 16 98 70 6 2 2 6
42563 - 2 2 6 2 2 6 66 66 66 221 221 221
42564 -253 253 253 253 253 253 253 253 253 253 253 253
42565 -253 253 253 253 253 253 253 253 253 253 253 253
42566 -253 253 253 253 253 253 253 253 253 253 253 253
42567 -253 253 253 253 253 253 253 253 253 253 253 253
42568 -253 253 253 206 206 206 198 198 198 214 166 58
42569 -230 174 11 230 174 11 216 158 10 192 133 9
42570 -163 110 8 116 81 8 102 78 10 116 81 8
42571 -167 114 7 197 138 11 226 170 11 239 182 13
42572 -242 186 14 242 186 14 162 146 94 78 78 78
42573 - 34 34 34 14 14 14 6 6 6 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 6 6 6
42578 - 30 30 30 78 78 78 190 142 34 226 170 11
42579 -239 182 13 246 190 14 246 190 14 246 190 14
42580 -246 190 14 246 190 14 246 190 14 246 190 14
42581 -246 190 14 246 190 14 246 190 14 246 190 14
42582 -246 190 14 241 196 14 203 166 17 22 18 6
42583 - 2 2 6 2 2 6 2 2 6 38 38 38
42584 -218 218 218 253 253 253 253 253 253 253 253 253
42585 -253 253 253 253 253 253 253 253 253 253 253 253
42586 -253 253 253 253 253 253 253 253 253 253 253 253
42587 -253 253 253 253 253 253 253 253 253 253 253 253
42588 -250 250 250 206 206 206 198 198 198 202 162 69
42589 -226 170 11 236 178 12 224 166 10 210 150 10
42590 -200 144 11 197 138 11 192 133 9 197 138 11
42591 -210 150 10 226 170 11 242 186 14 246 190 14
42592 -246 190 14 246 186 14 225 175 15 124 112 88
42593 - 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
42598 - 30 30 30 78 78 78 174 135 50 224 166 10
42599 -239 182 13 246 190 14 246 190 14 246 190 14
42600 -246 190 14 246 190 14 246 190 14 246 190 14
42601 -246 190 14 246 190 14 246 190 14 246 190 14
42602 -246 190 14 246 190 14 241 196 14 139 102 15
42603 - 2 2 6 2 2 6 2 2 6 2 2 6
42604 - 78 78 78 250 250 250 253 253 253 253 253 253
42605 -253 253 253 253 253 253 253 253 253 253 253 253
42606 -253 253 253 253 253 253 253 253 253 253 253 253
42607 -253 253 253 253 253 253 253 253 253 253 253 253
42608 -250 250 250 214 214 214 198 198 198 190 150 46
42609 -219 162 10 236 178 12 234 174 13 224 166 10
42610 -216 158 10 213 154 11 213 154 11 216 158 10
42611 -226 170 11 239 182 13 246 190 14 246 190 14
42612 -246 190 14 246 190 14 242 186 14 206 162 42
42613 -101 101 101 58 58 58 30 30 30 14 14 14
42614 - 6 6 6 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 10 10 10
42618 - 30 30 30 74 74 74 174 135 50 216 158 10
42619 -236 178 12 246 190 14 246 190 14 246 190 14
42620 -246 190 14 246 190 14 246 190 14 246 190 14
42621 -246 190 14 246 190 14 246 190 14 246 190 14
42622 -246 190 14 246 190 14 241 196 14 226 184 13
42623 - 61 42 6 2 2 6 2 2 6 2 2 6
42624 - 22 22 22 238 238 238 253 253 253 253 253 253
42625 -253 253 253 253 253 253 253 253 253 253 253 253
42626 -253 253 253 253 253 253 253 253 253 253 253 253
42627 -253 253 253 253 253 253 253 253 253 253 253 253
42628 -253 253 253 226 226 226 187 187 187 180 133 36
42629 -216 158 10 236 178 12 239 182 13 236 178 12
42630 -230 174 11 226 170 11 226 170 11 230 174 11
42631 -236 178 12 242 186 14 246 190 14 246 190 14
42632 -246 190 14 246 190 14 246 186 14 239 182 13
42633 -206 162 42 106 106 106 66 66 66 34 34 34
42634 - 14 14 14 6 6 6 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 6 6 6
42638 - 26 26 26 70 70 70 163 133 67 213 154 11
42639 -236 178 12 246 190 14 246 190 14 246 190 14
42640 -246 190 14 246 190 14 246 190 14 246 190 14
42641 -246 190 14 246 190 14 246 190 14 246 190 14
42642 -246 190 14 246 190 14 246 190 14 241 196 14
42643 -190 146 13 18 14 6 2 2 6 2 2 6
42644 - 46 46 46 246 246 246 253 253 253 253 253 253
42645 -253 253 253 253 253 253 253 253 253 253 253 253
42646 -253 253 253 253 253 253 253 253 253 253 253 253
42647 -253 253 253 253 253 253 253 253 253 253 253 253
42648 -253 253 253 221 221 221 86 86 86 156 107 11
42649 -216 158 10 236 178 12 242 186 14 246 186 14
42650 -242 186 14 239 182 13 239 182 13 242 186 14
42651 -242 186 14 246 186 14 246 190 14 246 190 14
42652 -246 190 14 246 190 14 246 190 14 246 190 14
42653 -242 186 14 225 175 15 142 122 72 66 66 66
42654 - 30 30 30 10 10 10 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 6 6 6
42658 - 26 26 26 70 70 70 163 133 67 210 150 10
42659 -236 178 12 246 190 14 246 190 14 246 190 14
42660 -246 190 14 246 190 14 246 190 14 246 190 14
42661 -246 190 14 246 190 14 246 190 14 246 190 14
42662 -246 190 14 246 190 14 246 190 14 246 190 14
42663 -232 195 16 121 92 8 34 34 34 106 106 106
42664 -221 221 221 253 253 253 253 253 253 253 253 253
42665 -253 253 253 253 253 253 253 253 253 253 253 253
42666 -253 253 253 253 253 253 253 253 253 253 253 253
42667 -253 253 253 253 253 253 253 253 253 253 253 253
42668 -242 242 242 82 82 82 18 14 6 163 110 8
42669 -216 158 10 236 178 12 242 186 14 246 190 14
42670 -246 190 14 246 190 14 246 190 14 246 190 14
42671 -246 190 14 246 190 14 246 190 14 246 190 14
42672 -246 190 14 246 190 14 246 190 14 246 190 14
42673 -246 190 14 246 190 14 242 186 14 163 133 67
42674 - 46 46 46 18 18 18 6 6 6 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 10 10 10
42678 - 30 30 30 78 78 78 163 133 67 210 150 10
42679 -236 178 12 246 186 14 246 190 14 246 190 14
42680 -246 190 14 246 190 14 246 190 14 246 190 14
42681 -246 190 14 246 190 14 246 190 14 246 190 14
42682 -246 190 14 246 190 14 246 190 14 246 190 14
42683 -241 196 14 215 174 15 190 178 144 253 253 253
42684 -253 253 253 253 253 253 253 253 253 253 253 253
42685 -253 253 253 253 253 253 253 253 253 253 253 253
42686 -253 253 253 253 253 253 253 253 253 253 253 253
42687 -253 253 253 253 253 253 253 253 253 218 218 218
42688 - 58 58 58 2 2 6 22 18 6 167 114 7
42689 -216 158 10 236 178 12 246 186 14 246 190 14
42690 -246 190 14 246 190 14 246 190 14 246 190 14
42691 -246 190 14 246 190 14 246 190 14 246 190 14
42692 -246 190 14 246 190 14 246 190 14 246 190 14
42693 -246 190 14 246 186 14 242 186 14 190 150 46
42694 - 54 54 54 22 22 22 6 6 6 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 14 14 14
42698 - 38 38 38 86 86 86 180 133 36 213 154 11
42699 -236 178 12 246 186 14 246 190 14 246 190 14
42700 -246 190 14 246 190 14 246 190 14 246 190 14
42701 -246 190 14 246 190 14 246 190 14 246 190 14
42702 -246 190 14 246 190 14 246 190 14 246 190 14
42703 -246 190 14 232 195 16 190 146 13 214 214 214
42704 -253 253 253 253 253 253 253 253 253 253 253 253
42705 -253 253 253 253 253 253 253 253 253 253 253 253
42706 -253 253 253 253 253 253 253 253 253 253 253 253
42707 -253 253 253 250 250 250 170 170 170 26 26 26
42708 - 2 2 6 2 2 6 37 26 9 163 110 8
42709 -219 162 10 239 182 13 246 186 14 246 190 14
42710 -246 190 14 246 190 14 246 190 14 246 190 14
42711 -246 190 14 246 190 14 246 190 14 246 190 14
42712 -246 190 14 246 190 14 246 190 14 246 190 14
42713 -246 186 14 236 178 12 224 166 10 142 122 72
42714 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
42718 - 50 50 50 109 106 95 192 133 9 224 166 10
42719 -242 186 14 246 190 14 246 190 14 246 190 14
42720 -246 190 14 246 190 14 246 190 14 246 190 14
42721 -246 190 14 246 190 14 246 190 14 246 190 14
42722 -246 190 14 246 190 14 246 190 14 246 190 14
42723 -242 186 14 226 184 13 210 162 10 142 110 46
42724 -226 226 226 253 253 253 253 253 253 253 253 253
42725 -253 253 253 253 253 253 253 253 253 253 253 253
42726 -253 253 253 253 253 253 253 253 253 253 253 253
42727 -198 198 198 66 66 66 2 2 6 2 2 6
42728 - 2 2 6 2 2 6 50 34 6 156 107 11
42729 -219 162 10 239 182 13 246 186 14 246 190 14
42730 -246 190 14 246 190 14 246 190 14 246 190 14
42731 -246 190 14 246 190 14 246 190 14 246 190 14
42732 -246 190 14 246 190 14 246 190 14 242 186 14
42733 -234 174 13 213 154 11 154 122 46 66 66 66
42734 - 30 30 30 10 10 10 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 6 6 6 22 22 22
42738 - 58 58 58 154 121 60 206 145 10 234 174 13
42739 -242 186 14 246 186 14 246 190 14 246 190 14
42740 -246 190 14 246 190 14 246 190 14 246 190 14
42741 -246 190 14 246 190 14 246 190 14 246 190 14
42742 -246 190 14 246 190 14 246 190 14 246 190 14
42743 -246 186 14 236 178 12 210 162 10 163 110 8
42744 - 61 42 6 138 138 138 218 218 218 250 250 250
42745 -253 253 253 253 253 253 253 253 253 250 250 250
42746 -242 242 242 210 210 210 144 144 144 66 66 66
42747 - 6 6 6 2 2 6 2 2 6 2 2 6
42748 - 2 2 6 2 2 6 61 42 6 163 110 8
42749 -216 158 10 236 178 12 246 190 14 246 190 14
42750 -246 190 14 246 190 14 246 190 14 246 190 14
42751 -246 190 14 246 190 14 246 190 14 246 190 14
42752 -246 190 14 239 182 13 230 174 11 216 158 10
42753 -190 142 34 124 112 88 70 70 70 38 38 38
42754 - 18 18 18 6 6 6 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 6 6 6 22 22 22
42758 - 62 62 62 168 124 44 206 145 10 224 166 10
42759 -236 178 12 239 182 13 242 186 14 242 186 14
42760 -246 186 14 246 190 14 246 190 14 246 190 14
42761 -246 190 14 246 190 14 246 190 14 246 190 14
42762 -246 190 14 246 190 14 246 190 14 246 190 14
42763 -246 190 14 236 178 12 216 158 10 175 118 6
42764 - 80 54 7 2 2 6 6 6 6 30 30 30
42765 - 54 54 54 62 62 62 50 50 50 38 38 38
42766 - 14 14 14 2 2 6 2 2 6 2 2 6
42767 - 2 2 6 2 2 6 2 2 6 2 2 6
42768 - 2 2 6 6 6 6 80 54 7 167 114 7
42769 -213 154 11 236 178 12 246 190 14 246 190 14
42770 -246 190 14 246 190 14 246 190 14 246 190 14
42771 -246 190 14 242 186 14 239 182 13 239 182 13
42772 -230 174 11 210 150 10 174 135 50 124 112 88
42773 - 82 82 82 54 54 54 34 34 34 18 18 18
42774 - 6 6 6 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 6 6 6 18 18 18
42778 - 50 50 50 158 118 36 192 133 9 200 144 11
42779 -216 158 10 219 162 10 224 166 10 226 170 11
42780 -230 174 11 236 178 12 239 182 13 239 182 13
42781 -242 186 14 246 186 14 246 190 14 246 190 14
42782 -246 190 14 246 190 14 246 190 14 246 190 14
42783 -246 186 14 230 174 11 210 150 10 163 110 8
42784 -104 69 6 10 10 10 2 2 6 2 2 6
42785 - 2 2 6 2 2 6 2 2 6 2 2 6
42786 - 2 2 6 2 2 6 2 2 6 2 2 6
42787 - 2 2 6 2 2 6 2 2 6 2 2 6
42788 - 2 2 6 6 6 6 91 60 6 167 114 7
42789 -206 145 10 230 174 11 242 186 14 246 190 14
42790 -246 190 14 246 190 14 246 186 14 242 186 14
42791 -239 182 13 230 174 11 224 166 10 213 154 11
42792 -180 133 36 124 112 88 86 86 86 58 58 58
42793 - 38 38 38 22 22 22 10 10 10 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 14 14 14
42798 - 34 34 34 70 70 70 138 110 50 158 118 36
42799 -167 114 7 180 123 7 192 133 9 197 138 11
42800 -200 144 11 206 145 10 213 154 11 219 162 10
42801 -224 166 10 230 174 11 239 182 13 242 186 14
42802 -246 186 14 246 186 14 246 186 14 246 186 14
42803 -239 182 13 216 158 10 185 133 11 152 99 6
42804 -104 69 6 18 14 6 2 2 6 2 2 6
42805 - 2 2 6 2 2 6 2 2 6 2 2 6
42806 - 2 2 6 2 2 6 2 2 6 2 2 6
42807 - 2 2 6 2 2 6 2 2 6 2 2 6
42808 - 2 2 6 6 6 6 80 54 7 152 99 6
42809 -192 133 9 219 162 10 236 178 12 239 182 13
42810 -246 186 14 242 186 14 239 182 13 236 178 12
42811 -224 166 10 206 145 10 192 133 9 154 121 60
42812 - 94 94 94 62 62 62 42 42 42 22 22 22
42813 - 14 14 14 6 6 6 0 0 0 0 0 0
42814 - 0 0 0 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 6 6 6
42818 - 18 18 18 34 34 34 58 58 58 78 78 78
42819 -101 98 89 124 112 88 142 110 46 156 107 11
42820 -163 110 8 167 114 7 175 118 6 180 123 7
42821 -185 133 11 197 138 11 210 150 10 219 162 10
42822 -226 170 11 236 178 12 236 178 12 234 174 13
42823 -219 162 10 197 138 11 163 110 8 130 83 6
42824 - 91 60 6 10 10 10 2 2 6 2 2 6
42825 - 18 18 18 38 38 38 38 38 38 38 38 38
42826 - 38 38 38 38 38 38 38 38 38 38 38 38
42827 - 38 38 38 38 38 38 26 26 26 2 2 6
42828 - 2 2 6 6 6 6 70 47 6 137 92 6
42829 -175 118 6 200 144 11 219 162 10 230 174 11
42830 -234 174 13 230 174 11 219 162 10 210 150 10
42831 -192 133 9 163 110 8 124 112 88 82 82 82
42832 - 50 50 50 30 30 30 14 14 14 6 6 6
42833 - 0 0 0 0 0 0 0 0 0 0 0 0
42834 - 0 0 0 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 - 6 6 6 14 14 14 22 22 22 34 34 34
42839 - 42 42 42 58 58 58 74 74 74 86 86 86
42840 -101 98 89 122 102 70 130 98 46 121 87 25
42841 -137 92 6 152 99 6 163 110 8 180 123 7
42842 -185 133 11 197 138 11 206 145 10 200 144 11
42843 -180 123 7 156 107 11 130 83 6 104 69 6
42844 - 50 34 6 54 54 54 110 110 110 101 98 89
42845 - 86 86 86 82 82 82 78 78 78 78 78 78
42846 - 78 78 78 78 78 78 78 78 78 78 78 78
42847 - 78 78 78 82 82 82 86 86 86 94 94 94
42848 -106 106 106 101 101 101 86 66 34 124 80 6
42849 -156 107 11 180 123 7 192 133 9 200 144 11
42850 -206 145 10 200 144 11 192 133 9 175 118 6
42851 -139 102 15 109 106 95 70 70 70 42 42 42
42852 - 22 22 22 10 10 10 0 0 0 0 0 0
42853 - 0 0 0 0 0 0 0 0 0 0 0 0
42854 - 0 0 0 0 0 0 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 6 6 6 10 10 10
42859 - 14 14 14 22 22 22 30 30 30 38 38 38
42860 - 50 50 50 62 62 62 74 74 74 90 90 90
42861 -101 98 89 112 100 78 121 87 25 124 80 6
42862 -137 92 6 152 99 6 152 99 6 152 99 6
42863 -138 86 6 124 80 6 98 70 6 86 66 30
42864 -101 98 89 82 82 82 58 58 58 46 46 46
42865 - 38 38 38 34 34 34 34 34 34 34 34 34
42866 - 34 34 34 34 34 34 34 34 34 34 34 34
42867 - 34 34 34 34 34 34 38 38 38 42 42 42
42868 - 54 54 54 82 82 82 94 86 76 91 60 6
42869 -134 86 6 156 107 11 167 114 7 175 118 6
42870 -175 118 6 167 114 7 152 99 6 121 87 25
42871 -101 98 89 62 62 62 34 34 34 18 18 18
42872 - 6 6 6 0 0 0 0 0 0 0 0 0
42873 - 0 0 0 0 0 0 0 0 0 0 0 0
42874 - 0 0 0 0 0 0 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 6 6 6 6 6 6 10 10 10
42880 - 18 18 18 22 22 22 30 30 30 42 42 42
42881 - 50 50 50 66 66 66 86 86 86 101 98 89
42882 -106 86 58 98 70 6 104 69 6 104 69 6
42883 -104 69 6 91 60 6 82 62 34 90 90 90
42884 - 62 62 62 38 38 38 22 22 22 14 14 14
42885 - 10 10 10 10 10 10 10 10 10 10 10 10
42886 - 10 10 10 10 10 10 6 6 6 10 10 10
42887 - 10 10 10 10 10 10 10 10 10 14 14 14
42888 - 22 22 22 42 42 42 70 70 70 89 81 66
42889 - 80 54 7 104 69 6 124 80 6 137 92 6
42890 -134 86 6 116 81 8 100 82 52 86 86 86
42891 - 58 58 58 30 30 30 14 14 14 6 6 6
42892 - 0 0 0 0 0 0 0 0 0 0 0 0
42893 - 0 0 0 0 0 0 0 0 0 0 0 0
42894 - 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
42901 - 18 18 18 26 26 26 38 38 38 54 54 54
42902 - 70 70 70 86 86 86 94 86 76 89 81 66
42903 - 89 81 66 86 86 86 74 74 74 50 50 50
42904 - 30 30 30 14 14 14 6 6 6 0 0 0
42905 - 0 0 0 0 0 0 0 0 0 0 0 0
42906 - 0 0 0 0 0 0 0 0 0 0 0 0
42907 - 0 0 0 0 0 0 0 0 0 0 0 0
42908 - 6 6 6 18 18 18 34 34 34 58 58 58
42909 - 82 82 82 89 81 66 89 81 66 89 81 66
42910 - 94 86 66 94 86 76 74 74 74 50 50 50
42911 - 26 26 26 14 14 14 6 6 6 0 0 0
42912 - 0 0 0 0 0 0 0 0 0 0 0 0
42913 - 0 0 0 0 0 0 0 0 0 0 0 0
42914 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 6 6 6 14 14 14 18 18 18
42922 - 30 30 30 38 38 38 46 46 46 54 54 54
42923 - 50 50 50 42 42 42 30 30 30 18 18 18
42924 - 10 10 10 0 0 0 0 0 0 0 0 0
42925 - 0 0 0 0 0 0 0 0 0 0 0 0
42926 - 0 0 0 0 0 0 0 0 0 0 0 0
42927 - 0 0 0 0 0 0 0 0 0 0 0 0
42928 - 0 0 0 6 6 6 14 14 14 26 26 26
42929 - 38 38 38 50 50 50 58 58 58 58 58 58
42930 - 54 54 54 42 42 42 30 30 30 18 18 18
42931 - 10 10 10 0 0 0 0 0 0 0 0 0
42932 - 0 0 0 0 0 0 0 0 0 0 0 0
42933 - 0 0 0 0 0 0 0 0 0 0 0 0
42934 - 0 0 0 0 0 0 0 0 0 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 6 6 6
42942 - 6 6 6 10 10 10 14 14 14 18 18 18
42943 - 18 18 18 14 14 14 10 10 10 6 6 6
42944 - 0 0 0 0 0 0 0 0 0 0 0 0
42945 - 0 0 0 0 0 0 0 0 0 0 0 0
42946 - 0 0 0 0 0 0 0 0 0 0 0 0
42947 - 0 0 0 0 0 0 0 0 0 0 0 0
42948 - 0 0 0 0 0 0 0 0 0 6 6 6
42949 - 14 14 14 18 18 18 22 22 22 22 22 22
42950 - 18 18 18 14 14 14 10 10 10 6 6 6
42951 - 0 0 0 0 0 0 0 0 0 0 0 0
42952 - 0 0 0 0 0 0 0 0 0 0 0 0
42953 - 0 0 0 0 0 0 0 0 0 0 0 0
42954 - 0 0 0 0 0 0 0 0 0 0 0 0
42955 - 0 0 0 0 0 0 0 0 0 0 0 0
42956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42969 +4 4 4 4 4 4
42970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42983 +4 4 4 4 4 4
42984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42997 +4 4 4 4 4 4
42998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43011 +4 4 4 4 4 4
43012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43025 +4 4 4 4 4 4
43026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43039 +4 4 4 4 4 4
43040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43044 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
43045 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
43046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43049 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
43050 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43051 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43053 +4 4 4 4 4 4
43054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43058 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
43059 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43060 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43063 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
43064 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43065 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43066 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43067 +4 4 4 4 4 4
43068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43072 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43073 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43074 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43077 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
43078 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43079 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43080 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43081 +4 4 4 4 4 4
43082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43085 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43086 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43087 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43088 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
43089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43090 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43091 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43092 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43093 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43094 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43095 +4 4 4 4 4 4
43096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43099 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43100 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43101 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43102 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43103 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43104 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43105 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43106 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43107 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43108 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43109 +4 4 4 4 4 4
43110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43113 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43114 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43115 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43116 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43117 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43118 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43119 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43120 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43121 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43122 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43123 +4 4 4 4 4 4
43124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43126 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
43127 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43128 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43129 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43130 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43131 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43132 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43133 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43134 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43135 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43136 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43137 +4 4 4 4 4 4
43138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43140 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
43141 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43142 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43143 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43144 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43145 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43146 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43147 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43148 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43149 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43150 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43151 +4 4 4 4 4 4
43152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43154 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43155 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43156 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43157 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43158 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43159 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43160 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43161 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43162 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43163 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43164 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43165 +4 4 4 4 4 4
43166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43168 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43169 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43170 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43171 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43172 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43173 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43174 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43175 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43176 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43177 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43178 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43179 +4 4 4 4 4 4
43180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43181 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43182 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43183 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43184 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43185 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43186 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43187 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43188 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43189 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43190 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43191 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43192 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43193 +4 4 4 4 4 4
43194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43195 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43196 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43197 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43198 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43199 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43200 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43201 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43202 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43203 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43204 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43205 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43206 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43207 +0 0 0 4 4 4
43208 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43209 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43210 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43211 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43212 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43213 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43214 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43215 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43216 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43217 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43218 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43219 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43220 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43221 +2 0 0 0 0 0
43222 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43223 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43224 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43225 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43226 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43227 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43228 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43229 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43230 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43231 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43232 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43233 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43234 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43235 +37 38 37 0 0 0
43236 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43237 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43238 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43239 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43240 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43241 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43242 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43243 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43244 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43245 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43246 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43247 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43248 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43249 +85 115 134 4 0 0
43250 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43251 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43252 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43253 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43254 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43255 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43256 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43257 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43258 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43259 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43260 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43261 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43262 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43263 +60 73 81 4 0 0
43264 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43265 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43266 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43267 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43268 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43269 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43270 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43271 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43272 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43273 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43274 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43275 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43276 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43277 +16 19 21 4 0 0
43278 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43279 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43280 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43281 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43282 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43283 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43284 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43285 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43286 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43287 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43288 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43289 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43290 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
43291 +4 0 0 4 3 3
43292 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
43293 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
43294 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
43295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
43296 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
43297 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
43298 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
43299 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
43300 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
43301 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
43302 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
43303 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
43304 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
43305 +3 2 2 4 4 4
43306 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
43307 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
43308 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
43309 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43310 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
43311 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
43312 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
43313 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
43314 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
43315 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
43316 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
43317 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
43318 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
43319 +4 4 4 4 4 4
43320 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
43321 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
43322 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
43323 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
43324 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
43325 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
43326 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
43327 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
43328 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
43329 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
43330 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
43331 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
43332 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
43333 +4 4 4 4 4 4
43334 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
43335 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
43336 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
43337 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
43338 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
43339 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43340 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
43341 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
43342 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
43343 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
43344 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
43345 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
43346 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
43347 +5 5 5 5 5 5
43348 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
43349 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
43350 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
43351 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
43352 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
43353 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43354 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
43355 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
43356 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
43357 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
43358 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
43359 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
43360 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43361 +5 5 5 4 4 4
43362 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
43363 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
43364 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
43365 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
43366 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43367 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
43368 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
43369 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
43370 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
43371 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
43372 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
43373 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43375 +4 4 4 4 4 4
43376 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
43377 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
43378 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
43379 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
43380 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
43381 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43382 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43383 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43384 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43385 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43386 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43387 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
43388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43389 +4 4 4 4 4 4
43390 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43391 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43392 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43393 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43394 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43395 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43396 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43397 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43398 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43399 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43400 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
43401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43403 +4 4 4 4 4 4
43404 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43405 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43406 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43407 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43408 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43409 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43410 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43411 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43412 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43413 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43414 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
43415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43417 +4 4 4 4 4 4
43418 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43419 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43420 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43421 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43422 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43423 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43424 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43425 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43426 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43427 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43428 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43431 +4 4 4 4 4 4
43432 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43433 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43434 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43435 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43436 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43437 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43438 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43439 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43440 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43441 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43442 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
43443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43445 +4 4 4 4 4 4
43446 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43447 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43448 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43449 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43450 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43451 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43452 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43453 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43454 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43455 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43456 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
43457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43459 +4 4 4 4 4 4
43460 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43461 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43462 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43463 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43464 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43465 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43466 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43467 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43468 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43469 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43470 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43473 +4 4 4 4 4 4
43474 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43475 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43476 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43477 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43478 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43479 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43480 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43481 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43482 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43483 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43484 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43487 +4 4 4 4 4 4
43488 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43489 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43490 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43491 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43492 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43493 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43494 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43495 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43496 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43497 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43498 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43501 +4 4 4 4 4 4
43502 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43503 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43504 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43505 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43506 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43507 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43508 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43509 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43510 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43511 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43512 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43515 +4 4 4 4 4 4
43516 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43517 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43518 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43519 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43520 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43521 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43522 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43523 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43524 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43525 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43526 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43529 +4 4 4 4 4 4
43530 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43531 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43532 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43533 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43534 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43535 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43536 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43537 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43538 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43539 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43540 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43543 +4 4 4 4 4 4
43544 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43545 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43546 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43547 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43548 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43549 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43550 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43551 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43552 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43553 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43554 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43557 +4 4 4 4 4 4
43558 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43559 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43560 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43561 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43562 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43563 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43564 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43565 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43566 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43567 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43568 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43571 +4 4 4 4 4 4
43572 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43573 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43574 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43575 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43576 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43577 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43578 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43579 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43580 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43581 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43582 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43585 +4 4 4 4 4 4
43586 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43587 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43588 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43589 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43590 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43591 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43592 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43593 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43594 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43595 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43596 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43599 +4 4 4 4 4 4
43600 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43601 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43602 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43603 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43604 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43605 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43606 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43607 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43608 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43609 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43610 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43613 +4 4 4 4 4 4
43614 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43615 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43616 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43617 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43618 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43619 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43620 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43621 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43622 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43623 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43624 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43627 +4 4 4 4 4 4
43628 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43629 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43630 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43631 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43632 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43633 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43634 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43635 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43636 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43637 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43638 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43641 +4 4 4 4 4 4
43642 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43643 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43644 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43645 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43646 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43647 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43648 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43649 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43650 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43651 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43652 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43655 +4 4 4 4 4 4
43656 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43657 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43658 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43659 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43660 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43661 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43662 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43663 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43664 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43665 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43666 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43669 +4 4 4 4 4 4
43670 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43671 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43672 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43673 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43674 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43675 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43676 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43677 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43678 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43679 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43680 +0 0 0 3 3 3 5 5 5 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
43684 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43685 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43686 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43687 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43688 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43689 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43690 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43691 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43692 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43693 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43694 +0 0 0 3 3 3 5 5 5 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
43698 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43699 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43700 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43701 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43702 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43703 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43704 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43705 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43706 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43707 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43708 +0 0 0 3 3 3 5 5 5 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
43712 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43713 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43714 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43715 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43716 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43717 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43718 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43719 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43720 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43721 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43722 +0 0 0 3 3 3 5 5 5 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
43726 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43727 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43728 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43729 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43730 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43731 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43732 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43733 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43734 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43735 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43736 +0 0 0 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
43740 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43741 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43742 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43743 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43744 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43745 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43746 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43747 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43748 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43749 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43750 +4 3 3 5 5 5 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
43754 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43755 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43756 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43757 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43758 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43759 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43760 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43761 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43762 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43763 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43764 +5 5 5 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 4 4 4 4 4 4 4 4 4
43767 +4 4 4 4 4 4
43768 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43769 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43770 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43771 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43772 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43773 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43774 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43775 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43776 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43777 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
43781 +4 4 4 4 4 4
43782 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43783 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43784 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43785 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43786 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43787 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43788 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43789 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43790 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43791 +13 16 17 4 0 0 4 0 0 4 3 3 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43795 +4 4 4 4 4 4
43796 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43797 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43798 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43799 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43800 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43801 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43802 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43803 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43804 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43805 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43809 +4 4 4 4 4 4
43810 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43811 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43812 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43813 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43814 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43815 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43816 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43817 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43818 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43819 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43823 +4 4 4 4 4 4
43824 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43825 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43826 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43827 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43828 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43829 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43830 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43831 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43832 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4
43835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43837 +4 4 4 4 4 4
43838 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43839 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43840 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43841 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43842 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43843 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43844 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43845 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43846 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4
43849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43851 +4 4 4 4 4 4
43852 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43853 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43854 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43855 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43856 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43857 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43858 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43859 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43860 +4 0 0 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 4 4 4 4 4 4 4 4 4
43863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43865 +4 4 4 4 4 4
43866 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43867 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43868 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43869 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43870 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43871 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43872 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43873 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43879 +4 4 4 4 4 4
43880 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43881 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43882 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43883 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43884 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43885 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43886 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43887 +6 6 6 4 0 0 4 0 0 4 3 3 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43893 +4 4 4 4 4 4
43894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43895 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43896 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43897 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43898 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43899 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43900 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43901 +4 0 0 4 3 3 6 6 6 4 4 4 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 4 4 4 4 4 4
43904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43907 +4 4 4 4 4 4
43908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43909 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43910 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43911 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43912 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43913 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43914 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43915 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43921 +4 4 4 4 4 4
43922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43923 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43924 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43925 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43926 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43927 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43928 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43929 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43935 +4 4 4 4 4 4
43936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43938 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43939 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43940 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43941 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43942 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
43943 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43949 +4 4 4 4 4 4
43950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43953 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43954 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
43955 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
43956 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
43957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43963 +4 4 4 4 4 4
43964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43967 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43968 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43969 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
43970 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
43971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43977 +4 4 4 4 4 4
43978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43981 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43982 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43983 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43984 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
43985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43991 +4 4 4 4 4 4
43992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43995 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
43996 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
43997 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
43998 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
43999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44005 +4 4 4 4 4 4
44006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44010 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44011 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44012 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44019 +4 4 4 4 4 4
44020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44024 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44025 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44026 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44033 +4 4 4 4 4 4
44034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44038 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44039 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44040 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44047 +4 4 4 4 4 4
44048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44052 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44053 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
44054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44061 +4 4 4 4 4 4
44062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44066 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44067 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
44068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44075 +4 4 4 4 4 4
44076 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44077 index 86d449e..af6a7f7 100644
44078 --- a/drivers/video/udlfb.c
44079 +++ b/drivers/video/udlfb.c
44080 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44081 dlfb_urb_completion(urb);
44082
44083 error:
44084 - atomic_add(bytes_sent, &dev->bytes_sent);
44085 - atomic_add(bytes_identical, &dev->bytes_identical);
44086 - atomic_add(width*height*2, &dev->bytes_rendered);
44087 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44088 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44089 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44090 end_cycles = get_cycles();
44091 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44092 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44093 >> 10)), /* Kcycles */
44094 &dev->cpu_kcycles_used);
44095
44096 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44097 dlfb_urb_completion(urb);
44098
44099 error:
44100 - atomic_add(bytes_sent, &dev->bytes_sent);
44101 - atomic_add(bytes_identical, &dev->bytes_identical);
44102 - atomic_add(bytes_rendered, &dev->bytes_rendered);
44103 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44104 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44105 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44106 end_cycles = get_cycles();
44107 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44108 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44109 >> 10)), /* Kcycles */
44110 &dev->cpu_kcycles_used);
44111 }
44112 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44113 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44114 struct dlfb_data *dev = fb_info->par;
44115 return snprintf(buf, PAGE_SIZE, "%u\n",
44116 - atomic_read(&dev->bytes_rendered));
44117 + atomic_read_unchecked(&dev->bytes_rendered));
44118 }
44119
44120 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44121 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44122 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44123 struct dlfb_data *dev = fb_info->par;
44124 return snprintf(buf, PAGE_SIZE, "%u\n",
44125 - atomic_read(&dev->bytes_identical));
44126 + atomic_read_unchecked(&dev->bytes_identical));
44127 }
44128
44129 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44130 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44131 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44132 struct dlfb_data *dev = fb_info->par;
44133 return snprintf(buf, PAGE_SIZE, "%u\n",
44134 - atomic_read(&dev->bytes_sent));
44135 + atomic_read_unchecked(&dev->bytes_sent));
44136 }
44137
44138 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44139 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44140 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44141 struct dlfb_data *dev = fb_info->par;
44142 return snprintf(buf, PAGE_SIZE, "%u\n",
44143 - atomic_read(&dev->cpu_kcycles_used));
44144 + atomic_read_unchecked(&dev->cpu_kcycles_used));
44145 }
44146
44147 static ssize_t edid_show(
44148 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44149 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44150 struct dlfb_data *dev = fb_info->par;
44151
44152 - atomic_set(&dev->bytes_rendered, 0);
44153 - atomic_set(&dev->bytes_identical, 0);
44154 - atomic_set(&dev->bytes_sent, 0);
44155 - atomic_set(&dev->cpu_kcycles_used, 0);
44156 + atomic_set_unchecked(&dev->bytes_rendered, 0);
44157 + atomic_set_unchecked(&dev->bytes_identical, 0);
44158 + atomic_set_unchecked(&dev->bytes_sent, 0);
44159 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44160
44161 return count;
44162 }
44163 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44164 index 2f8f82d..191de37 100644
44165 --- a/drivers/video/uvesafb.c
44166 +++ b/drivers/video/uvesafb.c
44167 @@ -19,6 +19,7 @@
44168 #include <linux/io.h>
44169 #include <linux/mutex.h>
44170 #include <linux/slab.h>
44171 +#include <linux/moduleloader.h>
44172 #include <video/edid.h>
44173 #include <video/uvesafb.h>
44174 #ifdef CONFIG_X86
44175 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44176 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44177 par->pmi_setpal = par->ypan = 0;
44178 } else {
44179 +
44180 +#ifdef CONFIG_PAX_KERNEXEC
44181 +#ifdef CONFIG_MODULES
44182 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44183 +#endif
44184 + if (!par->pmi_code) {
44185 + par->pmi_setpal = par->ypan = 0;
44186 + return 0;
44187 + }
44188 +#endif
44189 +
44190 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44191 + task->t.regs.edi);
44192 +
44193 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44194 + pax_open_kernel();
44195 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44196 + pax_close_kernel();
44197 +
44198 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44199 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44200 +#else
44201 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44202 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44203 +#endif
44204 +
44205 printk(KERN_INFO "uvesafb: protected mode interface info at "
44206 "%04x:%04x\n",
44207 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44208 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
44209 par->ypan = ypan;
44210
44211 if (par->pmi_setpal || par->ypan) {
44212 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44213 if (__supported_pte_mask & _PAGE_NX) {
44214 par->pmi_setpal = par->ypan = 0;
44215 printk(KERN_WARNING "uvesafb: NX protection is actively."
44216 "We have better not to use the PMI.\n");
44217 - } else {
44218 + } else
44219 +#endif
44220 uvesafb_vbe_getpmi(task, par);
44221 - }
44222 }
44223 #else
44224 /* The protected mode interface is not available on non-x86. */
44225 @@ -1838,6 +1862,11 @@ out:
44226 if (par->vbe_modes)
44227 kfree(par->vbe_modes);
44228
44229 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44230 + if (par->pmi_code)
44231 + module_free_exec(NULL, par->pmi_code);
44232 +#endif
44233 +
44234 framebuffer_release(info);
44235 return err;
44236 }
44237 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
44238 kfree(par->vbe_state_orig);
44239 if (par->vbe_state_saved)
44240 kfree(par->vbe_state_saved);
44241 +
44242 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44243 + if (par->pmi_code)
44244 + module_free_exec(NULL, par->pmi_code);
44245 +#endif
44246 +
44247 }
44248
44249 framebuffer_release(info);
44250 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44251 index 501b340..86bd4cf 100644
44252 --- a/drivers/video/vesafb.c
44253 +++ b/drivers/video/vesafb.c
44254 @@ -9,6 +9,7 @@
44255 */
44256
44257 #include <linux/module.h>
44258 +#include <linux/moduleloader.h>
44259 #include <linux/kernel.h>
44260 #include <linux/errno.h>
44261 #include <linux/string.h>
44262 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44263 static int vram_total __initdata; /* Set total amount of memory */
44264 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44265 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44266 -static void (*pmi_start)(void) __read_mostly;
44267 -static void (*pmi_pal) (void) __read_mostly;
44268 +static void (*pmi_start)(void) __read_only;
44269 +static void (*pmi_pal) (void) __read_only;
44270 static int depth __read_mostly;
44271 static int vga_compat __read_mostly;
44272 /* --------------------------------------------------------------------- */
44273 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44274 unsigned int size_vmode;
44275 unsigned int size_remap;
44276 unsigned int size_total;
44277 + void *pmi_code = NULL;
44278
44279 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44280 return -ENODEV;
44281 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44282 size_remap = size_total;
44283 vesafb_fix.smem_len = size_remap;
44284
44285 -#ifndef __i386__
44286 - screen_info.vesapm_seg = 0;
44287 -#endif
44288 -
44289 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44290 printk(KERN_WARNING
44291 "vesafb: cannot reserve video memory at 0x%lx\n",
44292 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
44293 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
44294 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
44295
44296 +#ifdef __i386__
44297 +
44298 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44299 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
44300 + if (!pmi_code)
44301 +#elif !defined(CONFIG_PAX_KERNEXEC)
44302 + if (0)
44303 +#endif
44304 +
44305 +#endif
44306 + screen_info.vesapm_seg = 0;
44307 +
44308 if (screen_info.vesapm_seg) {
44309 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
44310 - screen_info.vesapm_seg,screen_info.vesapm_off);
44311 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
44312 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
44313 }
44314
44315 if (screen_info.vesapm_seg < 0xc000)
44316 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
44317
44318 if (ypan || pmi_setpal) {
44319 unsigned short *pmi_base;
44320 +
44321 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
44322 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
44323 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
44324 +
44325 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44326 + pax_open_kernel();
44327 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
44328 +#else
44329 + pmi_code = pmi_base;
44330 +#endif
44331 +
44332 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
44333 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
44334 +
44335 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44336 + pmi_start = ktva_ktla(pmi_start);
44337 + pmi_pal = ktva_ktla(pmi_pal);
44338 + pax_close_kernel();
44339 +#endif
44340 +
44341 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
44342 if (pmi_base[3]) {
44343 printk(KERN_INFO "vesafb: pmi: ports = ");
44344 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
44345 info->node, info->fix.id);
44346 return 0;
44347 err:
44348 +
44349 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44350 + module_free_exec(NULL, pmi_code);
44351 +#endif
44352 +
44353 if (info->screen_base)
44354 iounmap(info->screen_base);
44355 framebuffer_release(info);
44356 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
44357 index 88714ae..16c2e11 100644
44358 --- a/drivers/video/via/via_clock.h
44359 +++ b/drivers/video/via/via_clock.h
44360 @@ -56,7 +56,7 @@ struct via_clock {
44361
44362 void (*set_engine_pll_state)(u8 state);
44363 void (*set_engine_pll)(struct via_pll_config config);
44364 -};
44365 +} __no_const;
44366
44367
44368 static inline u32 get_pll_internal_frequency(u32 ref_freq,
44369 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
44370 index 6b1b7e1..b2fa4d5 100644
44371 --- a/drivers/virtio/virtio_mmio.c
44372 +++ b/drivers/virtio/virtio_mmio.c
44373 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
44374
44375 resources[0].end = memparse(device, &str) - 1;
44376
44377 - processed = sscanf(str, "@%lli:%u%n:%d%n",
44378 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
44379 &base, &resources[1].start, &consumed,
44380 &vm_cmdline_id, &consumed);
44381
44382 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
44383 index fef20db..d28b1ab 100644
44384 --- a/drivers/xen/xenfs/xenstored.c
44385 +++ b/drivers/xen/xenfs/xenstored.c
44386 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44387 static int xsd_kva_open(struct inode *inode, struct file *file)
44388 {
44389 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44390 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44391 + NULL);
44392 +#else
44393 xen_store_interface);
44394 +#endif
44395 +
44396 if (!file->private_data)
44397 return -ENOMEM;
44398 return 0;
44399 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44400 index 890bed5..17ae73e 100644
44401 --- a/fs/9p/vfs_inode.c
44402 +++ b/fs/9p/vfs_inode.c
44403 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44404 void
44405 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44406 {
44407 - char *s = nd_get_link(nd);
44408 + const char *s = nd_get_link(nd);
44409
44410 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44411 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44412 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44413 index 0efd152..b5802ad 100644
44414 --- a/fs/Kconfig.binfmt
44415 +++ b/fs/Kconfig.binfmt
44416 @@ -89,7 +89,7 @@ config HAVE_AOUT
44417
44418 config BINFMT_AOUT
44419 tristate "Kernel support for a.out and ECOFF binaries"
44420 - depends on HAVE_AOUT
44421 + depends on HAVE_AOUT && BROKEN
44422 ---help---
44423 A.out (Assembler.OUTput) is a set of formats for libraries and
44424 executables used in the earliest versions of UNIX. Linux used
44425 diff --git a/fs/aio.c b/fs/aio.c
44426 index 71f613c..9d01f1f 100644
44427 --- a/fs/aio.c
44428 +++ b/fs/aio.c
44429 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44430 size += sizeof(struct io_event) * nr_events;
44431 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44432
44433 - if (nr_pages < 0)
44434 + if (nr_pages <= 0)
44435 return -EINVAL;
44436
44437 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44438 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44439 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44440 {
44441 ssize_t ret;
44442 + struct iovec iovstack;
44443
44444 #ifdef CONFIG_COMPAT
44445 if (compat)
44446 ret = compat_rw_copy_check_uvector(type,
44447 (struct compat_iovec __user *)kiocb->ki_buf,
44448 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44449 + kiocb->ki_nbytes, 1, &iovstack,
44450 &kiocb->ki_iovec);
44451 else
44452 #endif
44453 ret = rw_copy_check_uvector(type,
44454 (struct iovec __user *)kiocb->ki_buf,
44455 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44456 + kiocb->ki_nbytes, 1, &iovstack,
44457 &kiocb->ki_iovec);
44458 if (ret < 0)
44459 goto out;
44460 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44461 if (ret < 0)
44462 goto out;
44463
44464 + if (kiocb->ki_iovec == &iovstack) {
44465 + kiocb->ki_inline_vec = iovstack;
44466 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
44467 + }
44468 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44469 kiocb->ki_cur_seg = 0;
44470 /* ki_nbytes/left now reflect bytes instead of segs */
44471 diff --git a/fs/attr.c b/fs/attr.c
44472 index cce7df5..eaa2731 100644
44473 --- a/fs/attr.c
44474 +++ b/fs/attr.c
44475 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44476 unsigned long limit;
44477
44478 limit = rlimit(RLIMIT_FSIZE);
44479 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44480 if (limit != RLIM_INFINITY && offset > limit)
44481 goto out_sig;
44482 if (offset > inode->i_sb->s_maxbytes)
44483 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44484 index dce436e..55e670d 100644
44485 --- a/fs/autofs4/waitq.c
44486 +++ b/fs/autofs4/waitq.c
44487 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44488 {
44489 unsigned long sigpipe, flags;
44490 mm_segment_t fs;
44491 - const char *data = (const char *)addr;
44492 + const char __user *data = (const char __force_user *)addr;
44493 ssize_t wr = 0;
44494
44495 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44496 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44497 return 1;
44498 }
44499
44500 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44501 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44502 +#endif
44503 +
44504 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44505 enum autofs_notify notify)
44506 {
44507 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44508
44509 /* If this is a direct mount request create a dummy name */
44510 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44511 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44512 + /* this name does get written to userland via autofs4_write() */
44513 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44514 +#else
44515 qstr.len = sprintf(name, "%p", dentry);
44516 +#endif
44517 else {
44518 qstr.len = autofs4_getpath(sbi, dentry, &name);
44519 if (!qstr.len) {
44520 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44521 index 2b3bda8..6a2d4be 100644
44522 --- a/fs/befs/linuxvfs.c
44523 +++ b/fs/befs/linuxvfs.c
44524 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44525 {
44526 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44527 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44528 - char *link = nd_get_link(nd);
44529 + const char *link = nd_get_link(nd);
44530 if (!IS_ERR(link))
44531 kfree(link);
44532 }
44533 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44534 index 0e7a6f8..332b1ca 100644
44535 --- a/fs/binfmt_aout.c
44536 +++ b/fs/binfmt_aout.c
44537 @@ -16,6 +16,7 @@
44538 #include <linux/string.h>
44539 #include <linux/fs.h>
44540 #include <linux/file.h>
44541 +#include <linux/security.h>
44542 #include <linux/stat.h>
44543 #include <linux/fcntl.h>
44544 #include <linux/ptrace.h>
44545 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44546 #endif
44547 # define START_STACK(u) ((void __user *)u.start_stack)
44548
44549 + memset(&dump, 0, sizeof(dump));
44550 +
44551 fs = get_fs();
44552 set_fs(KERNEL_DS);
44553 has_dumped = 1;
44554 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44555
44556 /* If the size of the dump file exceeds the rlimit, then see what would happen
44557 if we wrote the stack, but not the data area. */
44558 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44559 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44560 dump.u_dsize = 0;
44561
44562 /* Make sure we have enough room to write the stack and data areas. */
44563 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44564 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44565 dump.u_ssize = 0;
44566
44567 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44568 rlim = rlimit(RLIMIT_DATA);
44569 if (rlim >= RLIM_INFINITY)
44570 rlim = ~0;
44571 +
44572 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44573 if (ex.a_data + ex.a_bss > rlim)
44574 return -ENOMEM;
44575
44576 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44577
44578 install_exec_creds(bprm);
44579
44580 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44581 + current->mm->pax_flags = 0UL;
44582 +#endif
44583 +
44584 +#ifdef CONFIG_PAX_PAGEEXEC
44585 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44586 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44587 +
44588 +#ifdef CONFIG_PAX_EMUTRAMP
44589 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44590 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44591 +#endif
44592 +
44593 +#ifdef CONFIG_PAX_MPROTECT
44594 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44595 + current->mm->pax_flags |= MF_PAX_MPROTECT;
44596 +#endif
44597 +
44598 + }
44599 +#endif
44600 +
44601 if (N_MAGIC(ex) == OMAGIC) {
44602 unsigned long text_addr, map_size;
44603 loff_t pos;
44604 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44605 }
44606
44607 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44608 - PROT_READ | PROT_WRITE | PROT_EXEC,
44609 + PROT_READ | PROT_WRITE,
44610 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44611 fd_offset + ex.a_text);
44612 if (error != N_DATADDR(ex)) {
44613 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44614 index fbd9f60..0b845dd 100644
44615 --- a/fs/binfmt_elf.c
44616 +++ b/fs/binfmt_elf.c
44617 @@ -33,6 +33,7 @@
44618 #include <linux/elf.h>
44619 #include <linux/utsname.h>
44620 #include <linux/coredump.h>
44621 +#include <linux/xattr.h>
44622 #include <asm/uaccess.h>
44623 #include <asm/param.h>
44624 #include <asm/page.h>
44625 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44626 #define elf_core_dump NULL
44627 #endif
44628
44629 +#ifdef CONFIG_PAX_MPROTECT
44630 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44631 +#endif
44632 +
44633 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44634 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44635 #else
44636 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44637 .load_binary = load_elf_binary,
44638 .load_shlib = load_elf_library,
44639 .core_dump = elf_core_dump,
44640 +
44641 +#ifdef CONFIG_PAX_MPROTECT
44642 + .handle_mprotect= elf_handle_mprotect,
44643 +#endif
44644 +
44645 .min_coredump = ELF_EXEC_PAGESIZE,
44646 };
44647
44648 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44649
44650 static int set_brk(unsigned long start, unsigned long end)
44651 {
44652 + unsigned long e = end;
44653 +
44654 start = ELF_PAGEALIGN(start);
44655 end = ELF_PAGEALIGN(end);
44656 if (end > start) {
44657 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44658 if (BAD_ADDR(addr))
44659 return addr;
44660 }
44661 - current->mm->start_brk = current->mm->brk = end;
44662 + current->mm->start_brk = current->mm->brk = e;
44663 return 0;
44664 }
44665
44666 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44667 elf_addr_t __user *u_rand_bytes;
44668 const char *k_platform = ELF_PLATFORM;
44669 const char *k_base_platform = ELF_BASE_PLATFORM;
44670 - unsigned char k_rand_bytes[16];
44671 + u32 k_rand_bytes[4];
44672 int items;
44673 elf_addr_t *elf_info;
44674 int ei_index = 0;
44675 const struct cred *cred = current_cred();
44676 struct vm_area_struct *vma;
44677 + unsigned long saved_auxv[AT_VECTOR_SIZE];
44678
44679 /*
44680 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44681 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44682 * Generate 16 random bytes for userspace PRNG seeding.
44683 */
44684 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44685 - u_rand_bytes = (elf_addr_t __user *)
44686 - STACK_ALLOC(p, sizeof(k_rand_bytes));
44687 + srandom32(k_rand_bytes[0] ^ random32());
44688 + srandom32(k_rand_bytes[1] ^ random32());
44689 + srandom32(k_rand_bytes[2] ^ random32());
44690 + srandom32(k_rand_bytes[3] ^ random32());
44691 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
44692 + u_rand_bytes = (elf_addr_t __user *) p;
44693 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44694 return -EFAULT;
44695
44696 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44697 return -EFAULT;
44698 current->mm->env_end = p;
44699
44700 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44701 +
44702 /* Put the elf_info on the stack in the right place. */
44703 sp = (elf_addr_t __user *)envp + 1;
44704 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44705 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44706 return -EFAULT;
44707 return 0;
44708 }
44709 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44710 an ELF header */
44711
44712 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44713 - struct file *interpreter, unsigned long *interp_map_addr,
44714 - unsigned long no_base)
44715 + struct file *interpreter, unsigned long no_base)
44716 {
44717 struct elf_phdr *elf_phdata;
44718 struct elf_phdr *eppnt;
44719 - unsigned long load_addr = 0;
44720 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44721 int load_addr_set = 0;
44722 unsigned long last_bss = 0, elf_bss = 0;
44723 - unsigned long error = ~0UL;
44724 + unsigned long error = -EINVAL;
44725 unsigned long total_size;
44726 int retval, i, size;
44727
44728 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44729 goto out_close;
44730 }
44731
44732 +#ifdef CONFIG_PAX_SEGMEXEC
44733 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44734 + pax_task_size = SEGMEXEC_TASK_SIZE;
44735 +#endif
44736 +
44737 eppnt = elf_phdata;
44738 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44739 if (eppnt->p_type == PT_LOAD) {
44740 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44741 map_addr = elf_map(interpreter, load_addr + vaddr,
44742 eppnt, elf_prot, elf_type, total_size);
44743 total_size = 0;
44744 - if (!*interp_map_addr)
44745 - *interp_map_addr = map_addr;
44746 error = map_addr;
44747 if (BAD_ADDR(map_addr))
44748 goto out_close;
44749 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44750 k = load_addr + eppnt->p_vaddr;
44751 if (BAD_ADDR(k) ||
44752 eppnt->p_filesz > eppnt->p_memsz ||
44753 - eppnt->p_memsz > TASK_SIZE ||
44754 - TASK_SIZE - eppnt->p_memsz < k) {
44755 + eppnt->p_memsz > pax_task_size ||
44756 + pax_task_size - eppnt->p_memsz < k) {
44757 error = -ENOMEM;
44758 goto out_close;
44759 }
44760 @@ -530,6 +551,315 @@ out:
44761 return error;
44762 }
44763
44764 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44765 +#ifdef CONFIG_PAX_SOFTMODE
44766 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44767 +{
44768 + unsigned long pax_flags = 0UL;
44769 +
44770 +#ifdef CONFIG_PAX_PAGEEXEC
44771 + if (elf_phdata->p_flags & PF_PAGEEXEC)
44772 + pax_flags |= MF_PAX_PAGEEXEC;
44773 +#endif
44774 +
44775 +#ifdef CONFIG_PAX_SEGMEXEC
44776 + if (elf_phdata->p_flags & PF_SEGMEXEC)
44777 + pax_flags |= MF_PAX_SEGMEXEC;
44778 +#endif
44779 +
44780 +#ifdef CONFIG_PAX_EMUTRAMP
44781 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44782 + pax_flags |= MF_PAX_EMUTRAMP;
44783 +#endif
44784 +
44785 +#ifdef CONFIG_PAX_MPROTECT
44786 + if (elf_phdata->p_flags & PF_MPROTECT)
44787 + pax_flags |= MF_PAX_MPROTECT;
44788 +#endif
44789 +
44790 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44791 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44792 + pax_flags |= MF_PAX_RANDMMAP;
44793 +#endif
44794 +
44795 + return pax_flags;
44796 +}
44797 +#endif
44798 +
44799 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44800 +{
44801 + unsigned long pax_flags = 0UL;
44802 +
44803 +#ifdef CONFIG_PAX_PAGEEXEC
44804 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44805 + pax_flags |= MF_PAX_PAGEEXEC;
44806 +#endif
44807 +
44808 +#ifdef CONFIG_PAX_SEGMEXEC
44809 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44810 + pax_flags |= MF_PAX_SEGMEXEC;
44811 +#endif
44812 +
44813 +#ifdef CONFIG_PAX_EMUTRAMP
44814 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44815 + pax_flags |= MF_PAX_EMUTRAMP;
44816 +#endif
44817 +
44818 +#ifdef CONFIG_PAX_MPROTECT
44819 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44820 + pax_flags |= MF_PAX_MPROTECT;
44821 +#endif
44822 +
44823 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44824 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44825 + pax_flags |= MF_PAX_RANDMMAP;
44826 +#endif
44827 +
44828 + return pax_flags;
44829 +}
44830 +#endif
44831 +
44832 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44833 +#ifdef CONFIG_PAX_SOFTMODE
44834 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44835 +{
44836 + unsigned long pax_flags = 0UL;
44837 +
44838 +#ifdef CONFIG_PAX_PAGEEXEC
44839 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44840 + pax_flags |= MF_PAX_PAGEEXEC;
44841 +#endif
44842 +
44843 +#ifdef CONFIG_PAX_SEGMEXEC
44844 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44845 + pax_flags |= MF_PAX_SEGMEXEC;
44846 +#endif
44847 +
44848 +#ifdef CONFIG_PAX_EMUTRAMP
44849 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44850 + pax_flags |= MF_PAX_EMUTRAMP;
44851 +#endif
44852 +
44853 +#ifdef CONFIG_PAX_MPROTECT
44854 + if (pax_flags_softmode & MF_PAX_MPROTECT)
44855 + pax_flags |= MF_PAX_MPROTECT;
44856 +#endif
44857 +
44858 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44859 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44860 + pax_flags |= MF_PAX_RANDMMAP;
44861 +#endif
44862 +
44863 + return pax_flags;
44864 +}
44865 +#endif
44866 +
44867 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44868 +{
44869 + unsigned long pax_flags = 0UL;
44870 +
44871 +#ifdef CONFIG_PAX_PAGEEXEC
44872 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44873 + pax_flags |= MF_PAX_PAGEEXEC;
44874 +#endif
44875 +
44876 +#ifdef CONFIG_PAX_SEGMEXEC
44877 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44878 + pax_flags |= MF_PAX_SEGMEXEC;
44879 +#endif
44880 +
44881 +#ifdef CONFIG_PAX_EMUTRAMP
44882 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44883 + pax_flags |= MF_PAX_EMUTRAMP;
44884 +#endif
44885 +
44886 +#ifdef CONFIG_PAX_MPROTECT
44887 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44888 + pax_flags |= MF_PAX_MPROTECT;
44889 +#endif
44890 +
44891 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44892 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44893 + pax_flags |= MF_PAX_RANDMMAP;
44894 +#endif
44895 +
44896 + return pax_flags;
44897 +}
44898 +#endif
44899 +
44900 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44901 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44902 +{
44903 + unsigned long pax_flags = 0UL;
44904 +
44905 +#ifdef CONFIG_PAX_EI_PAX
44906 +
44907 +#ifdef CONFIG_PAX_PAGEEXEC
44908 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44909 + pax_flags |= MF_PAX_PAGEEXEC;
44910 +#endif
44911 +
44912 +#ifdef CONFIG_PAX_SEGMEXEC
44913 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44914 + pax_flags |= MF_PAX_SEGMEXEC;
44915 +#endif
44916 +
44917 +#ifdef CONFIG_PAX_EMUTRAMP
44918 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44919 + pax_flags |= MF_PAX_EMUTRAMP;
44920 +#endif
44921 +
44922 +#ifdef CONFIG_PAX_MPROTECT
44923 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44924 + pax_flags |= MF_PAX_MPROTECT;
44925 +#endif
44926 +
44927 +#ifdef CONFIG_PAX_ASLR
44928 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44929 + pax_flags |= MF_PAX_RANDMMAP;
44930 +#endif
44931 +
44932 +#else
44933 +
44934 +#ifdef CONFIG_PAX_PAGEEXEC
44935 + pax_flags |= MF_PAX_PAGEEXEC;
44936 +#endif
44937 +
44938 +#ifdef CONFIG_PAX_SEGMEXEC
44939 + pax_flags |= MF_PAX_SEGMEXEC;
44940 +#endif
44941 +
44942 +#ifdef CONFIG_PAX_MPROTECT
44943 + pax_flags |= MF_PAX_MPROTECT;
44944 +#endif
44945 +
44946 +#ifdef CONFIG_PAX_RANDMMAP
44947 + if (randomize_va_space)
44948 + pax_flags |= MF_PAX_RANDMMAP;
44949 +#endif
44950 +
44951 +#endif
44952 +
44953 + return pax_flags;
44954 +}
44955 +
44956 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
44957 +{
44958 +
44959 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44960 + unsigned long i;
44961 +
44962 + for (i = 0UL; i < elf_ex->e_phnum; i++)
44963 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
44964 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
44965 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
44966 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
44967 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
44968 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
44969 + return ~0UL;
44970 +
44971 +#ifdef CONFIG_PAX_SOFTMODE
44972 + if (pax_softmode)
44973 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
44974 + else
44975 +#endif
44976 +
44977 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
44978 + break;
44979 + }
44980 +#endif
44981 +
44982 + return ~0UL;
44983 +}
44984 +
44985 +static unsigned long pax_parse_xattr_pax(struct file * const file)
44986 +{
44987 +
44988 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44989 + ssize_t xattr_size, i;
44990 + unsigned char xattr_value[5];
44991 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
44992 +
44993 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
44994 + if (xattr_size <= 0 || xattr_size > 5)
44995 + return ~0UL;
44996 +
44997 + for (i = 0; i < xattr_size; i++)
44998 + switch (xattr_value[i]) {
44999 + default:
45000 + return ~0UL;
45001 +
45002 +#define parse_flag(option1, option2, flag) \
45003 + case option1: \
45004 + if (pax_flags_hardmode & MF_PAX_##flag) \
45005 + return ~0UL; \
45006 + pax_flags_hardmode |= MF_PAX_##flag; \
45007 + break; \
45008 + case option2: \
45009 + if (pax_flags_softmode & MF_PAX_##flag) \
45010 + return ~0UL; \
45011 + pax_flags_softmode |= MF_PAX_##flag; \
45012 + break;
45013 +
45014 + parse_flag('p', 'P', PAGEEXEC);
45015 + parse_flag('e', 'E', EMUTRAMP);
45016 + parse_flag('m', 'M', MPROTECT);
45017 + parse_flag('r', 'R', RANDMMAP);
45018 + parse_flag('s', 'S', SEGMEXEC);
45019 +
45020 +#undef parse_flag
45021 + }
45022 +
45023 + if (pax_flags_hardmode & pax_flags_softmode)
45024 + return ~0UL;
45025 +
45026 +#ifdef CONFIG_PAX_SOFTMODE
45027 + if (pax_softmode)
45028 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45029 + else
45030 +#endif
45031 +
45032 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45033 +#else
45034 + return ~0UL;
45035 +#endif
45036 +
45037 +}
45038 +
45039 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45040 +{
45041 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45042 +
45043 + pax_flags = pax_parse_ei_pax(elf_ex);
45044 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45045 + xattr_pax_flags = pax_parse_xattr_pax(file);
45046 +
45047 + if (pt_pax_flags == ~0UL)
45048 + pt_pax_flags = xattr_pax_flags;
45049 + else if (xattr_pax_flags == ~0UL)
45050 + xattr_pax_flags = pt_pax_flags;
45051 + if (pt_pax_flags != xattr_pax_flags)
45052 + return -EINVAL;
45053 + if (pt_pax_flags != ~0UL)
45054 + pax_flags = pt_pax_flags;
45055 +
45056 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45057 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45058 + if ((__supported_pte_mask & _PAGE_NX))
45059 + pax_flags &= ~MF_PAX_SEGMEXEC;
45060 + else
45061 + pax_flags &= ~MF_PAX_PAGEEXEC;
45062 + }
45063 +#endif
45064 +
45065 + if (0 > pax_check_flags(&pax_flags))
45066 + return -EINVAL;
45067 +
45068 + current->mm->pax_flags = pax_flags;
45069 + return 0;
45070 +}
45071 +#endif
45072 +
45073 /*
45074 * These are the functions used to load ELF style executables and shared
45075 * libraries. There is no binary dependent code anywhere else.
45076 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45077 {
45078 unsigned int random_variable = 0;
45079
45080 +#ifdef CONFIG_PAX_RANDUSTACK
45081 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45082 + return stack_top - current->mm->delta_stack;
45083 +#endif
45084 +
45085 if ((current->flags & PF_RANDOMIZE) &&
45086 !(current->personality & ADDR_NO_RANDOMIZE)) {
45087 random_variable = get_random_int() & STACK_RND_MASK;
45088 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45089 unsigned long load_addr = 0, load_bias = 0;
45090 int load_addr_set = 0;
45091 char * elf_interpreter = NULL;
45092 - unsigned long error;
45093 + unsigned long error = 0;
45094 struct elf_phdr *elf_ppnt, *elf_phdata;
45095 unsigned long elf_bss, elf_brk;
45096 int retval, i;
45097 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45098 unsigned long start_code, end_code, start_data, end_data;
45099 unsigned long reloc_func_desc __maybe_unused = 0;
45100 int executable_stack = EXSTACK_DEFAULT;
45101 - unsigned long def_flags = 0;
45102 struct {
45103 struct elfhdr elf_ex;
45104 struct elfhdr interp_elf_ex;
45105 } *loc;
45106 + unsigned long pax_task_size = TASK_SIZE;
45107
45108 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45109 if (!loc) {
45110 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45111 goto out_free_dentry;
45112
45113 /* OK, This is the point of no return */
45114 - current->mm->def_flags = def_flags;
45115 +
45116 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45117 + current->mm->pax_flags = 0UL;
45118 +#endif
45119 +
45120 +#ifdef CONFIG_PAX_DLRESOLVE
45121 + current->mm->call_dl_resolve = 0UL;
45122 +#endif
45123 +
45124 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45125 + current->mm->call_syscall = 0UL;
45126 +#endif
45127 +
45128 +#ifdef CONFIG_PAX_ASLR
45129 + current->mm->delta_mmap = 0UL;
45130 + current->mm->delta_stack = 0UL;
45131 +#endif
45132 +
45133 + current->mm->def_flags = 0;
45134 +
45135 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45136 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45137 + send_sig(SIGKILL, current, 0);
45138 + goto out_free_dentry;
45139 + }
45140 +#endif
45141 +
45142 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45143 + pax_set_initial_flags(bprm);
45144 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45145 + if (pax_set_initial_flags_func)
45146 + (pax_set_initial_flags_func)(bprm);
45147 +#endif
45148 +
45149 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45150 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45151 + current->mm->context.user_cs_limit = PAGE_SIZE;
45152 + current->mm->def_flags |= VM_PAGEEXEC;
45153 + }
45154 +#endif
45155 +
45156 +#ifdef CONFIG_PAX_SEGMEXEC
45157 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45158 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45159 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45160 + pax_task_size = SEGMEXEC_TASK_SIZE;
45161 + current->mm->def_flags |= VM_NOHUGEPAGE;
45162 + }
45163 +#endif
45164 +
45165 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45166 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45167 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45168 + put_cpu();
45169 + }
45170 +#endif
45171
45172 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45173 may depend on the personality. */
45174 SET_PERSONALITY(loc->elf_ex);
45175 +
45176 +#ifdef CONFIG_PAX_ASLR
45177 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45178 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45179 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45180 + }
45181 +#endif
45182 +
45183 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45184 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45185 + executable_stack = EXSTACK_DISABLE_X;
45186 + current->personality &= ~READ_IMPLIES_EXEC;
45187 + } else
45188 +#endif
45189 +
45190 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45191 current->personality |= READ_IMPLIES_EXEC;
45192
45193 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45194 #else
45195 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45196 #endif
45197 +
45198 +#ifdef CONFIG_PAX_RANDMMAP
45199 + /* PaX: randomize base address at the default exe base if requested */
45200 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45201 +#ifdef CONFIG_SPARC64
45202 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45203 +#else
45204 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45205 +#endif
45206 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45207 + elf_flags |= MAP_FIXED;
45208 + }
45209 +#endif
45210 +
45211 }
45212
45213 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45214 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45215 * allowed task size. Note that p_filesz must always be
45216 * <= p_memsz so it is only necessary to check p_memsz.
45217 */
45218 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45219 - elf_ppnt->p_memsz > TASK_SIZE ||
45220 - TASK_SIZE - elf_ppnt->p_memsz < k) {
45221 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45222 + elf_ppnt->p_memsz > pax_task_size ||
45223 + pax_task_size - elf_ppnt->p_memsz < k) {
45224 /* set_brk can never work. Avoid overflows. */
45225 send_sig(SIGKILL, current, 0);
45226 retval = -EINVAL;
45227 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45228 goto out_free_dentry;
45229 }
45230 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45231 - send_sig(SIGSEGV, current, 0);
45232 - retval = -EFAULT; /* Nobody gets to see this, but.. */
45233 - goto out_free_dentry;
45234 + /*
45235 + * This bss-zeroing can fail if the ELF
45236 + * file specifies odd protections. So
45237 + * we don't check the return value
45238 + */
45239 }
45240
45241 +#ifdef CONFIG_PAX_RANDMMAP
45242 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45243 + unsigned long start, size;
45244 +
45245 + start = ELF_PAGEALIGN(elf_brk);
45246 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45247 + down_read(&current->mm->mmap_sem);
45248 + retval = -ENOMEM;
45249 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45250 + unsigned long prot = PROT_NONE;
45251 +
45252 + up_read(&current->mm->mmap_sem);
45253 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45254 +// if (current->personality & ADDR_NO_RANDOMIZE)
45255 +// prot = PROT_READ;
45256 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45257 + retval = IS_ERR_VALUE(start) ? start : 0;
45258 + } else
45259 + up_read(&current->mm->mmap_sem);
45260 + if (retval == 0)
45261 + retval = set_brk(start + size, start + size + PAGE_SIZE);
45262 + if (retval < 0) {
45263 + send_sig(SIGKILL, current, 0);
45264 + goto out_free_dentry;
45265 + }
45266 + }
45267 +#endif
45268 +
45269 if (elf_interpreter) {
45270 - unsigned long interp_map_addr = 0;
45271 -
45272 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45273 interpreter,
45274 - &interp_map_addr,
45275 load_bias);
45276 if (!IS_ERR((void *)elf_entry)) {
45277 /*
45278 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45279 * Decide what to dump of a segment, part, all or none.
45280 */
45281 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45282 - unsigned long mm_flags)
45283 + unsigned long mm_flags, long signr)
45284 {
45285 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45286
45287 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45288 if (vma->vm_file == NULL)
45289 return 0;
45290
45291 - if (FILTER(MAPPED_PRIVATE))
45292 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45293 goto whole;
45294
45295 /*
45296 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45297 {
45298 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45299 int i = 0;
45300 - do
45301 + do {
45302 i += 2;
45303 - while (auxv[i - 2] != AT_NULL);
45304 + } while (auxv[i - 2] != AT_NULL);
45305 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
45306 }
45307
45308 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
45309 }
45310
45311 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
45312 - unsigned long mm_flags)
45313 + struct coredump_params *cprm)
45314 {
45315 struct vm_area_struct *vma;
45316 size_t size = 0;
45317
45318 for (vma = first_vma(current, gate_vma); vma != NULL;
45319 vma = next_vma(vma, gate_vma))
45320 - size += vma_dump_size(vma, mm_flags);
45321 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45322 return size;
45323 }
45324
45325 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45326
45327 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
45328
45329 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
45330 + offset += elf_core_vma_data_size(gate_vma, cprm);
45331 offset += elf_core_extra_data_size();
45332 e_shoff = offset;
45333
45334 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
45335 offset = dataoff;
45336
45337 size += sizeof(*elf);
45338 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45339 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
45340 goto end_coredump;
45341
45342 size += sizeof(*phdr4note);
45343 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45344 if (size > cprm->limit
45345 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
45346 goto end_coredump;
45347 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45348 phdr.p_offset = offset;
45349 phdr.p_vaddr = vma->vm_start;
45350 phdr.p_paddr = 0;
45351 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
45352 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45353 phdr.p_memsz = vma->vm_end - vma->vm_start;
45354 offset += phdr.p_filesz;
45355 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
45356 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45357 phdr.p_align = ELF_EXEC_PAGESIZE;
45358
45359 size += sizeof(phdr);
45360 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45361 if (size > cprm->limit
45362 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
45363 goto end_coredump;
45364 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45365 unsigned long addr;
45366 unsigned long end;
45367
45368 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
45369 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45370
45371 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
45372 struct page *page;
45373 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45374 page = get_dump_page(addr);
45375 if (page) {
45376 void *kaddr = kmap(page);
45377 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
45378 stop = ((size += PAGE_SIZE) > cprm->limit) ||
45379 !dump_write(cprm->file, kaddr,
45380 PAGE_SIZE);
45381 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45382
45383 if (e_phnum == PN_XNUM) {
45384 size += sizeof(*shdr4extnum);
45385 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45386 if (size > cprm->limit
45387 || !dump_write(cprm->file, shdr4extnum,
45388 sizeof(*shdr4extnum)))
45389 @@ -2216,6 +2667,97 @@ out:
45390
45391 #endif /* CONFIG_ELF_CORE */
45392
45393 +#ifdef CONFIG_PAX_MPROTECT
45394 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
45395 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45396 + * we'll remove VM_MAYWRITE for good on RELRO segments.
45397 + *
45398 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45399 + * basis because we want to allow the common case and not the special ones.
45400 + */
45401 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45402 +{
45403 + struct elfhdr elf_h;
45404 + struct elf_phdr elf_p;
45405 + unsigned long i;
45406 + unsigned long oldflags;
45407 + bool is_textrel_rw, is_textrel_rx, is_relro;
45408 +
45409 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45410 + return;
45411 +
45412 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45413 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45414 +
45415 +#ifdef CONFIG_PAX_ELFRELOCS
45416 + /* possible TEXTREL */
45417 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45418 + 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);
45419 +#else
45420 + is_textrel_rw = false;
45421 + is_textrel_rx = false;
45422 +#endif
45423 +
45424 + /* possible RELRO */
45425 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45426 +
45427 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45428 + return;
45429 +
45430 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45431 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45432 +
45433 +#ifdef CONFIG_PAX_ETEXECRELOCS
45434 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45435 +#else
45436 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45437 +#endif
45438 +
45439 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45440 + !elf_check_arch(&elf_h) ||
45441 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45442 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45443 + return;
45444 +
45445 + for (i = 0UL; i < elf_h.e_phnum; i++) {
45446 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45447 + return;
45448 + switch (elf_p.p_type) {
45449 + case PT_DYNAMIC:
45450 + if (!is_textrel_rw && !is_textrel_rx)
45451 + continue;
45452 + i = 0UL;
45453 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45454 + elf_dyn dyn;
45455 +
45456 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45457 + return;
45458 + if (dyn.d_tag == DT_NULL)
45459 + return;
45460 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45461 + gr_log_textrel(vma);
45462 + if (is_textrel_rw)
45463 + vma->vm_flags |= VM_MAYWRITE;
45464 + else
45465 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45466 + vma->vm_flags &= ~VM_MAYWRITE;
45467 + return;
45468 + }
45469 + i++;
45470 + }
45471 + return;
45472 +
45473 + case PT_GNU_RELRO:
45474 + if (!is_relro)
45475 + continue;
45476 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45477 + vma->vm_flags &= ~VM_MAYWRITE;
45478 + return;
45479 + }
45480 + }
45481 +}
45482 +#endif
45483 +
45484 static int __init init_elf_binfmt(void)
45485 {
45486 register_binfmt(&elf_format);
45487 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45488 index e280352..7b2f231 100644
45489 --- a/fs/binfmt_flat.c
45490 +++ b/fs/binfmt_flat.c
45491 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45492 realdatastart = (unsigned long) -ENOMEM;
45493 printk("Unable to allocate RAM for process data, errno %d\n",
45494 (int)-realdatastart);
45495 + down_write(&current->mm->mmap_sem);
45496 vm_munmap(textpos, text_len);
45497 + up_write(&current->mm->mmap_sem);
45498 ret = realdatastart;
45499 goto err;
45500 }
45501 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45502 }
45503 if (IS_ERR_VALUE(result)) {
45504 printk("Unable to read data+bss, errno %d\n", (int)-result);
45505 + down_write(&current->mm->mmap_sem);
45506 vm_munmap(textpos, text_len);
45507 vm_munmap(realdatastart, len);
45508 + up_write(&current->mm->mmap_sem);
45509 ret = result;
45510 goto err;
45511 }
45512 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45513 }
45514 if (IS_ERR_VALUE(result)) {
45515 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45516 + down_write(&current->mm->mmap_sem);
45517 vm_munmap(textpos, text_len + data_len + extra +
45518 MAX_SHARED_LIBS * sizeof(unsigned long));
45519 + up_write(&current->mm->mmap_sem);
45520 ret = result;
45521 goto err;
45522 }
45523 diff --git a/fs/bio.c b/fs/bio.c
45524 index b96fc6c..431d628 100644
45525 --- a/fs/bio.c
45526 +++ b/fs/bio.c
45527 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45528 /*
45529 * Overflow, abort
45530 */
45531 - if (end < start)
45532 + if (end < start || end - start > INT_MAX - nr_pages)
45533 return ERR_PTR(-EINVAL);
45534
45535 nr_pages += end - start;
45536 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45537 /*
45538 * Overflow, abort
45539 */
45540 - if (end < start)
45541 + if (end < start || end - start > INT_MAX - nr_pages)
45542 return ERR_PTR(-EINVAL);
45543
45544 nr_pages += end - start;
45545 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45546 const int read = bio_data_dir(bio) == READ;
45547 struct bio_map_data *bmd = bio->bi_private;
45548 int i;
45549 - char *p = bmd->sgvecs[0].iov_base;
45550 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45551
45552 __bio_for_each_segment(bvec, bio, i, 0) {
45553 char *addr = page_address(bvec->bv_page);
45554 diff --git a/fs/block_dev.c b/fs/block_dev.c
45555 index ab3a456..7da538b 100644
45556 --- a/fs/block_dev.c
45557 +++ b/fs/block_dev.c
45558 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45559 else if (bdev->bd_contains == bdev)
45560 return true; /* is a whole device which isn't held */
45561
45562 - else if (whole->bd_holder == bd_may_claim)
45563 + else if (whole->bd_holder == (void *)bd_may_claim)
45564 return true; /* is a partition of a device that is being partitioned */
45565 else if (whole->bd_holder != NULL)
45566 return false; /* is a partition of a held device */
45567 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45568 index cdfb4c4..da736d4 100644
45569 --- a/fs/btrfs/ctree.c
45570 +++ b/fs/btrfs/ctree.c
45571 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45572 free_extent_buffer(buf);
45573 add_root_to_dirty_list(root);
45574 } else {
45575 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45576 - parent_start = parent->start;
45577 - else
45578 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45579 + if (parent)
45580 + parent_start = parent->start;
45581 + else
45582 + parent_start = 0;
45583 + } else
45584 parent_start = 0;
45585
45586 WARN_ON(trans->transid != btrfs_header_generation(parent));
45587 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45588 index 95542a1..95a8727 100644
45589 --- a/fs/btrfs/inode.c
45590 +++ b/fs/btrfs/inode.c
45591 @@ -7243,7 +7243,7 @@ fail:
45592 return -ENOMEM;
45593 }
45594
45595 -static int btrfs_getattr(struct vfsmount *mnt,
45596 +int btrfs_getattr(struct vfsmount *mnt,
45597 struct dentry *dentry, struct kstat *stat)
45598 {
45599 struct inode *inode = dentry->d_inode;
45600 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45601 return 0;
45602 }
45603
45604 +EXPORT_SYMBOL(btrfs_getattr);
45605 +
45606 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
45607 +{
45608 + return BTRFS_I(inode)->root->anon_dev;
45609 +}
45610 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45611 +
45612 /*
45613 * If a file is moved, it will inherit the cow and compression flags of the new
45614 * directory.
45615 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45616 index 8fcf9a5..a200000 100644
45617 --- a/fs/btrfs/ioctl.c
45618 +++ b/fs/btrfs/ioctl.c
45619 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45620 for (i = 0; i < num_types; i++) {
45621 struct btrfs_space_info *tmp;
45622
45623 + /* Don't copy in more than we allocated */
45624 if (!slot_count)
45625 break;
45626
45627 + slot_count--;
45628 +
45629 info = NULL;
45630 rcu_read_lock();
45631 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45632 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45633 memcpy(dest, &space, sizeof(space));
45634 dest++;
45635 space_args.total_spaces++;
45636 - slot_count--;
45637 }
45638 - if (!slot_count)
45639 - break;
45640 }
45641 up_read(&info->groups_sem);
45642 }
45643 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45644 index 776f0aa..3aad281 100644
45645 --- a/fs/btrfs/relocation.c
45646 +++ b/fs/btrfs/relocation.c
45647 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45648 }
45649 spin_unlock(&rc->reloc_root_tree.lock);
45650
45651 - BUG_ON((struct btrfs_root *)node->data != root);
45652 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
45653
45654 if (!del) {
45655 spin_lock(&rc->reloc_root_tree.lock);
45656 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45657 index 622f469..e8d2d55 100644
45658 --- a/fs/cachefiles/bind.c
45659 +++ b/fs/cachefiles/bind.c
45660 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45661 args);
45662
45663 /* start by checking things over */
45664 - ASSERT(cache->fstop_percent >= 0 &&
45665 - cache->fstop_percent < cache->fcull_percent &&
45666 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
45667 cache->fcull_percent < cache->frun_percent &&
45668 cache->frun_percent < 100);
45669
45670 - ASSERT(cache->bstop_percent >= 0 &&
45671 - cache->bstop_percent < cache->bcull_percent &&
45672 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
45673 cache->bcull_percent < cache->brun_percent &&
45674 cache->brun_percent < 100);
45675
45676 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45677 index 0a1467b..6a53245 100644
45678 --- a/fs/cachefiles/daemon.c
45679 +++ b/fs/cachefiles/daemon.c
45680 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45681 if (n > buflen)
45682 return -EMSGSIZE;
45683
45684 - if (copy_to_user(_buffer, buffer, n) != 0)
45685 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45686 return -EFAULT;
45687
45688 return n;
45689 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45690 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45691 return -EIO;
45692
45693 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
45694 + if (datalen > PAGE_SIZE - 1)
45695 return -EOPNOTSUPP;
45696
45697 /* drag the command string into the kernel so we can parse it */
45698 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45699 if (args[0] != '%' || args[1] != '\0')
45700 return -EINVAL;
45701
45702 - if (fstop < 0 || fstop >= cache->fcull_percent)
45703 + if (fstop >= cache->fcull_percent)
45704 return cachefiles_daemon_range_error(cache, args);
45705
45706 cache->fstop_percent = fstop;
45707 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45708 if (args[0] != '%' || args[1] != '\0')
45709 return -EINVAL;
45710
45711 - if (bstop < 0 || bstop >= cache->bcull_percent)
45712 + if (bstop >= cache->bcull_percent)
45713 return cachefiles_daemon_range_error(cache, args);
45714
45715 cache->bstop_percent = bstop;
45716 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45717 index bd6bc1b..b627b53 100644
45718 --- a/fs/cachefiles/internal.h
45719 +++ b/fs/cachefiles/internal.h
45720 @@ -57,7 +57,7 @@ struct cachefiles_cache {
45721 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45722 struct rb_root active_nodes; /* active nodes (can't be culled) */
45723 rwlock_t active_lock; /* lock for active_nodes */
45724 - atomic_t gravecounter; /* graveyard uniquifier */
45725 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45726 unsigned frun_percent; /* when to stop culling (% files) */
45727 unsigned fcull_percent; /* when to start culling (% files) */
45728 unsigned fstop_percent; /* when to stop allocating (% files) */
45729 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45730 * proc.c
45731 */
45732 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45733 -extern atomic_t cachefiles_lookup_histogram[HZ];
45734 -extern atomic_t cachefiles_mkdir_histogram[HZ];
45735 -extern atomic_t cachefiles_create_histogram[HZ];
45736 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45737 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45738 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45739
45740 extern int __init cachefiles_proc_init(void);
45741 extern void cachefiles_proc_cleanup(void);
45742 static inline
45743 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45744 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45745 {
45746 unsigned long jif = jiffies - start_jif;
45747 if (jif >= HZ)
45748 jif = HZ - 1;
45749 - atomic_inc(&histogram[jif]);
45750 + atomic_inc_unchecked(&histogram[jif]);
45751 }
45752
45753 #else
45754 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45755 index b0b5f7c..039bb26 100644
45756 --- a/fs/cachefiles/namei.c
45757 +++ b/fs/cachefiles/namei.c
45758 @@ -318,7 +318,7 @@ try_again:
45759 /* first step is to make up a grave dentry in the graveyard */
45760 sprintf(nbuffer, "%08x%08x",
45761 (uint32_t) get_seconds(),
45762 - (uint32_t) atomic_inc_return(&cache->gravecounter));
45763 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45764
45765 /* do the multiway lock magic */
45766 trap = lock_rename(cache->graveyard, dir);
45767 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45768 index eccd339..4c1d995 100644
45769 --- a/fs/cachefiles/proc.c
45770 +++ b/fs/cachefiles/proc.c
45771 @@ -14,9 +14,9 @@
45772 #include <linux/seq_file.h>
45773 #include "internal.h"
45774
45775 -atomic_t cachefiles_lookup_histogram[HZ];
45776 -atomic_t cachefiles_mkdir_histogram[HZ];
45777 -atomic_t cachefiles_create_histogram[HZ];
45778 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45779 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45780 +atomic_unchecked_t cachefiles_create_histogram[HZ];
45781
45782 /*
45783 * display the latency histogram
45784 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45785 return 0;
45786 default:
45787 index = (unsigned long) v - 3;
45788 - x = atomic_read(&cachefiles_lookup_histogram[index]);
45789 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
45790 - z = atomic_read(&cachefiles_create_histogram[index]);
45791 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45792 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45793 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45794 if (x == 0 && y == 0 && z == 0)
45795 return 0;
45796
45797 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45798 index c994691..2a1537f 100644
45799 --- a/fs/cachefiles/rdwr.c
45800 +++ b/fs/cachefiles/rdwr.c
45801 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45802 old_fs = get_fs();
45803 set_fs(KERNEL_DS);
45804 ret = file->f_op->write(
45805 - file, (const void __user *) data, len, &pos);
45806 + file, (const void __force_user *) data, len, &pos);
45807 set_fs(old_fs);
45808 kunmap(page);
45809 if (ret != len)
45810 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45811 index e5b7731..b9c59fb 100644
45812 --- a/fs/ceph/dir.c
45813 +++ b/fs/ceph/dir.c
45814 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45815 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45816 struct ceph_mds_client *mdsc = fsc->mdsc;
45817 unsigned frag = fpos_frag(filp->f_pos);
45818 - int off = fpos_off(filp->f_pos);
45819 + unsigned int off = fpos_off(filp->f_pos);
45820 int err;
45821 u32 ftype;
45822 struct ceph_mds_reply_info_parsed *rinfo;
45823 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45824 index d9ea6ed..1e6c8ac 100644
45825 --- a/fs/cifs/cifs_debug.c
45826 +++ b/fs/cifs/cifs_debug.c
45827 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45828
45829 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45830 #ifdef CONFIG_CIFS_STATS2
45831 - atomic_set(&totBufAllocCount, 0);
45832 - atomic_set(&totSmBufAllocCount, 0);
45833 + atomic_set_unchecked(&totBufAllocCount, 0);
45834 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45835 #endif /* CONFIG_CIFS_STATS2 */
45836 spin_lock(&cifs_tcp_ses_lock);
45837 list_for_each(tmp1, &cifs_tcp_ses_list) {
45838 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45839 tcon = list_entry(tmp3,
45840 struct cifs_tcon,
45841 tcon_list);
45842 - atomic_set(&tcon->num_smbs_sent, 0);
45843 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45844 if (server->ops->clear_stats)
45845 server->ops->clear_stats(tcon);
45846 }
45847 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45848 smBufAllocCount.counter, cifs_min_small);
45849 #ifdef CONFIG_CIFS_STATS2
45850 seq_printf(m, "Total Large %d Small %d Allocations\n",
45851 - atomic_read(&totBufAllocCount),
45852 - atomic_read(&totSmBufAllocCount));
45853 + atomic_read_unchecked(&totBufAllocCount),
45854 + atomic_read_unchecked(&totSmBufAllocCount));
45855 #endif /* CONFIG_CIFS_STATS2 */
45856
45857 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45858 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45859 if (tcon->need_reconnect)
45860 seq_puts(m, "\tDISCONNECTED ");
45861 seq_printf(m, "\nSMBs: %d",
45862 - atomic_read(&tcon->num_smbs_sent));
45863 + atomic_read_unchecked(&tcon->num_smbs_sent));
45864 if (server->ops->print_stats)
45865 server->ops->print_stats(m, tcon);
45866 }
45867 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45868 index e7931cc..76a1ab9 100644
45869 --- a/fs/cifs/cifsfs.c
45870 +++ b/fs/cifs/cifsfs.c
45871 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45872 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45873 cifs_req_cachep = kmem_cache_create("cifs_request",
45874 CIFSMaxBufSize + max_hdr_size, 0,
45875 - SLAB_HWCACHE_ALIGN, NULL);
45876 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45877 if (cifs_req_cachep == NULL)
45878 return -ENOMEM;
45879
45880 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45881 efficient to alloc 1 per page off the slab compared to 17K (5page)
45882 alloc of large cifs buffers even when page debugging is on */
45883 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45884 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45885 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45886 NULL);
45887 if (cifs_sm_req_cachep == NULL) {
45888 mempool_destroy(cifs_req_poolp);
45889 @@ -1111,8 +1111,8 @@ init_cifs(void)
45890 atomic_set(&bufAllocCount, 0);
45891 atomic_set(&smBufAllocCount, 0);
45892 #ifdef CONFIG_CIFS_STATS2
45893 - atomic_set(&totBufAllocCount, 0);
45894 - atomic_set(&totSmBufAllocCount, 0);
45895 + atomic_set_unchecked(&totBufAllocCount, 0);
45896 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45897 #endif /* CONFIG_CIFS_STATS2 */
45898
45899 atomic_set(&midCount, 0);
45900 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45901 index f5af252..489b5f2 100644
45902 --- a/fs/cifs/cifsglob.h
45903 +++ b/fs/cifs/cifsglob.h
45904 @@ -751,35 +751,35 @@ struct cifs_tcon {
45905 __u16 Flags; /* optional support bits */
45906 enum statusEnum tidStatus;
45907 #ifdef CONFIG_CIFS_STATS
45908 - atomic_t num_smbs_sent;
45909 + atomic_unchecked_t num_smbs_sent;
45910 union {
45911 struct {
45912 - atomic_t num_writes;
45913 - atomic_t num_reads;
45914 - atomic_t num_flushes;
45915 - atomic_t num_oplock_brks;
45916 - atomic_t num_opens;
45917 - atomic_t num_closes;
45918 - atomic_t num_deletes;
45919 - atomic_t num_mkdirs;
45920 - atomic_t num_posixopens;
45921 - atomic_t num_posixmkdirs;
45922 - atomic_t num_rmdirs;
45923 - atomic_t num_renames;
45924 - atomic_t num_t2renames;
45925 - atomic_t num_ffirst;
45926 - atomic_t num_fnext;
45927 - atomic_t num_fclose;
45928 - atomic_t num_hardlinks;
45929 - atomic_t num_symlinks;
45930 - atomic_t num_locks;
45931 - atomic_t num_acl_get;
45932 - atomic_t num_acl_set;
45933 + atomic_unchecked_t num_writes;
45934 + atomic_unchecked_t num_reads;
45935 + atomic_unchecked_t num_flushes;
45936 + atomic_unchecked_t num_oplock_brks;
45937 + atomic_unchecked_t num_opens;
45938 + atomic_unchecked_t num_closes;
45939 + atomic_unchecked_t num_deletes;
45940 + atomic_unchecked_t num_mkdirs;
45941 + atomic_unchecked_t num_posixopens;
45942 + atomic_unchecked_t num_posixmkdirs;
45943 + atomic_unchecked_t num_rmdirs;
45944 + atomic_unchecked_t num_renames;
45945 + atomic_unchecked_t num_t2renames;
45946 + atomic_unchecked_t num_ffirst;
45947 + atomic_unchecked_t num_fnext;
45948 + atomic_unchecked_t num_fclose;
45949 + atomic_unchecked_t num_hardlinks;
45950 + atomic_unchecked_t num_symlinks;
45951 + atomic_unchecked_t num_locks;
45952 + atomic_unchecked_t num_acl_get;
45953 + atomic_unchecked_t num_acl_set;
45954 } cifs_stats;
45955 #ifdef CONFIG_CIFS_SMB2
45956 struct {
45957 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45958 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45959 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45960 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45961 } smb2_stats;
45962 #endif /* CONFIG_CIFS_SMB2 */
45963 } stats;
45964 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
45965 }
45966
45967 #ifdef CONFIG_CIFS_STATS
45968 -#define cifs_stats_inc atomic_inc
45969 +#define cifs_stats_inc atomic_inc_unchecked
45970
45971 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
45972 unsigned int bytes)
45973 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
45974 /* Various Debug counters */
45975 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
45976 #ifdef CONFIG_CIFS_STATS2
45977 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
45978 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
45979 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
45980 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
45981 #endif
45982 GLOBAL_EXTERN atomic_t smBufAllocCount;
45983 GLOBAL_EXTERN atomic_t midCount;
45984 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
45985 index 51dc2fb..1e12a33 100644
45986 --- a/fs/cifs/link.c
45987 +++ b/fs/cifs/link.c
45988 @@ -616,7 +616,7 @@ symlink_exit:
45989
45990 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
45991 {
45992 - char *p = nd_get_link(nd);
45993 + const char *p = nd_get_link(nd);
45994 if (!IS_ERR(p))
45995 kfree(p);
45996 }
45997 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
45998 index 3a00c0d..42d901c 100644
45999 --- a/fs/cifs/misc.c
46000 +++ b/fs/cifs/misc.c
46001 @@ -169,7 +169,7 @@ cifs_buf_get(void)
46002 memset(ret_buf, 0, buf_size + 3);
46003 atomic_inc(&bufAllocCount);
46004 #ifdef CONFIG_CIFS_STATS2
46005 - atomic_inc(&totBufAllocCount);
46006 + atomic_inc_unchecked(&totBufAllocCount);
46007 #endif /* CONFIG_CIFS_STATS2 */
46008 }
46009
46010 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46011 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46012 atomic_inc(&smBufAllocCount);
46013 #ifdef CONFIG_CIFS_STATS2
46014 - atomic_inc(&totSmBufAllocCount);
46015 + atomic_inc_unchecked(&totSmBufAllocCount);
46016 #endif /* CONFIG_CIFS_STATS2 */
46017
46018 }
46019 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46020 index 591bf19..690d600 100644
46021 --- a/fs/cifs/smb1ops.c
46022 +++ b/fs/cifs/smb1ops.c
46023 @@ -617,27 +617,27 @@ static void
46024 cifs_clear_stats(struct cifs_tcon *tcon)
46025 {
46026 #ifdef CONFIG_CIFS_STATS
46027 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46028 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46029 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46030 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46031 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46032 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46033 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46034 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46035 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46036 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46037 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46038 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46039 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46040 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46041 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46042 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46043 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46044 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46045 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46046 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46047 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46048 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46049 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46050 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46051 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46052 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46053 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46054 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46055 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46056 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46057 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46058 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46059 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46060 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46061 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46062 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46063 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46064 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46065 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46066 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46067 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46068 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46069 #endif
46070 }
46071
46072 @@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46073 {
46074 #ifdef CONFIG_CIFS_STATS
46075 seq_printf(m, " Oplocks breaks: %d",
46076 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46077 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46078 seq_printf(m, "\nReads: %d Bytes: %llu",
46079 - atomic_read(&tcon->stats.cifs_stats.num_reads),
46080 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46081 (long long)(tcon->bytes_read));
46082 seq_printf(m, "\nWrites: %d Bytes: %llu",
46083 - atomic_read(&tcon->stats.cifs_stats.num_writes),
46084 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46085 (long long)(tcon->bytes_written));
46086 seq_printf(m, "\nFlushes: %d",
46087 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
46088 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46089 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46090 - atomic_read(&tcon->stats.cifs_stats.num_locks),
46091 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46092 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46093 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46094 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46095 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46096 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46097 - atomic_read(&tcon->stats.cifs_stats.num_opens),
46098 - atomic_read(&tcon->stats.cifs_stats.num_closes),
46099 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
46100 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46101 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46102 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46103 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46104 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46105 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46106 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46107 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46108 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46109 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46110 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46111 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46112 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46113 seq_printf(m, "\nRenames: %d T2 Renames %d",
46114 - atomic_read(&tcon->stats.cifs_stats.num_renames),
46115 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46116 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46117 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46118 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46119 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46120 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
46121 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
46122 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46123 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46124 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46125 #endif
46126 }
46127
46128 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46129 index 4d9dbe0..0af4601 100644
46130 --- a/fs/cifs/smb2ops.c
46131 +++ b/fs/cifs/smb2ops.c
46132 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46133 #ifdef CONFIG_CIFS_STATS
46134 int i;
46135 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46136 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46137 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46138 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46139 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46140 }
46141 #endif
46142 }
46143 @@ -301,66 +301,66 @@ static void
46144 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46145 {
46146 #ifdef CONFIG_CIFS_STATS
46147 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46148 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46149 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46150 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46151 seq_printf(m, "\nNegotiates: %d sent %d failed",
46152 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46153 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46154 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46155 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46156 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46157 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46158 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46159 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46160 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46161 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46162 seq_printf(m, "\nLogoffs: %d sent %d failed",
46163 - atomic_read(&sent[SMB2_LOGOFF_HE]),
46164 - atomic_read(&failed[SMB2_LOGOFF_HE]));
46165 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46166 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46167 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46168 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46169 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46170 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46171 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46172 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46173 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46174 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46175 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46176 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46177 seq_printf(m, "\nCreates: %d sent %d failed",
46178 - atomic_read(&sent[SMB2_CREATE_HE]),
46179 - atomic_read(&failed[SMB2_CREATE_HE]));
46180 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46181 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46182 seq_printf(m, "\nCloses: %d sent %d failed",
46183 - atomic_read(&sent[SMB2_CLOSE_HE]),
46184 - atomic_read(&failed[SMB2_CLOSE_HE]));
46185 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46186 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46187 seq_printf(m, "\nFlushes: %d sent %d failed",
46188 - atomic_read(&sent[SMB2_FLUSH_HE]),
46189 - atomic_read(&failed[SMB2_FLUSH_HE]));
46190 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46191 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46192 seq_printf(m, "\nReads: %d sent %d failed",
46193 - atomic_read(&sent[SMB2_READ_HE]),
46194 - atomic_read(&failed[SMB2_READ_HE]));
46195 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
46196 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
46197 seq_printf(m, "\nWrites: %d sent %d failed",
46198 - atomic_read(&sent[SMB2_WRITE_HE]),
46199 - atomic_read(&failed[SMB2_WRITE_HE]));
46200 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46201 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46202 seq_printf(m, "\nLocks: %d sent %d failed",
46203 - atomic_read(&sent[SMB2_LOCK_HE]),
46204 - atomic_read(&failed[SMB2_LOCK_HE]));
46205 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46206 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46207 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46208 - atomic_read(&sent[SMB2_IOCTL_HE]),
46209 - atomic_read(&failed[SMB2_IOCTL_HE]));
46210 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46211 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46212 seq_printf(m, "\nCancels: %d sent %d failed",
46213 - atomic_read(&sent[SMB2_CANCEL_HE]),
46214 - atomic_read(&failed[SMB2_CANCEL_HE]));
46215 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46216 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46217 seq_printf(m, "\nEchos: %d sent %d failed",
46218 - atomic_read(&sent[SMB2_ECHO_HE]),
46219 - atomic_read(&failed[SMB2_ECHO_HE]));
46220 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46221 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46222 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46223 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46224 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46225 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46226 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46227 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46228 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46229 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46230 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46231 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46232 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46233 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46234 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46235 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46236 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46237 seq_printf(m, "\nSetInfos: %d sent %d failed",
46238 - atomic_read(&sent[SMB2_SET_INFO_HE]),
46239 - atomic_read(&failed[SMB2_SET_INFO_HE]));
46240 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46241 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46242 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46243 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46244 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46245 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46246 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46247 #endif
46248 }
46249
46250 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46251 index 958ae0e..505c9d0 100644
46252 --- a/fs/coda/cache.c
46253 +++ b/fs/coda/cache.c
46254 @@ -24,7 +24,7 @@
46255 #include "coda_linux.h"
46256 #include "coda_cache.h"
46257
46258 -static atomic_t permission_epoch = ATOMIC_INIT(0);
46259 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46260
46261 /* replace or extend an acl cache hit */
46262 void coda_cache_enter(struct inode *inode, int mask)
46263 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46264 struct coda_inode_info *cii = ITOC(inode);
46265
46266 spin_lock(&cii->c_lock);
46267 - cii->c_cached_epoch = atomic_read(&permission_epoch);
46268 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46269 if (cii->c_uid != current_fsuid()) {
46270 cii->c_uid = current_fsuid();
46271 cii->c_cached_perm = mask;
46272 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46273 {
46274 struct coda_inode_info *cii = ITOC(inode);
46275 spin_lock(&cii->c_lock);
46276 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
46277 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
46278 spin_unlock(&cii->c_lock);
46279 }
46280
46281 /* remove all acl caches */
46282 void coda_cache_clear_all(struct super_block *sb)
46283 {
46284 - atomic_inc(&permission_epoch);
46285 + atomic_inc_unchecked(&permission_epoch);
46286 }
46287
46288
46289 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
46290 spin_lock(&cii->c_lock);
46291 hit = (mask & cii->c_cached_perm) == mask &&
46292 cii->c_uid == current_fsuid() &&
46293 - cii->c_cached_epoch == atomic_read(&permission_epoch);
46294 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
46295 spin_unlock(&cii->c_lock);
46296
46297 return hit;
46298 diff --git a/fs/compat.c b/fs/compat.c
46299 index 015e1e1..5ce8e54 100644
46300 --- a/fs/compat.c
46301 +++ b/fs/compat.c
46302 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
46303
46304 set_fs(KERNEL_DS);
46305 /* The __user pointer cast is valid because of the set_fs() */
46306 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
46307 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
46308 set_fs(oldfs);
46309 /* truncating is ok because it's a user address */
46310 if (!ret)
46311 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
46312 goto out;
46313
46314 ret = -EINVAL;
46315 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
46316 + if (nr_segs > UIO_MAXIOV)
46317 goto out;
46318 if (nr_segs > fast_segs) {
46319 ret = -ENOMEM;
46320 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
46321
46322 struct compat_readdir_callback {
46323 struct compat_old_linux_dirent __user *dirent;
46324 + struct file * file;
46325 int result;
46326 };
46327
46328 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
46329 buf->result = -EOVERFLOW;
46330 return -EOVERFLOW;
46331 }
46332 +
46333 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46334 + return 0;
46335 +
46336 buf->result++;
46337 dirent = buf->dirent;
46338 if (!access_ok(VERIFY_WRITE, dirent,
46339 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
46340
46341 buf.result = 0;
46342 buf.dirent = dirent;
46343 + buf.file = f.file;
46344
46345 error = vfs_readdir(f.file, compat_fillonedir, &buf);
46346 if (buf.result)
46347 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
46348 struct compat_getdents_callback {
46349 struct compat_linux_dirent __user *current_dir;
46350 struct compat_linux_dirent __user *previous;
46351 + struct file * file;
46352 int count;
46353 int error;
46354 };
46355 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
46356 buf->error = -EOVERFLOW;
46357 return -EOVERFLOW;
46358 }
46359 +
46360 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46361 + return 0;
46362 +
46363 dirent = buf->previous;
46364 if (dirent) {
46365 if (__put_user(offset, &dirent->d_off))
46366 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46367 buf.previous = NULL;
46368 buf.count = count;
46369 buf.error = 0;
46370 + buf.file = f.file;
46371
46372 error = vfs_readdir(f.file, compat_filldir, &buf);
46373 if (error >= 0)
46374 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46375 struct compat_getdents_callback64 {
46376 struct linux_dirent64 __user *current_dir;
46377 struct linux_dirent64 __user *previous;
46378 + struct file * file;
46379 int count;
46380 int error;
46381 };
46382 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
46383 buf->error = -EINVAL; /* only used if we fail.. */
46384 if (reclen > buf->count)
46385 return -EINVAL;
46386 +
46387 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46388 + return 0;
46389 +
46390 dirent = buf->previous;
46391
46392 if (dirent) {
46393 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46394 buf.previous = NULL;
46395 buf.count = count;
46396 buf.error = 0;
46397 + buf.file = f.file;
46398
46399 error = vfs_readdir(f.file, compat_filldir64, &buf);
46400 if (error >= 0)
46401 error = buf.error;
46402 lastdirent = buf.previous;
46403 if (lastdirent) {
46404 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
46405 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46406 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46407 error = -EFAULT;
46408 else
46409 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46410 index a81147e..20bf2b5 100644
46411 --- a/fs/compat_binfmt_elf.c
46412 +++ b/fs/compat_binfmt_elf.c
46413 @@ -30,11 +30,13 @@
46414 #undef elf_phdr
46415 #undef elf_shdr
46416 #undef elf_note
46417 +#undef elf_dyn
46418 #undef elf_addr_t
46419 #define elfhdr elf32_hdr
46420 #define elf_phdr elf32_phdr
46421 #define elf_shdr elf32_shdr
46422 #define elf_note elf32_note
46423 +#define elf_dyn Elf32_Dyn
46424 #define elf_addr_t Elf32_Addr
46425
46426 /*
46427 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46428 index 4c6285f..b7a2411 100644
46429 --- a/fs/compat_ioctl.c
46430 +++ b/fs/compat_ioctl.c
46431 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46432 return -EFAULT;
46433 if (__get_user(udata, &ss32->iomem_base))
46434 return -EFAULT;
46435 - ss.iomem_base = compat_ptr(udata);
46436 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46437 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46438 __get_user(ss.port_high, &ss32->port_high))
46439 return -EFAULT;
46440 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46441 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46442 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46443 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46444 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46445 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46446 return -EFAULT;
46447
46448 return ioctl_preallocate(file, p);
46449 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46450 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46451 {
46452 unsigned int a, b;
46453 - a = *(unsigned int *)p;
46454 - b = *(unsigned int *)q;
46455 + a = *(const unsigned int *)p;
46456 + b = *(const unsigned int *)q;
46457 if (a > b)
46458 return 1;
46459 if (a < b)
46460 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46461 index 7414ae2..d98ad6d 100644
46462 --- a/fs/configfs/dir.c
46463 +++ b/fs/configfs/dir.c
46464 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46465 }
46466 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46467 struct configfs_dirent *next;
46468 - const char * name;
46469 + const unsigned char * name;
46470 + char d_name[sizeof(next->s_dentry->d_iname)];
46471 int len;
46472 struct inode *inode = NULL;
46473
46474 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46475 continue;
46476
46477 name = configfs_get_name(next);
46478 - len = strlen(name);
46479 + if (next->s_dentry && name == next->s_dentry->d_iname) {
46480 + len = next->s_dentry->d_name.len;
46481 + memcpy(d_name, name, len);
46482 + name = d_name;
46483 + } else
46484 + len = strlen(name);
46485
46486 /*
46487 * We'll have a dentry and an inode for
46488 diff --git a/fs/coredump.c b/fs/coredump.c
46489 index ce47379..68c8e43 100644
46490 --- a/fs/coredump.c
46491 +++ b/fs/coredump.c
46492 @@ -52,7 +52,7 @@ struct core_name {
46493 char *corename;
46494 int used, size;
46495 };
46496 -static atomic_t call_count = ATOMIC_INIT(1);
46497 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46498
46499 /* The maximal length of core_pattern is also specified in sysctl.c */
46500
46501 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46502 {
46503 char *old_corename = cn->corename;
46504
46505 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46506 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46507 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46508
46509 if (!cn->corename) {
46510 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46511 int pid_in_pattern = 0;
46512 int err = 0;
46513
46514 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46515 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46516 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46517 cn->used = 0;
46518
46519 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46520 pipe = file->f_path.dentry->d_inode->i_pipe;
46521
46522 pipe_lock(pipe);
46523 - pipe->readers++;
46524 - pipe->writers--;
46525 + atomic_inc(&pipe->readers);
46526 + atomic_dec(&pipe->writers);
46527
46528 - while ((pipe->readers > 1) && (!signal_pending(current))) {
46529 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46530 wake_up_interruptible_sync(&pipe->wait);
46531 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46532 pipe_wait(pipe);
46533 }
46534
46535 - pipe->readers--;
46536 - pipe->writers++;
46537 + atomic_dec(&pipe->readers);
46538 + atomic_inc(&pipe->writers);
46539 pipe_unlock(pipe);
46540
46541 }
46542 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46543 int ispipe;
46544 struct files_struct *displaced;
46545 bool need_nonrelative = false;
46546 - static atomic_t core_dump_count = ATOMIC_INIT(0);
46547 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46548 + long signr = siginfo->si_signo;
46549 struct coredump_params cprm = {
46550 .siginfo = siginfo,
46551 .regs = regs,
46552 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46553 .mm_flags = mm->flags,
46554 };
46555
46556 - audit_core_dumps(siginfo->si_signo);
46557 + audit_core_dumps(signr);
46558 +
46559 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46560 + gr_handle_brute_attach(cprm.mm_flags);
46561
46562 binfmt = mm->binfmt;
46563 if (!binfmt || !binfmt->core_dump)
46564 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46565 need_nonrelative = true;
46566 }
46567
46568 - retval = coredump_wait(siginfo->si_signo, &core_state);
46569 + retval = coredump_wait(signr, &core_state);
46570 if (retval < 0)
46571 goto fail_creds;
46572
46573 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46574 }
46575 cprm.limit = RLIM_INFINITY;
46576
46577 - dump_count = atomic_inc_return(&core_dump_count);
46578 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46579 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46580 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46581 task_tgid_vnr(current), current->comm);
46582 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46583 } else {
46584 struct inode *inode;
46585
46586 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46587 +
46588 if (cprm.limit < binfmt->min_coredump)
46589 goto fail_unlock;
46590
46591 @@ -640,7 +646,7 @@ close_fail:
46592 filp_close(cprm.file, NULL);
46593 fail_dropcount:
46594 if (ispipe)
46595 - atomic_dec(&core_dump_count);
46596 + atomic_dec_unchecked(&core_dump_count);
46597 fail_unlock:
46598 kfree(cn.corename);
46599 fail_corename:
46600 @@ -659,7 +665,7 @@ fail:
46601 */
46602 int dump_write(struct file *file, const void *addr, int nr)
46603 {
46604 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46605 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46606 }
46607 EXPORT_SYMBOL(dump_write);
46608
46609 diff --git a/fs/dcache.c b/fs/dcache.c
46610 index 0d0adb6..f4646e9 100644
46611 --- a/fs/dcache.c
46612 +++ b/fs/dcache.c
46613 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46614 mempages -= reserve;
46615
46616 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46617 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46618 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46619
46620 dcache_init();
46621 inode_init();
46622 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46623 index b607d92..41fda09 100644
46624 --- a/fs/debugfs/inode.c
46625 +++ b/fs/debugfs/inode.c
46626 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46627 */
46628 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46629 {
46630 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46631 + return __create_file(name, S_IFDIR | S_IRWXU,
46632 +#else
46633 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46634 +#endif
46635 parent, NULL, NULL);
46636 }
46637 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46638 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46639 index cc7709e..7e7211f 100644
46640 --- a/fs/ecryptfs/inode.c
46641 +++ b/fs/ecryptfs/inode.c
46642 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46643 old_fs = get_fs();
46644 set_fs(get_ds());
46645 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46646 - (char __user *)lower_buf,
46647 + (char __force_user *)lower_buf,
46648 PATH_MAX);
46649 set_fs(old_fs);
46650 if (rc < 0)
46651 @@ -706,7 +706,7 @@ out:
46652 static void
46653 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46654 {
46655 - char *buf = nd_get_link(nd);
46656 + const char *buf = nd_get_link(nd);
46657 if (!IS_ERR(buf)) {
46658 /* Free the char* */
46659 kfree(buf);
46660 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46661 index 412e6ed..4292d22 100644
46662 --- a/fs/ecryptfs/miscdev.c
46663 +++ b/fs/ecryptfs/miscdev.c
46664 @@ -315,7 +315,7 @@ check_list:
46665 goto out_unlock_msg_ctx;
46666 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46667 if (msg_ctx->msg) {
46668 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
46669 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46670 goto out_unlock_msg_ctx;
46671 i += packet_length_size;
46672 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46673 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46674 index b2a34a1..162fa69 100644
46675 --- a/fs/ecryptfs/read_write.c
46676 +++ b/fs/ecryptfs/read_write.c
46677 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46678 return -EIO;
46679 fs_save = get_fs();
46680 set_fs(get_ds());
46681 - rc = vfs_write(lower_file, data, size, &offset);
46682 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46683 set_fs(fs_save);
46684 mark_inode_dirty_sync(ecryptfs_inode);
46685 return rc;
46686 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46687 return -EIO;
46688 fs_save = get_fs();
46689 set_fs(get_ds());
46690 - rc = vfs_read(lower_file, data, size, &offset);
46691 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46692 set_fs(fs_save);
46693 return rc;
46694 }
46695 diff --git a/fs/exec.c b/fs/exec.c
46696 index c6e6de4..45e71ad 100644
46697 --- a/fs/exec.c
46698 +++ b/fs/exec.c
46699 @@ -55,6 +55,17 @@
46700 #include <linux/pipe_fs_i.h>
46701 #include <linux/oom.h>
46702 #include <linux/compat.h>
46703 +#include <linux/random.h>
46704 +#include <linux/seq_file.h>
46705 +#include <linux/coredump.h>
46706 +#include <linux/mman.h>
46707 +
46708 +#ifdef CONFIG_PAX_REFCOUNT
46709 +#include <linux/kallsyms.h>
46710 +#include <linux/kdebug.h>
46711 +#endif
46712 +
46713 +#include <trace/events/fs.h>
46714
46715 #include <asm/uaccess.h>
46716 #include <asm/mmu_context.h>
46717 @@ -66,6 +77,18 @@
46718
46719 #include <trace/events/sched.h>
46720
46721 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46722 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46723 +{
46724 + 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");
46725 +}
46726 +#endif
46727 +
46728 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46729 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46730 +EXPORT_SYMBOL(pax_set_initial_flags_func);
46731 +#endif
46732 +
46733 int suid_dumpable = 0;
46734
46735 static LIST_HEAD(formats);
46736 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46737 int write)
46738 {
46739 struct page *page;
46740 - int ret;
46741
46742 -#ifdef CONFIG_STACK_GROWSUP
46743 - if (write) {
46744 - ret = expand_downwards(bprm->vma, pos);
46745 - if (ret < 0)
46746 - return NULL;
46747 - }
46748 -#endif
46749 - ret = get_user_pages(current, bprm->mm, pos,
46750 - 1, write, 1, &page, NULL);
46751 - if (ret <= 0)
46752 + if (0 > expand_downwards(bprm->vma, pos))
46753 + return NULL;
46754 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46755 return NULL;
46756
46757 if (write) {
46758 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46759 if (size <= ARG_MAX)
46760 return page;
46761
46762 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46763 + // only allow 512KB for argv+env on suid/sgid binaries
46764 + // to prevent easy ASLR exhaustion
46765 + if (((bprm->cred->euid != current_euid()) ||
46766 + (bprm->cred->egid != current_egid())) &&
46767 + (size > (512 * 1024))) {
46768 + put_page(page);
46769 + return NULL;
46770 + }
46771 +#endif
46772 +
46773 /*
46774 * Limit to 1/4-th the stack size for the argv+env strings.
46775 * This ensures that:
46776 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46777 vma->vm_end = STACK_TOP_MAX;
46778 vma->vm_start = vma->vm_end - PAGE_SIZE;
46779 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46780 +
46781 +#ifdef CONFIG_PAX_SEGMEXEC
46782 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46783 +#endif
46784 +
46785 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46786 INIT_LIST_HEAD(&vma->anon_vma_chain);
46787
46788 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46789 mm->stack_vm = mm->total_vm = 1;
46790 up_write(&mm->mmap_sem);
46791 bprm->p = vma->vm_end - sizeof(void *);
46792 +
46793 +#ifdef CONFIG_PAX_RANDUSTACK
46794 + if (randomize_va_space)
46795 + bprm->p ^= random32() & ~PAGE_MASK;
46796 +#endif
46797 +
46798 return 0;
46799 err:
46800 up_write(&mm->mmap_sem);
46801 @@ -384,19 +421,7 @@ err:
46802 return err;
46803 }
46804
46805 -struct user_arg_ptr {
46806 -#ifdef CONFIG_COMPAT
46807 - bool is_compat;
46808 -#endif
46809 - union {
46810 - const char __user *const __user *native;
46811 -#ifdef CONFIG_COMPAT
46812 - const compat_uptr_t __user *compat;
46813 -#endif
46814 - } ptr;
46815 -};
46816 -
46817 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46818 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46819 {
46820 const char __user *native;
46821
46822 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46823 compat_uptr_t compat;
46824
46825 if (get_user(compat, argv.ptr.compat + nr))
46826 - return ERR_PTR(-EFAULT);
46827 + return (const char __force_user *)ERR_PTR(-EFAULT);
46828
46829 return compat_ptr(compat);
46830 }
46831 #endif
46832
46833 if (get_user(native, argv.ptr.native + nr))
46834 - return ERR_PTR(-EFAULT);
46835 + return (const char __force_user *)ERR_PTR(-EFAULT);
46836
46837 return native;
46838 }
46839 @@ -431,11 +456,12 @@ static int count(struct user_arg_ptr argv, int max)
46840 if (!p)
46841 break;
46842
46843 - if (IS_ERR(p))
46844 + if (IS_ERR((const char __force_kernel *)p))
46845 return -EFAULT;
46846
46847 - if (i++ >= max)
46848 + if (i >= max)
46849 return -E2BIG;
46850 + ++i;
46851
46852 if (fatal_signal_pending(current))
46853 return -ERESTARTNOHAND;
46854 @@ -465,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46855
46856 ret = -EFAULT;
46857 str = get_user_arg_ptr(argv, argc);
46858 - if (IS_ERR(str))
46859 + if (IS_ERR((const char __force_kernel *)str))
46860 goto out;
46861
46862 len = strnlen_user(str, MAX_ARG_STRLEN);
46863 @@ -547,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46864 int r;
46865 mm_segment_t oldfs = get_fs();
46866 struct user_arg_ptr argv = {
46867 - .ptr.native = (const char __user *const __user *)__argv,
46868 + .ptr.native = (const char __force_user *const __force_user *)__argv,
46869 };
46870
46871 set_fs(KERNEL_DS);
46872 @@ -582,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46873 unsigned long new_end = old_end - shift;
46874 struct mmu_gather tlb;
46875
46876 - BUG_ON(new_start > new_end);
46877 + if (new_start >= new_end || new_start < mmap_min_addr)
46878 + return -ENOMEM;
46879
46880 /*
46881 * ensure there are no vmas between where we want to go
46882 @@ -591,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46883 if (vma != find_vma(mm, new_start))
46884 return -EFAULT;
46885
46886 +#ifdef CONFIG_PAX_SEGMEXEC
46887 + BUG_ON(pax_find_mirror_vma(vma));
46888 +#endif
46889 +
46890 /*
46891 * cover the whole range: [new_start, old_end)
46892 */
46893 @@ -671,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46894 stack_top = arch_align_stack(stack_top);
46895 stack_top = PAGE_ALIGN(stack_top);
46896
46897 - if (unlikely(stack_top < mmap_min_addr) ||
46898 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46899 - return -ENOMEM;
46900 -
46901 stack_shift = vma->vm_end - stack_top;
46902
46903 bprm->p -= stack_shift;
46904 @@ -686,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46905 bprm->exec -= stack_shift;
46906
46907 down_write(&mm->mmap_sem);
46908 +
46909 + /* Move stack pages down in memory. */
46910 + if (stack_shift) {
46911 + ret = shift_arg_pages(vma, stack_shift);
46912 + if (ret)
46913 + goto out_unlock;
46914 + }
46915 +
46916 vm_flags = VM_STACK_FLAGS;
46917
46918 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46919 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46920 + vm_flags &= ~VM_EXEC;
46921 +
46922 +#ifdef CONFIG_PAX_MPROTECT
46923 + if (mm->pax_flags & MF_PAX_MPROTECT)
46924 + vm_flags &= ~VM_MAYEXEC;
46925 +#endif
46926 +
46927 + }
46928 +#endif
46929 +
46930 /*
46931 * Adjust stack execute permissions; explicitly enable for
46932 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46933 @@ -706,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46934 goto out_unlock;
46935 BUG_ON(prev != vma);
46936
46937 - /* Move stack pages down in memory. */
46938 - if (stack_shift) {
46939 - ret = shift_arg_pages(vma, stack_shift);
46940 - if (ret)
46941 - goto out_unlock;
46942 - }
46943 -
46944 /* mprotect_fixup is overkill to remove the temporary stack flags */
46945 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
46946
46947 @@ -736,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
46948 #endif
46949 current->mm->start_stack = bprm->p;
46950 ret = expand_stack(vma, stack_base);
46951 +
46952 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
46953 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
46954 + unsigned long size, flags, vm_flags;
46955 +
46956 + size = STACK_TOP - vma->vm_end;
46957 + flags = MAP_FIXED | MAP_PRIVATE;
46958 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
46959 +
46960 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
46961 +
46962 +#ifdef CONFIG_X86
46963 + if (!ret) {
46964 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
46965 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
46966 + }
46967 +#endif
46968 +
46969 + }
46970 +#endif
46971 +
46972 if (ret)
46973 ret = -EFAULT;
46974
46975 @@ -771,6 +832,8 @@ struct file *open_exec(const char *name)
46976
46977 fsnotify_open(file);
46978
46979 + trace_open_exec(name);
46980 +
46981 err = deny_write_access(file);
46982 if (err)
46983 goto exit;
46984 @@ -794,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
46985 old_fs = get_fs();
46986 set_fs(get_ds());
46987 /* The cast to a user pointer is valid due to the set_fs() */
46988 - result = vfs_read(file, (void __user *)addr, count, &pos);
46989 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
46990 set_fs(old_fs);
46991 return result;
46992 }
46993 @@ -1246,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
46994 }
46995 rcu_read_unlock();
46996
46997 - if (p->fs->users > n_fs) {
46998 + if (atomic_read(&p->fs->users) > n_fs) {
46999 bprm->unsafe |= LSM_UNSAFE_SHARE;
47000 } else {
47001 res = -EAGAIN;
47002 @@ -1449,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
47003
47004 EXPORT_SYMBOL(search_binary_handler);
47005
47006 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47007 +static DEFINE_PER_CPU(u64, exec_counter);
47008 +static int __init init_exec_counters(void)
47009 +{
47010 + unsigned int cpu;
47011 +
47012 + for_each_possible_cpu(cpu) {
47013 + per_cpu(exec_counter, cpu) = (u64)cpu;
47014 + }
47015 +
47016 + return 0;
47017 +}
47018 +early_initcall(init_exec_counters);
47019 +static inline void increment_exec_counter(void)
47020 +{
47021 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
47022 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47023 +}
47024 +#else
47025 +static inline void increment_exec_counter(void) {}
47026 +#endif
47027 +
47028 /*
47029 * sys_execve() executes a new program.
47030 */
47031 @@ -1457,6 +1542,11 @@ static int do_execve_common(const char *filename,
47032 struct user_arg_ptr envp,
47033 struct pt_regs *regs)
47034 {
47035 +#ifdef CONFIG_GRKERNSEC
47036 + struct file *old_exec_file;
47037 + struct acl_subject_label *old_acl;
47038 + struct rlimit old_rlim[RLIM_NLIMITS];
47039 +#endif
47040 struct linux_binprm *bprm;
47041 struct file *file;
47042 struct files_struct *displaced;
47043 @@ -1464,6 +1554,8 @@ static int do_execve_common(const char *filename,
47044 int retval;
47045 const struct cred *cred = current_cred();
47046
47047 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47048 +
47049 /*
47050 * We move the actual failure in case of RLIMIT_NPROC excess from
47051 * set*uid() to execve() because too many poorly written programs
47052 @@ -1504,12 +1596,27 @@ static int do_execve_common(const char *filename,
47053 if (IS_ERR(file))
47054 goto out_unmark;
47055
47056 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
47057 + retval = -EPERM;
47058 + goto out_file;
47059 + }
47060 +
47061 sched_exec();
47062
47063 bprm->file = file;
47064 bprm->filename = filename;
47065 bprm->interp = filename;
47066
47067 + if (gr_process_user_ban()) {
47068 + retval = -EPERM;
47069 + goto out_file;
47070 + }
47071 +
47072 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47073 + retval = -EACCES;
47074 + goto out_file;
47075 + }
47076 +
47077 retval = bprm_mm_init(bprm);
47078 if (retval)
47079 goto out_file;
47080 @@ -1526,24 +1633,65 @@ static int do_execve_common(const char *filename,
47081 if (retval < 0)
47082 goto out;
47083
47084 +#ifdef CONFIG_GRKERNSEC
47085 + old_acl = current->acl;
47086 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47087 + old_exec_file = current->exec_file;
47088 + get_file(file);
47089 + current->exec_file = file;
47090 +#endif
47091 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47092 + /* limit suid stack to 8MB
47093 + we saved the old limits above and will restore them if this exec fails
47094 + */
47095 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47096 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47097 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47098 +#endif
47099 +
47100 + if (!gr_tpe_allow(file)) {
47101 + retval = -EACCES;
47102 + goto out_fail;
47103 + }
47104 +
47105 + if (gr_check_crash_exec(file)) {
47106 + retval = -EACCES;
47107 + goto out_fail;
47108 + }
47109 +
47110 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47111 + bprm->unsafe);
47112 + if (retval < 0)
47113 + goto out_fail;
47114 +
47115 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47116 if (retval < 0)
47117 - goto out;
47118 + goto out_fail;
47119
47120 bprm->exec = bprm->p;
47121 retval = copy_strings(bprm->envc, envp, bprm);
47122 if (retval < 0)
47123 - goto out;
47124 + goto out_fail;
47125
47126 retval = copy_strings(bprm->argc, argv, bprm);
47127 if (retval < 0)
47128 - goto out;
47129 + goto out_fail;
47130 +
47131 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47132 +
47133 + gr_handle_exec_args(bprm, argv);
47134
47135 retval = search_binary_handler(bprm,regs);
47136 if (retval < 0)
47137 - goto out;
47138 + goto out_fail;
47139 +#ifdef CONFIG_GRKERNSEC
47140 + if (old_exec_file)
47141 + fput(old_exec_file);
47142 +#endif
47143
47144 /* execve succeeded */
47145 +
47146 + increment_exec_counter();
47147 current->fs->in_exec = 0;
47148 current->in_execve = 0;
47149 acct_update_integrals(current);
47150 @@ -1552,6 +1700,14 @@ static int do_execve_common(const char *filename,
47151 put_files_struct(displaced);
47152 return retval;
47153
47154 +out_fail:
47155 +#ifdef CONFIG_GRKERNSEC
47156 + current->acl = old_acl;
47157 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47158 + fput(current->exec_file);
47159 + current->exec_file = old_exec_file;
47160 +#endif
47161 +
47162 out:
47163 if (bprm->mm) {
47164 acct_arg_size(bprm, 0);
47165 @@ -1727,3 +1883,253 @@ int kernel_execve(const char *filename,
47166 ret_from_kernel_execve(p);
47167 }
47168 #endif
47169 +
47170 +int pax_check_flags(unsigned long *flags)
47171 +{
47172 + int retval = 0;
47173 +
47174 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47175 + if (*flags & MF_PAX_SEGMEXEC)
47176 + {
47177 + *flags &= ~MF_PAX_SEGMEXEC;
47178 + retval = -EINVAL;
47179 + }
47180 +#endif
47181 +
47182 + if ((*flags & MF_PAX_PAGEEXEC)
47183 +
47184 +#ifdef CONFIG_PAX_PAGEEXEC
47185 + && (*flags & MF_PAX_SEGMEXEC)
47186 +#endif
47187 +
47188 + )
47189 + {
47190 + *flags &= ~MF_PAX_PAGEEXEC;
47191 + retval = -EINVAL;
47192 + }
47193 +
47194 + if ((*flags & MF_PAX_MPROTECT)
47195 +
47196 +#ifdef CONFIG_PAX_MPROTECT
47197 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47198 +#endif
47199 +
47200 + )
47201 + {
47202 + *flags &= ~MF_PAX_MPROTECT;
47203 + retval = -EINVAL;
47204 + }
47205 +
47206 + if ((*flags & MF_PAX_EMUTRAMP)
47207 +
47208 +#ifdef CONFIG_PAX_EMUTRAMP
47209 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47210 +#endif
47211 +
47212 + )
47213 + {
47214 + *flags &= ~MF_PAX_EMUTRAMP;
47215 + retval = -EINVAL;
47216 + }
47217 +
47218 + return retval;
47219 +}
47220 +
47221 +EXPORT_SYMBOL(pax_check_flags);
47222 +
47223 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47224 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47225 +{
47226 + struct task_struct *tsk = current;
47227 + struct mm_struct *mm = current->mm;
47228 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47229 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47230 + char *path_exec = NULL;
47231 + char *path_fault = NULL;
47232 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
47233 + siginfo_t info = { };
47234 +
47235 + if (buffer_exec && buffer_fault) {
47236 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47237 +
47238 + down_read(&mm->mmap_sem);
47239 + vma = mm->mmap;
47240 + while (vma && (!vma_exec || !vma_fault)) {
47241 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47242 + vma_exec = vma;
47243 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47244 + vma_fault = vma;
47245 + vma = vma->vm_next;
47246 + }
47247 + if (vma_exec) {
47248 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47249 + if (IS_ERR(path_exec))
47250 + path_exec = "<path too long>";
47251 + else {
47252 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47253 + if (path_exec) {
47254 + *path_exec = 0;
47255 + path_exec = buffer_exec;
47256 + } else
47257 + path_exec = "<path too long>";
47258 + }
47259 + }
47260 + if (vma_fault) {
47261 + start = vma_fault->vm_start;
47262 + end = vma_fault->vm_end;
47263 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47264 + if (vma_fault->vm_file) {
47265 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47266 + if (IS_ERR(path_fault))
47267 + path_fault = "<path too long>";
47268 + else {
47269 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
47270 + if (path_fault) {
47271 + *path_fault = 0;
47272 + path_fault = buffer_fault;
47273 + } else
47274 + path_fault = "<path too long>";
47275 + }
47276 + } else
47277 + path_fault = "<anonymous mapping>";
47278 + }
47279 + up_read(&mm->mmap_sem);
47280 + }
47281 + if (tsk->signal->curr_ip)
47282 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
47283 + else
47284 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
47285 + 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),
47286 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
47287 + free_page((unsigned long)buffer_exec);
47288 + free_page((unsigned long)buffer_fault);
47289 + pax_report_insns(regs, pc, sp);
47290 + info.si_signo = SIGKILL;
47291 + info.si_errno = 0;
47292 + info.si_code = SI_KERNEL;
47293 + info.si_pid = 0;
47294 + info.si_uid = 0;
47295 + do_coredump(&info, regs);
47296 +}
47297 +#endif
47298 +
47299 +#ifdef CONFIG_PAX_REFCOUNT
47300 +void pax_report_refcount_overflow(struct pt_regs *regs)
47301 +{
47302 + if (current->signal->curr_ip)
47303 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47304 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
47305 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47306 + else
47307 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
47308 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47309 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
47310 + show_regs(regs);
47311 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
47312 +}
47313 +#endif
47314 +
47315 +#ifdef CONFIG_PAX_USERCOPY
47316 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
47317 +static noinline int check_stack_object(const void *obj, unsigned long len)
47318 +{
47319 + const void * const stack = task_stack_page(current);
47320 + const void * const stackend = stack + THREAD_SIZE;
47321 +
47322 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47323 + const void *frame = NULL;
47324 + const void *oldframe;
47325 +#endif
47326 +
47327 + if (obj + len < obj)
47328 + return -1;
47329 +
47330 + if (obj + len <= stack || stackend <= obj)
47331 + return 0;
47332 +
47333 + if (obj < stack || stackend < obj + len)
47334 + return -1;
47335 +
47336 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47337 + oldframe = __builtin_frame_address(1);
47338 + if (oldframe)
47339 + frame = __builtin_frame_address(2);
47340 + /*
47341 + low ----------------------------------------------> high
47342 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
47343 + ^----------------^
47344 + allow copies only within here
47345 + */
47346 + while (stack <= frame && frame < stackend) {
47347 + /* if obj + len extends past the last frame, this
47348 + check won't pass and the next frame will be 0,
47349 + causing us to bail out and correctly report
47350 + the copy as invalid
47351 + */
47352 + if (obj + len <= frame)
47353 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
47354 + oldframe = frame;
47355 + frame = *(const void * const *)frame;
47356 + }
47357 + return -1;
47358 +#else
47359 + return 1;
47360 +#endif
47361 +}
47362 +
47363 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
47364 +{
47365 + if (current->signal->curr_ip)
47366 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47367 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47368 + else
47369 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47370 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47371 + dump_stack();
47372 + gr_handle_kernel_exploit();
47373 + do_group_exit(SIGKILL);
47374 +}
47375 +#endif
47376 +
47377 +void __check_object_size(const void *ptr, unsigned long n, bool to)
47378 +{
47379 +
47380 +#ifdef CONFIG_PAX_USERCOPY
47381 + const char *type;
47382 +
47383 + if (!n)
47384 + return;
47385 +
47386 + type = check_heap_object(ptr, n);
47387 + if (!type) {
47388 + if (check_stack_object(ptr, n) != -1)
47389 + return;
47390 + type = "<process stack>";
47391 + }
47392 +
47393 + pax_report_usercopy(ptr, n, to, type);
47394 +#endif
47395 +
47396 +}
47397 +EXPORT_SYMBOL(__check_object_size);
47398 +
47399 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47400 +void pax_track_stack(void)
47401 +{
47402 + unsigned long sp = (unsigned long)&sp;
47403 + if (sp < current_thread_info()->lowest_stack &&
47404 + sp > (unsigned long)task_stack_page(current))
47405 + current_thread_info()->lowest_stack = sp;
47406 +}
47407 +EXPORT_SYMBOL(pax_track_stack);
47408 +#endif
47409 +
47410 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
47411 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47412 +{
47413 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47414 + dump_stack();
47415 + do_group_exit(SIGKILL);
47416 +}
47417 +EXPORT_SYMBOL(report_size_overflow);
47418 +#endif
47419 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47420 index 2616d0e..2ffdec9 100644
47421 --- a/fs/ext2/balloc.c
47422 +++ b/fs/ext2/balloc.c
47423 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47424
47425 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47426 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47427 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47428 + if (free_blocks < root_blocks + 1 &&
47429 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47430 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47431 - !in_group_p (sbi->s_resgid))) {
47432 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47433 return 0;
47434 }
47435 return 1;
47436 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47437 index 22548f5..41521d8 100644
47438 --- a/fs/ext3/balloc.c
47439 +++ b/fs/ext3/balloc.c
47440 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47441
47442 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47443 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47444 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47445 + if (free_blocks < root_blocks + 1 &&
47446 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47447 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47448 - !in_group_p (sbi->s_resgid))) {
47449 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47450 return 0;
47451 }
47452 return 1;
47453 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47454 index cf18217..8f6b9c3 100644
47455 --- a/fs/ext4/balloc.c
47456 +++ b/fs/ext4/balloc.c
47457 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47458 /* Hm, nope. Are (enough) root reserved clusters available? */
47459 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47460 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47461 - capable(CAP_SYS_RESOURCE) ||
47462 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47463 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47464 + capable_nolog(CAP_SYS_RESOURCE)) {
47465
47466 if (free_clusters >= (nclusters + dirty_clusters))
47467 return 1;
47468 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47469 index 3c20de1..6ff2460 100644
47470 --- a/fs/ext4/ext4.h
47471 +++ b/fs/ext4/ext4.h
47472 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47473 unsigned long s_mb_last_start;
47474
47475 /* stats for buddy allocator */
47476 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47477 - atomic_t s_bal_success; /* we found long enough chunks */
47478 - atomic_t s_bal_allocated; /* in blocks */
47479 - atomic_t s_bal_ex_scanned; /* total extents scanned */
47480 - atomic_t s_bal_goals; /* goal hits */
47481 - atomic_t s_bal_breaks; /* too long searches */
47482 - atomic_t s_bal_2orders; /* 2^order hits */
47483 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47484 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47485 + atomic_unchecked_t s_bal_allocated; /* in blocks */
47486 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47487 + atomic_unchecked_t s_bal_goals; /* goal hits */
47488 + atomic_unchecked_t s_bal_breaks; /* too long searches */
47489 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47490 spinlock_t s_bal_lock;
47491 unsigned long s_mb_buddies_generated;
47492 unsigned long long s_mb_generation_time;
47493 - atomic_t s_mb_lost_chunks;
47494 - atomic_t s_mb_preallocated;
47495 - atomic_t s_mb_discarded;
47496 + atomic_unchecked_t s_mb_lost_chunks;
47497 + atomic_unchecked_t s_mb_preallocated;
47498 + atomic_unchecked_t s_mb_discarded;
47499 atomic_t s_lock_busy;
47500
47501 /* locality groups */
47502 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47503 index 526e553..3f2de85 100644
47504 --- a/fs/ext4/mballoc.c
47505 +++ b/fs/ext4/mballoc.c
47506 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47507 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47508
47509 if (EXT4_SB(sb)->s_mb_stats)
47510 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47511 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47512
47513 break;
47514 }
47515 @@ -2044,7 +2044,7 @@ repeat:
47516 ac->ac_status = AC_STATUS_CONTINUE;
47517 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47518 cr = 3;
47519 - atomic_inc(&sbi->s_mb_lost_chunks);
47520 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47521 goto repeat;
47522 }
47523 }
47524 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47525 if (sbi->s_mb_stats) {
47526 ext4_msg(sb, KERN_INFO,
47527 "mballoc: %u blocks %u reqs (%u success)",
47528 - atomic_read(&sbi->s_bal_allocated),
47529 - atomic_read(&sbi->s_bal_reqs),
47530 - atomic_read(&sbi->s_bal_success));
47531 + atomic_read_unchecked(&sbi->s_bal_allocated),
47532 + atomic_read_unchecked(&sbi->s_bal_reqs),
47533 + atomic_read_unchecked(&sbi->s_bal_success));
47534 ext4_msg(sb, KERN_INFO,
47535 "mballoc: %u extents scanned, %u goal hits, "
47536 "%u 2^N hits, %u breaks, %u lost",
47537 - atomic_read(&sbi->s_bal_ex_scanned),
47538 - atomic_read(&sbi->s_bal_goals),
47539 - atomic_read(&sbi->s_bal_2orders),
47540 - atomic_read(&sbi->s_bal_breaks),
47541 - atomic_read(&sbi->s_mb_lost_chunks));
47542 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47543 + atomic_read_unchecked(&sbi->s_bal_goals),
47544 + atomic_read_unchecked(&sbi->s_bal_2orders),
47545 + atomic_read_unchecked(&sbi->s_bal_breaks),
47546 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47547 ext4_msg(sb, KERN_INFO,
47548 "mballoc: %lu generated and it took %Lu",
47549 sbi->s_mb_buddies_generated,
47550 sbi->s_mb_generation_time);
47551 ext4_msg(sb, KERN_INFO,
47552 "mballoc: %u preallocated, %u discarded",
47553 - atomic_read(&sbi->s_mb_preallocated),
47554 - atomic_read(&sbi->s_mb_discarded));
47555 + atomic_read_unchecked(&sbi->s_mb_preallocated),
47556 + atomic_read_unchecked(&sbi->s_mb_discarded));
47557 }
47558
47559 free_percpu(sbi->s_locality_groups);
47560 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47561 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47562
47563 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47564 - atomic_inc(&sbi->s_bal_reqs);
47565 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47566 + atomic_inc_unchecked(&sbi->s_bal_reqs);
47567 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47568 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47569 - atomic_inc(&sbi->s_bal_success);
47570 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47571 + atomic_inc_unchecked(&sbi->s_bal_success);
47572 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47573 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47574 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47575 - atomic_inc(&sbi->s_bal_goals);
47576 + atomic_inc_unchecked(&sbi->s_bal_goals);
47577 if (ac->ac_found > sbi->s_mb_max_to_scan)
47578 - atomic_inc(&sbi->s_bal_breaks);
47579 + atomic_inc_unchecked(&sbi->s_bal_breaks);
47580 }
47581
47582 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47583 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47584 trace_ext4_mb_new_inode_pa(ac, pa);
47585
47586 ext4_mb_use_inode_pa(ac, pa);
47587 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47588 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47589
47590 ei = EXT4_I(ac->ac_inode);
47591 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47592 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47593 trace_ext4_mb_new_group_pa(ac, pa);
47594
47595 ext4_mb_use_group_pa(ac, pa);
47596 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47597 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47598
47599 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47600 lg = ac->ac_lg;
47601 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47602 * from the bitmap and continue.
47603 */
47604 }
47605 - atomic_add(free, &sbi->s_mb_discarded);
47606 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
47607
47608 return err;
47609 }
47610 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47611 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47612 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47613 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47614 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47615 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47616 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47617
47618 return 0;
47619 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47620 index d59b351..775f8c8 100644
47621 --- a/fs/ext4/super.c
47622 +++ b/fs/ext4/super.c
47623 @@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47624 ext4_fsblk_t overhead = 0;
47625 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47626
47627 - memset(buf, 0, PAGE_SIZE);
47628 if (!buf)
47629 return -ENOMEM;
47630
47631 diff --git a/fs/fcntl.c b/fs/fcntl.c
47632 index 71a600a..20d87b1 100644
47633 --- a/fs/fcntl.c
47634 +++ b/fs/fcntl.c
47635 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47636 if (err)
47637 return err;
47638
47639 + if (gr_handle_chroot_fowner(pid, type))
47640 + return -ENOENT;
47641 + if (gr_check_protected_task_fowner(pid, type))
47642 + return -EACCES;
47643 +
47644 f_modown(filp, pid, type, force);
47645 return 0;
47646 }
47647 diff --git a/fs/fhandle.c b/fs/fhandle.c
47648 index f775bfd..629bd4c 100644
47649 --- a/fs/fhandle.c
47650 +++ b/fs/fhandle.c
47651 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
47652 } else
47653 retval = 0;
47654 /* copy the mount id */
47655 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
47656 - sizeof(*mnt_id)) ||
47657 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
47658 copy_to_user(ufh, handle,
47659 sizeof(struct file_handle) + handle_bytes))
47660 retval = -EFAULT;
47661 diff --git a/fs/fifo.c b/fs/fifo.c
47662 index cf6f434..3d7942c 100644
47663 --- a/fs/fifo.c
47664 +++ b/fs/fifo.c
47665 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47666 */
47667 filp->f_op = &read_pipefifo_fops;
47668 pipe->r_counter++;
47669 - if (pipe->readers++ == 0)
47670 + if (atomic_inc_return(&pipe->readers) == 1)
47671 wake_up_partner(inode);
47672
47673 - if (!pipe->writers) {
47674 + if (!atomic_read(&pipe->writers)) {
47675 if ((filp->f_flags & O_NONBLOCK)) {
47676 /* suppress POLLHUP until we have
47677 * seen a writer */
47678 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47679 * errno=ENXIO when there is no process reading the FIFO.
47680 */
47681 ret = -ENXIO;
47682 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47683 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47684 goto err;
47685
47686 filp->f_op = &write_pipefifo_fops;
47687 pipe->w_counter++;
47688 - if (!pipe->writers++)
47689 + if (atomic_inc_return(&pipe->writers) == 1)
47690 wake_up_partner(inode);
47691
47692 - if (!pipe->readers) {
47693 + if (!atomic_read(&pipe->readers)) {
47694 if (wait_for_partner(inode, &pipe->r_counter))
47695 goto err_wr;
47696 }
47697 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47698 */
47699 filp->f_op = &rdwr_pipefifo_fops;
47700
47701 - pipe->readers++;
47702 - pipe->writers++;
47703 + atomic_inc(&pipe->readers);
47704 + atomic_inc(&pipe->writers);
47705 pipe->r_counter++;
47706 pipe->w_counter++;
47707 - if (pipe->readers == 1 || pipe->writers == 1)
47708 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47709 wake_up_partner(inode);
47710 break;
47711
47712 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47713 return 0;
47714
47715 err_rd:
47716 - if (!--pipe->readers)
47717 + if (atomic_dec_and_test(&pipe->readers))
47718 wake_up_interruptible(&pipe->wait);
47719 ret = -ERESTARTSYS;
47720 goto err;
47721
47722 err_wr:
47723 - if (!--pipe->writers)
47724 + if (atomic_dec_and_test(&pipe->writers))
47725 wake_up_interruptible(&pipe->wait);
47726 ret = -ERESTARTSYS;
47727 goto err;
47728
47729 err:
47730 - if (!pipe->readers && !pipe->writers)
47731 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47732 free_pipe_info(inode);
47733
47734 err_nocleanup:
47735 diff --git a/fs/file.c b/fs/file.c
47736 index eff2316..8c8930c 100644
47737 --- a/fs/file.c
47738 +++ b/fs/file.c
47739 @@ -16,6 +16,7 @@
47740 #include <linux/slab.h>
47741 #include <linux/vmalloc.h>
47742 #include <linux/file.h>
47743 +#include <linux/security.h>
47744 #include <linux/fdtable.h>
47745 #include <linux/bitops.h>
47746 #include <linux/interrupt.h>
47747 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47748 if (!file)
47749 return __close_fd(files, fd);
47750
47751 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47752 if (fd >= rlimit(RLIMIT_NOFILE))
47753 return -EBADF;
47754
47755 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47756 if (unlikely(oldfd == newfd))
47757 return -EINVAL;
47758
47759 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47760 if (newfd >= rlimit(RLIMIT_NOFILE))
47761 return -EBADF;
47762
47763 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47764 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47765 {
47766 int err;
47767 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47768 if (from >= rlimit(RLIMIT_NOFILE))
47769 return -EINVAL;
47770 err = alloc_fd(from, flags);
47771 diff --git a/fs/filesystems.c b/fs/filesystems.c
47772 index da165f6..3671bdb 100644
47773 --- a/fs/filesystems.c
47774 +++ b/fs/filesystems.c
47775 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47776 int len = dot ? dot - name : strlen(name);
47777
47778 fs = __get_fs_type(name, len);
47779 +
47780 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
47781 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47782 +#else
47783 if (!fs && (request_module("%.*s", len, name) == 0))
47784 +#endif
47785 fs = __get_fs_type(name, len);
47786
47787 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47788 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47789 index 5df4775..9d9336f 100644
47790 --- a/fs/fs_struct.c
47791 +++ b/fs/fs_struct.c
47792 @@ -4,6 +4,7 @@
47793 #include <linux/path.h>
47794 #include <linux/slab.h>
47795 #include <linux/fs_struct.h>
47796 +#include <linux/grsecurity.h>
47797 #include "internal.h"
47798
47799 /*
47800 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47801 write_seqcount_begin(&fs->seq);
47802 old_root = fs->root;
47803 fs->root = *path;
47804 + gr_set_chroot_entries(current, path);
47805 write_seqcount_end(&fs->seq);
47806 spin_unlock(&fs->lock);
47807 if (old_root.dentry)
47808 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47809 return 1;
47810 }
47811
47812 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47813 +{
47814 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47815 + return 0;
47816 + *p = *new;
47817 +
47818 + /* This function is only called from pivot_root(). Leave our
47819 + gr_chroot_dentry and is_chrooted flags as-is, so that a
47820 + pivoted root isn't treated as a chroot
47821 + */
47822 + //gr_set_chroot_entries(task, new);
47823 +
47824 + return 1;
47825 +}
47826 +
47827 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47828 {
47829 struct task_struct *g, *p;
47830 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47831 int hits = 0;
47832 spin_lock(&fs->lock);
47833 write_seqcount_begin(&fs->seq);
47834 - hits += replace_path(&fs->root, old_root, new_root);
47835 + hits += replace_root_path(p, &fs->root, old_root, new_root);
47836 hits += replace_path(&fs->pwd, old_root, new_root);
47837 write_seqcount_end(&fs->seq);
47838 while (hits--) {
47839 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47840 task_lock(tsk);
47841 spin_lock(&fs->lock);
47842 tsk->fs = NULL;
47843 - kill = !--fs->users;
47844 + gr_clear_chroot_entries(tsk);
47845 + kill = !atomic_dec_return(&fs->users);
47846 spin_unlock(&fs->lock);
47847 task_unlock(tsk);
47848 if (kill)
47849 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47850 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47851 /* We don't need to lock fs - think why ;-) */
47852 if (fs) {
47853 - fs->users = 1;
47854 + atomic_set(&fs->users, 1);
47855 fs->in_exec = 0;
47856 spin_lock_init(&fs->lock);
47857 seqcount_init(&fs->seq);
47858 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47859 spin_lock(&old->lock);
47860 fs->root = old->root;
47861 path_get(&fs->root);
47862 + /* instead of calling gr_set_chroot_entries here,
47863 + we call it from every caller of this function
47864 + */
47865 fs->pwd = old->pwd;
47866 path_get(&fs->pwd);
47867 spin_unlock(&old->lock);
47868 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47869
47870 task_lock(current);
47871 spin_lock(&fs->lock);
47872 - kill = !--fs->users;
47873 + kill = !atomic_dec_return(&fs->users);
47874 current->fs = new_fs;
47875 + gr_set_chroot_entries(current, &new_fs->root);
47876 spin_unlock(&fs->lock);
47877 task_unlock(current);
47878
47879 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47880
47881 int current_umask(void)
47882 {
47883 - return current->fs->umask;
47884 + return current->fs->umask | gr_acl_umask();
47885 }
47886 EXPORT_SYMBOL(current_umask);
47887
47888 /* to be mentioned only in INIT_TASK */
47889 struct fs_struct init_fs = {
47890 - .users = 1,
47891 + .users = ATOMIC_INIT(1),
47892 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47893 .seq = SEQCNT_ZERO,
47894 .umask = 0022,
47895 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47896 task_lock(current);
47897
47898 spin_lock(&init_fs.lock);
47899 - init_fs.users++;
47900 + atomic_inc(&init_fs.users);
47901 spin_unlock(&init_fs.lock);
47902
47903 spin_lock(&fs->lock);
47904 current->fs = &init_fs;
47905 - kill = !--fs->users;
47906 + gr_set_chroot_entries(current, &current->fs->root);
47907 + kill = !atomic_dec_return(&fs->users);
47908 spin_unlock(&fs->lock);
47909
47910 task_unlock(current);
47911 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47912 index 9905350..02eaec4 100644
47913 --- a/fs/fscache/cookie.c
47914 +++ b/fs/fscache/cookie.c
47915 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47916 parent ? (char *) parent->def->name : "<no-parent>",
47917 def->name, netfs_data);
47918
47919 - fscache_stat(&fscache_n_acquires);
47920 + fscache_stat_unchecked(&fscache_n_acquires);
47921
47922 /* if there's no parent cookie, then we don't create one here either */
47923 if (!parent) {
47924 - fscache_stat(&fscache_n_acquires_null);
47925 + fscache_stat_unchecked(&fscache_n_acquires_null);
47926 _leave(" [no parent]");
47927 return NULL;
47928 }
47929 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47930 /* allocate and initialise a cookie */
47931 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47932 if (!cookie) {
47933 - fscache_stat(&fscache_n_acquires_oom);
47934 + fscache_stat_unchecked(&fscache_n_acquires_oom);
47935 _leave(" [ENOMEM]");
47936 return NULL;
47937 }
47938 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47939
47940 switch (cookie->def->type) {
47941 case FSCACHE_COOKIE_TYPE_INDEX:
47942 - fscache_stat(&fscache_n_cookie_index);
47943 + fscache_stat_unchecked(&fscache_n_cookie_index);
47944 break;
47945 case FSCACHE_COOKIE_TYPE_DATAFILE:
47946 - fscache_stat(&fscache_n_cookie_data);
47947 + fscache_stat_unchecked(&fscache_n_cookie_data);
47948 break;
47949 default:
47950 - fscache_stat(&fscache_n_cookie_special);
47951 + fscache_stat_unchecked(&fscache_n_cookie_special);
47952 break;
47953 }
47954
47955 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47956 if (fscache_acquire_non_index_cookie(cookie) < 0) {
47957 atomic_dec(&parent->n_children);
47958 __fscache_cookie_put(cookie);
47959 - fscache_stat(&fscache_n_acquires_nobufs);
47960 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
47961 _leave(" = NULL");
47962 return NULL;
47963 }
47964 }
47965
47966 - fscache_stat(&fscache_n_acquires_ok);
47967 + fscache_stat_unchecked(&fscache_n_acquires_ok);
47968 _leave(" = %p", cookie);
47969 return cookie;
47970 }
47971 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
47972 cache = fscache_select_cache_for_object(cookie->parent);
47973 if (!cache) {
47974 up_read(&fscache_addremove_sem);
47975 - fscache_stat(&fscache_n_acquires_no_cache);
47976 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
47977 _leave(" = -ENOMEDIUM [no cache]");
47978 return -ENOMEDIUM;
47979 }
47980 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
47981 object = cache->ops->alloc_object(cache, cookie);
47982 fscache_stat_d(&fscache_n_cop_alloc_object);
47983 if (IS_ERR(object)) {
47984 - fscache_stat(&fscache_n_object_no_alloc);
47985 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
47986 ret = PTR_ERR(object);
47987 goto error;
47988 }
47989
47990 - fscache_stat(&fscache_n_object_alloc);
47991 + fscache_stat_unchecked(&fscache_n_object_alloc);
47992
47993 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
47994
47995 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
47996 struct fscache_object *object;
47997 struct hlist_node *_p;
47998
47999 - fscache_stat(&fscache_n_updates);
48000 + fscache_stat_unchecked(&fscache_n_updates);
48001
48002 if (!cookie) {
48003 - fscache_stat(&fscache_n_updates_null);
48004 + fscache_stat_unchecked(&fscache_n_updates_null);
48005 _leave(" [no cookie]");
48006 return;
48007 }
48008 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48009 struct fscache_object *object;
48010 unsigned long event;
48011
48012 - fscache_stat(&fscache_n_relinquishes);
48013 + fscache_stat_unchecked(&fscache_n_relinquishes);
48014 if (retire)
48015 - fscache_stat(&fscache_n_relinquishes_retire);
48016 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48017
48018 if (!cookie) {
48019 - fscache_stat(&fscache_n_relinquishes_null);
48020 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
48021 _leave(" [no cookie]");
48022 return;
48023 }
48024 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48025
48026 /* wait for the cookie to finish being instantiated (or to fail) */
48027 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48028 - fscache_stat(&fscache_n_relinquishes_waitcrt);
48029 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48030 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48031 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48032 }
48033 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48034 index f6aad48..88dcf26 100644
48035 --- a/fs/fscache/internal.h
48036 +++ b/fs/fscache/internal.h
48037 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
48038 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48039 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48040
48041 -extern atomic_t fscache_n_op_pend;
48042 -extern atomic_t fscache_n_op_run;
48043 -extern atomic_t fscache_n_op_enqueue;
48044 -extern atomic_t fscache_n_op_deferred_release;
48045 -extern atomic_t fscache_n_op_release;
48046 -extern atomic_t fscache_n_op_gc;
48047 -extern atomic_t fscache_n_op_cancelled;
48048 -extern atomic_t fscache_n_op_rejected;
48049 +extern atomic_unchecked_t fscache_n_op_pend;
48050 +extern atomic_unchecked_t fscache_n_op_run;
48051 +extern atomic_unchecked_t fscache_n_op_enqueue;
48052 +extern atomic_unchecked_t fscache_n_op_deferred_release;
48053 +extern atomic_unchecked_t fscache_n_op_release;
48054 +extern atomic_unchecked_t fscache_n_op_gc;
48055 +extern atomic_unchecked_t fscache_n_op_cancelled;
48056 +extern atomic_unchecked_t fscache_n_op_rejected;
48057
48058 -extern atomic_t fscache_n_attr_changed;
48059 -extern atomic_t fscache_n_attr_changed_ok;
48060 -extern atomic_t fscache_n_attr_changed_nobufs;
48061 -extern atomic_t fscache_n_attr_changed_nomem;
48062 -extern atomic_t fscache_n_attr_changed_calls;
48063 +extern atomic_unchecked_t fscache_n_attr_changed;
48064 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
48065 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48066 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48067 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
48068
48069 -extern atomic_t fscache_n_allocs;
48070 -extern atomic_t fscache_n_allocs_ok;
48071 -extern atomic_t fscache_n_allocs_wait;
48072 -extern atomic_t fscache_n_allocs_nobufs;
48073 -extern atomic_t fscache_n_allocs_intr;
48074 -extern atomic_t fscache_n_allocs_object_dead;
48075 -extern atomic_t fscache_n_alloc_ops;
48076 -extern atomic_t fscache_n_alloc_op_waits;
48077 +extern atomic_unchecked_t fscache_n_allocs;
48078 +extern atomic_unchecked_t fscache_n_allocs_ok;
48079 +extern atomic_unchecked_t fscache_n_allocs_wait;
48080 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
48081 +extern atomic_unchecked_t fscache_n_allocs_intr;
48082 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
48083 +extern atomic_unchecked_t fscache_n_alloc_ops;
48084 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
48085
48086 -extern atomic_t fscache_n_retrievals;
48087 -extern atomic_t fscache_n_retrievals_ok;
48088 -extern atomic_t fscache_n_retrievals_wait;
48089 -extern atomic_t fscache_n_retrievals_nodata;
48090 -extern atomic_t fscache_n_retrievals_nobufs;
48091 -extern atomic_t fscache_n_retrievals_intr;
48092 -extern atomic_t fscache_n_retrievals_nomem;
48093 -extern atomic_t fscache_n_retrievals_object_dead;
48094 -extern atomic_t fscache_n_retrieval_ops;
48095 -extern atomic_t fscache_n_retrieval_op_waits;
48096 +extern atomic_unchecked_t fscache_n_retrievals;
48097 +extern atomic_unchecked_t fscache_n_retrievals_ok;
48098 +extern atomic_unchecked_t fscache_n_retrievals_wait;
48099 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
48100 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48101 +extern atomic_unchecked_t fscache_n_retrievals_intr;
48102 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
48103 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48104 +extern atomic_unchecked_t fscache_n_retrieval_ops;
48105 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48106
48107 -extern atomic_t fscache_n_stores;
48108 -extern atomic_t fscache_n_stores_ok;
48109 -extern atomic_t fscache_n_stores_again;
48110 -extern atomic_t fscache_n_stores_nobufs;
48111 -extern atomic_t fscache_n_stores_oom;
48112 -extern atomic_t fscache_n_store_ops;
48113 -extern atomic_t fscache_n_store_calls;
48114 -extern atomic_t fscache_n_store_pages;
48115 -extern atomic_t fscache_n_store_radix_deletes;
48116 -extern atomic_t fscache_n_store_pages_over_limit;
48117 +extern atomic_unchecked_t fscache_n_stores;
48118 +extern atomic_unchecked_t fscache_n_stores_ok;
48119 +extern atomic_unchecked_t fscache_n_stores_again;
48120 +extern atomic_unchecked_t fscache_n_stores_nobufs;
48121 +extern atomic_unchecked_t fscache_n_stores_oom;
48122 +extern atomic_unchecked_t fscache_n_store_ops;
48123 +extern atomic_unchecked_t fscache_n_store_calls;
48124 +extern atomic_unchecked_t fscache_n_store_pages;
48125 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
48126 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48127
48128 -extern atomic_t fscache_n_store_vmscan_not_storing;
48129 -extern atomic_t fscache_n_store_vmscan_gone;
48130 -extern atomic_t fscache_n_store_vmscan_busy;
48131 -extern atomic_t fscache_n_store_vmscan_cancelled;
48132 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48133 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48134 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48135 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48136
48137 -extern atomic_t fscache_n_marks;
48138 -extern atomic_t fscache_n_uncaches;
48139 +extern atomic_unchecked_t fscache_n_marks;
48140 +extern atomic_unchecked_t fscache_n_uncaches;
48141
48142 -extern atomic_t fscache_n_acquires;
48143 -extern atomic_t fscache_n_acquires_null;
48144 -extern atomic_t fscache_n_acquires_no_cache;
48145 -extern atomic_t fscache_n_acquires_ok;
48146 -extern atomic_t fscache_n_acquires_nobufs;
48147 -extern atomic_t fscache_n_acquires_oom;
48148 +extern atomic_unchecked_t fscache_n_acquires;
48149 +extern atomic_unchecked_t fscache_n_acquires_null;
48150 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
48151 +extern atomic_unchecked_t fscache_n_acquires_ok;
48152 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
48153 +extern atomic_unchecked_t fscache_n_acquires_oom;
48154
48155 -extern atomic_t fscache_n_updates;
48156 -extern atomic_t fscache_n_updates_null;
48157 -extern atomic_t fscache_n_updates_run;
48158 +extern atomic_unchecked_t fscache_n_updates;
48159 +extern atomic_unchecked_t fscache_n_updates_null;
48160 +extern atomic_unchecked_t fscache_n_updates_run;
48161
48162 -extern atomic_t fscache_n_relinquishes;
48163 -extern atomic_t fscache_n_relinquishes_null;
48164 -extern atomic_t fscache_n_relinquishes_waitcrt;
48165 -extern atomic_t fscache_n_relinquishes_retire;
48166 +extern atomic_unchecked_t fscache_n_relinquishes;
48167 +extern atomic_unchecked_t fscache_n_relinquishes_null;
48168 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48169 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
48170
48171 -extern atomic_t fscache_n_cookie_index;
48172 -extern atomic_t fscache_n_cookie_data;
48173 -extern atomic_t fscache_n_cookie_special;
48174 +extern atomic_unchecked_t fscache_n_cookie_index;
48175 +extern atomic_unchecked_t fscache_n_cookie_data;
48176 +extern atomic_unchecked_t fscache_n_cookie_special;
48177
48178 -extern atomic_t fscache_n_object_alloc;
48179 -extern atomic_t fscache_n_object_no_alloc;
48180 -extern atomic_t fscache_n_object_lookups;
48181 -extern atomic_t fscache_n_object_lookups_negative;
48182 -extern atomic_t fscache_n_object_lookups_positive;
48183 -extern atomic_t fscache_n_object_lookups_timed_out;
48184 -extern atomic_t fscache_n_object_created;
48185 -extern atomic_t fscache_n_object_avail;
48186 -extern atomic_t fscache_n_object_dead;
48187 +extern atomic_unchecked_t fscache_n_object_alloc;
48188 +extern atomic_unchecked_t fscache_n_object_no_alloc;
48189 +extern atomic_unchecked_t fscache_n_object_lookups;
48190 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
48191 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
48192 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48193 +extern atomic_unchecked_t fscache_n_object_created;
48194 +extern atomic_unchecked_t fscache_n_object_avail;
48195 +extern atomic_unchecked_t fscache_n_object_dead;
48196
48197 -extern atomic_t fscache_n_checkaux_none;
48198 -extern atomic_t fscache_n_checkaux_okay;
48199 -extern atomic_t fscache_n_checkaux_update;
48200 -extern atomic_t fscache_n_checkaux_obsolete;
48201 +extern atomic_unchecked_t fscache_n_checkaux_none;
48202 +extern atomic_unchecked_t fscache_n_checkaux_okay;
48203 +extern atomic_unchecked_t fscache_n_checkaux_update;
48204 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48205
48206 extern atomic_t fscache_n_cop_alloc_object;
48207 extern atomic_t fscache_n_cop_lookup_object;
48208 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
48209 atomic_inc(stat);
48210 }
48211
48212 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48213 +{
48214 + atomic_inc_unchecked(stat);
48215 +}
48216 +
48217 static inline void fscache_stat_d(atomic_t *stat)
48218 {
48219 atomic_dec(stat);
48220 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
48221
48222 #define __fscache_stat(stat) (NULL)
48223 #define fscache_stat(stat) do {} while (0)
48224 +#define fscache_stat_unchecked(stat) do {} while (0)
48225 #define fscache_stat_d(stat) do {} while (0)
48226 #endif
48227
48228 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48229 index b6b897c..0ffff9c 100644
48230 --- a/fs/fscache/object.c
48231 +++ b/fs/fscache/object.c
48232 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48233 /* update the object metadata on disk */
48234 case FSCACHE_OBJECT_UPDATING:
48235 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48236 - fscache_stat(&fscache_n_updates_run);
48237 + fscache_stat_unchecked(&fscache_n_updates_run);
48238 fscache_stat(&fscache_n_cop_update_object);
48239 object->cache->ops->update_object(object);
48240 fscache_stat_d(&fscache_n_cop_update_object);
48241 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48242 spin_lock(&object->lock);
48243 object->state = FSCACHE_OBJECT_DEAD;
48244 spin_unlock(&object->lock);
48245 - fscache_stat(&fscache_n_object_dead);
48246 + fscache_stat_unchecked(&fscache_n_object_dead);
48247 goto terminal_transit;
48248
48249 /* handle the parent cache of this object being withdrawn from
48250 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48251 spin_lock(&object->lock);
48252 object->state = FSCACHE_OBJECT_DEAD;
48253 spin_unlock(&object->lock);
48254 - fscache_stat(&fscache_n_object_dead);
48255 + fscache_stat_unchecked(&fscache_n_object_dead);
48256 goto terminal_transit;
48257
48258 /* complain about the object being woken up once it is
48259 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48260 parent->cookie->def->name, cookie->def->name,
48261 object->cache->tag->name);
48262
48263 - fscache_stat(&fscache_n_object_lookups);
48264 + fscache_stat_unchecked(&fscache_n_object_lookups);
48265 fscache_stat(&fscache_n_cop_lookup_object);
48266 ret = object->cache->ops->lookup_object(object);
48267 fscache_stat_d(&fscache_n_cop_lookup_object);
48268 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48269 if (ret == -ETIMEDOUT) {
48270 /* probably stuck behind another object, so move this one to
48271 * the back of the queue */
48272 - fscache_stat(&fscache_n_object_lookups_timed_out);
48273 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
48274 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48275 }
48276
48277 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48278
48279 spin_lock(&object->lock);
48280 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48281 - fscache_stat(&fscache_n_object_lookups_negative);
48282 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
48283
48284 /* transit here to allow write requests to begin stacking up
48285 * and read requests to begin returning ENODATA */
48286 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
48287 * result, in which case there may be data available */
48288 spin_lock(&object->lock);
48289 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48290 - fscache_stat(&fscache_n_object_lookups_positive);
48291 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
48292
48293 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
48294
48295 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
48296 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48297 } else {
48298 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
48299 - fscache_stat(&fscache_n_object_created);
48300 + fscache_stat_unchecked(&fscache_n_object_created);
48301
48302 object->state = FSCACHE_OBJECT_AVAILABLE;
48303 spin_unlock(&object->lock);
48304 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
48305 fscache_enqueue_dependents(object);
48306
48307 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
48308 - fscache_stat(&fscache_n_object_avail);
48309 + fscache_stat_unchecked(&fscache_n_object_avail);
48310
48311 _leave("");
48312 }
48313 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48314 enum fscache_checkaux result;
48315
48316 if (!object->cookie->def->check_aux) {
48317 - fscache_stat(&fscache_n_checkaux_none);
48318 + fscache_stat_unchecked(&fscache_n_checkaux_none);
48319 return FSCACHE_CHECKAUX_OKAY;
48320 }
48321
48322 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48323 switch (result) {
48324 /* entry okay as is */
48325 case FSCACHE_CHECKAUX_OKAY:
48326 - fscache_stat(&fscache_n_checkaux_okay);
48327 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
48328 break;
48329
48330 /* entry requires update */
48331 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
48332 - fscache_stat(&fscache_n_checkaux_update);
48333 + fscache_stat_unchecked(&fscache_n_checkaux_update);
48334 break;
48335
48336 /* entry requires deletion */
48337 case FSCACHE_CHECKAUX_OBSOLETE:
48338 - fscache_stat(&fscache_n_checkaux_obsolete);
48339 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
48340 break;
48341
48342 default:
48343 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
48344 index 30afdfa..2256596 100644
48345 --- a/fs/fscache/operation.c
48346 +++ b/fs/fscache/operation.c
48347 @@ -17,7 +17,7 @@
48348 #include <linux/slab.h>
48349 #include "internal.h"
48350
48351 -atomic_t fscache_op_debug_id;
48352 +atomic_unchecked_t fscache_op_debug_id;
48353 EXPORT_SYMBOL(fscache_op_debug_id);
48354
48355 /**
48356 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
48357 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
48358 ASSERTCMP(atomic_read(&op->usage), >, 0);
48359
48360 - fscache_stat(&fscache_n_op_enqueue);
48361 + fscache_stat_unchecked(&fscache_n_op_enqueue);
48362 switch (op->flags & FSCACHE_OP_TYPE) {
48363 case FSCACHE_OP_ASYNC:
48364 _debug("queue async");
48365 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
48366 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
48367 if (op->processor)
48368 fscache_enqueue_operation(op);
48369 - fscache_stat(&fscache_n_op_run);
48370 + fscache_stat_unchecked(&fscache_n_op_run);
48371 }
48372
48373 /*
48374 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48375 if (object->n_ops > 1) {
48376 atomic_inc(&op->usage);
48377 list_add_tail(&op->pend_link, &object->pending_ops);
48378 - fscache_stat(&fscache_n_op_pend);
48379 + fscache_stat_unchecked(&fscache_n_op_pend);
48380 } else if (!list_empty(&object->pending_ops)) {
48381 atomic_inc(&op->usage);
48382 list_add_tail(&op->pend_link, &object->pending_ops);
48383 - fscache_stat(&fscache_n_op_pend);
48384 + fscache_stat_unchecked(&fscache_n_op_pend);
48385 fscache_start_operations(object);
48386 } else {
48387 ASSERTCMP(object->n_in_progress, ==, 0);
48388 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48389 object->n_exclusive++; /* reads and writes must wait */
48390 atomic_inc(&op->usage);
48391 list_add_tail(&op->pend_link, &object->pending_ops);
48392 - fscache_stat(&fscache_n_op_pend);
48393 + fscache_stat_unchecked(&fscache_n_op_pend);
48394 ret = 0;
48395 } else {
48396 /* not allowed to submit ops in any other state */
48397 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48398 if (object->n_exclusive > 0) {
48399 atomic_inc(&op->usage);
48400 list_add_tail(&op->pend_link, &object->pending_ops);
48401 - fscache_stat(&fscache_n_op_pend);
48402 + fscache_stat_unchecked(&fscache_n_op_pend);
48403 } else if (!list_empty(&object->pending_ops)) {
48404 atomic_inc(&op->usage);
48405 list_add_tail(&op->pend_link, &object->pending_ops);
48406 - fscache_stat(&fscache_n_op_pend);
48407 + fscache_stat_unchecked(&fscache_n_op_pend);
48408 fscache_start_operations(object);
48409 } else {
48410 ASSERTCMP(object->n_exclusive, ==, 0);
48411 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48412 object->n_ops++;
48413 atomic_inc(&op->usage);
48414 list_add_tail(&op->pend_link, &object->pending_ops);
48415 - fscache_stat(&fscache_n_op_pend);
48416 + fscache_stat_unchecked(&fscache_n_op_pend);
48417 ret = 0;
48418 } else if (object->state == FSCACHE_OBJECT_DYING ||
48419 object->state == FSCACHE_OBJECT_LC_DYING ||
48420 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48421 - fscache_stat(&fscache_n_op_rejected);
48422 + fscache_stat_unchecked(&fscache_n_op_rejected);
48423 ret = -ENOBUFS;
48424 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48425 fscache_report_unexpected_submission(object, op, ostate);
48426 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48427
48428 ret = -EBUSY;
48429 if (!list_empty(&op->pend_link)) {
48430 - fscache_stat(&fscache_n_op_cancelled);
48431 + fscache_stat_unchecked(&fscache_n_op_cancelled);
48432 list_del_init(&op->pend_link);
48433 object->n_ops--;
48434 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48435 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48436 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48437 BUG();
48438
48439 - fscache_stat(&fscache_n_op_release);
48440 + fscache_stat_unchecked(&fscache_n_op_release);
48441
48442 if (op->release) {
48443 op->release(op);
48444 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48445 * lock, and defer it otherwise */
48446 if (!spin_trylock(&object->lock)) {
48447 _debug("defer put");
48448 - fscache_stat(&fscache_n_op_deferred_release);
48449 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
48450
48451 cache = object->cache;
48452 spin_lock(&cache->op_gc_list_lock);
48453 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48454
48455 _debug("GC DEFERRED REL OBJ%x OP%x",
48456 object->debug_id, op->debug_id);
48457 - fscache_stat(&fscache_n_op_gc);
48458 + fscache_stat_unchecked(&fscache_n_op_gc);
48459
48460 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48461
48462 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48463 index 3f7a59b..cf196cc 100644
48464 --- a/fs/fscache/page.c
48465 +++ b/fs/fscache/page.c
48466 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48467 val = radix_tree_lookup(&cookie->stores, page->index);
48468 if (!val) {
48469 rcu_read_unlock();
48470 - fscache_stat(&fscache_n_store_vmscan_not_storing);
48471 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48472 __fscache_uncache_page(cookie, page);
48473 return true;
48474 }
48475 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48476 spin_unlock(&cookie->stores_lock);
48477
48478 if (xpage) {
48479 - fscache_stat(&fscache_n_store_vmscan_cancelled);
48480 - fscache_stat(&fscache_n_store_radix_deletes);
48481 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48482 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48483 ASSERTCMP(xpage, ==, page);
48484 } else {
48485 - fscache_stat(&fscache_n_store_vmscan_gone);
48486 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48487 }
48488
48489 wake_up_bit(&cookie->flags, 0);
48490 @@ -107,7 +107,7 @@ page_busy:
48491 /* we might want to wait here, but that could deadlock the allocator as
48492 * the work threads writing to the cache may all end up sleeping
48493 * on memory allocation */
48494 - fscache_stat(&fscache_n_store_vmscan_busy);
48495 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48496 return false;
48497 }
48498 EXPORT_SYMBOL(__fscache_maybe_release_page);
48499 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48500 FSCACHE_COOKIE_STORING_TAG);
48501 if (!radix_tree_tag_get(&cookie->stores, page->index,
48502 FSCACHE_COOKIE_PENDING_TAG)) {
48503 - fscache_stat(&fscache_n_store_radix_deletes);
48504 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48505 xpage = radix_tree_delete(&cookie->stores, page->index);
48506 }
48507 spin_unlock(&cookie->stores_lock);
48508 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48509
48510 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48511
48512 - fscache_stat(&fscache_n_attr_changed_calls);
48513 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48514
48515 if (fscache_object_is_active(object)) {
48516 fscache_stat(&fscache_n_cop_attr_changed);
48517 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48518
48519 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48520
48521 - fscache_stat(&fscache_n_attr_changed);
48522 + fscache_stat_unchecked(&fscache_n_attr_changed);
48523
48524 op = kzalloc(sizeof(*op), GFP_KERNEL);
48525 if (!op) {
48526 - fscache_stat(&fscache_n_attr_changed_nomem);
48527 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48528 _leave(" = -ENOMEM");
48529 return -ENOMEM;
48530 }
48531 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48532 if (fscache_submit_exclusive_op(object, op) < 0)
48533 goto nobufs;
48534 spin_unlock(&cookie->lock);
48535 - fscache_stat(&fscache_n_attr_changed_ok);
48536 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48537 fscache_put_operation(op);
48538 _leave(" = 0");
48539 return 0;
48540 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48541 nobufs:
48542 spin_unlock(&cookie->lock);
48543 kfree(op);
48544 - fscache_stat(&fscache_n_attr_changed_nobufs);
48545 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48546 _leave(" = %d", -ENOBUFS);
48547 return -ENOBUFS;
48548 }
48549 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48550 /* allocate a retrieval operation and attempt to submit it */
48551 op = kzalloc(sizeof(*op), GFP_NOIO);
48552 if (!op) {
48553 - fscache_stat(&fscache_n_retrievals_nomem);
48554 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48555 return NULL;
48556 }
48557
48558 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48559 return 0;
48560 }
48561
48562 - fscache_stat(&fscache_n_retrievals_wait);
48563 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
48564
48565 jif = jiffies;
48566 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48567 fscache_wait_bit_interruptible,
48568 TASK_INTERRUPTIBLE) != 0) {
48569 - fscache_stat(&fscache_n_retrievals_intr);
48570 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48571 _leave(" = -ERESTARTSYS");
48572 return -ERESTARTSYS;
48573 }
48574 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48575 */
48576 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48577 struct fscache_retrieval *op,
48578 - atomic_t *stat_op_waits,
48579 - atomic_t *stat_object_dead)
48580 + atomic_unchecked_t *stat_op_waits,
48581 + atomic_unchecked_t *stat_object_dead)
48582 {
48583 int ret;
48584
48585 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48586 goto check_if_dead;
48587
48588 _debug(">>> WT");
48589 - fscache_stat(stat_op_waits);
48590 + fscache_stat_unchecked(stat_op_waits);
48591 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48592 fscache_wait_bit_interruptible,
48593 TASK_INTERRUPTIBLE) < 0) {
48594 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48595
48596 check_if_dead:
48597 if (unlikely(fscache_object_is_dead(object))) {
48598 - fscache_stat(stat_object_dead);
48599 + fscache_stat_unchecked(stat_object_dead);
48600 return -ENOBUFS;
48601 }
48602 return 0;
48603 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48604
48605 _enter("%p,%p,,,", cookie, page);
48606
48607 - fscache_stat(&fscache_n_retrievals);
48608 + fscache_stat_unchecked(&fscache_n_retrievals);
48609
48610 if (hlist_empty(&cookie->backing_objects))
48611 goto nobufs;
48612 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48613 goto nobufs_unlock;
48614 spin_unlock(&cookie->lock);
48615
48616 - fscache_stat(&fscache_n_retrieval_ops);
48617 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48618
48619 /* pin the netfs read context in case we need to do the actual netfs
48620 * read because we've encountered a cache read failure */
48621 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48622
48623 error:
48624 if (ret == -ENOMEM)
48625 - fscache_stat(&fscache_n_retrievals_nomem);
48626 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48627 else if (ret == -ERESTARTSYS)
48628 - fscache_stat(&fscache_n_retrievals_intr);
48629 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48630 else if (ret == -ENODATA)
48631 - fscache_stat(&fscache_n_retrievals_nodata);
48632 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48633 else if (ret < 0)
48634 - fscache_stat(&fscache_n_retrievals_nobufs);
48635 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48636 else
48637 - fscache_stat(&fscache_n_retrievals_ok);
48638 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48639
48640 fscache_put_retrieval(op);
48641 _leave(" = %d", ret);
48642 @@ -429,7 +429,7 @@ nobufs_unlock:
48643 spin_unlock(&cookie->lock);
48644 kfree(op);
48645 nobufs:
48646 - fscache_stat(&fscache_n_retrievals_nobufs);
48647 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48648 _leave(" = -ENOBUFS");
48649 return -ENOBUFS;
48650 }
48651 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48652
48653 _enter("%p,,%d,,,", cookie, *nr_pages);
48654
48655 - fscache_stat(&fscache_n_retrievals);
48656 + fscache_stat_unchecked(&fscache_n_retrievals);
48657
48658 if (hlist_empty(&cookie->backing_objects))
48659 goto nobufs;
48660 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48661 goto nobufs_unlock;
48662 spin_unlock(&cookie->lock);
48663
48664 - fscache_stat(&fscache_n_retrieval_ops);
48665 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48666
48667 /* pin the netfs read context in case we need to do the actual netfs
48668 * read because we've encountered a cache read failure */
48669 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48670
48671 error:
48672 if (ret == -ENOMEM)
48673 - fscache_stat(&fscache_n_retrievals_nomem);
48674 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48675 else if (ret == -ERESTARTSYS)
48676 - fscache_stat(&fscache_n_retrievals_intr);
48677 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48678 else if (ret == -ENODATA)
48679 - fscache_stat(&fscache_n_retrievals_nodata);
48680 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48681 else if (ret < 0)
48682 - fscache_stat(&fscache_n_retrievals_nobufs);
48683 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48684 else
48685 - fscache_stat(&fscache_n_retrievals_ok);
48686 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48687
48688 fscache_put_retrieval(op);
48689 _leave(" = %d", ret);
48690 @@ -545,7 +545,7 @@ nobufs_unlock:
48691 spin_unlock(&cookie->lock);
48692 kfree(op);
48693 nobufs:
48694 - fscache_stat(&fscache_n_retrievals_nobufs);
48695 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48696 _leave(" = -ENOBUFS");
48697 return -ENOBUFS;
48698 }
48699 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48700
48701 _enter("%p,%p,,,", cookie, page);
48702
48703 - fscache_stat(&fscache_n_allocs);
48704 + fscache_stat_unchecked(&fscache_n_allocs);
48705
48706 if (hlist_empty(&cookie->backing_objects))
48707 goto nobufs;
48708 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48709 goto nobufs_unlock;
48710 spin_unlock(&cookie->lock);
48711
48712 - fscache_stat(&fscache_n_alloc_ops);
48713 + fscache_stat_unchecked(&fscache_n_alloc_ops);
48714
48715 ret = fscache_wait_for_retrieval_activation(
48716 object, op,
48717 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48718
48719 error:
48720 if (ret == -ERESTARTSYS)
48721 - fscache_stat(&fscache_n_allocs_intr);
48722 + fscache_stat_unchecked(&fscache_n_allocs_intr);
48723 else if (ret < 0)
48724 - fscache_stat(&fscache_n_allocs_nobufs);
48725 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48726 else
48727 - fscache_stat(&fscache_n_allocs_ok);
48728 + fscache_stat_unchecked(&fscache_n_allocs_ok);
48729
48730 fscache_put_retrieval(op);
48731 _leave(" = %d", ret);
48732 @@ -625,7 +625,7 @@ nobufs_unlock:
48733 spin_unlock(&cookie->lock);
48734 kfree(op);
48735 nobufs:
48736 - fscache_stat(&fscache_n_allocs_nobufs);
48737 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48738 _leave(" = -ENOBUFS");
48739 return -ENOBUFS;
48740 }
48741 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48742
48743 spin_lock(&cookie->stores_lock);
48744
48745 - fscache_stat(&fscache_n_store_calls);
48746 + fscache_stat_unchecked(&fscache_n_store_calls);
48747
48748 /* find a page to store */
48749 page = NULL;
48750 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48751 page = results[0];
48752 _debug("gang %d [%lx]", n, page->index);
48753 if (page->index > op->store_limit) {
48754 - fscache_stat(&fscache_n_store_pages_over_limit);
48755 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48756 goto superseded;
48757 }
48758
48759 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48760 spin_unlock(&cookie->stores_lock);
48761 spin_unlock(&object->lock);
48762
48763 - fscache_stat(&fscache_n_store_pages);
48764 + fscache_stat_unchecked(&fscache_n_store_pages);
48765 fscache_stat(&fscache_n_cop_write_page);
48766 ret = object->cache->ops->write_page(op, page);
48767 fscache_stat_d(&fscache_n_cop_write_page);
48768 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48769 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48770 ASSERT(PageFsCache(page));
48771
48772 - fscache_stat(&fscache_n_stores);
48773 + fscache_stat_unchecked(&fscache_n_stores);
48774
48775 op = kzalloc(sizeof(*op), GFP_NOIO);
48776 if (!op)
48777 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48778 spin_unlock(&cookie->stores_lock);
48779 spin_unlock(&object->lock);
48780
48781 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48782 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48783 op->store_limit = object->store_limit;
48784
48785 if (fscache_submit_op(object, &op->op) < 0)
48786 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48787
48788 spin_unlock(&cookie->lock);
48789 radix_tree_preload_end();
48790 - fscache_stat(&fscache_n_store_ops);
48791 - fscache_stat(&fscache_n_stores_ok);
48792 + fscache_stat_unchecked(&fscache_n_store_ops);
48793 + fscache_stat_unchecked(&fscache_n_stores_ok);
48794
48795 /* the work queue now carries its own ref on the object */
48796 fscache_put_operation(&op->op);
48797 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48798 return 0;
48799
48800 already_queued:
48801 - fscache_stat(&fscache_n_stores_again);
48802 + fscache_stat_unchecked(&fscache_n_stores_again);
48803 already_pending:
48804 spin_unlock(&cookie->stores_lock);
48805 spin_unlock(&object->lock);
48806 spin_unlock(&cookie->lock);
48807 radix_tree_preload_end();
48808 kfree(op);
48809 - fscache_stat(&fscache_n_stores_ok);
48810 + fscache_stat_unchecked(&fscache_n_stores_ok);
48811 _leave(" = 0");
48812 return 0;
48813
48814 @@ -851,14 +851,14 @@ nobufs:
48815 spin_unlock(&cookie->lock);
48816 radix_tree_preload_end();
48817 kfree(op);
48818 - fscache_stat(&fscache_n_stores_nobufs);
48819 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
48820 _leave(" = -ENOBUFS");
48821 return -ENOBUFS;
48822
48823 nomem_free:
48824 kfree(op);
48825 nomem:
48826 - fscache_stat(&fscache_n_stores_oom);
48827 + fscache_stat_unchecked(&fscache_n_stores_oom);
48828 _leave(" = -ENOMEM");
48829 return -ENOMEM;
48830 }
48831 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48832 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48833 ASSERTCMP(page, !=, NULL);
48834
48835 - fscache_stat(&fscache_n_uncaches);
48836 + fscache_stat_unchecked(&fscache_n_uncaches);
48837
48838 /* cache withdrawal may beat us to it */
48839 if (!PageFsCache(page))
48840 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48841 unsigned long loop;
48842
48843 #ifdef CONFIG_FSCACHE_STATS
48844 - atomic_add(pagevec->nr, &fscache_n_marks);
48845 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48846 #endif
48847
48848 for (loop = 0; loop < pagevec->nr; loop++) {
48849 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48850 index 4765190..2a067f2 100644
48851 --- a/fs/fscache/stats.c
48852 +++ b/fs/fscache/stats.c
48853 @@ -18,95 +18,95 @@
48854 /*
48855 * operation counters
48856 */
48857 -atomic_t fscache_n_op_pend;
48858 -atomic_t fscache_n_op_run;
48859 -atomic_t fscache_n_op_enqueue;
48860 -atomic_t fscache_n_op_requeue;
48861 -atomic_t fscache_n_op_deferred_release;
48862 -atomic_t fscache_n_op_release;
48863 -atomic_t fscache_n_op_gc;
48864 -atomic_t fscache_n_op_cancelled;
48865 -atomic_t fscache_n_op_rejected;
48866 +atomic_unchecked_t fscache_n_op_pend;
48867 +atomic_unchecked_t fscache_n_op_run;
48868 +atomic_unchecked_t fscache_n_op_enqueue;
48869 +atomic_unchecked_t fscache_n_op_requeue;
48870 +atomic_unchecked_t fscache_n_op_deferred_release;
48871 +atomic_unchecked_t fscache_n_op_release;
48872 +atomic_unchecked_t fscache_n_op_gc;
48873 +atomic_unchecked_t fscache_n_op_cancelled;
48874 +atomic_unchecked_t fscache_n_op_rejected;
48875
48876 -atomic_t fscache_n_attr_changed;
48877 -atomic_t fscache_n_attr_changed_ok;
48878 -atomic_t fscache_n_attr_changed_nobufs;
48879 -atomic_t fscache_n_attr_changed_nomem;
48880 -atomic_t fscache_n_attr_changed_calls;
48881 +atomic_unchecked_t fscache_n_attr_changed;
48882 +atomic_unchecked_t fscache_n_attr_changed_ok;
48883 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
48884 +atomic_unchecked_t fscache_n_attr_changed_nomem;
48885 +atomic_unchecked_t fscache_n_attr_changed_calls;
48886
48887 -atomic_t fscache_n_allocs;
48888 -atomic_t fscache_n_allocs_ok;
48889 -atomic_t fscache_n_allocs_wait;
48890 -atomic_t fscache_n_allocs_nobufs;
48891 -atomic_t fscache_n_allocs_intr;
48892 -atomic_t fscache_n_allocs_object_dead;
48893 -atomic_t fscache_n_alloc_ops;
48894 -atomic_t fscache_n_alloc_op_waits;
48895 +atomic_unchecked_t fscache_n_allocs;
48896 +atomic_unchecked_t fscache_n_allocs_ok;
48897 +atomic_unchecked_t fscache_n_allocs_wait;
48898 +atomic_unchecked_t fscache_n_allocs_nobufs;
48899 +atomic_unchecked_t fscache_n_allocs_intr;
48900 +atomic_unchecked_t fscache_n_allocs_object_dead;
48901 +atomic_unchecked_t fscache_n_alloc_ops;
48902 +atomic_unchecked_t fscache_n_alloc_op_waits;
48903
48904 -atomic_t fscache_n_retrievals;
48905 -atomic_t fscache_n_retrievals_ok;
48906 -atomic_t fscache_n_retrievals_wait;
48907 -atomic_t fscache_n_retrievals_nodata;
48908 -atomic_t fscache_n_retrievals_nobufs;
48909 -atomic_t fscache_n_retrievals_intr;
48910 -atomic_t fscache_n_retrievals_nomem;
48911 -atomic_t fscache_n_retrievals_object_dead;
48912 -atomic_t fscache_n_retrieval_ops;
48913 -atomic_t fscache_n_retrieval_op_waits;
48914 +atomic_unchecked_t fscache_n_retrievals;
48915 +atomic_unchecked_t fscache_n_retrievals_ok;
48916 +atomic_unchecked_t fscache_n_retrievals_wait;
48917 +atomic_unchecked_t fscache_n_retrievals_nodata;
48918 +atomic_unchecked_t fscache_n_retrievals_nobufs;
48919 +atomic_unchecked_t fscache_n_retrievals_intr;
48920 +atomic_unchecked_t fscache_n_retrievals_nomem;
48921 +atomic_unchecked_t fscache_n_retrievals_object_dead;
48922 +atomic_unchecked_t fscache_n_retrieval_ops;
48923 +atomic_unchecked_t fscache_n_retrieval_op_waits;
48924
48925 -atomic_t fscache_n_stores;
48926 -atomic_t fscache_n_stores_ok;
48927 -atomic_t fscache_n_stores_again;
48928 -atomic_t fscache_n_stores_nobufs;
48929 -atomic_t fscache_n_stores_oom;
48930 -atomic_t fscache_n_store_ops;
48931 -atomic_t fscache_n_store_calls;
48932 -atomic_t fscache_n_store_pages;
48933 -atomic_t fscache_n_store_radix_deletes;
48934 -atomic_t fscache_n_store_pages_over_limit;
48935 +atomic_unchecked_t fscache_n_stores;
48936 +atomic_unchecked_t fscache_n_stores_ok;
48937 +atomic_unchecked_t fscache_n_stores_again;
48938 +atomic_unchecked_t fscache_n_stores_nobufs;
48939 +atomic_unchecked_t fscache_n_stores_oom;
48940 +atomic_unchecked_t fscache_n_store_ops;
48941 +atomic_unchecked_t fscache_n_store_calls;
48942 +atomic_unchecked_t fscache_n_store_pages;
48943 +atomic_unchecked_t fscache_n_store_radix_deletes;
48944 +atomic_unchecked_t fscache_n_store_pages_over_limit;
48945
48946 -atomic_t fscache_n_store_vmscan_not_storing;
48947 -atomic_t fscache_n_store_vmscan_gone;
48948 -atomic_t fscache_n_store_vmscan_busy;
48949 -atomic_t fscache_n_store_vmscan_cancelled;
48950 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48951 +atomic_unchecked_t fscache_n_store_vmscan_gone;
48952 +atomic_unchecked_t fscache_n_store_vmscan_busy;
48953 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48954
48955 -atomic_t fscache_n_marks;
48956 -atomic_t fscache_n_uncaches;
48957 +atomic_unchecked_t fscache_n_marks;
48958 +atomic_unchecked_t fscache_n_uncaches;
48959
48960 -atomic_t fscache_n_acquires;
48961 -atomic_t fscache_n_acquires_null;
48962 -atomic_t fscache_n_acquires_no_cache;
48963 -atomic_t fscache_n_acquires_ok;
48964 -atomic_t fscache_n_acquires_nobufs;
48965 -atomic_t fscache_n_acquires_oom;
48966 +atomic_unchecked_t fscache_n_acquires;
48967 +atomic_unchecked_t fscache_n_acquires_null;
48968 +atomic_unchecked_t fscache_n_acquires_no_cache;
48969 +atomic_unchecked_t fscache_n_acquires_ok;
48970 +atomic_unchecked_t fscache_n_acquires_nobufs;
48971 +atomic_unchecked_t fscache_n_acquires_oom;
48972
48973 -atomic_t fscache_n_updates;
48974 -atomic_t fscache_n_updates_null;
48975 -atomic_t fscache_n_updates_run;
48976 +atomic_unchecked_t fscache_n_updates;
48977 +atomic_unchecked_t fscache_n_updates_null;
48978 +atomic_unchecked_t fscache_n_updates_run;
48979
48980 -atomic_t fscache_n_relinquishes;
48981 -atomic_t fscache_n_relinquishes_null;
48982 -atomic_t fscache_n_relinquishes_waitcrt;
48983 -atomic_t fscache_n_relinquishes_retire;
48984 +atomic_unchecked_t fscache_n_relinquishes;
48985 +atomic_unchecked_t fscache_n_relinquishes_null;
48986 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48987 +atomic_unchecked_t fscache_n_relinquishes_retire;
48988
48989 -atomic_t fscache_n_cookie_index;
48990 -atomic_t fscache_n_cookie_data;
48991 -atomic_t fscache_n_cookie_special;
48992 +atomic_unchecked_t fscache_n_cookie_index;
48993 +atomic_unchecked_t fscache_n_cookie_data;
48994 +atomic_unchecked_t fscache_n_cookie_special;
48995
48996 -atomic_t fscache_n_object_alloc;
48997 -atomic_t fscache_n_object_no_alloc;
48998 -atomic_t fscache_n_object_lookups;
48999 -atomic_t fscache_n_object_lookups_negative;
49000 -atomic_t fscache_n_object_lookups_positive;
49001 -atomic_t fscache_n_object_lookups_timed_out;
49002 -atomic_t fscache_n_object_created;
49003 -atomic_t fscache_n_object_avail;
49004 -atomic_t fscache_n_object_dead;
49005 +atomic_unchecked_t fscache_n_object_alloc;
49006 +atomic_unchecked_t fscache_n_object_no_alloc;
49007 +atomic_unchecked_t fscache_n_object_lookups;
49008 +atomic_unchecked_t fscache_n_object_lookups_negative;
49009 +atomic_unchecked_t fscache_n_object_lookups_positive;
49010 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
49011 +atomic_unchecked_t fscache_n_object_created;
49012 +atomic_unchecked_t fscache_n_object_avail;
49013 +atomic_unchecked_t fscache_n_object_dead;
49014
49015 -atomic_t fscache_n_checkaux_none;
49016 -atomic_t fscache_n_checkaux_okay;
49017 -atomic_t fscache_n_checkaux_update;
49018 -atomic_t fscache_n_checkaux_obsolete;
49019 +atomic_unchecked_t fscache_n_checkaux_none;
49020 +atomic_unchecked_t fscache_n_checkaux_okay;
49021 +atomic_unchecked_t fscache_n_checkaux_update;
49022 +atomic_unchecked_t fscache_n_checkaux_obsolete;
49023
49024 atomic_t fscache_n_cop_alloc_object;
49025 atomic_t fscache_n_cop_lookup_object;
49026 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49027 seq_puts(m, "FS-Cache statistics\n");
49028
49029 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49030 - atomic_read(&fscache_n_cookie_index),
49031 - atomic_read(&fscache_n_cookie_data),
49032 - atomic_read(&fscache_n_cookie_special));
49033 + atomic_read_unchecked(&fscache_n_cookie_index),
49034 + atomic_read_unchecked(&fscache_n_cookie_data),
49035 + atomic_read_unchecked(&fscache_n_cookie_special));
49036
49037 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49038 - atomic_read(&fscache_n_object_alloc),
49039 - atomic_read(&fscache_n_object_no_alloc),
49040 - atomic_read(&fscache_n_object_avail),
49041 - atomic_read(&fscache_n_object_dead));
49042 + atomic_read_unchecked(&fscache_n_object_alloc),
49043 + atomic_read_unchecked(&fscache_n_object_no_alloc),
49044 + atomic_read_unchecked(&fscache_n_object_avail),
49045 + atomic_read_unchecked(&fscache_n_object_dead));
49046 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49047 - atomic_read(&fscache_n_checkaux_none),
49048 - atomic_read(&fscache_n_checkaux_okay),
49049 - atomic_read(&fscache_n_checkaux_update),
49050 - atomic_read(&fscache_n_checkaux_obsolete));
49051 + atomic_read_unchecked(&fscache_n_checkaux_none),
49052 + atomic_read_unchecked(&fscache_n_checkaux_okay),
49053 + atomic_read_unchecked(&fscache_n_checkaux_update),
49054 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49055
49056 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49057 - atomic_read(&fscache_n_marks),
49058 - atomic_read(&fscache_n_uncaches));
49059 + atomic_read_unchecked(&fscache_n_marks),
49060 + atomic_read_unchecked(&fscache_n_uncaches));
49061
49062 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49063 " oom=%u\n",
49064 - atomic_read(&fscache_n_acquires),
49065 - atomic_read(&fscache_n_acquires_null),
49066 - atomic_read(&fscache_n_acquires_no_cache),
49067 - atomic_read(&fscache_n_acquires_ok),
49068 - atomic_read(&fscache_n_acquires_nobufs),
49069 - atomic_read(&fscache_n_acquires_oom));
49070 + atomic_read_unchecked(&fscache_n_acquires),
49071 + atomic_read_unchecked(&fscache_n_acquires_null),
49072 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
49073 + atomic_read_unchecked(&fscache_n_acquires_ok),
49074 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
49075 + atomic_read_unchecked(&fscache_n_acquires_oom));
49076
49077 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49078 - atomic_read(&fscache_n_object_lookups),
49079 - atomic_read(&fscache_n_object_lookups_negative),
49080 - atomic_read(&fscache_n_object_lookups_positive),
49081 - atomic_read(&fscache_n_object_created),
49082 - atomic_read(&fscache_n_object_lookups_timed_out));
49083 + atomic_read_unchecked(&fscache_n_object_lookups),
49084 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
49085 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
49086 + atomic_read_unchecked(&fscache_n_object_created),
49087 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49088
49089 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49090 - atomic_read(&fscache_n_updates),
49091 - atomic_read(&fscache_n_updates_null),
49092 - atomic_read(&fscache_n_updates_run));
49093 + atomic_read_unchecked(&fscache_n_updates),
49094 + atomic_read_unchecked(&fscache_n_updates_null),
49095 + atomic_read_unchecked(&fscache_n_updates_run));
49096
49097 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49098 - atomic_read(&fscache_n_relinquishes),
49099 - atomic_read(&fscache_n_relinquishes_null),
49100 - atomic_read(&fscache_n_relinquishes_waitcrt),
49101 - atomic_read(&fscache_n_relinquishes_retire));
49102 + atomic_read_unchecked(&fscache_n_relinquishes),
49103 + atomic_read_unchecked(&fscache_n_relinquishes_null),
49104 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49105 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
49106
49107 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49108 - atomic_read(&fscache_n_attr_changed),
49109 - atomic_read(&fscache_n_attr_changed_ok),
49110 - atomic_read(&fscache_n_attr_changed_nobufs),
49111 - atomic_read(&fscache_n_attr_changed_nomem),
49112 - atomic_read(&fscache_n_attr_changed_calls));
49113 + atomic_read_unchecked(&fscache_n_attr_changed),
49114 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
49115 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49116 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49117 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
49118
49119 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49120 - atomic_read(&fscache_n_allocs),
49121 - atomic_read(&fscache_n_allocs_ok),
49122 - atomic_read(&fscache_n_allocs_wait),
49123 - atomic_read(&fscache_n_allocs_nobufs),
49124 - atomic_read(&fscache_n_allocs_intr));
49125 + atomic_read_unchecked(&fscache_n_allocs),
49126 + atomic_read_unchecked(&fscache_n_allocs_ok),
49127 + atomic_read_unchecked(&fscache_n_allocs_wait),
49128 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
49129 + atomic_read_unchecked(&fscache_n_allocs_intr));
49130 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49131 - atomic_read(&fscache_n_alloc_ops),
49132 - atomic_read(&fscache_n_alloc_op_waits),
49133 - atomic_read(&fscache_n_allocs_object_dead));
49134 + atomic_read_unchecked(&fscache_n_alloc_ops),
49135 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
49136 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
49137
49138 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49139 " int=%u oom=%u\n",
49140 - atomic_read(&fscache_n_retrievals),
49141 - atomic_read(&fscache_n_retrievals_ok),
49142 - atomic_read(&fscache_n_retrievals_wait),
49143 - atomic_read(&fscache_n_retrievals_nodata),
49144 - atomic_read(&fscache_n_retrievals_nobufs),
49145 - atomic_read(&fscache_n_retrievals_intr),
49146 - atomic_read(&fscache_n_retrievals_nomem));
49147 + atomic_read_unchecked(&fscache_n_retrievals),
49148 + atomic_read_unchecked(&fscache_n_retrievals_ok),
49149 + atomic_read_unchecked(&fscache_n_retrievals_wait),
49150 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
49151 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49152 + atomic_read_unchecked(&fscache_n_retrievals_intr),
49153 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
49154 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49155 - atomic_read(&fscache_n_retrieval_ops),
49156 - atomic_read(&fscache_n_retrieval_op_waits),
49157 - atomic_read(&fscache_n_retrievals_object_dead));
49158 + atomic_read_unchecked(&fscache_n_retrieval_ops),
49159 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49160 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49161
49162 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49163 - atomic_read(&fscache_n_stores),
49164 - atomic_read(&fscache_n_stores_ok),
49165 - atomic_read(&fscache_n_stores_again),
49166 - atomic_read(&fscache_n_stores_nobufs),
49167 - atomic_read(&fscache_n_stores_oom));
49168 + atomic_read_unchecked(&fscache_n_stores),
49169 + atomic_read_unchecked(&fscache_n_stores_ok),
49170 + atomic_read_unchecked(&fscache_n_stores_again),
49171 + atomic_read_unchecked(&fscache_n_stores_nobufs),
49172 + atomic_read_unchecked(&fscache_n_stores_oom));
49173 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49174 - atomic_read(&fscache_n_store_ops),
49175 - atomic_read(&fscache_n_store_calls),
49176 - atomic_read(&fscache_n_store_pages),
49177 - atomic_read(&fscache_n_store_radix_deletes),
49178 - atomic_read(&fscache_n_store_pages_over_limit));
49179 + atomic_read_unchecked(&fscache_n_store_ops),
49180 + atomic_read_unchecked(&fscache_n_store_calls),
49181 + atomic_read_unchecked(&fscache_n_store_pages),
49182 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
49183 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49184
49185 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
49186 - atomic_read(&fscache_n_store_vmscan_not_storing),
49187 - atomic_read(&fscache_n_store_vmscan_gone),
49188 - atomic_read(&fscache_n_store_vmscan_busy),
49189 - atomic_read(&fscache_n_store_vmscan_cancelled));
49190 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49191 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49192 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49193 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
49194
49195 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49196 - atomic_read(&fscache_n_op_pend),
49197 - atomic_read(&fscache_n_op_run),
49198 - atomic_read(&fscache_n_op_enqueue),
49199 - atomic_read(&fscache_n_op_cancelled),
49200 - atomic_read(&fscache_n_op_rejected));
49201 + atomic_read_unchecked(&fscache_n_op_pend),
49202 + atomic_read_unchecked(&fscache_n_op_run),
49203 + atomic_read_unchecked(&fscache_n_op_enqueue),
49204 + atomic_read_unchecked(&fscache_n_op_cancelled),
49205 + atomic_read_unchecked(&fscache_n_op_rejected));
49206 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49207 - atomic_read(&fscache_n_op_deferred_release),
49208 - atomic_read(&fscache_n_op_release),
49209 - atomic_read(&fscache_n_op_gc));
49210 + atomic_read_unchecked(&fscache_n_op_deferred_release),
49211 + atomic_read_unchecked(&fscache_n_op_release),
49212 + atomic_read_unchecked(&fscache_n_op_gc));
49213
49214 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49215 atomic_read(&fscache_n_cop_alloc_object),
49216 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
49217 index ee8d550..7189d8c 100644
49218 --- a/fs/fuse/cuse.c
49219 +++ b/fs/fuse/cuse.c
49220 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
49221 INIT_LIST_HEAD(&cuse_conntbl[i]);
49222
49223 /* inherit and extend fuse_dev_operations */
49224 - cuse_channel_fops = fuse_dev_operations;
49225 - cuse_channel_fops.owner = THIS_MODULE;
49226 - cuse_channel_fops.open = cuse_channel_open;
49227 - cuse_channel_fops.release = cuse_channel_release;
49228 + pax_open_kernel();
49229 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
49230 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
49231 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
49232 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
49233 + pax_close_kernel();
49234
49235 cuse_class = class_create(THIS_MODULE, "cuse");
49236 if (IS_ERR(cuse_class))
49237 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
49238 index 8c23fa7..0e3aac7 100644
49239 --- a/fs/fuse/dev.c
49240 +++ b/fs/fuse/dev.c
49241 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
49242 ret = 0;
49243 pipe_lock(pipe);
49244
49245 - if (!pipe->readers) {
49246 + if (!atomic_read(&pipe->readers)) {
49247 send_sig(SIGPIPE, current, 0);
49248 if (!ret)
49249 ret = -EPIPE;
49250 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
49251 index 324bc08..4fdd56e 100644
49252 --- a/fs/fuse/dir.c
49253 +++ b/fs/fuse/dir.c
49254 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
49255 return link;
49256 }
49257
49258 -static void free_link(char *link)
49259 +static void free_link(const char *link)
49260 {
49261 if (!IS_ERR(link))
49262 free_page((unsigned long) link);
49263 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
49264 index 381893c..3793318 100644
49265 --- a/fs/gfs2/inode.c
49266 +++ b/fs/gfs2/inode.c
49267 @@ -1490,7 +1490,7 @@ out:
49268
49269 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
49270 {
49271 - char *s = nd_get_link(nd);
49272 + const char *s = nd_get_link(nd);
49273 if (!IS_ERR(s))
49274 kfree(s);
49275 }
49276 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
49277 index c5bc355..163a13e 100644
49278 --- a/fs/hugetlbfs/inode.c
49279 +++ b/fs/hugetlbfs/inode.c
49280 @@ -153,6 +153,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
49281 struct vm_area_struct *vma;
49282 unsigned long start_addr;
49283 struct hstate *h = hstate_file(file);
49284 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
49285
49286 if (len & ~huge_page_mask(h))
49287 return -EINVAL;
49288 @@ -165,18 +166,21 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
49289 return addr;
49290 }
49291
49292 +#ifdef CONFIG_PAX_RANDMMAP
49293 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
49294 +#endif
49295 +
49296 if (addr) {
49297 addr = ALIGN(addr, huge_page_size(h));
49298 vma = find_vma(mm, addr);
49299 - if (TASK_SIZE - len >= addr &&
49300 - (!vma || addr + len <= vma->vm_start))
49301 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
49302 return addr;
49303 }
49304
49305 if (len > mm->cached_hole_size)
49306 start_addr = mm->free_area_cache;
49307 else {
49308 - start_addr = TASK_UNMAPPED_BASE;
49309 + start_addr = mm->mmap_base;
49310 mm->cached_hole_size = 0;
49311 }
49312
49313 @@ -190,15 +194,15 @@ full_search:
49314 * Start a new search - just in case we missed
49315 * some holes.
49316 */
49317 - if (start_addr != TASK_UNMAPPED_BASE) {
49318 - start_addr = TASK_UNMAPPED_BASE;
49319 + if (start_addr != mm->mmap_base) {
49320 + start_addr = mm->mmap_base;
49321 mm->cached_hole_size = 0;
49322 goto full_search;
49323 }
49324 return -ENOMEM;
49325 }
49326
49327 - if (!vma || addr + len <= vma->vm_start) {
49328 + if (check_heap_stack_gap(vma, addr, len, offset)) {
49329 mm->free_area_cache = addr + len;
49330 return addr;
49331 }
49332 @@ -923,7 +927,7 @@ static struct file_system_type hugetlbfs_fs_type = {
49333 .kill_sb = kill_litter_super,
49334 };
49335
49336 -static struct vfsmount *hugetlbfs_vfsmount;
49337 +struct vfsmount *hugetlbfs_vfsmount;
49338
49339 static int can_do_hugetlb_shm(void)
49340 {
49341 diff --git a/fs/inode.c b/fs/inode.c
49342 index 64999f1..8fad608 100644
49343 --- a/fs/inode.c
49344 +++ b/fs/inode.c
49345 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
49346
49347 #ifdef CONFIG_SMP
49348 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
49349 - static atomic_t shared_last_ino;
49350 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
49351 + static atomic_unchecked_t shared_last_ino;
49352 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
49353
49354 res = next - LAST_INO_BATCH;
49355 }
49356 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
49357 index 4a6cf28..d3a29d3 100644
49358 --- a/fs/jffs2/erase.c
49359 +++ b/fs/jffs2/erase.c
49360 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
49361 struct jffs2_unknown_node marker = {
49362 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
49363 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49364 - .totlen = cpu_to_je32(c->cleanmarker_size)
49365 + .totlen = cpu_to_je32(c->cleanmarker_size),
49366 + .hdr_crc = cpu_to_je32(0)
49367 };
49368
49369 jffs2_prealloc_raw_node_refs(c, jeb, 1);
49370 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
49371 index a6597d6..41b30ec 100644
49372 --- a/fs/jffs2/wbuf.c
49373 +++ b/fs/jffs2/wbuf.c
49374 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
49375 {
49376 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
49377 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49378 - .totlen = constant_cpu_to_je32(8)
49379 + .totlen = constant_cpu_to_je32(8),
49380 + .hdr_crc = constant_cpu_to_je32(0)
49381 };
49382
49383 /*
49384 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
49385 index 1a543be..d803c40 100644
49386 --- a/fs/jfs/super.c
49387 +++ b/fs/jfs/super.c
49388 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
49389
49390 jfs_inode_cachep =
49391 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
49392 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
49393 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
49394 init_once);
49395 if (jfs_inode_cachep == NULL)
49396 return -ENOMEM;
49397 diff --git a/fs/libfs.c b/fs/libfs.c
49398 index 7cc37ca..b3e3eec 100644
49399 --- a/fs/libfs.c
49400 +++ b/fs/libfs.c
49401 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49402
49403 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49404 struct dentry *next;
49405 + char d_name[sizeof(next->d_iname)];
49406 + const unsigned char *name;
49407 +
49408 next = list_entry(p, struct dentry, d_u.d_child);
49409 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49410 if (!simple_positive(next)) {
49411 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49412
49413 spin_unlock(&next->d_lock);
49414 spin_unlock(&dentry->d_lock);
49415 - if (filldir(dirent, next->d_name.name,
49416 + name = next->d_name.name;
49417 + if (name == next->d_iname) {
49418 + memcpy(d_name, name, next->d_name.len);
49419 + name = d_name;
49420 + }
49421 + if (filldir(dirent, name,
49422 next->d_name.len, filp->f_pos,
49423 next->d_inode->i_ino,
49424 dt_type(next->d_inode)) < 0)
49425 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49426 index 05d2912..760abfa 100644
49427 --- a/fs/lockd/clntproc.c
49428 +++ b/fs/lockd/clntproc.c
49429 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49430 /*
49431 * Cookie counter for NLM requests
49432 */
49433 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49434 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49435
49436 void nlmclnt_next_cookie(struct nlm_cookie *c)
49437 {
49438 - u32 cookie = atomic_inc_return(&nlm_cookie);
49439 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49440
49441 memcpy(c->data, &cookie, 4);
49442 c->len=4;
49443 diff --git a/fs/locks.c b/fs/locks.c
49444 index a94e331..060bce3 100644
49445 --- a/fs/locks.c
49446 +++ b/fs/locks.c
49447 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49448 return;
49449
49450 if (filp->f_op && filp->f_op->flock) {
49451 - struct file_lock fl = {
49452 + struct file_lock flock = {
49453 .fl_pid = current->tgid,
49454 .fl_file = filp,
49455 .fl_flags = FL_FLOCK,
49456 .fl_type = F_UNLCK,
49457 .fl_end = OFFSET_MAX,
49458 };
49459 - filp->f_op->flock(filp, F_SETLKW, &fl);
49460 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
49461 - fl.fl_ops->fl_release_private(&fl);
49462 + filp->f_op->flock(filp, F_SETLKW, &flock);
49463 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
49464 + flock.fl_ops->fl_release_private(&flock);
49465 }
49466
49467 lock_flocks();
49468 diff --git a/fs/namei.c b/fs/namei.c
49469 index 5f4cdf3..959a013 100644
49470 --- a/fs/namei.c
49471 +++ b/fs/namei.c
49472 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49473 if (ret != -EACCES)
49474 return ret;
49475
49476 +#ifdef CONFIG_GRKERNSEC
49477 + /* we'll block if we have to log due to a denied capability use */
49478 + if (mask & MAY_NOT_BLOCK)
49479 + return -ECHILD;
49480 +#endif
49481 +
49482 if (S_ISDIR(inode->i_mode)) {
49483 /* DACs are overridable for directories */
49484 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
49485 - return 0;
49486 if (!(mask & MAY_WRITE))
49487 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49488 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49489 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49490 return 0;
49491 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
49492 + return 0;
49493 return -EACCES;
49494 }
49495 /*
49496 + * Searching includes executable on directories, else just read.
49497 + */
49498 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49499 + if (mask == MAY_READ)
49500 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49501 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49502 + return 0;
49503 +
49504 + /*
49505 * Read/write DACs are always overridable.
49506 * Executable DACs are overridable when there is
49507 * at least one exec bit set.
49508 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49509 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49510 return 0;
49511
49512 - /*
49513 - * Searching includes executable on directories, else just read.
49514 - */
49515 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49516 - if (mask == MAY_READ)
49517 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49518 - return 0;
49519 -
49520 return -EACCES;
49521 }
49522
49523 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49524 {
49525 struct dentry *dentry = link->dentry;
49526 int error;
49527 - char *s;
49528 + const char *s;
49529
49530 BUG_ON(nd->flags & LOOKUP_RCU);
49531
49532 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49533 if (error)
49534 goto out_put_nd_path;
49535
49536 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
49537 + dentry->d_inode, dentry, nd->path.mnt)) {
49538 + error = -EACCES;
49539 + goto out_put_nd_path;
49540 + }
49541 +
49542 nd->last_type = LAST_BIND;
49543 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49544 error = PTR_ERR(*p);
49545 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49546 break;
49547 res = walk_component(nd, path, &nd->last,
49548 nd->last_type, LOOKUP_FOLLOW);
49549 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49550 + res = -EACCES;
49551 put_link(nd, &link, cookie);
49552 } while (res > 0);
49553
49554 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49555 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49556 {
49557 unsigned long a, b, adata, bdata, mask, hash, len;
49558 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49559 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49560
49561 hash = a = 0;
49562 len = -sizeof(unsigned long);
49563 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49564 if (err)
49565 break;
49566 err = lookup_last(nd, &path);
49567 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
49568 + err = -EACCES;
49569 put_link(nd, &link, cookie);
49570 }
49571 }
49572 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49573 if (!err)
49574 err = complete_walk(nd);
49575
49576 + if (!(nd->flags & LOOKUP_PARENT)) {
49577 +#ifdef CONFIG_GRKERNSEC
49578 + if (flags & LOOKUP_RCU) {
49579 + if (!err)
49580 + path_put(&nd->path);
49581 + err = -ECHILD;
49582 + } else
49583 +#endif
49584 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49585 + if (!err)
49586 + path_put(&nd->path);
49587 + err = -ENOENT;
49588 + }
49589 + }
49590 +
49591 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49592 if (!nd->inode->i_op->lookup) {
49593 path_put(&nd->path);
49594 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49595 retval = path_lookupat(dfd, name->name,
49596 flags | LOOKUP_REVAL, nd);
49597
49598 - if (likely(!retval))
49599 + if (likely(!retval)) {
49600 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49601 +#ifdef CONFIG_GRKERNSEC
49602 + if (flags & LOOKUP_RCU)
49603 + return -ECHILD;
49604 +#endif
49605 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49606 + return -ENOENT;
49607 + }
49608 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49609 + }
49610 return retval;
49611 }
49612
49613 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49614 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49615 return -EPERM;
49616
49617 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49618 + return -EPERM;
49619 + if (gr_handle_rawio(inode))
49620 + return -EPERM;
49621 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49622 + return -EACCES;
49623 +
49624 return 0;
49625 }
49626
49627 @@ -2623,7 +2672,7 @@ looked_up:
49628 * cleared otherwise prior to returning.
49629 */
49630 static int lookup_open(struct nameidata *nd, struct path *path,
49631 - struct file *file,
49632 + struct path *link, struct file *file,
49633 const struct open_flags *op,
49634 bool got_write, int *opened)
49635 {
49636 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49637 /* Negative dentry, just create the file */
49638 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49639 umode_t mode = op->mode;
49640 +
49641 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49642 + error = -EACCES;
49643 + goto out_dput;
49644 + }
49645 +
49646 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49647 + error = -EACCES;
49648 + goto out_dput;
49649 + }
49650 +
49651 if (!IS_POSIXACL(dir->d_inode))
49652 mode &= ~current_umask();
49653 /*
49654 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49655 nd->flags & LOOKUP_EXCL);
49656 if (error)
49657 goto out_dput;
49658 + else
49659 + gr_handle_create(dentry, nd->path.mnt);
49660 }
49661 out_no_open:
49662 path->dentry = dentry;
49663 @@ -2693,7 +2755,7 @@ out_dput:
49664 /*
49665 * Handle the last step of open()
49666 */
49667 -static int do_last(struct nameidata *nd, struct path *path,
49668 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49669 struct file *file, const struct open_flags *op,
49670 int *opened, struct filename *name)
49671 {
49672 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49673 error = complete_walk(nd);
49674 if (error)
49675 return error;
49676 +#ifdef CONFIG_GRKERNSEC
49677 + if (nd->flags & LOOKUP_RCU) {
49678 + error = -ECHILD;
49679 + goto out;
49680 + }
49681 +#endif
49682 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49683 + error = -ENOENT;
49684 + goto out;
49685 + }
49686 audit_inode(name, nd->path.dentry, 0);
49687 if (open_flag & O_CREAT) {
49688 error = -EISDIR;
49689 goto out;
49690 }
49691 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49692 + error = -EACCES;
49693 + goto out;
49694 + }
49695 goto finish_open;
49696 case LAST_BIND:
49697 error = complete_walk(nd);
49698 if (error)
49699 return error;
49700 +#ifdef CONFIG_GRKERNSEC
49701 + if (nd->flags & LOOKUP_RCU) {
49702 + error = -ECHILD;
49703 + goto out;
49704 + }
49705 +#endif
49706 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49707 + error = -ENOENT;
49708 + goto out;
49709 + }
49710 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49711 + error = -EACCES;
49712 + goto out;
49713 + }
49714 audit_inode(name, dir, 0);
49715 goto finish_open;
49716 }
49717 @@ -2780,7 +2870,7 @@ retry_lookup:
49718 */
49719 }
49720 mutex_lock(&dir->d_inode->i_mutex);
49721 - error = lookup_open(nd, path, file, op, got_write, opened);
49722 + error = lookup_open(nd, path, link, file, op, got_write, opened);
49723 mutex_unlock(&dir->d_inode->i_mutex);
49724
49725 if (error <= 0) {
49726 @@ -2804,11 +2894,28 @@ retry_lookup:
49727 goto finish_open_created;
49728 }
49729
49730 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49731 + error = -ENOENT;
49732 + goto exit_dput;
49733 + }
49734 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49735 + error = -EACCES;
49736 + goto exit_dput;
49737 + }
49738 +
49739 /*
49740 * create/update audit record if it already exists.
49741 */
49742 - if (path->dentry->d_inode)
49743 + if (path->dentry->d_inode) {
49744 + /* only check if O_CREAT is specified, all other checks need to go
49745 + into may_open */
49746 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49747 + error = -EACCES;
49748 + goto exit_dput;
49749 + }
49750 +
49751 audit_inode(name, path->dentry, 0);
49752 + }
49753
49754 /*
49755 * If atomic_open() acquired write access it is dropped now due to
49756 @@ -2849,6 +2956,11 @@ finish_lookup:
49757 }
49758 }
49759 BUG_ON(inode != path->dentry->d_inode);
49760 + /* if we're resolving a symlink to another symlink */
49761 + if (link && gr_handle_symlink_owner(link, inode)) {
49762 + error = -EACCES;
49763 + goto out;
49764 + }
49765 return 1;
49766 }
49767
49768 @@ -2858,7 +2970,6 @@ finish_lookup:
49769 save_parent.dentry = nd->path.dentry;
49770 save_parent.mnt = mntget(path->mnt);
49771 nd->path.dentry = path->dentry;
49772 -
49773 }
49774 nd->inode = inode;
49775 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49776 @@ -2867,6 +2978,22 @@ finish_lookup:
49777 path_put(&save_parent);
49778 return error;
49779 }
49780 +
49781 +#ifdef CONFIG_GRKERNSEC
49782 + if (nd->flags & LOOKUP_RCU) {
49783 + error = -ECHILD;
49784 + goto out;
49785 + }
49786 +#endif
49787 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49788 + error = -ENOENT;
49789 + goto out;
49790 + }
49791 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49792 + error = -EACCES;
49793 + goto out;
49794 + }
49795 +
49796 error = -EISDIR;
49797 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49798 goto out;
49799 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49800 if (unlikely(error))
49801 goto out;
49802
49803 - error = do_last(nd, &path, file, op, &opened, pathname);
49804 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49805 while (unlikely(error > 0)) { /* trailing symlink */
49806 struct path link = path;
49807 void *cookie;
49808 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49809 error = follow_link(&link, nd, &cookie);
49810 if (unlikely(error))
49811 break;
49812 - error = do_last(nd, &path, file, op, &opened, pathname);
49813 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
49814 put_link(nd, &link, cookie);
49815 }
49816 out:
49817 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49818 goto unlock;
49819
49820 error = -EEXIST;
49821 - if (dentry->d_inode)
49822 + if (dentry->d_inode) {
49823 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49824 + error = -ENOENT;
49825 + }
49826 goto fail;
49827 + }
49828 /*
49829 * Special case - lookup gave negative, but... we had foo/bar/
49830 * From the vfs_mknod() POV we just have a negative dentry -
49831 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49832 }
49833 EXPORT_SYMBOL(user_path_create);
49834
49835 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49836 +{
49837 + struct filename *tmp = getname(pathname);
49838 + struct dentry *res;
49839 + if (IS_ERR(tmp))
49840 + return ERR_CAST(tmp);
49841 + res = kern_path_create(dfd, tmp->name, path, is_dir);
49842 + if (IS_ERR(res))
49843 + putname(tmp);
49844 + else
49845 + *to = tmp;
49846 + return res;
49847 +}
49848 +
49849 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49850 {
49851 int error = may_create(dir, dentry);
49852 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49853
49854 if (!IS_POSIXACL(path.dentry->d_inode))
49855 mode &= ~current_umask();
49856 +
49857 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49858 + error = -EPERM;
49859 + goto out;
49860 + }
49861 +
49862 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49863 + error = -EACCES;
49864 + goto out;
49865 + }
49866 +
49867 error = security_path_mknod(&path, dentry, mode, dev);
49868 if (error)
49869 goto out;
49870 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49871 break;
49872 }
49873 out:
49874 + if (!error)
49875 + gr_handle_create(dentry, path.mnt);
49876 done_path_create(&path, dentry);
49877 return error;
49878 }
49879 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49880
49881 if (!IS_POSIXACL(path.dentry->d_inode))
49882 mode &= ~current_umask();
49883 +
49884 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49885 + error = -EACCES;
49886 + goto out;
49887 + }
49888 +
49889 error = security_path_mkdir(&path, dentry, mode);
49890 if (!error)
49891 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49892 + if (!error)
49893 + gr_handle_create(dentry, path.mnt);
49894 +out:
49895 done_path_create(&path, dentry);
49896 return error;
49897 }
49898 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49899 struct filename *name;
49900 struct dentry *dentry;
49901 struct nameidata nd;
49902 + ino_t saved_ino = 0;
49903 + dev_t saved_dev = 0;
49904
49905 name = user_path_parent(dfd, pathname, &nd);
49906 if (IS_ERR(name))
49907 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49908 error = -ENOENT;
49909 goto exit3;
49910 }
49911 +
49912 + saved_ino = dentry->d_inode->i_ino;
49913 + saved_dev = gr_get_dev_from_dentry(dentry);
49914 +
49915 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49916 + error = -EACCES;
49917 + goto exit3;
49918 + }
49919 +
49920 error = security_path_rmdir(&nd.path, dentry);
49921 if (error)
49922 goto exit3;
49923 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49924 + if (!error && (saved_dev || saved_ino))
49925 + gr_handle_delete(saved_ino, saved_dev);
49926 exit3:
49927 dput(dentry);
49928 exit2:
49929 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49930 struct dentry *dentry;
49931 struct nameidata nd;
49932 struct inode *inode = NULL;
49933 + ino_t saved_ino = 0;
49934 + dev_t saved_dev = 0;
49935
49936 name = user_path_parent(dfd, pathname, &nd);
49937 if (IS_ERR(name))
49938 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49939 if (!inode)
49940 goto slashes;
49941 ihold(inode);
49942 +
49943 + if (inode->i_nlink <= 1) {
49944 + saved_ino = inode->i_ino;
49945 + saved_dev = gr_get_dev_from_dentry(dentry);
49946 + }
49947 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
49948 + error = -EACCES;
49949 + goto exit2;
49950 + }
49951 +
49952 error = security_path_unlink(&nd.path, dentry);
49953 if (error)
49954 goto exit2;
49955 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
49956 + if (!error && (saved_ino || saved_dev))
49957 + gr_handle_delete(saved_ino, saved_dev);
49958 exit2:
49959 dput(dentry);
49960 }
49961 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
49962 if (IS_ERR(dentry))
49963 goto out_putname;
49964
49965 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
49966 + error = -EACCES;
49967 + goto out;
49968 + }
49969 +
49970 error = security_path_symlink(&path, dentry, from->name);
49971 if (!error)
49972 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
49973 + if (!error)
49974 + gr_handle_create(dentry, path.mnt);
49975 +out:
49976 done_path_create(&path, dentry);
49977 out_putname:
49978 putname(from);
49979 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49980 {
49981 struct dentry *new_dentry;
49982 struct path old_path, new_path;
49983 + struct filename *to = NULL;
49984 int how = 0;
49985 int error;
49986
49987 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49988 if (error)
49989 return error;
49990
49991 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
49992 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
49993 error = PTR_ERR(new_dentry);
49994 if (IS_ERR(new_dentry))
49995 goto out;
49996 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49997 error = may_linkat(&old_path);
49998 if (unlikely(error))
49999 goto out_dput;
50000 +
50001 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
50002 + old_path.dentry->d_inode,
50003 + old_path.dentry->d_inode->i_mode, to)) {
50004 + error = -EACCES;
50005 + goto out_dput;
50006 + }
50007 +
50008 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50009 + old_path.dentry, old_path.mnt, to)) {
50010 + error = -EACCES;
50011 + goto out_dput;
50012 + }
50013 +
50014 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50015 if (error)
50016 goto out_dput;
50017 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50018 + if (!error)
50019 + gr_handle_create(new_dentry, new_path.mnt);
50020 out_dput:
50021 + putname(to);
50022 done_path_create(&new_path, new_dentry);
50023 out:
50024 path_put(&old_path);
50025 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
50026 if (new_dentry == trap)
50027 goto exit5;
50028
50029 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50030 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
50031 + to);
50032 + if (error)
50033 + goto exit5;
50034 +
50035 error = security_path_rename(&oldnd.path, old_dentry,
50036 &newnd.path, new_dentry);
50037 if (error)
50038 goto exit5;
50039 error = vfs_rename(old_dir->d_inode, old_dentry,
50040 new_dir->d_inode, new_dentry);
50041 + if (!error)
50042 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50043 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50044 exit5:
50045 dput(new_dentry);
50046 exit4:
50047 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50048
50049 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50050 {
50051 + char tmpbuf[64];
50052 + const char *newlink;
50053 int len;
50054
50055 len = PTR_ERR(link);
50056 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50057 len = strlen(link);
50058 if (len > (unsigned) buflen)
50059 len = buflen;
50060 - if (copy_to_user(buffer, link, len))
50061 +
50062 + if (len < sizeof(tmpbuf)) {
50063 + memcpy(tmpbuf, link, len);
50064 + newlink = tmpbuf;
50065 + } else
50066 + newlink = link;
50067 +
50068 + if (copy_to_user(buffer, newlink, len))
50069 len = -EFAULT;
50070 out:
50071 return len;
50072 diff --git a/fs/namespace.c b/fs/namespace.c
50073 index 2496062..e26f6d6 100644
50074 --- a/fs/namespace.c
50075 +++ b/fs/namespace.c
50076 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
50077 if (!(sb->s_flags & MS_RDONLY))
50078 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50079 up_write(&sb->s_umount);
50080 +
50081 + gr_log_remount(mnt->mnt_devname, retval);
50082 +
50083 return retval;
50084 }
50085
50086 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
50087 br_write_unlock(&vfsmount_lock);
50088 up_write(&namespace_sem);
50089 release_mounts(&umount_list);
50090 +
50091 + gr_log_unmount(mnt->mnt_devname, retval);
50092 +
50093 return retval;
50094 }
50095
50096 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50097 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50098 MS_STRICTATIME);
50099
50100 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50101 + retval = -EPERM;
50102 + goto dput_out;
50103 + }
50104 +
50105 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50106 + retval = -EPERM;
50107 + goto dput_out;
50108 + }
50109 +
50110 if (flags & MS_REMOUNT)
50111 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50112 data_page);
50113 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50114 dev_name, data_page);
50115 dput_out:
50116 path_put(&path);
50117 +
50118 + gr_log_mount(dev_name, dir_name, retval);
50119 +
50120 return retval;
50121 }
50122
50123 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50124 if (error)
50125 goto out2;
50126
50127 + if (gr_handle_chroot_pivot()) {
50128 + error = -EPERM;
50129 + goto out2;
50130 + }
50131 +
50132 get_fs_root(current->fs, &root);
50133 error = lock_mount(&old);
50134 if (error)
50135 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50136 index 6fa01ae..2790820 100644
50137 --- a/fs/nfs/inode.c
50138 +++ b/fs/nfs/inode.c
50139 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
50140 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
50141 }
50142
50143 -static atomic_long_t nfs_attr_generation_counter;
50144 +static atomic_long_unchecked_t nfs_attr_generation_counter;
50145
50146 static unsigned long nfs_read_attr_generation_counter(void)
50147 {
50148 - return atomic_long_read(&nfs_attr_generation_counter);
50149 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
50150 }
50151
50152 unsigned long nfs_inc_attr_generation_counter(void)
50153 {
50154 - return atomic_long_inc_return(&nfs_attr_generation_counter);
50155 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
50156 }
50157
50158 void nfs_fattr_init(struct nfs_fattr *fattr)
50159 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
50160 index f59169e..fd7d359 100644
50161 --- a/fs/nfsd/vfs.c
50162 +++ b/fs/nfsd/vfs.c
50163 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50164 } else {
50165 oldfs = get_fs();
50166 set_fs(KERNEL_DS);
50167 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
50168 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
50169 set_fs(oldfs);
50170 }
50171
50172 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50173
50174 /* Write the data. */
50175 oldfs = get_fs(); set_fs(KERNEL_DS);
50176 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
50177 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
50178 set_fs(oldfs);
50179 if (host_err < 0)
50180 goto out_nfserr;
50181 @@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
50182 */
50183
50184 oldfs = get_fs(); set_fs(KERNEL_DS);
50185 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
50186 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
50187 set_fs(oldfs);
50188
50189 if (host_err < 0)
50190 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
50191 index 6fcaeb8..9d16d04 100644
50192 --- a/fs/notify/fanotify/fanotify_user.c
50193 +++ b/fs/notify/fanotify/fanotify_user.c
50194 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
50195
50196 fd = fanotify_event_metadata.fd;
50197 ret = -EFAULT;
50198 - if (copy_to_user(buf, &fanotify_event_metadata,
50199 - fanotify_event_metadata.event_len))
50200 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
50201 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
50202 goto out_close_fd;
50203
50204 ret = prepare_for_access_response(group, event, fd);
50205 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
50206 index c887b13..0fdf472 100644
50207 --- a/fs/notify/notification.c
50208 +++ b/fs/notify/notification.c
50209 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
50210 * get set to 0 so it will never get 'freed'
50211 */
50212 static struct fsnotify_event *q_overflow_event;
50213 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50214 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50215
50216 /**
50217 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
50218 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50219 */
50220 u32 fsnotify_get_cookie(void)
50221 {
50222 - return atomic_inc_return(&fsnotify_sync_cookie);
50223 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
50224 }
50225 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
50226
50227 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
50228 index 99e3610..02c1068 100644
50229 --- a/fs/ntfs/dir.c
50230 +++ b/fs/ntfs/dir.c
50231 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
50232 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
50233 ~(s64)(ndir->itype.index.block_size - 1)));
50234 /* Bounds checks. */
50235 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50236 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50237 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
50238 "inode 0x%lx or driver bug.", vdir->i_ino);
50239 goto err_out;
50240 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
50241 index 1ecf464..e1ff8bf 100644
50242 --- a/fs/ntfs/file.c
50243 +++ b/fs/ntfs/file.c
50244 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
50245 #endif /* NTFS_RW */
50246 };
50247
50248 -const struct file_operations ntfs_empty_file_ops = {};
50249 +const struct file_operations ntfs_empty_file_ops __read_only;
50250
50251 -const struct inode_operations ntfs_empty_inode_ops = {};
50252 +const struct inode_operations ntfs_empty_inode_ops __read_only;
50253 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
50254 index a9f78c7..ed8a381 100644
50255 --- a/fs/ocfs2/localalloc.c
50256 +++ b/fs/ocfs2/localalloc.c
50257 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
50258 goto bail;
50259 }
50260
50261 - atomic_inc(&osb->alloc_stats.moves);
50262 + atomic_inc_unchecked(&osb->alloc_stats.moves);
50263
50264 bail:
50265 if (handle)
50266 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
50267 index d355e6e..578d905 100644
50268 --- a/fs/ocfs2/ocfs2.h
50269 +++ b/fs/ocfs2/ocfs2.h
50270 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
50271
50272 struct ocfs2_alloc_stats
50273 {
50274 - atomic_t moves;
50275 - atomic_t local_data;
50276 - atomic_t bitmap_data;
50277 - atomic_t bg_allocs;
50278 - atomic_t bg_extends;
50279 + atomic_unchecked_t moves;
50280 + atomic_unchecked_t local_data;
50281 + atomic_unchecked_t bitmap_data;
50282 + atomic_unchecked_t bg_allocs;
50283 + atomic_unchecked_t bg_extends;
50284 };
50285
50286 enum ocfs2_local_alloc_state
50287 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
50288 index f169da4..9112253 100644
50289 --- a/fs/ocfs2/suballoc.c
50290 +++ b/fs/ocfs2/suballoc.c
50291 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
50292 mlog_errno(status);
50293 goto bail;
50294 }
50295 - atomic_inc(&osb->alloc_stats.bg_extends);
50296 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
50297
50298 /* You should never ask for this much metadata */
50299 BUG_ON(bits_wanted >
50300 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
50301 mlog_errno(status);
50302 goto bail;
50303 }
50304 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50305 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50306
50307 *suballoc_loc = res.sr_bg_blkno;
50308 *suballoc_bit_start = res.sr_bit_offset;
50309 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
50310 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
50311 res->sr_bits);
50312
50313 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50314 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50315
50316 BUG_ON(res->sr_bits != 1);
50317
50318 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
50319 mlog_errno(status);
50320 goto bail;
50321 }
50322 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50323 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50324
50325 BUG_ON(res.sr_bits != 1);
50326
50327 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50328 cluster_start,
50329 num_clusters);
50330 if (!status)
50331 - atomic_inc(&osb->alloc_stats.local_data);
50332 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
50333 } else {
50334 if (min_clusters > (osb->bitmap_cpg - 1)) {
50335 /* The only paths asking for contiguousness
50336 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50337 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
50338 res.sr_bg_blkno,
50339 res.sr_bit_offset);
50340 - atomic_inc(&osb->alloc_stats.bitmap_data);
50341 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
50342 *num_clusters = res.sr_bits;
50343 }
50344 }
50345 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
50346 index 0e91ec2..f4b3fc6 100644
50347 --- a/fs/ocfs2/super.c
50348 +++ b/fs/ocfs2/super.c
50349 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
50350 "%10s => GlobalAllocs: %d LocalAllocs: %d "
50351 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
50352 "Stats",
50353 - atomic_read(&osb->alloc_stats.bitmap_data),
50354 - atomic_read(&osb->alloc_stats.local_data),
50355 - atomic_read(&osb->alloc_stats.bg_allocs),
50356 - atomic_read(&osb->alloc_stats.moves),
50357 - atomic_read(&osb->alloc_stats.bg_extends));
50358 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
50359 + atomic_read_unchecked(&osb->alloc_stats.local_data),
50360 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
50361 + atomic_read_unchecked(&osb->alloc_stats.moves),
50362 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
50363
50364 out += snprintf(buf + out, len - out,
50365 "%10s => State: %u Descriptor: %llu Size: %u bits "
50366 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
50367 spin_lock_init(&osb->osb_xattr_lock);
50368 ocfs2_init_steal_slots(osb);
50369
50370 - atomic_set(&osb->alloc_stats.moves, 0);
50371 - atomic_set(&osb->alloc_stats.local_data, 0);
50372 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
50373 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
50374 - atomic_set(&osb->alloc_stats.bg_extends, 0);
50375 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
50376 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
50377 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
50378 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
50379 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
50380
50381 /* Copy the blockcheck stats from the superblock probe */
50382 osb->osb_ecc_stats = *stats;
50383 diff --git a/fs/open.c b/fs/open.c
50384 index 59071f5..c6229a0 100644
50385 --- a/fs/open.c
50386 +++ b/fs/open.c
50387 @@ -31,6 +31,8 @@
50388 #include <linux/ima.h>
50389 #include <linux/dnotify.h>
50390
50391 +#define CREATE_TRACE_POINTS
50392 +#include <trace/events/fs.h>
50393 #include "internal.h"
50394
50395 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
50396 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
50397 error = locks_verify_truncate(inode, NULL, length);
50398 if (!error)
50399 error = security_path_truncate(&path);
50400 +
50401 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50402 + error = -EACCES;
50403 +
50404 if (!error)
50405 error = do_truncate(path.dentry, length, 0, NULL);
50406
50407 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50408 if (__mnt_is_readonly(path.mnt))
50409 res = -EROFS;
50410
50411 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50412 + res = -EACCES;
50413 +
50414 out_path_release:
50415 path_put(&path);
50416 out:
50417 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50418 if (error)
50419 goto dput_and_out;
50420
50421 + gr_log_chdir(path.dentry, path.mnt);
50422 +
50423 set_fs_pwd(current->fs, &path);
50424
50425 dput_and_out:
50426 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50427 goto out_putf;
50428
50429 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50430 +
50431 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50432 + error = -EPERM;
50433 +
50434 + if (!error)
50435 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50436 +
50437 if (!error)
50438 set_fs_pwd(current->fs, &f.file->f_path);
50439 out_putf:
50440 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50441 if (error)
50442 goto dput_and_out;
50443
50444 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50445 + goto dput_and_out;
50446 +
50447 set_fs_root(current->fs, &path);
50448 +
50449 + gr_handle_chroot_chdir(&path);
50450 +
50451 error = 0;
50452 dput_and_out:
50453 path_put(&path);
50454 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50455 if (error)
50456 return error;
50457 mutex_lock(&inode->i_mutex);
50458 +
50459 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50460 + error = -EACCES;
50461 + goto out_unlock;
50462 + }
50463 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50464 + error = -EACCES;
50465 + goto out_unlock;
50466 + }
50467 +
50468 error = security_path_chmod(path, mode);
50469 if (error)
50470 goto out_unlock;
50471 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50472 uid = make_kuid(current_user_ns(), user);
50473 gid = make_kgid(current_user_ns(), group);
50474
50475 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
50476 + return -EACCES;
50477 +
50478 newattrs.ia_valid = ATTR_CTIME;
50479 if (user != (uid_t) -1) {
50480 if (!uid_valid(uid))
50481 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50482 } else {
50483 fsnotify_open(f);
50484 fd_install(fd, f);
50485 + trace_do_sys_open(tmp->name, flags, mode);
50486 }
50487 }
50488 putname(tmp);
50489 diff --git a/fs/pipe.c b/fs/pipe.c
50490 index bd3479d..fb92c4d 100644
50491 --- a/fs/pipe.c
50492 +++ b/fs/pipe.c
50493 @@ -438,9 +438,9 @@ redo:
50494 }
50495 if (bufs) /* More to do? */
50496 continue;
50497 - if (!pipe->writers)
50498 + if (!atomic_read(&pipe->writers))
50499 break;
50500 - if (!pipe->waiting_writers) {
50501 + if (!atomic_read(&pipe->waiting_writers)) {
50502 /* syscall merging: Usually we must not sleep
50503 * if O_NONBLOCK is set, or if we got some data.
50504 * But if a writer sleeps in kernel space, then
50505 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50506 mutex_lock(&inode->i_mutex);
50507 pipe = inode->i_pipe;
50508
50509 - if (!pipe->readers) {
50510 + if (!atomic_read(&pipe->readers)) {
50511 send_sig(SIGPIPE, current, 0);
50512 ret = -EPIPE;
50513 goto out;
50514 @@ -553,7 +553,7 @@ redo1:
50515 for (;;) {
50516 int bufs;
50517
50518 - if (!pipe->readers) {
50519 + if (!atomic_read(&pipe->readers)) {
50520 send_sig(SIGPIPE, current, 0);
50521 if (!ret)
50522 ret = -EPIPE;
50523 @@ -644,9 +644,9 @@ redo2:
50524 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50525 do_wakeup = 0;
50526 }
50527 - pipe->waiting_writers++;
50528 + atomic_inc(&pipe->waiting_writers);
50529 pipe_wait(pipe);
50530 - pipe->waiting_writers--;
50531 + atomic_dec(&pipe->waiting_writers);
50532 }
50533 out:
50534 mutex_unlock(&inode->i_mutex);
50535 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50536 mask = 0;
50537 if (filp->f_mode & FMODE_READ) {
50538 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50539 - if (!pipe->writers && filp->f_version != pipe->w_counter)
50540 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50541 mask |= POLLHUP;
50542 }
50543
50544 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50545 * Most Unices do not set POLLERR for FIFOs but on Linux they
50546 * behave exactly like pipes for poll().
50547 */
50548 - if (!pipe->readers)
50549 + if (!atomic_read(&pipe->readers))
50550 mask |= POLLERR;
50551 }
50552
50553 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50554
50555 mutex_lock(&inode->i_mutex);
50556 pipe = inode->i_pipe;
50557 - pipe->readers -= decr;
50558 - pipe->writers -= decw;
50559 + atomic_sub(decr, &pipe->readers);
50560 + atomic_sub(decw, &pipe->writers);
50561
50562 - if (!pipe->readers && !pipe->writers) {
50563 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50564 free_pipe_info(inode);
50565 } else {
50566 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50567 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50568
50569 if (inode->i_pipe) {
50570 ret = 0;
50571 - inode->i_pipe->readers++;
50572 + atomic_inc(&inode->i_pipe->readers);
50573 }
50574
50575 mutex_unlock(&inode->i_mutex);
50576 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50577
50578 if (inode->i_pipe) {
50579 ret = 0;
50580 - inode->i_pipe->writers++;
50581 + atomic_inc(&inode->i_pipe->writers);
50582 }
50583
50584 mutex_unlock(&inode->i_mutex);
50585 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50586 if (inode->i_pipe) {
50587 ret = 0;
50588 if (filp->f_mode & FMODE_READ)
50589 - inode->i_pipe->readers++;
50590 + atomic_inc(&inode->i_pipe->readers);
50591 if (filp->f_mode & FMODE_WRITE)
50592 - inode->i_pipe->writers++;
50593 + atomic_inc(&inode->i_pipe->writers);
50594 }
50595
50596 mutex_unlock(&inode->i_mutex);
50597 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50598 inode->i_pipe = NULL;
50599 }
50600
50601 -static struct vfsmount *pipe_mnt __read_mostly;
50602 +struct vfsmount *pipe_mnt __read_mostly;
50603
50604 /*
50605 * pipefs_dname() is called from d_path().
50606 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50607 goto fail_iput;
50608 inode->i_pipe = pipe;
50609
50610 - pipe->readers = pipe->writers = 1;
50611 + atomic_set(&pipe->readers, 1);
50612 + atomic_set(&pipe->writers, 1);
50613 inode->i_fop = &rdwr_pipefifo_fops;
50614
50615 /*
50616 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50617 index 15af622..0e9f4467 100644
50618 --- a/fs/proc/Kconfig
50619 +++ b/fs/proc/Kconfig
50620 @@ -30,12 +30,12 @@ config PROC_FS
50621
50622 config PROC_KCORE
50623 bool "/proc/kcore support" if !ARM
50624 - depends on PROC_FS && MMU
50625 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50626
50627 config PROC_VMCORE
50628 bool "/proc/vmcore support"
50629 - depends on PROC_FS && CRASH_DUMP
50630 - default y
50631 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50632 + default n
50633 help
50634 Exports the dump image of crashed kernel in ELF format.
50635
50636 @@ -59,8 +59,8 @@ config PROC_SYSCTL
50637 limited in memory.
50638
50639 config PROC_PAGE_MONITOR
50640 - default y
50641 - depends on PROC_FS && MMU
50642 + default n
50643 + depends on PROC_FS && MMU && !GRKERNSEC
50644 bool "Enable /proc page monitoring" if EXPERT
50645 help
50646 Various /proc files exist to monitor process memory utilization:
50647 diff --git a/fs/proc/array.c b/fs/proc/array.c
50648 index bd31e02..15cae71 100644
50649 --- a/fs/proc/array.c
50650 +++ b/fs/proc/array.c
50651 @@ -60,6 +60,7 @@
50652 #include <linux/tty.h>
50653 #include <linux/string.h>
50654 #include <linux/mman.h>
50655 +#include <linux/grsecurity.h>
50656 #include <linux/proc_fs.h>
50657 #include <linux/ioport.h>
50658 #include <linux/uaccess.h>
50659 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50660 seq_putc(m, '\n');
50661 }
50662
50663 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50664 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
50665 +{
50666 + if (p->mm)
50667 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50668 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50669 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50670 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50671 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50672 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50673 + else
50674 + seq_printf(m, "PaX:\t-----\n");
50675 +}
50676 +#endif
50677 +
50678 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50679 struct pid *pid, struct task_struct *task)
50680 {
50681 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50682 task_cpus_allowed(m, task);
50683 cpuset_task_status_allowed(m, task);
50684 task_context_switch_counts(m, task);
50685 +
50686 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50687 + task_pax(m, task);
50688 +#endif
50689 +
50690 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50691 + task_grsec_rbac(m, task);
50692 +#endif
50693 +
50694 return 0;
50695 }
50696
50697 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50698 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50699 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50700 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50701 +#endif
50702 +
50703 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50704 struct pid *pid, struct task_struct *task, int whole)
50705 {
50706 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50707 char tcomm[sizeof(task->comm)];
50708 unsigned long flags;
50709
50710 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50711 + if (current->exec_id != m->exec_id) {
50712 + gr_log_badprocpid("stat");
50713 + return 0;
50714 + }
50715 +#endif
50716 +
50717 state = *get_task_state(task);
50718 vsize = eip = esp = 0;
50719 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50720 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50721 gtime = task->gtime;
50722 }
50723
50724 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50725 + if (PAX_RAND_FLAGS(mm)) {
50726 + eip = 0;
50727 + esp = 0;
50728 + wchan = 0;
50729 + }
50730 +#endif
50731 +#ifdef CONFIG_GRKERNSEC_HIDESYM
50732 + wchan = 0;
50733 + eip =0;
50734 + esp =0;
50735 +#endif
50736 +
50737 /* scale priority and nice values from timeslices to -20..20 */
50738 /* to make it look like a "normal" Unix priority/nice value */
50739 priority = task_prio(task);
50740 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50741 seq_put_decimal_ull(m, ' ', vsize);
50742 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50743 seq_put_decimal_ull(m, ' ', rsslim);
50744 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50745 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50746 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50747 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50748 +#else
50749 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50750 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50751 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50752 +#endif
50753 seq_put_decimal_ull(m, ' ', esp);
50754 seq_put_decimal_ull(m, ' ', eip);
50755 /* The signal information here is obsolete.
50756 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50757 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50758 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50759
50760 - if (mm && permitted) {
50761 + if (mm && permitted
50762 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50763 + && !PAX_RAND_FLAGS(mm)
50764 +#endif
50765 + ) {
50766 seq_put_decimal_ull(m, ' ', mm->start_data);
50767 seq_put_decimal_ull(m, ' ', mm->end_data);
50768 seq_put_decimal_ull(m, ' ', mm->start_brk);
50769 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50770 struct pid *pid, struct task_struct *task)
50771 {
50772 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50773 - struct mm_struct *mm = get_task_mm(task);
50774 + struct mm_struct *mm;
50775
50776 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50777 + if (current->exec_id != m->exec_id) {
50778 + gr_log_badprocpid("statm");
50779 + return 0;
50780 + }
50781 +#endif
50782 + mm = get_task_mm(task);
50783 if (mm) {
50784 size = task_statm(mm, &shared, &text, &data, &resident);
50785 mmput(mm);
50786 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50787 return 0;
50788 }
50789
50790 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50791 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50792 +{
50793 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50794 +}
50795 +#endif
50796 +
50797 #ifdef CONFIG_CHECKPOINT_RESTORE
50798 static struct pid *
50799 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50800 diff --git a/fs/proc/base.c b/fs/proc/base.c
50801 index 9e28356..c485b3c 100644
50802 --- a/fs/proc/base.c
50803 +++ b/fs/proc/base.c
50804 @@ -111,6 +111,14 @@ struct pid_entry {
50805 union proc_op op;
50806 };
50807
50808 +struct getdents_callback {
50809 + struct linux_dirent __user * current_dir;
50810 + struct linux_dirent __user * previous;
50811 + struct file * file;
50812 + int count;
50813 + int error;
50814 +};
50815 +
50816 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50817 .name = (NAME), \
50818 .len = sizeof(NAME) - 1, \
50819 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50820 if (!mm->arg_end)
50821 goto out_mm; /* Shh! No looking before we're done */
50822
50823 + if (gr_acl_handle_procpidmem(task))
50824 + goto out_mm;
50825 +
50826 len = mm->arg_end - mm->arg_start;
50827
50828 if (len > PAGE_SIZE)
50829 @@ -235,12 +246,28 @@ out:
50830 return res;
50831 }
50832
50833 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50834 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50835 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50836 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50837 +#endif
50838 +
50839 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50840 {
50841 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50842 int res = PTR_ERR(mm);
50843 if (mm && !IS_ERR(mm)) {
50844 unsigned int nwords = 0;
50845 +
50846 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50847 + /* allow if we're currently ptracing this task */
50848 + if (PAX_RAND_FLAGS(mm) &&
50849 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50850 + mmput(mm);
50851 + return 0;
50852 + }
50853 +#endif
50854 +
50855 do {
50856 nwords += 2;
50857 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50858 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50859 }
50860
50861
50862 -#ifdef CONFIG_KALLSYMS
50863 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50864 /*
50865 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50866 * Returns the resolved symbol. If that fails, simply return the address.
50867 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50868 mutex_unlock(&task->signal->cred_guard_mutex);
50869 }
50870
50871 -#ifdef CONFIG_STACKTRACE
50872 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50873
50874 #define MAX_STACK_TRACE_DEPTH 64
50875
50876 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50877 return count;
50878 }
50879
50880 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50881 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50882 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50883 {
50884 long nr;
50885 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50886 /************************************************************************/
50887
50888 /* permission checks */
50889 -static int proc_fd_access_allowed(struct inode *inode)
50890 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50891 {
50892 struct task_struct *task;
50893 int allowed = 0;
50894 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50895 */
50896 task = get_proc_task(inode);
50897 if (task) {
50898 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50899 + if (log)
50900 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50901 + else
50902 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50903 put_task_struct(task);
50904 }
50905 return allowed;
50906 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50907 struct task_struct *task,
50908 int hide_pid_min)
50909 {
50910 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50911 + return false;
50912 +
50913 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50914 + rcu_read_lock();
50915 + {
50916 + const struct cred *tmpcred = current_cred();
50917 + const struct cred *cred = __task_cred(task);
50918 +
50919 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50920 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50921 + || in_group_p(grsec_proc_gid)
50922 +#endif
50923 + ) {
50924 + rcu_read_unlock();
50925 + return true;
50926 + }
50927 + }
50928 + rcu_read_unlock();
50929 +
50930 + if (!pid->hide_pid)
50931 + return false;
50932 +#endif
50933 +
50934 if (pid->hide_pid < hide_pid_min)
50935 return true;
50936 if (in_group_p(pid->pid_gid))
50937 return true;
50938 +
50939 return ptrace_may_access(task, PTRACE_MODE_READ);
50940 }
50941
50942 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
50943 put_task_struct(task);
50944
50945 if (!has_perms) {
50946 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50947 + {
50948 +#else
50949 if (pid->hide_pid == 2) {
50950 +#endif
50951 /*
50952 * Let's make getdents(), stat(), and open()
50953 * consistent with each other. If a process
50954 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50955 if (!task)
50956 return -ESRCH;
50957
50958 + if (gr_acl_handle_procpidmem(task)) {
50959 + put_task_struct(task);
50960 + return -EPERM;
50961 + }
50962 +
50963 mm = mm_access(task, mode);
50964 put_task_struct(task);
50965
50966 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50967
50968 file->private_data = mm;
50969
50970 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50971 + file->f_version = current->exec_id;
50972 +#endif
50973 +
50974 return 0;
50975 }
50976
50977 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
50978 ssize_t copied;
50979 char *page;
50980
50981 +#ifdef CONFIG_GRKERNSEC
50982 + if (write)
50983 + return -EPERM;
50984 +#endif
50985 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50986 + if (file->f_version != current->exec_id) {
50987 + gr_log_badprocpid("mem");
50988 + return 0;
50989 + }
50990 +#endif
50991 +
50992 if (!mm)
50993 return 0;
50994
50995 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
50996 if (!mm)
50997 return 0;
50998
50999 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51000 + if (file->f_version != current->exec_id) {
51001 + gr_log_badprocpid("environ");
51002 + return 0;
51003 + }
51004 +#endif
51005 +
51006 page = (char *)__get_free_page(GFP_TEMPORARY);
51007 if (!page)
51008 return -ENOMEM;
51009 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51010 int error = -EACCES;
51011
51012 /* Are we allowed to snoop on the tasks file descriptors? */
51013 - if (!proc_fd_access_allowed(inode))
51014 + if (!proc_fd_access_allowed(inode, 0))
51015 goto out;
51016
51017 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51018 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51019 struct path path;
51020
51021 /* Are we allowed to snoop on the tasks file descriptors? */
51022 - if (!proc_fd_access_allowed(inode))
51023 - goto out;
51024 + /* logging this is needed for learning on chromium to work properly,
51025 + but we don't want to flood the logs from 'ps' which does a readlink
51026 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51027 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
51028 + */
51029 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51030 + if (!proc_fd_access_allowed(inode,0))
51031 + goto out;
51032 + } else {
51033 + if (!proc_fd_access_allowed(inode,1))
51034 + goto out;
51035 + }
51036
51037 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51038 if (error)
51039 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51040 rcu_read_lock();
51041 cred = __task_cred(task);
51042 inode->i_uid = cred->euid;
51043 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51044 + inode->i_gid = grsec_proc_gid;
51045 +#else
51046 inode->i_gid = cred->egid;
51047 +#endif
51048 rcu_read_unlock();
51049 }
51050 security_task_to_inode(task, inode);
51051 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51052 return -ENOENT;
51053 }
51054 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51055 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51056 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51057 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51058 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51059 +#endif
51060 task_dumpable(task)) {
51061 cred = __task_cred(task);
51062 stat->uid = cred->euid;
51063 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51064 + stat->gid = grsec_proc_gid;
51065 +#else
51066 stat->gid = cred->egid;
51067 +#endif
51068 }
51069 }
51070 rcu_read_unlock();
51071 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51072
51073 if (task) {
51074 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51075 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51076 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51077 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51078 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51079 +#endif
51080 task_dumpable(task)) {
51081 rcu_read_lock();
51082 cred = __task_cred(task);
51083 inode->i_uid = cred->euid;
51084 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51085 + inode->i_gid = grsec_proc_gid;
51086 +#else
51087 inode->i_gid = cred->egid;
51088 +#endif
51089 rcu_read_unlock();
51090 } else {
51091 inode->i_uid = GLOBAL_ROOT_UID;
51092 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51093 if (!task)
51094 goto out_no_task;
51095
51096 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51097 + goto out;
51098 +
51099 /*
51100 * Yes, it does not scale. And it should not. Don't add
51101 * new entries into /proc/<tgid>/ without very good reasons.
51102 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
51103 if (!task)
51104 goto out_no_task;
51105
51106 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51107 + goto out;
51108 +
51109 ret = 0;
51110 i = filp->f_pos;
51111 switch (i) {
51112 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
51113 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
51114 void *cookie)
51115 {
51116 - char *s = nd_get_link(nd);
51117 + const char *s = nd_get_link(nd);
51118 if (!IS_ERR(s))
51119 kfree(s);
51120 }
51121 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51122 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51123 #endif
51124 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51125 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51126 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51127 INF("syscall", S_IRUGO, proc_pid_syscall),
51128 #endif
51129 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51130 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51131 #ifdef CONFIG_SECURITY
51132 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51133 #endif
51134 -#ifdef CONFIG_KALLSYMS
51135 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51136 INF("wchan", S_IRUGO, proc_pid_wchan),
51137 #endif
51138 -#ifdef CONFIG_STACKTRACE
51139 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51140 ONE("stack", S_IRUGO, proc_pid_stack),
51141 #endif
51142 #ifdef CONFIG_SCHEDSTATS
51143 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
51144 #ifdef CONFIG_HARDWALL
51145 INF("hardwall", S_IRUGO, proc_pid_hardwall),
51146 #endif
51147 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51148 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
51149 +#endif
51150 #ifdef CONFIG_USER_NS
51151 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
51152 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
51153 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
51154 if (!inode)
51155 goto out;
51156
51157 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51158 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
51159 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51160 + inode->i_gid = grsec_proc_gid;
51161 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
51162 +#else
51163 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
51164 +#endif
51165 inode->i_op = &proc_tgid_base_inode_operations;
51166 inode->i_fop = &proc_tgid_base_operations;
51167 inode->i_flags|=S_IMMUTABLE;
51168 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
51169 if (!task)
51170 goto out;
51171
51172 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51173 + goto out_put_task;
51174 +
51175 result = proc_pid_instantiate(dir, dentry, task, NULL);
51176 +out_put_task:
51177 put_task_struct(task);
51178 out:
51179 return result;
51180 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
51181 static int fake_filldir(void *buf, const char *name, int namelen,
51182 loff_t offset, u64 ino, unsigned d_type)
51183 {
51184 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
51185 + __buf->error = -EINVAL;
51186 return 0;
51187 }
51188
51189 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
51190 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
51191 #endif
51192 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51193 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51194 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51195 INF("syscall", S_IRUGO, proc_pid_syscall),
51196 #endif
51197 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51198 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
51199 #ifdef CONFIG_SECURITY
51200 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51201 #endif
51202 -#ifdef CONFIG_KALLSYMS
51203 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51204 INF("wchan", S_IRUGO, proc_pid_wchan),
51205 #endif
51206 -#ifdef CONFIG_STACKTRACE
51207 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51208 ONE("stack", S_IRUGO, proc_pid_stack),
51209 #endif
51210 #ifdef CONFIG_SCHEDSTATS
51211 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
51212 index 82676e3..5f8518a 100644
51213 --- a/fs/proc/cmdline.c
51214 +++ b/fs/proc/cmdline.c
51215 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
51216
51217 static int __init proc_cmdline_init(void)
51218 {
51219 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51220 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
51221 +#else
51222 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
51223 +#endif
51224 return 0;
51225 }
51226 module_init(proc_cmdline_init);
51227 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
51228 index b143471..bb105e5 100644
51229 --- a/fs/proc/devices.c
51230 +++ b/fs/proc/devices.c
51231 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
51232
51233 static int __init proc_devices_init(void)
51234 {
51235 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51236 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
51237 +#else
51238 proc_create("devices", 0, NULL, &proc_devinfo_operations);
51239 +#endif
51240 return 0;
51241 }
51242 module_init(proc_devices_init);
51243 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
51244 index f28a875..c467953 100644
51245 --- a/fs/proc/fd.c
51246 +++ b/fs/proc/fd.c
51247 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
51248 if (!task)
51249 return -ENOENT;
51250
51251 - files = get_files_struct(task);
51252 + if (!gr_acl_handle_procpidmem(task))
51253 + files = get_files_struct(task);
51254 put_task_struct(task);
51255
51256 if (files) {
51257 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
51258 */
51259 int proc_fd_permission(struct inode *inode, int mask)
51260 {
51261 + struct task_struct *task;
51262 int rv = generic_permission(inode, mask);
51263 - if (rv == 0)
51264 - return 0;
51265 +
51266 if (task_pid(current) == proc_pid(inode))
51267 rv = 0;
51268 +
51269 + task = get_proc_task(inode);
51270 + if (task == NULL)
51271 + return rv;
51272 +
51273 + if (gr_acl_handle_procpidmem(task))
51274 + rv = -EACCES;
51275 +
51276 + put_task_struct(task);
51277 +
51278 return rv;
51279 }
51280
51281 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
51282 index 3b22bbd..895b58c 100644
51283 --- a/fs/proc/inode.c
51284 +++ b/fs/proc/inode.c
51285 @@ -21,11 +21,17 @@
51286 #include <linux/seq_file.h>
51287 #include <linux/slab.h>
51288 #include <linux/mount.h>
51289 +#include <linux/grsecurity.h>
51290
51291 #include <asm/uaccess.h>
51292
51293 #include "internal.h"
51294
51295 +#ifdef CONFIG_PROC_SYSCTL
51296 +extern const struct inode_operations proc_sys_inode_operations;
51297 +extern const struct inode_operations proc_sys_dir_operations;
51298 +#endif
51299 +
51300 static void proc_evict_inode(struct inode *inode)
51301 {
51302 struct proc_dir_entry *de;
51303 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
51304 ns_ops = PROC_I(inode)->ns_ops;
51305 if (ns_ops && ns_ops->put)
51306 ns_ops->put(PROC_I(inode)->ns);
51307 +
51308 +#ifdef CONFIG_PROC_SYSCTL
51309 + if (inode->i_op == &proc_sys_inode_operations ||
51310 + inode->i_op == &proc_sys_dir_operations)
51311 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
51312 +#endif
51313 +
51314 }
51315
51316 static struct kmem_cache * proc_inode_cachep;
51317 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
51318 if (de->mode) {
51319 inode->i_mode = de->mode;
51320 inode->i_uid = de->uid;
51321 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51322 + inode->i_gid = grsec_proc_gid;
51323 +#else
51324 inode->i_gid = de->gid;
51325 +#endif
51326 }
51327 if (de->size)
51328 inode->i_size = de->size;
51329 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
51330 index 43973b0..a20e704 100644
51331 --- a/fs/proc/internal.h
51332 +++ b/fs/proc/internal.h
51333 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51334 struct pid *pid, struct task_struct *task);
51335 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51336 struct pid *pid, struct task_struct *task);
51337 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51338 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
51339 +#endif
51340 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
51341
51342 extern const struct file_operations proc_tid_children_operations;
51343 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
51344 index 86c67ee..cdca321 100644
51345 --- a/fs/proc/kcore.c
51346 +++ b/fs/proc/kcore.c
51347 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51348 * the addresses in the elf_phdr on our list.
51349 */
51350 start = kc_offset_to_vaddr(*fpos - elf_buflen);
51351 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
51352 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
51353 + if (tsz > buflen)
51354 tsz = buflen;
51355 -
51356 +
51357 while (buflen) {
51358 struct kcore_list *m;
51359
51360 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51361 kfree(elf_buf);
51362 } else {
51363 if (kern_addr_valid(start)) {
51364 - unsigned long n;
51365 + char *elf_buf;
51366 + mm_segment_t oldfs;
51367
51368 - n = copy_to_user(buffer, (char *)start, tsz);
51369 - /*
51370 - * We cannot distinguish between fault on source
51371 - * and fault on destination. When this happens
51372 - * we clear too and hope it will trigger the
51373 - * EFAULT again.
51374 - */
51375 - if (n) {
51376 - if (clear_user(buffer + tsz - n,
51377 - n))
51378 + elf_buf = kmalloc(tsz, GFP_KERNEL);
51379 + if (!elf_buf)
51380 + return -ENOMEM;
51381 + oldfs = get_fs();
51382 + set_fs(KERNEL_DS);
51383 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
51384 + set_fs(oldfs);
51385 + if (copy_to_user(buffer, elf_buf, tsz)) {
51386 + kfree(elf_buf);
51387 return -EFAULT;
51388 + }
51389 }
51390 + set_fs(oldfs);
51391 + kfree(elf_buf);
51392 } else {
51393 if (clear_user(buffer, tsz))
51394 return -EFAULT;
51395 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51396
51397 static int open_kcore(struct inode *inode, struct file *filp)
51398 {
51399 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51400 + return -EPERM;
51401 +#endif
51402 if (!capable(CAP_SYS_RAWIO))
51403 return -EPERM;
51404 if (kcore_need_update)
51405 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51406 index 80e4645..53e5fcf 100644
51407 --- a/fs/proc/meminfo.c
51408 +++ b/fs/proc/meminfo.c
51409 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51410 vmi.used >> 10,
51411 vmi.largest_chunk >> 10
51412 #ifdef CONFIG_MEMORY_FAILURE
51413 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51414 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51415 #endif
51416 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51417 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51418 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51419 index b1822dd..df622cb 100644
51420 --- a/fs/proc/nommu.c
51421 +++ b/fs/proc/nommu.c
51422 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51423 if (len < 1)
51424 len = 1;
51425 seq_printf(m, "%*c", len, ' ');
51426 - seq_path(m, &file->f_path, "");
51427 + seq_path(m, &file->f_path, "\n\\");
51428 }
51429
51430 seq_putc(m, '\n');
51431 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51432 index fe72cd0..cb9b67d 100644
51433 --- a/fs/proc/proc_net.c
51434 +++ b/fs/proc/proc_net.c
51435 @@ -23,6 +23,7 @@
51436 #include <linux/nsproxy.h>
51437 #include <net/net_namespace.h>
51438 #include <linux/seq_file.h>
51439 +#include <linux/grsecurity.h>
51440
51441 #include "internal.h"
51442
51443 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51444 struct task_struct *task;
51445 struct nsproxy *ns;
51446 struct net *net = NULL;
51447 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51448 + const struct cred *cred = current_cred();
51449 +#endif
51450 +
51451 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51452 + if (cred->fsuid)
51453 + return net;
51454 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51455 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
51456 + return net;
51457 +#endif
51458
51459 rcu_read_lock();
51460 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51461 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51462 index a781bdf..6665284 100644
51463 --- a/fs/proc/proc_sysctl.c
51464 +++ b/fs/proc/proc_sysctl.c
51465 @@ -12,11 +12,15 @@
51466 #include <linux/module.h>
51467 #include "internal.h"
51468
51469 +extern int gr_handle_chroot_sysctl(const int op);
51470 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51471 + const int op);
51472 +
51473 static const struct dentry_operations proc_sys_dentry_operations;
51474 static const struct file_operations proc_sys_file_operations;
51475 -static const struct inode_operations proc_sys_inode_operations;
51476 +const struct inode_operations proc_sys_inode_operations;
51477 static const struct file_operations proc_sys_dir_file_operations;
51478 -static const struct inode_operations proc_sys_dir_operations;
51479 +const struct inode_operations proc_sys_dir_operations;
51480
51481 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51482 {
51483 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51484
51485 err = NULL;
51486 d_set_d_op(dentry, &proc_sys_dentry_operations);
51487 +
51488 + gr_handle_proc_create(dentry, inode);
51489 +
51490 d_add(dentry, inode);
51491
51492 out:
51493 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51494 struct inode *inode = filp->f_path.dentry->d_inode;
51495 struct ctl_table_header *head = grab_header(inode);
51496 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51497 + int op = write ? MAY_WRITE : MAY_READ;
51498 ssize_t error;
51499 size_t res;
51500
51501 if (IS_ERR(head))
51502 return PTR_ERR(head);
51503
51504 +
51505 /*
51506 * At this point we know that the sysctl was not unregistered
51507 * and won't be until we finish.
51508 */
51509 error = -EPERM;
51510 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51511 + if (sysctl_perm(head->root, table, op))
51512 goto out;
51513
51514 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51515 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51516 if (!table->proc_handler)
51517 goto out;
51518
51519 +#ifdef CONFIG_GRKERNSEC
51520 + error = -EPERM;
51521 + if (gr_handle_chroot_sysctl(op))
51522 + goto out;
51523 + dget(filp->f_path.dentry);
51524 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51525 + dput(filp->f_path.dentry);
51526 + goto out;
51527 + }
51528 + dput(filp->f_path.dentry);
51529 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51530 + goto out;
51531 + if (write && !capable(CAP_SYS_ADMIN))
51532 + goto out;
51533 +#endif
51534 +
51535 /* careful: calling conventions are nasty here */
51536 res = count;
51537 error = table->proc_handler(table, write, buf, &res, ppos);
51538 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51539 return -ENOMEM;
51540 } else {
51541 d_set_d_op(child, &proc_sys_dentry_operations);
51542 +
51543 + gr_handle_proc_create(child, inode);
51544 +
51545 d_add(child, inode);
51546 }
51547 } else {
51548 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51549 if ((*pos)++ < file->f_pos)
51550 return 0;
51551
51552 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51553 + return 0;
51554 +
51555 if (unlikely(S_ISLNK(table->mode)))
51556 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51557 else
51558 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51559 if (IS_ERR(head))
51560 return PTR_ERR(head);
51561
51562 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51563 + return -ENOENT;
51564 +
51565 generic_fillattr(inode, stat);
51566 if (table)
51567 stat->mode = (stat->mode & S_IFMT) | table->mode;
51568 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51569 .llseek = generic_file_llseek,
51570 };
51571
51572 -static const struct inode_operations proc_sys_inode_operations = {
51573 +const struct inode_operations proc_sys_inode_operations = {
51574 .permission = proc_sys_permission,
51575 .setattr = proc_sys_setattr,
51576 .getattr = proc_sys_getattr,
51577 };
51578
51579 -static const struct inode_operations proc_sys_dir_operations = {
51580 +const struct inode_operations proc_sys_dir_operations = {
51581 .lookup = proc_sys_lookup,
51582 .permission = proc_sys_permission,
51583 .setattr = proc_sys_setattr,
51584 diff --git a/fs/proc/root.c b/fs/proc/root.c
51585 index 9889a92..2613b48 100644
51586 --- a/fs/proc/root.c
51587 +++ b/fs/proc/root.c
51588 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
51589 #ifdef CONFIG_PROC_DEVICETREE
51590 proc_device_tree_init();
51591 #endif
51592 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51593 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51594 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51595 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51596 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51597 +#endif
51598 +#else
51599 proc_mkdir("bus", NULL);
51600 +#endif
51601 proc_sys_init();
51602 }
51603
51604 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51605 index 90c63f9..e662cfc 100644
51606 --- a/fs/proc/task_mmu.c
51607 +++ b/fs/proc/task_mmu.c
51608 @@ -11,12 +11,19 @@
51609 #include <linux/rmap.h>
51610 #include <linux/swap.h>
51611 #include <linux/swapops.h>
51612 +#include <linux/grsecurity.h>
51613
51614 #include <asm/elf.h>
51615 #include <asm/uaccess.h>
51616 #include <asm/tlbflush.h>
51617 #include "internal.h"
51618
51619 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51620 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51621 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51622 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51623 +#endif
51624 +
51625 void task_mem(struct seq_file *m, struct mm_struct *mm)
51626 {
51627 unsigned long data, text, lib, swap;
51628 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51629 "VmExe:\t%8lu kB\n"
51630 "VmLib:\t%8lu kB\n"
51631 "VmPTE:\t%8lu kB\n"
51632 - "VmSwap:\t%8lu kB\n",
51633 - hiwater_vm << (PAGE_SHIFT-10),
51634 + "VmSwap:\t%8lu kB\n"
51635 +
51636 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51637 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51638 +#endif
51639 +
51640 + ,hiwater_vm << (PAGE_SHIFT-10),
51641 total_vm << (PAGE_SHIFT-10),
51642 mm->locked_vm << (PAGE_SHIFT-10),
51643 mm->pinned_vm << (PAGE_SHIFT-10),
51644 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51645 data << (PAGE_SHIFT-10),
51646 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51647 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51648 - swap << (PAGE_SHIFT-10));
51649 + swap << (PAGE_SHIFT-10)
51650 +
51651 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51652 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51653 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51654 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51655 +#else
51656 + , mm->context.user_cs_base
51657 + , mm->context.user_cs_limit
51658 +#endif
51659 +#endif
51660 +
51661 + );
51662 }
51663
51664 unsigned long task_vsize(struct mm_struct *mm)
51665 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51666 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51667 }
51668
51669 - /* We don't show the stack guard page in /proc/maps */
51670 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51671 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51672 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51673 +#else
51674 start = vma->vm_start;
51675 - if (stack_guard_page_start(vma, start))
51676 - start += PAGE_SIZE;
51677 end = vma->vm_end;
51678 - if (stack_guard_page_end(vma, end))
51679 - end -= PAGE_SIZE;
51680 +#endif
51681
51682 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51683 start,
51684 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51685 flags & VM_WRITE ? 'w' : '-',
51686 flags & VM_EXEC ? 'x' : '-',
51687 flags & VM_MAYSHARE ? 's' : 'p',
51688 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51689 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51690 +#else
51691 pgoff,
51692 +#endif
51693 MAJOR(dev), MINOR(dev), ino, &len);
51694
51695 /*
51696 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51697 */
51698 if (file) {
51699 pad_len_spaces(m, len);
51700 - seq_path(m, &file->f_path, "\n");
51701 + seq_path(m, &file->f_path, "\n\\");
51702 goto done;
51703 }
51704
51705 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51706 * Thread stack in /proc/PID/task/TID/maps or
51707 * the main process stack.
51708 */
51709 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
51710 - vma->vm_end >= mm->start_stack)) {
51711 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51712 + (vma->vm_start <= mm->start_stack &&
51713 + vma->vm_end >= mm->start_stack)) {
51714 name = "[stack]";
51715 } else {
51716 /* Thread stack in /proc/PID/maps */
51717 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51718 struct proc_maps_private *priv = m->private;
51719 struct task_struct *task = priv->task;
51720
51721 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51722 + if (current->exec_id != m->exec_id) {
51723 + gr_log_badprocpid("maps");
51724 + return 0;
51725 + }
51726 +#endif
51727 +
51728 show_map_vma(m, vma, is_pid);
51729
51730 if (m->count < m->size) /* vma is copied successfully */
51731 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51732 .private = &mss,
51733 };
51734
51735 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51736 + if (current->exec_id != m->exec_id) {
51737 + gr_log_badprocpid("smaps");
51738 + return 0;
51739 + }
51740 +#endif
51741 memset(&mss, 0, sizeof mss);
51742 - mss.vma = vma;
51743 - /* mmap_sem is held in m_start */
51744 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51745 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51746 -
51747 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51748 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51749 +#endif
51750 + mss.vma = vma;
51751 + /* mmap_sem is held in m_start */
51752 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51753 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51754 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51755 + }
51756 +#endif
51757 show_map_vma(m, vma, is_pid);
51758
51759 seq_printf(m,
51760 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51761 "KernelPageSize: %8lu kB\n"
51762 "MMUPageSize: %8lu kB\n"
51763 "Locked: %8lu kB\n",
51764 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51765 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51766 +#else
51767 (vma->vm_end - vma->vm_start) >> 10,
51768 +#endif
51769 mss.resident >> 10,
51770 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51771 mss.shared_clean >> 10,
51772 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51773 int n;
51774 char buffer[50];
51775
51776 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51777 + if (current->exec_id != m->exec_id) {
51778 + gr_log_badprocpid("numa_maps");
51779 + return 0;
51780 + }
51781 +#endif
51782 +
51783 if (!mm)
51784 return 0;
51785
51786 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51787 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51788 mpol_cond_put(pol);
51789
51790 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51791 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51792 +#else
51793 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51794 +#endif
51795
51796 if (file) {
51797 seq_printf(m, " file=");
51798 - seq_path(m, &file->f_path, "\n\t= ");
51799 + seq_path(m, &file->f_path, "\n\t\\= ");
51800 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51801 seq_printf(m, " heap");
51802 } else {
51803 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51804 index 1ccfa53..0848f95 100644
51805 --- a/fs/proc/task_nommu.c
51806 +++ b/fs/proc/task_nommu.c
51807 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51808 else
51809 bytes += kobjsize(mm);
51810
51811 - if (current->fs && current->fs->users > 1)
51812 + if (current->fs && atomic_read(&current->fs->users) > 1)
51813 sbytes += kobjsize(current->fs);
51814 else
51815 bytes += kobjsize(current->fs);
51816 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51817
51818 if (file) {
51819 pad_len_spaces(m, len);
51820 - seq_path(m, &file->f_path, "");
51821 + seq_path(m, &file->f_path, "\n\\");
51822 } else if (mm) {
51823 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51824
51825 diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51826 index 2d57e1a..43b1280 100644
51827 --- a/fs/pstore/ftrace.c
51828 +++ b/fs/pstore/ftrace.c
51829 @@ -28,7 +28,9 @@
51830 #include "internal.h"
51831
51832 static void notrace pstore_ftrace_call(unsigned long ip,
51833 - unsigned long parent_ip)
51834 + unsigned long parent_ip,
51835 + struct ftrace_ops *op,
51836 + struct pt_regs *regs)
51837 {
51838 unsigned long flags;
51839 struct pstore_ftrace_record rec = {};
51840 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51841 index 16e8abb..2dcf914 100644
51842 --- a/fs/quota/netlink.c
51843 +++ b/fs/quota/netlink.c
51844 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51845 void quota_send_warning(struct kqid qid, dev_t dev,
51846 const char warntype)
51847 {
51848 - static atomic_t seq;
51849 + static atomic_unchecked_t seq;
51850 struct sk_buff *skb;
51851 void *msg_head;
51852 int ret;
51853 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51854 "VFS: Not enough memory to send quota warning.\n");
51855 return;
51856 }
51857 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51858 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51859 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51860 if (!msg_head) {
51861 printk(KERN_ERR
51862 diff --git a/fs/read_write.c b/fs/read_write.c
51863 index d065348..8e2b43d 100644
51864 --- a/fs/read_write.c
51865 +++ b/fs/read_write.c
51866 @@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51867 if (retval > 0) {
51868 add_rchar(current, retval);
51869 add_wchar(current, retval);
51870 + fsnotify_access(in.file);
51871 + fsnotify_modify(out.file);
51872 }
51873
51874 inc_syscr(current);
51875 diff --git a/fs/readdir.c b/fs/readdir.c
51876 index 5e69ef5..e5d9099 100644
51877 --- a/fs/readdir.c
51878 +++ b/fs/readdir.c
51879 @@ -17,6 +17,7 @@
51880 #include <linux/security.h>
51881 #include <linux/syscalls.h>
51882 #include <linux/unistd.h>
51883 +#include <linux/namei.h>
51884
51885 #include <asm/uaccess.h>
51886
51887 @@ -67,6 +68,7 @@ struct old_linux_dirent {
51888
51889 struct readdir_callback {
51890 struct old_linux_dirent __user * dirent;
51891 + struct file * file;
51892 int result;
51893 };
51894
51895 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51896 buf->result = -EOVERFLOW;
51897 return -EOVERFLOW;
51898 }
51899 +
51900 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51901 + return 0;
51902 +
51903 buf->result++;
51904 dirent = buf->dirent;
51905 if (!access_ok(VERIFY_WRITE, dirent,
51906 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51907
51908 buf.result = 0;
51909 buf.dirent = dirent;
51910 + buf.file = f.file;
51911
51912 error = vfs_readdir(f.file, fillonedir, &buf);
51913 if (buf.result)
51914 @@ -139,6 +146,7 @@ struct linux_dirent {
51915 struct getdents_callback {
51916 struct linux_dirent __user * current_dir;
51917 struct linux_dirent __user * previous;
51918 + struct file * file;
51919 int count;
51920 int error;
51921 };
51922 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51923 buf->error = -EOVERFLOW;
51924 return -EOVERFLOW;
51925 }
51926 +
51927 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51928 + return 0;
51929 +
51930 dirent = buf->previous;
51931 if (dirent) {
51932 if (__put_user(offset, &dirent->d_off))
51933 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51934 buf.previous = NULL;
51935 buf.count = count;
51936 buf.error = 0;
51937 + buf.file = f.file;
51938
51939 error = vfs_readdir(f.file, filldir, &buf);
51940 if (error >= 0)
51941 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51942 struct getdents_callback64 {
51943 struct linux_dirent64 __user * current_dir;
51944 struct linux_dirent64 __user * previous;
51945 + struct file *file;
51946 int count;
51947 int error;
51948 };
51949 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
51950 buf->error = -EINVAL; /* only used if we fail.. */
51951 if (reclen > buf->count)
51952 return -EINVAL;
51953 +
51954 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51955 + return 0;
51956 +
51957 dirent = buf->previous;
51958 if (dirent) {
51959 if (__put_user(offset, &dirent->d_off))
51960 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51961
51962 buf.current_dir = dirent;
51963 buf.previous = NULL;
51964 + buf.file = f.file;
51965 buf.count = count;
51966 buf.error = 0;
51967
51968 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51969 error = buf.error;
51970 lastdirent = buf.previous;
51971 if (lastdirent) {
51972 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
51973 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
51974 if (__put_user(d_off, &lastdirent->d_off))
51975 error = -EFAULT;
51976 else
51977 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
51978 index 2b7882b..1c5ef48 100644
51979 --- a/fs/reiserfs/do_balan.c
51980 +++ b/fs/reiserfs/do_balan.c
51981 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
51982 return;
51983 }
51984
51985 - atomic_inc(&(fs_generation(tb->tb_sb)));
51986 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
51987 do_balance_starts(tb);
51988
51989 /* balance leaf returns 0 except if combining L R and S into
51990 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
51991 index e60e870..f40ac16 100644
51992 --- a/fs/reiserfs/procfs.c
51993 +++ b/fs/reiserfs/procfs.c
51994 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
51995 "SMALL_TAILS " : "NO_TAILS ",
51996 replay_only(sb) ? "REPLAY_ONLY " : "",
51997 convert_reiserfs(sb) ? "CONV " : "",
51998 - atomic_read(&r->s_generation_counter),
51999 + atomic_read_unchecked(&r->s_generation_counter),
52000 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52001 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52002 SF(s_good_search_by_key_reada), SF(s_bmaps),
52003 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52004 index 33215f5..c5d427a 100644
52005 --- a/fs/reiserfs/reiserfs.h
52006 +++ b/fs/reiserfs/reiserfs.h
52007 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52008 /* Comment? -Hans */
52009 wait_queue_head_t s_wait;
52010 /* To be obsoleted soon by per buffer seals.. -Hans */
52011 - atomic_t s_generation_counter; // increased by one every time the
52012 + atomic_unchecked_t s_generation_counter; // increased by one every time the
52013 // tree gets re-balanced
52014 unsigned long s_properties; /* File system properties. Currently holds
52015 on-disk FS format */
52016 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52017 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52018
52019 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52020 -#define get_generation(s) atomic_read (&fs_generation(s))
52021 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52022 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52023 #define __fs_changed(gen,s) (gen != get_generation (s))
52024 #define fs_changed(gen,s) \
52025 diff --git a/fs/select.c b/fs/select.c
52026 index 2ef72d9..f213b17 100644
52027 --- a/fs/select.c
52028 +++ b/fs/select.c
52029 @@ -20,6 +20,7 @@
52030 #include <linux/export.h>
52031 #include <linux/slab.h>
52032 #include <linux/poll.h>
52033 +#include <linux/security.h>
52034 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52035 #include <linux/file.h>
52036 #include <linux/fdtable.h>
52037 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52038 struct poll_list *walk = head;
52039 unsigned long todo = nfds;
52040
52041 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52042 if (nfds > rlimit(RLIMIT_NOFILE))
52043 return -EINVAL;
52044
52045 diff --git a/fs/seq_file.c b/fs/seq_file.c
52046 index 99dffab..e4fcb71 100644
52047 --- a/fs/seq_file.c
52048 +++ b/fs/seq_file.c
52049 @@ -10,6 +10,7 @@
52050 #include <linux/seq_file.h>
52051 #include <linux/slab.h>
52052 #include <linux/cred.h>
52053 +#include <linux/sched.h>
52054
52055 #include <asm/uaccess.h>
52056 #include <asm/page.h>
52057 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52058 #ifdef CONFIG_USER_NS
52059 p->user_ns = file->f_cred->user_ns;
52060 #endif
52061 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52062 + p->exec_id = current->exec_id;
52063 +#endif
52064
52065 /*
52066 * Wrappers around seq_open(e.g. swaps_open) need to be
52067 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52068 return 0;
52069 }
52070 if (!m->buf) {
52071 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52072 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52073 if (!m->buf)
52074 return -ENOMEM;
52075 }
52076 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52077 Eoverflow:
52078 m->op->stop(m, p);
52079 kfree(m->buf);
52080 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52081 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52082 return !m->buf ? -ENOMEM : -EAGAIN;
52083 }
52084
52085 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52086
52087 /* grab buffer if we didn't have one */
52088 if (!m->buf) {
52089 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52090 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52091 if (!m->buf)
52092 goto Enomem;
52093 }
52094 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52095 goto Fill;
52096 m->op->stop(m, p);
52097 kfree(m->buf);
52098 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52099 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52100 if (!m->buf)
52101 goto Enomem;
52102 m->count = 0;
52103 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52104 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52105 void *data)
52106 {
52107 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52108 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52109 int res = -ENOMEM;
52110
52111 if (op) {
52112 diff --git a/fs/splice.c b/fs/splice.c
52113 index 48c7bd1..d0740e4 100644
52114 --- a/fs/splice.c
52115 +++ b/fs/splice.c
52116 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52117 pipe_lock(pipe);
52118
52119 for (;;) {
52120 - if (!pipe->readers) {
52121 + if (!atomic_read(&pipe->readers)) {
52122 send_sig(SIGPIPE, current, 0);
52123 if (!ret)
52124 ret = -EPIPE;
52125 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52126 do_wakeup = 0;
52127 }
52128
52129 - pipe->waiting_writers++;
52130 + atomic_inc(&pipe->waiting_writers);
52131 pipe_wait(pipe);
52132 - pipe->waiting_writers--;
52133 + atomic_dec(&pipe->waiting_writers);
52134 }
52135
52136 pipe_unlock(pipe);
52137 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52138 old_fs = get_fs();
52139 set_fs(get_ds());
52140 /* The cast to a user pointer is valid due to the set_fs() */
52141 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52142 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52143 set_fs(old_fs);
52144
52145 return res;
52146 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52147 old_fs = get_fs();
52148 set_fs(get_ds());
52149 /* The cast to a user pointer is valid due to the set_fs() */
52150 - res = vfs_write(file, (const char __user *)buf, count, &pos);
52151 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52152 set_fs(old_fs);
52153
52154 return res;
52155 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52156 goto err;
52157
52158 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
52159 - vec[i].iov_base = (void __user *) page_address(page);
52160 + vec[i].iov_base = (void __force_user *) page_address(page);
52161 vec[i].iov_len = this_len;
52162 spd.pages[i] = page;
52163 spd.nr_pages++;
52164 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
52165 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
52166 {
52167 while (!pipe->nrbufs) {
52168 - if (!pipe->writers)
52169 + if (!atomic_read(&pipe->writers))
52170 return 0;
52171
52172 - if (!pipe->waiting_writers && sd->num_spliced)
52173 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52174 return 0;
52175
52176 if (sd->flags & SPLICE_F_NONBLOCK)
52177 @@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52178 * out of the pipe right after the splice_to_pipe(). So set
52179 * PIPE_READERS appropriately.
52180 */
52181 - pipe->readers = 1;
52182 + atomic_set(&pipe->readers, 1);
52183
52184 current->splice_pipe = pipe;
52185 }
52186 @@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52187 ret = -ERESTARTSYS;
52188 break;
52189 }
52190 - if (!pipe->writers)
52191 + if (!atomic_read(&pipe->writers))
52192 break;
52193 - if (!pipe->waiting_writers) {
52194 + if (!atomic_read(&pipe->waiting_writers)) {
52195 if (flags & SPLICE_F_NONBLOCK) {
52196 ret = -EAGAIN;
52197 break;
52198 @@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52199 pipe_lock(pipe);
52200
52201 while (pipe->nrbufs >= pipe->buffers) {
52202 - if (!pipe->readers) {
52203 + if (!atomic_read(&pipe->readers)) {
52204 send_sig(SIGPIPE, current, 0);
52205 ret = -EPIPE;
52206 break;
52207 @@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52208 ret = -ERESTARTSYS;
52209 break;
52210 }
52211 - pipe->waiting_writers++;
52212 + atomic_inc(&pipe->waiting_writers);
52213 pipe_wait(pipe);
52214 - pipe->waiting_writers--;
52215 + atomic_dec(&pipe->waiting_writers);
52216 }
52217
52218 pipe_unlock(pipe);
52219 @@ -1826,14 +1826,14 @@ retry:
52220 pipe_double_lock(ipipe, opipe);
52221
52222 do {
52223 - if (!opipe->readers) {
52224 + if (!atomic_read(&opipe->readers)) {
52225 send_sig(SIGPIPE, current, 0);
52226 if (!ret)
52227 ret = -EPIPE;
52228 break;
52229 }
52230
52231 - if (!ipipe->nrbufs && !ipipe->writers)
52232 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
52233 break;
52234
52235 /*
52236 @@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52237 pipe_double_lock(ipipe, opipe);
52238
52239 do {
52240 - if (!opipe->readers) {
52241 + if (!atomic_read(&opipe->readers)) {
52242 send_sig(SIGPIPE, current, 0);
52243 if (!ret)
52244 ret = -EPIPE;
52245 @@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52246 * return EAGAIN if we have the potential of some data in the
52247 * future, otherwise just return 0
52248 */
52249 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
52250 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
52251 ret = -EAGAIN;
52252
52253 pipe_unlock(ipipe);
52254 diff --git a/fs/stat.c b/fs/stat.c
52255 index eae4946..6198f55 100644
52256 --- a/fs/stat.c
52257 +++ b/fs/stat.c
52258 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
52259 stat->gid = inode->i_gid;
52260 stat->rdev = inode->i_rdev;
52261 stat->size = i_size_read(inode);
52262 - stat->atime = inode->i_atime;
52263 - stat->mtime = inode->i_mtime;
52264 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52265 + stat->atime = inode->i_ctime;
52266 + stat->mtime = inode->i_ctime;
52267 + } else {
52268 + stat->atime = inode->i_atime;
52269 + stat->mtime = inode->i_mtime;
52270 + }
52271 stat->ctime = inode->i_ctime;
52272 stat->blksize = (1 << inode->i_blkbits);
52273 stat->blocks = inode->i_blocks;
52274 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
52275 if (retval)
52276 return retval;
52277
52278 - if (inode->i_op->getattr)
52279 - return inode->i_op->getattr(mnt, dentry, stat);
52280 + if (inode->i_op->getattr) {
52281 + retval = inode->i_op->getattr(mnt, dentry, stat);
52282 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52283 + stat->atime = stat->ctime;
52284 + stat->mtime = stat->ctime;
52285 + }
52286 + return retval;
52287 + }
52288
52289 generic_fillattr(inode, stat);
52290 return 0;
52291 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
52292 index 2fbdff6..5530a61 100644
52293 --- a/fs/sysfs/dir.c
52294 +++ b/fs/sysfs/dir.c
52295 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
52296 struct sysfs_dirent *sd;
52297 int rc;
52298
52299 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
52300 + const char *parent_name = parent_sd->s_name;
52301 +
52302 + mode = S_IFDIR | S_IRWXU;
52303 +
52304 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
52305 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
52306 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
52307 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
52308 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
52309 +#endif
52310 +
52311 /* allocate */
52312 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
52313 if (!sd)
52314 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
52315 index 00012e3..8392349 100644
52316 --- a/fs/sysfs/file.c
52317 +++ b/fs/sysfs/file.c
52318 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
52319
52320 struct sysfs_open_dirent {
52321 atomic_t refcnt;
52322 - atomic_t event;
52323 + atomic_unchecked_t event;
52324 wait_queue_head_t poll;
52325 struct list_head buffers; /* goes through sysfs_buffer.list */
52326 };
52327 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
52328 if (!sysfs_get_active(attr_sd))
52329 return -ENODEV;
52330
52331 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
52332 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
52333 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
52334
52335 sysfs_put_active(attr_sd);
52336 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
52337 return -ENOMEM;
52338
52339 atomic_set(&new_od->refcnt, 0);
52340 - atomic_set(&new_od->event, 1);
52341 + atomic_set_unchecked(&new_od->event, 1);
52342 init_waitqueue_head(&new_od->poll);
52343 INIT_LIST_HEAD(&new_od->buffers);
52344 goto retry;
52345 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
52346
52347 sysfs_put_active(attr_sd);
52348
52349 - if (buffer->event != atomic_read(&od->event))
52350 + if (buffer->event != atomic_read_unchecked(&od->event))
52351 goto trigger;
52352
52353 return DEFAULT_POLLMASK;
52354 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
52355
52356 od = sd->s_attr.open;
52357 if (od) {
52358 - atomic_inc(&od->event);
52359 + atomic_inc_unchecked(&od->event);
52360 wake_up_interruptible(&od->poll);
52361 }
52362
52363 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
52364 index 3c9eb56..9dea5be 100644
52365 --- a/fs/sysfs/symlink.c
52366 +++ b/fs/sysfs/symlink.c
52367 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52368
52369 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
52370 {
52371 - char *page = nd_get_link(nd);
52372 + const char *page = nd_get_link(nd);
52373 if (!IS_ERR(page))
52374 free_page((unsigned long)page);
52375 }
52376 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
52377 index c175b4d..8f36a16 100644
52378 --- a/fs/udf/misc.c
52379 +++ b/fs/udf/misc.c
52380 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
52381
52382 u8 udf_tag_checksum(const struct tag *t)
52383 {
52384 - u8 *data = (u8 *)t;
52385 + const u8 *data = (const u8 *)t;
52386 u8 checksum = 0;
52387 int i;
52388 for (i = 0; i < sizeof(struct tag); ++i)
52389 diff --git a/fs/utimes.c b/fs/utimes.c
52390 index bb0696a..552054b 100644
52391 --- a/fs/utimes.c
52392 +++ b/fs/utimes.c
52393 @@ -1,6 +1,7 @@
52394 #include <linux/compiler.h>
52395 #include <linux/file.h>
52396 #include <linux/fs.h>
52397 +#include <linux/security.h>
52398 #include <linux/linkage.h>
52399 #include <linux/mount.h>
52400 #include <linux/namei.h>
52401 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
52402 goto mnt_drop_write_and_out;
52403 }
52404 }
52405 +
52406 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
52407 + error = -EACCES;
52408 + goto mnt_drop_write_and_out;
52409 + }
52410 +
52411 mutex_lock(&inode->i_mutex);
52412 error = notify_change(path->dentry, &newattrs);
52413 mutex_unlock(&inode->i_mutex);
52414 diff --git a/fs/xattr.c b/fs/xattr.c
52415 index e21c119..21dfc7c 100644
52416 --- a/fs/xattr.c
52417 +++ b/fs/xattr.c
52418 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
52419 * Extended attribute SET operations
52420 */
52421 static long
52422 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
52423 +setxattr(struct path *path, const char __user *name, const void __user *value,
52424 size_t size, int flags)
52425 {
52426 int error;
52427 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
52428 posix_acl_fix_xattr_from_user(kvalue, size);
52429 }
52430
52431 - error = vfs_setxattr(d, kname, kvalue, size, flags);
52432 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
52433 + error = -EACCES;
52434 + goto out;
52435 + }
52436 +
52437 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52438 out:
52439 if (vvalue)
52440 vfree(vvalue);
52441 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52442 return error;
52443 error = mnt_want_write(path.mnt);
52444 if (!error) {
52445 - error = setxattr(path.dentry, name, value, size, flags);
52446 + error = setxattr(&path, name, value, size, flags);
52447 mnt_drop_write(path.mnt);
52448 }
52449 path_put(&path);
52450 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52451 return error;
52452 error = mnt_want_write(path.mnt);
52453 if (!error) {
52454 - error = setxattr(path.dentry, name, value, size, flags);
52455 + error = setxattr(&path, name, value, size, flags);
52456 mnt_drop_write(path.mnt);
52457 }
52458 path_put(&path);
52459 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52460 const void __user *,value, size_t, size, int, flags)
52461 {
52462 struct fd f = fdget(fd);
52463 - struct dentry *dentry;
52464 int error = -EBADF;
52465
52466 if (!f.file)
52467 return error;
52468 - dentry = f.file->f_path.dentry;
52469 - audit_inode(NULL, dentry, 0);
52470 + audit_inode(NULL, f.file->f_path.dentry, 0);
52471 error = mnt_want_write_file(f.file);
52472 if (!error) {
52473 - error = setxattr(dentry, name, value, size, flags);
52474 + error = setxattr(&f.file->f_path, name, value, size, flags);
52475 mnt_drop_write_file(f.file);
52476 }
52477 fdput(f);
52478 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52479 index 9fbea87..6b19972 100644
52480 --- a/fs/xattr_acl.c
52481 +++ b/fs/xattr_acl.c
52482 @@ -76,8 +76,8 @@ struct posix_acl *
52483 posix_acl_from_xattr(struct user_namespace *user_ns,
52484 const void *value, size_t size)
52485 {
52486 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52487 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52488 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52489 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52490 int count;
52491 struct posix_acl *acl;
52492 struct posix_acl_entry *acl_e;
52493 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52494 index 83d0cf3..2ef526b 100644
52495 --- a/fs/xfs/xfs_bmap.c
52496 +++ b/fs/xfs/xfs_bmap.c
52497 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52498 int nmap,
52499 int ret_nmap);
52500 #else
52501 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52502 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52503 #endif /* DEBUG */
52504
52505 STATIC int
52506 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52507 index 1b9fc3e..e1bdde0 100644
52508 --- a/fs/xfs/xfs_dir2_sf.c
52509 +++ b/fs/xfs/xfs_dir2_sf.c
52510 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52511 }
52512
52513 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52514 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52515 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52516 + char name[sfep->namelen];
52517 + memcpy(name, sfep->name, sfep->namelen);
52518 + if (filldir(dirent, name, sfep->namelen,
52519 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
52520 + *offset = off & 0x7fffffff;
52521 + return 0;
52522 + }
52523 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52524 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52525 *offset = off & 0x7fffffff;
52526 return 0;
52527 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52528 index c1df3c6..f987db6 100644
52529 --- a/fs/xfs/xfs_ioctl.c
52530 +++ b/fs/xfs/xfs_ioctl.c
52531 @@ -126,7 +126,7 @@ xfs_find_handle(
52532 }
52533
52534 error = -EFAULT;
52535 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52536 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52537 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52538 goto out_put;
52539
52540 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52541 index 4e00cf0..3374374 100644
52542 --- a/fs/xfs/xfs_iops.c
52543 +++ b/fs/xfs/xfs_iops.c
52544 @@ -394,7 +394,7 @@ xfs_vn_put_link(
52545 struct nameidata *nd,
52546 void *p)
52547 {
52548 - char *s = nd_get_link(nd);
52549 + const char *s = nd_get_link(nd);
52550
52551 if (!IS_ERR(s))
52552 kfree(s);
52553 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52554 new file mode 100644
52555 index 0000000..92247e4
52556 --- /dev/null
52557 +++ b/grsecurity/Kconfig
52558 @@ -0,0 +1,1021 @@
52559 +#
52560 +# grecurity configuration
52561 +#
52562 +menu "Memory Protections"
52563 +depends on GRKERNSEC
52564 +
52565 +config GRKERNSEC_KMEM
52566 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52567 + default y if GRKERNSEC_CONFIG_AUTO
52568 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52569 + help
52570 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52571 + be written to or read from to modify or leak the contents of the running
52572 + kernel. /dev/port will also not be allowed to be opened and support
52573 + for /dev/cpu/*/msr will be removed. If you have module
52574 + support disabled, enabling this will close up five ways that are
52575 + currently used to insert malicious code into the running kernel.
52576 +
52577 + Even with all these features enabled, we still highly recommend that
52578 + you use the RBAC system, as it is still possible for an attacker to
52579 + modify the running kernel through privileged I/O granted by ioperm/iopl.
52580 +
52581 + If you are not using XFree86, you may be able to stop this additional
52582 + case by enabling the 'Disable privileged I/O' option. Though nothing
52583 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52584 + but only to video memory, which is the only writing we allow in this
52585 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52586 + not be allowed to mprotect it with PROT_WRITE later.
52587 + Enabling this feature will prevent the "cpupower" and "powertop" tools
52588 + from working.
52589 +
52590 + It is highly recommended that you say Y here if you meet all the
52591 + conditions above.
52592 +
52593 +config GRKERNSEC_VM86
52594 + bool "Restrict VM86 mode"
52595 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52596 + depends on X86_32
52597 +
52598 + help
52599 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52600 + make use of a special execution mode on 32bit x86 processors called
52601 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52602 + video cards and will still work with this option enabled. The purpose
52603 + of the option is to prevent exploitation of emulation errors in
52604 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
52605 + Nearly all users should be able to enable this option.
52606 +
52607 +config GRKERNSEC_IO
52608 + bool "Disable privileged I/O"
52609 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52610 + depends on X86
52611 + select RTC_CLASS
52612 + select RTC_INTF_DEV
52613 + select RTC_DRV_CMOS
52614 +
52615 + help
52616 + If you say Y here, all ioperm and iopl calls will return an error.
52617 + Ioperm and iopl can be used to modify the running kernel.
52618 + Unfortunately, some programs need this access to operate properly,
52619 + the most notable of which are XFree86 and hwclock. hwclock can be
52620 + remedied by having RTC support in the kernel, so real-time
52621 + clock support is enabled if this option is enabled, to ensure
52622 + that hwclock operates correctly. XFree86 still will not
52623 + operate correctly with this option enabled, so DO NOT CHOOSE Y
52624 + IF YOU USE XFree86. If you use XFree86 and you still want to
52625 + protect your kernel against modification, use the RBAC system.
52626 +
52627 +config GRKERNSEC_JIT_HARDEN
52628 + bool "Harden BPF JIT against spray attacks"
52629 + default y if GRKERNSEC_CONFIG_AUTO
52630 + depends on BPF_JIT
52631 + help
52632 + If you say Y here, the native code generated by the kernel's Berkeley
52633 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52634 + attacks that attempt to fit attacker-beneficial instructions in
52635 + 32bit immediate fields of JIT-generated native instructions. The
52636 + attacker will generally aim to cause an unintended instruction sequence
52637 + of JIT-generated native code to execute by jumping into the middle of
52638 + a generated instruction. This feature effectively randomizes the 32bit
52639 + immediate constants present in the generated code to thwart such attacks.
52640 +
52641 + If you're using KERNEXEC, it's recommended that you enable this option
52642 + to supplement the hardening of the kernel.
52643 +
52644 +config GRKERNSEC_RAND_THREADSTACK
52645 + bool "Insert random gaps between thread stacks"
52646 + default y if GRKERNSEC_CONFIG_AUTO
52647 + depends on PAX_RANDMMAP && !PPC
52648 + help
52649 + If you say Y here, a random-sized gap will be enforced between allocated
52650 + thread stacks. Glibc's NPTL and other threading libraries that
52651 + pass MAP_STACK to the kernel for thread stack allocation are supported.
52652 + The implementation currently provides 8 bits of entropy for the gap.
52653 +
52654 + Many distributions do not compile threaded remote services with the
52655 + -fstack-check argument to GCC, causing the variable-sized stack-based
52656 + allocator, alloca(), to not probe the stack on allocation. This
52657 + permits an unbounded alloca() to skip over any guard page and potentially
52658 + modify another thread's stack reliably. An enforced random gap
52659 + reduces the reliability of such an attack and increases the chance
52660 + that such a read/write to another thread's stack instead lands in
52661 + an unmapped area, causing a crash and triggering grsecurity's
52662 + anti-bruteforcing logic.
52663 +
52664 +config GRKERNSEC_PROC_MEMMAP
52665 + bool "Harden ASLR against information leaks and entropy reduction"
52666 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52667 + depends on PAX_NOEXEC || PAX_ASLR
52668 + help
52669 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52670 + give no information about the addresses of its mappings if
52671 + PaX features that rely on random addresses are enabled on the task.
52672 + In addition to sanitizing this information and disabling other
52673 + dangerous sources of information, this option causes reads of sensitive
52674 + /proc/<pid> entries where the file descriptor was opened in a different
52675 + task than the one performing the read. Such attempts are logged.
52676 + This option also limits argv/env strings for suid/sgid binaries
52677 + to 512KB to prevent a complete exhaustion of the stack entropy provided
52678 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52679 + binaries to prevent alternative mmap layouts from being abused.
52680 +
52681 + If you use PaX it is essential that you say Y here as it closes up
52682 + several holes that make full ASLR useless locally.
52683 +
52684 +config GRKERNSEC_BRUTE
52685 + bool "Deter exploit bruteforcing"
52686 + default y if GRKERNSEC_CONFIG_AUTO
52687 + help
52688 + If you say Y here, attempts to bruteforce exploits against forking
52689 + daemons such as apache or sshd, as well as against suid/sgid binaries
52690 + will be deterred. When a child of a forking daemon is killed by PaX
52691 + or crashes due to an illegal instruction or other suspicious signal,
52692 + the parent process will be delayed 30 seconds upon every subsequent
52693 + fork until the administrator is able to assess the situation and
52694 + restart the daemon.
52695 + In the suid/sgid case, the attempt is logged, the user has all their
52696 + processes terminated, and they are prevented from executing any further
52697 + processes for 15 minutes.
52698 + It is recommended that you also enable signal logging in the auditing
52699 + section so that logs are generated when a process triggers a suspicious
52700 + signal.
52701 + If the sysctl option is enabled, a sysctl option with name
52702 + "deter_bruteforce" is created.
52703 +
52704 +
52705 +config GRKERNSEC_MODHARDEN
52706 + bool "Harden module auto-loading"
52707 + default y if GRKERNSEC_CONFIG_AUTO
52708 + depends on MODULES
52709 + help
52710 + If you say Y here, module auto-loading in response to use of some
52711 + feature implemented by an unloaded module will be restricted to
52712 + root users. Enabling this option helps defend against attacks
52713 + by unprivileged users who abuse the auto-loading behavior to
52714 + cause a vulnerable module to load that is then exploited.
52715 +
52716 + If this option prevents a legitimate use of auto-loading for a
52717 + non-root user, the administrator can execute modprobe manually
52718 + with the exact name of the module mentioned in the alert log.
52719 + Alternatively, the administrator can add the module to the list
52720 + of modules loaded at boot by modifying init scripts.
52721 +
52722 + Modification of init scripts will most likely be needed on
52723 + Ubuntu servers with encrypted home directory support enabled,
52724 + as the first non-root user logging in will cause the ecb(aes),
52725 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52726 +
52727 +config GRKERNSEC_HIDESYM
52728 + bool "Hide kernel symbols"
52729 + default y if GRKERNSEC_CONFIG_AUTO
52730 + select PAX_USERCOPY_SLABS
52731 + help
52732 + If you say Y here, getting information on loaded modules, and
52733 + displaying all kernel symbols through a syscall will be restricted
52734 + to users with CAP_SYS_MODULE. For software compatibility reasons,
52735 + /proc/kallsyms will be restricted to the root user. The RBAC
52736 + system can hide that entry even from root.
52737 +
52738 + This option also prevents leaking of kernel addresses through
52739 + several /proc entries.
52740 +
52741 + Note that this option is only effective provided the following
52742 + conditions are met:
52743 + 1) The kernel using grsecurity is not precompiled by some distribution
52744 + 2) You have also enabled GRKERNSEC_DMESG
52745 + 3) You are using the RBAC system and hiding other files such as your
52746 + kernel image and System.map. Alternatively, enabling this option
52747 + causes the permissions on /boot, /lib/modules, and the kernel
52748 + source directory to change at compile time to prevent
52749 + reading by non-root users.
52750 + If the above conditions are met, this option will aid in providing a
52751 + useful protection against local kernel exploitation of overflows
52752 + and arbitrary read/write vulnerabilities.
52753 +
52754 +config GRKERNSEC_KERN_LOCKOUT
52755 + bool "Active kernel exploit response"
52756 + default y if GRKERNSEC_CONFIG_AUTO
52757 + depends on X86 || ARM || PPC || SPARC
52758 + help
52759 + If you say Y here, when a PaX alert is triggered due to suspicious
52760 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52761 + or an OOPS occurs due to bad memory accesses, instead of just
52762 + terminating the offending process (and potentially allowing
52763 + a subsequent exploit from the same user), we will take one of two
52764 + actions:
52765 + If the user was root, we will panic the system
52766 + If the user was non-root, we will log the attempt, terminate
52767 + all processes owned by the user, then prevent them from creating
52768 + any new processes until the system is restarted
52769 + This deters repeated kernel exploitation/bruteforcing attempts
52770 + and is useful for later forensics.
52771 +
52772 +endmenu
52773 +menu "Role Based Access Control Options"
52774 +depends on GRKERNSEC
52775 +
52776 +config GRKERNSEC_RBAC_DEBUG
52777 + bool
52778 +
52779 +config GRKERNSEC_NO_RBAC
52780 + bool "Disable RBAC system"
52781 + help
52782 + If you say Y here, the /dev/grsec device will be removed from the kernel,
52783 + preventing the RBAC system from being enabled. You should only say Y
52784 + here if you have no intention of using the RBAC system, so as to prevent
52785 + an attacker with root access from misusing the RBAC system to hide files
52786 + and processes when loadable module support and /dev/[k]mem have been
52787 + locked down.
52788 +
52789 +config GRKERNSEC_ACL_HIDEKERN
52790 + bool "Hide kernel processes"
52791 + help
52792 + If you say Y here, all kernel threads will be hidden to all
52793 + processes but those whose subject has the "view hidden processes"
52794 + flag.
52795 +
52796 +config GRKERNSEC_ACL_MAXTRIES
52797 + int "Maximum tries before password lockout"
52798 + default 3
52799 + help
52800 + This option enforces the maximum number of times a user can attempt
52801 + to authorize themselves with the grsecurity RBAC system before being
52802 + denied the ability to attempt authorization again for a specified time.
52803 + The lower the number, the harder it will be to brute-force a password.
52804 +
52805 +config GRKERNSEC_ACL_TIMEOUT
52806 + int "Time to wait after max password tries, in seconds"
52807 + default 30
52808 + help
52809 + This option specifies the time the user must wait after attempting to
52810 + authorize to the RBAC system with the maximum number of invalid
52811 + passwords. The higher the number, the harder it will be to brute-force
52812 + a password.
52813 +
52814 +endmenu
52815 +menu "Filesystem Protections"
52816 +depends on GRKERNSEC
52817 +
52818 +config GRKERNSEC_PROC
52819 + bool "Proc restrictions"
52820 + default y if GRKERNSEC_CONFIG_AUTO
52821 + help
52822 + If you say Y here, the permissions of the /proc filesystem
52823 + will be altered to enhance system security and privacy. You MUST
52824 + choose either a user only restriction or a user and group restriction.
52825 + Depending upon the option you choose, you can either restrict users to
52826 + see only the processes they themselves run, or choose a group that can
52827 + view all processes and files normally restricted to root if you choose
52828 + the "restrict to user only" option. NOTE: If you're running identd or
52829 + ntpd as a non-root user, you will have to run it as the group you
52830 + specify here.
52831 +
52832 +config GRKERNSEC_PROC_USER
52833 + bool "Restrict /proc to user only"
52834 + depends on GRKERNSEC_PROC
52835 + help
52836 + If you say Y here, non-root users will only be able to view their own
52837 + processes, and restricts them from viewing network-related information,
52838 + and viewing kernel symbol and module information.
52839 +
52840 +config GRKERNSEC_PROC_USERGROUP
52841 + bool "Allow special group"
52842 + default y if GRKERNSEC_CONFIG_AUTO
52843 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52844 + help
52845 + If you say Y here, you will be able to select a group that will be
52846 + able to view all processes and network-related information. If you've
52847 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52848 + remain hidden. This option is useful if you want to run identd as
52849 + a non-root user. The group you select may also be chosen at boot time
52850 + via "grsec_proc_gid=" on the kernel commandline.
52851 +
52852 +config GRKERNSEC_PROC_GID
52853 + int "GID for special group"
52854 + depends on GRKERNSEC_PROC_USERGROUP
52855 + default 1001
52856 +
52857 +config GRKERNSEC_PROC_ADD
52858 + bool "Additional restrictions"
52859 + default y if GRKERNSEC_CONFIG_AUTO
52860 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52861 + help
52862 + If you say Y here, additional restrictions will be placed on
52863 + /proc that keep normal users from viewing device information and
52864 + slabinfo information that could be useful for exploits.
52865 +
52866 +config GRKERNSEC_LINK
52867 + bool "Linking restrictions"
52868 + default y if GRKERNSEC_CONFIG_AUTO
52869 + help
52870 + If you say Y here, /tmp race exploits will be prevented, since users
52871 + will no longer be able to follow symlinks owned by other users in
52872 + world-writable +t directories (e.g. /tmp), unless the owner of the
52873 + symlink is the owner of the directory. users will also not be
52874 + able to hardlink to files they do not own. If the sysctl option is
52875 + enabled, a sysctl option with name "linking_restrictions" is created.
52876 +
52877 +config GRKERNSEC_SYMLINKOWN
52878 + bool "Kernel-enforced SymlinksIfOwnerMatch"
52879 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52880 + help
52881 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
52882 + that prevents it from being used as a security feature. As Apache
52883 + verifies the symlink by performing a stat() against the target of
52884 + the symlink before it is followed, an attacker can setup a symlink
52885 + to point to a same-owned file, then replace the symlink with one
52886 + that targets another user's file just after Apache "validates" the
52887 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
52888 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52889 + will be in place for the group you specify. If the sysctl option
52890 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
52891 + created.
52892 +
52893 +config GRKERNSEC_SYMLINKOWN_GID
52894 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52895 + depends on GRKERNSEC_SYMLINKOWN
52896 + default 1006
52897 + help
52898 + Setting this GID determines what group kernel-enforced
52899 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52900 + is enabled, a sysctl option with name "symlinkown_gid" is created.
52901 +
52902 +config GRKERNSEC_FIFO
52903 + bool "FIFO restrictions"
52904 + default y if GRKERNSEC_CONFIG_AUTO
52905 + help
52906 + If you say Y here, users will not be able to write to FIFOs they don't
52907 + own in world-writable +t directories (e.g. /tmp), unless the owner of
52908 + the FIFO is the same owner of the directory it's held in. If the sysctl
52909 + option is enabled, a sysctl option with name "fifo_restrictions" is
52910 + created.
52911 +
52912 +config GRKERNSEC_SYSFS_RESTRICT
52913 + bool "Sysfs/debugfs restriction"
52914 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52915 + depends on SYSFS
52916 + help
52917 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52918 + any filesystem normally mounted under it (e.g. debugfs) will be
52919 + mostly accessible only by root. These filesystems generally provide access
52920 + to hardware and debug information that isn't appropriate for unprivileged
52921 + users of the system. Sysfs and debugfs have also become a large source
52922 + of new vulnerabilities, ranging from infoleaks to local compromise.
52923 + There has been very little oversight with an eye toward security involved
52924 + in adding new exporters of information to these filesystems, so their
52925 + use is discouraged.
52926 + For reasons of compatibility, a few directories have been whitelisted
52927 + for access by non-root users:
52928 + /sys/fs/selinux
52929 + /sys/fs/fuse
52930 + /sys/devices/system/cpu
52931 +
52932 +config GRKERNSEC_ROFS
52933 + bool "Runtime read-only mount protection"
52934 + help
52935 + If you say Y here, a sysctl option with name "romount_protect" will
52936 + be created. By setting this option to 1 at runtime, filesystems
52937 + will be protected in the following ways:
52938 + * No new writable mounts will be allowed
52939 + * Existing read-only mounts won't be able to be remounted read/write
52940 + * Write operations will be denied on all block devices
52941 + This option acts independently of grsec_lock: once it is set to 1,
52942 + it cannot be turned off. Therefore, please be mindful of the resulting
52943 + behavior if this option is enabled in an init script on a read-only
52944 + filesystem. This feature is mainly intended for secure embedded systems.
52945 +
52946 +config GRKERNSEC_DEVICE_SIDECHANNEL
52947 + bool "Eliminate stat/notify-based device sidechannels"
52948 + default y if GRKERNSEC_CONFIG_AUTO
52949 + help
52950 + If you say Y here, timing analyses on block or character
52951 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
52952 + will be thwarted for unprivileged users. If a process without
52953 + CAP_MKNOD stats such a device, the last access and last modify times
52954 + will match the device's create time. No access or modify events
52955 + will be triggered through inotify/dnotify/fanotify for such devices.
52956 + This feature will prevent attacks that may at a minimum
52957 + allow an attacker to determine the administrator's password length.
52958 +
52959 +config GRKERNSEC_CHROOT
52960 + bool "Chroot jail restrictions"
52961 + default y if GRKERNSEC_CONFIG_AUTO
52962 + help
52963 + If you say Y here, you will be able to choose several options that will
52964 + make breaking out of a chrooted jail much more difficult. If you
52965 + encounter no software incompatibilities with the following options, it
52966 + is recommended that you enable each one.
52967 +
52968 +config GRKERNSEC_CHROOT_MOUNT
52969 + bool "Deny mounts"
52970 + default y if GRKERNSEC_CONFIG_AUTO
52971 + depends on GRKERNSEC_CHROOT
52972 + help
52973 + If you say Y here, processes inside a chroot will not be able to
52974 + mount or remount filesystems. If the sysctl option is enabled, a
52975 + sysctl option with name "chroot_deny_mount" is created.
52976 +
52977 +config GRKERNSEC_CHROOT_DOUBLE
52978 + bool "Deny double-chroots"
52979 + default y if GRKERNSEC_CONFIG_AUTO
52980 + depends on GRKERNSEC_CHROOT
52981 + help
52982 + If you say Y here, processes inside a chroot will not be able to chroot
52983 + again outside the chroot. This is a widely used method of breaking
52984 + out of a chroot jail and should not be allowed. If the sysctl
52985 + option is enabled, a sysctl option with name
52986 + "chroot_deny_chroot" is created.
52987 +
52988 +config GRKERNSEC_CHROOT_PIVOT
52989 + bool "Deny pivot_root in chroot"
52990 + default y if GRKERNSEC_CONFIG_AUTO
52991 + depends on GRKERNSEC_CHROOT
52992 + help
52993 + If you say Y here, processes inside a chroot will not be able to use
52994 + a function called pivot_root() that was introduced in Linux 2.3.41. It
52995 + works similar to chroot in that it changes the root filesystem. This
52996 + function could be misused in a chrooted process to attempt to break out
52997 + of the chroot, and therefore should not be allowed. If the sysctl
52998 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
52999 + created.
53000 +
53001 +config GRKERNSEC_CHROOT_CHDIR
53002 + bool "Enforce chdir(\"/\") on all chroots"
53003 + default y if GRKERNSEC_CONFIG_AUTO
53004 + depends on GRKERNSEC_CHROOT
53005 + help
53006 + If you say Y here, the current working directory of all newly-chrooted
53007 + applications will be set to the the root directory of the chroot.
53008 + The man page on chroot(2) states:
53009 + Note that this call does not change the current working
53010 + directory, so that `.' can be outside the tree rooted at
53011 + `/'. In particular, the super-user can escape from a
53012 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53013 +
53014 + It is recommended that you say Y here, since it's not known to break
53015 + any software. If the sysctl option is enabled, a sysctl option with
53016 + name "chroot_enforce_chdir" is created.
53017 +
53018 +config GRKERNSEC_CHROOT_CHMOD
53019 + bool "Deny (f)chmod +s"
53020 + default y if GRKERNSEC_CONFIG_AUTO
53021 + depends on GRKERNSEC_CHROOT
53022 + help
53023 + If you say Y here, processes inside a chroot will not be able to chmod
53024 + or fchmod files to make them have suid or sgid bits. This protects
53025 + against another published method of breaking a chroot. If the sysctl
53026 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
53027 + created.
53028 +
53029 +config GRKERNSEC_CHROOT_FCHDIR
53030 + bool "Deny fchdir out of chroot"
53031 + default y if GRKERNSEC_CONFIG_AUTO
53032 + depends on GRKERNSEC_CHROOT
53033 + help
53034 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
53035 + to a file descriptor of the chrooting process that points to a directory
53036 + outside the filesystem will be stopped. If the sysctl option
53037 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53038 +
53039 +config GRKERNSEC_CHROOT_MKNOD
53040 + bool "Deny mknod"
53041 + default y if GRKERNSEC_CONFIG_AUTO
53042 + depends on GRKERNSEC_CHROOT
53043 + help
53044 + If you say Y here, processes inside a chroot will not be allowed to
53045 + mknod. The problem with using mknod inside a chroot is that it
53046 + would allow an attacker to create a device entry that is the same
53047 + as one on the physical root of your system, which could range from
53048 + anything from the console device to a device for your harddrive (which
53049 + they could then use to wipe the drive or steal data). It is recommended
53050 + that you say Y here, unless you run into software incompatibilities.
53051 + If the sysctl option is enabled, a sysctl option with name
53052 + "chroot_deny_mknod" is created.
53053 +
53054 +config GRKERNSEC_CHROOT_SHMAT
53055 + bool "Deny shmat() out of chroot"
53056 + default y if GRKERNSEC_CONFIG_AUTO
53057 + depends on GRKERNSEC_CHROOT
53058 + help
53059 + If you say Y here, processes inside a chroot will not be able to attach
53060 + to shared memory segments that were created outside of the chroot jail.
53061 + It is recommended that you say Y here. If the sysctl option is enabled,
53062 + a sysctl option with name "chroot_deny_shmat" is created.
53063 +
53064 +config GRKERNSEC_CHROOT_UNIX
53065 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
53066 + default y if GRKERNSEC_CONFIG_AUTO
53067 + depends on GRKERNSEC_CHROOT
53068 + help
53069 + If you say Y here, processes inside a chroot will not be able to
53070 + connect to abstract (meaning not belonging to a filesystem) Unix
53071 + domain sockets that were bound outside of a chroot. It is recommended
53072 + that you say Y here. If the sysctl option is enabled, a sysctl option
53073 + with name "chroot_deny_unix" is created.
53074 +
53075 +config GRKERNSEC_CHROOT_FINDTASK
53076 + bool "Protect outside processes"
53077 + default y if GRKERNSEC_CONFIG_AUTO
53078 + depends on GRKERNSEC_CHROOT
53079 + help
53080 + If you say Y here, processes inside a chroot will not be able to
53081 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53082 + getsid, or view any process outside of the chroot. If the sysctl
53083 + option is enabled, a sysctl option with name "chroot_findtask" is
53084 + created.
53085 +
53086 +config GRKERNSEC_CHROOT_NICE
53087 + bool "Restrict priority changes"
53088 + default y if GRKERNSEC_CONFIG_AUTO
53089 + depends on GRKERNSEC_CHROOT
53090 + help
53091 + If you say Y here, processes inside a chroot will not be able to raise
53092 + the priority of processes in the chroot, or alter the priority of
53093 + processes outside the chroot. This provides more security than simply
53094 + removing CAP_SYS_NICE from the process' capability set. If the
53095 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53096 + is created.
53097 +
53098 +config GRKERNSEC_CHROOT_SYSCTL
53099 + bool "Deny sysctl writes"
53100 + default y if GRKERNSEC_CONFIG_AUTO
53101 + depends on GRKERNSEC_CHROOT
53102 + help
53103 + If you say Y here, an attacker in a chroot will not be able to
53104 + write to sysctl entries, either by sysctl(2) or through a /proc
53105 + interface. It is strongly recommended that you say Y here. If the
53106 + sysctl option is enabled, a sysctl option with name
53107 + "chroot_deny_sysctl" is created.
53108 +
53109 +config GRKERNSEC_CHROOT_CAPS
53110 + bool "Capability restrictions"
53111 + default y if GRKERNSEC_CONFIG_AUTO
53112 + depends on GRKERNSEC_CHROOT
53113 + help
53114 + If you say Y here, the capabilities on all processes within a
53115 + chroot jail will be lowered to stop module insertion, raw i/o,
53116 + system and net admin tasks, rebooting the system, modifying immutable
53117 + files, modifying IPC owned by another, and changing the system time.
53118 + This is left an option because it can break some apps. Disable this
53119 + if your chrooted apps are having problems performing those kinds of
53120 + tasks. If the sysctl option is enabled, a sysctl option with
53121 + name "chroot_caps" is created.
53122 +
53123 +endmenu
53124 +menu "Kernel Auditing"
53125 +depends on GRKERNSEC
53126 +
53127 +config GRKERNSEC_AUDIT_GROUP
53128 + bool "Single group for auditing"
53129 + help
53130 + If you say Y here, the exec and chdir logging features will only operate
53131 + on a group you specify. This option is recommended if you only want to
53132 + watch certain users instead of having a large amount of logs from the
53133 + entire system. If the sysctl option is enabled, a sysctl option with
53134 + name "audit_group" is created.
53135 +
53136 +config GRKERNSEC_AUDIT_GID
53137 + int "GID for auditing"
53138 + depends on GRKERNSEC_AUDIT_GROUP
53139 + default 1007
53140 +
53141 +config GRKERNSEC_EXECLOG
53142 + bool "Exec logging"
53143 + help
53144 + If you say Y here, all execve() calls will be logged (since the
53145 + other exec*() calls are frontends to execve(), all execution
53146 + will be logged). Useful for shell-servers that like to keep track
53147 + of their users. If the sysctl option is enabled, a sysctl option with
53148 + name "exec_logging" is created.
53149 + WARNING: This option when enabled will produce a LOT of logs, especially
53150 + on an active system.
53151 +
53152 +config GRKERNSEC_RESLOG
53153 + bool "Resource logging"
53154 + default y if GRKERNSEC_CONFIG_AUTO
53155 + help
53156 + If you say Y here, all attempts to overstep resource limits will
53157 + be logged with the resource name, the requested size, and the current
53158 + limit. It is highly recommended that you say Y here. If the sysctl
53159 + option is enabled, a sysctl option with name "resource_logging" is
53160 + created. If the RBAC system is enabled, the sysctl value is ignored.
53161 +
53162 +config GRKERNSEC_CHROOT_EXECLOG
53163 + bool "Log execs within chroot"
53164 + help
53165 + If you say Y here, all executions inside a chroot jail will be logged
53166 + to syslog. This can cause a large amount of logs if certain
53167 + applications (eg. djb's daemontools) are installed on the system, and
53168 + is therefore left as an option. If the sysctl option is enabled, a
53169 + sysctl option with name "chroot_execlog" is created.
53170 +
53171 +config GRKERNSEC_AUDIT_PTRACE
53172 + bool "Ptrace logging"
53173 + help
53174 + If you say Y here, all attempts to attach to a process via ptrace
53175 + will be logged. If the sysctl option is enabled, a sysctl option
53176 + with name "audit_ptrace" is created.
53177 +
53178 +config GRKERNSEC_AUDIT_CHDIR
53179 + bool "Chdir logging"
53180 + help
53181 + If you say Y here, all chdir() calls will be logged. If the sysctl
53182 + option is enabled, a sysctl option with name "audit_chdir" is created.
53183 +
53184 +config GRKERNSEC_AUDIT_MOUNT
53185 + bool "(Un)Mount logging"
53186 + help
53187 + If you say Y here, all mounts and unmounts will be logged. If the
53188 + sysctl option is enabled, a sysctl option with name "audit_mount" is
53189 + created.
53190 +
53191 +config GRKERNSEC_SIGNAL
53192 + bool "Signal logging"
53193 + default y if GRKERNSEC_CONFIG_AUTO
53194 + help
53195 + If you say Y here, certain important signals will be logged, such as
53196 + SIGSEGV, which will as a result inform you of when a error in a program
53197 + occurred, which in some cases could mean a possible exploit attempt.
53198 + If the sysctl option is enabled, a sysctl option with name
53199 + "signal_logging" is created.
53200 +
53201 +config GRKERNSEC_FORKFAIL
53202 + bool "Fork failure logging"
53203 + help
53204 + If you say Y here, all failed fork() attempts will be logged.
53205 + This could suggest a fork bomb, or someone attempting to overstep
53206 + their process limit. If the sysctl option is enabled, a sysctl option
53207 + with name "forkfail_logging" is created.
53208 +
53209 +config GRKERNSEC_TIME
53210 + bool "Time change logging"
53211 + default y if GRKERNSEC_CONFIG_AUTO
53212 + help
53213 + If you say Y here, any changes of the system clock will be logged.
53214 + If the sysctl option is enabled, a sysctl option with name
53215 + "timechange_logging" is created.
53216 +
53217 +config GRKERNSEC_PROC_IPADDR
53218 + bool "/proc/<pid>/ipaddr support"
53219 + default y if GRKERNSEC_CONFIG_AUTO
53220 + help
53221 + If you say Y here, a new entry will be added to each /proc/<pid>
53222 + directory that contains the IP address of the person using the task.
53223 + The IP is carried across local TCP and AF_UNIX stream sockets.
53224 + This information can be useful for IDS/IPSes to perform remote response
53225 + to a local attack. The entry is readable by only the owner of the
53226 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53227 + the RBAC system), and thus does not create privacy concerns.
53228 +
53229 +config GRKERNSEC_RWXMAP_LOG
53230 + bool 'Denied RWX mmap/mprotect logging'
53231 + default y if GRKERNSEC_CONFIG_AUTO
53232 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53233 + help
53234 + If you say Y here, calls to mmap() and mprotect() with explicit
53235 + usage of PROT_WRITE and PROT_EXEC together will be logged when
53236 + denied by the PAX_MPROTECT feature. If the sysctl option is
53237 + enabled, a sysctl option with name "rwxmap_logging" is created.
53238 +
53239 +config GRKERNSEC_AUDIT_TEXTREL
53240 + bool 'ELF text relocations logging (READ HELP)'
53241 + depends on PAX_MPROTECT
53242 + help
53243 + If you say Y here, text relocations will be logged with the filename
53244 + of the offending library or binary. The purpose of the feature is
53245 + to help Linux distribution developers get rid of libraries and
53246 + binaries that need text relocations which hinder the future progress
53247 + of PaX. Only Linux distribution developers should say Y here, and
53248 + never on a production machine, as this option creates an information
53249 + leak that could aid an attacker in defeating the randomization of
53250 + a single memory region. If the sysctl option is enabled, a sysctl
53251 + option with name "audit_textrel" is created.
53252 +
53253 +endmenu
53254 +
53255 +menu "Executable Protections"
53256 +depends on GRKERNSEC
53257 +
53258 +config GRKERNSEC_DMESG
53259 + bool "Dmesg(8) restriction"
53260 + default y if GRKERNSEC_CONFIG_AUTO
53261 + help
53262 + If you say Y here, non-root users will not be able to use dmesg(8)
53263 + to view the contents of the kernel's circular log buffer.
53264 + The kernel's log buffer often contains kernel addresses and other
53265 + identifying information useful to an attacker in fingerprinting a
53266 + system for a targeted exploit.
53267 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
53268 + created.
53269 +
53270 +config GRKERNSEC_HARDEN_PTRACE
53271 + bool "Deter ptrace-based process snooping"
53272 + default y if GRKERNSEC_CONFIG_AUTO
53273 + help
53274 + If you say Y here, TTY sniffers and other malicious monitoring
53275 + programs implemented through ptrace will be defeated. If you
53276 + have been using the RBAC system, this option has already been
53277 + enabled for several years for all users, with the ability to make
53278 + fine-grained exceptions.
53279 +
53280 + This option only affects the ability of non-root users to ptrace
53281 + processes that are not a descendent of the ptracing process.
53282 + This means that strace ./binary and gdb ./binary will still work,
53283 + but attaching to arbitrary processes will not. If the sysctl
53284 + option is enabled, a sysctl option with name "harden_ptrace" is
53285 + created.
53286 +
53287 +config GRKERNSEC_PTRACE_READEXEC
53288 + bool "Require read access to ptrace sensitive binaries"
53289 + default y if GRKERNSEC_CONFIG_AUTO
53290 + help
53291 + If you say Y here, unprivileged users will not be able to ptrace unreadable
53292 + binaries. This option is useful in environments that
53293 + remove the read bits (e.g. file mode 4711) from suid binaries to
53294 + prevent infoleaking of their contents. This option adds
53295 + consistency to the use of that file mode, as the binary could normally
53296 + be read out when run without privileges while ptracing.
53297 +
53298 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
53299 + is created.
53300 +
53301 +config GRKERNSEC_SETXID
53302 + bool "Enforce consistent multithreaded privileges"
53303 + default y if GRKERNSEC_CONFIG_AUTO
53304 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
53305 + help
53306 + If you say Y here, a change from a root uid to a non-root uid
53307 + in a multithreaded application will cause the resulting uids,
53308 + gids, supplementary groups, and capabilities in that thread
53309 + to be propagated to the other threads of the process. In most
53310 + cases this is unnecessary, as glibc will emulate this behavior
53311 + on behalf of the application. Other libcs do not act in the
53312 + same way, allowing the other threads of the process to continue
53313 + running with root privileges. If the sysctl option is enabled,
53314 + a sysctl option with name "consistent_setxid" is created.
53315 +
53316 +config GRKERNSEC_TPE
53317 + bool "Trusted Path Execution (TPE)"
53318 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53319 + help
53320 + If you say Y here, you will be able to choose a gid to add to the
53321 + supplementary groups of users you want to mark as "untrusted."
53322 + These users will not be able to execute any files that are not in
53323 + root-owned directories writable only by root. If the sysctl option
53324 + is enabled, a sysctl option with name "tpe" is created.
53325 +
53326 +config GRKERNSEC_TPE_ALL
53327 + bool "Partially restrict all non-root users"
53328 + depends on GRKERNSEC_TPE
53329 + help
53330 + If you say Y here, all non-root users will be covered under
53331 + a weaker TPE restriction. This is separate from, and in addition to,
53332 + the main TPE options that you have selected elsewhere. Thus, if a
53333 + "trusted" GID is chosen, this restriction applies to even that GID.
53334 + Under this restriction, all non-root users will only be allowed to
53335 + execute files in directories they own that are not group or
53336 + world-writable, or in directories owned by root and writable only by
53337 + root. If the sysctl option is enabled, a sysctl option with name
53338 + "tpe_restrict_all" is created.
53339 +
53340 +config GRKERNSEC_TPE_INVERT
53341 + bool "Invert GID option"
53342 + depends on GRKERNSEC_TPE
53343 + help
53344 + If you say Y here, the group you specify in the TPE configuration will
53345 + decide what group TPE restrictions will be *disabled* for. This
53346 + option is useful if you want TPE restrictions to be applied to most
53347 + users on the system. If the sysctl option is enabled, a sysctl option
53348 + with name "tpe_invert" is created. Unlike other sysctl options, this
53349 + entry will default to on for backward-compatibility.
53350 +
53351 +config GRKERNSEC_TPE_GID
53352 + int
53353 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
53354 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
53355 +
53356 +config GRKERNSEC_TPE_UNTRUSTED_GID
53357 + int "GID for TPE-untrusted users"
53358 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53359 + default 1005
53360 + help
53361 + Setting this GID determines what group TPE restrictions will be
53362 + *enabled* for. If the sysctl option is enabled, a sysctl option
53363 + with name "tpe_gid" is created.
53364 +
53365 +config GRKERNSEC_TPE_TRUSTED_GID
53366 + int "GID for TPE-trusted users"
53367 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53368 + default 1005
53369 + help
53370 + Setting this GID determines what group TPE restrictions will be
53371 + *disabled* for. If the sysctl option is enabled, a sysctl option
53372 + with name "tpe_gid" is created.
53373 +
53374 +endmenu
53375 +menu "Network Protections"
53376 +depends on GRKERNSEC
53377 +
53378 +config GRKERNSEC_RANDNET
53379 + bool "Larger entropy pools"
53380 + default y if GRKERNSEC_CONFIG_AUTO
53381 + help
53382 + If you say Y here, the entropy pools used for many features of Linux
53383 + and grsecurity will be doubled in size. Since several grsecurity
53384 + features use additional randomness, it is recommended that you say Y
53385 + here. Saying Y here has a similar effect as modifying
53386 + /proc/sys/kernel/random/poolsize.
53387 +
53388 +config GRKERNSEC_BLACKHOLE
53389 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53390 + default y if GRKERNSEC_CONFIG_AUTO
53391 + depends on NET
53392 + help
53393 + If you say Y here, neither TCP resets nor ICMP
53394 + destination-unreachable packets will be sent in response to packets
53395 + sent to ports for which no associated listening process exists.
53396 + This feature supports both IPV4 and IPV6 and exempts the
53397 + loopback interface from blackholing. Enabling this feature
53398 + makes a host more resilient to DoS attacks and reduces network
53399 + visibility against scanners.
53400 +
53401 + The blackhole feature as-implemented is equivalent to the FreeBSD
53402 + blackhole feature, as it prevents RST responses to all packets, not
53403 + just SYNs. Under most application behavior this causes no
53404 + problems, but applications (like haproxy) may not close certain
53405 + connections in a way that cleanly terminates them on the remote
53406 + end, leaving the remote host in LAST_ACK state. Because of this
53407 + side-effect and to prevent intentional LAST_ACK DoSes, this
53408 + feature also adds automatic mitigation against such attacks.
53409 + The mitigation drastically reduces the amount of time a socket
53410 + can spend in LAST_ACK state. If you're using haproxy and not
53411 + all servers it connects to have this option enabled, consider
53412 + disabling this feature on the haproxy host.
53413 +
53414 + If the sysctl option is enabled, two sysctl options with names
53415 + "ip_blackhole" and "lastack_retries" will be created.
53416 + While "ip_blackhole" takes the standard zero/non-zero on/off
53417 + toggle, "lastack_retries" uses the same kinds of values as
53418 + "tcp_retries1" and "tcp_retries2". The default value of 4
53419 + prevents a socket from lasting more than 45 seconds in LAST_ACK
53420 + state.
53421 +
53422 +config GRKERNSEC_NO_SIMULT_CONNECT
53423 + bool "Disable TCP Simultaneous Connect"
53424 + default y if GRKERNSEC_CONFIG_AUTO
53425 + depends on NET
53426 + help
53427 + If you say Y here, a feature by Willy Tarreau will be enabled that
53428 + removes a weakness in Linux's strict implementation of TCP that
53429 + allows two clients to connect to each other without either entering
53430 + a listening state. The weakness allows an attacker to easily prevent
53431 + a client from connecting to a known server provided the source port
53432 + for the connection is guessed correctly.
53433 +
53434 + As the weakness could be used to prevent an antivirus or IPS from
53435 + fetching updates, or prevent an SSL gateway from fetching a CRL,
53436 + it should be eliminated by enabling this option. Though Linux is
53437 + one of few operating systems supporting simultaneous connect, it
53438 + has no legitimate use in practice and is rarely supported by firewalls.
53439 +
53440 +config GRKERNSEC_SOCKET
53441 + bool "Socket restrictions"
53442 + depends on NET
53443 + help
53444 + If you say Y here, you will be able to choose from several options.
53445 + If you assign a GID on your system and add it to the supplementary
53446 + groups of users you want to restrict socket access to, this patch
53447 + will perform up to three things, based on the option(s) you choose.
53448 +
53449 +config GRKERNSEC_SOCKET_ALL
53450 + bool "Deny any sockets to group"
53451 + depends on GRKERNSEC_SOCKET
53452 + help
53453 + If you say Y here, you will be able to choose a GID of whose users will
53454 + be unable to connect to other hosts from your machine or run server
53455 + applications from your machine. If the sysctl option is enabled, a
53456 + sysctl option with name "socket_all" is created.
53457 +
53458 +config GRKERNSEC_SOCKET_ALL_GID
53459 + int "GID to deny all sockets for"
53460 + depends on GRKERNSEC_SOCKET_ALL
53461 + default 1004
53462 + help
53463 + Here you can choose the GID to disable socket access for. Remember to
53464 + add the users you want socket access disabled for to the GID
53465 + specified here. If the sysctl option is enabled, a sysctl option
53466 + with name "socket_all_gid" is created.
53467 +
53468 +config GRKERNSEC_SOCKET_CLIENT
53469 + bool "Deny client sockets to group"
53470 + depends on GRKERNSEC_SOCKET
53471 + help
53472 + If you say Y here, you will be able to choose a GID of whose users will
53473 + be unable to connect to other hosts from your machine, but will be
53474 + able to run servers. If this option is enabled, all users in the group
53475 + you specify will have to use passive mode when initiating ftp transfers
53476 + from the shell on your machine. If the sysctl option is enabled, a
53477 + sysctl option with name "socket_client" is created.
53478 +
53479 +config GRKERNSEC_SOCKET_CLIENT_GID
53480 + int "GID to deny client sockets for"
53481 + depends on GRKERNSEC_SOCKET_CLIENT
53482 + default 1003
53483 + help
53484 + Here you can choose the GID to disable client socket access for.
53485 + Remember to add the users you want client socket access disabled for to
53486 + the GID specified here. If the sysctl option is enabled, a sysctl
53487 + option with name "socket_client_gid" is created.
53488 +
53489 +config GRKERNSEC_SOCKET_SERVER
53490 + bool "Deny server sockets to group"
53491 + depends on GRKERNSEC_SOCKET
53492 + help
53493 + If you say Y here, you will be able to choose a GID of whose users will
53494 + be unable to run server applications from your machine. If the sysctl
53495 + option is enabled, a sysctl option with name "socket_server" is created.
53496 +
53497 +config GRKERNSEC_SOCKET_SERVER_GID
53498 + int "GID to deny server sockets for"
53499 + depends on GRKERNSEC_SOCKET_SERVER
53500 + default 1002
53501 + help
53502 + Here you can choose the GID to disable server socket access for.
53503 + Remember to add the users you want server socket access disabled for to
53504 + the GID specified here. If the sysctl option is enabled, a sysctl
53505 + option with name "socket_server_gid" is created.
53506 +
53507 +endmenu
53508 +menu "Sysctl Support"
53509 +depends on GRKERNSEC && SYSCTL
53510 +
53511 +config GRKERNSEC_SYSCTL
53512 + bool "Sysctl support"
53513 + default y if GRKERNSEC_CONFIG_AUTO
53514 + help
53515 + If you say Y here, you will be able to change the options that
53516 + grsecurity runs with at bootup, without having to recompile your
53517 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53518 + to enable (1) or disable (0) various features. All the sysctl entries
53519 + are mutable until the "grsec_lock" entry is set to a non-zero value.
53520 + All features enabled in the kernel configuration are disabled at boot
53521 + if you do not say Y to the "Turn on features by default" option.
53522 + All options should be set at startup, and the grsec_lock entry should
53523 + be set to a non-zero value after all the options are set.
53524 + *THIS IS EXTREMELY IMPORTANT*
53525 +
53526 +config GRKERNSEC_SYSCTL_DISTRO
53527 + bool "Extra sysctl support for distro makers (READ HELP)"
53528 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53529 + help
53530 + If you say Y here, additional sysctl options will be created
53531 + for features that affect processes running as root. Therefore,
53532 + it is critical when using this option that the grsec_lock entry be
53533 + enabled after boot. Only distros with prebuilt kernel packages
53534 + with this option enabled that can ensure grsec_lock is enabled
53535 + after boot should use this option.
53536 + *Failure to set grsec_lock after boot makes all grsec features
53537 + this option covers useless*
53538 +
53539 + Currently this option creates the following sysctl entries:
53540 + "Disable Privileged I/O": "disable_priv_io"
53541 +
53542 +config GRKERNSEC_SYSCTL_ON
53543 + bool "Turn on features by default"
53544 + default y if GRKERNSEC_CONFIG_AUTO
53545 + depends on GRKERNSEC_SYSCTL
53546 + help
53547 + If you say Y here, instead of having all features enabled in the
53548 + kernel configuration disabled at boot time, the features will be
53549 + enabled at boot time. It is recommended you say Y here unless
53550 + there is some reason you would want all sysctl-tunable features to
53551 + be disabled by default. As mentioned elsewhere, it is important
53552 + to enable the grsec_lock entry once you have finished modifying
53553 + the sysctl entries.
53554 +
53555 +endmenu
53556 +menu "Logging Options"
53557 +depends on GRKERNSEC
53558 +
53559 +config GRKERNSEC_FLOODTIME
53560 + int "Seconds in between log messages (minimum)"
53561 + default 10
53562 + help
53563 + This option allows you to enforce the number of seconds between
53564 + grsecurity log messages. The default should be suitable for most
53565 + people, however, if you choose to change it, choose a value small enough
53566 + to allow informative logs to be produced, but large enough to
53567 + prevent flooding.
53568 +
53569 +config GRKERNSEC_FLOODBURST
53570 + int "Number of messages in a burst (maximum)"
53571 + default 6
53572 + help
53573 + This option allows you to choose the maximum number of messages allowed
53574 + within the flood time interval you chose in a separate option. The
53575 + default should be suitable for most people, however if you find that
53576 + many of your logs are being interpreted as flooding, you may want to
53577 + raise this value.
53578 +
53579 +endmenu
53580 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53581 new file mode 100644
53582 index 0000000..1b9afa9
53583 --- /dev/null
53584 +++ b/grsecurity/Makefile
53585 @@ -0,0 +1,38 @@
53586 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53587 +# during 2001-2009 it has been completely redesigned by Brad Spengler
53588 +# into an RBAC system
53589 +#
53590 +# All code in this directory and various hooks inserted throughout the kernel
53591 +# are copyright Brad Spengler - Open Source Security, Inc., and released
53592 +# under the GPL v2 or higher
53593 +
53594 +KBUILD_CFLAGS += -Werror
53595 +
53596 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53597 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
53598 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53599 +
53600 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53601 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53602 + gracl_learn.o grsec_log.o
53603 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53604 +
53605 +ifdef CONFIG_NET
53606 +obj-y += grsec_sock.o
53607 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53608 +endif
53609 +
53610 +ifndef CONFIG_GRKERNSEC
53611 +obj-y += grsec_disabled.o
53612 +endif
53613 +
53614 +ifdef CONFIG_GRKERNSEC_HIDESYM
53615 +extra-y := grsec_hidesym.o
53616 +$(obj)/grsec_hidesym.o:
53617 + @-chmod -f 500 /boot
53618 + @-chmod -f 500 /lib/modules
53619 + @-chmod -f 500 /lib64/modules
53620 + @-chmod -f 500 /lib32/modules
53621 + @-chmod -f 700 .
53622 + @echo ' grsec: protected kernel image paths'
53623 +endif
53624 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53625 new file mode 100644
53626 index 0000000..960766a
53627 --- /dev/null
53628 +++ b/grsecurity/gracl.c
53629 @@ -0,0 +1,4003 @@
53630 +#include <linux/kernel.h>
53631 +#include <linux/module.h>
53632 +#include <linux/sched.h>
53633 +#include <linux/mm.h>
53634 +#include <linux/file.h>
53635 +#include <linux/fs.h>
53636 +#include <linux/namei.h>
53637 +#include <linux/mount.h>
53638 +#include <linux/tty.h>
53639 +#include <linux/proc_fs.h>
53640 +#include <linux/lglock.h>
53641 +#include <linux/slab.h>
53642 +#include <linux/vmalloc.h>
53643 +#include <linux/types.h>
53644 +#include <linux/sysctl.h>
53645 +#include <linux/netdevice.h>
53646 +#include <linux/ptrace.h>
53647 +#include <linux/gracl.h>
53648 +#include <linux/gralloc.h>
53649 +#include <linux/security.h>
53650 +#include <linux/grinternal.h>
53651 +#include <linux/pid_namespace.h>
53652 +#include <linux/stop_machine.h>
53653 +#include <linux/fdtable.h>
53654 +#include <linux/percpu.h>
53655 +#include <linux/lglock.h>
53656 +#include "../fs/mount.h"
53657 +
53658 +#include <asm/uaccess.h>
53659 +#include <asm/errno.h>
53660 +#include <asm/mman.h>
53661 +
53662 +extern struct lglock vfsmount_lock;
53663 +
53664 +static struct acl_role_db acl_role_set;
53665 +static struct name_db name_set;
53666 +static struct inodev_db inodev_set;
53667 +
53668 +/* for keeping track of userspace pointers used for subjects, so we
53669 + can share references in the kernel as well
53670 +*/
53671 +
53672 +static struct path real_root;
53673 +
53674 +static struct acl_subj_map_db subj_map_set;
53675 +
53676 +static struct acl_role_label *default_role;
53677 +
53678 +static struct acl_role_label *role_list;
53679 +
53680 +static u16 acl_sp_role_value;
53681 +
53682 +extern char *gr_shared_page[4];
53683 +static DEFINE_MUTEX(gr_dev_mutex);
53684 +DEFINE_RWLOCK(gr_inode_lock);
53685 +
53686 +struct gr_arg *gr_usermode;
53687 +
53688 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
53689 +
53690 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53691 +extern void gr_clear_learn_entries(void);
53692 +
53693 +unsigned char *gr_system_salt;
53694 +unsigned char *gr_system_sum;
53695 +
53696 +static struct sprole_pw **acl_special_roles = NULL;
53697 +static __u16 num_sprole_pws = 0;
53698 +
53699 +static struct acl_role_label *kernel_role = NULL;
53700 +
53701 +static unsigned int gr_auth_attempts = 0;
53702 +static unsigned long gr_auth_expires = 0UL;
53703 +
53704 +#ifdef CONFIG_NET
53705 +extern struct vfsmount *sock_mnt;
53706 +#endif
53707 +
53708 +extern struct vfsmount *pipe_mnt;
53709 +extern struct vfsmount *shm_mnt;
53710 +#ifdef CONFIG_HUGETLBFS
53711 +extern struct vfsmount *hugetlbfs_vfsmount;
53712 +#endif
53713 +
53714 +static struct acl_object_label *fakefs_obj_rw;
53715 +static struct acl_object_label *fakefs_obj_rwx;
53716 +
53717 +extern int gr_init_uidset(void);
53718 +extern void gr_free_uidset(void);
53719 +extern void gr_remove_uid(uid_t uid);
53720 +extern int gr_find_uid(uid_t uid);
53721 +
53722 +__inline__ int
53723 +gr_acl_is_enabled(void)
53724 +{
53725 + return (gr_status & GR_READY);
53726 +}
53727 +
53728 +#ifdef CONFIG_BTRFS_FS
53729 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53730 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53731 +#endif
53732 +
53733 +static inline dev_t __get_dev(const struct dentry *dentry)
53734 +{
53735 +#ifdef CONFIG_BTRFS_FS
53736 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53737 + return get_btrfs_dev_from_inode(dentry->d_inode);
53738 + else
53739 +#endif
53740 + return dentry->d_inode->i_sb->s_dev;
53741 +}
53742 +
53743 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53744 +{
53745 + return __get_dev(dentry);
53746 +}
53747 +
53748 +static char gr_task_roletype_to_char(struct task_struct *task)
53749 +{
53750 + switch (task->role->roletype &
53751 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53752 + GR_ROLE_SPECIAL)) {
53753 + case GR_ROLE_DEFAULT:
53754 + return 'D';
53755 + case GR_ROLE_USER:
53756 + return 'U';
53757 + case GR_ROLE_GROUP:
53758 + return 'G';
53759 + case GR_ROLE_SPECIAL:
53760 + return 'S';
53761 + }
53762 +
53763 + return 'X';
53764 +}
53765 +
53766 +char gr_roletype_to_char(void)
53767 +{
53768 + return gr_task_roletype_to_char(current);
53769 +}
53770 +
53771 +__inline__ int
53772 +gr_acl_tpe_check(void)
53773 +{
53774 + if (unlikely(!(gr_status & GR_READY)))
53775 + return 0;
53776 + if (current->role->roletype & GR_ROLE_TPE)
53777 + return 1;
53778 + else
53779 + return 0;
53780 +}
53781 +
53782 +int
53783 +gr_handle_rawio(const struct inode *inode)
53784 +{
53785 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53786 + if (inode && S_ISBLK(inode->i_mode) &&
53787 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53788 + !capable(CAP_SYS_RAWIO))
53789 + return 1;
53790 +#endif
53791 + return 0;
53792 +}
53793 +
53794 +static int
53795 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53796 +{
53797 + if (likely(lena != lenb))
53798 + return 0;
53799 +
53800 + return !memcmp(a, b, lena);
53801 +}
53802 +
53803 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53804 +{
53805 + *buflen -= namelen;
53806 + if (*buflen < 0)
53807 + return -ENAMETOOLONG;
53808 + *buffer -= namelen;
53809 + memcpy(*buffer, str, namelen);
53810 + return 0;
53811 +}
53812 +
53813 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53814 +{
53815 + return prepend(buffer, buflen, name->name, name->len);
53816 +}
53817 +
53818 +static int prepend_path(const struct path *path, struct path *root,
53819 + char **buffer, int *buflen)
53820 +{
53821 + struct dentry *dentry = path->dentry;
53822 + struct vfsmount *vfsmnt = path->mnt;
53823 + struct mount *mnt = real_mount(vfsmnt);
53824 + bool slash = false;
53825 + int error = 0;
53826 +
53827 + while (dentry != root->dentry || vfsmnt != root->mnt) {
53828 + struct dentry * parent;
53829 +
53830 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53831 + /* Global root? */
53832 + if (!mnt_has_parent(mnt)) {
53833 + goto out;
53834 + }
53835 + dentry = mnt->mnt_mountpoint;
53836 + mnt = mnt->mnt_parent;
53837 + vfsmnt = &mnt->mnt;
53838 + continue;
53839 + }
53840 + parent = dentry->d_parent;
53841 + prefetch(parent);
53842 + spin_lock(&dentry->d_lock);
53843 + error = prepend_name(buffer, buflen, &dentry->d_name);
53844 + spin_unlock(&dentry->d_lock);
53845 + if (!error)
53846 + error = prepend(buffer, buflen, "/", 1);
53847 + if (error)
53848 + break;
53849 +
53850 + slash = true;
53851 + dentry = parent;
53852 + }
53853 +
53854 +out:
53855 + if (!error && !slash)
53856 + error = prepend(buffer, buflen, "/", 1);
53857 +
53858 + return error;
53859 +}
53860 +
53861 +/* this must be called with vfsmount_lock and rename_lock held */
53862 +
53863 +static char *__our_d_path(const struct path *path, struct path *root,
53864 + char *buf, int buflen)
53865 +{
53866 + char *res = buf + buflen;
53867 + int error;
53868 +
53869 + prepend(&res, &buflen, "\0", 1);
53870 + error = prepend_path(path, root, &res, &buflen);
53871 + if (error)
53872 + return ERR_PTR(error);
53873 +
53874 + return res;
53875 +}
53876 +
53877 +static char *
53878 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53879 +{
53880 + char *retval;
53881 +
53882 + retval = __our_d_path(path, root, buf, buflen);
53883 + if (unlikely(IS_ERR(retval)))
53884 + retval = strcpy(buf, "<path too long>");
53885 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53886 + retval[1] = '\0';
53887 +
53888 + return retval;
53889 +}
53890 +
53891 +static char *
53892 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53893 + char *buf, int buflen)
53894 +{
53895 + struct path path;
53896 + char *res;
53897 +
53898 + path.dentry = (struct dentry *)dentry;
53899 + path.mnt = (struct vfsmount *)vfsmnt;
53900 +
53901 + /* we can use real_root.dentry, real_root.mnt, because this is only called
53902 + by the RBAC system */
53903 + res = gen_full_path(&path, &real_root, buf, buflen);
53904 +
53905 + return res;
53906 +}
53907 +
53908 +static char *
53909 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53910 + char *buf, int buflen)
53911 +{
53912 + char *res;
53913 + struct path path;
53914 + struct path root;
53915 + struct task_struct *reaper = init_pid_ns.child_reaper;
53916 +
53917 + path.dentry = (struct dentry *)dentry;
53918 + path.mnt = (struct vfsmount *)vfsmnt;
53919 +
53920 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53921 + get_fs_root(reaper->fs, &root);
53922 +
53923 + write_seqlock(&rename_lock);
53924 + br_read_lock(&vfsmount_lock);
53925 + res = gen_full_path(&path, &root, buf, buflen);
53926 + br_read_unlock(&vfsmount_lock);
53927 + write_sequnlock(&rename_lock);
53928 +
53929 + path_put(&root);
53930 + return res;
53931 +}
53932 +
53933 +static char *
53934 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53935 +{
53936 + char *ret;
53937 + write_seqlock(&rename_lock);
53938 + br_read_lock(&vfsmount_lock);
53939 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53940 + PAGE_SIZE);
53941 + br_read_unlock(&vfsmount_lock);
53942 + write_sequnlock(&rename_lock);
53943 + return ret;
53944 +}
53945 +
53946 +static char *
53947 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53948 +{
53949 + char *ret;
53950 + char *buf;
53951 + int buflen;
53952 +
53953 + write_seqlock(&rename_lock);
53954 + br_read_lock(&vfsmount_lock);
53955 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53956 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
53957 + buflen = (int)(ret - buf);
53958 + if (buflen >= 5)
53959 + prepend(&ret, &buflen, "/proc", 5);
53960 + else
53961 + ret = strcpy(buf, "<path too long>");
53962 + br_read_unlock(&vfsmount_lock);
53963 + write_sequnlock(&rename_lock);
53964 + return ret;
53965 +}
53966 +
53967 +char *
53968 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
53969 +{
53970 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53971 + PAGE_SIZE);
53972 +}
53973 +
53974 +char *
53975 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
53976 +{
53977 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53978 + PAGE_SIZE);
53979 +}
53980 +
53981 +char *
53982 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
53983 +{
53984 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
53985 + PAGE_SIZE);
53986 +}
53987 +
53988 +char *
53989 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
53990 +{
53991 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
53992 + PAGE_SIZE);
53993 +}
53994 +
53995 +char *
53996 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
53997 +{
53998 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
53999 + PAGE_SIZE);
54000 +}
54001 +
54002 +__inline__ __u32
54003 +to_gr_audit(const __u32 reqmode)
54004 +{
54005 + /* masks off auditable permission flags, then shifts them to create
54006 + auditing flags, and adds the special case of append auditing if
54007 + we're requesting write */
54008 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54009 +}
54010 +
54011 +struct acl_subject_label *
54012 +lookup_subject_map(const struct acl_subject_label *userp)
54013 +{
54014 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
54015 + struct subject_map *match;
54016 +
54017 + match = subj_map_set.s_hash[index];
54018 +
54019 + while (match && match->user != userp)
54020 + match = match->next;
54021 +
54022 + if (match != NULL)
54023 + return match->kernel;
54024 + else
54025 + return NULL;
54026 +}
54027 +
54028 +static void
54029 +insert_subj_map_entry(struct subject_map *subjmap)
54030 +{
54031 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54032 + struct subject_map **curr;
54033 +
54034 + subjmap->prev = NULL;
54035 +
54036 + curr = &subj_map_set.s_hash[index];
54037 + if (*curr != NULL)
54038 + (*curr)->prev = subjmap;
54039 +
54040 + subjmap->next = *curr;
54041 + *curr = subjmap;
54042 +
54043 + return;
54044 +}
54045 +
54046 +static struct acl_role_label *
54047 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54048 + const gid_t gid)
54049 +{
54050 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54051 + struct acl_role_label *match;
54052 + struct role_allowed_ip *ipp;
54053 + unsigned int x;
54054 + u32 curr_ip = task->signal->curr_ip;
54055 +
54056 + task->signal->saved_ip = curr_ip;
54057 +
54058 + match = acl_role_set.r_hash[index];
54059 +
54060 + while (match) {
54061 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54062 + for (x = 0; x < match->domain_child_num; x++) {
54063 + if (match->domain_children[x] == uid)
54064 + goto found;
54065 + }
54066 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54067 + break;
54068 + match = match->next;
54069 + }
54070 +found:
54071 + if (match == NULL) {
54072 + try_group:
54073 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54074 + match = acl_role_set.r_hash[index];
54075 +
54076 + while (match) {
54077 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54078 + for (x = 0; x < match->domain_child_num; x++) {
54079 + if (match->domain_children[x] == gid)
54080 + goto found2;
54081 + }
54082 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54083 + break;
54084 + match = match->next;
54085 + }
54086 +found2:
54087 + if (match == NULL)
54088 + match = default_role;
54089 + if (match->allowed_ips == NULL)
54090 + return match;
54091 + else {
54092 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54093 + if (likely
54094 + ((ntohl(curr_ip) & ipp->netmask) ==
54095 + (ntohl(ipp->addr) & ipp->netmask)))
54096 + return match;
54097 + }
54098 + match = default_role;
54099 + }
54100 + } else if (match->allowed_ips == NULL) {
54101 + return match;
54102 + } else {
54103 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54104 + if (likely
54105 + ((ntohl(curr_ip) & ipp->netmask) ==
54106 + (ntohl(ipp->addr) & ipp->netmask)))
54107 + return match;
54108 + }
54109 + goto try_group;
54110 + }
54111 +
54112 + return match;
54113 +}
54114 +
54115 +struct acl_subject_label *
54116 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54117 + const struct acl_role_label *role)
54118 +{
54119 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54120 + struct acl_subject_label *match;
54121 +
54122 + match = role->subj_hash[index];
54123 +
54124 + while (match && (match->inode != ino || match->device != dev ||
54125 + (match->mode & GR_DELETED))) {
54126 + match = match->next;
54127 + }
54128 +
54129 + if (match && !(match->mode & GR_DELETED))
54130 + return match;
54131 + else
54132 + return NULL;
54133 +}
54134 +
54135 +struct acl_subject_label *
54136 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54137 + const struct acl_role_label *role)
54138 +{
54139 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54140 + struct acl_subject_label *match;
54141 +
54142 + match = role->subj_hash[index];
54143 +
54144 + while (match && (match->inode != ino || match->device != dev ||
54145 + !(match->mode & GR_DELETED))) {
54146 + match = match->next;
54147 + }
54148 +
54149 + if (match && (match->mode & GR_DELETED))
54150 + return match;
54151 + else
54152 + return NULL;
54153 +}
54154 +
54155 +static struct acl_object_label *
54156 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
54157 + const struct acl_subject_label *subj)
54158 +{
54159 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54160 + struct acl_object_label *match;
54161 +
54162 + match = subj->obj_hash[index];
54163 +
54164 + while (match && (match->inode != ino || match->device != dev ||
54165 + (match->mode & GR_DELETED))) {
54166 + match = match->next;
54167 + }
54168 +
54169 + if (match && !(match->mode & GR_DELETED))
54170 + return match;
54171 + else
54172 + return NULL;
54173 +}
54174 +
54175 +static struct acl_object_label *
54176 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54177 + const struct acl_subject_label *subj)
54178 +{
54179 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54180 + struct acl_object_label *match;
54181 +
54182 + match = subj->obj_hash[index];
54183 +
54184 + while (match && (match->inode != ino || match->device != dev ||
54185 + !(match->mode & GR_DELETED))) {
54186 + match = match->next;
54187 + }
54188 +
54189 + if (match && (match->mode & GR_DELETED))
54190 + return match;
54191 +
54192 + match = subj->obj_hash[index];
54193 +
54194 + while (match && (match->inode != ino || match->device != dev ||
54195 + (match->mode & GR_DELETED))) {
54196 + match = match->next;
54197 + }
54198 +
54199 + if (match && !(match->mode & GR_DELETED))
54200 + return match;
54201 + else
54202 + return NULL;
54203 +}
54204 +
54205 +static struct name_entry *
54206 +lookup_name_entry(const char *name)
54207 +{
54208 + unsigned int len = strlen(name);
54209 + unsigned int key = full_name_hash(name, len);
54210 + unsigned int index = key % name_set.n_size;
54211 + struct name_entry *match;
54212 +
54213 + match = name_set.n_hash[index];
54214 +
54215 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
54216 + match = match->next;
54217 +
54218 + return match;
54219 +}
54220 +
54221 +static struct name_entry *
54222 +lookup_name_entry_create(const char *name)
54223 +{
54224 + unsigned int len = strlen(name);
54225 + unsigned int key = full_name_hash(name, len);
54226 + unsigned int index = key % name_set.n_size;
54227 + struct name_entry *match;
54228 +
54229 + match = name_set.n_hash[index];
54230 +
54231 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54232 + !match->deleted))
54233 + match = match->next;
54234 +
54235 + if (match && match->deleted)
54236 + return match;
54237 +
54238 + match = name_set.n_hash[index];
54239 +
54240 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54241 + match->deleted))
54242 + match = match->next;
54243 +
54244 + if (match && !match->deleted)
54245 + return match;
54246 + else
54247 + return NULL;
54248 +}
54249 +
54250 +static struct inodev_entry *
54251 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
54252 +{
54253 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
54254 + struct inodev_entry *match;
54255 +
54256 + match = inodev_set.i_hash[index];
54257 +
54258 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
54259 + match = match->next;
54260 +
54261 + return match;
54262 +}
54263 +
54264 +static void
54265 +insert_inodev_entry(struct inodev_entry *entry)
54266 +{
54267 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
54268 + inodev_set.i_size);
54269 + struct inodev_entry **curr;
54270 +
54271 + entry->prev = NULL;
54272 +
54273 + curr = &inodev_set.i_hash[index];
54274 + if (*curr != NULL)
54275 + (*curr)->prev = entry;
54276 +
54277 + entry->next = *curr;
54278 + *curr = entry;
54279 +
54280 + return;
54281 +}
54282 +
54283 +static void
54284 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
54285 +{
54286 + unsigned int index =
54287 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
54288 + struct acl_role_label **curr;
54289 + struct acl_role_label *tmp, *tmp2;
54290 +
54291 + curr = &acl_role_set.r_hash[index];
54292 +
54293 + /* simple case, slot is empty, just set it to our role */
54294 + if (*curr == NULL) {
54295 + *curr = role;
54296 + } else {
54297 + /* example:
54298 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
54299 + 2 -> 3
54300 + */
54301 + /* first check to see if we can already be reached via this slot */
54302 + tmp = *curr;
54303 + while (tmp && tmp != role)
54304 + tmp = tmp->next;
54305 + if (tmp == role) {
54306 + /* we don't need to add ourselves to this slot's chain */
54307 + return;
54308 + }
54309 + /* we need to add ourselves to this chain, two cases */
54310 + if (role->next == NULL) {
54311 + /* simple case, append the current chain to our role */
54312 + role->next = *curr;
54313 + *curr = role;
54314 + } else {
54315 + /* 1 -> 2 -> 3 -> 4
54316 + 2 -> 3 -> 4
54317 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
54318 + */
54319 + /* trickier case: walk our role's chain until we find
54320 + the role for the start of the current slot's chain */
54321 + tmp = role;
54322 + tmp2 = *curr;
54323 + while (tmp->next && tmp->next != tmp2)
54324 + tmp = tmp->next;
54325 + if (tmp->next == tmp2) {
54326 + /* from example above, we found 3, so just
54327 + replace this slot's chain with ours */
54328 + *curr = role;
54329 + } else {
54330 + /* we didn't find a subset of our role's chain
54331 + in the current slot's chain, so append their
54332 + chain to ours, and set us as the first role in
54333 + the slot's chain
54334 +
54335 + we could fold this case with the case above,
54336 + but making it explicit for clarity
54337 + */
54338 + tmp->next = tmp2;
54339 + *curr = role;
54340 + }
54341 + }
54342 + }
54343 +
54344 + return;
54345 +}
54346 +
54347 +static void
54348 +insert_acl_role_label(struct acl_role_label *role)
54349 +{
54350 + int i;
54351 +
54352 + if (role_list == NULL) {
54353 + role_list = role;
54354 + role->prev = NULL;
54355 + } else {
54356 + role->prev = role_list;
54357 + role_list = role;
54358 + }
54359 +
54360 + /* used for hash chains */
54361 + role->next = NULL;
54362 +
54363 + if (role->roletype & GR_ROLE_DOMAIN) {
54364 + for (i = 0; i < role->domain_child_num; i++)
54365 + __insert_acl_role_label(role, role->domain_children[i]);
54366 + } else
54367 + __insert_acl_role_label(role, role->uidgid);
54368 +}
54369 +
54370 +static int
54371 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
54372 +{
54373 + struct name_entry **curr, *nentry;
54374 + struct inodev_entry *ientry;
54375 + unsigned int len = strlen(name);
54376 + unsigned int key = full_name_hash(name, len);
54377 + unsigned int index = key % name_set.n_size;
54378 +
54379 + curr = &name_set.n_hash[index];
54380 +
54381 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
54382 + curr = &((*curr)->next);
54383 +
54384 + if (*curr != NULL)
54385 + return 1;
54386 +
54387 + nentry = acl_alloc(sizeof (struct name_entry));
54388 + if (nentry == NULL)
54389 + return 0;
54390 + ientry = acl_alloc(sizeof (struct inodev_entry));
54391 + if (ientry == NULL)
54392 + return 0;
54393 + ientry->nentry = nentry;
54394 +
54395 + nentry->key = key;
54396 + nentry->name = name;
54397 + nentry->inode = inode;
54398 + nentry->device = device;
54399 + nentry->len = len;
54400 + nentry->deleted = deleted;
54401 +
54402 + nentry->prev = NULL;
54403 + curr = &name_set.n_hash[index];
54404 + if (*curr != NULL)
54405 + (*curr)->prev = nentry;
54406 + nentry->next = *curr;
54407 + *curr = nentry;
54408 +
54409 + /* insert us into the table searchable by inode/dev */
54410 + insert_inodev_entry(ientry);
54411 +
54412 + return 1;
54413 +}
54414 +
54415 +static void
54416 +insert_acl_obj_label(struct acl_object_label *obj,
54417 + struct acl_subject_label *subj)
54418 +{
54419 + unsigned int index =
54420 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
54421 + struct acl_object_label **curr;
54422 +
54423 +
54424 + obj->prev = NULL;
54425 +
54426 + curr = &subj->obj_hash[index];
54427 + if (*curr != NULL)
54428 + (*curr)->prev = obj;
54429 +
54430 + obj->next = *curr;
54431 + *curr = obj;
54432 +
54433 + return;
54434 +}
54435 +
54436 +static void
54437 +insert_acl_subj_label(struct acl_subject_label *obj,
54438 + struct acl_role_label *role)
54439 +{
54440 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
54441 + struct acl_subject_label **curr;
54442 +
54443 + obj->prev = NULL;
54444 +
54445 + curr = &role->subj_hash[index];
54446 + if (*curr != NULL)
54447 + (*curr)->prev = obj;
54448 +
54449 + obj->next = *curr;
54450 + *curr = obj;
54451 +
54452 + return;
54453 +}
54454 +
54455 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
54456 +
54457 +static void *
54458 +create_table(__u32 * len, int elementsize)
54459 +{
54460 + unsigned int table_sizes[] = {
54461 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
54462 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
54463 + 4194301, 8388593, 16777213, 33554393, 67108859
54464 + };
54465 + void *newtable = NULL;
54466 + unsigned int pwr = 0;
54467 +
54468 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
54469 + table_sizes[pwr] <= *len)
54470 + pwr++;
54471 +
54472 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
54473 + return newtable;
54474 +
54475 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54476 + newtable =
54477 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54478 + else
54479 + newtable = vmalloc(table_sizes[pwr] * elementsize);
54480 +
54481 + *len = table_sizes[pwr];
54482 +
54483 + return newtable;
54484 +}
54485 +
54486 +static int
54487 +init_variables(const struct gr_arg *arg)
54488 +{
54489 + struct task_struct *reaper = init_pid_ns.child_reaper;
54490 + unsigned int stacksize;
54491 +
54492 + subj_map_set.s_size = arg->role_db.num_subjects;
54493 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54494 + name_set.n_size = arg->role_db.num_objects;
54495 + inodev_set.i_size = arg->role_db.num_objects;
54496 +
54497 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
54498 + !name_set.n_size || !inodev_set.i_size)
54499 + return 1;
54500 +
54501 + if (!gr_init_uidset())
54502 + return 1;
54503 +
54504 + /* set up the stack that holds allocation info */
54505 +
54506 + stacksize = arg->role_db.num_pointers + 5;
54507 +
54508 + if (!acl_alloc_stack_init(stacksize))
54509 + return 1;
54510 +
54511 + /* grab reference for the real root dentry and vfsmount */
54512 + get_fs_root(reaper->fs, &real_root);
54513 +
54514 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54515 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54516 +#endif
54517 +
54518 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54519 + if (fakefs_obj_rw == NULL)
54520 + return 1;
54521 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54522 +
54523 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54524 + if (fakefs_obj_rwx == NULL)
54525 + return 1;
54526 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54527 +
54528 + subj_map_set.s_hash =
54529 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54530 + acl_role_set.r_hash =
54531 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54532 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54533 + inodev_set.i_hash =
54534 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54535 +
54536 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54537 + !name_set.n_hash || !inodev_set.i_hash)
54538 + return 1;
54539 +
54540 + memset(subj_map_set.s_hash, 0,
54541 + sizeof(struct subject_map *) * subj_map_set.s_size);
54542 + memset(acl_role_set.r_hash, 0,
54543 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
54544 + memset(name_set.n_hash, 0,
54545 + sizeof (struct name_entry *) * name_set.n_size);
54546 + memset(inodev_set.i_hash, 0,
54547 + sizeof (struct inodev_entry *) * inodev_set.i_size);
54548 +
54549 + return 0;
54550 +}
54551 +
54552 +/* free information not needed after startup
54553 + currently contains user->kernel pointer mappings for subjects
54554 +*/
54555 +
54556 +static void
54557 +free_init_variables(void)
54558 +{
54559 + __u32 i;
54560 +
54561 + if (subj_map_set.s_hash) {
54562 + for (i = 0; i < subj_map_set.s_size; i++) {
54563 + if (subj_map_set.s_hash[i]) {
54564 + kfree(subj_map_set.s_hash[i]);
54565 + subj_map_set.s_hash[i] = NULL;
54566 + }
54567 + }
54568 +
54569 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54570 + PAGE_SIZE)
54571 + kfree(subj_map_set.s_hash);
54572 + else
54573 + vfree(subj_map_set.s_hash);
54574 + }
54575 +
54576 + return;
54577 +}
54578 +
54579 +static void
54580 +free_variables(void)
54581 +{
54582 + struct acl_subject_label *s;
54583 + struct acl_role_label *r;
54584 + struct task_struct *task, *task2;
54585 + unsigned int x;
54586 +
54587 + gr_clear_learn_entries();
54588 +
54589 + read_lock(&tasklist_lock);
54590 + do_each_thread(task2, task) {
54591 + task->acl_sp_role = 0;
54592 + task->acl_role_id = 0;
54593 + task->acl = NULL;
54594 + task->role = NULL;
54595 + } while_each_thread(task2, task);
54596 + read_unlock(&tasklist_lock);
54597 +
54598 + /* release the reference to the real root dentry and vfsmount */
54599 + path_put(&real_root);
54600 + memset(&real_root, 0, sizeof(real_root));
54601 +
54602 + /* free all object hash tables */
54603 +
54604 + FOR_EACH_ROLE_START(r)
54605 + if (r->subj_hash == NULL)
54606 + goto next_role;
54607 + FOR_EACH_SUBJECT_START(r, s, x)
54608 + if (s->obj_hash == NULL)
54609 + break;
54610 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54611 + kfree(s->obj_hash);
54612 + else
54613 + vfree(s->obj_hash);
54614 + FOR_EACH_SUBJECT_END(s, x)
54615 + FOR_EACH_NESTED_SUBJECT_START(r, s)
54616 + if (s->obj_hash == NULL)
54617 + break;
54618 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54619 + kfree(s->obj_hash);
54620 + else
54621 + vfree(s->obj_hash);
54622 + FOR_EACH_NESTED_SUBJECT_END(s)
54623 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54624 + kfree(r->subj_hash);
54625 + else
54626 + vfree(r->subj_hash);
54627 + r->subj_hash = NULL;
54628 +next_role:
54629 + FOR_EACH_ROLE_END(r)
54630 +
54631 + acl_free_all();
54632 +
54633 + if (acl_role_set.r_hash) {
54634 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54635 + PAGE_SIZE)
54636 + kfree(acl_role_set.r_hash);
54637 + else
54638 + vfree(acl_role_set.r_hash);
54639 + }
54640 + if (name_set.n_hash) {
54641 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
54642 + PAGE_SIZE)
54643 + kfree(name_set.n_hash);
54644 + else
54645 + vfree(name_set.n_hash);
54646 + }
54647 +
54648 + if (inodev_set.i_hash) {
54649 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54650 + PAGE_SIZE)
54651 + kfree(inodev_set.i_hash);
54652 + else
54653 + vfree(inodev_set.i_hash);
54654 + }
54655 +
54656 + gr_free_uidset();
54657 +
54658 + memset(&name_set, 0, sizeof (struct name_db));
54659 + memset(&inodev_set, 0, sizeof (struct inodev_db));
54660 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54661 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54662 +
54663 + default_role = NULL;
54664 + kernel_role = NULL;
54665 + role_list = NULL;
54666 +
54667 + return;
54668 +}
54669 +
54670 +static __u32
54671 +count_user_objs(struct acl_object_label *userp)
54672 +{
54673 + struct acl_object_label o_tmp;
54674 + __u32 num = 0;
54675 +
54676 + while (userp) {
54677 + if (copy_from_user(&o_tmp, userp,
54678 + sizeof (struct acl_object_label)))
54679 + break;
54680 +
54681 + userp = o_tmp.prev;
54682 + num++;
54683 + }
54684 +
54685 + return num;
54686 +}
54687 +
54688 +static struct acl_subject_label *
54689 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54690 +
54691 +static int
54692 +copy_user_glob(struct acl_object_label *obj)
54693 +{
54694 + struct acl_object_label *g_tmp, **guser;
54695 + unsigned int len;
54696 + char *tmp;
54697 +
54698 + if (obj->globbed == NULL)
54699 + return 0;
54700 +
54701 + guser = &obj->globbed;
54702 + while (*guser) {
54703 + g_tmp = (struct acl_object_label *)
54704 + acl_alloc(sizeof (struct acl_object_label));
54705 + if (g_tmp == NULL)
54706 + return -ENOMEM;
54707 +
54708 + if (copy_from_user(g_tmp, *guser,
54709 + sizeof (struct acl_object_label)))
54710 + return -EFAULT;
54711 +
54712 + len = strnlen_user(g_tmp->filename, PATH_MAX);
54713 +
54714 + if (!len || len >= PATH_MAX)
54715 + return -EINVAL;
54716 +
54717 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54718 + return -ENOMEM;
54719 +
54720 + if (copy_from_user(tmp, g_tmp->filename, len))
54721 + return -EFAULT;
54722 + tmp[len-1] = '\0';
54723 + g_tmp->filename = tmp;
54724 +
54725 + *guser = g_tmp;
54726 + guser = &(g_tmp->next);
54727 + }
54728 +
54729 + return 0;
54730 +}
54731 +
54732 +static int
54733 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54734 + struct acl_role_label *role)
54735 +{
54736 + struct acl_object_label *o_tmp;
54737 + unsigned int len;
54738 + int ret;
54739 + char *tmp;
54740 +
54741 + while (userp) {
54742 + if ((o_tmp = (struct acl_object_label *)
54743 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
54744 + return -ENOMEM;
54745 +
54746 + if (copy_from_user(o_tmp, userp,
54747 + sizeof (struct acl_object_label)))
54748 + return -EFAULT;
54749 +
54750 + userp = o_tmp->prev;
54751 +
54752 + len = strnlen_user(o_tmp->filename, PATH_MAX);
54753 +
54754 + if (!len || len >= PATH_MAX)
54755 + return -EINVAL;
54756 +
54757 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54758 + return -ENOMEM;
54759 +
54760 + if (copy_from_user(tmp, o_tmp->filename, len))
54761 + return -EFAULT;
54762 + tmp[len-1] = '\0';
54763 + o_tmp->filename = tmp;
54764 +
54765 + insert_acl_obj_label(o_tmp, subj);
54766 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54767 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54768 + return -ENOMEM;
54769 +
54770 + ret = copy_user_glob(o_tmp);
54771 + if (ret)
54772 + return ret;
54773 +
54774 + if (o_tmp->nested) {
54775 + int already_copied;
54776 +
54777 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54778 + if (IS_ERR(o_tmp->nested))
54779 + return PTR_ERR(o_tmp->nested);
54780 +
54781 + /* insert into nested subject list if we haven't copied this one yet
54782 + to prevent duplicate entries */
54783 + if (!already_copied) {
54784 + o_tmp->nested->next = role->hash->first;
54785 + role->hash->first = o_tmp->nested;
54786 + }
54787 + }
54788 + }
54789 +
54790 + return 0;
54791 +}
54792 +
54793 +static __u32
54794 +count_user_subjs(struct acl_subject_label *userp)
54795 +{
54796 + struct acl_subject_label s_tmp;
54797 + __u32 num = 0;
54798 +
54799 + while (userp) {
54800 + if (copy_from_user(&s_tmp, userp,
54801 + sizeof (struct acl_subject_label)))
54802 + break;
54803 +
54804 + userp = s_tmp.prev;
54805 + }
54806 +
54807 + return num;
54808 +}
54809 +
54810 +static int
54811 +copy_user_allowedips(struct acl_role_label *rolep)
54812 +{
54813 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54814 +
54815 + ruserip = rolep->allowed_ips;
54816 +
54817 + while (ruserip) {
54818 + rlast = rtmp;
54819 +
54820 + if ((rtmp = (struct role_allowed_ip *)
54821 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54822 + return -ENOMEM;
54823 +
54824 + if (copy_from_user(rtmp, ruserip,
54825 + sizeof (struct role_allowed_ip)))
54826 + return -EFAULT;
54827 +
54828 + ruserip = rtmp->prev;
54829 +
54830 + if (!rlast) {
54831 + rtmp->prev = NULL;
54832 + rolep->allowed_ips = rtmp;
54833 + } else {
54834 + rlast->next = rtmp;
54835 + rtmp->prev = rlast;
54836 + }
54837 +
54838 + if (!ruserip)
54839 + rtmp->next = NULL;
54840 + }
54841 +
54842 + return 0;
54843 +}
54844 +
54845 +static int
54846 +copy_user_transitions(struct acl_role_label *rolep)
54847 +{
54848 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
54849 +
54850 + unsigned int len;
54851 + char *tmp;
54852 +
54853 + rusertp = rolep->transitions;
54854 +
54855 + while (rusertp) {
54856 + rlast = rtmp;
54857 +
54858 + if ((rtmp = (struct role_transition *)
54859 + acl_alloc(sizeof (struct role_transition))) == NULL)
54860 + return -ENOMEM;
54861 +
54862 + if (copy_from_user(rtmp, rusertp,
54863 + sizeof (struct role_transition)))
54864 + return -EFAULT;
54865 +
54866 + rusertp = rtmp->prev;
54867 +
54868 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54869 +
54870 + if (!len || len >= GR_SPROLE_LEN)
54871 + return -EINVAL;
54872 +
54873 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54874 + return -ENOMEM;
54875 +
54876 + if (copy_from_user(tmp, rtmp->rolename, len))
54877 + return -EFAULT;
54878 + tmp[len-1] = '\0';
54879 + rtmp->rolename = tmp;
54880 +
54881 + if (!rlast) {
54882 + rtmp->prev = NULL;
54883 + rolep->transitions = rtmp;
54884 + } else {
54885 + rlast->next = rtmp;
54886 + rtmp->prev = rlast;
54887 + }
54888 +
54889 + if (!rusertp)
54890 + rtmp->next = NULL;
54891 + }
54892 +
54893 + return 0;
54894 +}
54895 +
54896 +static struct acl_subject_label *
54897 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54898 +{
54899 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54900 + unsigned int len;
54901 + char *tmp;
54902 + __u32 num_objs;
54903 + struct acl_ip_label **i_tmp, *i_utmp2;
54904 + struct gr_hash_struct ghash;
54905 + struct subject_map *subjmap;
54906 + unsigned int i_num;
54907 + int err;
54908 +
54909 + if (already_copied != NULL)
54910 + *already_copied = 0;
54911 +
54912 + s_tmp = lookup_subject_map(userp);
54913 +
54914 + /* we've already copied this subject into the kernel, just return
54915 + the reference to it, and don't copy it over again
54916 + */
54917 + if (s_tmp) {
54918 + if (already_copied != NULL)
54919 + *already_copied = 1;
54920 + return(s_tmp);
54921 + }
54922 +
54923 + if ((s_tmp = (struct acl_subject_label *)
54924 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54925 + return ERR_PTR(-ENOMEM);
54926 +
54927 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54928 + if (subjmap == NULL)
54929 + return ERR_PTR(-ENOMEM);
54930 +
54931 + subjmap->user = userp;
54932 + subjmap->kernel = s_tmp;
54933 + insert_subj_map_entry(subjmap);
54934 +
54935 + if (copy_from_user(s_tmp, userp,
54936 + sizeof (struct acl_subject_label)))
54937 + return ERR_PTR(-EFAULT);
54938 +
54939 + len = strnlen_user(s_tmp->filename, PATH_MAX);
54940 +
54941 + if (!len || len >= PATH_MAX)
54942 + return ERR_PTR(-EINVAL);
54943 +
54944 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54945 + return ERR_PTR(-ENOMEM);
54946 +
54947 + if (copy_from_user(tmp, s_tmp->filename, len))
54948 + return ERR_PTR(-EFAULT);
54949 + tmp[len-1] = '\0';
54950 + s_tmp->filename = tmp;
54951 +
54952 + if (!strcmp(s_tmp->filename, "/"))
54953 + role->root_label = s_tmp;
54954 +
54955 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
54956 + return ERR_PTR(-EFAULT);
54957 +
54958 + /* copy user and group transition tables */
54959 +
54960 + if (s_tmp->user_trans_num) {
54961 + uid_t *uidlist;
54962 +
54963 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
54964 + if (uidlist == NULL)
54965 + return ERR_PTR(-ENOMEM);
54966 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
54967 + return ERR_PTR(-EFAULT);
54968 +
54969 + s_tmp->user_transitions = uidlist;
54970 + }
54971 +
54972 + if (s_tmp->group_trans_num) {
54973 + gid_t *gidlist;
54974 +
54975 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
54976 + if (gidlist == NULL)
54977 + return ERR_PTR(-ENOMEM);
54978 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
54979 + return ERR_PTR(-EFAULT);
54980 +
54981 + s_tmp->group_transitions = gidlist;
54982 + }
54983 +
54984 + /* set up object hash table */
54985 + num_objs = count_user_objs(ghash.first);
54986 +
54987 + s_tmp->obj_hash_size = num_objs;
54988 + s_tmp->obj_hash =
54989 + (struct acl_object_label **)
54990 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
54991 +
54992 + if (!s_tmp->obj_hash)
54993 + return ERR_PTR(-ENOMEM);
54994 +
54995 + memset(s_tmp->obj_hash, 0,
54996 + s_tmp->obj_hash_size *
54997 + sizeof (struct acl_object_label *));
54998 +
54999 + /* add in objects */
55000 + err = copy_user_objs(ghash.first, s_tmp, role);
55001 +
55002 + if (err)
55003 + return ERR_PTR(err);
55004 +
55005 + /* set pointer for parent subject */
55006 + if (s_tmp->parent_subject) {
55007 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55008 +
55009 + if (IS_ERR(s_tmp2))
55010 + return s_tmp2;
55011 +
55012 + s_tmp->parent_subject = s_tmp2;
55013 + }
55014 +
55015 + /* add in ip acls */
55016 +
55017 + if (!s_tmp->ip_num) {
55018 + s_tmp->ips = NULL;
55019 + goto insert;
55020 + }
55021 +
55022 + i_tmp =
55023 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55024 + sizeof (struct acl_ip_label *));
55025 +
55026 + if (!i_tmp)
55027 + return ERR_PTR(-ENOMEM);
55028 +
55029 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55030 + *(i_tmp + i_num) =
55031 + (struct acl_ip_label *)
55032 + acl_alloc(sizeof (struct acl_ip_label));
55033 + if (!*(i_tmp + i_num))
55034 + return ERR_PTR(-ENOMEM);
55035 +
55036 + if (copy_from_user
55037 + (&i_utmp2, s_tmp->ips + i_num,
55038 + sizeof (struct acl_ip_label *)))
55039 + return ERR_PTR(-EFAULT);
55040 +
55041 + if (copy_from_user
55042 + (*(i_tmp + i_num), i_utmp2,
55043 + sizeof (struct acl_ip_label)))
55044 + return ERR_PTR(-EFAULT);
55045 +
55046 + if ((*(i_tmp + i_num))->iface == NULL)
55047 + continue;
55048 +
55049 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55050 + if (!len || len >= IFNAMSIZ)
55051 + return ERR_PTR(-EINVAL);
55052 + tmp = acl_alloc(len);
55053 + if (tmp == NULL)
55054 + return ERR_PTR(-ENOMEM);
55055 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55056 + return ERR_PTR(-EFAULT);
55057 + (*(i_tmp + i_num))->iface = tmp;
55058 + }
55059 +
55060 + s_tmp->ips = i_tmp;
55061 +
55062 +insert:
55063 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55064 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55065 + return ERR_PTR(-ENOMEM);
55066 +
55067 + return s_tmp;
55068 +}
55069 +
55070 +static int
55071 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55072 +{
55073 + struct acl_subject_label s_pre;
55074 + struct acl_subject_label * ret;
55075 + int err;
55076 +
55077 + while (userp) {
55078 + if (copy_from_user(&s_pre, userp,
55079 + sizeof (struct acl_subject_label)))
55080 + return -EFAULT;
55081 +
55082 + ret = do_copy_user_subj(userp, role, NULL);
55083 +
55084 + err = PTR_ERR(ret);
55085 + if (IS_ERR(ret))
55086 + return err;
55087 +
55088 + insert_acl_subj_label(ret, role);
55089 +
55090 + userp = s_pre.prev;
55091 + }
55092 +
55093 + return 0;
55094 +}
55095 +
55096 +static int
55097 +copy_user_acl(struct gr_arg *arg)
55098 +{
55099 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55100 + struct acl_subject_label *subj_list;
55101 + struct sprole_pw *sptmp;
55102 + struct gr_hash_struct *ghash;
55103 + uid_t *domainlist;
55104 + unsigned int r_num;
55105 + unsigned int len;
55106 + char *tmp;
55107 + int err = 0;
55108 + __u16 i;
55109 + __u32 num_subjs;
55110 +
55111 + /* we need a default and kernel role */
55112 + if (arg->role_db.num_roles < 2)
55113 + return -EINVAL;
55114 +
55115 + /* copy special role authentication info from userspace */
55116 +
55117 + num_sprole_pws = arg->num_sprole_pws;
55118 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55119 +
55120 + if (!acl_special_roles && num_sprole_pws)
55121 + return -ENOMEM;
55122 +
55123 + for (i = 0; i < num_sprole_pws; i++) {
55124 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55125 + if (!sptmp)
55126 + return -ENOMEM;
55127 + if (copy_from_user(sptmp, arg->sprole_pws + i,
55128 + sizeof (struct sprole_pw)))
55129 + return -EFAULT;
55130 +
55131 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55132 +
55133 + if (!len || len >= GR_SPROLE_LEN)
55134 + return -EINVAL;
55135 +
55136 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55137 + return -ENOMEM;
55138 +
55139 + if (copy_from_user(tmp, sptmp->rolename, len))
55140 + return -EFAULT;
55141 +
55142 + tmp[len-1] = '\0';
55143 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55144 + printk(KERN_ALERT "Copying special role %s\n", tmp);
55145 +#endif
55146 + sptmp->rolename = tmp;
55147 + acl_special_roles[i] = sptmp;
55148 + }
55149 +
55150 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55151 +
55152 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55153 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
55154 +
55155 + if (!r_tmp)
55156 + return -ENOMEM;
55157 +
55158 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
55159 + sizeof (struct acl_role_label *)))
55160 + return -EFAULT;
55161 +
55162 + if (copy_from_user(r_tmp, r_utmp2,
55163 + sizeof (struct acl_role_label)))
55164 + return -EFAULT;
55165 +
55166 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
55167 +
55168 + if (!len || len >= PATH_MAX)
55169 + return -EINVAL;
55170 +
55171 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55172 + return -ENOMEM;
55173 +
55174 + if (copy_from_user(tmp, r_tmp->rolename, len))
55175 + return -EFAULT;
55176 +
55177 + tmp[len-1] = '\0';
55178 + r_tmp->rolename = tmp;
55179 +
55180 + if (!strcmp(r_tmp->rolename, "default")
55181 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55182 + default_role = r_tmp;
55183 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
55184 + kernel_role = r_tmp;
55185 + }
55186 +
55187 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
55188 + return -ENOMEM;
55189 +
55190 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
55191 + return -EFAULT;
55192 +
55193 + r_tmp->hash = ghash;
55194 +
55195 + num_subjs = count_user_subjs(r_tmp->hash->first);
55196 +
55197 + r_tmp->subj_hash_size = num_subjs;
55198 + r_tmp->subj_hash =
55199 + (struct acl_subject_label **)
55200 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
55201 +
55202 + if (!r_tmp->subj_hash)
55203 + return -ENOMEM;
55204 +
55205 + err = copy_user_allowedips(r_tmp);
55206 + if (err)
55207 + return err;
55208 +
55209 + /* copy domain info */
55210 + if (r_tmp->domain_children != NULL) {
55211 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
55212 + if (domainlist == NULL)
55213 + return -ENOMEM;
55214 +
55215 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
55216 + return -EFAULT;
55217 +
55218 + r_tmp->domain_children = domainlist;
55219 + }
55220 +
55221 + err = copy_user_transitions(r_tmp);
55222 + if (err)
55223 + return err;
55224 +
55225 + memset(r_tmp->subj_hash, 0,
55226 + r_tmp->subj_hash_size *
55227 + sizeof (struct acl_subject_label *));
55228 +
55229 + /* acquire the list of subjects, then NULL out
55230 + the list prior to parsing the subjects for this role,
55231 + as during this parsing the list is replaced with a list
55232 + of *nested* subjects for the role
55233 + */
55234 + subj_list = r_tmp->hash->first;
55235 +
55236 + /* set nested subject list to null */
55237 + r_tmp->hash->first = NULL;
55238 +
55239 + err = copy_user_subjs(subj_list, r_tmp);
55240 +
55241 + if (err)
55242 + return err;
55243 +
55244 + insert_acl_role_label(r_tmp);
55245 + }
55246 +
55247 + if (default_role == NULL || kernel_role == NULL)
55248 + return -EINVAL;
55249 +
55250 + return err;
55251 +}
55252 +
55253 +static int
55254 +gracl_init(struct gr_arg *args)
55255 +{
55256 + int error = 0;
55257 +
55258 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
55259 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
55260 +
55261 + if (init_variables(args)) {
55262 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
55263 + error = -ENOMEM;
55264 + free_variables();
55265 + goto out;
55266 + }
55267 +
55268 + error = copy_user_acl(args);
55269 + free_init_variables();
55270 + if (error) {
55271 + free_variables();
55272 + goto out;
55273 + }
55274 +
55275 + if ((error = gr_set_acls(0))) {
55276 + free_variables();
55277 + goto out;
55278 + }
55279 +
55280 + pax_open_kernel();
55281 + gr_status |= GR_READY;
55282 + pax_close_kernel();
55283 +
55284 + out:
55285 + return error;
55286 +}
55287 +
55288 +/* derived from glibc fnmatch() 0: match, 1: no match*/
55289 +
55290 +static int
55291 +glob_match(const char *p, const char *n)
55292 +{
55293 + char c;
55294 +
55295 + while ((c = *p++) != '\0') {
55296 + switch (c) {
55297 + case '?':
55298 + if (*n == '\0')
55299 + return 1;
55300 + else if (*n == '/')
55301 + return 1;
55302 + break;
55303 + case '\\':
55304 + if (*n != c)
55305 + return 1;
55306 + break;
55307 + case '*':
55308 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
55309 + if (*n == '/')
55310 + return 1;
55311 + else if (c == '?') {
55312 + if (*n == '\0')
55313 + return 1;
55314 + else
55315 + ++n;
55316 + }
55317 + }
55318 + if (c == '\0') {
55319 + return 0;
55320 + } else {
55321 + const char *endp;
55322 +
55323 + if ((endp = strchr(n, '/')) == NULL)
55324 + endp = n + strlen(n);
55325 +
55326 + if (c == '[') {
55327 + for (--p; n < endp; ++n)
55328 + if (!glob_match(p, n))
55329 + return 0;
55330 + } else if (c == '/') {
55331 + while (*n != '\0' && *n != '/')
55332 + ++n;
55333 + if (*n == '/' && !glob_match(p, n + 1))
55334 + return 0;
55335 + } else {
55336 + for (--p; n < endp; ++n)
55337 + if (*n == c && !glob_match(p, n))
55338 + return 0;
55339 + }
55340 +
55341 + return 1;
55342 + }
55343 + case '[':
55344 + {
55345 + int not;
55346 + char cold;
55347 +
55348 + if (*n == '\0' || *n == '/')
55349 + return 1;
55350 +
55351 + not = (*p == '!' || *p == '^');
55352 + if (not)
55353 + ++p;
55354 +
55355 + c = *p++;
55356 + for (;;) {
55357 + unsigned char fn = (unsigned char)*n;
55358 +
55359 + if (c == '\0')
55360 + return 1;
55361 + else {
55362 + if (c == fn)
55363 + goto matched;
55364 + cold = c;
55365 + c = *p++;
55366 +
55367 + if (c == '-' && *p != ']') {
55368 + unsigned char cend = *p++;
55369 +
55370 + if (cend == '\0')
55371 + return 1;
55372 +
55373 + if (cold <= fn && fn <= cend)
55374 + goto matched;
55375 +
55376 + c = *p++;
55377 + }
55378 + }
55379 +
55380 + if (c == ']')
55381 + break;
55382 + }
55383 + if (!not)
55384 + return 1;
55385 + break;
55386 + matched:
55387 + while (c != ']') {
55388 + if (c == '\0')
55389 + return 1;
55390 +
55391 + c = *p++;
55392 + }
55393 + if (not)
55394 + return 1;
55395 + }
55396 + break;
55397 + default:
55398 + if (c != *n)
55399 + return 1;
55400 + }
55401 +
55402 + ++n;
55403 + }
55404 +
55405 + if (*n == '\0')
55406 + return 0;
55407 +
55408 + if (*n == '/')
55409 + return 0;
55410 +
55411 + return 1;
55412 +}
55413 +
55414 +static struct acl_object_label *
55415 +chk_glob_label(struct acl_object_label *globbed,
55416 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
55417 +{
55418 + struct acl_object_label *tmp;
55419 +
55420 + if (*path == NULL)
55421 + *path = gr_to_filename_nolock(dentry, mnt);
55422 +
55423 + tmp = globbed;
55424 +
55425 + while (tmp) {
55426 + if (!glob_match(tmp->filename, *path))
55427 + return tmp;
55428 + tmp = tmp->next;
55429 + }
55430 +
55431 + return NULL;
55432 +}
55433 +
55434 +static struct acl_object_label *
55435 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55436 + const ino_t curr_ino, const dev_t curr_dev,
55437 + const struct acl_subject_label *subj, char **path, const int checkglob)
55438 +{
55439 + struct acl_subject_label *tmpsubj;
55440 + struct acl_object_label *retval;
55441 + struct acl_object_label *retval2;
55442 +
55443 + tmpsubj = (struct acl_subject_label *) subj;
55444 + read_lock(&gr_inode_lock);
55445 + do {
55446 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
55447 + if (retval) {
55448 + if (checkglob && retval->globbed) {
55449 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
55450 + if (retval2)
55451 + retval = retval2;
55452 + }
55453 + break;
55454 + }
55455 + } while ((tmpsubj = tmpsubj->parent_subject));
55456 + read_unlock(&gr_inode_lock);
55457 +
55458 + return retval;
55459 +}
55460 +
55461 +static __inline__ struct acl_object_label *
55462 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55463 + struct dentry *curr_dentry,
55464 + const struct acl_subject_label *subj, char **path, const int checkglob)
55465 +{
55466 + int newglob = checkglob;
55467 + ino_t inode;
55468 + dev_t device;
55469 +
55470 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
55471 + as we don't want a / * rule to match instead of the / object
55472 + don't do this for create lookups that call this function though, since they're looking up
55473 + on the parent and thus need globbing checks on all paths
55474 + */
55475 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55476 + newglob = GR_NO_GLOB;
55477 +
55478 + spin_lock(&curr_dentry->d_lock);
55479 + inode = curr_dentry->d_inode->i_ino;
55480 + device = __get_dev(curr_dentry);
55481 + spin_unlock(&curr_dentry->d_lock);
55482 +
55483 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55484 +}
55485 +
55486 +static struct acl_object_label *
55487 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55488 + const struct acl_subject_label *subj, char *path, const int checkglob)
55489 +{
55490 + struct dentry *dentry = (struct dentry *) l_dentry;
55491 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55492 + struct mount *real_mnt = real_mount(mnt);
55493 + struct acl_object_label *retval;
55494 + struct dentry *parent;
55495 +
55496 + write_seqlock(&rename_lock);
55497 + br_read_lock(&vfsmount_lock);
55498 +
55499 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55500 +#ifdef CONFIG_NET
55501 + mnt == sock_mnt ||
55502 +#endif
55503 +#ifdef CONFIG_HUGETLBFS
55504 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55505 +#endif
55506 + /* ignore Eric Biederman */
55507 + IS_PRIVATE(l_dentry->d_inode))) {
55508 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55509 + goto out;
55510 + }
55511 +
55512 + for (;;) {
55513 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55514 + break;
55515 +
55516 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55517 + if (!mnt_has_parent(real_mnt))
55518 + break;
55519 +
55520 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55521 + if (retval != NULL)
55522 + goto out;
55523 +
55524 + dentry = real_mnt->mnt_mountpoint;
55525 + real_mnt = real_mnt->mnt_parent;
55526 + mnt = &real_mnt->mnt;
55527 + continue;
55528 + }
55529 +
55530 + parent = dentry->d_parent;
55531 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55532 + if (retval != NULL)
55533 + goto out;
55534 +
55535 + dentry = parent;
55536 + }
55537 +
55538 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55539 +
55540 + /* real_root is pinned so we don't have to hold a reference */
55541 + if (retval == NULL)
55542 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55543 +out:
55544 + br_read_unlock(&vfsmount_lock);
55545 + write_sequnlock(&rename_lock);
55546 +
55547 + BUG_ON(retval == NULL);
55548 +
55549 + return retval;
55550 +}
55551 +
55552 +static __inline__ struct acl_object_label *
55553 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55554 + const struct acl_subject_label *subj)
55555 +{
55556 + char *path = NULL;
55557 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55558 +}
55559 +
55560 +static __inline__ struct acl_object_label *
55561 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55562 + const struct acl_subject_label *subj)
55563 +{
55564 + char *path = NULL;
55565 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55566 +}
55567 +
55568 +static __inline__ struct acl_object_label *
55569 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55570 + const struct acl_subject_label *subj, char *path)
55571 +{
55572 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55573 +}
55574 +
55575 +static struct acl_subject_label *
55576 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55577 + const struct acl_role_label *role)
55578 +{
55579 + struct dentry *dentry = (struct dentry *) l_dentry;
55580 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55581 + struct mount *real_mnt = real_mount(mnt);
55582 + struct acl_subject_label *retval;
55583 + struct dentry *parent;
55584 +
55585 + write_seqlock(&rename_lock);
55586 + br_read_lock(&vfsmount_lock);
55587 +
55588 + for (;;) {
55589 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55590 + break;
55591 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55592 + if (!mnt_has_parent(real_mnt))
55593 + break;
55594 +
55595 + spin_lock(&dentry->d_lock);
55596 + read_lock(&gr_inode_lock);
55597 + retval =
55598 + lookup_acl_subj_label(dentry->d_inode->i_ino,
55599 + __get_dev(dentry), role);
55600 + read_unlock(&gr_inode_lock);
55601 + spin_unlock(&dentry->d_lock);
55602 + if (retval != NULL)
55603 + goto out;
55604 +
55605 + dentry = real_mnt->mnt_mountpoint;
55606 + real_mnt = real_mnt->mnt_parent;
55607 + mnt = &real_mnt->mnt;
55608 + continue;
55609 + }
55610 +
55611 + spin_lock(&dentry->d_lock);
55612 + read_lock(&gr_inode_lock);
55613 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55614 + __get_dev(dentry), role);
55615 + read_unlock(&gr_inode_lock);
55616 + parent = dentry->d_parent;
55617 + spin_unlock(&dentry->d_lock);
55618 +
55619 + if (retval != NULL)
55620 + goto out;
55621 +
55622 + dentry = parent;
55623 + }
55624 +
55625 + spin_lock(&dentry->d_lock);
55626 + read_lock(&gr_inode_lock);
55627 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55628 + __get_dev(dentry), role);
55629 + read_unlock(&gr_inode_lock);
55630 + spin_unlock(&dentry->d_lock);
55631 +
55632 + if (unlikely(retval == NULL)) {
55633 + /* real_root is pinned, we don't need to hold a reference */
55634 + read_lock(&gr_inode_lock);
55635 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55636 + __get_dev(real_root.dentry), role);
55637 + read_unlock(&gr_inode_lock);
55638 + }
55639 +out:
55640 + br_read_unlock(&vfsmount_lock);
55641 + write_sequnlock(&rename_lock);
55642 +
55643 + BUG_ON(retval == NULL);
55644 +
55645 + return retval;
55646 +}
55647 +
55648 +static void
55649 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55650 +{
55651 + struct task_struct *task = current;
55652 + const struct cred *cred = current_cred();
55653 +
55654 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55655 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55656 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55657 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55658 +
55659 + return;
55660 +}
55661 +
55662 +static void
55663 +gr_log_learn_id_change(const char type, const unsigned int real,
55664 + const unsigned int effective, const unsigned int fs)
55665 +{
55666 + struct task_struct *task = current;
55667 + const struct cred *cred = current_cred();
55668 +
55669 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55670 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55671 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55672 + type, real, effective, fs, &task->signal->saved_ip);
55673 +
55674 + return;
55675 +}
55676 +
55677 +__u32
55678 +gr_search_file(const struct dentry * dentry, const __u32 mode,
55679 + const struct vfsmount * mnt)
55680 +{
55681 + __u32 retval = mode;
55682 + struct acl_subject_label *curracl;
55683 + struct acl_object_label *currobj;
55684 +
55685 + if (unlikely(!(gr_status & GR_READY)))
55686 + return (mode & ~GR_AUDITS);
55687 +
55688 + curracl = current->acl;
55689 +
55690 + currobj = chk_obj_label(dentry, mnt, curracl);
55691 + retval = currobj->mode & mode;
55692 +
55693 + /* if we're opening a specified transfer file for writing
55694 + (e.g. /dev/initctl), then transfer our role to init
55695 + */
55696 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55697 + current->role->roletype & GR_ROLE_PERSIST)) {
55698 + struct task_struct *task = init_pid_ns.child_reaper;
55699 +
55700 + if (task->role != current->role) {
55701 + task->acl_sp_role = 0;
55702 + task->acl_role_id = current->acl_role_id;
55703 + task->role = current->role;
55704 + rcu_read_lock();
55705 + read_lock(&grsec_exec_file_lock);
55706 + gr_apply_subject_to_task(task);
55707 + read_unlock(&grsec_exec_file_lock);
55708 + rcu_read_unlock();
55709 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55710 + }
55711 + }
55712 +
55713 + if (unlikely
55714 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55715 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55716 + __u32 new_mode = mode;
55717 +
55718 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55719 +
55720 + retval = new_mode;
55721 +
55722 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55723 + new_mode |= GR_INHERIT;
55724 +
55725 + if (!(mode & GR_NOLEARN))
55726 + gr_log_learn(dentry, mnt, new_mode);
55727 + }
55728 +
55729 + return retval;
55730 +}
55731 +
55732 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55733 + const struct dentry *parent,
55734 + const struct vfsmount *mnt)
55735 +{
55736 + struct name_entry *match;
55737 + struct acl_object_label *matchpo;
55738 + struct acl_subject_label *curracl;
55739 + char *path;
55740 +
55741 + if (unlikely(!(gr_status & GR_READY)))
55742 + return NULL;
55743 +
55744 + preempt_disable();
55745 + path = gr_to_filename_rbac(new_dentry, mnt);
55746 + match = lookup_name_entry_create(path);
55747 +
55748 + curracl = current->acl;
55749 +
55750 + if (match) {
55751 + read_lock(&gr_inode_lock);
55752 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55753 + read_unlock(&gr_inode_lock);
55754 +
55755 + if (matchpo) {
55756 + preempt_enable();
55757 + return matchpo;
55758 + }
55759 + }
55760 +
55761 + // lookup parent
55762 +
55763 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55764 +
55765 + preempt_enable();
55766 + return matchpo;
55767 +}
55768 +
55769 +__u32
55770 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55771 + const struct vfsmount * mnt, const __u32 mode)
55772 +{
55773 + struct acl_object_label *matchpo;
55774 + __u32 retval;
55775 +
55776 + if (unlikely(!(gr_status & GR_READY)))
55777 + return (mode & ~GR_AUDITS);
55778 +
55779 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
55780 +
55781 + retval = matchpo->mode & mode;
55782 +
55783 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55784 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55785 + __u32 new_mode = mode;
55786 +
55787 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55788 +
55789 + gr_log_learn(new_dentry, mnt, new_mode);
55790 + return new_mode;
55791 + }
55792 +
55793 + return retval;
55794 +}
55795 +
55796 +__u32
55797 +gr_check_link(const struct dentry * new_dentry,
55798 + const struct dentry * parent_dentry,
55799 + const struct vfsmount * parent_mnt,
55800 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55801 +{
55802 + struct acl_object_label *obj;
55803 + __u32 oldmode, newmode;
55804 + __u32 needmode;
55805 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55806 + GR_DELETE | GR_INHERIT;
55807 +
55808 + if (unlikely(!(gr_status & GR_READY)))
55809 + return (GR_CREATE | GR_LINK);
55810 +
55811 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55812 + oldmode = obj->mode;
55813 +
55814 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55815 + newmode = obj->mode;
55816 +
55817 + needmode = newmode & checkmodes;
55818 +
55819 + // old name for hardlink must have at least the permissions of the new name
55820 + if ((oldmode & needmode) != needmode)
55821 + goto bad;
55822 +
55823 + // if old name had restrictions/auditing, make sure the new name does as well
55824 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55825 +
55826 + // don't allow hardlinking of suid/sgid/fcapped files without permission
55827 + if (is_privileged_binary(old_dentry))
55828 + needmode |= GR_SETID;
55829 +
55830 + if ((newmode & needmode) != needmode)
55831 + goto bad;
55832 +
55833 + // enforce minimum permissions
55834 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55835 + return newmode;
55836 +bad:
55837 + needmode = oldmode;
55838 + if (is_privileged_binary(old_dentry))
55839 + needmode |= GR_SETID;
55840 +
55841 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55842 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55843 + return (GR_CREATE | GR_LINK);
55844 + } else if (newmode & GR_SUPPRESS)
55845 + return GR_SUPPRESS;
55846 + else
55847 + return 0;
55848 +}
55849 +
55850 +int
55851 +gr_check_hidden_task(const struct task_struct *task)
55852 +{
55853 + if (unlikely(!(gr_status & GR_READY)))
55854 + return 0;
55855 +
55856 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55857 + return 1;
55858 +
55859 + return 0;
55860 +}
55861 +
55862 +int
55863 +gr_check_protected_task(const struct task_struct *task)
55864 +{
55865 + if (unlikely(!(gr_status & GR_READY) || !task))
55866 + return 0;
55867 +
55868 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55869 + task->acl != current->acl)
55870 + return 1;
55871 +
55872 + return 0;
55873 +}
55874 +
55875 +int
55876 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55877 +{
55878 + struct task_struct *p;
55879 + int ret = 0;
55880 +
55881 + if (unlikely(!(gr_status & GR_READY) || !pid))
55882 + return ret;
55883 +
55884 + read_lock(&tasklist_lock);
55885 + do_each_pid_task(pid, type, p) {
55886 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55887 + p->acl != current->acl) {
55888 + ret = 1;
55889 + goto out;
55890 + }
55891 + } while_each_pid_task(pid, type, p);
55892 +out:
55893 + read_unlock(&tasklist_lock);
55894 +
55895 + return ret;
55896 +}
55897 +
55898 +void
55899 +gr_copy_label(struct task_struct *tsk)
55900 +{
55901 + tsk->signal->used_accept = 0;
55902 + tsk->acl_sp_role = 0;
55903 + tsk->acl_role_id = current->acl_role_id;
55904 + tsk->acl = current->acl;
55905 + tsk->role = current->role;
55906 + tsk->signal->curr_ip = current->signal->curr_ip;
55907 + tsk->signal->saved_ip = current->signal->saved_ip;
55908 + if (current->exec_file)
55909 + get_file(current->exec_file);
55910 + tsk->exec_file = current->exec_file;
55911 + tsk->is_writable = current->is_writable;
55912 + if (unlikely(current->signal->used_accept)) {
55913 + current->signal->curr_ip = 0;
55914 + current->signal->saved_ip = 0;
55915 + }
55916 +
55917 + return;
55918 +}
55919 +
55920 +static void
55921 +gr_set_proc_res(struct task_struct *task)
55922 +{
55923 + struct acl_subject_label *proc;
55924 + unsigned short i;
55925 +
55926 + proc = task->acl;
55927 +
55928 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55929 + return;
55930 +
55931 + for (i = 0; i < RLIM_NLIMITS; i++) {
55932 + if (!(proc->resmask & (1 << i)))
55933 + continue;
55934 +
55935 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55936 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55937 + }
55938 +
55939 + return;
55940 +}
55941 +
55942 +extern int __gr_process_user_ban(struct user_struct *user);
55943 +
55944 +int
55945 +gr_check_user_change(int real, int effective, int fs)
55946 +{
55947 + unsigned int i;
55948 + __u16 num;
55949 + uid_t *uidlist;
55950 + int curuid;
55951 + int realok = 0;
55952 + int effectiveok = 0;
55953 + int fsok = 0;
55954 +
55955 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55956 + struct user_struct *user;
55957 +
55958 + if (real == -1)
55959 + goto skipit;
55960 +
55961 + user = find_user(real);
55962 + if (user == NULL)
55963 + goto skipit;
55964 +
55965 + if (__gr_process_user_ban(user)) {
55966 + /* for find_user */
55967 + free_uid(user);
55968 + return 1;
55969 + }
55970 +
55971 + /* for find_user */
55972 + free_uid(user);
55973 +
55974 +skipit:
55975 +#endif
55976 +
55977 + if (unlikely(!(gr_status & GR_READY)))
55978 + return 0;
55979 +
55980 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55981 + gr_log_learn_id_change('u', real, effective, fs);
55982 +
55983 + num = current->acl->user_trans_num;
55984 + uidlist = current->acl->user_transitions;
55985 +
55986 + if (uidlist == NULL)
55987 + return 0;
55988 +
55989 + if (real == -1)
55990 + realok = 1;
55991 + if (effective == -1)
55992 + effectiveok = 1;
55993 + if (fs == -1)
55994 + fsok = 1;
55995 +
55996 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
55997 + for (i = 0; i < num; i++) {
55998 + curuid = (int)uidlist[i];
55999 + if (real == curuid)
56000 + realok = 1;
56001 + if (effective == curuid)
56002 + effectiveok = 1;
56003 + if (fs == curuid)
56004 + fsok = 1;
56005 + }
56006 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
56007 + for (i = 0; i < num; i++) {
56008 + curuid = (int)uidlist[i];
56009 + if (real == curuid)
56010 + break;
56011 + if (effective == curuid)
56012 + break;
56013 + if (fs == curuid)
56014 + break;
56015 + }
56016 + /* not in deny list */
56017 + if (i == num) {
56018 + realok = 1;
56019 + effectiveok = 1;
56020 + fsok = 1;
56021 + }
56022 + }
56023 +
56024 + if (realok && effectiveok && fsok)
56025 + return 0;
56026 + else {
56027 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56028 + return 1;
56029 + }
56030 +}
56031 +
56032 +int
56033 +gr_check_group_change(int real, int effective, int fs)
56034 +{
56035 + unsigned int i;
56036 + __u16 num;
56037 + gid_t *gidlist;
56038 + int curgid;
56039 + int realok = 0;
56040 + int effectiveok = 0;
56041 + int fsok = 0;
56042 +
56043 + if (unlikely(!(gr_status & GR_READY)))
56044 + return 0;
56045 +
56046 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56047 + gr_log_learn_id_change('g', real, effective, fs);
56048 +
56049 + num = current->acl->group_trans_num;
56050 + gidlist = current->acl->group_transitions;
56051 +
56052 + if (gidlist == NULL)
56053 + return 0;
56054 +
56055 + if (real == -1)
56056 + realok = 1;
56057 + if (effective == -1)
56058 + effectiveok = 1;
56059 + if (fs == -1)
56060 + fsok = 1;
56061 +
56062 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
56063 + for (i = 0; i < num; i++) {
56064 + curgid = (int)gidlist[i];
56065 + if (real == curgid)
56066 + realok = 1;
56067 + if (effective == curgid)
56068 + effectiveok = 1;
56069 + if (fs == curgid)
56070 + fsok = 1;
56071 + }
56072 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
56073 + for (i = 0; i < num; i++) {
56074 + curgid = (int)gidlist[i];
56075 + if (real == curgid)
56076 + break;
56077 + if (effective == curgid)
56078 + break;
56079 + if (fs == curgid)
56080 + break;
56081 + }
56082 + /* not in deny list */
56083 + if (i == num) {
56084 + realok = 1;
56085 + effectiveok = 1;
56086 + fsok = 1;
56087 + }
56088 + }
56089 +
56090 + if (realok && effectiveok && fsok)
56091 + return 0;
56092 + else {
56093 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56094 + return 1;
56095 + }
56096 +}
56097 +
56098 +extern int gr_acl_is_capable(const int cap);
56099 +
56100 +void
56101 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56102 +{
56103 + struct acl_role_label *role = task->role;
56104 + struct acl_subject_label *subj = NULL;
56105 + struct acl_object_label *obj;
56106 + struct file *filp;
56107 +
56108 + if (unlikely(!(gr_status & GR_READY)))
56109 + return;
56110 +
56111 + filp = task->exec_file;
56112 +
56113 + /* kernel process, we'll give them the kernel role */
56114 + if (unlikely(!filp)) {
56115 + task->role = kernel_role;
56116 + task->acl = kernel_role->root_label;
56117 + return;
56118 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56119 + role = lookup_acl_role_label(task, uid, gid);
56120 +
56121 + /* don't change the role if we're not a privileged process */
56122 + if (role && task->role != role &&
56123 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56124 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56125 + return;
56126 +
56127 + /* perform subject lookup in possibly new role
56128 + we can use this result below in the case where role == task->role
56129 + */
56130 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56131 +
56132 + /* if we changed uid/gid, but result in the same role
56133 + and are using inheritance, don't lose the inherited subject
56134 + if current subject is other than what normal lookup
56135 + would result in, we arrived via inheritance, don't
56136 + lose subject
56137 + */
56138 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56139 + (subj == task->acl)))
56140 + task->acl = subj;
56141 +
56142 + task->role = role;
56143 +
56144 + task->is_writable = 0;
56145 +
56146 + /* ignore additional mmap checks for processes that are writable
56147 + by the default ACL */
56148 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56149 + if (unlikely(obj->mode & GR_WRITE))
56150 + task->is_writable = 1;
56151 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56152 + if (unlikely(obj->mode & GR_WRITE))
56153 + task->is_writable = 1;
56154 +
56155 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56156 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56157 +#endif
56158 +
56159 + gr_set_proc_res(task);
56160 +
56161 + return;
56162 +}
56163 +
56164 +int
56165 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56166 + const int unsafe_flags)
56167 +{
56168 + struct task_struct *task = current;
56169 + struct acl_subject_label *newacl;
56170 + struct acl_object_label *obj;
56171 + __u32 retmode;
56172 +
56173 + if (unlikely(!(gr_status & GR_READY)))
56174 + return 0;
56175 +
56176 + newacl = chk_subj_label(dentry, mnt, task->role);
56177 +
56178 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
56179 + did an exec
56180 + */
56181 + rcu_read_lock();
56182 + read_lock(&tasklist_lock);
56183 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
56184 + (task->parent->acl->mode & GR_POVERRIDE))) {
56185 + read_unlock(&tasklist_lock);
56186 + rcu_read_unlock();
56187 + goto skip_check;
56188 + }
56189 + read_unlock(&tasklist_lock);
56190 + rcu_read_unlock();
56191 +
56192 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
56193 + !(task->role->roletype & GR_ROLE_GOD) &&
56194 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
56195 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56196 + if (unsafe_flags & LSM_UNSAFE_SHARE)
56197 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
56198 + else
56199 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
56200 + return -EACCES;
56201 + }
56202 +
56203 +skip_check:
56204 +
56205 + obj = chk_obj_label(dentry, mnt, task->acl);
56206 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
56207 +
56208 + if (!(task->acl->mode & GR_INHERITLEARN) &&
56209 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
56210 + if (obj->nested)
56211 + task->acl = obj->nested;
56212 + else
56213 + task->acl = newacl;
56214 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
56215 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
56216 +
56217 + task->is_writable = 0;
56218 +
56219 + /* ignore additional mmap checks for processes that are writable
56220 + by the default ACL */
56221 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
56222 + if (unlikely(obj->mode & GR_WRITE))
56223 + task->is_writable = 1;
56224 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
56225 + if (unlikely(obj->mode & GR_WRITE))
56226 + task->is_writable = 1;
56227 +
56228 + gr_set_proc_res(task);
56229 +
56230 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56231 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56232 +#endif
56233 + return 0;
56234 +}
56235 +
56236 +/* always called with valid inodev ptr */
56237 +static void
56238 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
56239 +{
56240 + struct acl_object_label *matchpo;
56241 + struct acl_subject_label *matchps;
56242 + struct acl_subject_label *subj;
56243 + struct acl_role_label *role;
56244 + unsigned int x;
56245 +
56246 + FOR_EACH_ROLE_START(role)
56247 + FOR_EACH_SUBJECT_START(role, subj, x)
56248 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56249 + matchpo->mode |= GR_DELETED;
56250 + FOR_EACH_SUBJECT_END(subj,x)
56251 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56252 + /* nested subjects aren't in the role's subj_hash table */
56253 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56254 + matchpo->mode |= GR_DELETED;
56255 + FOR_EACH_NESTED_SUBJECT_END(subj)
56256 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
56257 + matchps->mode |= GR_DELETED;
56258 + FOR_EACH_ROLE_END(role)
56259 +
56260 + inodev->nentry->deleted = 1;
56261 +
56262 + return;
56263 +}
56264 +
56265 +void
56266 +gr_handle_delete(const ino_t ino, const dev_t dev)
56267 +{
56268 + struct inodev_entry *inodev;
56269 +
56270 + if (unlikely(!(gr_status & GR_READY)))
56271 + return;
56272 +
56273 + write_lock(&gr_inode_lock);
56274 + inodev = lookup_inodev_entry(ino, dev);
56275 + if (inodev != NULL)
56276 + do_handle_delete(inodev, ino, dev);
56277 + write_unlock(&gr_inode_lock);
56278 +
56279 + return;
56280 +}
56281 +
56282 +static void
56283 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
56284 + const ino_t newinode, const dev_t newdevice,
56285 + struct acl_subject_label *subj)
56286 +{
56287 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
56288 + struct acl_object_label *match;
56289 +
56290 + match = subj->obj_hash[index];
56291 +
56292 + while (match && (match->inode != oldinode ||
56293 + match->device != olddevice ||
56294 + !(match->mode & GR_DELETED)))
56295 + match = match->next;
56296 +
56297 + if (match && (match->inode == oldinode)
56298 + && (match->device == olddevice)
56299 + && (match->mode & GR_DELETED)) {
56300 + if (match->prev == NULL) {
56301 + subj->obj_hash[index] = match->next;
56302 + if (match->next != NULL)
56303 + match->next->prev = NULL;
56304 + } else {
56305 + match->prev->next = match->next;
56306 + if (match->next != NULL)
56307 + match->next->prev = match->prev;
56308 + }
56309 + match->prev = NULL;
56310 + match->next = NULL;
56311 + match->inode = newinode;
56312 + match->device = newdevice;
56313 + match->mode &= ~GR_DELETED;
56314 +
56315 + insert_acl_obj_label(match, subj);
56316 + }
56317 +
56318 + return;
56319 +}
56320 +
56321 +static void
56322 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
56323 + const ino_t newinode, const dev_t newdevice,
56324 + struct acl_role_label *role)
56325 +{
56326 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
56327 + struct acl_subject_label *match;
56328 +
56329 + match = role->subj_hash[index];
56330 +
56331 + while (match && (match->inode != oldinode ||
56332 + match->device != olddevice ||
56333 + !(match->mode & GR_DELETED)))
56334 + match = match->next;
56335 +
56336 + if (match && (match->inode == oldinode)
56337 + && (match->device == olddevice)
56338 + && (match->mode & GR_DELETED)) {
56339 + if (match->prev == NULL) {
56340 + role->subj_hash[index] = match->next;
56341 + if (match->next != NULL)
56342 + match->next->prev = NULL;
56343 + } else {
56344 + match->prev->next = match->next;
56345 + if (match->next != NULL)
56346 + match->next->prev = match->prev;
56347 + }
56348 + match->prev = NULL;
56349 + match->next = NULL;
56350 + match->inode = newinode;
56351 + match->device = newdevice;
56352 + match->mode &= ~GR_DELETED;
56353 +
56354 + insert_acl_subj_label(match, role);
56355 + }
56356 +
56357 + return;
56358 +}
56359 +
56360 +static void
56361 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
56362 + const ino_t newinode, const dev_t newdevice)
56363 +{
56364 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
56365 + struct inodev_entry *match;
56366 +
56367 + match = inodev_set.i_hash[index];
56368 +
56369 + while (match && (match->nentry->inode != oldinode ||
56370 + match->nentry->device != olddevice || !match->nentry->deleted))
56371 + match = match->next;
56372 +
56373 + if (match && (match->nentry->inode == oldinode)
56374 + && (match->nentry->device == olddevice) &&
56375 + match->nentry->deleted) {
56376 + if (match->prev == NULL) {
56377 + inodev_set.i_hash[index] = match->next;
56378 + if (match->next != NULL)
56379 + match->next->prev = NULL;
56380 + } else {
56381 + match->prev->next = match->next;
56382 + if (match->next != NULL)
56383 + match->next->prev = match->prev;
56384 + }
56385 + match->prev = NULL;
56386 + match->next = NULL;
56387 + match->nentry->inode = newinode;
56388 + match->nentry->device = newdevice;
56389 + match->nentry->deleted = 0;
56390 +
56391 + insert_inodev_entry(match);
56392 + }
56393 +
56394 + return;
56395 +}
56396 +
56397 +static void
56398 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
56399 +{
56400 + struct acl_subject_label *subj;
56401 + struct acl_role_label *role;
56402 + unsigned int x;
56403 +
56404 + FOR_EACH_ROLE_START(role)
56405 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
56406 +
56407 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56408 + if ((subj->inode == ino) && (subj->device == dev)) {
56409 + subj->inode = ino;
56410 + subj->device = dev;
56411 + }
56412 + /* nested subjects aren't in the role's subj_hash table */
56413 + update_acl_obj_label(matchn->inode, matchn->device,
56414 + ino, dev, subj);
56415 + FOR_EACH_NESTED_SUBJECT_END(subj)
56416 + FOR_EACH_SUBJECT_START(role, subj, x)
56417 + update_acl_obj_label(matchn->inode, matchn->device,
56418 + ino, dev, subj);
56419 + FOR_EACH_SUBJECT_END(subj,x)
56420 + FOR_EACH_ROLE_END(role)
56421 +
56422 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
56423 +
56424 + return;
56425 +}
56426 +
56427 +static void
56428 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
56429 + const struct vfsmount *mnt)
56430 +{
56431 + ino_t ino = dentry->d_inode->i_ino;
56432 + dev_t dev = __get_dev(dentry);
56433 +
56434 + __do_handle_create(matchn, ino, dev);
56435 +
56436 + return;
56437 +}
56438 +
56439 +void
56440 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56441 +{
56442 + struct name_entry *matchn;
56443 +
56444 + if (unlikely(!(gr_status & GR_READY)))
56445 + return;
56446 +
56447 + preempt_disable();
56448 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
56449 +
56450 + if (unlikely((unsigned long)matchn)) {
56451 + write_lock(&gr_inode_lock);
56452 + do_handle_create(matchn, dentry, mnt);
56453 + write_unlock(&gr_inode_lock);
56454 + }
56455 + preempt_enable();
56456 +
56457 + return;
56458 +}
56459 +
56460 +void
56461 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56462 +{
56463 + struct name_entry *matchn;
56464 +
56465 + if (unlikely(!(gr_status & GR_READY)))
56466 + return;
56467 +
56468 + preempt_disable();
56469 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
56470 +
56471 + if (unlikely((unsigned long)matchn)) {
56472 + write_lock(&gr_inode_lock);
56473 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
56474 + write_unlock(&gr_inode_lock);
56475 + }
56476 + preempt_enable();
56477 +
56478 + return;
56479 +}
56480 +
56481 +void
56482 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56483 + struct dentry *old_dentry,
56484 + struct dentry *new_dentry,
56485 + struct vfsmount *mnt, const __u8 replace)
56486 +{
56487 + struct name_entry *matchn;
56488 + struct inodev_entry *inodev;
56489 + struct inode *inode = new_dentry->d_inode;
56490 + ino_t old_ino = old_dentry->d_inode->i_ino;
56491 + dev_t old_dev = __get_dev(old_dentry);
56492 +
56493 + /* vfs_rename swaps the name and parent link for old_dentry and
56494 + new_dentry
56495 + at this point, old_dentry has the new name, parent link, and inode
56496 + for the renamed file
56497 + if a file is being replaced by a rename, new_dentry has the inode
56498 + and name for the replaced file
56499 + */
56500 +
56501 + if (unlikely(!(gr_status & GR_READY)))
56502 + return;
56503 +
56504 + preempt_disable();
56505 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56506 +
56507 + /* we wouldn't have to check d_inode if it weren't for
56508 + NFS silly-renaming
56509 + */
56510 +
56511 + write_lock(&gr_inode_lock);
56512 + if (unlikely(replace && inode)) {
56513 + ino_t new_ino = inode->i_ino;
56514 + dev_t new_dev = __get_dev(new_dentry);
56515 +
56516 + inodev = lookup_inodev_entry(new_ino, new_dev);
56517 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56518 + do_handle_delete(inodev, new_ino, new_dev);
56519 + }
56520 +
56521 + inodev = lookup_inodev_entry(old_ino, old_dev);
56522 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56523 + do_handle_delete(inodev, old_ino, old_dev);
56524 +
56525 + if (unlikely((unsigned long)matchn))
56526 + do_handle_create(matchn, old_dentry, mnt);
56527 +
56528 + write_unlock(&gr_inode_lock);
56529 + preempt_enable();
56530 +
56531 + return;
56532 +}
56533 +
56534 +static int
56535 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56536 + unsigned char **sum)
56537 +{
56538 + struct acl_role_label *r;
56539 + struct role_allowed_ip *ipp;
56540 + struct role_transition *trans;
56541 + unsigned int i;
56542 + int found = 0;
56543 + u32 curr_ip = current->signal->curr_ip;
56544 +
56545 + current->signal->saved_ip = curr_ip;
56546 +
56547 + /* check transition table */
56548 +
56549 + for (trans = current->role->transitions; trans; trans = trans->next) {
56550 + if (!strcmp(rolename, trans->rolename)) {
56551 + found = 1;
56552 + break;
56553 + }
56554 + }
56555 +
56556 + if (!found)
56557 + return 0;
56558 +
56559 + /* handle special roles that do not require authentication
56560 + and check ip */
56561 +
56562 + FOR_EACH_ROLE_START(r)
56563 + if (!strcmp(rolename, r->rolename) &&
56564 + (r->roletype & GR_ROLE_SPECIAL)) {
56565 + found = 0;
56566 + if (r->allowed_ips != NULL) {
56567 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56568 + if ((ntohl(curr_ip) & ipp->netmask) ==
56569 + (ntohl(ipp->addr) & ipp->netmask))
56570 + found = 1;
56571 + }
56572 + } else
56573 + found = 2;
56574 + if (!found)
56575 + return 0;
56576 +
56577 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56578 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56579 + *salt = NULL;
56580 + *sum = NULL;
56581 + return 1;
56582 + }
56583 + }
56584 + FOR_EACH_ROLE_END(r)
56585 +
56586 + for (i = 0; i < num_sprole_pws; i++) {
56587 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56588 + *salt = acl_special_roles[i]->salt;
56589 + *sum = acl_special_roles[i]->sum;
56590 + return 1;
56591 + }
56592 + }
56593 +
56594 + return 0;
56595 +}
56596 +
56597 +static void
56598 +assign_special_role(char *rolename)
56599 +{
56600 + struct acl_object_label *obj;
56601 + struct acl_role_label *r;
56602 + struct acl_role_label *assigned = NULL;
56603 + struct task_struct *tsk;
56604 + struct file *filp;
56605 +
56606 + FOR_EACH_ROLE_START(r)
56607 + if (!strcmp(rolename, r->rolename) &&
56608 + (r->roletype & GR_ROLE_SPECIAL)) {
56609 + assigned = r;
56610 + break;
56611 + }
56612 + FOR_EACH_ROLE_END(r)
56613 +
56614 + if (!assigned)
56615 + return;
56616 +
56617 + read_lock(&tasklist_lock);
56618 + read_lock(&grsec_exec_file_lock);
56619 +
56620 + tsk = current->real_parent;
56621 + if (tsk == NULL)
56622 + goto out_unlock;
56623 +
56624 + filp = tsk->exec_file;
56625 + if (filp == NULL)
56626 + goto out_unlock;
56627 +
56628 + tsk->is_writable = 0;
56629 +
56630 + tsk->acl_sp_role = 1;
56631 + tsk->acl_role_id = ++acl_sp_role_value;
56632 + tsk->role = assigned;
56633 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56634 +
56635 + /* ignore additional mmap checks for processes that are writable
56636 + by the default ACL */
56637 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56638 + if (unlikely(obj->mode & GR_WRITE))
56639 + tsk->is_writable = 1;
56640 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56641 + if (unlikely(obj->mode & GR_WRITE))
56642 + tsk->is_writable = 1;
56643 +
56644 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56645 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56646 +#endif
56647 +
56648 +out_unlock:
56649 + read_unlock(&grsec_exec_file_lock);
56650 + read_unlock(&tasklist_lock);
56651 + return;
56652 +}
56653 +
56654 +int gr_check_secure_terminal(struct task_struct *task)
56655 +{
56656 + struct task_struct *p, *p2, *p3;
56657 + struct files_struct *files;
56658 + struct fdtable *fdt;
56659 + struct file *our_file = NULL, *file;
56660 + int i;
56661 +
56662 + if (task->signal->tty == NULL)
56663 + return 1;
56664 +
56665 + files = get_files_struct(task);
56666 + if (files != NULL) {
56667 + rcu_read_lock();
56668 + fdt = files_fdtable(files);
56669 + for (i=0; i < fdt->max_fds; i++) {
56670 + file = fcheck_files(files, i);
56671 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56672 + get_file(file);
56673 + our_file = file;
56674 + }
56675 + }
56676 + rcu_read_unlock();
56677 + put_files_struct(files);
56678 + }
56679 +
56680 + if (our_file == NULL)
56681 + return 1;
56682 +
56683 + read_lock(&tasklist_lock);
56684 + do_each_thread(p2, p) {
56685 + files = get_files_struct(p);
56686 + if (files == NULL ||
56687 + (p->signal && p->signal->tty == task->signal->tty)) {
56688 + if (files != NULL)
56689 + put_files_struct(files);
56690 + continue;
56691 + }
56692 + rcu_read_lock();
56693 + fdt = files_fdtable(files);
56694 + for (i=0; i < fdt->max_fds; i++) {
56695 + file = fcheck_files(files, i);
56696 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56697 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56698 + p3 = task;
56699 + while (p3->pid > 0) {
56700 + if (p3 == p)
56701 + break;
56702 + p3 = p3->real_parent;
56703 + }
56704 + if (p3 == p)
56705 + break;
56706 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56707 + gr_handle_alertkill(p);
56708 + rcu_read_unlock();
56709 + put_files_struct(files);
56710 + read_unlock(&tasklist_lock);
56711 + fput(our_file);
56712 + return 0;
56713 + }
56714 + }
56715 + rcu_read_unlock();
56716 + put_files_struct(files);
56717 + } while_each_thread(p2, p);
56718 + read_unlock(&tasklist_lock);
56719 +
56720 + fput(our_file);
56721 + return 1;
56722 +}
56723 +
56724 +static int gr_rbac_disable(void *unused)
56725 +{
56726 + pax_open_kernel();
56727 + gr_status &= ~GR_READY;
56728 + pax_close_kernel();
56729 +
56730 + return 0;
56731 +}
56732 +
56733 +ssize_t
56734 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56735 +{
56736 + struct gr_arg_wrapper uwrap;
56737 + unsigned char *sprole_salt = NULL;
56738 + unsigned char *sprole_sum = NULL;
56739 + int error = sizeof (struct gr_arg_wrapper);
56740 + int error2 = 0;
56741 +
56742 + mutex_lock(&gr_dev_mutex);
56743 +
56744 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56745 + error = -EPERM;
56746 + goto out;
56747 + }
56748 +
56749 + if (count != sizeof (struct gr_arg_wrapper)) {
56750 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56751 + error = -EINVAL;
56752 + goto out;
56753 + }
56754 +
56755 +
56756 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56757 + gr_auth_expires = 0;
56758 + gr_auth_attempts = 0;
56759 + }
56760 +
56761 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56762 + error = -EFAULT;
56763 + goto out;
56764 + }
56765 +
56766 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56767 + error = -EINVAL;
56768 + goto out;
56769 + }
56770 +
56771 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56772 + error = -EFAULT;
56773 + goto out;
56774 + }
56775 +
56776 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56777 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56778 + time_after(gr_auth_expires, get_seconds())) {
56779 + error = -EBUSY;
56780 + goto out;
56781 + }
56782 +
56783 + /* if non-root trying to do anything other than use a special role,
56784 + do not attempt authentication, do not count towards authentication
56785 + locking
56786 + */
56787 +
56788 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56789 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56790 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56791 + error = -EPERM;
56792 + goto out;
56793 + }
56794 +
56795 + /* ensure pw and special role name are null terminated */
56796 +
56797 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56798 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56799 +
56800 + /* Okay.
56801 + * We have our enough of the argument structure..(we have yet
56802 + * to copy_from_user the tables themselves) . Copy the tables
56803 + * only if we need them, i.e. for loading operations. */
56804 +
56805 + switch (gr_usermode->mode) {
56806 + case GR_STATUS:
56807 + if (gr_status & GR_READY) {
56808 + error = 1;
56809 + if (!gr_check_secure_terminal(current))
56810 + error = 3;
56811 + } else
56812 + error = 2;
56813 + goto out;
56814 + case GR_SHUTDOWN:
56815 + if ((gr_status & GR_READY)
56816 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56817 + stop_machine(gr_rbac_disable, NULL, NULL);
56818 + free_variables();
56819 + memset(gr_usermode, 0, sizeof (struct gr_arg));
56820 + memset(gr_system_salt, 0, GR_SALT_LEN);
56821 + memset(gr_system_sum, 0, GR_SHA_LEN);
56822 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56823 + } else if (gr_status & GR_READY) {
56824 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56825 + error = -EPERM;
56826 + } else {
56827 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56828 + error = -EAGAIN;
56829 + }
56830 + break;
56831 + case GR_ENABLE:
56832 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56833 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56834 + else {
56835 + if (gr_status & GR_READY)
56836 + error = -EAGAIN;
56837 + else
56838 + error = error2;
56839 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56840 + }
56841 + break;
56842 + case GR_RELOAD:
56843 + if (!(gr_status & GR_READY)) {
56844 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56845 + error = -EAGAIN;
56846 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56847 + stop_machine(gr_rbac_disable, NULL, NULL);
56848 + free_variables();
56849 + error2 = gracl_init(gr_usermode);
56850 + if (!error2)
56851 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56852 + else {
56853 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56854 + error = error2;
56855 + }
56856 + } else {
56857 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56858 + error = -EPERM;
56859 + }
56860 + break;
56861 + case GR_SEGVMOD:
56862 + if (unlikely(!(gr_status & GR_READY))) {
56863 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56864 + error = -EAGAIN;
56865 + break;
56866 + }
56867 +
56868 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56869 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56870 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56871 + struct acl_subject_label *segvacl;
56872 + segvacl =
56873 + lookup_acl_subj_label(gr_usermode->segv_inode,
56874 + gr_usermode->segv_device,
56875 + current->role);
56876 + if (segvacl) {
56877 + segvacl->crashes = 0;
56878 + segvacl->expires = 0;
56879 + }
56880 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56881 + gr_remove_uid(gr_usermode->segv_uid);
56882 + }
56883 + } else {
56884 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56885 + error = -EPERM;
56886 + }
56887 + break;
56888 + case GR_SPROLE:
56889 + case GR_SPROLEPAM:
56890 + if (unlikely(!(gr_status & GR_READY))) {
56891 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56892 + error = -EAGAIN;
56893 + break;
56894 + }
56895 +
56896 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56897 + current->role->expires = 0;
56898 + current->role->auth_attempts = 0;
56899 + }
56900 +
56901 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56902 + time_after(current->role->expires, get_seconds())) {
56903 + error = -EBUSY;
56904 + goto out;
56905 + }
56906 +
56907 + if (lookup_special_role_auth
56908 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56909 + && ((!sprole_salt && !sprole_sum)
56910 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56911 + char *p = "";
56912 + assign_special_role(gr_usermode->sp_role);
56913 + read_lock(&tasklist_lock);
56914 + if (current->real_parent)
56915 + p = current->real_parent->role->rolename;
56916 + read_unlock(&tasklist_lock);
56917 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56918 + p, acl_sp_role_value);
56919 + } else {
56920 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56921 + error = -EPERM;
56922 + if(!(current->role->auth_attempts++))
56923 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56924 +
56925 + goto out;
56926 + }
56927 + break;
56928 + case GR_UNSPROLE:
56929 + if (unlikely(!(gr_status & GR_READY))) {
56930 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56931 + error = -EAGAIN;
56932 + break;
56933 + }
56934 +
56935 + if (current->role->roletype & GR_ROLE_SPECIAL) {
56936 + char *p = "";
56937 + int i = 0;
56938 +
56939 + read_lock(&tasklist_lock);
56940 + if (current->real_parent) {
56941 + p = current->real_parent->role->rolename;
56942 + i = current->real_parent->acl_role_id;
56943 + }
56944 + read_unlock(&tasklist_lock);
56945 +
56946 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
56947 + gr_set_acls(1);
56948 + } else {
56949 + error = -EPERM;
56950 + goto out;
56951 + }
56952 + break;
56953 + default:
56954 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
56955 + error = -EINVAL;
56956 + break;
56957 + }
56958 +
56959 + if (error != -EPERM)
56960 + goto out;
56961 +
56962 + if(!(gr_auth_attempts++))
56963 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56964 +
56965 + out:
56966 + mutex_unlock(&gr_dev_mutex);
56967 + return error;
56968 +}
56969 +
56970 +/* must be called with
56971 + rcu_read_lock();
56972 + read_lock(&tasklist_lock);
56973 + read_lock(&grsec_exec_file_lock);
56974 +*/
56975 +int gr_apply_subject_to_task(struct task_struct *task)
56976 +{
56977 + struct acl_object_label *obj;
56978 + char *tmpname;
56979 + struct acl_subject_label *tmpsubj;
56980 + struct file *filp;
56981 + struct name_entry *nmatch;
56982 +
56983 + filp = task->exec_file;
56984 + if (filp == NULL)
56985 + return 0;
56986 +
56987 + /* the following is to apply the correct subject
56988 + on binaries running when the RBAC system
56989 + is enabled, when the binaries have been
56990 + replaced or deleted since their execution
56991 + -----
56992 + when the RBAC system starts, the inode/dev
56993 + from exec_file will be one the RBAC system
56994 + is unaware of. It only knows the inode/dev
56995 + of the present file on disk, or the absence
56996 + of it.
56997 + */
56998 + preempt_disable();
56999 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57000 +
57001 + nmatch = lookup_name_entry(tmpname);
57002 + preempt_enable();
57003 + tmpsubj = NULL;
57004 + if (nmatch) {
57005 + if (nmatch->deleted)
57006 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57007 + else
57008 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57009 + if (tmpsubj != NULL)
57010 + task->acl = tmpsubj;
57011 + }
57012 + if (tmpsubj == NULL)
57013 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57014 + task->role);
57015 + if (task->acl) {
57016 + task->is_writable = 0;
57017 + /* ignore additional mmap checks for processes that are writable
57018 + by the default ACL */
57019 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57020 + if (unlikely(obj->mode & GR_WRITE))
57021 + task->is_writable = 1;
57022 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57023 + if (unlikely(obj->mode & GR_WRITE))
57024 + task->is_writable = 1;
57025 +
57026 + gr_set_proc_res(task);
57027 +
57028 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57029 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57030 +#endif
57031 + } else {
57032 + return 1;
57033 + }
57034 +
57035 + return 0;
57036 +}
57037 +
57038 +int
57039 +gr_set_acls(const int type)
57040 +{
57041 + struct task_struct *task, *task2;
57042 + struct acl_role_label *role = current->role;
57043 + __u16 acl_role_id = current->acl_role_id;
57044 + const struct cred *cred;
57045 + int ret;
57046 +
57047 + rcu_read_lock();
57048 + read_lock(&tasklist_lock);
57049 + read_lock(&grsec_exec_file_lock);
57050 + do_each_thread(task2, task) {
57051 + /* check to see if we're called from the exit handler,
57052 + if so, only replace ACLs that have inherited the admin
57053 + ACL */
57054 +
57055 + if (type && (task->role != role ||
57056 + task->acl_role_id != acl_role_id))
57057 + continue;
57058 +
57059 + task->acl_role_id = 0;
57060 + task->acl_sp_role = 0;
57061 +
57062 + if (task->exec_file) {
57063 + cred = __task_cred(task);
57064 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57065 + ret = gr_apply_subject_to_task(task);
57066 + if (ret) {
57067 + read_unlock(&grsec_exec_file_lock);
57068 + read_unlock(&tasklist_lock);
57069 + rcu_read_unlock();
57070 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57071 + return ret;
57072 + }
57073 + } else {
57074 + // it's a kernel process
57075 + task->role = kernel_role;
57076 + task->acl = kernel_role->root_label;
57077 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57078 + task->acl->mode &= ~GR_PROCFIND;
57079 +#endif
57080 + }
57081 + } while_each_thread(task2, task);
57082 + read_unlock(&grsec_exec_file_lock);
57083 + read_unlock(&tasklist_lock);
57084 + rcu_read_unlock();
57085 +
57086 + return 0;
57087 +}
57088 +
57089 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57090 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57091 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57092 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57093 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57094 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57095 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57096 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57097 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57098 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57099 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57100 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57101 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57102 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57103 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57104 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57105 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57106 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57107 +};
57108 +
57109 +void
57110 +gr_learn_resource(const struct task_struct *task,
57111 + const int res, const unsigned long wanted, const int gt)
57112 +{
57113 + struct acl_subject_label *acl;
57114 + const struct cred *cred;
57115 +
57116 + if (unlikely((gr_status & GR_READY) &&
57117 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57118 + goto skip_reslog;
57119 +
57120 + gr_log_resource(task, res, wanted, gt);
57121 +skip_reslog:
57122 +
57123 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57124 + return;
57125 +
57126 + acl = task->acl;
57127 +
57128 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57129 + !(acl->resmask & (1 << (unsigned short) res))))
57130 + return;
57131 +
57132 + if (wanted >= acl->res[res].rlim_cur) {
57133 + unsigned long res_add;
57134 +
57135 + res_add = wanted + res_learn_bumps[res];
57136 +
57137 + acl->res[res].rlim_cur = res_add;
57138 +
57139 + if (wanted > acl->res[res].rlim_max)
57140 + acl->res[res].rlim_max = res_add;
57141 +
57142 + /* only log the subject filename, since resource logging is supported for
57143 + single-subject learning only */
57144 + rcu_read_lock();
57145 + cred = __task_cred(task);
57146 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57147 + task->role->roletype, cred->uid, cred->gid, acl->filename,
57148 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
57149 + "", (unsigned long) res, &task->signal->saved_ip);
57150 + rcu_read_unlock();
57151 + }
57152 +
57153 + return;
57154 +}
57155 +EXPORT_SYMBOL(gr_learn_resource);
57156 +#endif
57157 +
57158 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
57159 +void
57160 +pax_set_initial_flags(struct linux_binprm *bprm)
57161 +{
57162 + struct task_struct *task = current;
57163 + struct acl_subject_label *proc;
57164 + unsigned long flags;
57165 +
57166 + if (unlikely(!(gr_status & GR_READY)))
57167 + return;
57168 +
57169 + flags = pax_get_flags(task);
57170 +
57171 + proc = task->acl;
57172 +
57173 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
57174 + flags &= ~MF_PAX_PAGEEXEC;
57175 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
57176 + flags &= ~MF_PAX_SEGMEXEC;
57177 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
57178 + flags &= ~MF_PAX_RANDMMAP;
57179 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
57180 + flags &= ~MF_PAX_EMUTRAMP;
57181 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
57182 + flags &= ~MF_PAX_MPROTECT;
57183 +
57184 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
57185 + flags |= MF_PAX_PAGEEXEC;
57186 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
57187 + flags |= MF_PAX_SEGMEXEC;
57188 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
57189 + flags |= MF_PAX_RANDMMAP;
57190 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
57191 + flags |= MF_PAX_EMUTRAMP;
57192 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
57193 + flags |= MF_PAX_MPROTECT;
57194 +
57195 + pax_set_flags(task, flags);
57196 +
57197 + return;
57198 +}
57199 +#endif
57200 +
57201 +int
57202 +gr_handle_proc_ptrace(struct task_struct *task)
57203 +{
57204 + struct file *filp;
57205 + struct task_struct *tmp = task;
57206 + struct task_struct *curtemp = current;
57207 + __u32 retmode;
57208 +
57209 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57210 + if (unlikely(!(gr_status & GR_READY)))
57211 + return 0;
57212 +#endif
57213 +
57214 + read_lock(&tasklist_lock);
57215 + read_lock(&grsec_exec_file_lock);
57216 + filp = task->exec_file;
57217 +
57218 + while (tmp->pid > 0) {
57219 + if (tmp == curtemp)
57220 + break;
57221 + tmp = tmp->real_parent;
57222 + }
57223 +
57224 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57225 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
57226 + read_unlock(&grsec_exec_file_lock);
57227 + read_unlock(&tasklist_lock);
57228 + return 1;
57229 + }
57230 +
57231 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57232 + if (!(gr_status & GR_READY)) {
57233 + read_unlock(&grsec_exec_file_lock);
57234 + read_unlock(&tasklist_lock);
57235 + return 0;
57236 + }
57237 +#endif
57238 +
57239 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
57240 + read_unlock(&grsec_exec_file_lock);
57241 + read_unlock(&tasklist_lock);
57242 +
57243 + if (retmode & GR_NOPTRACE)
57244 + return 1;
57245 +
57246 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
57247 + && (current->acl != task->acl || (current->acl != current->role->root_label
57248 + && current->pid != task->pid)))
57249 + return 1;
57250 +
57251 + return 0;
57252 +}
57253 +
57254 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
57255 +{
57256 + if (unlikely(!(gr_status & GR_READY)))
57257 + return;
57258 +
57259 + if (!(current->role->roletype & GR_ROLE_GOD))
57260 + return;
57261 +
57262 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
57263 + p->role->rolename, gr_task_roletype_to_char(p),
57264 + p->acl->filename);
57265 +}
57266 +
57267 +int
57268 +gr_handle_ptrace(struct task_struct *task, const long request)
57269 +{
57270 + struct task_struct *tmp = task;
57271 + struct task_struct *curtemp = current;
57272 + __u32 retmode;
57273 +
57274 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57275 + if (unlikely(!(gr_status & GR_READY)))
57276 + return 0;
57277 +#endif
57278 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
57279 + read_lock(&tasklist_lock);
57280 + while (tmp->pid > 0) {
57281 + if (tmp == curtemp)
57282 + break;
57283 + tmp = tmp->real_parent;
57284 + }
57285 +
57286 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57287 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
57288 + read_unlock(&tasklist_lock);
57289 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57290 + return 1;
57291 + }
57292 + read_unlock(&tasklist_lock);
57293 + }
57294 +
57295 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57296 + if (!(gr_status & GR_READY))
57297 + return 0;
57298 +#endif
57299 +
57300 + read_lock(&grsec_exec_file_lock);
57301 + if (unlikely(!task->exec_file)) {
57302 + read_unlock(&grsec_exec_file_lock);
57303 + return 0;
57304 + }
57305 +
57306 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
57307 + read_unlock(&grsec_exec_file_lock);
57308 +
57309 + if (retmode & GR_NOPTRACE) {
57310 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57311 + return 1;
57312 + }
57313 +
57314 + if (retmode & GR_PTRACERD) {
57315 + switch (request) {
57316 + case PTRACE_SEIZE:
57317 + case PTRACE_POKETEXT:
57318 + case PTRACE_POKEDATA:
57319 + case PTRACE_POKEUSR:
57320 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
57321 + case PTRACE_SETREGS:
57322 + case PTRACE_SETFPREGS:
57323 +#endif
57324 +#ifdef CONFIG_X86
57325 + case PTRACE_SETFPXREGS:
57326 +#endif
57327 +#ifdef CONFIG_ALTIVEC
57328 + case PTRACE_SETVRREGS:
57329 +#endif
57330 + return 1;
57331 + default:
57332 + return 0;
57333 + }
57334 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
57335 + !(current->role->roletype & GR_ROLE_GOD) &&
57336 + (current->acl != task->acl)) {
57337 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57338 + return 1;
57339 + }
57340 +
57341 + return 0;
57342 +}
57343 +
57344 +static int is_writable_mmap(const struct file *filp)
57345 +{
57346 + struct task_struct *task = current;
57347 + struct acl_object_label *obj, *obj2;
57348 +
57349 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
57350 + !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))) {
57351 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57352 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
57353 + task->role->root_label);
57354 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
57355 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
57356 + return 1;
57357 + }
57358 + }
57359 + return 0;
57360 +}
57361 +
57362 +int
57363 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
57364 +{
57365 + __u32 mode;
57366 +
57367 + if (unlikely(!file || !(prot & PROT_EXEC)))
57368 + return 1;
57369 +
57370 + if (is_writable_mmap(file))
57371 + return 0;
57372 +
57373 + mode =
57374 + gr_search_file(file->f_path.dentry,
57375 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57376 + file->f_path.mnt);
57377 +
57378 + if (!gr_tpe_allow(file))
57379 + return 0;
57380 +
57381 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57382 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57383 + return 0;
57384 + } else if (unlikely(!(mode & GR_EXEC))) {
57385 + return 0;
57386 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57387 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57388 + return 1;
57389 + }
57390 +
57391 + return 1;
57392 +}
57393 +
57394 +int
57395 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57396 +{
57397 + __u32 mode;
57398 +
57399 + if (unlikely(!file || !(prot & PROT_EXEC)))
57400 + return 1;
57401 +
57402 + if (is_writable_mmap(file))
57403 + return 0;
57404 +
57405 + mode =
57406 + gr_search_file(file->f_path.dentry,
57407 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57408 + file->f_path.mnt);
57409 +
57410 + if (!gr_tpe_allow(file))
57411 + return 0;
57412 +
57413 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57414 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57415 + return 0;
57416 + } else if (unlikely(!(mode & GR_EXEC))) {
57417 + return 0;
57418 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57419 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57420 + return 1;
57421 + }
57422 +
57423 + return 1;
57424 +}
57425 +
57426 +void
57427 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57428 +{
57429 + unsigned long runtime;
57430 + unsigned long cputime;
57431 + unsigned int wday, cday;
57432 + __u8 whr, chr;
57433 + __u8 wmin, cmin;
57434 + __u8 wsec, csec;
57435 + struct timespec timeval;
57436 +
57437 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
57438 + !(task->acl->mode & GR_PROCACCT)))
57439 + return;
57440 +
57441 + do_posix_clock_monotonic_gettime(&timeval);
57442 + runtime = timeval.tv_sec - task->start_time.tv_sec;
57443 + wday = runtime / (3600 * 24);
57444 + runtime -= wday * (3600 * 24);
57445 + whr = runtime / 3600;
57446 + runtime -= whr * 3600;
57447 + wmin = runtime / 60;
57448 + runtime -= wmin * 60;
57449 + wsec = runtime;
57450 +
57451 + cputime = (task->utime + task->stime) / HZ;
57452 + cday = cputime / (3600 * 24);
57453 + cputime -= cday * (3600 * 24);
57454 + chr = cputime / 3600;
57455 + cputime -= chr * 3600;
57456 + cmin = cputime / 60;
57457 + cputime -= cmin * 60;
57458 + csec = cputime;
57459 +
57460 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57461 +
57462 + return;
57463 +}
57464 +
57465 +void gr_set_kernel_label(struct task_struct *task)
57466 +{
57467 + if (gr_status & GR_READY) {
57468 + task->role = kernel_role;
57469 + task->acl = kernel_role->root_label;
57470 + }
57471 + return;
57472 +}
57473 +
57474 +#ifdef CONFIG_TASKSTATS
57475 +int gr_is_taskstats_denied(int pid)
57476 +{
57477 + struct task_struct *task;
57478 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57479 + const struct cred *cred;
57480 +#endif
57481 + int ret = 0;
57482 +
57483 + /* restrict taskstats viewing to un-chrooted root users
57484 + who have the 'view' subject flag if the RBAC system is enabled
57485 + */
57486 +
57487 + rcu_read_lock();
57488 + read_lock(&tasklist_lock);
57489 + task = find_task_by_vpid(pid);
57490 + if (task) {
57491 +#ifdef CONFIG_GRKERNSEC_CHROOT
57492 + if (proc_is_chrooted(task))
57493 + ret = -EACCES;
57494 +#endif
57495 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57496 + cred = __task_cred(task);
57497 +#ifdef CONFIG_GRKERNSEC_PROC_USER
57498 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57499 + ret = -EACCES;
57500 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57501 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57502 + ret = -EACCES;
57503 +#endif
57504 +#endif
57505 + if (gr_status & GR_READY) {
57506 + if (!(task->acl->mode & GR_VIEW))
57507 + ret = -EACCES;
57508 + }
57509 + } else
57510 + ret = -ENOENT;
57511 +
57512 + read_unlock(&tasklist_lock);
57513 + rcu_read_unlock();
57514 +
57515 + return ret;
57516 +}
57517 +#endif
57518 +
57519 +/* AUXV entries are filled via a descendant of search_binary_handler
57520 + after we've already applied the subject for the target
57521 +*/
57522 +int gr_acl_enable_at_secure(void)
57523 +{
57524 + if (unlikely(!(gr_status & GR_READY)))
57525 + return 0;
57526 +
57527 + if (current->acl->mode & GR_ATSECURE)
57528 + return 1;
57529 +
57530 + return 0;
57531 +}
57532 +
57533 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57534 +{
57535 + struct task_struct *task = current;
57536 + struct dentry *dentry = file->f_path.dentry;
57537 + struct vfsmount *mnt = file->f_path.mnt;
57538 + struct acl_object_label *obj, *tmp;
57539 + struct acl_subject_label *subj;
57540 + unsigned int bufsize;
57541 + int is_not_root;
57542 + char *path;
57543 + dev_t dev = __get_dev(dentry);
57544 +
57545 + if (unlikely(!(gr_status & GR_READY)))
57546 + return 1;
57547 +
57548 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57549 + return 1;
57550 +
57551 + /* ignore Eric Biederman */
57552 + if (IS_PRIVATE(dentry->d_inode))
57553 + return 1;
57554 +
57555 + subj = task->acl;
57556 + read_lock(&gr_inode_lock);
57557 + do {
57558 + obj = lookup_acl_obj_label(ino, dev, subj);
57559 + if (obj != NULL) {
57560 + read_unlock(&gr_inode_lock);
57561 + return (obj->mode & GR_FIND) ? 1 : 0;
57562 + }
57563 + } while ((subj = subj->parent_subject));
57564 + read_unlock(&gr_inode_lock);
57565 +
57566 + /* this is purely an optimization since we're looking for an object
57567 + for the directory we're doing a readdir on
57568 + if it's possible for any globbed object to match the entry we're
57569 + filling into the directory, then the object we find here will be
57570 + an anchor point with attached globbed objects
57571 + */
57572 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57573 + if (obj->globbed == NULL)
57574 + return (obj->mode & GR_FIND) ? 1 : 0;
57575 +
57576 + is_not_root = ((obj->filename[0] == '/') &&
57577 + (obj->filename[1] == '\0')) ? 0 : 1;
57578 + bufsize = PAGE_SIZE - namelen - is_not_root;
57579 +
57580 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
57581 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57582 + return 1;
57583 +
57584 + preempt_disable();
57585 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57586 + bufsize);
57587 +
57588 + bufsize = strlen(path);
57589 +
57590 + /* if base is "/", don't append an additional slash */
57591 + if (is_not_root)
57592 + *(path + bufsize) = '/';
57593 + memcpy(path + bufsize + is_not_root, name, namelen);
57594 + *(path + bufsize + namelen + is_not_root) = '\0';
57595 +
57596 + tmp = obj->globbed;
57597 + while (tmp) {
57598 + if (!glob_match(tmp->filename, path)) {
57599 + preempt_enable();
57600 + return (tmp->mode & GR_FIND) ? 1 : 0;
57601 + }
57602 + tmp = tmp->next;
57603 + }
57604 + preempt_enable();
57605 + return (obj->mode & GR_FIND) ? 1 : 0;
57606 +}
57607 +
57608 +void gr_put_exec_file(struct task_struct *task)
57609 +{
57610 + struct file *filp;
57611 +
57612 + write_lock(&grsec_exec_file_lock);
57613 + filp = task->exec_file;
57614 + task->exec_file = NULL;
57615 + write_unlock(&grsec_exec_file_lock);
57616 +
57617 + if (filp)
57618 + fput(filp);
57619 +
57620 + return;
57621 +}
57622 +
57623 +
57624 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57625 +EXPORT_SYMBOL(gr_acl_is_enabled);
57626 +#endif
57627 +EXPORT_SYMBOL(gr_set_kernel_label);
57628 +#ifdef CONFIG_SECURITY
57629 +EXPORT_SYMBOL(gr_check_user_change);
57630 +EXPORT_SYMBOL(gr_check_group_change);
57631 +#endif
57632 +
57633 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57634 new file mode 100644
57635 index 0000000..34fefda
57636 --- /dev/null
57637 +++ b/grsecurity/gracl_alloc.c
57638 @@ -0,0 +1,105 @@
57639 +#include <linux/kernel.h>
57640 +#include <linux/mm.h>
57641 +#include <linux/slab.h>
57642 +#include <linux/vmalloc.h>
57643 +#include <linux/gracl.h>
57644 +#include <linux/grsecurity.h>
57645 +
57646 +static unsigned long alloc_stack_next = 1;
57647 +static unsigned long alloc_stack_size = 1;
57648 +static void **alloc_stack;
57649 +
57650 +static __inline__ int
57651 +alloc_pop(void)
57652 +{
57653 + if (alloc_stack_next == 1)
57654 + return 0;
57655 +
57656 + kfree(alloc_stack[alloc_stack_next - 2]);
57657 +
57658 + alloc_stack_next--;
57659 +
57660 + return 1;
57661 +}
57662 +
57663 +static __inline__ int
57664 +alloc_push(void *buf)
57665 +{
57666 + if (alloc_stack_next >= alloc_stack_size)
57667 + return 1;
57668 +
57669 + alloc_stack[alloc_stack_next - 1] = buf;
57670 +
57671 + alloc_stack_next++;
57672 +
57673 + return 0;
57674 +}
57675 +
57676 +void *
57677 +acl_alloc(unsigned long len)
57678 +{
57679 + void *ret = NULL;
57680 +
57681 + if (!len || len > PAGE_SIZE)
57682 + goto out;
57683 +
57684 + ret = kmalloc(len, GFP_KERNEL);
57685 +
57686 + if (ret) {
57687 + if (alloc_push(ret)) {
57688 + kfree(ret);
57689 + ret = NULL;
57690 + }
57691 + }
57692 +
57693 +out:
57694 + return ret;
57695 +}
57696 +
57697 +void *
57698 +acl_alloc_num(unsigned long num, unsigned long len)
57699 +{
57700 + if (!len || (num > (PAGE_SIZE / len)))
57701 + return NULL;
57702 +
57703 + return acl_alloc(num * len);
57704 +}
57705 +
57706 +void
57707 +acl_free_all(void)
57708 +{
57709 + if (gr_acl_is_enabled() || !alloc_stack)
57710 + return;
57711 +
57712 + while (alloc_pop()) ;
57713 +
57714 + if (alloc_stack) {
57715 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57716 + kfree(alloc_stack);
57717 + else
57718 + vfree(alloc_stack);
57719 + }
57720 +
57721 + alloc_stack = NULL;
57722 + alloc_stack_size = 1;
57723 + alloc_stack_next = 1;
57724 +
57725 + return;
57726 +}
57727 +
57728 +int
57729 +acl_alloc_stack_init(unsigned long size)
57730 +{
57731 + if ((size * sizeof (void *)) <= PAGE_SIZE)
57732 + alloc_stack =
57733 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57734 + else
57735 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
57736 +
57737 + alloc_stack_size = size;
57738 +
57739 + if (!alloc_stack)
57740 + return 0;
57741 + else
57742 + return 1;
57743 +}
57744 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57745 new file mode 100644
57746 index 0000000..6d21049
57747 --- /dev/null
57748 +++ b/grsecurity/gracl_cap.c
57749 @@ -0,0 +1,110 @@
57750 +#include <linux/kernel.h>
57751 +#include <linux/module.h>
57752 +#include <linux/sched.h>
57753 +#include <linux/gracl.h>
57754 +#include <linux/grsecurity.h>
57755 +#include <linux/grinternal.h>
57756 +
57757 +extern const char *captab_log[];
57758 +extern int captab_log_entries;
57759 +
57760 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57761 +{
57762 + struct acl_subject_label *curracl;
57763 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57764 + kernel_cap_t cap_audit = __cap_empty_set;
57765 +
57766 + if (!gr_acl_is_enabled())
57767 + return 1;
57768 +
57769 + curracl = task->acl;
57770 +
57771 + cap_drop = curracl->cap_lower;
57772 + cap_mask = curracl->cap_mask;
57773 + cap_audit = curracl->cap_invert_audit;
57774 +
57775 + while ((curracl = curracl->parent_subject)) {
57776 + /* if the cap isn't specified in the current computed mask but is specified in the
57777 + current level subject, and is lowered in the current level subject, then add
57778 + it to the set of dropped capabilities
57779 + otherwise, add the current level subject's mask to the current computed mask
57780 + */
57781 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57782 + cap_raise(cap_mask, cap);
57783 + if (cap_raised(curracl->cap_lower, cap))
57784 + cap_raise(cap_drop, cap);
57785 + if (cap_raised(curracl->cap_invert_audit, cap))
57786 + cap_raise(cap_audit, cap);
57787 + }
57788 + }
57789 +
57790 + if (!cap_raised(cap_drop, cap)) {
57791 + if (cap_raised(cap_audit, cap))
57792 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57793 + return 1;
57794 + }
57795 +
57796 + curracl = task->acl;
57797 +
57798 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57799 + && cap_raised(cred->cap_effective, cap)) {
57800 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57801 + task->role->roletype, cred->uid,
57802 + cred->gid, task->exec_file ?
57803 + gr_to_filename(task->exec_file->f_path.dentry,
57804 + task->exec_file->f_path.mnt) : curracl->filename,
57805 + curracl->filename, 0UL,
57806 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57807 + return 1;
57808 + }
57809 +
57810 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57811 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57812 +
57813 + return 0;
57814 +}
57815 +
57816 +int
57817 +gr_acl_is_capable(const int cap)
57818 +{
57819 + return gr_task_acl_is_capable(current, current_cred(), cap);
57820 +}
57821 +
57822 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57823 +{
57824 + struct acl_subject_label *curracl;
57825 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57826 +
57827 + if (!gr_acl_is_enabled())
57828 + return 1;
57829 +
57830 + curracl = task->acl;
57831 +
57832 + cap_drop = curracl->cap_lower;
57833 + cap_mask = curracl->cap_mask;
57834 +
57835 + while ((curracl = curracl->parent_subject)) {
57836 + /* if the cap isn't specified in the current computed mask but is specified in the
57837 + current level subject, and is lowered in the current level subject, then add
57838 + it to the set of dropped capabilities
57839 + otherwise, add the current level subject's mask to the current computed mask
57840 + */
57841 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57842 + cap_raise(cap_mask, cap);
57843 + if (cap_raised(curracl->cap_lower, cap))
57844 + cap_raise(cap_drop, cap);
57845 + }
57846 + }
57847 +
57848 + if (!cap_raised(cap_drop, cap))
57849 + return 1;
57850 +
57851 + return 0;
57852 +}
57853 +
57854 +int
57855 +gr_acl_is_capable_nolog(const int cap)
57856 +{
57857 + return gr_task_acl_is_capable_nolog(current, cap);
57858 +}
57859 +
57860 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57861 new file mode 100644
57862 index 0000000..a340c17
57863 --- /dev/null
57864 +++ b/grsecurity/gracl_fs.c
57865 @@ -0,0 +1,431 @@
57866 +#include <linux/kernel.h>
57867 +#include <linux/sched.h>
57868 +#include <linux/types.h>
57869 +#include <linux/fs.h>
57870 +#include <linux/file.h>
57871 +#include <linux/stat.h>
57872 +#include <linux/grsecurity.h>
57873 +#include <linux/grinternal.h>
57874 +#include <linux/gracl.h>
57875 +
57876 +umode_t
57877 +gr_acl_umask(void)
57878 +{
57879 + if (unlikely(!gr_acl_is_enabled()))
57880 + return 0;
57881 +
57882 + return current->role->umask;
57883 +}
57884 +
57885 +__u32
57886 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57887 + const struct vfsmount * mnt)
57888 +{
57889 + __u32 mode;
57890 +
57891 + if (unlikely(!dentry->d_inode))
57892 + return GR_FIND;
57893 +
57894 + mode =
57895 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57896 +
57897 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57898 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57899 + return mode;
57900 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57901 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57902 + return 0;
57903 + } else if (unlikely(!(mode & GR_FIND)))
57904 + return 0;
57905 +
57906 + return GR_FIND;
57907 +}
57908 +
57909 +__u32
57910 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57911 + int acc_mode)
57912 +{
57913 + __u32 reqmode = GR_FIND;
57914 + __u32 mode;
57915 +
57916 + if (unlikely(!dentry->d_inode))
57917 + return reqmode;
57918 +
57919 + if (acc_mode & MAY_APPEND)
57920 + reqmode |= GR_APPEND;
57921 + else if (acc_mode & MAY_WRITE)
57922 + reqmode |= GR_WRITE;
57923 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57924 + reqmode |= GR_READ;
57925 +
57926 + mode =
57927 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57928 + mnt);
57929 +
57930 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57931 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57932 + reqmode & GR_READ ? " reading" : "",
57933 + reqmode & GR_WRITE ? " writing" : reqmode &
57934 + GR_APPEND ? " appending" : "");
57935 + return reqmode;
57936 + } else
57937 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57938 + {
57939 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57940 + reqmode & GR_READ ? " reading" : "",
57941 + reqmode & GR_WRITE ? " writing" : reqmode &
57942 + GR_APPEND ? " appending" : "");
57943 + return 0;
57944 + } else if (unlikely((mode & reqmode) != reqmode))
57945 + return 0;
57946 +
57947 + return reqmode;
57948 +}
57949 +
57950 +__u32
57951 +gr_acl_handle_creat(const struct dentry * dentry,
57952 + const struct dentry * p_dentry,
57953 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57954 + const int imode)
57955 +{
57956 + __u32 reqmode = GR_WRITE | GR_CREATE;
57957 + __u32 mode;
57958 +
57959 + if (acc_mode & MAY_APPEND)
57960 + reqmode |= GR_APPEND;
57961 + // if a directory was required or the directory already exists, then
57962 + // don't count this open as a read
57963 + if ((acc_mode & MAY_READ) &&
57964 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
57965 + reqmode |= GR_READ;
57966 + if ((open_flags & O_CREAT) &&
57967 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57968 + reqmode |= GR_SETID;
57969 +
57970 + mode =
57971 + gr_check_create(dentry, p_dentry, p_mnt,
57972 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57973 +
57974 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57975 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57976 + reqmode & GR_READ ? " reading" : "",
57977 + reqmode & GR_WRITE ? " writing" : reqmode &
57978 + GR_APPEND ? " appending" : "");
57979 + return reqmode;
57980 + } else
57981 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57982 + {
57983 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57984 + reqmode & GR_READ ? " reading" : "",
57985 + reqmode & GR_WRITE ? " writing" : reqmode &
57986 + GR_APPEND ? " appending" : "");
57987 + return 0;
57988 + } else if (unlikely((mode & reqmode) != reqmode))
57989 + return 0;
57990 +
57991 + return reqmode;
57992 +}
57993 +
57994 +__u32
57995 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
57996 + const int fmode)
57997 +{
57998 + __u32 mode, reqmode = GR_FIND;
57999 +
58000 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58001 + reqmode |= GR_EXEC;
58002 + if (fmode & S_IWOTH)
58003 + reqmode |= GR_WRITE;
58004 + if (fmode & S_IROTH)
58005 + reqmode |= GR_READ;
58006 +
58007 + mode =
58008 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58009 + mnt);
58010 +
58011 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58012 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58013 + reqmode & GR_READ ? " reading" : "",
58014 + reqmode & GR_WRITE ? " writing" : "",
58015 + reqmode & GR_EXEC ? " executing" : "");
58016 + return reqmode;
58017 + } else
58018 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58019 + {
58020 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58021 + reqmode & GR_READ ? " reading" : "",
58022 + reqmode & GR_WRITE ? " writing" : "",
58023 + reqmode & GR_EXEC ? " executing" : "");
58024 + return 0;
58025 + } else if (unlikely((mode & reqmode) != reqmode))
58026 + return 0;
58027 +
58028 + return reqmode;
58029 +}
58030 +
58031 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58032 +{
58033 + __u32 mode;
58034 +
58035 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58036 +
58037 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58038 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58039 + return mode;
58040 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58041 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58042 + return 0;
58043 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58044 + return 0;
58045 +
58046 + return (reqmode);
58047 +}
58048 +
58049 +__u32
58050 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58051 +{
58052 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58053 +}
58054 +
58055 +__u32
58056 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58057 +{
58058 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58059 +}
58060 +
58061 +__u32
58062 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58063 +{
58064 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58065 +}
58066 +
58067 +__u32
58068 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58069 +{
58070 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58071 +}
58072 +
58073 +__u32
58074 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58075 + umode_t *modeptr)
58076 +{
58077 + umode_t mode;
58078 +
58079 + *modeptr &= ~gr_acl_umask();
58080 + mode = *modeptr;
58081 +
58082 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58083 + return 1;
58084 +
58085 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58086 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58087 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58088 + GR_CHMOD_ACL_MSG);
58089 + } else {
58090 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58091 + }
58092 +}
58093 +
58094 +__u32
58095 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58096 +{
58097 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58098 +}
58099 +
58100 +__u32
58101 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58102 +{
58103 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58104 +}
58105 +
58106 +__u32
58107 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58108 +{
58109 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58110 +}
58111 +
58112 +__u32
58113 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58114 +{
58115 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58116 + GR_UNIXCONNECT_ACL_MSG);
58117 +}
58118 +
58119 +/* hardlinks require at minimum create and link permission,
58120 + any additional privilege required is based on the
58121 + privilege of the file being linked to
58122 +*/
58123 +__u32
58124 +gr_acl_handle_link(const struct dentry * new_dentry,
58125 + const struct dentry * parent_dentry,
58126 + const struct vfsmount * parent_mnt,
58127 + const struct dentry * old_dentry,
58128 + const struct vfsmount * old_mnt, const struct filename *to)
58129 +{
58130 + __u32 mode;
58131 + __u32 needmode = GR_CREATE | GR_LINK;
58132 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58133 +
58134 + mode =
58135 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58136 + old_mnt);
58137 +
58138 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58139 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58140 + return mode;
58141 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58142 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58143 + return 0;
58144 + } else if (unlikely((mode & needmode) != needmode))
58145 + return 0;
58146 +
58147 + return 1;
58148 +}
58149 +
58150 +__u32
58151 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58152 + const struct dentry * parent_dentry,
58153 + const struct vfsmount * parent_mnt, const struct filename *from)
58154 +{
58155 + __u32 needmode = GR_WRITE | GR_CREATE;
58156 + __u32 mode;
58157 +
58158 + mode =
58159 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
58160 + GR_CREATE | GR_AUDIT_CREATE |
58161 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
58162 +
58163 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
58164 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58165 + return mode;
58166 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58167 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58168 + return 0;
58169 + } else if (unlikely((mode & needmode) != needmode))
58170 + return 0;
58171 +
58172 + return (GR_WRITE | GR_CREATE);
58173 +}
58174 +
58175 +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)
58176 +{
58177 + __u32 mode;
58178 +
58179 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58180 +
58181 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58182 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
58183 + return mode;
58184 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58185 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
58186 + return 0;
58187 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58188 + return 0;
58189 +
58190 + return (reqmode);
58191 +}
58192 +
58193 +__u32
58194 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58195 + const struct dentry * parent_dentry,
58196 + const struct vfsmount * parent_mnt,
58197 + const int mode)
58198 +{
58199 + __u32 reqmode = GR_WRITE | GR_CREATE;
58200 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58201 + reqmode |= GR_SETID;
58202 +
58203 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58204 + reqmode, GR_MKNOD_ACL_MSG);
58205 +}
58206 +
58207 +__u32
58208 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
58209 + const struct dentry *parent_dentry,
58210 + const struct vfsmount *parent_mnt)
58211 +{
58212 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58213 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
58214 +}
58215 +
58216 +#define RENAME_CHECK_SUCCESS(old, new) \
58217 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
58218 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
58219 +
58220 +int
58221 +gr_acl_handle_rename(struct dentry *new_dentry,
58222 + struct dentry *parent_dentry,
58223 + const struct vfsmount *parent_mnt,
58224 + struct dentry *old_dentry,
58225 + struct inode *old_parent_inode,
58226 + struct vfsmount *old_mnt, const struct filename *newname)
58227 +{
58228 + __u32 comp1, comp2;
58229 + int error = 0;
58230 +
58231 + if (unlikely(!gr_acl_is_enabled()))
58232 + return 0;
58233 +
58234 + if (!new_dentry->d_inode) {
58235 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
58236 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
58237 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
58238 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
58239 + GR_DELETE | GR_AUDIT_DELETE |
58240 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58241 + GR_SUPPRESS, old_mnt);
58242 + } else {
58243 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
58244 + GR_CREATE | GR_DELETE |
58245 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
58246 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58247 + GR_SUPPRESS, parent_mnt);
58248 + comp2 =
58249 + gr_search_file(old_dentry,
58250 + GR_READ | GR_WRITE | GR_AUDIT_READ |
58251 + GR_DELETE | GR_AUDIT_DELETE |
58252 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
58253 + }
58254 +
58255 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
58256 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
58257 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58258 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
58259 + && !(comp2 & GR_SUPPRESS)) {
58260 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58261 + error = -EACCES;
58262 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
58263 + error = -EACCES;
58264 +
58265 + return error;
58266 +}
58267 +
58268 +void
58269 +gr_acl_handle_exit(void)
58270 +{
58271 + u16 id;
58272 + char *rolename;
58273 +
58274 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
58275 + !(current->role->roletype & GR_ROLE_PERSIST))) {
58276 + id = current->acl_role_id;
58277 + rolename = current->role->rolename;
58278 + gr_set_acls(1);
58279 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
58280 + }
58281 +
58282 + gr_put_exec_file(current);
58283 + return;
58284 +}
58285 +
58286 +int
58287 +gr_acl_handle_procpidmem(const struct task_struct *task)
58288 +{
58289 + if (unlikely(!gr_acl_is_enabled()))
58290 + return 0;
58291 +
58292 + if (task != current && task->acl->mode & GR_PROTPROCFD)
58293 + return -EACCES;
58294 +
58295 + return 0;
58296 +}
58297 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
58298 new file mode 100644
58299 index 0000000..58800a7
58300 --- /dev/null
58301 +++ b/grsecurity/gracl_ip.c
58302 @@ -0,0 +1,384 @@
58303 +#include <linux/kernel.h>
58304 +#include <asm/uaccess.h>
58305 +#include <asm/errno.h>
58306 +#include <net/sock.h>
58307 +#include <linux/file.h>
58308 +#include <linux/fs.h>
58309 +#include <linux/net.h>
58310 +#include <linux/in.h>
58311 +#include <linux/skbuff.h>
58312 +#include <linux/ip.h>
58313 +#include <linux/udp.h>
58314 +#include <linux/types.h>
58315 +#include <linux/sched.h>
58316 +#include <linux/netdevice.h>
58317 +#include <linux/inetdevice.h>
58318 +#include <linux/gracl.h>
58319 +#include <linux/grsecurity.h>
58320 +#include <linux/grinternal.h>
58321 +
58322 +#define GR_BIND 0x01
58323 +#define GR_CONNECT 0x02
58324 +#define GR_INVERT 0x04
58325 +#define GR_BINDOVERRIDE 0x08
58326 +#define GR_CONNECTOVERRIDE 0x10
58327 +#define GR_SOCK_FAMILY 0x20
58328 +
58329 +static const char * gr_protocols[IPPROTO_MAX] = {
58330 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
58331 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
58332 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
58333 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
58334 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
58335 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
58336 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
58337 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
58338 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
58339 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
58340 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
58341 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
58342 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
58343 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
58344 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
58345 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
58346 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
58347 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
58348 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
58349 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
58350 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
58351 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
58352 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
58353 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
58354 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
58355 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
58356 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
58357 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
58358 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
58359 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
58360 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
58361 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
58362 + };
58363 +
58364 +static const char * gr_socktypes[SOCK_MAX] = {
58365 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
58366 + "unknown:7", "unknown:8", "unknown:9", "packet"
58367 + };
58368 +
58369 +static const char * gr_sockfamilies[AF_MAX+1] = {
58370 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
58371 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
58372 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
58373 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
58374 + };
58375 +
58376 +const char *
58377 +gr_proto_to_name(unsigned char proto)
58378 +{
58379 + return gr_protocols[proto];
58380 +}
58381 +
58382 +const char *
58383 +gr_socktype_to_name(unsigned char type)
58384 +{
58385 + return gr_socktypes[type];
58386 +}
58387 +
58388 +const char *
58389 +gr_sockfamily_to_name(unsigned char family)
58390 +{
58391 + return gr_sockfamilies[family];
58392 +}
58393 +
58394 +int
58395 +gr_search_socket(const int domain, const int type, const int protocol)
58396 +{
58397 + struct acl_subject_label *curr;
58398 + const struct cred *cred = current_cred();
58399 +
58400 + if (unlikely(!gr_acl_is_enabled()))
58401 + goto exit;
58402 +
58403 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
58404 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
58405 + goto exit; // let the kernel handle it
58406 +
58407 + curr = current->acl;
58408 +
58409 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
58410 + /* the family is allowed, if this is PF_INET allow it only if
58411 + the extra sock type/protocol checks pass */
58412 + if (domain == PF_INET)
58413 + goto inet_check;
58414 + goto exit;
58415 + } else {
58416 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58417 + __u32 fakeip = 0;
58418 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58419 + current->role->roletype, cred->uid,
58420 + cred->gid, current->exec_file ?
58421 + gr_to_filename(current->exec_file->f_path.dentry,
58422 + current->exec_file->f_path.mnt) :
58423 + curr->filename, curr->filename,
58424 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
58425 + &current->signal->saved_ip);
58426 + goto exit;
58427 + }
58428 + goto exit_fail;
58429 + }
58430 +
58431 +inet_check:
58432 + /* the rest of this checking is for IPv4 only */
58433 + if (!curr->ips)
58434 + goto exit;
58435 +
58436 + if ((curr->ip_type & (1 << type)) &&
58437 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
58438 + goto exit;
58439 +
58440 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58441 + /* we don't place acls on raw sockets , and sometimes
58442 + dgram/ip sockets are opened for ioctl and not
58443 + bind/connect, so we'll fake a bind learn log */
58444 + if (type == SOCK_RAW || type == SOCK_PACKET) {
58445 + __u32 fakeip = 0;
58446 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58447 + current->role->roletype, cred->uid,
58448 + cred->gid, current->exec_file ?
58449 + gr_to_filename(current->exec_file->f_path.dentry,
58450 + current->exec_file->f_path.mnt) :
58451 + curr->filename, curr->filename,
58452 + &fakeip, 0, type,
58453 + protocol, GR_CONNECT, &current->signal->saved_ip);
58454 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58455 + __u32 fakeip = 0;
58456 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58457 + current->role->roletype, cred->uid,
58458 + cred->gid, current->exec_file ?
58459 + gr_to_filename(current->exec_file->f_path.dentry,
58460 + current->exec_file->f_path.mnt) :
58461 + curr->filename, curr->filename,
58462 + &fakeip, 0, type,
58463 + protocol, GR_BIND, &current->signal->saved_ip);
58464 + }
58465 + /* we'll log when they use connect or bind */
58466 + goto exit;
58467 + }
58468 +
58469 +exit_fail:
58470 + if (domain == PF_INET)
58471 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58472 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
58473 + else
58474 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58475 + gr_socktype_to_name(type), protocol);
58476 +
58477 + return 0;
58478 +exit:
58479 + return 1;
58480 +}
58481 +
58482 +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)
58483 +{
58484 + if ((ip->mode & mode) &&
58485 + (ip_port >= ip->low) &&
58486 + (ip_port <= ip->high) &&
58487 + ((ntohl(ip_addr) & our_netmask) ==
58488 + (ntohl(our_addr) & our_netmask))
58489 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58490 + && (ip->type & (1 << type))) {
58491 + if (ip->mode & GR_INVERT)
58492 + return 2; // specifically denied
58493 + else
58494 + return 1; // allowed
58495 + }
58496 +
58497 + return 0; // not specifically allowed, may continue parsing
58498 +}
58499 +
58500 +static int
58501 +gr_search_connectbind(const int full_mode, struct sock *sk,
58502 + struct sockaddr_in *addr, const int type)
58503 +{
58504 + char iface[IFNAMSIZ] = {0};
58505 + struct acl_subject_label *curr;
58506 + struct acl_ip_label *ip;
58507 + struct inet_sock *isk;
58508 + struct net_device *dev;
58509 + struct in_device *idev;
58510 + unsigned long i;
58511 + int ret;
58512 + int mode = full_mode & (GR_BIND | GR_CONNECT);
58513 + __u32 ip_addr = 0;
58514 + __u32 our_addr;
58515 + __u32 our_netmask;
58516 + char *p;
58517 + __u16 ip_port = 0;
58518 + const struct cred *cred = current_cred();
58519 +
58520 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58521 + return 0;
58522 +
58523 + curr = current->acl;
58524 + isk = inet_sk(sk);
58525 +
58526 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58527 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58528 + addr->sin_addr.s_addr = curr->inaddr_any_override;
58529 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58530 + struct sockaddr_in saddr;
58531 + int err;
58532 +
58533 + saddr.sin_family = AF_INET;
58534 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
58535 + saddr.sin_port = isk->inet_sport;
58536 +
58537 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58538 + if (err)
58539 + return err;
58540 +
58541 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58542 + if (err)
58543 + return err;
58544 + }
58545 +
58546 + if (!curr->ips)
58547 + return 0;
58548 +
58549 + ip_addr = addr->sin_addr.s_addr;
58550 + ip_port = ntohs(addr->sin_port);
58551 +
58552 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58553 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58554 + current->role->roletype, cred->uid,
58555 + cred->gid, current->exec_file ?
58556 + gr_to_filename(current->exec_file->f_path.dentry,
58557 + current->exec_file->f_path.mnt) :
58558 + curr->filename, curr->filename,
58559 + &ip_addr, ip_port, type,
58560 + sk->sk_protocol, mode, &current->signal->saved_ip);
58561 + return 0;
58562 + }
58563 +
58564 + for (i = 0; i < curr->ip_num; i++) {
58565 + ip = *(curr->ips + i);
58566 + if (ip->iface != NULL) {
58567 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
58568 + p = strchr(iface, ':');
58569 + if (p != NULL)
58570 + *p = '\0';
58571 + dev = dev_get_by_name(sock_net(sk), iface);
58572 + if (dev == NULL)
58573 + continue;
58574 + idev = in_dev_get(dev);
58575 + if (idev == NULL) {
58576 + dev_put(dev);
58577 + continue;
58578 + }
58579 + rcu_read_lock();
58580 + for_ifa(idev) {
58581 + if (!strcmp(ip->iface, ifa->ifa_label)) {
58582 + our_addr = ifa->ifa_address;
58583 + our_netmask = 0xffffffff;
58584 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58585 + if (ret == 1) {
58586 + rcu_read_unlock();
58587 + in_dev_put(idev);
58588 + dev_put(dev);
58589 + return 0;
58590 + } else if (ret == 2) {
58591 + rcu_read_unlock();
58592 + in_dev_put(idev);
58593 + dev_put(dev);
58594 + goto denied;
58595 + }
58596 + }
58597 + } endfor_ifa(idev);
58598 + rcu_read_unlock();
58599 + in_dev_put(idev);
58600 + dev_put(dev);
58601 + } else {
58602 + our_addr = ip->addr;
58603 + our_netmask = ip->netmask;
58604 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58605 + if (ret == 1)
58606 + return 0;
58607 + else if (ret == 2)
58608 + goto denied;
58609 + }
58610 + }
58611 +
58612 +denied:
58613 + if (mode == GR_BIND)
58614 + 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));
58615 + else if (mode == GR_CONNECT)
58616 + 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));
58617 +
58618 + return -EACCES;
58619 +}
58620 +
58621 +int
58622 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58623 +{
58624 + /* always allow disconnection of dgram sockets with connect */
58625 + if (addr->sin_family == AF_UNSPEC)
58626 + return 0;
58627 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58628 +}
58629 +
58630 +int
58631 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58632 +{
58633 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58634 +}
58635 +
58636 +int gr_search_listen(struct socket *sock)
58637 +{
58638 + struct sock *sk = sock->sk;
58639 + struct sockaddr_in addr;
58640 +
58641 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58642 + addr.sin_port = inet_sk(sk)->inet_sport;
58643 +
58644 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58645 +}
58646 +
58647 +int gr_search_accept(struct socket *sock)
58648 +{
58649 + struct sock *sk = sock->sk;
58650 + struct sockaddr_in addr;
58651 +
58652 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58653 + addr.sin_port = inet_sk(sk)->inet_sport;
58654 +
58655 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58656 +}
58657 +
58658 +int
58659 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58660 +{
58661 + if (addr)
58662 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58663 + else {
58664 + struct sockaddr_in sin;
58665 + const struct inet_sock *inet = inet_sk(sk);
58666 +
58667 + sin.sin_addr.s_addr = inet->inet_daddr;
58668 + sin.sin_port = inet->inet_dport;
58669 +
58670 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58671 + }
58672 +}
58673 +
58674 +int
58675 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58676 +{
58677 + struct sockaddr_in sin;
58678 +
58679 + if (unlikely(skb->len < sizeof (struct udphdr)))
58680 + return 0; // skip this packet
58681 +
58682 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58683 + sin.sin_port = udp_hdr(skb)->source;
58684 +
58685 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58686 +}
58687 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58688 new file mode 100644
58689 index 0000000..25f54ef
58690 --- /dev/null
58691 +++ b/grsecurity/gracl_learn.c
58692 @@ -0,0 +1,207 @@
58693 +#include <linux/kernel.h>
58694 +#include <linux/mm.h>
58695 +#include <linux/sched.h>
58696 +#include <linux/poll.h>
58697 +#include <linux/string.h>
58698 +#include <linux/file.h>
58699 +#include <linux/types.h>
58700 +#include <linux/vmalloc.h>
58701 +#include <linux/grinternal.h>
58702 +
58703 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58704 + size_t count, loff_t *ppos);
58705 +extern int gr_acl_is_enabled(void);
58706 +
58707 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58708 +static int gr_learn_attached;
58709 +
58710 +/* use a 512k buffer */
58711 +#define LEARN_BUFFER_SIZE (512 * 1024)
58712 +
58713 +static DEFINE_SPINLOCK(gr_learn_lock);
58714 +static DEFINE_MUTEX(gr_learn_user_mutex);
58715 +
58716 +/* we need to maintain two buffers, so that the kernel context of grlearn
58717 + uses a semaphore around the userspace copying, and the other kernel contexts
58718 + use a spinlock when copying into the buffer, since they cannot sleep
58719 +*/
58720 +static char *learn_buffer;
58721 +static char *learn_buffer_user;
58722 +static int learn_buffer_len;
58723 +static int learn_buffer_user_len;
58724 +
58725 +static ssize_t
58726 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58727 +{
58728 + DECLARE_WAITQUEUE(wait, current);
58729 + ssize_t retval = 0;
58730 +
58731 + add_wait_queue(&learn_wait, &wait);
58732 + set_current_state(TASK_INTERRUPTIBLE);
58733 + do {
58734 + mutex_lock(&gr_learn_user_mutex);
58735 + spin_lock(&gr_learn_lock);
58736 + if (learn_buffer_len)
58737 + break;
58738 + spin_unlock(&gr_learn_lock);
58739 + mutex_unlock(&gr_learn_user_mutex);
58740 + if (file->f_flags & O_NONBLOCK) {
58741 + retval = -EAGAIN;
58742 + goto out;
58743 + }
58744 + if (signal_pending(current)) {
58745 + retval = -ERESTARTSYS;
58746 + goto out;
58747 + }
58748 +
58749 + schedule();
58750 + } while (1);
58751 +
58752 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58753 + learn_buffer_user_len = learn_buffer_len;
58754 + retval = learn_buffer_len;
58755 + learn_buffer_len = 0;
58756 +
58757 + spin_unlock(&gr_learn_lock);
58758 +
58759 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58760 + retval = -EFAULT;
58761 +
58762 + mutex_unlock(&gr_learn_user_mutex);
58763 +out:
58764 + set_current_state(TASK_RUNNING);
58765 + remove_wait_queue(&learn_wait, &wait);
58766 + return retval;
58767 +}
58768 +
58769 +static unsigned int
58770 +poll_learn(struct file * file, poll_table * wait)
58771 +{
58772 + poll_wait(file, &learn_wait, wait);
58773 +
58774 + if (learn_buffer_len)
58775 + return (POLLIN | POLLRDNORM);
58776 +
58777 + return 0;
58778 +}
58779 +
58780 +void
58781 +gr_clear_learn_entries(void)
58782 +{
58783 + char *tmp;
58784 +
58785 + mutex_lock(&gr_learn_user_mutex);
58786 + spin_lock(&gr_learn_lock);
58787 + tmp = learn_buffer;
58788 + learn_buffer = NULL;
58789 + spin_unlock(&gr_learn_lock);
58790 + if (tmp)
58791 + vfree(tmp);
58792 + if (learn_buffer_user != NULL) {
58793 + vfree(learn_buffer_user);
58794 + learn_buffer_user = NULL;
58795 + }
58796 + learn_buffer_len = 0;
58797 + mutex_unlock(&gr_learn_user_mutex);
58798 +
58799 + return;
58800 +}
58801 +
58802 +void
58803 +gr_add_learn_entry(const char *fmt, ...)
58804 +{
58805 + va_list args;
58806 + unsigned int len;
58807 +
58808 + if (!gr_learn_attached)
58809 + return;
58810 +
58811 + spin_lock(&gr_learn_lock);
58812 +
58813 + /* leave a gap at the end so we know when it's "full" but don't have to
58814 + compute the exact length of the string we're trying to append
58815 + */
58816 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58817 + spin_unlock(&gr_learn_lock);
58818 + wake_up_interruptible(&learn_wait);
58819 + return;
58820 + }
58821 + if (learn_buffer == NULL) {
58822 + spin_unlock(&gr_learn_lock);
58823 + return;
58824 + }
58825 +
58826 + va_start(args, fmt);
58827 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58828 + va_end(args);
58829 +
58830 + learn_buffer_len += len + 1;
58831 +
58832 + spin_unlock(&gr_learn_lock);
58833 + wake_up_interruptible(&learn_wait);
58834 +
58835 + return;
58836 +}
58837 +
58838 +static int
58839 +open_learn(struct inode *inode, struct file *file)
58840 +{
58841 + if (file->f_mode & FMODE_READ && gr_learn_attached)
58842 + return -EBUSY;
58843 + if (file->f_mode & FMODE_READ) {
58844 + int retval = 0;
58845 + mutex_lock(&gr_learn_user_mutex);
58846 + if (learn_buffer == NULL)
58847 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58848 + if (learn_buffer_user == NULL)
58849 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58850 + if (learn_buffer == NULL) {
58851 + retval = -ENOMEM;
58852 + goto out_error;
58853 + }
58854 + if (learn_buffer_user == NULL) {
58855 + retval = -ENOMEM;
58856 + goto out_error;
58857 + }
58858 + learn_buffer_len = 0;
58859 + learn_buffer_user_len = 0;
58860 + gr_learn_attached = 1;
58861 +out_error:
58862 + mutex_unlock(&gr_learn_user_mutex);
58863 + return retval;
58864 + }
58865 + return 0;
58866 +}
58867 +
58868 +static int
58869 +close_learn(struct inode *inode, struct file *file)
58870 +{
58871 + if (file->f_mode & FMODE_READ) {
58872 + char *tmp = NULL;
58873 + mutex_lock(&gr_learn_user_mutex);
58874 + spin_lock(&gr_learn_lock);
58875 + tmp = learn_buffer;
58876 + learn_buffer = NULL;
58877 + spin_unlock(&gr_learn_lock);
58878 + if (tmp)
58879 + vfree(tmp);
58880 + if (learn_buffer_user != NULL) {
58881 + vfree(learn_buffer_user);
58882 + learn_buffer_user = NULL;
58883 + }
58884 + learn_buffer_len = 0;
58885 + learn_buffer_user_len = 0;
58886 + gr_learn_attached = 0;
58887 + mutex_unlock(&gr_learn_user_mutex);
58888 + }
58889 +
58890 + return 0;
58891 +}
58892 +
58893 +const struct file_operations grsec_fops = {
58894 + .read = read_learn,
58895 + .write = write_grsec_handler,
58896 + .open = open_learn,
58897 + .release = close_learn,
58898 + .poll = poll_learn,
58899 +};
58900 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58901 new file mode 100644
58902 index 0000000..39645c9
58903 --- /dev/null
58904 +++ b/grsecurity/gracl_res.c
58905 @@ -0,0 +1,68 @@
58906 +#include <linux/kernel.h>
58907 +#include <linux/sched.h>
58908 +#include <linux/gracl.h>
58909 +#include <linux/grinternal.h>
58910 +
58911 +static const char *restab_log[] = {
58912 + [RLIMIT_CPU] = "RLIMIT_CPU",
58913 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58914 + [RLIMIT_DATA] = "RLIMIT_DATA",
58915 + [RLIMIT_STACK] = "RLIMIT_STACK",
58916 + [RLIMIT_CORE] = "RLIMIT_CORE",
58917 + [RLIMIT_RSS] = "RLIMIT_RSS",
58918 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
58919 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58920 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58921 + [RLIMIT_AS] = "RLIMIT_AS",
58922 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58923 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58924 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58925 + [RLIMIT_NICE] = "RLIMIT_NICE",
58926 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58927 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58928 + [GR_CRASH_RES] = "RLIMIT_CRASH"
58929 +};
58930 +
58931 +void
58932 +gr_log_resource(const struct task_struct *task,
58933 + const int res, const unsigned long wanted, const int gt)
58934 +{
58935 + const struct cred *cred;
58936 + unsigned long rlim;
58937 +
58938 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
58939 + return;
58940 +
58941 + // not yet supported resource
58942 + if (unlikely(!restab_log[res]))
58943 + return;
58944 +
58945 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
58946 + rlim = task_rlimit_max(task, res);
58947 + else
58948 + rlim = task_rlimit(task, res);
58949 +
58950 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
58951 + return;
58952 +
58953 + rcu_read_lock();
58954 + cred = __task_cred(task);
58955 +
58956 + if (res == RLIMIT_NPROC &&
58957 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
58958 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
58959 + goto out_rcu_unlock;
58960 + else if (res == RLIMIT_MEMLOCK &&
58961 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
58962 + goto out_rcu_unlock;
58963 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
58964 + goto out_rcu_unlock;
58965 + rcu_read_unlock();
58966 +
58967 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
58968 +
58969 + return;
58970 +out_rcu_unlock:
58971 + rcu_read_unlock();
58972 + return;
58973 +}
58974 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
58975 new file mode 100644
58976 index 0000000..25197e9
58977 --- /dev/null
58978 +++ b/grsecurity/gracl_segv.c
58979 @@ -0,0 +1,299 @@
58980 +#include <linux/kernel.h>
58981 +#include <linux/mm.h>
58982 +#include <asm/uaccess.h>
58983 +#include <asm/errno.h>
58984 +#include <asm/mman.h>
58985 +#include <net/sock.h>
58986 +#include <linux/file.h>
58987 +#include <linux/fs.h>
58988 +#include <linux/net.h>
58989 +#include <linux/in.h>
58990 +#include <linux/slab.h>
58991 +#include <linux/types.h>
58992 +#include <linux/sched.h>
58993 +#include <linux/timer.h>
58994 +#include <linux/gracl.h>
58995 +#include <linux/grsecurity.h>
58996 +#include <linux/grinternal.h>
58997 +
58998 +static struct crash_uid *uid_set;
58999 +static unsigned short uid_used;
59000 +static DEFINE_SPINLOCK(gr_uid_lock);
59001 +extern rwlock_t gr_inode_lock;
59002 +extern struct acl_subject_label *
59003 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59004 + struct acl_role_label *role);
59005 +
59006 +#ifdef CONFIG_BTRFS_FS
59007 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59008 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59009 +#endif
59010 +
59011 +static inline dev_t __get_dev(const struct dentry *dentry)
59012 +{
59013 +#ifdef CONFIG_BTRFS_FS
59014 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59015 + return get_btrfs_dev_from_inode(dentry->d_inode);
59016 + else
59017 +#endif
59018 + return dentry->d_inode->i_sb->s_dev;
59019 +}
59020 +
59021 +int
59022 +gr_init_uidset(void)
59023 +{
59024 + uid_set =
59025 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59026 + uid_used = 0;
59027 +
59028 + return uid_set ? 1 : 0;
59029 +}
59030 +
59031 +void
59032 +gr_free_uidset(void)
59033 +{
59034 + if (uid_set)
59035 + kfree(uid_set);
59036 +
59037 + return;
59038 +}
59039 +
59040 +int
59041 +gr_find_uid(const uid_t uid)
59042 +{
59043 + struct crash_uid *tmp = uid_set;
59044 + uid_t buid;
59045 + int low = 0, high = uid_used - 1, mid;
59046 +
59047 + while (high >= low) {
59048 + mid = (low + high) >> 1;
59049 + buid = tmp[mid].uid;
59050 + if (buid == uid)
59051 + return mid;
59052 + if (buid > uid)
59053 + high = mid - 1;
59054 + if (buid < uid)
59055 + low = mid + 1;
59056 + }
59057 +
59058 + return -1;
59059 +}
59060 +
59061 +static __inline__ void
59062 +gr_insertsort(void)
59063 +{
59064 + unsigned short i, j;
59065 + struct crash_uid index;
59066 +
59067 + for (i = 1; i < uid_used; i++) {
59068 + index = uid_set[i];
59069 + j = i;
59070 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59071 + uid_set[j] = uid_set[j - 1];
59072 + j--;
59073 + }
59074 + uid_set[j] = index;
59075 + }
59076 +
59077 + return;
59078 +}
59079 +
59080 +static __inline__ void
59081 +gr_insert_uid(const uid_t uid, const unsigned long expires)
59082 +{
59083 + int loc;
59084 +
59085 + if (uid_used == GR_UIDTABLE_MAX)
59086 + return;
59087 +
59088 + loc = gr_find_uid(uid);
59089 +
59090 + if (loc >= 0) {
59091 + uid_set[loc].expires = expires;
59092 + return;
59093 + }
59094 +
59095 + uid_set[uid_used].uid = uid;
59096 + uid_set[uid_used].expires = expires;
59097 + uid_used++;
59098 +
59099 + gr_insertsort();
59100 +
59101 + return;
59102 +}
59103 +
59104 +void
59105 +gr_remove_uid(const unsigned short loc)
59106 +{
59107 + unsigned short i;
59108 +
59109 + for (i = loc + 1; i < uid_used; i++)
59110 + uid_set[i - 1] = uid_set[i];
59111 +
59112 + uid_used--;
59113 +
59114 + return;
59115 +}
59116 +
59117 +int
59118 +gr_check_crash_uid(const uid_t uid)
59119 +{
59120 + int loc;
59121 + int ret = 0;
59122 +
59123 + if (unlikely(!gr_acl_is_enabled()))
59124 + return 0;
59125 +
59126 + spin_lock(&gr_uid_lock);
59127 + loc = gr_find_uid(uid);
59128 +
59129 + if (loc < 0)
59130 + goto out_unlock;
59131 +
59132 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
59133 + gr_remove_uid(loc);
59134 + else
59135 + ret = 1;
59136 +
59137 +out_unlock:
59138 + spin_unlock(&gr_uid_lock);
59139 + return ret;
59140 +}
59141 +
59142 +static __inline__ int
59143 +proc_is_setxid(const struct cred *cred)
59144 +{
59145 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
59146 + !uid_eq(cred->uid, cred->fsuid))
59147 + return 1;
59148 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
59149 + !uid_eq(cred->gid, cred->fsgid))
59150 + return 1;
59151 +
59152 + return 0;
59153 +}
59154 +
59155 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
59156 +
59157 +void
59158 +gr_handle_crash(struct task_struct *task, const int sig)
59159 +{
59160 + struct acl_subject_label *curr;
59161 + struct task_struct *tsk, *tsk2;
59162 + const struct cred *cred;
59163 + const struct cred *cred2;
59164 +
59165 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
59166 + return;
59167 +
59168 + if (unlikely(!gr_acl_is_enabled()))
59169 + return;
59170 +
59171 + curr = task->acl;
59172 +
59173 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
59174 + return;
59175 +
59176 + if (time_before_eq(curr->expires, get_seconds())) {
59177 + curr->expires = 0;
59178 + curr->crashes = 0;
59179 + }
59180 +
59181 + curr->crashes++;
59182 +
59183 + if (!curr->expires)
59184 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
59185 +
59186 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59187 + time_after(curr->expires, get_seconds())) {
59188 + rcu_read_lock();
59189 + cred = __task_cred(task);
59190 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
59191 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59192 + spin_lock(&gr_uid_lock);
59193 + gr_insert_uid(cred->uid, curr->expires);
59194 + spin_unlock(&gr_uid_lock);
59195 + curr->expires = 0;
59196 + curr->crashes = 0;
59197 + read_lock(&tasklist_lock);
59198 + do_each_thread(tsk2, tsk) {
59199 + cred2 = __task_cred(tsk);
59200 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
59201 + gr_fake_force_sig(SIGKILL, tsk);
59202 + } while_each_thread(tsk2, tsk);
59203 + read_unlock(&tasklist_lock);
59204 + } else {
59205 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59206 + read_lock(&tasklist_lock);
59207 + read_lock(&grsec_exec_file_lock);
59208 + do_each_thread(tsk2, tsk) {
59209 + if (likely(tsk != task)) {
59210 + // if this thread has the same subject as the one that triggered
59211 + // RES_CRASH and it's the same binary, kill it
59212 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
59213 + gr_fake_force_sig(SIGKILL, tsk);
59214 + }
59215 + } while_each_thread(tsk2, tsk);
59216 + read_unlock(&grsec_exec_file_lock);
59217 + read_unlock(&tasklist_lock);
59218 + }
59219 + rcu_read_unlock();
59220 + }
59221 +
59222 + return;
59223 +}
59224 +
59225 +int
59226 +gr_check_crash_exec(const struct file *filp)
59227 +{
59228 + struct acl_subject_label *curr;
59229 +
59230 + if (unlikely(!gr_acl_is_enabled()))
59231 + return 0;
59232 +
59233 + read_lock(&gr_inode_lock);
59234 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
59235 + __get_dev(filp->f_path.dentry),
59236 + current->role);
59237 + read_unlock(&gr_inode_lock);
59238 +
59239 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
59240 + (!curr->crashes && !curr->expires))
59241 + return 0;
59242 +
59243 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59244 + time_after(curr->expires, get_seconds()))
59245 + return 1;
59246 + else if (time_before_eq(curr->expires, get_seconds())) {
59247 + curr->crashes = 0;
59248 + curr->expires = 0;
59249 + }
59250 +
59251 + return 0;
59252 +}
59253 +
59254 +void
59255 +gr_handle_alertkill(struct task_struct *task)
59256 +{
59257 + struct acl_subject_label *curracl;
59258 + __u32 curr_ip;
59259 + struct task_struct *p, *p2;
59260 +
59261 + if (unlikely(!gr_acl_is_enabled()))
59262 + return;
59263 +
59264 + curracl = task->acl;
59265 + curr_ip = task->signal->curr_ip;
59266 +
59267 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
59268 + read_lock(&tasklist_lock);
59269 + do_each_thread(p2, p) {
59270 + if (p->signal->curr_ip == curr_ip)
59271 + gr_fake_force_sig(SIGKILL, p);
59272 + } while_each_thread(p2, p);
59273 + read_unlock(&tasklist_lock);
59274 + } else if (curracl->mode & GR_KILLPROC)
59275 + gr_fake_force_sig(SIGKILL, task);
59276 +
59277 + return;
59278 +}
59279 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
59280 new file mode 100644
59281 index 0000000..9d83a69
59282 --- /dev/null
59283 +++ b/grsecurity/gracl_shm.c
59284 @@ -0,0 +1,40 @@
59285 +#include <linux/kernel.h>
59286 +#include <linux/mm.h>
59287 +#include <linux/sched.h>
59288 +#include <linux/file.h>
59289 +#include <linux/ipc.h>
59290 +#include <linux/gracl.h>
59291 +#include <linux/grsecurity.h>
59292 +#include <linux/grinternal.h>
59293 +
59294 +int
59295 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59296 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59297 +{
59298 + struct task_struct *task;
59299 +
59300 + if (!gr_acl_is_enabled())
59301 + return 1;
59302 +
59303 + rcu_read_lock();
59304 + read_lock(&tasklist_lock);
59305 +
59306 + task = find_task_by_vpid(shm_cprid);
59307 +
59308 + if (unlikely(!task))
59309 + task = find_task_by_vpid(shm_lapid);
59310 +
59311 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
59312 + (task->pid == shm_lapid)) &&
59313 + (task->acl->mode & GR_PROTSHM) &&
59314 + (task->acl != current->acl))) {
59315 + read_unlock(&tasklist_lock);
59316 + rcu_read_unlock();
59317 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
59318 + return 0;
59319 + }
59320 + read_unlock(&tasklist_lock);
59321 + rcu_read_unlock();
59322 +
59323 + return 1;
59324 +}
59325 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
59326 new file mode 100644
59327 index 0000000..bc0be01
59328 --- /dev/null
59329 +++ b/grsecurity/grsec_chdir.c
59330 @@ -0,0 +1,19 @@
59331 +#include <linux/kernel.h>
59332 +#include <linux/sched.h>
59333 +#include <linux/fs.h>
59334 +#include <linux/file.h>
59335 +#include <linux/grsecurity.h>
59336 +#include <linux/grinternal.h>
59337 +
59338 +void
59339 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
59340 +{
59341 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59342 + if ((grsec_enable_chdir && grsec_enable_group &&
59343 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
59344 + !grsec_enable_group)) {
59345 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
59346 + }
59347 +#endif
59348 + return;
59349 +}
59350 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
59351 new file mode 100644
59352 index 0000000..70fe0ae
59353 --- /dev/null
59354 +++ b/grsecurity/grsec_chroot.c
59355 @@ -0,0 +1,357 @@
59356 +#include <linux/kernel.h>
59357 +#include <linux/module.h>
59358 +#include <linux/sched.h>
59359 +#include <linux/file.h>
59360 +#include <linux/fs.h>
59361 +#include <linux/mount.h>
59362 +#include <linux/types.h>
59363 +#include "../fs/mount.h"
59364 +#include <linux/grsecurity.h>
59365 +#include <linux/grinternal.h>
59366 +
59367 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
59368 +{
59369 +#ifdef CONFIG_GRKERNSEC
59370 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
59371 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
59372 + task->gr_is_chrooted = 1;
59373 + else
59374 + task->gr_is_chrooted = 0;
59375 +
59376 + task->gr_chroot_dentry = path->dentry;
59377 +#endif
59378 + return;
59379 +}
59380 +
59381 +void gr_clear_chroot_entries(struct task_struct *task)
59382 +{
59383 +#ifdef CONFIG_GRKERNSEC
59384 + task->gr_is_chrooted = 0;
59385 + task->gr_chroot_dentry = NULL;
59386 +#endif
59387 + return;
59388 +}
59389 +
59390 +int
59391 +gr_handle_chroot_unix(const pid_t pid)
59392 +{
59393 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59394 + struct task_struct *p;
59395 +
59396 + if (unlikely(!grsec_enable_chroot_unix))
59397 + return 1;
59398 +
59399 + if (likely(!proc_is_chrooted(current)))
59400 + return 1;
59401 +
59402 + rcu_read_lock();
59403 + read_lock(&tasklist_lock);
59404 + p = find_task_by_vpid_unrestricted(pid);
59405 + if (unlikely(p && !have_same_root(current, p))) {
59406 + read_unlock(&tasklist_lock);
59407 + rcu_read_unlock();
59408 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
59409 + return 0;
59410 + }
59411 + read_unlock(&tasklist_lock);
59412 + rcu_read_unlock();
59413 +#endif
59414 + return 1;
59415 +}
59416 +
59417 +int
59418 +gr_handle_chroot_nice(void)
59419 +{
59420 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59421 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
59422 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
59423 + return -EPERM;
59424 + }
59425 +#endif
59426 + return 0;
59427 +}
59428 +
59429 +int
59430 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
59431 +{
59432 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59433 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
59434 + && proc_is_chrooted(current)) {
59435 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
59436 + return -EACCES;
59437 + }
59438 +#endif
59439 + return 0;
59440 +}
59441 +
59442 +int
59443 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59444 +{
59445 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59446 + struct task_struct *p;
59447 + int ret = 0;
59448 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59449 + return ret;
59450 +
59451 + read_lock(&tasklist_lock);
59452 + do_each_pid_task(pid, type, p) {
59453 + if (!have_same_root(current, p)) {
59454 + ret = 1;
59455 + goto out;
59456 + }
59457 + } while_each_pid_task(pid, type, p);
59458 +out:
59459 + read_unlock(&tasklist_lock);
59460 + return ret;
59461 +#endif
59462 + return 0;
59463 +}
59464 +
59465 +int
59466 +gr_pid_is_chrooted(struct task_struct *p)
59467 +{
59468 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59469 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59470 + return 0;
59471 +
59472 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59473 + !have_same_root(current, p)) {
59474 + return 1;
59475 + }
59476 +#endif
59477 + return 0;
59478 +}
59479 +
59480 +EXPORT_SYMBOL(gr_pid_is_chrooted);
59481 +
59482 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59483 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59484 +{
59485 + struct path path, currentroot;
59486 + int ret = 0;
59487 +
59488 + path.dentry = (struct dentry *)u_dentry;
59489 + path.mnt = (struct vfsmount *)u_mnt;
59490 + get_fs_root(current->fs, &currentroot);
59491 + if (path_is_under(&path, &currentroot))
59492 + ret = 1;
59493 + path_put(&currentroot);
59494 +
59495 + return ret;
59496 +}
59497 +#endif
59498 +
59499 +int
59500 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59501 +{
59502 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59503 + if (!grsec_enable_chroot_fchdir)
59504 + return 1;
59505 +
59506 + if (!proc_is_chrooted(current))
59507 + return 1;
59508 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59509 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59510 + return 0;
59511 + }
59512 +#endif
59513 + return 1;
59514 +}
59515 +
59516 +int
59517 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59518 + const time_t shm_createtime)
59519 +{
59520 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59521 + struct task_struct *p;
59522 + time_t starttime;
59523 +
59524 + if (unlikely(!grsec_enable_chroot_shmat))
59525 + return 1;
59526 +
59527 + if (likely(!proc_is_chrooted(current)))
59528 + return 1;
59529 +
59530 + rcu_read_lock();
59531 + read_lock(&tasklist_lock);
59532 +
59533 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59534 + starttime = p->start_time.tv_sec;
59535 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59536 + if (have_same_root(current, p)) {
59537 + goto allow;
59538 + } else {
59539 + read_unlock(&tasklist_lock);
59540 + rcu_read_unlock();
59541 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59542 + return 0;
59543 + }
59544 + }
59545 + /* creator exited, pid reuse, fall through to next check */
59546 + }
59547 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59548 + if (unlikely(!have_same_root(current, p))) {
59549 + read_unlock(&tasklist_lock);
59550 + rcu_read_unlock();
59551 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59552 + return 0;
59553 + }
59554 + }
59555 +
59556 +allow:
59557 + read_unlock(&tasklist_lock);
59558 + rcu_read_unlock();
59559 +#endif
59560 + return 1;
59561 +}
59562 +
59563 +void
59564 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59565 +{
59566 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59567 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59568 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59569 +#endif
59570 + return;
59571 +}
59572 +
59573 +int
59574 +gr_handle_chroot_mknod(const struct dentry *dentry,
59575 + const struct vfsmount *mnt, const int mode)
59576 +{
59577 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59578 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59579 + proc_is_chrooted(current)) {
59580 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59581 + return -EPERM;
59582 + }
59583 +#endif
59584 + return 0;
59585 +}
59586 +
59587 +int
59588 +gr_handle_chroot_mount(const struct dentry *dentry,
59589 + const struct vfsmount *mnt, const char *dev_name)
59590 +{
59591 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59592 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59593 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59594 + return -EPERM;
59595 + }
59596 +#endif
59597 + return 0;
59598 +}
59599 +
59600 +int
59601 +gr_handle_chroot_pivot(void)
59602 +{
59603 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59604 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59605 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59606 + return -EPERM;
59607 + }
59608 +#endif
59609 + return 0;
59610 +}
59611 +
59612 +int
59613 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59614 +{
59615 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59616 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59617 + !gr_is_outside_chroot(dentry, mnt)) {
59618 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59619 + return -EPERM;
59620 + }
59621 +#endif
59622 + return 0;
59623 +}
59624 +
59625 +extern const char *captab_log[];
59626 +extern int captab_log_entries;
59627 +
59628 +int
59629 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59630 +{
59631 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59632 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59633 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59634 + if (cap_raised(chroot_caps, cap)) {
59635 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59636 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59637 + }
59638 + return 0;
59639 + }
59640 + }
59641 +#endif
59642 + return 1;
59643 +}
59644 +
59645 +int
59646 +gr_chroot_is_capable(const int cap)
59647 +{
59648 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59649 + return gr_task_chroot_is_capable(current, current_cred(), cap);
59650 +#endif
59651 + return 1;
59652 +}
59653 +
59654 +int
59655 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59656 +{
59657 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59658 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59659 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59660 + if (cap_raised(chroot_caps, cap)) {
59661 + return 0;
59662 + }
59663 + }
59664 +#endif
59665 + return 1;
59666 +}
59667 +
59668 +int
59669 +gr_chroot_is_capable_nolog(const int cap)
59670 +{
59671 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59672 + return gr_task_chroot_is_capable_nolog(current, cap);
59673 +#endif
59674 + return 1;
59675 +}
59676 +
59677 +int
59678 +gr_handle_chroot_sysctl(const int op)
59679 +{
59680 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59681 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59682 + proc_is_chrooted(current))
59683 + return -EACCES;
59684 +#endif
59685 + return 0;
59686 +}
59687 +
59688 +void
59689 +gr_handle_chroot_chdir(struct path *path)
59690 +{
59691 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59692 + if (grsec_enable_chroot_chdir)
59693 + set_fs_pwd(current->fs, path);
59694 +#endif
59695 + return;
59696 +}
59697 +
59698 +int
59699 +gr_handle_chroot_chmod(const struct dentry *dentry,
59700 + const struct vfsmount *mnt, const int mode)
59701 +{
59702 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59703 + /* allow chmod +s on directories, but not files */
59704 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59705 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59706 + proc_is_chrooted(current)) {
59707 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59708 + return -EPERM;
59709 + }
59710 +#endif
59711 + return 0;
59712 +}
59713 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59714 new file mode 100644
59715 index 0000000..e6796b3
59716 --- /dev/null
59717 +++ b/grsecurity/grsec_disabled.c
59718 @@ -0,0 +1,434 @@
59719 +#include <linux/kernel.h>
59720 +#include <linux/module.h>
59721 +#include <linux/sched.h>
59722 +#include <linux/file.h>
59723 +#include <linux/fs.h>
59724 +#include <linux/kdev_t.h>
59725 +#include <linux/net.h>
59726 +#include <linux/in.h>
59727 +#include <linux/ip.h>
59728 +#include <linux/skbuff.h>
59729 +#include <linux/sysctl.h>
59730 +
59731 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59732 +void
59733 +pax_set_initial_flags(struct linux_binprm *bprm)
59734 +{
59735 + return;
59736 +}
59737 +#endif
59738 +
59739 +#ifdef CONFIG_SYSCTL
59740 +__u32
59741 +gr_handle_sysctl(const struct ctl_table * table, const int op)
59742 +{
59743 + return 0;
59744 +}
59745 +#endif
59746 +
59747 +#ifdef CONFIG_TASKSTATS
59748 +int gr_is_taskstats_denied(int pid)
59749 +{
59750 + return 0;
59751 +}
59752 +#endif
59753 +
59754 +int
59755 +gr_acl_is_enabled(void)
59756 +{
59757 + return 0;
59758 +}
59759 +
59760 +void
59761 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59762 +{
59763 + return;
59764 +}
59765 +
59766 +int
59767 +gr_handle_rawio(const struct inode *inode)
59768 +{
59769 + return 0;
59770 +}
59771 +
59772 +void
59773 +gr_acl_handle_psacct(struct task_struct *task, const long code)
59774 +{
59775 + return;
59776 +}
59777 +
59778 +int
59779 +gr_handle_ptrace(struct task_struct *task, const long request)
59780 +{
59781 + return 0;
59782 +}
59783 +
59784 +int
59785 +gr_handle_proc_ptrace(struct task_struct *task)
59786 +{
59787 + return 0;
59788 +}
59789 +
59790 +int
59791 +gr_set_acls(const int type)
59792 +{
59793 + return 0;
59794 +}
59795 +
59796 +int
59797 +gr_check_hidden_task(const struct task_struct *tsk)
59798 +{
59799 + return 0;
59800 +}
59801 +
59802 +int
59803 +gr_check_protected_task(const struct task_struct *task)
59804 +{
59805 + return 0;
59806 +}
59807 +
59808 +int
59809 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59810 +{
59811 + return 0;
59812 +}
59813 +
59814 +void
59815 +gr_copy_label(struct task_struct *tsk)
59816 +{
59817 + return;
59818 +}
59819 +
59820 +void
59821 +gr_set_pax_flags(struct task_struct *task)
59822 +{
59823 + return;
59824 +}
59825 +
59826 +int
59827 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59828 + const int unsafe_share)
59829 +{
59830 + return 0;
59831 +}
59832 +
59833 +void
59834 +gr_handle_delete(const ino_t ino, const dev_t dev)
59835 +{
59836 + return;
59837 +}
59838 +
59839 +void
59840 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59841 +{
59842 + return;
59843 +}
59844 +
59845 +void
59846 +gr_handle_crash(struct task_struct *task, const int sig)
59847 +{
59848 + return;
59849 +}
59850 +
59851 +int
59852 +gr_check_crash_exec(const struct file *filp)
59853 +{
59854 + return 0;
59855 +}
59856 +
59857 +int
59858 +gr_check_crash_uid(const uid_t uid)
59859 +{
59860 + return 0;
59861 +}
59862 +
59863 +void
59864 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59865 + struct dentry *old_dentry,
59866 + struct dentry *new_dentry,
59867 + struct vfsmount *mnt, const __u8 replace)
59868 +{
59869 + return;
59870 +}
59871 +
59872 +int
59873 +gr_search_socket(const int family, const int type, const int protocol)
59874 +{
59875 + return 1;
59876 +}
59877 +
59878 +int
59879 +gr_search_connectbind(const int mode, const struct socket *sock,
59880 + const struct sockaddr_in *addr)
59881 +{
59882 + return 0;
59883 +}
59884 +
59885 +void
59886 +gr_handle_alertkill(struct task_struct *task)
59887 +{
59888 + return;
59889 +}
59890 +
59891 +__u32
59892 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59893 +{
59894 + return 1;
59895 +}
59896 +
59897 +__u32
59898 +gr_acl_handle_hidden_file(const struct dentry * dentry,
59899 + const struct vfsmount * mnt)
59900 +{
59901 + return 1;
59902 +}
59903 +
59904 +__u32
59905 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59906 + int acc_mode)
59907 +{
59908 + return 1;
59909 +}
59910 +
59911 +__u32
59912 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59913 +{
59914 + return 1;
59915 +}
59916 +
59917 +__u32
59918 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59919 +{
59920 + return 1;
59921 +}
59922 +
59923 +int
59924 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59925 + unsigned int *vm_flags)
59926 +{
59927 + return 1;
59928 +}
59929 +
59930 +__u32
59931 +gr_acl_handle_truncate(const struct dentry * dentry,
59932 + const struct vfsmount * mnt)
59933 +{
59934 + return 1;
59935 +}
59936 +
59937 +__u32
59938 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59939 +{
59940 + return 1;
59941 +}
59942 +
59943 +__u32
59944 +gr_acl_handle_access(const struct dentry * dentry,
59945 + const struct vfsmount * mnt, const int fmode)
59946 +{
59947 + return 1;
59948 +}
59949 +
59950 +__u32
59951 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
59952 + umode_t *mode)
59953 +{
59954 + return 1;
59955 +}
59956 +
59957 +__u32
59958 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
59959 +{
59960 + return 1;
59961 +}
59962 +
59963 +__u32
59964 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
59965 +{
59966 + return 1;
59967 +}
59968 +
59969 +void
59970 +grsecurity_init(void)
59971 +{
59972 + return;
59973 +}
59974 +
59975 +umode_t gr_acl_umask(void)
59976 +{
59977 + return 0;
59978 +}
59979 +
59980 +__u32
59981 +gr_acl_handle_mknod(const struct dentry * new_dentry,
59982 + const struct dentry * parent_dentry,
59983 + const struct vfsmount * parent_mnt,
59984 + const int mode)
59985 +{
59986 + return 1;
59987 +}
59988 +
59989 +__u32
59990 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
59991 + const struct dentry * parent_dentry,
59992 + const struct vfsmount * parent_mnt)
59993 +{
59994 + return 1;
59995 +}
59996 +
59997 +__u32
59998 +gr_acl_handle_symlink(const struct dentry * new_dentry,
59999 + const struct dentry * parent_dentry,
60000 + const struct vfsmount * parent_mnt, const struct filename *from)
60001 +{
60002 + return 1;
60003 +}
60004 +
60005 +__u32
60006 +gr_acl_handle_link(const struct dentry * new_dentry,
60007 + const struct dentry * parent_dentry,
60008 + const struct vfsmount * parent_mnt,
60009 + const struct dentry * old_dentry,
60010 + const struct vfsmount * old_mnt, const struct filename *to)
60011 +{
60012 + return 1;
60013 +}
60014 +
60015 +int
60016 +gr_acl_handle_rename(const struct dentry *new_dentry,
60017 + const struct dentry *parent_dentry,
60018 + const struct vfsmount *parent_mnt,
60019 + const struct dentry *old_dentry,
60020 + const struct inode *old_parent_inode,
60021 + const struct vfsmount *old_mnt, const struct filename *newname)
60022 +{
60023 + return 0;
60024 +}
60025 +
60026 +int
60027 +gr_acl_handle_filldir(const struct file *file, const char *name,
60028 + const int namelen, const ino_t ino)
60029 +{
60030 + return 1;
60031 +}
60032 +
60033 +int
60034 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60035 + const time_t shm_createtime, const uid_t cuid, const int shmid)
60036 +{
60037 + return 1;
60038 +}
60039 +
60040 +int
60041 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60042 +{
60043 + return 0;
60044 +}
60045 +
60046 +int
60047 +gr_search_accept(const struct socket *sock)
60048 +{
60049 + return 0;
60050 +}
60051 +
60052 +int
60053 +gr_search_listen(const struct socket *sock)
60054 +{
60055 + return 0;
60056 +}
60057 +
60058 +int
60059 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60060 +{
60061 + return 0;
60062 +}
60063 +
60064 +__u32
60065 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60066 +{
60067 + return 1;
60068 +}
60069 +
60070 +__u32
60071 +gr_acl_handle_creat(const struct dentry * dentry,
60072 + const struct dentry * p_dentry,
60073 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60074 + const int imode)
60075 +{
60076 + return 1;
60077 +}
60078 +
60079 +void
60080 +gr_acl_handle_exit(void)
60081 +{
60082 + return;
60083 +}
60084 +
60085 +int
60086 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60087 +{
60088 + return 1;
60089 +}
60090 +
60091 +void
60092 +gr_set_role_label(const uid_t uid, const gid_t gid)
60093 +{
60094 + return;
60095 +}
60096 +
60097 +int
60098 +gr_acl_handle_procpidmem(const struct task_struct *task)
60099 +{
60100 + return 0;
60101 +}
60102 +
60103 +int
60104 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60105 +{
60106 + return 0;
60107 +}
60108 +
60109 +int
60110 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60111 +{
60112 + return 0;
60113 +}
60114 +
60115 +void
60116 +gr_set_kernel_label(struct task_struct *task)
60117 +{
60118 + return;
60119 +}
60120 +
60121 +int
60122 +gr_check_user_change(int real, int effective, int fs)
60123 +{
60124 + return 0;
60125 +}
60126 +
60127 +int
60128 +gr_check_group_change(int real, int effective, int fs)
60129 +{
60130 + return 0;
60131 +}
60132 +
60133 +int gr_acl_enable_at_secure(void)
60134 +{
60135 + return 0;
60136 +}
60137 +
60138 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60139 +{
60140 + return dentry->d_inode->i_sb->s_dev;
60141 +}
60142 +
60143 +void gr_put_exec_file(struct task_struct *task)
60144 +{
60145 + return;
60146 +}
60147 +
60148 +EXPORT_SYMBOL(gr_set_kernel_label);
60149 +#ifdef CONFIG_SECURITY
60150 +EXPORT_SYMBOL(gr_check_user_change);
60151 +EXPORT_SYMBOL(gr_check_group_change);
60152 +#endif
60153 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
60154 new file mode 100644
60155 index 0000000..abfa971
60156 --- /dev/null
60157 +++ b/grsecurity/grsec_exec.c
60158 @@ -0,0 +1,174 @@
60159 +#include <linux/kernel.h>
60160 +#include <linux/sched.h>
60161 +#include <linux/file.h>
60162 +#include <linux/binfmts.h>
60163 +#include <linux/fs.h>
60164 +#include <linux/types.h>
60165 +#include <linux/grdefs.h>
60166 +#include <linux/grsecurity.h>
60167 +#include <linux/grinternal.h>
60168 +#include <linux/capability.h>
60169 +#include <linux/module.h>
60170 +
60171 +#include <asm/uaccess.h>
60172 +
60173 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60174 +static char gr_exec_arg_buf[132];
60175 +static DEFINE_MUTEX(gr_exec_arg_mutex);
60176 +#endif
60177 +
60178 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
60179 +
60180 +void
60181 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
60182 +{
60183 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60184 + char *grarg = gr_exec_arg_buf;
60185 + unsigned int i, x, execlen = 0;
60186 + char c;
60187 +
60188 + if (!((grsec_enable_execlog && grsec_enable_group &&
60189 + in_group_p(grsec_audit_gid))
60190 + || (grsec_enable_execlog && !grsec_enable_group)))
60191 + return;
60192 +
60193 + mutex_lock(&gr_exec_arg_mutex);
60194 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
60195 +
60196 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
60197 + const char __user *p;
60198 + unsigned int len;
60199 +
60200 + p = get_user_arg_ptr(argv, i);
60201 + if (IS_ERR(p))
60202 + goto log;
60203 +
60204 + len = strnlen_user(p, 128 - execlen);
60205 + if (len > 128 - execlen)
60206 + len = 128 - execlen;
60207 + else if (len > 0)
60208 + len--;
60209 + if (copy_from_user(grarg + execlen, p, len))
60210 + goto log;
60211 +
60212 + /* rewrite unprintable characters */
60213 + for (x = 0; x < len; x++) {
60214 + c = *(grarg + execlen + x);
60215 + if (c < 32 || c > 126)
60216 + *(grarg + execlen + x) = ' ';
60217 + }
60218 +
60219 + execlen += len;
60220 + *(grarg + execlen) = ' ';
60221 + *(grarg + execlen + 1) = '\0';
60222 + execlen++;
60223 + }
60224 +
60225 + log:
60226 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
60227 + bprm->file->f_path.mnt, grarg);
60228 + mutex_unlock(&gr_exec_arg_mutex);
60229 +#endif
60230 + return;
60231 +}
60232 +
60233 +#ifdef CONFIG_GRKERNSEC
60234 +extern int gr_acl_is_capable(const int cap);
60235 +extern int gr_acl_is_capable_nolog(const int cap);
60236 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60237 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
60238 +extern int gr_chroot_is_capable(const int cap);
60239 +extern int gr_chroot_is_capable_nolog(const int cap);
60240 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60241 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
60242 +#endif
60243 +
60244 +const char *captab_log[] = {
60245 + "CAP_CHOWN",
60246 + "CAP_DAC_OVERRIDE",
60247 + "CAP_DAC_READ_SEARCH",
60248 + "CAP_FOWNER",
60249 + "CAP_FSETID",
60250 + "CAP_KILL",
60251 + "CAP_SETGID",
60252 + "CAP_SETUID",
60253 + "CAP_SETPCAP",
60254 + "CAP_LINUX_IMMUTABLE",
60255 + "CAP_NET_BIND_SERVICE",
60256 + "CAP_NET_BROADCAST",
60257 + "CAP_NET_ADMIN",
60258 + "CAP_NET_RAW",
60259 + "CAP_IPC_LOCK",
60260 + "CAP_IPC_OWNER",
60261 + "CAP_SYS_MODULE",
60262 + "CAP_SYS_RAWIO",
60263 + "CAP_SYS_CHROOT",
60264 + "CAP_SYS_PTRACE",
60265 + "CAP_SYS_PACCT",
60266 + "CAP_SYS_ADMIN",
60267 + "CAP_SYS_BOOT",
60268 + "CAP_SYS_NICE",
60269 + "CAP_SYS_RESOURCE",
60270 + "CAP_SYS_TIME",
60271 + "CAP_SYS_TTY_CONFIG",
60272 + "CAP_MKNOD",
60273 + "CAP_LEASE",
60274 + "CAP_AUDIT_WRITE",
60275 + "CAP_AUDIT_CONTROL",
60276 + "CAP_SETFCAP",
60277 + "CAP_MAC_OVERRIDE",
60278 + "CAP_MAC_ADMIN",
60279 + "CAP_SYSLOG",
60280 + "CAP_WAKE_ALARM"
60281 +};
60282 +
60283 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
60284 +
60285 +int gr_is_capable(const int cap)
60286 +{
60287 +#ifdef CONFIG_GRKERNSEC
60288 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
60289 + return 1;
60290 + return 0;
60291 +#else
60292 + return 1;
60293 +#endif
60294 +}
60295 +
60296 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60297 +{
60298 +#ifdef CONFIG_GRKERNSEC
60299 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
60300 + return 1;
60301 + return 0;
60302 +#else
60303 + return 1;
60304 +#endif
60305 +}
60306 +
60307 +int gr_is_capable_nolog(const int cap)
60308 +{
60309 +#ifdef CONFIG_GRKERNSEC
60310 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
60311 + return 1;
60312 + return 0;
60313 +#else
60314 + return 1;
60315 +#endif
60316 +}
60317 +
60318 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
60319 +{
60320 +#ifdef CONFIG_GRKERNSEC
60321 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
60322 + return 1;
60323 + return 0;
60324 +#else
60325 + return 1;
60326 +#endif
60327 +}
60328 +
60329 +EXPORT_SYMBOL(gr_is_capable);
60330 +EXPORT_SYMBOL(gr_is_capable_nolog);
60331 +EXPORT_SYMBOL(gr_task_is_capable);
60332 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
60333 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
60334 new file mode 100644
60335 index 0000000..d3ee748
60336 --- /dev/null
60337 +++ b/grsecurity/grsec_fifo.c
60338 @@ -0,0 +1,24 @@
60339 +#include <linux/kernel.h>
60340 +#include <linux/sched.h>
60341 +#include <linux/fs.h>
60342 +#include <linux/file.h>
60343 +#include <linux/grinternal.h>
60344 +
60345 +int
60346 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
60347 + const struct dentry *dir, const int flag, const int acc_mode)
60348 +{
60349 +#ifdef CONFIG_GRKERNSEC_FIFO
60350 + const struct cred *cred = current_cred();
60351 +
60352 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
60353 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
60354 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
60355 + (cred->fsuid != dentry->d_inode->i_uid)) {
60356 + if (!inode_permission(dentry->d_inode, acc_mode))
60357 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
60358 + return -EACCES;
60359 + }
60360 +#endif
60361 + return 0;
60362 +}
60363 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
60364 new file mode 100644
60365 index 0000000..8ca18bf
60366 --- /dev/null
60367 +++ b/grsecurity/grsec_fork.c
60368 @@ -0,0 +1,23 @@
60369 +#include <linux/kernel.h>
60370 +#include <linux/sched.h>
60371 +#include <linux/grsecurity.h>
60372 +#include <linux/grinternal.h>
60373 +#include <linux/errno.h>
60374 +
60375 +void
60376 +gr_log_forkfail(const int retval)
60377 +{
60378 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60379 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
60380 + switch (retval) {
60381 + case -EAGAIN:
60382 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
60383 + break;
60384 + case -ENOMEM:
60385 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
60386 + break;
60387 + }
60388 + }
60389 +#endif
60390 + return;
60391 +}
60392 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
60393 new file mode 100644
60394 index 0000000..05a6015
60395 --- /dev/null
60396 +++ b/grsecurity/grsec_init.c
60397 @@ -0,0 +1,283 @@
60398 +#include <linux/kernel.h>
60399 +#include <linux/sched.h>
60400 +#include <linux/mm.h>
60401 +#include <linux/gracl.h>
60402 +#include <linux/slab.h>
60403 +#include <linux/vmalloc.h>
60404 +#include <linux/percpu.h>
60405 +#include <linux/module.h>
60406 +
60407 +int grsec_enable_ptrace_readexec;
60408 +int grsec_enable_setxid;
60409 +int grsec_enable_symlinkown;
60410 +int grsec_symlinkown_gid;
60411 +int grsec_enable_brute;
60412 +int grsec_enable_link;
60413 +int grsec_enable_dmesg;
60414 +int grsec_enable_harden_ptrace;
60415 +int grsec_enable_fifo;
60416 +int grsec_enable_execlog;
60417 +int grsec_enable_signal;
60418 +int grsec_enable_forkfail;
60419 +int grsec_enable_audit_ptrace;
60420 +int grsec_enable_time;
60421 +int grsec_enable_audit_textrel;
60422 +int grsec_enable_group;
60423 +int grsec_audit_gid;
60424 +int grsec_enable_chdir;
60425 +int grsec_enable_mount;
60426 +int grsec_enable_rofs;
60427 +int grsec_enable_chroot_findtask;
60428 +int grsec_enable_chroot_mount;
60429 +int grsec_enable_chroot_shmat;
60430 +int grsec_enable_chroot_fchdir;
60431 +int grsec_enable_chroot_double;
60432 +int grsec_enable_chroot_pivot;
60433 +int grsec_enable_chroot_chdir;
60434 +int grsec_enable_chroot_chmod;
60435 +int grsec_enable_chroot_mknod;
60436 +int grsec_enable_chroot_nice;
60437 +int grsec_enable_chroot_execlog;
60438 +int grsec_enable_chroot_caps;
60439 +int grsec_enable_chroot_sysctl;
60440 +int grsec_enable_chroot_unix;
60441 +int grsec_enable_tpe;
60442 +int grsec_tpe_gid;
60443 +int grsec_enable_blackhole;
60444 +#ifdef CONFIG_IPV6_MODULE
60445 +EXPORT_SYMBOL(grsec_enable_blackhole);
60446 +#endif
60447 +int grsec_lastack_retries;
60448 +int grsec_enable_tpe_all;
60449 +int grsec_enable_tpe_invert;
60450 +int grsec_enable_socket_all;
60451 +int grsec_socket_all_gid;
60452 +int grsec_enable_socket_client;
60453 +int grsec_socket_client_gid;
60454 +int grsec_enable_socket_server;
60455 +int grsec_socket_server_gid;
60456 +int grsec_resource_logging;
60457 +int grsec_disable_privio;
60458 +int grsec_enable_log_rwxmaps;
60459 +int grsec_lock;
60460 +
60461 +DEFINE_SPINLOCK(grsec_alert_lock);
60462 +unsigned long grsec_alert_wtime = 0;
60463 +unsigned long grsec_alert_fyet = 0;
60464 +
60465 +DEFINE_SPINLOCK(grsec_audit_lock);
60466 +
60467 +DEFINE_RWLOCK(grsec_exec_file_lock);
60468 +
60469 +char *gr_shared_page[4];
60470 +
60471 +char *gr_alert_log_fmt;
60472 +char *gr_audit_log_fmt;
60473 +char *gr_alert_log_buf;
60474 +char *gr_audit_log_buf;
60475 +
60476 +extern struct gr_arg *gr_usermode;
60477 +extern unsigned char *gr_system_salt;
60478 +extern unsigned char *gr_system_sum;
60479 +
60480 +void __init
60481 +grsecurity_init(void)
60482 +{
60483 + int j;
60484 + /* create the per-cpu shared pages */
60485 +
60486 +#ifdef CONFIG_X86
60487 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60488 +#endif
60489 +
60490 + for (j = 0; j < 4; j++) {
60491 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60492 + if (gr_shared_page[j] == NULL) {
60493 + panic("Unable to allocate grsecurity shared page");
60494 + return;
60495 + }
60496 + }
60497 +
60498 + /* allocate log buffers */
60499 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60500 + if (!gr_alert_log_fmt) {
60501 + panic("Unable to allocate grsecurity alert log format buffer");
60502 + return;
60503 + }
60504 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60505 + if (!gr_audit_log_fmt) {
60506 + panic("Unable to allocate grsecurity audit log format buffer");
60507 + return;
60508 + }
60509 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60510 + if (!gr_alert_log_buf) {
60511 + panic("Unable to allocate grsecurity alert log buffer");
60512 + return;
60513 + }
60514 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60515 + if (!gr_audit_log_buf) {
60516 + panic("Unable to allocate grsecurity audit log buffer");
60517 + return;
60518 + }
60519 +
60520 + /* allocate memory for authentication structure */
60521 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60522 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60523 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60524 +
60525 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60526 + panic("Unable to allocate grsecurity authentication structure");
60527 + return;
60528 + }
60529 +
60530 +
60531 +#ifdef CONFIG_GRKERNSEC_IO
60532 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60533 + grsec_disable_privio = 1;
60534 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60535 + grsec_disable_privio = 1;
60536 +#else
60537 + grsec_disable_privio = 0;
60538 +#endif
60539 +#endif
60540 +
60541 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60542 + /* for backward compatibility, tpe_invert always defaults to on if
60543 + enabled in the kernel
60544 + */
60545 + grsec_enable_tpe_invert = 1;
60546 +#endif
60547 +
60548 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60549 +#ifndef CONFIG_GRKERNSEC_SYSCTL
60550 + grsec_lock = 1;
60551 +#endif
60552 +
60553 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60554 + grsec_enable_audit_textrel = 1;
60555 +#endif
60556 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60557 + grsec_enable_log_rwxmaps = 1;
60558 +#endif
60559 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60560 + grsec_enable_group = 1;
60561 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60562 +#endif
60563 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60564 + grsec_enable_ptrace_readexec = 1;
60565 +#endif
60566 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60567 + grsec_enable_chdir = 1;
60568 +#endif
60569 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60570 + grsec_enable_harden_ptrace = 1;
60571 +#endif
60572 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60573 + grsec_enable_mount = 1;
60574 +#endif
60575 +#ifdef CONFIG_GRKERNSEC_LINK
60576 + grsec_enable_link = 1;
60577 +#endif
60578 +#ifdef CONFIG_GRKERNSEC_BRUTE
60579 + grsec_enable_brute = 1;
60580 +#endif
60581 +#ifdef CONFIG_GRKERNSEC_DMESG
60582 + grsec_enable_dmesg = 1;
60583 +#endif
60584 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60585 + grsec_enable_blackhole = 1;
60586 + grsec_lastack_retries = 4;
60587 +#endif
60588 +#ifdef CONFIG_GRKERNSEC_FIFO
60589 + grsec_enable_fifo = 1;
60590 +#endif
60591 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60592 + grsec_enable_execlog = 1;
60593 +#endif
60594 +#ifdef CONFIG_GRKERNSEC_SETXID
60595 + grsec_enable_setxid = 1;
60596 +#endif
60597 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60598 + grsec_enable_signal = 1;
60599 +#endif
60600 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60601 + grsec_enable_forkfail = 1;
60602 +#endif
60603 +#ifdef CONFIG_GRKERNSEC_TIME
60604 + grsec_enable_time = 1;
60605 +#endif
60606 +#ifdef CONFIG_GRKERNSEC_RESLOG
60607 + grsec_resource_logging = 1;
60608 +#endif
60609 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60610 + grsec_enable_chroot_findtask = 1;
60611 +#endif
60612 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60613 + grsec_enable_chroot_unix = 1;
60614 +#endif
60615 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60616 + grsec_enable_chroot_mount = 1;
60617 +#endif
60618 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60619 + grsec_enable_chroot_fchdir = 1;
60620 +#endif
60621 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60622 + grsec_enable_chroot_shmat = 1;
60623 +#endif
60624 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60625 + grsec_enable_audit_ptrace = 1;
60626 +#endif
60627 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60628 + grsec_enable_chroot_double = 1;
60629 +#endif
60630 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60631 + grsec_enable_chroot_pivot = 1;
60632 +#endif
60633 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60634 + grsec_enable_chroot_chdir = 1;
60635 +#endif
60636 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60637 + grsec_enable_chroot_chmod = 1;
60638 +#endif
60639 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60640 + grsec_enable_chroot_mknod = 1;
60641 +#endif
60642 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60643 + grsec_enable_chroot_nice = 1;
60644 +#endif
60645 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60646 + grsec_enable_chroot_execlog = 1;
60647 +#endif
60648 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60649 + grsec_enable_chroot_caps = 1;
60650 +#endif
60651 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60652 + grsec_enable_chroot_sysctl = 1;
60653 +#endif
60654 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60655 + grsec_enable_symlinkown = 1;
60656 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60657 +#endif
60658 +#ifdef CONFIG_GRKERNSEC_TPE
60659 + grsec_enable_tpe = 1;
60660 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60661 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60662 + grsec_enable_tpe_all = 1;
60663 +#endif
60664 +#endif
60665 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60666 + grsec_enable_socket_all = 1;
60667 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60668 +#endif
60669 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60670 + grsec_enable_socket_client = 1;
60671 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60672 +#endif
60673 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60674 + grsec_enable_socket_server = 1;
60675 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60676 +#endif
60677 +#endif
60678 +
60679 + return;
60680 +}
60681 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60682 new file mode 100644
60683 index 0000000..6095407
60684 --- /dev/null
60685 +++ b/grsecurity/grsec_link.c
60686 @@ -0,0 +1,58 @@
60687 +#include <linux/kernel.h>
60688 +#include <linux/sched.h>
60689 +#include <linux/fs.h>
60690 +#include <linux/file.h>
60691 +#include <linux/grinternal.h>
60692 +
60693 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60694 +{
60695 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60696 + const struct inode *link_inode = link->dentry->d_inode;
60697 +
60698 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60699 + /* ignore root-owned links, e.g. /proc/self */
60700 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60701 + !uid_eq(link_inode->i_uid, target->i_uid)) {
60702 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60703 + return 1;
60704 + }
60705 +#endif
60706 + return 0;
60707 +}
60708 +
60709 +int
60710 +gr_handle_follow_link(const struct inode *parent,
60711 + const struct inode *inode,
60712 + const struct dentry *dentry, const struct vfsmount *mnt)
60713 +{
60714 +#ifdef CONFIG_GRKERNSEC_LINK
60715 + const struct cred *cred = current_cred();
60716 +
60717 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60718 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60719 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60720 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60721 + return -EACCES;
60722 + }
60723 +#endif
60724 + return 0;
60725 +}
60726 +
60727 +int
60728 +gr_handle_hardlink(const struct dentry *dentry,
60729 + const struct vfsmount *mnt,
60730 + struct inode *inode, const int mode, const struct filename *to)
60731 +{
60732 +#ifdef CONFIG_GRKERNSEC_LINK
60733 + const struct cred *cred = current_cred();
60734 +
60735 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60736 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60737 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60738 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60739 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60740 + return -EPERM;
60741 + }
60742 +#endif
60743 + return 0;
60744 +}
60745 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60746 new file mode 100644
60747 index 0000000..7bd6c2b
60748 --- /dev/null
60749 +++ b/grsecurity/grsec_log.c
60750 @@ -0,0 +1,329 @@
60751 +#include <linux/kernel.h>
60752 +#include <linux/sched.h>
60753 +#include <linux/file.h>
60754 +#include <linux/tty.h>
60755 +#include <linux/fs.h>
60756 +#include <linux/grinternal.h>
60757 +
60758 +#ifdef CONFIG_TREE_PREEMPT_RCU
60759 +#define DISABLE_PREEMPT() preempt_disable()
60760 +#define ENABLE_PREEMPT() preempt_enable()
60761 +#else
60762 +#define DISABLE_PREEMPT()
60763 +#define ENABLE_PREEMPT()
60764 +#endif
60765 +
60766 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
60767 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
60768 +
60769 +#define BEGIN_LOCKS(x) \
60770 + DISABLE_PREEMPT(); \
60771 + rcu_read_lock(); \
60772 + read_lock(&tasklist_lock); \
60773 + read_lock(&grsec_exec_file_lock); \
60774 + if (x != GR_DO_AUDIT) \
60775 + spin_lock(&grsec_alert_lock); \
60776 + else \
60777 + spin_lock(&grsec_audit_lock)
60778 +
60779 +#define END_LOCKS(x) \
60780 + if (x != GR_DO_AUDIT) \
60781 + spin_unlock(&grsec_alert_lock); \
60782 + else \
60783 + spin_unlock(&grsec_audit_lock); \
60784 + read_unlock(&grsec_exec_file_lock); \
60785 + read_unlock(&tasklist_lock); \
60786 + rcu_read_unlock(); \
60787 + ENABLE_PREEMPT(); \
60788 + if (x == GR_DONT_AUDIT) \
60789 + gr_handle_alertkill(current)
60790 +
60791 +enum {
60792 + FLOODING,
60793 + NO_FLOODING
60794 +};
60795 +
60796 +extern char *gr_alert_log_fmt;
60797 +extern char *gr_audit_log_fmt;
60798 +extern char *gr_alert_log_buf;
60799 +extern char *gr_audit_log_buf;
60800 +
60801 +static int gr_log_start(int audit)
60802 +{
60803 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60804 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60805 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60806 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60807 + unsigned long curr_secs = get_seconds();
60808 +
60809 + if (audit == GR_DO_AUDIT)
60810 + goto set_fmt;
60811 +
60812 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60813 + grsec_alert_wtime = curr_secs;
60814 + grsec_alert_fyet = 0;
60815 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60816 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60817 + grsec_alert_fyet++;
60818 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60819 + grsec_alert_wtime = curr_secs;
60820 + grsec_alert_fyet++;
60821 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60822 + return FLOODING;
60823 + }
60824 + else return FLOODING;
60825 +
60826 +set_fmt:
60827 +#endif
60828 + memset(buf, 0, PAGE_SIZE);
60829 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
60830 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60831 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60832 + } else if (current->signal->curr_ip) {
60833 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60834 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60835 + } else if (gr_acl_is_enabled()) {
60836 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60837 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60838 + } else {
60839 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
60840 + strcpy(buf, fmt);
60841 + }
60842 +
60843 + return NO_FLOODING;
60844 +}
60845 +
60846 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60847 + __attribute__ ((format (printf, 2, 0)));
60848 +
60849 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60850 +{
60851 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60852 + unsigned int len = strlen(buf);
60853 +
60854 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60855 +
60856 + return;
60857 +}
60858 +
60859 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60860 + __attribute__ ((format (printf, 2, 3)));
60861 +
60862 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60863 +{
60864 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60865 + unsigned int len = strlen(buf);
60866 + va_list ap;
60867 +
60868 + va_start(ap, msg);
60869 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60870 + va_end(ap);
60871 +
60872 + return;
60873 +}
60874 +
60875 +static void gr_log_end(int audit, int append_default)
60876 +{
60877 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60878 + if (append_default) {
60879 + struct task_struct *task = current;
60880 + struct task_struct *parent = task->real_parent;
60881 + const struct cred *cred = __task_cred(task);
60882 + const struct cred *pcred = __task_cred(parent);
60883 + unsigned int len = strlen(buf);
60884 +
60885 + 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));
60886 + }
60887 +
60888 + printk("%s\n", buf);
60889 +
60890 + return;
60891 +}
60892 +
60893 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60894 +{
60895 + int logtype;
60896 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60897 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60898 + void *voidptr = NULL;
60899 + int num1 = 0, num2 = 0;
60900 + unsigned long ulong1 = 0, ulong2 = 0;
60901 + struct dentry *dentry = NULL;
60902 + struct vfsmount *mnt = NULL;
60903 + struct file *file = NULL;
60904 + struct task_struct *task = NULL;
60905 + const struct cred *cred, *pcred;
60906 + va_list ap;
60907 +
60908 + BEGIN_LOCKS(audit);
60909 + logtype = gr_log_start(audit);
60910 + if (logtype == FLOODING) {
60911 + END_LOCKS(audit);
60912 + return;
60913 + }
60914 + va_start(ap, argtypes);
60915 + switch (argtypes) {
60916 + case GR_TTYSNIFF:
60917 + task = va_arg(ap, struct task_struct *);
60918 + 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));
60919 + break;
60920 + case GR_SYSCTL_HIDDEN:
60921 + str1 = va_arg(ap, char *);
60922 + gr_log_middle_varargs(audit, msg, result, str1);
60923 + break;
60924 + case GR_RBAC:
60925 + dentry = va_arg(ap, struct dentry *);
60926 + mnt = va_arg(ap, struct vfsmount *);
60927 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60928 + break;
60929 + case GR_RBAC_STR:
60930 + dentry = va_arg(ap, struct dentry *);
60931 + mnt = va_arg(ap, struct vfsmount *);
60932 + str1 = va_arg(ap, char *);
60933 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60934 + break;
60935 + case GR_STR_RBAC:
60936 + str1 = va_arg(ap, char *);
60937 + dentry = va_arg(ap, struct dentry *);
60938 + mnt = va_arg(ap, struct vfsmount *);
60939 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60940 + break;
60941 + case GR_RBAC_MODE2:
60942 + dentry = va_arg(ap, struct dentry *);
60943 + mnt = va_arg(ap, struct vfsmount *);
60944 + str1 = va_arg(ap, char *);
60945 + str2 = va_arg(ap, char *);
60946 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
60947 + break;
60948 + case GR_RBAC_MODE3:
60949 + dentry = va_arg(ap, struct dentry *);
60950 + mnt = va_arg(ap, struct vfsmount *);
60951 + str1 = va_arg(ap, char *);
60952 + str2 = va_arg(ap, char *);
60953 + str3 = va_arg(ap, char *);
60954 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
60955 + break;
60956 + case GR_FILENAME:
60957 + dentry = va_arg(ap, struct dentry *);
60958 + mnt = va_arg(ap, struct vfsmount *);
60959 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
60960 + break;
60961 + case GR_STR_FILENAME:
60962 + str1 = va_arg(ap, char *);
60963 + dentry = va_arg(ap, struct dentry *);
60964 + mnt = va_arg(ap, struct vfsmount *);
60965 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
60966 + break;
60967 + case GR_FILENAME_STR:
60968 + dentry = va_arg(ap, struct dentry *);
60969 + mnt = va_arg(ap, struct vfsmount *);
60970 + str1 = va_arg(ap, char *);
60971 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
60972 + break;
60973 + case GR_FILENAME_TWO_INT:
60974 + dentry = va_arg(ap, struct dentry *);
60975 + mnt = va_arg(ap, struct vfsmount *);
60976 + num1 = va_arg(ap, int);
60977 + num2 = va_arg(ap, int);
60978 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
60979 + break;
60980 + case GR_FILENAME_TWO_INT_STR:
60981 + dentry = va_arg(ap, struct dentry *);
60982 + mnt = va_arg(ap, struct vfsmount *);
60983 + num1 = va_arg(ap, int);
60984 + num2 = va_arg(ap, int);
60985 + str1 = va_arg(ap, char *);
60986 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
60987 + break;
60988 + case GR_TEXTREL:
60989 + file = va_arg(ap, struct file *);
60990 + ulong1 = va_arg(ap, unsigned long);
60991 + ulong2 = va_arg(ap, unsigned long);
60992 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
60993 + break;
60994 + case GR_PTRACE:
60995 + task = va_arg(ap, struct task_struct *);
60996 + 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));
60997 + break;
60998 + case GR_RESOURCE:
60999 + task = va_arg(ap, struct task_struct *);
61000 + cred = __task_cred(task);
61001 + pcred = __task_cred(task->real_parent);
61002 + ulong1 = va_arg(ap, unsigned long);
61003 + str1 = va_arg(ap, char *);
61004 + ulong2 = va_arg(ap, unsigned long);
61005 + 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));
61006 + break;
61007 + case GR_CAP:
61008 + task = va_arg(ap, struct task_struct *);
61009 + cred = __task_cred(task);
61010 + pcred = __task_cred(task->real_parent);
61011 + str1 = va_arg(ap, char *);
61012 + 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));
61013 + break;
61014 + case GR_SIG:
61015 + str1 = va_arg(ap, char *);
61016 + voidptr = va_arg(ap, void *);
61017 + gr_log_middle_varargs(audit, msg, str1, voidptr);
61018 + break;
61019 + case GR_SIG2:
61020 + task = va_arg(ap, struct task_struct *);
61021 + cred = __task_cred(task);
61022 + pcred = __task_cred(task->real_parent);
61023 + num1 = va_arg(ap, int);
61024 + 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));
61025 + break;
61026 + case GR_CRASH1:
61027 + task = va_arg(ap, struct task_struct *);
61028 + cred = __task_cred(task);
61029 + pcred = __task_cred(task->real_parent);
61030 + ulong1 = va_arg(ap, unsigned long);
61031 + 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);
61032 + break;
61033 + case GR_CRASH2:
61034 + task = va_arg(ap, struct task_struct *);
61035 + cred = __task_cred(task);
61036 + pcred = __task_cred(task->real_parent);
61037 + ulong1 = va_arg(ap, unsigned long);
61038 + 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);
61039 + break;
61040 + case GR_RWXMAP:
61041 + file = va_arg(ap, struct file *);
61042 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61043 + break;
61044 + case GR_PSACCT:
61045 + {
61046 + unsigned int wday, cday;
61047 + __u8 whr, chr;
61048 + __u8 wmin, cmin;
61049 + __u8 wsec, csec;
61050 + char cur_tty[64] = { 0 };
61051 + char parent_tty[64] = { 0 };
61052 +
61053 + task = va_arg(ap, struct task_struct *);
61054 + wday = va_arg(ap, unsigned int);
61055 + cday = va_arg(ap, unsigned int);
61056 + whr = va_arg(ap, int);
61057 + chr = va_arg(ap, int);
61058 + wmin = va_arg(ap, int);
61059 + cmin = va_arg(ap, int);
61060 + wsec = va_arg(ap, int);
61061 + csec = va_arg(ap, int);
61062 + ulong1 = va_arg(ap, unsigned long);
61063 + cred = __task_cred(task);
61064 + pcred = __task_cred(task->real_parent);
61065 +
61066 + 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));
61067 + }
61068 + break;
61069 + default:
61070 + gr_log_middle(audit, msg, ap);
61071 + }
61072 + va_end(ap);
61073 + // these don't need DEFAULTSECARGS printed on the end
61074 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61075 + gr_log_end(audit, 0);
61076 + else
61077 + gr_log_end(audit, 1);
61078 + END_LOCKS(audit);
61079 +}
61080 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61081 new file mode 100644
61082 index 0000000..f536303
61083 --- /dev/null
61084 +++ b/grsecurity/grsec_mem.c
61085 @@ -0,0 +1,40 @@
61086 +#include <linux/kernel.h>
61087 +#include <linux/sched.h>
61088 +#include <linux/mm.h>
61089 +#include <linux/mman.h>
61090 +#include <linux/grinternal.h>
61091 +
61092 +void
61093 +gr_handle_ioperm(void)
61094 +{
61095 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61096 + return;
61097 +}
61098 +
61099 +void
61100 +gr_handle_iopl(void)
61101 +{
61102 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61103 + return;
61104 +}
61105 +
61106 +void
61107 +gr_handle_mem_readwrite(u64 from, u64 to)
61108 +{
61109 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61110 + return;
61111 +}
61112 +
61113 +void
61114 +gr_handle_vm86(void)
61115 +{
61116 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61117 + return;
61118 +}
61119 +
61120 +void
61121 +gr_log_badprocpid(const char *entry)
61122 +{
61123 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61124 + return;
61125 +}
61126 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61127 new file mode 100644
61128 index 0000000..2131422
61129 --- /dev/null
61130 +++ b/grsecurity/grsec_mount.c
61131 @@ -0,0 +1,62 @@
61132 +#include <linux/kernel.h>
61133 +#include <linux/sched.h>
61134 +#include <linux/mount.h>
61135 +#include <linux/grsecurity.h>
61136 +#include <linux/grinternal.h>
61137 +
61138 +void
61139 +gr_log_remount(const char *devname, const int retval)
61140 +{
61141 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61142 + if (grsec_enable_mount && (retval >= 0))
61143 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
61144 +#endif
61145 + return;
61146 +}
61147 +
61148 +void
61149 +gr_log_unmount(const char *devname, const int retval)
61150 +{
61151 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61152 + if (grsec_enable_mount && (retval >= 0))
61153 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
61154 +#endif
61155 + return;
61156 +}
61157 +
61158 +void
61159 +gr_log_mount(const char *from, const char *to, const int retval)
61160 +{
61161 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61162 + if (grsec_enable_mount && (retval >= 0))
61163 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
61164 +#endif
61165 + return;
61166 +}
61167 +
61168 +int
61169 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
61170 +{
61171 +#ifdef CONFIG_GRKERNSEC_ROFS
61172 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
61173 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
61174 + return -EPERM;
61175 + } else
61176 + return 0;
61177 +#endif
61178 + return 0;
61179 +}
61180 +
61181 +int
61182 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
61183 +{
61184 +#ifdef CONFIG_GRKERNSEC_ROFS
61185 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
61186 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
61187 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
61188 + return -EPERM;
61189 + } else
61190 + return 0;
61191 +#endif
61192 + return 0;
61193 +}
61194 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
61195 new file mode 100644
61196 index 0000000..a3b12a0
61197 --- /dev/null
61198 +++ b/grsecurity/grsec_pax.c
61199 @@ -0,0 +1,36 @@
61200 +#include <linux/kernel.h>
61201 +#include <linux/sched.h>
61202 +#include <linux/mm.h>
61203 +#include <linux/file.h>
61204 +#include <linux/grinternal.h>
61205 +#include <linux/grsecurity.h>
61206 +
61207 +void
61208 +gr_log_textrel(struct vm_area_struct * vma)
61209 +{
61210 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61211 + if (grsec_enable_audit_textrel)
61212 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
61213 +#endif
61214 + return;
61215 +}
61216 +
61217 +void
61218 +gr_log_rwxmmap(struct file *file)
61219 +{
61220 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61221 + if (grsec_enable_log_rwxmaps)
61222 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
61223 +#endif
61224 + return;
61225 +}
61226 +
61227 +void
61228 +gr_log_rwxmprotect(struct file *file)
61229 +{
61230 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61231 + if (grsec_enable_log_rwxmaps)
61232 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
61233 +#endif
61234 + return;
61235 +}
61236 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
61237 new file mode 100644
61238 index 0000000..f7f29aa
61239 --- /dev/null
61240 +++ b/grsecurity/grsec_ptrace.c
61241 @@ -0,0 +1,30 @@
61242 +#include <linux/kernel.h>
61243 +#include <linux/sched.h>
61244 +#include <linux/grinternal.h>
61245 +#include <linux/security.h>
61246 +
61247 +void
61248 +gr_audit_ptrace(struct task_struct *task)
61249 +{
61250 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61251 + if (grsec_enable_audit_ptrace)
61252 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
61253 +#endif
61254 + return;
61255 +}
61256 +
61257 +int
61258 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
61259 +{
61260 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61261 + const struct dentry *dentry = file->f_path.dentry;
61262 + const struct vfsmount *mnt = file->f_path.mnt;
61263 +
61264 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
61265 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
61266 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
61267 + return -EACCES;
61268 + }
61269 +#endif
61270 + return 0;
61271 +}
61272 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
61273 new file mode 100644
61274 index 0000000..5c00416
61275 --- /dev/null
61276 +++ b/grsecurity/grsec_sig.c
61277 @@ -0,0 +1,222 @@
61278 +#include <linux/kernel.h>
61279 +#include <linux/sched.h>
61280 +#include <linux/delay.h>
61281 +#include <linux/grsecurity.h>
61282 +#include <linux/grinternal.h>
61283 +#include <linux/hardirq.h>
61284 +
61285 +char *signames[] = {
61286 + [SIGSEGV] = "Segmentation fault",
61287 + [SIGILL] = "Illegal instruction",
61288 + [SIGABRT] = "Abort",
61289 + [SIGBUS] = "Invalid alignment/Bus error"
61290 +};
61291 +
61292 +void
61293 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
61294 +{
61295 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61296 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
61297 + (sig == SIGABRT) || (sig == SIGBUS))) {
61298 + if (t->pid == current->pid) {
61299 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
61300 + } else {
61301 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
61302 + }
61303 + }
61304 +#endif
61305 + return;
61306 +}
61307 +
61308 +int
61309 +gr_handle_signal(const struct task_struct *p, const int sig)
61310 +{
61311 +#ifdef CONFIG_GRKERNSEC
61312 + /* ignore the 0 signal for protected task checks */
61313 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
61314 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
61315 + return -EPERM;
61316 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
61317 + return -EPERM;
61318 + }
61319 +#endif
61320 + return 0;
61321 +}
61322 +
61323 +#ifdef CONFIG_GRKERNSEC
61324 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
61325 +
61326 +int gr_fake_force_sig(int sig, struct task_struct *t)
61327 +{
61328 + unsigned long int flags;
61329 + int ret, blocked, ignored;
61330 + struct k_sigaction *action;
61331 +
61332 + spin_lock_irqsave(&t->sighand->siglock, flags);
61333 + action = &t->sighand->action[sig-1];
61334 + ignored = action->sa.sa_handler == SIG_IGN;
61335 + blocked = sigismember(&t->blocked, sig);
61336 + if (blocked || ignored) {
61337 + action->sa.sa_handler = SIG_DFL;
61338 + if (blocked) {
61339 + sigdelset(&t->blocked, sig);
61340 + recalc_sigpending_and_wake(t);
61341 + }
61342 + }
61343 + if (action->sa.sa_handler == SIG_DFL)
61344 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
61345 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
61346 +
61347 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
61348 +
61349 + return ret;
61350 +}
61351 +#endif
61352 +
61353 +#ifdef CONFIG_GRKERNSEC_BRUTE
61354 +#define GR_USER_BAN_TIME (15 * 60)
61355 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
61356 +
61357 +static int __get_dumpable(unsigned long mm_flags)
61358 +{
61359 + int ret;
61360 +
61361 + ret = mm_flags & MMF_DUMPABLE_MASK;
61362 + return (ret >= 2) ? 2 : ret;
61363 +}
61364 +#endif
61365 +
61366 +void gr_handle_brute_attach(unsigned long mm_flags)
61367 +{
61368 +#ifdef CONFIG_GRKERNSEC_BRUTE
61369 + struct task_struct *p = current;
61370 + kuid_t uid = GLOBAL_ROOT_UID;
61371 + int daemon = 0;
61372 +
61373 + if (!grsec_enable_brute)
61374 + return;
61375 +
61376 + rcu_read_lock();
61377 + read_lock(&tasklist_lock);
61378 + read_lock(&grsec_exec_file_lock);
61379 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
61380 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
61381 + p->real_parent->brute = 1;
61382 + daemon = 1;
61383 + } else {
61384 + const struct cred *cred = __task_cred(p), *cred2;
61385 + struct task_struct *tsk, *tsk2;
61386 +
61387 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61388 + struct user_struct *user;
61389 +
61390 + uid = cred->uid;
61391 +
61392 + /* this is put upon execution past expiration */
61393 + user = find_user(uid);
61394 + if (user == NULL)
61395 + goto unlock;
61396 + user->banned = 1;
61397 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
61398 + if (user->ban_expires == ~0UL)
61399 + user->ban_expires--;
61400 +
61401 + do_each_thread(tsk2, tsk) {
61402 + cred2 = __task_cred(tsk);
61403 + if (tsk != p && uid_eq(cred2->uid, uid))
61404 + gr_fake_force_sig(SIGKILL, tsk);
61405 + } while_each_thread(tsk2, tsk);
61406 + }
61407 + }
61408 +unlock:
61409 + read_unlock(&grsec_exec_file_lock);
61410 + read_unlock(&tasklist_lock);
61411 + rcu_read_unlock();
61412 +
61413 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
61414 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
61415 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
61416 + else if (daemon)
61417 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
61418 +
61419 +#endif
61420 + return;
61421 +}
61422 +
61423 +void gr_handle_brute_check(void)
61424 +{
61425 +#ifdef CONFIG_GRKERNSEC_BRUTE
61426 + struct task_struct *p = current;
61427 +
61428 + if (unlikely(p->brute)) {
61429 + if (!grsec_enable_brute)
61430 + p->brute = 0;
61431 + else if (time_before(get_seconds(), p->brute_expires))
61432 + msleep(30 * 1000);
61433 + }
61434 +#endif
61435 + return;
61436 +}
61437 +
61438 +void gr_handle_kernel_exploit(void)
61439 +{
61440 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61441 + const struct cred *cred;
61442 + struct task_struct *tsk, *tsk2;
61443 + struct user_struct *user;
61444 + kuid_t uid;
61445 +
61446 + if (in_irq() || in_serving_softirq() || in_nmi())
61447 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61448 +
61449 + uid = current_uid();
61450 +
61451 + if (uid_eq(uid, GLOBAL_ROOT_UID))
61452 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
61453 + else {
61454 + /* kill all the processes of this user, hold a reference
61455 + to their creds struct, and prevent them from creating
61456 + another process until system reset
61457 + */
61458 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61459 + from_kuid_munged(&init_user_ns, uid));
61460 + /* we intentionally leak this ref */
61461 + user = get_uid(current->cred->user);
61462 + if (user) {
61463 + user->banned = 1;
61464 + user->ban_expires = ~0UL;
61465 + }
61466 +
61467 + read_lock(&tasklist_lock);
61468 + do_each_thread(tsk2, tsk) {
61469 + cred = __task_cred(tsk);
61470 + if (uid_eq(cred->uid, uid))
61471 + gr_fake_force_sig(SIGKILL, tsk);
61472 + } while_each_thread(tsk2, tsk);
61473 + read_unlock(&tasklist_lock);
61474 + }
61475 +#endif
61476 +}
61477 +
61478 +int __gr_process_user_ban(struct user_struct *user)
61479 +{
61480 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61481 + if (unlikely(user->banned)) {
61482 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61483 + user->banned = 0;
61484 + user->ban_expires = 0;
61485 + free_uid(user);
61486 + } else
61487 + return -EPERM;
61488 + }
61489 +#endif
61490 + return 0;
61491 +}
61492 +
61493 +int gr_process_user_ban(void)
61494 +{
61495 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61496 + return __gr_process_user_ban(current->cred->user);
61497 +#endif
61498 + return 0;
61499 +}
61500 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61501 new file mode 100644
61502 index 0000000..4030d57
61503 --- /dev/null
61504 +++ b/grsecurity/grsec_sock.c
61505 @@ -0,0 +1,244 @@
61506 +#include <linux/kernel.h>
61507 +#include <linux/module.h>
61508 +#include <linux/sched.h>
61509 +#include <linux/file.h>
61510 +#include <linux/net.h>
61511 +#include <linux/in.h>
61512 +#include <linux/ip.h>
61513 +#include <net/sock.h>
61514 +#include <net/inet_sock.h>
61515 +#include <linux/grsecurity.h>
61516 +#include <linux/grinternal.h>
61517 +#include <linux/gracl.h>
61518 +
61519 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61520 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61521 +
61522 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
61523 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
61524 +
61525 +#ifdef CONFIG_UNIX_MODULE
61526 +EXPORT_SYMBOL(gr_acl_handle_unix);
61527 +EXPORT_SYMBOL(gr_acl_handle_mknod);
61528 +EXPORT_SYMBOL(gr_handle_chroot_unix);
61529 +EXPORT_SYMBOL(gr_handle_create);
61530 +#endif
61531 +
61532 +#ifdef CONFIG_GRKERNSEC
61533 +#define gr_conn_table_size 32749
61534 +struct conn_table_entry {
61535 + struct conn_table_entry *next;
61536 + struct signal_struct *sig;
61537 +};
61538 +
61539 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61540 +DEFINE_SPINLOCK(gr_conn_table_lock);
61541 +
61542 +extern const char * gr_socktype_to_name(unsigned char type);
61543 +extern const char * gr_proto_to_name(unsigned char proto);
61544 +extern const char * gr_sockfamily_to_name(unsigned char family);
61545 +
61546 +static __inline__ int
61547 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61548 +{
61549 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61550 +}
61551 +
61552 +static __inline__ int
61553 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61554 + __u16 sport, __u16 dport)
61555 +{
61556 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61557 + sig->gr_sport == sport && sig->gr_dport == dport))
61558 + return 1;
61559 + else
61560 + return 0;
61561 +}
61562 +
61563 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61564 +{
61565 + struct conn_table_entry **match;
61566 + unsigned int index;
61567 +
61568 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61569 + sig->gr_sport, sig->gr_dport,
61570 + gr_conn_table_size);
61571 +
61572 + newent->sig = sig;
61573 +
61574 + match = &gr_conn_table[index];
61575 + newent->next = *match;
61576 + *match = newent;
61577 +
61578 + return;
61579 +}
61580 +
61581 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61582 +{
61583 + struct conn_table_entry *match, *last = NULL;
61584 + unsigned int index;
61585 +
61586 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61587 + sig->gr_sport, sig->gr_dport,
61588 + gr_conn_table_size);
61589 +
61590 + match = gr_conn_table[index];
61591 + while (match && !conn_match(match->sig,
61592 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61593 + sig->gr_dport)) {
61594 + last = match;
61595 + match = match->next;
61596 + }
61597 +
61598 + if (match) {
61599 + if (last)
61600 + last->next = match->next;
61601 + else
61602 + gr_conn_table[index] = NULL;
61603 + kfree(match);
61604 + }
61605 +
61606 + return;
61607 +}
61608 +
61609 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61610 + __u16 sport, __u16 dport)
61611 +{
61612 + struct conn_table_entry *match;
61613 + unsigned int index;
61614 +
61615 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61616 +
61617 + match = gr_conn_table[index];
61618 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61619 + match = match->next;
61620 +
61621 + if (match)
61622 + return match->sig;
61623 + else
61624 + return NULL;
61625 +}
61626 +
61627 +#endif
61628 +
61629 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61630 +{
61631 +#ifdef CONFIG_GRKERNSEC
61632 + struct signal_struct *sig = task->signal;
61633 + struct conn_table_entry *newent;
61634 +
61635 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61636 + if (newent == NULL)
61637 + return;
61638 + /* no bh lock needed since we are called with bh disabled */
61639 + spin_lock(&gr_conn_table_lock);
61640 + gr_del_task_from_ip_table_nolock(sig);
61641 + sig->gr_saddr = inet->inet_rcv_saddr;
61642 + sig->gr_daddr = inet->inet_daddr;
61643 + sig->gr_sport = inet->inet_sport;
61644 + sig->gr_dport = inet->inet_dport;
61645 + gr_add_to_task_ip_table_nolock(sig, newent);
61646 + spin_unlock(&gr_conn_table_lock);
61647 +#endif
61648 + return;
61649 +}
61650 +
61651 +void gr_del_task_from_ip_table(struct task_struct *task)
61652 +{
61653 +#ifdef CONFIG_GRKERNSEC
61654 + spin_lock_bh(&gr_conn_table_lock);
61655 + gr_del_task_from_ip_table_nolock(task->signal);
61656 + spin_unlock_bh(&gr_conn_table_lock);
61657 +#endif
61658 + return;
61659 +}
61660 +
61661 +void
61662 +gr_attach_curr_ip(const struct sock *sk)
61663 +{
61664 +#ifdef CONFIG_GRKERNSEC
61665 + struct signal_struct *p, *set;
61666 + const struct inet_sock *inet = inet_sk(sk);
61667 +
61668 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61669 + return;
61670 +
61671 + set = current->signal;
61672 +
61673 + spin_lock_bh(&gr_conn_table_lock);
61674 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61675 + inet->inet_dport, inet->inet_sport);
61676 + if (unlikely(p != NULL)) {
61677 + set->curr_ip = p->curr_ip;
61678 + set->used_accept = 1;
61679 + gr_del_task_from_ip_table_nolock(p);
61680 + spin_unlock_bh(&gr_conn_table_lock);
61681 + return;
61682 + }
61683 + spin_unlock_bh(&gr_conn_table_lock);
61684 +
61685 + set->curr_ip = inet->inet_daddr;
61686 + set->used_accept = 1;
61687 +#endif
61688 + return;
61689 +}
61690 +
61691 +int
61692 +gr_handle_sock_all(const int family, const int type, const int protocol)
61693 +{
61694 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61695 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61696 + (family != AF_UNIX)) {
61697 + if (family == AF_INET)
61698 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61699 + else
61700 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61701 + return -EACCES;
61702 + }
61703 +#endif
61704 + return 0;
61705 +}
61706 +
61707 +int
61708 +gr_handle_sock_server(const struct sockaddr *sck)
61709 +{
61710 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61711 + if (grsec_enable_socket_server &&
61712 + in_group_p(grsec_socket_server_gid) &&
61713 + sck && (sck->sa_family != AF_UNIX) &&
61714 + (sck->sa_family != AF_LOCAL)) {
61715 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61716 + return -EACCES;
61717 + }
61718 +#endif
61719 + return 0;
61720 +}
61721 +
61722 +int
61723 +gr_handle_sock_server_other(const struct sock *sck)
61724 +{
61725 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61726 + if (grsec_enable_socket_server &&
61727 + in_group_p(grsec_socket_server_gid) &&
61728 + sck && (sck->sk_family != AF_UNIX) &&
61729 + (sck->sk_family != AF_LOCAL)) {
61730 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61731 + return -EACCES;
61732 + }
61733 +#endif
61734 + return 0;
61735 +}
61736 +
61737 +int
61738 +gr_handle_sock_client(const struct sockaddr *sck)
61739 +{
61740 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61741 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61742 + sck && (sck->sa_family != AF_UNIX) &&
61743 + (sck->sa_family != AF_LOCAL)) {
61744 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61745 + return -EACCES;
61746 + }
61747 +#endif
61748 + return 0;
61749 +}
61750 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61751 new file mode 100644
61752 index 0000000..f55ef0f
61753 --- /dev/null
61754 +++ b/grsecurity/grsec_sysctl.c
61755 @@ -0,0 +1,469 @@
61756 +#include <linux/kernel.h>
61757 +#include <linux/sched.h>
61758 +#include <linux/sysctl.h>
61759 +#include <linux/grsecurity.h>
61760 +#include <linux/grinternal.h>
61761 +
61762 +int
61763 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61764 +{
61765 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61766 + if (dirname == NULL || name == NULL)
61767 + return 0;
61768 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61769 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61770 + return -EACCES;
61771 + }
61772 +#endif
61773 + return 0;
61774 +}
61775 +
61776 +#ifdef CONFIG_GRKERNSEC_ROFS
61777 +static int __maybe_unused one = 1;
61778 +#endif
61779 +
61780 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61781 +struct ctl_table grsecurity_table[] = {
61782 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61783 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61784 +#ifdef CONFIG_GRKERNSEC_IO
61785 + {
61786 + .procname = "disable_priv_io",
61787 + .data = &grsec_disable_privio,
61788 + .maxlen = sizeof(int),
61789 + .mode = 0600,
61790 + .proc_handler = &proc_dointvec,
61791 + },
61792 +#endif
61793 +#endif
61794 +#ifdef CONFIG_GRKERNSEC_LINK
61795 + {
61796 + .procname = "linking_restrictions",
61797 + .data = &grsec_enable_link,
61798 + .maxlen = sizeof(int),
61799 + .mode = 0600,
61800 + .proc_handler = &proc_dointvec,
61801 + },
61802 +#endif
61803 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61804 + {
61805 + .procname = "enforce_symlinksifowner",
61806 + .data = &grsec_enable_symlinkown,
61807 + .maxlen = sizeof(int),
61808 + .mode = 0600,
61809 + .proc_handler = &proc_dointvec,
61810 + },
61811 + {
61812 + .procname = "symlinkown_gid",
61813 + .data = &grsec_symlinkown_gid,
61814 + .maxlen = sizeof(int),
61815 + .mode = 0600,
61816 + .proc_handler = &proc_dointvec,
61817 + },
61818 +#endif
61819 +#ifdef CONFIG_GRKERNSEC_BRUTE
61820 + {
61821 + .procname = "deter_bruteforce",
61822 + .data = &grsec_enable_brute,
61823 + .maxlen = sizeof(int),
61824 + .mode = 0600,
61825 + .proc_handler = &proc_dointvec,
61826 + },
61827 +#endif
61828 +#ifdef CONFIG_GRKERNSEC_FIFO
61829 + {
61830 + .procname = "fifo_restrictions",
61831 + .data = &grsec_enable_fifo,
61832 + .maxlen = sizeof(int),
61833 + .mode = 0600,
61834 + .proc_handler = &proc_dointvec,
61835 + },
61836 +#endif
61837 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61838 + {
61839 + .procname = "ptrace_readexec",
61840 + .data = &grsec_enable_ptrace_readexec,
61841 + .maxlen = sizeof(int),
61842 + .mode = 0600,
61843 + .proc_handler = &proc_dointvec,
61844 + },
61845 +#endif
61846 +#ifdef CONFIG_GRKERNSEC_SETXID
61847 + {
61848 + .procname = "consistent_setxid",
61849 + .data = &grsec_enable_setxid,
61850 + .maxlen = sizeof(int),
61851 + .mode = 0600,
61852 + .proc_handler = &proc_dointvec,
61853 + },
61854 +#endif
61855 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61856 + {
61857 + .procname = "ip_blackhole",
61858 + .data = &grsec_enable_blackhole,
61859 + .maxlen = sizeof(int),
61860 + .mode = 0600,
61861 + .proc_handler = &proc_dointvec,
61862 + },
61863 + {
61864 + .procname = "lastack_retries",
61865 + .data = &grsec_lastack_retries,
61866 + .maxlen = sizeof(int),
61867 + .mode = 0600,
61868 + .proc_handler = &proc_dointvec,
61869 + },
61870 +#endif
61871 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61872 + {
61873 + .procname = "exec_logging",
61874 + .data = &grsec_enable_execlog,
61875 + .maxlen = sizeof(int),
61876 + .mode = 0600,
61877 + .proc_handler = &proc_dointvec,
61878 + },
61879 +#endif
61880 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61881 + {
61882 + .procname = "rwxmap_logging",
61883 + .data = &grsec_enable_log_rwxmaps,
61884 + .maxlen = sizeof(int),
61885 + .mode = 0600,
61886 + .proc_handler = &proc_dointvec,
61887 + },
61888 +#endif
61889 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61890 + {
61891 + .procname = "signal_logging",
61892 + .data = &grsec_enable_signal,
61893 + .maxlen = sizeof(int),
61894 + .mode = 0600,
61895 + .proc_handler = &proc_dointvec,
61896 + },
61897 +#endif
61898 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61899 + {
61900 + .procname = "forkfail_logging",
61901 + .data = &grsec_enable_forkfail,
61902 + .maxlen = sizeof(int),
61903 + .mode = 0600,
61904 + .proc_handler = &proc_dointvec,
61905 + },
61906 +#endif
61907 +#ifdef CONFIG_GRKERNSEC_TIME
61908 + {
61909 + .procname = "timechange_logging",
61910 + .data = &grsec_enable_time,
61911 + .maxlen = sizeof(int),
61912 + .mode = 0600,
61913 + .proc_handler = &proc_dointvec,
61914 + },
61915 +#endif
61916 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61917 + {
61918 + .procname = "chroot_deny_shmat",
61919 + .data = &grsec_enable_chroot_shmat,
61920 + .maxlen = sizeof(int),
61921 + .mode = 0600,
61922 + .proc_handler = &proc_dointvec,
61923 + },
61924 +#endif
61925 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61926 + {
61927 + .procname = "chroot_deny_unix",
61928 + .data = &grsec_enable_chroot_unix,
61929 + .maxlen = sizeof(int),
61930 + .mode = 0600,
61931 + .proc_handler = &proc_dointvec,
61932 + },
61933 +#endif
61934 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61935 + {
61936 + .procname = "chroot_deny_mount",
61937 + .data = &grsec_enable_chroot_mount,
61938 + .maxlen = sizeof(int),
61939 + .mode = 0600,
61940 + .proc_handler = &proc_dointvec,
61941 + },
61942 +#endif
61943 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61944 + {
61945 + .procname = "chroot_deny_fchdir",
61946 + .data = &grsec_enable_chroot_fchdir,
61947 + .maxlen = sizeof(int),
61948 + .mode = 0600,
61949 + .proc_handler = &proc_dointvec,
61950 + },
61951 +#endif
61952 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61953 + {
61954 + .procname = "chroot_deny_chroot",
61955 + .data = &grsec_enable_chroot_double,
61956 + .maxlen = sizeof(int),
61957 + .mode = 0600,
61958 + .proc_handler = &proc_dointvec,
61959 + },
61960 +#endif
61961 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61962 + {
61963 + .procname = "chroot_deny_pivot",
61964 + .data = &grsec_enable_chroot_pivot,
61965 + .maxlen = sizeof(int),
61966 + .mode = 0600,
61967 + .proc_handler = &proc_dointvec,
61968 + },
61969 +#endif
61970 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61971 + {
61972 + .procname = "chroot_enforce_chdir",
61973 + .data = &grsec_enable_chroot_chdir,
61974 + .maxlen = sizeof(int),
61975 + .mode = 0600,
61976 + .proc_handler = &proc_dointvec,
61977 + },
61978 +#endif
61979 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61980 + {
61981 + .procname = "chroot_deny_chmod",
61982 + .data = &grsec_enable_chroot_chmod,
61983 + .maxlen = sizeof(int),
61984 + .mode = 0600,
61985 + .proc_handler = &proc_dointvec,
61986 + },
61987 +#endif
61988 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61989 + {
61990 + .procname = "chroot_deny_mknod",
61991 + .data = &grsec_enable_chroot_mknod,
61992 + .maxlen = sizeof(int),
61993 + .mode = 0600,
61994 + .proc_handler = &proc_dointvec,
61995 + },
61996 +#endif
61997 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61998 + {
61999 + .procname = "chroot_restrict_nice",
62000 + .data = &grsec_enable_chroot_nice,
62001 + .maxlen = sizeof(int),
62002 + .mode = 0600,
62003 + .proc_handler = &proc_dointvec,
62004 + },
62005 +#endif
62006 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62007 + {
62008 + .procname = "chroot_execlog",
62009 + .data = &grsec_enable_chroot_execlog,
62010 + .maxlen = sizeof(int),
62011 + .mode = 0600,
62012 + .proc_handler = &proc_dointvec,
62013 + },
62014 +#endif
62015 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62016 + {
62017 + .procname = "chroot_caps",
62018 + .data = &grsec_enable_chroot_caps,
62019 + .maxlen = sizeof(int),
62020 + .mode = 0600,
62021 + .proc_handler = &proc_dointvec,
62022 + },
62023 +#endif
62024 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62025 + {
62026 + .procname = "chroot_deny_sysctl",
62027 + .data = &grsec_enable_chroot_sysctl,
62028 + .maxlen = sizeof(int),
62029 + .mode = 0600,
62030 + .proc_handler = &proc_dointvec,
62031 + },
62032 +#endif
62033 +#ifdef CONFIG_GRKERNSEC_TPE
62034 + {
62035 + .procname = "tpe",
62036 + .data = &grsec_enable_tpe,
62037 + .maxlen = sizeof(int),
62038 + .mode = 0600,
62039 + .proc_handler = &proc_dointvec,
62040 + },
62041 + {
62042 + .procname = "tpe_gid",
62043 + .data = &grsec_tpe_gid,
62044 + .maxlen = sizeof(int),
62045 + .mode = 0600,
62046 + .proc_handler = &proc_dointvec,
62047 + },
62048 +#endif
62049 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62050 + {
62051 + .procname = "tpe_invert",
62052 + .data = &grsec_enable_tpe_invert,
62053 + .maxlen = sizeof(int),
62054 + .mode = 0600,
62055 + .proc_handler = &proc_dointvec,
62056 + },
62057 +#endif
62058 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62059 + {
62060 + .procname = "tpe_restrict_all",
62061 + .data = &grsec_enable_tpe_all,
62062 + .maxlen = sizeof(int),
62063 + .mode = 0600,
62064 + .proc_handler = &proc_dointvec,
62065 + },
62066 +#endif
62067 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62068 + {
62069 + .procname = "socket_all",
62070 + .data = &grsec_enable_socket_all,
62071 + .maxlen = sizeof(int),
62072 + .mode = 0600,
62073 + .proc_handler = &proc_dointvec,
62074 + },
62075 + {
62076 + .procname = "socket_all_gid",
62077 + .data = &grsec_socket_all_gid,
62078 + .maxlen = sizeof(int),
62079 + .mode = 0600,
62080 + .proc_handler = &proc_dointvec,
62081 + },
62082 +#endif
62083 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62084 + {
62085 + .procname = "socket_client",
62086 + .data = &grsec_enable_socket_client,
62087 + .maxlen = sizeof(int),
62088 + .mode = 0600,
62089 + .proc_handler = &proc_dointvec,
62090 + },
62091 + {
62092 + .procname = "socket_client_gid",
62093 + .data = &grsec_socket_client_gid,
62094 + .maxlen = sizeof(int),
62095 + .mode = 0600,
62096 + .proc_handler = &proc_dointvec,
62097 + },
62098 +#endif
62099 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62100 + {
62101 + .procname = "socket_server",
62102 + .data = &grsec_enable_socket_server,
62103 + .maxlen = sizeof(int),
62104 + .mode = 0600,
62105 + .proc_handler = &proc_dointvec,
62106 + },
62107 + {
62108 + .procname = "socket_server_gid",
62109 + .data = &grsec_socket_server_gid,
62110 + .maxlen = sizeof(int),
62111 + .mode = 0600,
62112 + .proc_handler = &proc_dointvec,
62113 + },
62114 +#endif
62115 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62116 + {
62117 + .procname = "audit_group",
62118 + .data = &grsec_enable_group,
62119 + .maxlen = sizeof(int),
62120 + .mode = 0600,
62121 + .proc_handler = &proc_dointvec,
62122 + },
62123 + {
62124 + .procname = "audit_gid",
62125 + .data = &grsec_audit_gid,
62126 + .maxlen = sizeof(int),
62127 + .mode = 0600,
62128 + .proc_handler = &proc_dointvec,
62129 + },
62130 +#endif
62131 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62132 + {
62133 + .procname = "audit_chdir",
62134 + .data = &grsec_enable_chdir,
62135 + .maxlen = sizeof(int),
62136 + .mode = 0600,
62137 + .proc_handler = &proc_dointvec,
62138 + },
62139 +#endif
62140 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62141 + {
62142 + .procname = "audit_mount",
62143 + .data = &grsec_enable_mount,
62144 + .maxlen = sizeof(int),
62145 + .mode = 0600,
62146 + .proc_handler = &proc_dointvec,
62147 + },
62148 +#endif
62149 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62150 + {
62151 + .procname = "audit_textrel",
62152 + .data = &grsec_enable_audit_textrel,
62153 + .maxlen = sizeof(int),
62154 + .mode = 0600,
62155 + .proc_handler = &proc_dointvec,
62156 + },
62157 +#endif
62158 +#ifdef CONFIG_GRKERNSEC_DMESG
62159 + {
62160 + .procname = "dmesg",
62161 + .data = &grsec_enable_dmesg,
62162 + .maxlen = sizeof(int),
62163 + .mode = 0600,
62164 + .proc_handler = &proc_dointvec,
62165 + },
62166 +#endif
62167 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62168 + {
62169 + .procname = "chroot_findtask",
62170 + .data = &grsec_enable_chroot_findtask,
62171 + .maxlen = sizeof(int),
62172 + .mode = 0600,
62173 + .proc_handler = &proc_dointvec,
62174 + },
62175 +#endif
62176 +#ifdef CONFIG_GRKERNSEC_RESLOG
62177 + {
62178 + .procname = "resource_logging",
62179 + .data = &grsec_resource_logging,
62180 + .maxlen = sizeof(int),
62181 + .mode = 0600,
62182 + .proc_handler = &proc_dointvec,
62183 + },
62184 +#endif
62185 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62186 + {
62187 + .procname = "audit_ptrace",
62188 + .data = &grsec_enable_audit_ptrace,
62189 + .maxlen = sizeof(int),
62190 + .mode = 0600,
62191 + .proc_handler = &proc_dointvec,
62192 + },
62193 +#endif
62194 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62195 + {
62196 + .procname = "harden_ptrace",
62197 + .data = &grsec_enable_harden_ptrace,
62198 + .maxlen = sizeof(int),
62199 + .mode = 0600,
62200 + .proc_handler = &proc_dointvec,
62201 + },
62202 +#endif
62203 + {
62204 + .procname = "grsec_lock",
62205 + .data = &grsec_lock,
62206 + .maxlen = sizeof(int),
62207 + .mode = 0600,
62208 + .proc_handler = &proc_dointvec,
62209 + },
62210 +#endif
62211 +#ifdef CONFIG_GRKERNSEC_ROFS
62212 + {
62213 + .procname = "romount_protect",
62214 + .data = &grsec_enable_rofs,
62215 + .maxlen = sizeof(int),
62216 + .mode = 0600,
62217 + .proc_handler = &proc_dointvec_minmax,
62218 + .extra1 = &one,
62219 + .extra2 = &one,
62220 + },
62221 +#endif
62222 + { }
62223 +};
62224 +#endif
62225 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
62226 new file mode 100644
62227 index 0000000..0dc13c3
62228 --- /dev/null
62229 +++ b/grsecurity/grsec_time.c
62230 @@ -0,0 +1,16 @@
62231 +#include <linux/kernel.h>
62232 +#include <linux/sched.h>
62233 +#include <linux/grinternal.h>
62234 +#include <linux/module.h>
62235 +
62236 +void
62237 +gr_log_timechange(void)
62238 +{
62239 +#ifdef CONFIG_GRKERNSEC_TIME
62240 + if (grsec_enable_time)
62241 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
62242 +#endif
62243 + return;
62244 +}
62245 +
62246 +EXPORT_SYMBOL(gr_log_timechange);
62247 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
62248 new file mode 100644
62249 index 0000000..07e0dc0
62250 --- /dev/null
62251 +++ b/grsecurity/grsec_tpe.c
62252 @@ -0,0 +1,73 @@
62253 +#include <linux/kernel.h>
62254 +#include <linux/sched.h>
62255 +#include <linux/file.h>
62256 +#include <linux/fs.h>
62257 +#include <linux/grinternal.h>
62258 +
62259 +extern int gr_acl_tpe_check(void);
62260 +
62261 +int
62262 +gr_tpe_allow(const struct file *file)
62263 +{
62264 +#ifdef CONFIG_GRKERNSEC
62265 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
62266 + const struct cred *cred = current_cred();
62267 + char *msg = NULL;
62268 + char *msg2 = NULL;
62269 +
62270 + // never restrict root
62271 + if (!cred->uid)
62272 + return 1;
62273 +
62274 + if (grsec_enable_tpe) {
62275 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62276 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
62277 + msg = "not being in trusted group";
62278 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
62279 + msg = "being in untrusted group";
62280 +#else
62281 + if (in_group_p(grsec_tpe_gid))
62282 + msg = "being in untrusted group";
62283 +#endif
62284 + }
62285 + if (!msg && gr_acl_tpe_check())
62286 + msg = "being in untrusted role";
62287 +
62288 + // not in any affected group/role
62289 + if (!msg)
62290 + goto next_check;
62291 +
62292 + if (inode->i_uid)
62293 + msg2 = "file in non-root-owned directory";
62294 + else if (inode->i_mode & S_IWOTH)
62295 + msg2 = "file in world-writable directory";
62296 + else if (inode->i_mode & S_IWGRP)
62297 + msg2 = "file in group-writable directory";
62298 +
62299 + if (msg && msg2) {
62300 + char fullmsg[70] = {0};
62301 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
62302 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
62303 + return 0;
62304 + }
62305 + msg = NULL;
62306 +next_check:
62307 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62308 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
62309 + return 1;
62310 +
62311 + if (inode->i_uid && (inode->i_uid != cred->uid))
62312 + msg = "directory not owned by user";
62313 + else if (inode->i_mode & S_IWOTH)
62314 + msg = "file in world-writable directory";
62315 + else if (inode->i_mode & S_IWGRP)
62316 + msg = "file in group-writable directory";
62317 +
62318 + if (msg) {
62319 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
62320 + return 0;
62321 + }
62322 +#endif
62323 +#endif
62324 + return 1;
62325 +}
62326 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
62327 new file mode 100644
62328 index 0000000..9f7b1ac
62329 --- /dev/null
62330 +++ b/grsecurity/grsum.c
62331 @@ -0,0 +1,61 @@
62332 +#include <linux/err.h>
62333 +#include <linux/kernel.h>
62334 +#include <linux/sched.h>
62335 +#include <linux/mm.h>
62336 +#include <linux/scatterlist.h>
62337 +#include <linux/crypto.h>
62338 +#include <linux/gracl.h>
62339 +
62340 +
62341 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
62342 +#error "crypto and sha256 must be built into the kernel"
62343 +#endif
62344 +
62345 +int
62346 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
62347 +{
62348 + char *p;
62349 + struct crypto_hash *tfm;
62350 + struct hash_desc desc;
62351 + struct scatterlist sg;
62352 + unsigned char temp_sum[GR_SHA_LEN];
62353 + volatile int retval = 0;
62354 + volatile int dummy = 0;
62355 + unsigned int i;
62356 +
62357 + sg_init_table(&sg, 1);
62358 +
62359 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
62360 + if (IS_ERR(tfm)) {
62361 + /* should never happen, since sha256 should be built in */
62362 + return 1;
62363 + }
62364 +
62365 + desc.tfm = tfm;
62366 + desc.flags = 0;
62367 +
62368 + crypto_hash_init(&desc);
62369 +
62370 + p = salt;
62371 + sg_set_buf(&sg, p, GR_SALT_LEN);
62372 + crypto_hash_update(&desc, &sg, sg.length);
62373 +
62374 + p = entry->pw;
62375 + sg_set_buf(&sg, p, strlen(p));
62376 +
62377 + crypto_hash_update(&desc, &sg, sg.length);
62378 +
62379 + crypto_hash_final(&desc, temp_sum);
62380 +
62381 + memset(entry->pw, 0, GR_PW_LEN);
62382 +
62383 + for (i = 0; i < GR_SHA_LEN; i++)
62384 + if (sum[i] != temp_sum[i])
62385 + retval = 1;
62386 + else
62387 + dummy = 1; // waste a cycle
62388 +
62389 + crypto_free_hash(tfm);
62390 +
62391 + return retval;
62392 +}
62393 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
62394 index 77ff547..181834f 100644
62395 --- a/include/asm-generic/4level-fixup.h
62396 +++ b/include/asm-generic/4level-fixup.h
62397 @@ -13,8 +13,10 @@
62398 #define pmd_alloc(mm, pud, address) \
62399 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
62400 NULL: pmd_offset(pud, address))
62401 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
62402
62403 #define pud_alloc(mm, pgd, address) (pgd)
62404 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
62405 #define pud_offset(pgd, start) (pgd)
62406 #define pud_none(pud) 0
62407 #define pud_bad(pud) 0
62408 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
62409 index b7babf0..04ad282 100644
62410 --- a/include/asm-generic/atomic-long.h
62411 +++ b/include/asm-generic/atomic-long.h
62412 @@ -22,6 +22,12 @@
62413
62414 typedef atomic64_t atomic_long_t;
62415
62416 +#ifdef CONFIG_PAX_REFCOUNT
62417 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
62418 +#else
62419 +typedef atomic64_t atomic_long_unchecked_t;
62420 +#endif
62421 +
62422 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62423
62424 static inline long atomic_long_read(atomic_long_t *l)
62425 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62426 return (long)atomic64_read(v);
62427 }
62428
62429 +#ifdef CONFIG_PAX_REFCOUNT
62430 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62431 +{
62432 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62433 +
62434 + return (long)atomic64_read_unchecked(v);
62435 +}
62436 +#endif
62437 +
62438 static inline void atomic_long_set(atomic_long_t *l, long i)
62439 {
62440 atomic64_t *v = (atomic64_t *)l;
62441 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62442 atomic64_set(v, i);
62443 }
62444
62445 +#ifdef CONFIG_PAX_REFCOUNT
62446 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62447 +{
62448 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62449 +
62450 + atomic64_set_unchecked(v, i);
62451 +}
62452 +#endif
62453 +
62454 static inline void atomic_long_inc(atomic_long_t *l)
62455 {
62456 atomic64_t *v = (atomic64_t *)l;
62457 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62458 atomic64_inc(v);
62459 }
62460
62461 +#ifdef CONFIG_PAX_REFCOUNT
62462 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62463 +{
62464 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62465 +
62466 + atomic64_inc_unchecked(v);
62467 +}
62468 +#endif
62469 +
62470 static inline void atomic_long_dec(atomic_long_t *l)
62471 {
62472 atomic64_t *v = (atomic64_t *)l;
62473 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62474 atomic64_dec(v);
62475 }
62476
62477 +#ifdef CONFIG_PAX_REFCOUNT
62478 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62479 +{
62480 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62481 +
62482 + atomic64_dec_unchecked(v);
62483 +}
62484 +#endif
62485 +
62486 static inline void atomic_long_add(long i, atomic_long_t *l)
62487 {
62488 atomic64_t *v = (atomic64_t *)l;
62489 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62490 atomic64_add(i, v);
62491 }
62492
62493 +#ifdef CONFIG_PAX_REFCOUNT
62494 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62495 +{
62496 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62497 +
62498 + atomic64_add_unchecked(i, v);
62499 +}
62500 +#endif
62501 +
62502 static inline void atomic_long_sub(long i, atomic_long_t *l)
62503 {
62504 atomic64_t *v = (atomic64_t *)l;
62505 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62506 atomic64_sub(i, v);
62507 }
62508
62509 +#ifdef CONFIG_PAX_REFCOUNT
62510 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62511 +{
62512 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62513 +
62514 + atomic64_sub_unchecked(i, v);
62515 +}
62516 +#endif
62517 +
62518 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62519 {
62520 atomic64_t *v = (atomic64_t *)l;
62521 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62522 return (long)atomic64_add_return(i, v);
62523 }
62524
62525 +#ifdef CONFIG_PAX_REFCOUNT
62526 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62527 +{
62528 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62529 +
62530 + return (long)atomic64_add_return_unchecked(i, v);
62531 +}
62532 +#endif
62533 +
62534 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62535 {
62536 atomic64_t *v = (atomic64_t *)l;
62537 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62538 return (long)atomic64_inc_return(v);
62539 }
62540
62541 +#ifdef CONFIG_PAX_REFCOUNT
62542 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62543 +{
62544 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62545 +
62546 + return (long)atomic64_inc_return_unchecked(v);
62547 +}
62548 +#endif
62549 +
62550 static inline long atomic_long_dec_return(atomic_long_t *l)
62551 {
62552 atomic64_t *v = (atomic64_t *)l;
62553 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62554
62555 typedef atomic_t atomic_long_t;
62556
62557 +#ifdef CONFIG_PAX_REFCOUNT
62558 +typedef atomic_unchecked_t atomic_long_unchecked_t;
62559 +#else
62560 +typedef atomic_t atomic_long_unchecked_t;
62561 +#endif
62562 +
62563 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62564 static inline long atomic_long_read(atomic_long_t *l)
62565 {
62566 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62567 return (long)atomic_read(v);
62568 }
62569
62570 +#ifdef CONFIG_PAX_REFCOUNT
62571 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62572 +{
62573 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62574 +
62575 + return (long)atomic_read_unchecked(v);
62576 +}
62577 +#endif
62578 +
62579 static inline void atomic_long_set(atomic_long_t *l, long i)
62580 {
62581 atomic_t *v = (atomic_t *)l;
62582 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62583 atomic_set(v, i);
62584 }
62585
62586 +#ifdef CONFIG_PAX_REFCOUNT
62587 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62588 +{
62589 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62590 +
62591 + atomic_set_unchecked(v, i);
62592 +}
62593 +#endif
62594 +
62595 static inline void atomic_long_inc(atomic_long_t *l)
62596 {
62597 atomic_t *v = (atomic_t *)l;
62598 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62599 atomic_inc(v);
62600 }
62601
62602 +#ifdef CONFIG_PAX_REFCOUNT
62603 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62604 +{
62605 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62606 +
62607 + atomic_inc_unchecked(v);
62608 +}
62609 +#endif
62610 +
62611 static inline void atomic_long_dec(atomic_long_t *l)
62612 {
62613 atomic_t *v = (atomic_t *)l;
62614 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62615 atomic_dec(v);
62616 }
62617
62618 +#ifdef CONFIG_PAX_REFCOUNT
62619 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62620 +{
62621 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62622 +
62623 + atomic_dec_unchecked(v);
62624 +}
62625 +#endif
62626 +
62627 static inline void atomic_long_add(long i, atomic_long_t *l)
62628 {
62629 atomic_t *v = (atomic_t *)l;
62630 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62631 atomic_add(i, v);
62632 }
62633
62634 +#ifdef CONFIG_PAX_REFCOUNT
62635 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62636 +{
62637 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62638 +
62639 + atomic_add_unchecked(i, v);
62640 +}
62641 +#endif
62642 +
62643 static inline void atomic_long_sub(long i, atomic_long_t *l)
62644 {
62645 atomic_t *v = (atomic_t *)l;
62646 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62647 atomic_sub(i, v);
62648 }
62649
62650 +#ifdef CONFIG_PAX_REFCOUNT
62651 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62652 +{
62653 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62654 +
62655 + atomic_sub_unchecked(i, v);
62656 +}
62657 +#endif
62658 +
62659 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62660 {
62661 atomic_t *v = (atomic_t *)l;
62662 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62663 return (long)atomic_add_return(i, v);
62664 }
62665
62666 +#ifdef CONFIG_PAX_REFCOUNT
62667 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62668 +{
62669 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62670 +
62671 + return (long)atomic_add_return_unchecked(i, v);
62672 +}
62673 +
62674 +#endif
62675 +
62676 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62677 {
62678 atomic_t *v = (atomic_t *)l;
62679 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62680 return (long)atomic_inc_return(v);
62681 }
62682
62683 +#ifdef CONFIG_PAX_REFCOUNT
62684 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62685 +{
62686 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62687 +
62688 + return (long)atomic_inc_return_unchecked(v);
62689 +}
62690 +#endif
62691 +
62692 static inline long atomic_long_dec_return(atomic_long_t *l)
62693 {
62694 atomic_t *v = (atomic_t *)l;
62695 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62696
62697 #endif /* BITS_PER_LONG == 64 */
62698
62699 +#ifdef CONFIG_PAX_REFCOUNT
62700 +static inline void pax_refcount_needs_these_functions(void)
62701 +{
62702 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
62703 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62704 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62705 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62706 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62707 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62708 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62709 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62710 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62711 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62712 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62713 +#ifdef CONFIG_X86
62714 + atomic_clear_mask_unchecked(0, NULL);
62715 + atomic_set_mask_unchecked(0, NULL);
62716 +#endif
62717 +
62718 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62719 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62720 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62721 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62722 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62723 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62724 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62725 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62726 +}
62727 +#else
62728 +#define atomic_read_unchecked(v) atomic_read(v)
62729 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62730 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62731 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62732 +#define atomic_inc_unchecked(v) atomic_inc(v)
62733 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62734 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62735 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62736 +#define atomic_dec_unchecked(v) atomic_dec(v)
62737 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62738 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62739 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62740 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62741 +
62742 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
62743 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62744 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62745 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62746 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62747 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62748 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62749 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62750 +#endif
62751 +
62752 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62753 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62754 index 1ced641..c896ee8 100644
62755 --- a/include/asm-generic/atomic.h
62756 +++ b/include/asm-generic/atomic.h
62757 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62758 * Atomically clears the bits set in @mask from @v
62759 */
62760 #ifndef atomic_clear_mask
62761 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62762 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62763 {
62764 unsigned long flags;
62765
62766 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62767 index b18ce4f..2ee2843 100644
62768 --- a/include/asm-generic/atomic64.h
62769 +++ b/include/asm-generic/atomic64.h
62770 @@ -16,6 +16,8 @@ typedef struct {
62771 long long counter;
62772 } atomic64_t;
62773
62774 +typedef atomic64_t atomic64_unchecked_t;
62775 +
62776 #define ATOMIC64_INIT(i) { (i) }
62777
62778 extern long long atomic64_read(const atomic64_t *v);
62779 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62780 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62781 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62782
62783 +#define atomic64_read_unchecked(v) atomic64_read(v)
62784 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62785 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62786 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62787 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62788 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
62789 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62790 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
62791 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62792 +
62793 #endif /* _ASM_GENERIC_ATOMIC64_H */
62794 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62795 index 1bfcfe5..e04c5c9 100644
62796 --- a/include/asm-generic/cache.h
62797 +++ b/include/asm-generic/cache.h
62798 @@ -6,7 +6,7 @@
62799 * cache lines need to provide their own cache.h.
62800 */
62801
62802 -#define L1_CACHE_SHIFT 5
62803 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62804 +#define L1_CACHE_SHIFT 5UL
62805 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62806
62807 #endif /* __ASM_GENERIC_CACHE_H */
62808 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62809 index 0d68a1e..b74a761 100644
62810 --- a/include/asm-generic/emergency-restart.h
62811 +++ b/include/asm-generic/emergency-restart.h
62812 @@ -1,7 +1,7 @@
62813 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62814 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62815
62816 -static inline void machine_emergency_restart(void)
62817 +static inline __noreturn void machine_emergency_restart(void)
62818 {
62819 machine_restart(NULL);
62820 }
62821 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62822 index 90f99c7..00ce236 100644
62823 --- a/include/asm-generic/kmap_types.h
62824 +++ b/include/asm-generic/kmap_types.h
62825 @@ -2,9 +2,9 @@
62826 #define _ASM_GENERIC_KMAP_TYPES_H
62827
62828 #ifdef __WITH_KM_FENCE
62829 -# define KM_TYPE_NR 41
62830 +# define KM_TYPE_NR 42
62831 #else
62832 -# define KM_TYPE_NR 20
62833 +# define KM_TYPE_NR 21
62834 #endif
62835
62836 #endif
62837 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62838 index 9ceb03b..62b0b8f 100644
62839 --- a/include/asm-generic/local.h
62840 +++ b/include/asm-generic/local.h
62841 @@ -23,24 +23,37 @@ typedef struct
62842 atomic_long_t a;
62843 } local_t;
62844
62845 +typedef struct {
62846 + atomic_long_unchecked_t a;
62847 +} local_unchecked_t;
62848 +
62849 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62850
62851 #define local_read(l) atomic_long_read(&(l)->a)
62852 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62853 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62854 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62855 #define local_inc(l) atomic_long_inc(&(l)->a)
62856 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62857 #define local_dec(l) atomic_long_dec(&(l)->a)
62858 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62859 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62860 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62861 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62862 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62863
62864 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62865 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62866 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62867 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62868 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62869 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62870 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62871 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62872 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62873
62874 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62875 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62876 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62877 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62878 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62879 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62880 index 725612b..9cc513a 100644
62881 --- a/include/asm-generic/pgtable-nopmd.h
62882 +++ b/include/asm-generic/pgtable-nopmd.h
62883 @@ -1,14 +1,19 @@
62884 #ifndef _PGTABLE_NOPMD_H
62885 #define _PGTABLE_NOPMD_H
62886
62887 -#ifndef __ASSEMBLY__
62888 -
62889 #include <asm-generic/pgtable-nopud.h>
62890
62891 -struct mm_struct;
62892 -
62893 #define __PAGETABLE_PMD_FOLDED
62894
62895 +#define PMD_SHIFT PUD_SHIFT
62896 +#define PTRS_PER_PMD 1
62897 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62898 +#define PMD_MASK (~(PMD_SIZE-1))
62899 +
62900 +#ifndef __ASSEMBLY__
62901 +
62902 +struct mm_struct;
62903 +
62904 /*
62905 * Having the pmd type consist of a pud gets the size right, and allows
62906 * us to conceptually access the pud entry that this pmd is folded into
62907 @@ -16,11 +21,6 @@ struct mm_struct;
62908 */
62909 typedef struct { pud_t pud; } pmd_t;
62910
62911 -#define PMD_SHIFT PUD_SHIFT
62912 -#define PTRS_PER_PMD 1
62913 -#define PMD_SIZE (1UL << PMD_SHIFT)
62914 -#define PMD_MASK (~(PMD_SIZE-1))
62915 -
62916 /*
62917 * The "pud_xxx()" functions here are trivial for a folded two-level
62918 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62919 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62920 index 810431d..0ec4804f 100644
62921 --- a/include/asm-generic/pgtable-nopud.h
62922 +++ b/include/asm-generic/pgtable-nopud.h
62923 @@ -1,10 +1,15 @@
62924 #ifndef _PGTABLE_NOPUD_H
62925 #define _PGTABLE_NOPUD_H
62926
62927 -#ifndef __ASSEMBLY__
62928 -
62929 #define __PAGETABLE_PUD_FOLDED
62930
62931 +#define PUD_SHIFT PGDIR_SHIFT
62932 +#define PTRS_PER_PUD 1
62933 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62934 +#define PUD_MASK (~(PUD_SIZE-1))
62935 +
62936 +#ifndef __ASSEMBLY__
62937 +
62938 /*
62939 * Having the pud type consist of a pgd gets the size right, and allows
62940 * us to conceptually access the pgd entry that this pud is folded into
62941 @@ -12,11 +17,6 @@
62942 */
62943 typedef struct { pgd_t pgd; } pud_t;
62944
62945 -#define PUD_SHIFT PGDIR_SHIFT
62946 -#define PTRS_PER_PUD 1
62947 -#define PUD_SIZE (1UL << PUD_SHIFT)
62948 -#define PUD_MASK (~(PUD_SIZE-1))
62949 -
62950 /*
62951 * The "pgd_xxx()" functions here are trivial for a folded two-level
62952 * setup: the pud is never bad, and a pud always exists (as it's folded
62953 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
62954 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
62955
62956 #define pgd_populate(mm, pgd, pud) do { } while (0)
62957 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
62958 /*
62959 * (puds are folded into pgds so this doesn't get actually called,
62960 * but the define is needed for a generic inline function.)
62961 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
62962 index b36ce40..019426d 100644
62963 --- a/include/asm-generic/pgtable.h
62964 +++ b/include/asm-generic/pgtable.h
62965 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
62966 #endif
62967 }
62968
62969 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
62970 +static inline unsigned long pax_open_kernel(void) { return 0; }
62971 +#endif
62972 +
62973 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
62974 +static inline unsigned long pax_close_kernel(void) { return 0; }
62975 +#endif
62976 +
62977 #endif /* CONFIG_MMU */
62978
62979 #endif /* !__ASSEMBLY__ */
62980 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62981 index d1ea7ce..b1ebf2a 100644
62982 --- a/include/asm-generic/vmlinux.lds.h
62983 +++ b/include/asm-generic/vmlinux.lds.h
62984 @@ -218,6 +218,7 @@
62985 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
62986 VMLINUX_SYMBOL(__start_rodata) = .; \
62987 *(.rodata) *(.rodata.*) \
62988 + *(.data..read_only) \
62989 *(__vermagic) /* Kernel version magic */ \
62990 . = ALIGN(8); \
62991 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
62992 @@ -725,17 +726,18 @@
62993 * section in the linker script will go there too. @phdr should have
62994 * a leading colon.
62995 *
62996 - * Note that this macros defines __per_cpu_load as an absolute symbol.
62997 + * Note that this macros defines per_cpu_load as an absolute symbol.
62998 * If there is no need to put the percpu section at a predetermined
62999 * address, use PERCPU_SECTION.
63000 */
63001 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63002 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
63003 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63004 + per_cpu_load = .; \
63005 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63006 - LOAD_OFFSET) { \
63007 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63008 PERCPU_INPUT(cacheline) \
63009 } phdr \
63010 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63011 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63012
63013 /**
63014 * PERCPU_SECTION - define output section for percpu area, simple version
63015 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63016 index 418d270..bfd2794 100644
63017 --- a/include/crypto/algapi.h
63018 +++ b/include/crypto/algapi.h
63019 @@ -34,7 +34,7 @@ struct crypto_type {
63020 unsigned int maskclear;
63021 unsigned int maskset;
63022 unsigned int tfmsize;
63023 -};
63024 +} __do_const;
63025
63026 struct crypto_instance {
63027 struct crypto_alg alg;
63028 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63029 index 3fd8280..2b3c415 100644
63030 --- a/include/drm/drmP.h
63031 +++ b/include/drm/drmP.h
63032 @@ -72,6 +72,7 @@
63033 #include <linux/workqueue.h>
63034 #include <linux/poll.h>
63035 #include <asm/pgalloc.h>
63036 +#include <asm/local.h>
63037 #include <drm/drm.h>
63038 #include <drm/drm_sarea.h>
63039
63040 @@ -1068,7 +1069,7 @@ struct drm_device {
63041
63042 /** \name Usage Counters */
63043 /*@{ */
63044 - int open_count; /**< Outstanding files open */
63045 + local_t open_count; /**< Outstanding files open */
63046 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63047 atomic_t vma_count; /**< Outstanding vma areas open */
63048 int buf_use; /**< Buffers in use -- cannot alloc */
63049 @@ -1079,7 +1080,7 @@ struct drm_device {
63050 /*@{ */
63051 unsigned long counters;
63052 enum drm_stat_type types[15];
63053 - atomic_t counts[15];
63054 + atomic_unchecked_t counts[15];
63055 /*@} */
63056
63057 struct list_head filelist;
63058 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63059 index e01cc80..6fb6f25 100644
63060 --- a/include/drm/drm_crtc_helper.h
63061 +++ b/include/drm/drm_crtc_helper.h
63062 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63063 struct drm_connector *connector);
63064 /* disable encoder when not in use - more explicit than dpms off */
63065 void (*disable)(struct drm_encoder *encoder);
63066 -};
63067 +} __no_const;
63068
63069 /**
63070 * drm_connector_helper_funcs - helper operations for connectors
63071 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63072 index d6d1da4..fdd1ac5 100644
63073 --- a/include/drm/ttm/ttm_memory.h
63074 +++ b/include/drm/ttm/ttm_memory.h
63075 @@ -48,7 +48,7 @@
63076
63077 struct ttm_mem_shrink {
63078 int (*do_shrink) (struct ttm_mem_shrink *);
63079 -};
63080 +} __no_const;
63081
63082 /**
63083 * struct ttm_mem_global - Global memory accounting structure.
63084 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63085 index 22ef21c..75904ba 100644
63086 --- a/include/linux/atmdev.h
63087 +++ b/include/linux/atmdev.h
63088 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63089 #endif
63090
63091 struct k_atm_aal_stats {
63092 -#define __HANDLE_ITEM(i) atomic_t i
63093 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63094 __AAL_STAT_ITEMS
63095 #undef __HANDLE_ITEM
63096 };
63097 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63098 index de0628e..38f42eb 100644
63099 --- a/include/linux/binfmts.h
63100 +++ b/include/linux/binfmts.h
63101 @@ -75,6 +75,7 @@ struct linux_binfmt {
63102 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
63103 int (*load_shlib)(struct file *);
63104 int (*core_dump)(struct coredump_params *cprm);
63105 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63106 unsigned long min_coredump; /* minimal dump size */
63107 };
63108
63109 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63110 index 1756001..ab117ec 100644
63111 --- a/include/linux/blkdev.h
63112 +++ b/include/linux/blkdev.h
63113 @@ -1478,7 +1478,7 @@ struct block_device_operations {
63114 /* this callback is with swap_lock and sometimes page table lock held */
63115 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63116 struct module *owner;
63117 -};
63118 +} __do_const;
63119
63120 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63121 unsigned long);
63122 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63123 index 7c2e030..b72475d 100644
63124 --- a/include/linux/blktrace_api.h
63125 +++ b/include/linux/blktrace_api.h
63126 @@ -23,7 +23,7 @@ struct blk_trace {
63127 struct dentry *dir;
63128 struct dentry *dropped_file;
63129 struct dentry *msg_file;
63130 - atomic_t dropped;
63131 + atomic_unchecked_t dropped;
63132 };
63133
63134 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63135 diff --git a/include/linux/cache.h b/include/linux/cache.h
63136 index 4c57065..4307975 100644
63137 --- a/include/linux/cache.h
63138 +++ b/include/linux/cache.h
63139 @@ -16,6 +16,10 @@
63140 #define __read_mostly
63141 #endif
63142
63143 +#ifndef __read_only
63144 +#define __read_only __read_mostly
63145 +#endif
63146 +
63147 #ifndef ____cacheline_aligned
63148 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
63149 #endif
63150 diff --git a/include/linux/capability.h b/include/linux/capability.h
63151 index 98503b7..cc36d18 100644
63152 --- a/include/linux/capability.h
63153 +++ b/include/linux/capability.h
63154 @@ -211,8 +211,13 @@ extern bool capable(int cap);
63155 extern bool ns_capable(struct user_namespace *ns, int cap);
63156 extern bool nsown_capable(int cap);
63157 extern bool inode_capable(const struct inode *inode, int cap);
63158 +extern bool capable_nolog(int cap);
63159 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
63160 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
63161
63162 /* audit system wants to get cap info from files as well */
63163 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
63164
63165 +extern int is_privileged_binary(const struct dentry *dentry);
63166 +
63167 #endif /* !_LINUX_CAPABILITY_H */
63168 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
63169 index 8609d57..86e4d79 100644
63170 --- a/include/linux/cdrom.h
63171 +++ b/include/linux/cdrom.h
63172 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
63173
63174 /* driver specifications */
63175 const int capability; /* capability flags */
63176 - int n_minors; /* number of active minor devices */
63177 /* handle uniform packets for scsi type devices (scsi,atapi) */
63178 int (*generic_packet) (struct cdrom_device_info *,
63179 struct packet_command *);
63180 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
63181 index 42e55de..1cd0e66 100644
63182 --- a/include/linux/cleancache.h
63183 +++ b/include/linux/cleancache.h
63184 @@ -31,7 +31,7 @@ struct cleancache_ops {
63185 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
63186 void (*invalidate_inode)(int, struct cleancache_filekey);
63187 void (*invalidate_fs)(int);
63188 -};
63189 +} __no_const;
63190
63191 extern struct cleancache_ops
63192 cleancache_register_ops(struct cleancache_ops *ops);
63193 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
63194 index 412bc6c..c31666e 100644
63195 --- a/include/linux/compiler-gcc4.h
63196 +++ b/include/linux/compiler-gcc4.h
63197 @@ -32,6 +32,21 @@
63198 #define __linktime_error(message) __attribute__((__error__(message)))
63199
63200 #if __GNUC_MINOR__ >= 5
63201 +
63202 +#ifdef CONSTIFY_PLUGIN
63203 +#define __no_const __attribute__((no_const))
63204 +#define __do_const __attribute__((do_const))
63205 +#endif
63206 +
63207 +#ifdef SIZE_OVERFLOW_PLUGIN
63208 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
63209 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
63210 +#endif
63211 +
63212 +#ifdef LATENT_ENTROPY_PLUGIN
63213 +#define __latent_entropy __attribute__((latent_entropy))
63214 +#endif
63215 +
63216 /*
63217 * Mark a position in code as unreachable. This can be used to
63218 * suppress control flow warnings after asm blocks that transfer
63219 @@ -47,6 +62,11 @@
63220 #define __noclone __attribute__((__noclone__))
63221
63222 #endif
63223 +
63224 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
63225 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
63226 +#define __bos0(ptr) __bos((ptr), 0)
63227 +#define __bos1(ptr) __bos((ptr), 1)
63228 #endif
63229
63230 #if __GNUC_MINOR__ >= 6
63231 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
63232 index f430e41..38be90f 100644
63233 --- a/include/linux/compiler.h
63234 +++ b/include/linux/compiler.h
63235 @@ -5,31 +5,62 @@
63236
63237 #ifdef __CHECKER__
63238 # define __user __attribute__((noderef, address_space(1)))
63239 +# define __force_user __force __user
63240 # define __kernel __attribute__((address_space(0)))
63241 +# define __force_kernel __force __kernel
63242 # define __safe __attribute__((safe))
63243 # define __force __attribute__((force))
63244 # define __nocast __attribute__((nocast))
63245 # define __iomem __attribute__((noderef, address_space(2)))
63246 +# define __force_iomem __force __iomem
63247 # define __acquires(x) __attribute__((context(x,0,1)))
63248 # define __releases(x) __attribute__((context(x,1,0)))
63249 # define __acquire(x) __context__(x,1)
63250 # define __release(x) __context__(x,-1)
63251 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
63252 # define __percpu __attribute__((noderef, address_space(3)))
63253 +# define __force_percpu __force __percpu
63254 #ifdef CONFIG_SPARSE_RCU_POINTER
63255 # define __rcu __attribute__((noderef, address_space(4)))
63256 +# define __force_rcu __force __rcu
63257 #else
63258 # define __rcu
63259 +# define __force_rcu
63260 #endif
63261 extern void __chk_user_ptr(const volatile void __user *);
63262 extern void __chk_io_ptr(const volatile void __iomem *);
63263 +#elif defined(CHECKER_PLUGIN)
63264 +//# define __user
63265 +//# define __force_user
63266 +//# define __kernel
63267 +//# define __force_kernel
63268 +# define __safe
63269 +# define __force
63270 +# define __nocast
63271 +# define __iomem
63272 +# define __force_iomem
63273 +# define __chk_user_ptr(x) (void)0
63274 +# define __chk_io_ptr(x) (void)0
63275 +# define __builtin_warning(x, y...) (1)
63276 +# define __acquires(x)
63277 +# define __releases(x)
63278 +# define __acquire(x) (void)0
63279 +# define __release(x) (void)0
63280 +# define __cond_lock(x,c) (c)
63281 +# define __percpu
63282 +# define __force_percpu
63283 +# define __rcu
63284 +# define __force_rcu
63285 #else
63286 # define __user
63287 +# define __force_user
63288 # define __kernel
63289 +# define __force_kernel
63290 # define __safe
63291 # define __force
63292 # define __nocast
63293 # define __iomem
63294 +# define __force_iomem
63295 # define __chk_user_ptr(x) (void)0
63296 # define __chk_io_ptr(x) (void)0
63297 # define __builtin_warning(x, y...) (1)
63298 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
63299 # define __release(x) (void)0
63300 # define __cond_lock(x,c) (c)
63301 # define __percpu
63302 +# define __force_percpu
63303 # define __rcu
63304 +# define __force_rcu
63305 #endif
63306
63307 #ifdef __KERNEL__
63308 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63309 # define __attribute_const__ /* unimplemented */
63310 #endif
63311
63312 +#ifndef __no_const
63313 +# define __no_const
63314 +#endif
63315 +
63316 +#ifndef __do_const
63317 +# define __do_const
63318 +#endif
63319 +
63320 +#ifndef __size_overflow
63321 +# define __size_overflow(...)
63322 +#endif
63323 +
63324 +#ifndef __intentional_overflow
63325 +# define __intentional_overflow(...)
63326 +#endif
63327 +
63328 +#ifndef __latent_entropy
63329 +# define __latent_entropy
63330 +#endif
63331 +
63332 /*
63333 * Tell gcc if a function is cold. The compiler will assume any path
63334 * directly leading to the call is unlikely.
63335 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63336 #define __cold
63337 #endif
63338
63339 +#ifndef __alloc_size
63340 +#define __alloc_size(...)
63341 +#endif
63342 +
63343 +#ifndef __bos
63344 +#define __bos(ptr, arg)
63345 +#endif
63346 +
63347 +#ifndef __bos0
63348 +#define __bos0(ptr)
63349 +#endif
63350 +
63351 +#ifndef __bos1
63352 +#define __bos1(ptr)
63353 +#endif
63354 +
63355 /* Simple shorthand for a section definition */
63356 #ifndef __section
63357 # define __section(S) __attribute__ ((__section__(#S)))
63358 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63359 * use is to mediate communication between process-level code and irq/NMI
63360 * handlers, all running on the same CPU.
63361 */
63362 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
63363 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
63364 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
63365
63366 #endif /* __LINUX_COMPILER_H */
63367 diff --git a/include/linux/cred.h b/include/linux/cred.h
63368 index ebbed2c..908cc2c 100644
63369 --- a/include/linux/cred.h
63370 +++ b/include/linux/cred.h
63371 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
63372 static inline void validate_process_creds(void)
63373 {
63374 }
63375 +static inline void validate_task_creds(struct task_struct *task)
63376 +{
63377 +}
63378 #endif
63379
63380 /**
63381 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
63382 index b92eadf..b4ecdc1 100644
63383 --- a/include/linux/crypto.h
63384 +++ b/include/linux/crypto.h
63385 @@ -373,7 +373,7 @@ struct cipher_tfm {
63386 const u8 *key, unsigned int keylen);
63387 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63388 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63389 -};
63390 +} __no_const;
63391
63392 struct hash_tfm {
63393 int (*init)(struct hash_desc *desc);
63394 @@ -394,13 +394,13 @@ struct compress_tfm {
63395 int (*cot_decompress)(struct crypto_tfm *tfm,
63396 const u8 *src, unsigned int slen,
63397 u8 *dst, unsigned int *dlen);
63398 -};
63399 +} __no_const;
63400
63401 struct rng_tfm {
63402 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63403 unsigned int dlen);
63404 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63405 -};
63406 +} __no_const;
63407
63408 #define crt_ablkcipher crt_u.ablkcipher
63409 #define crt_aead crt_u.aead
63410 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63411 index 7925bf0..d5143d2 100644
63412 --- a/include/linux/decompress/mm.h
63413 +++ b/include/linux/decompress/mm.h
63414 @@ -77,7 +77,7 @@ static void free(void *where)
63415 * warnings when not needed (indeed large_malloc / large_free are not
63416 * needed by inflate */
63417
63418 -#define malloc(a) kmalloc(a, GFP_KERNEL)
63419 +#define malloc(a) kmalloc((a), GFP_KERNEL)
63420 #define free(a) kfree(a)
63421
63422 #define large_malloc(a) vmalloc(a)
63423 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63424 index 94af418..b1ca7a2 100644
63425 --- a/include/linux/dma-mapping.h
63426 +++ b/include/linux/dma-mapping.h
63427 @@ -54,7 +54,7 @@ struct dma_map_ops {
63428 u64 (*get_required_mask)(struct device *dev);
63429 #endif
63430 int is_phys;
63431 -};
63432 +} __do_const;
63433
63434 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63435
63436 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63437 index d3201e4..8281e63 100644
63438 --- a/include/linux/dmaengine.h
63439 +++ b/include/linux/dmaengine.h
63440 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63441 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63442 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63443
63444 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63445 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63446 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63447 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63448 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63449 struct dma_pinned_list *pinned_list, struct page *page,
63450 unsigned int offset, size_t len);
63451
63452 diff --git a/include/linux/elf.h b/include/linux/elf.h
63453 index 8c9048e..16a4665 100644
63454 --- a/include/linux/elf.h
63455 +++ b/include/linux/elf.h
63456 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63457 #define elf_note elf32_note
63458 #define elf_addr_t Elf32_Off
63459 #define Elf_Half Elf32_Half
63460 +#define elf_dyn Elf32_Dyn
63461
63462 #else
63463
63464 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63465 #define elf_note elf64_note
63466 #define elf_addr_t Elf64_Off
63467 #define Elf_Half Elf64_Half
63468 +#define elf_dyn Elf64_Dyn
63469
63470 #endif
63471
63472 diff --git a/include/linux/filter.h b/include/linux/filter.h
63473 index 24d251f..7afb83d 100644
63474 --- a/include/linux/filter.h
63475 +++ b/include/linux/filter.h
63476 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
63477
63478 struct sk_buff;
63479 struct sock;
63480 +struct bpf_jit_work;
63481
63482 struct sk_filter
63483 {
63484 @@ -27,6 +28,9 @@ struct sk_filter
63485 unsigned int len; /* Number of filter blocks */
63486 unsigned int (*bpf_func)(const struct sk_buff *skb,
63487 const struct sock_filter *filter);
63488 +#ifdef CONFIG_BPF_JIT
63489 + struct bpf_jit_work *work;
63490 +#endif
63491 struct rcu_head rcu;
63492 struct sock_filter insns[0];
63493 };
63494 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63495 index 3044254..9767f41 100644
63496 --- a/include/linux/frontswap.h
63497 +++ b/include/linux/frontswap.h
63498 @@ -11,7 +11,7 @@ struct frontswap_ops {
63499 int (*load)(unsigned, pgoff_t, struct page *);
63500 void (*invalidate_page)(unsigned, pgoff_t);
63501 void (*invalidate_area)(unsigned);
63502 -};
63503 +} __no_const;
63504
63505 extern bool frontswap_enabled;
63506 extern struct frontswap_ops
63507 diff --git a/include/linux/fs.h b/include/linux/fs.h
63508 index 75fe9a1..8417cac 100644
63509 --- a/include/linux/fs.h
63510 +++ b/include/linux/fs.h
63511 @@ -1543,7 +1543,8 @@ struct file_operations {
63512 int (*setlease)(struct file *, long, struct file_lock **);
63513 long (*fallocate)(struct file *file, int mode, loff_t offset,
63514 loff_t len);
63515 -};
63516 +} __do_const;
63517 +typedef struct file_operations __no_const file_operations_no_const;
63518
63519 struct inode_operations {
63520 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63521 @@ -2667,4 +2668,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
63522 inode->i_flags |= S_NOSEC;
63523 }
63524
63525 +static inline bool is_sidechannel_device(const struct inode *inode)
63526 +{
63527 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
63528 + umode_t mode = inode->i_mode;
63529 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
63530 +#else
63531 + return false;
63532 +#endif
63533 +}
63534 +
63535 #endif /* _LINUX_FS_H */
63536 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63537 index 003dc0f..3c4ea97 100644
63538 --- a/include/linux/fs_struct.h
63539 +++ b/include/linux/fs_struct.h
63540 @@ -6,7 +6,7 @@
63541 #include <linux/seqlock.h>
63542
63543 struct fs_struct {
63544 - int users;
63545 + atomic_t users;
63546 spinlock_t lock;
63547 seqcount_t seq;
63548 int umask;
63549 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63550 index ce31408..b1ad003 100644
63551 --- a/include/linux/fscache-cache.h
63552 +++ b/include/linux/fscache-cache.h
63553 @@ -102,7 +102,7 @@ struct fscache_operation {
63554 fscache_operation_release_t release;
63555 };
63556
63557 -extern atomic_t fscache_op_debug_id;
63558 +extern atomic_unchecked_t fscache_op_debug_id;
63559 extern void fscache_op_work_func(struct work_struct *work);
63560
63561 extern void fscache_enqueue_operation(struct fscache_operation *);
63562 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63563 {
63564 INIT_WORK(&op->work, fscache_op_work_func);
63565 atomic_set(&op->usage, 1);
63566 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63567 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63568 op->processor = processor;
63569 op->release = release;
63570 INIT_LIST_HEAD(&op->pend_link);
63571 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63572 index 0fbfb46..508eb0d 100644
63573 --- a/include/linux/fsnotify.h
63574 +++ b/include/linux/fsnotify.h
63575 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
63576 struct inode *inode = path->dentry->d_inode;
63577 __u32 mask = FS_ACCESS;
63578
63579 + if (is_sidechannel_device(inode))
63580 + return;
63581 +
63582 if (S_ISDIR(inode->i_mode))
63583 mask |= FS_ISDIR;
63584
63585 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
63586 struct inode *inode = path->dentry->d_inode;
63587 __u32 mask = FS_MODIFY;
63588
63589 + if (is_sidechannel_device(inode))
63590 + return;
63591 +
63592 if (S_ISDIR(inode->i_mode))
63593 mask |= FS_ISDIR;
63594
63595 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63596 */
63597 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63598 {
63599 - return kstrdup(name, GFP_KERNEL);
63600 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63601 }
63602
63603 /*
63604 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63605 index 642928c..93afe6a 100644
63606 --- a/include/linux/ftrace_event.h
63607 +++ b/include/linux/ftrace_event.h
63608 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63609 extern int trace_add_event_call(struct ftrace_event_call *call);
63610 extern void trace_remove_event_call(struct ftrace_event_call *call);
63611
63612 -#define is_signed_type(type) (((type)(-1)) < 0)
63613 +#define is_signed_type(type) (((type)(-1)) < (type)1)
63614
63615 int trace_set_clr_event(const char *system, const char *event, int set);
63616
63617 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63618 index 4f440b3..342233a 100644
63619 --- a/include/linux/genhd.h
63620 +++ b/include/linux/genhd.h
63621 @@ -190,7 +190,7 @@ struct gendisk {
63622 struct kobject *slave_dir;
63623
63624 struct timer_rand_state *random;
63625 - atomic_t sync_io; /* RAID */
63626 + atomic_unchecked_t sync_io; /* RAID */
63627 struct disk_events *ev;
63628 #ifdef CONFIG_BLK_DEV_INTEGRITY
63629 struct blk_integrity *integrity;
63630 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63631 index d0a7967..63c4c47 100644
63632 --- a/include/linux/gfp.h
63633 +++ b/include/linux/gfp.h
63634 @@ -35,6 +35,12 @@ struct vm_area_struct;
63635 #define ___GFP_OTHER_NODE 0x800000u
63636 #define ___GFP_WRITE 0x1000000u
63637
63638 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63639 +#define ___GFP_USERCOPY 0x2000000u
63640 +#else
63641 +#define ___GFP_USERCOPY 0
63642 +#endif
63643 +
63644 /*
63645 * GFP bitmasks..
63646 *
63647 @@ -89,6 +95,7 @@ struct vm_area_struct;
63648 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63649 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63650 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63651 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63652
63653 /*
63654 * This may seem redundant, but it's a way of annotating false positives vs.
63655 @@ -96,7 +103,7 @@ struct vm_area_struct;
63656 */
63657 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63658
63659 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63660 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63661 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63662
63663 /* This equals 0, but use constants in case they ever change */
63664 @@ -150,6 +157,8 @@ struct vm_area_struct;
63665 /* 4GB DMA on some platforms */
63666 #define GFP_DMA32 __GFP_DMA32
63667
63668 +#define GFP_USERCOPY __GFP_USERCOPY
63669 +
63670 /* Convert GFP flags to their corresponding migrate type */
63671 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63672 {
63673 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63674 new file mode 100644
63675 index 0000000..ebe6d72
63676 --- /dev/null
63677 +++ b/include/linux/gracl.h
63678 @@ -0,0 +1,319 @@
63679 +#ifndef GR_ACL_H
63680 +#define GR_ACL_H
63681 +
63682 +#include <linux/grdefs.h>
63683 +#include <linux/resource.h>
63684 +#include <linux/capability.h>
63685 +#include <linux/dcache.h>
63686 +#include <asm/resource.h>
63687 +
63688 +/* Major status information */
63689 +
63690 +#define GR_VERSION "grsecurity 2.9.1"
63691 +#define GRSECURITY_VERSION 0x2901
63692 +
63693 +enum {
63694 + GR_SHUTDOWN = 0,
63695 + GR_ENABLE = 1,
63696 + GR_SPROLE = 2,
63697 + GR_RELOAD = 3,
63698 + GR_SEGVMOD = 4,
63699 + GR_STATUS = 5,
63700 + GR_UNSPROLE = 6,
63701 + GR_PASSSET = 7,
63702 + GR_SPROLEPAM = 8,
63703 +};
63704 +
63705 +/* Password setup definitions
63706 + * kernel/grhash.c */
63707 +enum {
63708 + GR_PW_LEN = 128,
63709 + GR_SALT_LEN = 16,
63710 + GR_SHA_LEN = 32,
63711 +};
63712 +
63713 +enum {
63714 + GR_SPROLE_LEN = 64,
63715 +};
63716 +
63717 +enum {
63718 + GR_NO_GLOB = 0,
63719 + GR_REG_GLOB,
63720 + GR_CREATE_GLOB
63721 +};
63722 +
63723 +#define GR_NLIMITS 32
63724 +
63725 +/* Begin Data Structures */
63726 +
63727 +struct sprole_pw {
63728 + unsigned char *rolename;
63729 + unsigned char salt[GR_SALT_LEN];
63730 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63731 +};
63732 +
63733 +struct name_entry {
63734 + __u32 key;
63735 + ino_t inode;
63736 + dev_t device;
63737 + char *name;
63738 + __u16 len;
63739 + __u8 deleted;
63740 + struct name_entry *prev;
63741 + struct name_entry *next;
63742 +};
63743 +
63744 +struct inodev_entry {
63745 + struct name_entry *nentry;
63746 + struct inodev_entry *prev;
63747 + struct inodev_entry *next;
63748 +};
63749 +
63750 +struct acl_role_db {
63751 + struct acl_role_label **r_hash;
63752 + __u32 r_size;
63753 +};
63754 +
63755 +struct inodev_db {
63756 + struct inodev_entry **i_hash;
63757 + __u32 i_size;
63758 +};
63759 +
63760 +struct name_db {
63761 + struct name_entry **n_hash;
63762 + __u32 n_size;
63763 +};
63764 +
63765 +struct crash_uid {
63766 + uid_t uid;
63767 + unsigned long expires;
63768 +};
63769 +
63770 +struct gr_hash_struct {
63771 + void **table;
63772 + void **nametable;
63773 + void *first;
63774 + __u32 table_size;
63775 + __u32 used_size;
63776 + int type;
63777 +};
63778 +
63779 +/* Userspace Grsecurity ACL data structures */
63780 +
63781 +struct acl_subject_label {
63782 + char *filename;
63783 + ino_t inode;
63784 + dev_t device;
63785 + __u32 mode;
63786 + kernel_cap_t cap_mask;
63787 + kernel_cap_t cap_lower;
63788 + kernel_cap_t cap_invert_audit;
63789 +
63790 + struct rlimit res[GR_NLIMITS];
63791 + __u32 resmask;
63792 +
63793 + __u8 user_trans_type;
63794 + __u8 group_trans_type;
63795 + uid_t *user_transitions;
63796 + gid_t *group_transitions;
63797 + __u16 user_trans_num;
63798 + __u16 group_trans_num;
63799 +
63800 + __u32 sock_families[2];
63801 + __u32 ip_proto[8];
63802 + __u32 ip_type;
63803 + struct acl_ip_label **ips;
63804 + __u32 ip_num;
63805 + __u32 inaddr_any_override;
63806 +
63807 + __u32 crashes;
63808 + unsigned long expires;
63809 +
63810 + struct acl_subject_label *parent_subject;
63811 + struct gr_hash_struct *hash;
63812 + struct acl_subject_label *prev;
63813 + struct acl_subject_label *next;
63814 +
63815 + struct acl_object_label **obj_hash;
63816 + __u32 obj_hash_size;
63817 + __u16 pax_flags;
63818 +};
63819 +
63820 +struct role_allowed_ip {
63821 + __u32 addr;
63822 + __u32 netmask;
63823 +
63824 + struct role_allowed_ip *prev;
63825 + struct role_allowed_ip *next;
63826 +};
63827 +
63828 +struct role_transition {
63829 + char *rolename;
63830 +
63831 + struct role_transition *prev;
63832 + struct role_transition *next;
63833 +};
63834 +
63835 +struct acl_role_label {
63836 + char *rolename;
63837 + uid_t uidgid;
63838 + __u16 roletype;
63839 +
63840 + __u16 auth_attempts;
63841 + unsigned long expires;
63842 +
63843 + struct acl_subject_label *root_label;
63844 + struct gr_hash_struct *hash;
63845 +
63846 + struct acl_role_label *prev;
63847 + struct acl_role_label *next;
63848 +
63849 + struct role_transition *transitions;
63850 + struct role_allowed_ip *allowed_ips;
63851 + uid_t *domain_children;
63852 + __u16 domain_child_num;
63853 +
63854 + umode_t umask;
63855 +
63856 + struct acl_subject_label **subj_hash;
63857 + __u32 subj_hash_size;
63858 +};
63859 +
63860 +struct user_acl_role_db {
63861 + struct acl_role_label **r_table;
63862 + __u32 num_pointers; /* Number of allocations to track */
63863 + __u32 num_roles; /* Number of roles */
63864 + __u32 num_domain_children; /* Number of domain children */
63865 + __u32 num_subjects; /* Number of subjects */
63866 + __u32 num_objects; /* Number of objects */
63867 +};
63868 +
63869 +struct acl_object_label {
63870 + char *filename;
63871 + ino_t inode;
63872 + dev_t device;
63873 + __u32 mode;
63874 +
63875 + struct acl_subject_label *nested;
63876 + struct acl_object_label *globbed;
63877 +
63878 + /* next two structures not used */
63879 +
63880 + struct acl_object_label *prev;
63881 + struct acl_object_label *next;
63882 +};
63883 +
63884 +struct acl_ip_label {
63885 + char *iface;
63886 + __u32 addr;
63887 + __u32 netmask;
63888 + __u16 low, high;
63889 + __u8 mode;
63890 + __u32 type;
63891 + __u32 proto[8];
63892 +
63893 + /* next two structures not used */
63894 +
63895 + struct acl_ip_label *prev;
63896 + struct acl_ip_label *next;
63897 +};
63898 +
63899 +struct gr_arg {
63900 + struct user_acl_role_db role_db;
63901 + unsigned char pw[GR_PW_LEN];
63902 + unsigned char salt[GR_SALT_LEN];
63903 + unsigned char sum[GR_SHA_LEN];
63904 + unsigned char sp_role[GR_SPROLE_LEN];
63905 + struct sprole_pw *sprole_pws;
63906 + dev_t segv_device;
63907 + ino_t segv_inode;
63908 + uid_t segv_uid;
63909 + __u16 num_sprole_pws;
63910 + __u16 mode;
63911 +};
63912 +
63913 +struct gr_arg_wrapper {
63914 + struct gr_arg *arg;
63915 + __u32 version;
63916 + __u32 size;
63917 +};
63918 +
63919 +struct subject_map {
63920 + struct acl_subject_label *user;
63921 + struct acl_subject_label *kernel;
63922 + struct subject_map *prev;
63923 + struct subject_map *next;
63924 +};
63925 +
63926 +struct acl_subj_map_db {
63927 + struct subject_map **s_hash;
63928 + __u32 s_size;
63929 +};
63930 +
63931 +/* End Data Structures Section */
63932 +
63933 +/* Hash functions generated by empirical testing by Brad Spengler
63934 + Makes good use of the low bits of the inode. Generally 0-1 times
63935 + in loop for successful match. 0-3 for unsuccessful match.
63936 + Shift/add algorithm with modulus of table size and an XOR*/
63937 +
63938 +static __inline__ unsigned int
63939 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63940 +{
63941 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
63942 +}
63943 +
63944 + static __inline__ unsigned int
63945 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
63946 +{
63947 + return ((const unsigned long)userp % sz);
63948 +}
63949 +
63950 +static __inline__ unsigned int
63951 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
63952 +{
63953 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
63954 +}
63955 +
63956 +static __inline__ unsigned int
63957 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
63958 +{
63959 + return full_name_hash((const unsigned char *)name, len) % sz;
63960 +}
63961 +
63962 +#define FOR_EACH_ROLE_START(role) \
63963 + role = role_list; \
63964 + while (role) {
63965 +
63966 +#define FOR_EACH_ROLE_END(role) \
63967 + role = role->prev; \
63968 + }
63969 +
63970 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
63971 + subj = NULL; \
63972 + iter = 0; \
63973 + while (iter < role->subj_hash_size) { \
63974 + if (subj == NULL) \
63975 + subj = role->subj_hash[iter]; \
63976 + if (subj == NULL) { \
63977 + iter++; \
63978 + continue; \
63979 + }
63980 +
63981 +#define FOR_EACH_SUBJECT_END(subj,iter) \
63982 + subj = subj->next; \
63983 + if (subj == NULL) \
63984 + iter++; \
63985 + }
63986 +
63987 +
63988 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
63989 + subj = role->hash->first; \
63990 + while (subj != NULL) {
63991 +
63992 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
63993 + subj = subj->next; \
63994 + }
63995 +
63996 +#endif
63997 +
63998 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
63999 new file mode 100644
64000 index 0000000..323ecf2
64001 --- /dev/null
64002 +++ b/include/linux/gralloc.h
64003 @@ -0,0 +1,9 @@
64004 +#ifndef __GRALLOC_H
64005 +#define __GRALLOC_H
64006 +
64007 +void acl_free_all(void);
64008 +int acl_alloc_stack_init(unsigned long size);
64009 +void *acl_alloc(unsigned long len);
64010 +void *acl_alloc_num(unsigned long num, unsigned long len);
64011 +
64012 +#endif
64013 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64014 new file mode 100644
64015 index 0000000..be66033
64016 --- /dev/null
64017 +++ b/include/linux/grdefs.h
64018 @@ -0,0 +1,140 @@
64019 +#ifndef GRDEFS_H
64020 +#define GRDEFS_H
64021 +
64022 +/* Begin grsecurity status declarations */
64023 +
64024 +enum {
64025 + GR_READY = 0x01,
64026 + GR_STATUS_INIT = 0x00 // disabled state
64027 +};
64028 +
64029 +/* Begin ACL declarations */
64030 +
64031 +/* Role flags */
64032 +
64033 +enum {
64034 + GR_ROLE_USER = 0x0001,
64035 + GR_ROLE_GROUP = 0x0002,
64036 + GR_ROLE_DEFAULT = 0x0004,
64037 + GR_ROLE_SPECIAL = 0x0008,
64038 + GR_ROLE_AUTH = 0x0010,
64039 + GR_ROLE_NOPW = 0x0020,
64040 + GR_ROLE_GOD = 0x0040,
64041 + GR_ROLE_LEARN = 0x0080,
64042 + GR_ROLE_TPE = 0x0100,
64043 + GR_ROLE_DOMAIN = 0x0200,
64044 + GR_ROLE_PAM = 0x0400,
64045 + GR_ROLE_PERSIST = 0x0800
64046 +};
64047 +
64048 +/* ACL Subject and Object mode flags */
64049 +enum {
64050 + GR_DELETED = 0x80000000
64051 +};
64052 +
64053 +/* ACL Object-only mode flags */
64054 +enum {
64055 + GR_READ = 0x00000001,
64056 + GR_APPEND = 0x00000002,
64057 + GR_WRITE = 0x00000004,
64058 + GR_EXEC = 0x00000008,
64059 + GR_FIND = 0x00000010,
64060 + GR_INHERIT = 0x00000020,
64061 + GR_SETID = 0x00000040,
64062 + GR_CREATE = 0x00000080,
64063 + GR_DELETE = 0x00000100,
64064 + GR_LINK = 0x00000200,
64065 + GR_AUDIT_READ = 0x00000400,
64066 + GR_AUDIT_APPEND = 0x00000800,
64067 + GR_AUDIT_WRITE = 0x00001000,
64068 + GR_AUDIT_EXEC = 0x00002000,
64069 + GR_AUDIT_FIND = 0x00004000,
64070 + GR_AUDIT_INHERIT= 0x00008000,
64071 + GR_AUDIT_SETID = 0x00010000,
64072 + GR_AUDIT_CREATE = 0x00020000,
64073 + GR_AUDIT_DELETE = 0x00040000,
64074 + GR_AUDIT_LINK = 0x00080000,
64075 + GR_PTRACERD = 0x00100000,
64076 + GR_NOPTRACE = 0x00200000,
64077 + GR_SUPPRESS = 0x00400000,
64078 + GR_NOLEARN = 0x00800000,
64079 + GR_INIT_TRANSFER= 0x01000000
64080 +};
64081 +
64082 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64083 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64084 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64085 +
64086 +/* ACL subject-only mode flags */
64087 +enum {
64088 + GR_KILL = 0x00000001,
64089 + GR_VIEW = 0x00000002,
64090 + GR_PROTECTED = 0x00000004,
64091 + GR_LEARN = 0x00000008,
64092 + GR_OVERRIDE = 0x00000010,
64093 + /* just a placeholder, this mode is only used in userspace */
64094 + GR_DUMMY = 0x00000020,
64095 + GR_PROTSHM = 0x00000040,
64096 + GR_KILLPROC = 0x00000080,
64097 + GR_KILLIPPROC = 0x00000100,
64098 + /* just a placeholder, this mode is only used in userspace */
64099 + GR_NOTROJAN = 0x00000200,
64100 + GR_PROTPROCFD = 0x00000400,
64101 + GR_PROCACCT = 0x00000800,
64102 + GR_RELAXPTRACE = 0x00001000,
64103 + //GR_NESTED = 0x00002000,
64104 + GR_INHERITLEARN = 0x00004000,
64105 + GR_PROCFIND = 0x00008000,
64106 + GR_POVERRIDE = 0x00010000,
64107 + GR_KERNELAUTH = 0x00020000,
64108 + GR_ATSECURE = 0x00040000,
64109 + GR_SHMEXEC = 0x00080000
64110 +};
64111 +
64112 +enum {
64113 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64114 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64115 + GR_PAX_ENABLE_MPROTECT = 0x0004,
64116 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
64117 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
64118 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
64119 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
64120 + GR_PAX_DISABLE_MPROTECT = 0x0400,
64121 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
64122 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
64123 +};
64124 +
64125 +enum {
64126 + GR_ID_USER = 0x01,
64127 + GR_ID_GROUP = 0x02,
64128 +};
64129 +
64130 +enum {
64131 + GR_ID_ALLOW = 0x01,
64132 + GR_ID_DENY = 0x02,
64133 +};
64134 +
64135 +#define GR_CRASH_RES 31
64136 +#define GR_UIDTABLE_MAX 500
64137 +
64138 +/* begin resource learning section */
64139 +enum {
64140 + GR_RLIM_CPU_BUMP = 60,
64141 + GR_RLIM_FSIZE_BUMP = 50000,
64142 + GR_RLIM_DATA_BUMP = 10000,
64143 + GR_RLIM_STACK_BUMP = 1000,
64144 + GR_RLIM_CORE_BUMP = 10000,
64145 + GR_RLIM_RSS_BUMP = 500000,
64146 + GR_RLIM_NPROC_BUMP = 1,
64147 + GR_RLIM_NOFILE_BUMP = 5,
64148 + GR_RLIM_MEMLOCK_BUMP = 50000,
64149 + GR_RLIM_AS_BUMP = 500000,
64150 + GR_RLIM_LOCKS_BUMP = 2,
64151 + GR_RLIM_SIGPENDING_BUMP = 5,
64152 + GR_RLIM_MSGQUEUE_BUMP = 10000,
64153 + GR_RLIM_NICE_BUMP = 1,
64154 + GR_RLIM_RTPRIO_BUMP = 1,
64155 + GR_RLIM_RTTIME_BUMP = 1000000
64156 +};
64157 +
64158 +#endif
64159 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
64160 new file mode 100644
64161 index 0000000..baa6e96
64162 --- /dev/null
64163 +++ b/include/linux/grinternal.h
64164 @@ -0,0 +1,215 @@
64165 +#ifndef __GRINTERNAL_H
64166 +#define __GRINTERNAL_H
64167 +
64168 +#ifdef CONFIG_GRKERNSEC
64169 +
64170 +#include <linux/fs.h>
64171 +#include <linux/mnt_namespace.h>
64172 +#include <linux/nsproxy.h>
64173 +#include <linux/gracl.h>
64174 +#include <linux/grdefs.h>
64175 +#include <linux/grmsg.h>
64176 +
64177 +void gr_add_learn_entry(const char *fmt, ...)
64178 + __attribute__ ((format (printf, 1, 2)));
64179 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
64180 + const struct vfsmount *mnt);
64181 +__u32 gr_check_create(const struct dentry *new_dentry,
64182 + const struct dentry *parent,
64183 + const struct vfsmount *mnt, const __u32 mode);
64184 +int gr_check_protected_task(const struct task_struct *task);
64185 +__u32 to_gr_audit(const __u32 reqmode);
64186 +int gr_set_acls(const int type);
64187 +int gr_apply_subject_to_task(struct task_struct *task);
64188 +int gr_acl_is_enabled(void);
64189 +char gr_roletype_to_char(void);
64190 +
64191 +void gr_handle_alertkill(struct task_struct *task);
64192 +char *gr_to_filename(const struct dentry *dentry,
64193 + const struct vfsmount *mnt);
64194 +char *gr_to_filename1(const struct dentry *dentry,
64195 + const struct vfsmount *mnt);
64196 +char *gr_to_filename2(const struct dentry *dentry,
64197 + const struct vfsmount *mnt);
64198 +char *gr_to_filename3(const struct dentry *dentry,
64199 + const struct vfsmount *mnt);
64200 +
64201 +extern int grsec_enable_ptrace_readexec;
64202 +extern int grsec_enable_harden_ptrace;
64203 +extern int grsec_enable_link;
64204 +extern int grsec_enable_fifo;
64205 +extern int grsec_enable_execve;
64206 +extern int grsec_enable_shm;
64207 +extern int grsec_enable_execlog;
64208 +extern int grsec_enable_signal;
64209 +extern int grsec_enable_audit_ptrace;
64210 +extern int grsec_enable_forkfail;
64211 +extern int grsec_enable_time;
64212 +extern int grsec_enable_rofs;
64213 +extern int grsec_enable_chroot_shmat;
64214 +extern int grsec_enable_chroot_mount;
64215 +extern int grsec_enable_chroot_double;
64216 +extern int grsec_enable_chroot_pivot;
64217 +extern int grsec_enable_chroot_chdir;
64218 +extern int grsec_enable_chroot_chmod;
64219 +extern int grsec_enable_chroot_mknod;
64220 +extern int grsec_enable_chroot_fchdir;
64221 +extern int grsec_enable_chroot_nice;
64222 +extern int grsec_enable_chroot_execlog;
64223 +extern int grsec_enable_chroot_caps;
64224 +extern int grsec_enable_chroot_sysctl;
64225 +extern int grsec_enable_chroot_unix;
64226 +extern int grsec_enable_symlinkown;
64227 +extern int grsec_symlinkown_gid;
64228 +extern int grsec_enable_tpe;
64229 +extern int grsec_tpe_gid;
64230 +extern int grsec_enable_tpe_all;
64231 +extern int grsec_enable_tpe_invert;
64232 +extern int grsec_enable_socket_all;
64233 +extern int grsec_socket_all_gid;
64234 +extern int grsec_enable_socket_client;
64235 +extern int grsec_socket_client_gid;
64236 +extern int grsec_enable_socket_server;
64237 +extern int grsec_socket_server_gid;
64238 +extern int grsec_audit_gid;
64239 +extern int grsec_enable_group;
64240 +extern int grsec_enable_audit_textrel;
64241 +extern int grsec_enable_log_rwxmaps;
64242 +extern int grsec_enable_mount;
64243 +extern int grsec_enable_chdir;
64244 +extern int grsec_resource_logging;
64245 +extern int grsec_enable_blackhole;
64246 +extern int grsec_lastack_retries;
64247 +extern int grsec_enable_brute;
64248 +extern int grsec_lock;
64249 +
64250 +extern spinlock_t grsec_alert_lock;
64251 +extern unsigned long grsec_alert_wtime;
64252 +extern unsigned long grsec_alert_fyet;
64253 +
64254 +extern spinlock_t grsec_audit_lock;
64255 +
64256 +extern rwlock_t grsec_exec_file_lock;
64257 +
64258 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
64259 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
64260 + (tsk)->exec_file->f_vfsmnt) : "/")
64261 +
64262 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
64263 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
64264 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64265 +
64266 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
64267 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
64268 + (tsk)->exec_file->f_vfsmnt) : "/")
64269 +
64270 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
64271 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
64272 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64273 +
64274 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
64275 +
64276 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
64277 +
64278 +#define GR_CHROOT_CAPS {{ \
64279 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
64280 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
64281 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
64282 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
64283 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
64284 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
64285 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
64286 +
64287 +#define security_learn(normal_msg,args...) \
64288 +({ \
64289 + read_lock(&grsec_exec_file_lock); \
64290 + gr_add_learn_entry(normal_msg "\n", ## args); \
64291 + read_unlock(&grsec_exec_file_lock); \
64292 +})
64293 +
64294 +enum {
64295 + GR_DO_AUDIT,
64296 + GR_DONT_AUDIT,
64297 + /* used for non-audit messages that we shouldn't kill the task on */
64298 + GR_DONT_AUDIT_GOOD
64299 +};
64300 +
64301 +enum {
64302 + GR_TTYSNIFF,
64303 + GR_RBAC,
64304 + GR_RBAC_STR,
64305 + GR_STR_RBAC,
64306 + GR_RBAC_MODE2,
64307 + GR_RBAC_MODE3,
64308 + GR_FILENAME,
64309 + GR_SYSCTL_HIDDEN,
64310 + GR_NOARGS,
64311 + GR_ONE_INT,
64312 + GR_ONE_INT_TWO_STR,
64313 + GR_ONE_STR,
64314 + GR_STR_INT,
64315 + GR_TWO_STR_INT,
64316 + GR_TWO_INT,
64317 + GR_TWO_U64,
64318 + GR_THREE_INT,
64319 + GR_FIVE_INT_TWO_STR,
64320 + GR_TWO_STR,
64321 + GR_THREE_STR,
64322 + GR_FOUR_STR,
64323 + GR_STR_FILENAME,
64324 + GR_FILENAME_STR,
64325 + GR_FILENAME_TWO_INT,
64326 + GR_FILENAME_TWO_INT_STR,
64327 + GR_TEXTREL,
64328 + GR_PTRACE,
64329 + GR_RESOURCE,
64330 + GR_CAP,
64331 + GR_SIG,
64332 + GR_SIG2,
64333 + GR_CRASH1,
64334 + GR_CRASH2,
64335 + GR_PSACCT,
64336 + GR_RWXMAP
64337 +};
64338 +
64339 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
64340 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
64341 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
64342 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
64343 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
64344 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
64345 +#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)
64346 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
64347 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
64348 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
64349 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
64350 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
64351 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
64352 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
64353 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
64354 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
64355 +#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)
64356 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
64357 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
64358 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
64359 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
64360 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
64361 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
64362 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
64363 +#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)
64364 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
64365 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
64366 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
64367 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
64368 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
64369 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
64370 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
64371 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64372 +#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)
64373 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64374 +
64375 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64376 +
64377 +#endif
64378 +
64379 +#endif
64380 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64381 new file mode 100644
64382 index 0000000..2bd4c8d
64383 --- /dev/null
64384 +++ b/include/linux/grmsg.h
64385 @@ -0,0 +1,111 @@
64386 +#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"
64387 +#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"
64388 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64389 +#define GR_STOPMOD_MSG "denied modification of module state by "
64390 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64391 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64392 +#define GR_IOPERM_MSG "denied use of ioperm() by "
64393 +#define GR_IOPL_MSG "denied use of iopl() by "
64394 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64395 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64396 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64397 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64398 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64399 +#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"
64400 +#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"
64401 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64402 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64403 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64404 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64405 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64406 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64407 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64408 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64409 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64410 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64411 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64412 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64413 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64414 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64415 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64416 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64417 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64418 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64419 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64420 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64421 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64422 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64423 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64424 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64425 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64426 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64427 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64428 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64429 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64430 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64431 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64432 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64433 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64434 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64435 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64436 +#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"
64437 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64438 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64439 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64440 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64441 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64442 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64443 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64444 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64445 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64446 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64447 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64448 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64449 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64450 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64451 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64452 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64453 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64454 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64455 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64456 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64457 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
64458 +#define GR_NICE_CHROOT_MSG "denied priority change by "
64459 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64460 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64461 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64462 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64463 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64464 +#define GR_TIME_MSG "time set by "
64465 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64466 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64467 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64468 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64469 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64470 +#define GR_BIND_MSG "denied bind() by "
64471 +#define GR_CONNECT_MSG "denied connect() by "
64472 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64473 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64474 +#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"
64475 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64476 +#define GR_CAP_ACL_MSG "use of %s denied for "
64477 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64478 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64479 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64480 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64481 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64482 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64483 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64484 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64485 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64486 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64487 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64488 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64489 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64490 +#define GR_VM86_MSG "denied use of vm86 by "
64491 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64492 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64493 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64494 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64495 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64496 +#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 "
64497 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64498 new file mode 100644
64499 index 0000000..c5e5913
64500 --- /dev/null
64501 +++ b/include/linux/grsecurity.h
64502 @@ -0,0 +1,257 @@
64503 +#ifndef GR_SECURITY_H
64504 +#define GR_SECURITY_H
64505 +#include <linux/fs.h>
64506 +#include <linux/fs_struct.h>
64507 +#include <linux/binfmts.h>
64508 +#include <linux/gracl.h>
64509 +
64510 +/* notify of brain-dead configs */
64511 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64512 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64513 +#endif
64514 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64515 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64516 +#endif
64517 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64518 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64519 +#endif
64520 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64521 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
64522 +#endif
64523 +
64524 +#include <linux/compat.h>
64525 +
64526 +struct user_arg_ptr {
64527 +#ifdef CONFIG_COMPAT
64528 + bool is_compat;
64529 +#endif
64530 + union {
64531 + const char __user *const __user *native;
64532 +#ifdef CONFIG_COMPAT
64533 + const compat_uptr_t __user *compat;
64534 +#endif
64535 + } ptr;
64536 +};
64537 +
64538 +void gr_handle_brute_attach(unsigned long mm_flags);
64539 +void gr_handle_brute_check(void);
64540 +void gr_handle_kernel_exploit(void);
64541 +int gr_process_user_ban(void);
64542 +
64543 +char gr_roletype_to_char(void);
64544 +
64545 +int gr_acl_enable_at_secure(void);
64546 +
64547 +int gr_check_user_change(int real, int effective, int fs);
64548 +int gr_check_group_change(int real, int effective, int fs);
64549 +
64550 +void gr_del_task_from_ip_table(struct task_struct *p);
64551 +
64552 +int gr_pid_is_chrooted(struct task_struct *p);
64553 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64554 +int gr_handle_chroot_nice(void);
64555 +int gr_handle_chroot_sysctl(const int op);
64556 +int gr_handle_chroot_setpriority(struct task_struct *p,
64557 + const int niceval);
64558 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64559 +int gr_handle_chroot_chroot(const struct dentry *dentry,
64560 + const struct vfsmount *mnt);
64561 +void gr_handle_chroot_chdir(struct path *path);
64562 +int gr_handle_chroot_chmod(const struct dentry *dentry,
64563 + const struct vfsmount *mnt, const int mode);
64564 +int gr_handle_chroot_mknod(const struct dentry *dentry,
64565 + const struct vfsmount *mnt, const int mode);
64566 +int gr_handle_chroot_mount(const struct dentry *dentry,
64567 + const struct vfsmount *mnt,
64568 + const char *dev_name);
64569 +int gr_handle_chroot_pivot(void);
64570 +int gr_handle_chroot_unix(const pid_t pid);
64571 +
64572 +int gr_handle_rawio(const struct inode *inode);
64573 +
64574 +void gr_handle_ioperm(void);
64575 +void gr_handle_iopl(void);
64576 +
64577 +umode_t gr_acl_umask(void);
64578 +
64579 +int gr_tpe_allow(const struct file *file);
64580 +
64581 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64582 +void gr_clear_chroot_entries(struct task_struct *task);
64583 +
64584 +void gr_log_forkfail(const int retval);
64585 +void gr_log_timechange(void);
64586 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64587 +void gr_log_chdir(const struct dentry *dentry,
64588 + const struct vfsmount *mnt);
64589 +void gr_log_chroot_exec(const struct dentry *dentry,
64590 + const struct vfsmount *mnt);
64591 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64592 +void gr_log_remount(const char *devname, const int retval);
64593 +void gr_log_unmount(const char *devname, const int retval);
64594 +void gr_log_mount(const char *from, const char *to, const int retval);
64595 +void gr_log_textrel(struct vm_area_struct *vma);
64596 +void gr_log_rwxmmap(struct file *file);
64597 +void gr_log_rwxmprotect(struct file *file);
64598 +
64599 +int gr_handle_follow_link(const struct inode *parent,
64600 + const struct inode *inode,
64601 + const struct dentry *dentry,
64602 + const struct vfsmount *mnt);
64603 +int gr_handle_fifo(const struct dentry *dentry,
64604 + const struct vfsmount *mnt,
64605 + const struct dentry *dir, const int flag,
64606 + const int acc_mode);
64607 +int gr_handle_hardlink(const struct dentry *dentry,
64608 + const struct vfsmount *mnt,
64609 + struct inode *inode,
64610 + const int mode, const struct filename *to);
64611 +
64612 +int gr_is_capable(const int cap);
64613 +int gr_is_capable_nolog(const int cap);
64614 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64615 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64616 +
64617 +void gr_copy_label(struct task_struct *tsk);
64618 +void gr_handle_crash(struct task_struct *task, const int sig);
64619 +int gr_handle_signal(const struct task_struct *p, const int sig);
64620 +int gr_check_crash_uid(const uid_t uid);
64621 +int gr_check_protected_task(const struct task_struct *task);
64622 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64623 +int gr_acl_handle_mmap(const struct file *file,
64624 + const unsigned long prot);
64625 +int gr_acl_handle_mprotect(const struct file *file,
64626 + const unsigned long prot);
64627 +int gr_check_hidden_task(const struct task_struct *tsk);
64628 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64629 + const struct vfsmount *mnt);
64630 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
64631 + const struct vfsmount *mnt);
64632 +__u32 gr_acl_handle_access(const struct dentry *dentry,
64633 + const struct vfsmount *mnt, const int fmode);
64634 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64635 + const struct vfsmount *mnt, umode_t *mode);
64636 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
64637 + const struct vfsmount *mnt);
64638 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64639 + const struct vfsmount *mnt);
64640 +int gr_handle_ptrace(struct task_struct *task, const long request);
64641 +int gr_handle_proc_ptrace(struct task_struct *task);
64642 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
64643 + const struct vfsmount *mnt);
64644 +int gr_check_crash_exec(const struct file *filp);
64645 +int gr_acl_is_enabled(void);
64646 +void gr_set_kernel_label(struct task_struct *task);
64647 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
64648 + const gid_t gid);
64649 +int gr_set_proc_label(const struct dentry *dentry,
64650 + const struct vfsmount *mnt,
64651 + const int unsafe_flags);
64652 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64653 + const struct vfsmount *mnt);
64654 +__u32 gr_acl_handle_open(const struct dentry *dentry,
64655 + const struct vfsmount *mnt, int acc_mode);
64656 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
64657 + const struct dentry *p_dentry,
64658 + const struct vfsmount *p_mnt,
64659 + int open_flags, int acc_mode, const int imode);
64660 +void gr_handle_create(const struct dentry *dentry,
64661 + const struct vfsmount *mnt);
64662 +void gr_handle_proc_create(const struct dentry *dentry,
64663 + const struct inode *inode);
64664 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64665 + const struct dentry *parent_dentry,
64666 + const struct vfsmount *parent_mnt,
64667 + const int mode);
64668 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64669 + const struct dentry *parent_dentry,
64670 + const struct vfsmount *parent_mnt);
64671 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64672 + const struct vfsmount *mnt);
64673 +void gr_handle_delete(const ino_t ino, const dev_t dev);
64674 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64675 + const struct vfsmount *mnt);
64676 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64677 + const struct dentry *parent_dentry,
64678 + const struct vfsmount *parent_mnt,
64679 + const struct filename *from);
64680 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64681 + const struct dentry *parent_dentry,
64682 + const struct vfsmount *parent_mnt,
64683 + const struct dentry *old_dentry,
64684 + const struct vfsmount *old_mnt, const struct filename *to);
64685 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64686 +int gr_acl_handle_rename(struct dentry *new_dentry,
64687 + struct dentry *parent_dentry,
64688 + const struct vfsmount *parent_mnt,
64689 + struct dentry *old_dentry,
64690 + struct inode *old_parent_inode,
64691 + struct vfsmount *old_mnt, const struct filename *newname);
64692 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64693 + struct dentry *old_dentry,
64694 + struct dentry *new_dentry,
64695 + struct vfsmount *mnt, const __u8 replace);
64696 +__u32 gr_check_link(const struct dentry *new_dentry,
64697 + const struct dentry *parent_dentry,
64698 + const struct vfsmount *parent_mnt,
64699 + const struct dentry *old_dentry,
64700 + const struct vfsmount *old_mnt);
64701 +int gr_acl_handle_filldir(const struct file *file, const char *name,
64702 + const unsigned int namelen, const ino_t ino);
64703 +
64704 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
64705 + const struct vfsmount *mnt);
64706 +void gr_acl_handle_exit(void);
64707 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
64708 +int gr_acl_handle_procpidmem(const struct task_struct *task);
64709 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64710 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64711 +void gr_audit_ptrace(struct task_struct *task);
64712 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64713 +void gr_put_exec_file(struct task_struct *task);
64714 +
64715 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64716 +
64717 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
64718 +extern void gr_learn_resource(const struct task_struct *task, const int res,
64719 + const unsigned long wanted, const int gt);
64720 +#else
64721 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
64722 + const unsigned long wanted, const int gt)
64723 +{
64724 +}
64725 +#endif
64726 +
64727 +#ifdef CONFIG_GRKERNSEC_RESLOG
64728 +extern void gr_log_resource(const struct task_struct *task, const int res,
64729 + const unsigned long wanted, const int gt);
64730 +#else
64731 +static inline void gr_log_resource(const struct task_struct *task, const int res,
64732 + const unsigned long wanted, const int gt)
64733 +{
64734 +}
64735 +#endif
64736 +
64737 +#ifdef CONFIG_GRKERNSEC
64738 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64739 +void gr_handle_vm86(void);
64740 +void gr_handle_mem_readwrite(u64 from, u64 to);
64741 +
64742 +void gr_log_badprocpid(const char *entry);
64743 +
64744 +extern int grsec_enable_dmesg;
64745 +extern int grsec_disable_privio;
64746 +
64747 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64748 +extern int grsec_proc_gid;
64749 +#endif
64750 +
64751 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64752 +extern int grsec_enable_chroot_findtask;
64753 +#endif
64754 +#ifdef CONFIG_GRKERNSEC_SETXID
64755 +extern int grsec_enable_setxid;
64756 +#endif
64757 +#endif
64758 +
64759 +#endif
64760 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64761 new file mode 100644
64762 index 0000000..e7ffaaf
64763 --- /dev/null
64764 +++ b/include/linux/grsock.h
64765 @@ -0,0 +1,19 @@
64766 +#ifndef __GRSOCK_H
64767 +#define __GRSOCK_H
64768 +
64769 +extern void gr_attach_curr_ip(const struct sock *sk);
64770 +extern int gr_handle_sock_all(const int family, const int type,
64771 + const int protocol);
64772 +extern int gr_handle_sock_server(const struct sockaddr *sck);
64773 +extern int gr_handle_sock_server_other(const struct sock *sck);
64774 +extern int gr_handle_sock_client(const struct sockaddr *sck);
64775 +extern int gr_search_connect(struct socket * sock,
64776 + struct sockaddr_in * addr);
64777 +extern int gr_search_bind(struct socket * sock,
64778 + struct sockaddr_in * addr);
64779 +extern int gr_search_listen(struct socket * sock);
64780 +extern int gr_search_accept(struct socket * sock);
64781 +extern int gr_search_socket(const int domain, const int type,
64782 + const int protocol);
64783 +
64784 +#endif
64785 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64786 index ef788b5..ac41b7b 100644
64787 --- a/include/linux/highmem.h
64788 +++ b/include/linux/highmem.h
64789 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64790 kunmap_atomic(kaddr);
64791 }
64792
64793 +static inline void sanitize_highpage(struct page *page)
64794 +{
64795 + void *kaddr;
64796 + unsigned long flags;
64797 +
64798 + local_irq_save(flags);
64799 + kaddr = kmap_atomic(page);
64800 + clear_page(kaddr);
64801 + kunmap_atomic(kaddr);
64802 + local_irq_restore(flags);
64803 +}
64804 +
64805 static inline void zero_user_segments(struct page *page,
64806 unsigned start1, unsigned end1,
64807 unsigned start2, unsigned end2)
64808 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64809 index 800de22..7a2fa46 100644
64810 --- a/include/linux/i2c.h
64811 +++ b/include/linux/i2c.h
64812 @@ -367,6 +367,7 @@ struct i2c_algorithm {
64813 /* To determine what the adapter supports */
64814 u32 (*functionality) (struct i2c_adapter *);
64815 };
64816 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64817
64818 /*
64819 * i2c_adapter is the structure used to identify a physical i2c bus along
64820 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64821 index d23c3c2..eb63c81 100644
64822 --- a/include/linux/i2o.h
64823 +++ b/include/linux/i2o.h
64824 @@ -565,7 +565,7 @@ struct i2o_controller {
64825 struct i2o_device *exec; /* Executive */
64826 #if BITS_PER_LONG == 64
64827 spinlock_t context_list_lock; /* lock for context_list */
64828 - atomic_t context_list_counter; /* needed for unique contexts */
64829 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64830 struct list_head context_list; /* list of context id's
64831 and pointers */
64832 #endif
64833 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64834 index aff7ad8..3942bbd 100644
64835 --- a/include/linux/if_pppox.h
64836 +++ b/include/linux/if_pppox.h
64837 @@ -76,7 +76,7 @@ struct pppox_proto {
64838 int (*ioctl)(struct socket *sock, unsigned int cmd,
64839 unsigned long arg);
64840 struct module *owner;
64841 -};
64842 +} __do_const;
64843
64844 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64845 extern void unregister_pppox_proto(int proto_num);
64846 diff --git a/include/linux/init.h b/include/linux/init.h
64847 index e59041e..df0a975 100644
64848 --- a/include/linux/init.h
64849 +++ b/include/linux/init.h
64850 @@ -39,9 +39,36 @@
64851 * Also note, that this data cannot be "const".
64852 */
64853
64854 +#ifdef MODULE
64855 +#define add_init_latent_entropy
64856 +#define add_devinit_latent_entropy
64857 +#define add_cpuinit_latent_entropy
64858 +#define add_meminit_latent_entropy
64859 +#else
64860 +#define add_init_latent_entropy __latent_entropy
64861 +
64862 +#ifdef CONFIG_HOTPLUG
64863 +#define add_devinit_latent_entropy
64864 +#else
64865 +#define add_devinit_latent_entropy __latent_entropy
64866 +#endif
64867 +
64868 +#ifdef CONFIG_HOTPLUG_CPU
64869 +#define add_cpuinit_latent_entropy
64870 +#else
64871 +#define add_cpuinit_latent_entropy __latent_entropy
64872 +#endif
64873 +
64874 +#ifdef CONFIG_MEMORY_HOTPLUG
64875 +#define add_meminit_latent_entropy
64876 +#else
64877 +#define add_meminit_latent_entropy __latent_entropy
64878 +#endif
64879 +#endif
64880 +
64881 /* These are for everybody (although not all archs will actually
64882 discard it in modules) */
64883 -#define __init __section(.init.text) __cold notrace
64884 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64885 #define __initdata __section(.init.data)
64886 #define __initconst __constsection(.init.rodata)
64887 #define __exitdata __section(.exit.data)
64888 @@ -94,7 +121,7 @@
64889 #define __exit __section(.exit.text) __exitused __cold notrace
64890
64891 /* Used for HOTPLUG */
64892 -#define __devinit __section(.devinit.text) __cold notrace
64893 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64894 #define __devinitdata __section(.devinit.data)
64895 #define __devinitconst __constsection(.devinit.rodata)
64896 #define __devexit __section(.devexit.text) __exitused __cold notrace
64897 @@ -102,7 +129,7 @@
64898 #define __devexitconst __constsection(.devexit.rodata)
64899
64900 /* Used for HOTPLUG_CPU */
64901 -#define __cpuinit __section(.cpuinit.text) __cold notrace
64902 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64903 #define __cpuinitdata __section(.cpuinit.data)
64904 #define __cpuinitconst __constsection(.cpuinit.rodata)
64905 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64906 @@ -110,7 +137,7 @@
64907 #define __cpuexitconst __constsection(.cpuexit.rodata)
64908
64909 /* Used for MEMORY_HOTPLUG */
64910 -#define __meminit __section(.meminit.text) __cold notrace
64911 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64912 #define __meminitdata __section(.meminit.data)
64913 #define __meminitconst __constsection(.meminit.rodata)
64914 #define __memexit __section(.memexit.text) __exitused __cold notrace
64915 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64916 index 6d087c5..401cab8 100644
64917 --- a/include/linux/init_task.h
64918 +++ b/include/linux/init_task.h
64919 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64920
64921 #define INIT_TASK_COMM "swapper"
64922
64923 +#ifdef CONFIG_X86
64924 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64925 +#else
64926 +#define INIT_TASK_THREAD_INFO
64927 +#endif
64928 +
64929 /*
64930 * INIT_TASK is used to set up the first task table, touch at
64931 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64932 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64933 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64934 .comm = INIT_TASK_COMM, \
64935 .thread = INIT_THREAD, \
64936 + INIT_TASK_THREAD_INFO \
64937 .fs = &init_fs, \
64938 .files = &init_files, \
64939 .signal = &init_signals, \
64940 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64941 index 5e4e617..eee383d 100644
64942 --- a/include/linux/interrupt.h
64943 +++ b/include/linux/interrupt.h
64944 @@ -435,7 +435,7 @@ enum
64945 /* map softirq index to softirq name. update 'softirq_to_name' in
64946 * kernel/softirq.c when adding a new softirq.
64947 */
64948 -extern char *softirq_to_name[NR_SOFTIRQS];
64949 +extern const char * const softirq_to_name[NR_SOFTIRQS];
64950
64951 /* softirq mask and active fields moved to irq_cpustat_t in
64952 * asm/hardirq.h to get better cache usage. KAO
64953 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
64954
64955 struct softirq_action
64956 {
64957 - void (*action)(struct softirq_action *);
64958 + void (*action)(void);
64959 };
64960
64961 asmlinkage void do_softirq(void);
64962 asmlinkage void __do_softirq(void);
64963 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
64964 +extern void open_softirq(int nr, void (*action)(void));
64965 extern void softirq_init(void);
64966 extern void __raise_softirq_irqoff(unsigned int nr);
64967
64968 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
64969 index 6883e19..06992b1 100644
64970 --- a/include/linux/kallsyms.h
64971 +++ b/include/linux/kallsyms.h
64972 @@ -15,7 +15,8 @@
64973
64974 struct module;
64975
64976 -#ifdef CONFIG_KALLSYMS
64977 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
64978 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64979 /* Lookup the address for a symbol. Returns 0 if not found. */
64980 unsigned long kallsyms_lookup_name(const char *name);
64981
64982 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
64983 /* Stupid that this does nothing, but I didn't create this mess. */
64984 #define __print_symbol(fmt, addr)
64985 #endif /*CONFIG_KALLSYMS*/
64986 +#else /* when included by kallsyms.c, vsnprintf.c, or
64987 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
64988 +extern void __print_symbol(const char *fmt, unsigned long address);
64989 +extern int sprint_backtrace(char *buffer, unsigned long address);
64990 +extern int sprint_symbol(char *buffer, unsigned long address);
64991 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
64992 +const char *kallsyms_lookup(unsigned long addr,
64993 + unsigned long *symbolsize,
64994 + unsigned long *offset,
64995 + char **modname, char *namebuf);
64996 +#endif
64997
64998 /* This macro allows us to keep printk typechecking */
64999 static __printf(1, 2)
65000 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65001 index 4dff0c6..1ca9b72 100644
65002 --- a/include/linux/kgdb.h
65003 +++ b/include/linux/kgdb.h
65004 @@ -53,7 +53,7 @@ extern int kgdb_connected;
65005 extern int kgdb_io_module_registered;
65006
65007 extern atomic_t kgdb_setting_breakpoint;
65008 -extern atomic_t kgdb_cpu_doing_single_step;
65009 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65010
65011 extern struct task_struct *kgdb_usethread;
65012 extern struct task_struct *kgdb_contthread;
65013 @@ -255,7 +255,7 @@ struct kgdb_arch {
65014 void (*correct_hw_break)(void);
65015
65016 void (*enable_nmi)(bool on);
65017 -};
65018 +} __do_const;
65019
65020 /**
65021 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65022 @@ -280,7 +280,7 @@ struct kgdb_io {
65023 void (*pre_exception) (void);
65024 void (*post_exception) (void);
65025 int is_console;
65026 -};
65027 +} __do_const;
65028
65029 extern struct kgdb_arch arch_kgdb_ops;
65030
65031 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65032 index 5398d58..5883a34 100644
65033 --- a/include/linux/kmod.h
65034 +++ b/include/linux/kmod.h
65035 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65036 * usually useless though. */
65037 extern __printf(2, 3)
65038 int __request_module(bool wait, const char *name, ...);
65039 +extern __printf(3, 4)
65040 +int ___request_module(bool wait, char *param_name, const char *name, ...);
65041 #define request_module(mod...) __request_module(true, mod)
65042 #define request_module_nowait(mod...) __request_module(false, mod)
65043 #define try_then_request_module(x, mod...) \
65044 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65045 index 1e57449..4fede7b 100644
65046 --- a/include/linux/kobject.h
65047 +++ b/include/linux/kobject.h
65048 @@ -111,7 +111,7 @@ struct kobj_type {
65049 struct attribute **default_attrs;
65050 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65051 const void *(*namespace)(struct kobject *kobj);
65052 -};
65053 +} __do_const;
65054
65055 struct kobj_uevent_env {
65056 char *envp[UEVENT_NUM_ENVP];
65057 diff --git a/include/linux/kref.h b/include/linux/kref.h
65058 index 65af688..0592677 100644
65059 --- a/include/linux/kref.h
65060 +++ b/include/linux/kref.h
65061 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65062 static inline int kref_sub(struct kref *kref, unsigned int count,
65063 void (*release)(struct kref *kref))
65064 {
65065 - WARN_ON(release == NULL);
65066 + BUG_ON(release == NULL);
65067
65068 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65069 release(kref);
65070 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65071 index ecc5543..0e96bcc 100644
65072 --- a/include/linux/kvm_host.h
65073 +++ b/include/linux/kvm_host.h
65074 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65075 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65076 void vcpu_put(struct kvm_vcpu *vcpu);
65077
65078 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65079 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65080 struct module *module);
65081 void kvm_exit(void);
65082
65083 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65084 struct kvm_guest_debug *dbg);
65085 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65086
65087 -int kvm_arch_init(void *opaque);
65088 +int kvm_arch_init(const void *opaque);
65089 void kvm_arch_exit(void);
65090
65091 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65092 diff --git a/include/linux/libata.h b/include/linux/libata.h
65093 index 1e36c63..0c5046e 100644
65094 --- a/include/linux/libata.h
65095 +++ b/include/linux/libata.h
65096 @@ -915,7 +915,7 @@ struct ata_port_operations {
65097 * fields must be pointers.
65098 */
65099 const struct ata_port_operations *inherits;
65100 -};
65101 +} __do_const;
65102
65103 struct ata_port_info {
65104 unsigned long flags;
65105 diff --git a/include/linux/list.h b/include/linux/list.h
65106 index cc6d2aa..71febca 100644
65107 --- a/include/linux/list.h
65108 +++ b/include/linux/list.h
65109 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65110 extern void list_del(struct list_head *entry);
65111 #endif
65112
65113 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65114 +extern void pax_list_del(struct list_head *entry);
65115 +
65116 /**
65117 * list_replace - replace old entry by new one
65118 * @old : the element to be replaced
65119 diff --git a/include/linux/mm.h b/include/linux/mm.h
65120 index 280dae5..39046ec 100644
65121 --- a/include/linux/mm.h
65122 +++ b/include/linux/mm.h
65123 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
65124 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
65125 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
65126 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
65127 +
65128 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
65129 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
65130 +#endif
65131 +
65132 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
65133
65134 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
65135 @@ -1039,34 +1044,6 @@ int set_page_dirty(struct page *page);
65136 int set_page_dirty_lock(struct page *page);
65137 int clear_page_dirty_for_io(struct page *page);
65138
65139 -/* Is the vma a continuation of the stack vma above it? */
65140 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
65141 -{
65142 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
65143 -}
65144 -
65145 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
65146 - unsigned long addr)
65147 -{
65148 - return (vma->vm_flags & VM_GROWSDOWN) &&
65149 - (vma->vm_start == addr) &&
65150 - !vma_growsdown(vma->vm_prev, addr);
65151 -}
65152 -
65153 -/* Is the vma a continuation of the stack vma below it? */
65154 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
65155 -{
65156 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
65157 -}
65158 -
65159 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
65160 - unsigned long addr)
65161 -{
65162 - return (vma->vm_flags & VM_GROWSUP) &&
65163 - (vma->vm_end == addr) &&
65164 - !vma_growsup(vma->vm_next, addr);
65165 -}
65166 -
65167 extern pid_t
65168 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
65169
65170 @@ -1166,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
65171 }
65172 #endif
65173
65174 +#ifdef CONFIG_MMU
65175 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
65176 +#else
65177 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
65178 +{
65179 + return __pgprot(0);
65180 +}
65181 +#endif
65182 +
65183 int vma_wants_writenotify(struct vm_area_struct *vma);
65184
65185 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
65186 @@ -1184,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
65187 {
65188 return 0;
65189 }
65190 +
65191 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
65192 + unsigned long address)
65193 +{
65194 + return 0;
65195 +}
65196 #else
65197 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65198 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65199 #endif
65200
65201 #ifdef __PAGETABLE_PMD_FOLDED
65202 @@ -1194,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
65203 {
65204 return 0;
65205 }
65206 +
65207 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
65208 + unsigned long address)
65209 +{
65210 + return 0;
65211 +}
65212 #else
65213 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
65214 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
65215 #endif
65216
65217 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
65218 @@ -1213,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
65219 NULL: pud_offset(pgd, address);
65220 }
65221
65222 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
65223 +{
65224 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
65225 + NULL: pud_offset(pgd, address);
65226 +}
65227 +
65228 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
65229 {
65230 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
65231 NULL: pmd_offset(pud, address);
65232 }
65233 +
65234 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
65235 +{
65236 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
65237 + NULL: pmd_offset(pud, address);
65238 +}
65239 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
65240
65241 #if USE_SPLIT_PTLOCKS
65242 @@ -1447,6 +1459,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
65243 unsigned long, unsigned long,
65244 unsigned long, unsigned long);
65245 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
65246 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
65247
65248 /* These take the mm semaphore themselves */
65249 extern unsigned long vm_brk(unsigned long, unsigned long);
65250 @@ -1510,6 +1523,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
65251 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
65252 struct vm_area_struct **pprev);
65253
65254 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
65255 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
65256 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
65257 +
65258 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
65259 NULL if none. Assume start_addr < end_addr. */
65260 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
65261 @@ -1538,15 +1555,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
65262 return vma;
65263 }
65264
65265 -#ifdef CONFIG_MMU
65266 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
65267 -#else
65268 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
65269 -{
65270 - return __pgprot(0);
65271 -}
65272 -#endif
65273 -
65274 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
65275 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
65276 unsigned long pfn, unsigned long size, pgprot_t);
65277 @@ -1652,7 +1660,7 @@ extern int unpoison_memory(unsigned long pfn);
65278 extern int sysctl_memory_failure_early_kill;
65279 extern int sysctl_memory_failure_recovery;
65280 extern void shake_page(struct page *p, int access);
65281 -extern atomic_long_t mce_bad_pages;
65282 +extern atomic_long_unchecked_t mce_bad_pages;
65283 extern int soft_offline_page(struct page *page, int flags);
65284
65285 extern void dump_page(struct page *page);
65286 @@ -1683,5 +1691,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
65287 static inline bool page_is_guard(struct page *page) { return false; }
65288 #endif /* CONFIG_DEBUG_PAGEALLOC */
65289
65290 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65291 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
65292 +#else
65293 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
65294 +#endif
65295 +
65296 #endif /* __KERNEL__ */
65297 #endif /* _LINUX_MM_H */
65298 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
65299 index 31f8a3a..499f1db 100644
65300 --- a/include/linux/mm_types.h
65301 +++ b/include/linux/mm_types.h
65302 @@ -275,6 +275,8 @@ struct vm_area_struct {
65303 #ifdef CONFIG_NUMA
65304 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
65305 #endif
65306 +
65307 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
65308 };
65309
65310 struct core_thread {
65311 @@ -348,7 +350,7 @@ struct mm_struct {
65312 unsigned long def_flags;
65313 unsigned long nr_ptes; /* Page table pages */
65314 unsigned long start_code, end_code, start_data, end_data;
65315 - unsigned long start_brk, brk, start_stack;
65316 + unsigned long brk_gap, start_brk, brk, start_stack;
65317 unsigned long arg_start, arg_end, env_start, env_end;
65318
65319 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
65320 @@ -399,6 +401,24 @@ struct mm_struct {
65321 struct cpumask cpumask_allocation;
65322 #endif
65323 struct uprobes_state uprobes_state;
65324 +
65325 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65326 + unsigned long pax_flags;
65327 +#endif
65328 +
65329 +#ifdef CONFIG_PAX_DLRESOLVE
65330 + unsigned long call_dl_resolve;
65331 +#endif
65332 +
65333 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
65334 + unsigned long call_syscall;
65335 +#endif
65336 +
65337 +#ifdef CONFIG_PAX_ASLR
65338 + unsigned long delta_mmap; /* randomized offset */
65339 + unsigned long delta_stack; /* randomized offset */
65340 +#endif
65341 +
65342 };
65343
65344 static inline void mm_init_cpumask(struct mm_struct *mm)
65345 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
65346 index c5d5278..f0b68c8 100644
65347 --- a/include/linux/mmiotrace.h
65348 +++ b/include/linux/mmiotrace.h
65349 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
65350 /* Called from ioremap.c */
65351 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
65352 void __iomem *addr);
65353 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
65354 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
65355
65356 /* For anyone to insert markers. Remember trailing newline. */
65357 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
65358 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
65359 {
65360 }
65361
65362 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65363 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65364 {
65365 }
65366
65367 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65368 index a23923b..073fee4 100644
65369 --- a/include/linux/mmzone.h
65370 +++ b/include/linux/mmzone.h
65371 @@ -421,7 +421,7 @@ struct zone {
65372 unsigned long flags; /* zone flags, see below */
65373
65374 /* Zone statistics */
65375 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65376 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65377
65378 /*
65379 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65380 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65381 index fed3def..7cc3f93 100644
65382 --- a/include/linux/mod_devicetable.h
65383 +++ b/include/linux/mod_devicetable.h
65384 @@ -12,7 +12,7 @@
65385 typedef unsigned long kernel_ulong_t;
65386 #endif
65387
65388 -#define PCI_ANY_ID (~0)
65389 +#define PCI_ANY_ID ((__u16)~0)
65390
65391 struct pci_device_id {
65392 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65393 @@ -139,7 +139,7 @@ struct usb_device_id {
65394 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65395 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65396
65397 -#define HID_ANY_ID (~0)
65398 +#define HID_ANY_ID (~0U)
65399 #define HID_BUS_ANY 0xffff
65400 #define HID_GROUP_ANY 0x0000
65401
65402 diff --git a/include/linux/module.h b/include/linux/module.h
65403 index 1375ee3..d631af0 100644
65404 --- a/include/linux/module.h
65405 +++ b/include/linux/module.h
65406 @@ -17,9 +17,11 @@
65407 #include <linux/moduleparam.h>
65408 #include <linux/tracepoint.h>
65409 #include <linux/export.h>
65410 +#include <linux/fs.h>
65411
65412 #include <linux/percpu.h>
65413 #include <asm/module.h>
65414 +#include <asm/pgtable.h>
65415
65416 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65417 #define MODULE_SIG_STRING "~Module signature appended~\n"
65418 @@ -281,19 +283,16 @@ struct module
65419 int (*init)(void);
65420
65421 /* If this is non-NULL, vfree after init() returns */
65422 - void *module_init;
65423 + void *module_init_rx, *module_init_rw;
65424
65425 /* Here is the actual code + data, vfree'd on unload. */
65426 - void *module_core;
65427 + void *module_core_rx, *module_core_rw;
65428
65429 /* Here are the sizes of the init and core sections */
65430 - unsigned int init_size, core_size;
65431 + unsigned int init_size_rw, core_size_rw;
65432
65433 /* The size of the executable code in each section. */
65434 - unsigned int init_text_size, core_text_size;
65435 -
65436 - /* Size of RO sections of the module (text+rodata) */
65437 - unsigned int init_ro_size, core_ro_size;
65438 + unsigned int init_size_rx, core_size_rx;
65439
65440 /* Arch-specific module values */
65441 struct mod_arch_specific arch;
65442 @@ -349,6 +348,10 @@ struct module
65443 #ifdef CONFIG_EVENT_TRACING
65444 struct ftrace_event_call **trace_events;
65445 unsigned int num_trace_events;
65446 + struct file_operations trace_id;
65447 + struct file_operations trace_enable;
65448 + struct file_operations trace_format;
65449 + struct file_operations trace_filter;
65450 #endif
65451 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65452 unsigned int num_ftrace_callsites;
65453 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65454 bool is_module_percpu_address(unsigned long addr);
65455 bool is_module_text_address(unsigned long addr);
65456
65457 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65458 +{
65459 +
65460 +#ifdef CONFIG_PAX_KERNEXEC
65461 + if (ktla_ktva(addr) >= (unsigned long)start &&
65462 + ktla_ktva(addr) < (unsigned long)start + size)
65463 + return 1;
65464 +#endif
65465 +
65466 + return ((void *)addr >= start && (void *)addr < start + size);
65467 +}
65468 +
65469 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65470 +{
65471 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65472 +}
65473 +
65474 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65475 +{
65476 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65477 +}
65478 +
65479 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65480 +{
65481 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65482 +}
65483 +
65484 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65485 +{
65486 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65487 +}
65488 +
65489 static inline int within_module_core(unsigned long addr, struct module *mod)
65490 {
65491 - return (unsigned long)mod->module_core <= addr &&
65492 - addr < (unsigned long)mod->module_core + mod->core_size;
65493 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65494 }
65495
65496 static inline int within_module_init(unsigned long addr, struct module *mod)
65497 {
65498 - return (unsigned long)mod->module_init <= addr &&
65499 - addr < (unsigned long)mod->module_init + mod->init_size;
65500 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65501 }
65502
65503 /* Search for module by name: must hold module_mutex. */
65504 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65505 index 560ca53..5ee8d73 100644
65506 --- a/include/linux/moduleloader.h
65507 +++ b/include/linux/moduleloader.h
65508 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65509
65510 /* Allocator used for allocating struct module, core sections and init
65511 sections. Returns NULL on failure. */
65512 -void *module_alloc(unsigned long size);
65513 +void *module_alloc(unsigned long size) __size_overflow(1);
65514 +
65515 +#ifdef CONFIG_PAX_KERNEXEC
65516 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
65517 +#else
65518 +#define module_alloc_exec(x) module_alloc(x)
65519 +#endif
65520
65521 /* Free memory returned from module_alloc. */
65522 void module_free(struct module *mod, void *module_region);
65523
65524 +#ifdef CONFIG_PAX_KERNEXEC
65525 +void module_free_exec(struct module *mod, void *module_region);
65526 +#else
65527 +#define module_free_exec(x, y) module_free((x), (y))
65528 +#endif
65529 +
65530 /*
65531 * Apply the given relocation to the (simplified) ELF. Return -error
65532 * or 0.
65533 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65534 unsigned int relsec,
65535 struct module *me)
65536 {
65537 +#ifdef CONFIG_MODULES
65538 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65539 +#endif
65540 return -ENOEXEC;
65541 }
65542 #endif
65543 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65544 unsigned int relsec,
65545 struct module *me)
65546 {
65547 +#ifdef CONFIG_MODULES
65548 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65549 +#endif
65550 return -ENOEXEC;
65551 }
65552 #endif
65553 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65554 index d6a5806..7c13347 100644
65555 --- a/include/linux/moduleparam.h
65556 +++ b/include/linux/moduleparam.h
65557 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65558 * @len is usually just sizeof(string).
65559 */
65560 #define module_param_string(name, string, len, perm) \
65561 - static const struct kparam_string __param_string_##name \
65562 + static const struct kparam_string __param_string_##name __used \
65563 = { len, string }; \
65564 __module_param_call(MODULE_PARAM_PREFIX, name, \
65565 &param_ops_string, \
65566 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65567 */
65568 #define module_param_array_named(name, array, type, nump, perm) \
65569 param_check_##type(name, &(array)[0]); \
65570 - static const struct kparam_array __param_arr_##name \
65571 + static const struct kparam_array __param_arr_##name __used \
65572 = { .max = ARRAY_SIZE(array), .num = nump, \
65573 .ops = &param_ops_##type, \
65574 .elemsize = sizeof(array[0]), .elem = array }; \
65575 diff --git a/include/linux/namei.h b/include/linux/namei.h
65576 index 4bf19d8..5268cea 100644
65577 --- a/include/linux/namei.h
65578 +++ b/include/linux/namei.h
65579 @@ -18,7 +18,7 @@ struct nameidata {
65580 unsigned seq;
65581 int last_type;
65582 unsigned depth;
65583 - char *saved_names[MAX_NESTED_LINKS + 1];
65584 + const char *saved_names[MAX_NESTED_LINKS + 1];
65585 };
65586
65587 /*
65588 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65589
65590 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65591
65592 -static inline void nd_set_link(struct nameidata *nd, char *path)
65593 +static inline void nd_set_link(struct nameidata *nd, const char *path)
65594 {
65595 nd->saved_names[nd->depth] = path;
65596 }
65597
65598 -static inline char *nd_get_link(struct nameidata *nd)
65599 +static inline const char *nd_get_link(const struct nameidata *nd)
65600 {
65601 return nd->saved_names[nd->depth];
65602 }
65603 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65604 index a848ffc..3bbbaee 100644
65605 --- a/include/linux/netdevice.h
65606 +++ b/include/linux/netdevice.h
65607 @@ -999,6 +999,7 @@ struct net_device_ops {
65608 struct net_device *dev,
65609 int idx);
65610 };
65611 +typedef struct net_device_ops __no_const net_device_ops_no_const;
65612
65613 /*
65614 * The DEVICE structure.
65615 @@ -1059,7 +1060,7 @@ struct net_device {
65616 int iflink;
65617
65618 struct net_device_stats stats;
65619 - atomic_long_t rx_dropped; /* dropped packets by core network
65620 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65621 * Do not use this in drivers.
65622 */
65623
65624 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65625 index 7958e84..ed74d7a 100644
65626 --- a/include/linux/netfilter/ipset/ip_set.h
65627 +++ b/include/linux/netfilter/ipset/ip_set.h
65628 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
65629 /* Return true if "b" set is the same as "a"
65630 * according to the create set parameters */
65631 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65632 -};
65633 +} __do_const;
65634
65635 /* The core set type structure */
65636 struct ip_set_type {
65637 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65638 index 4966dde..7d8ce06 100644
65639 --- a/include/linux/netfilter/nfnetlink.h
65640 +++ b/include/linux/netfilter/nfnetlink.h
65641 @@ -16,7 +16,7 @@ struct nfnl_callback {
65642 const struct nlattr * const cda[]);
65643 const struct nla_policy *policy; /* netlink attribute policy */
65644 const u_int16_t attr_count; /* number of nlattr's */
65645 -};
65646 +} __do_const;
65647
65648 struct nfnetlink_subsystem {
65649 const char *name;
65650 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65651 new file mode 100644
65652 index 0000000..33f4af8
65653 --- /dev/null
65654 +++ b/include/linux/netfilter/xt_gradm.h
65655 @@ -0,0 +1,9 @@
65656 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
65657 +#define _LINUX_NETFILTER_XT_GRADM_H 1
65658 +
65659 +struct xt_gradm_mtinfo {
65660 + __u16 flags;
65661 + __u16 invflags;
65662 +};
65663 +
65664 +#endif
65665 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65666 index d65746e..62e72c2 100644
65667 --- a/include/linux/notifier.h
65668 +++ b/include/linux/notifier.h
65669 @@ -51,7 +51,8 @@ struct notifier_block {
65670 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65671 struct notifier_block __rcu *next;
65672 int priority;
65673 -};
65674 +} __do_const;
65675 +typedef struct notifier_block __no_const notifier_block_no_const;
65676
65677 struct atomic_notifier_head {
65678 spinlock_t lock;
65679 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65680 index a4c5624..79d6d88 100644
65681 --- a/include/linux/oprofile.h
65682 +++ b/include/linux/oprofile.h
65683 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65684 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65685 char const * name, ulong * val);
65686
65687 -/** Create a file for read-only access to an atomic_t. */
65688 +/** Create a file for read-only access to an atomic_unchecked_t. */
65689 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65690 - char const * name, atomic_t * val);
65691 + char const * name, atomic_unchecked_t * val);
65692
65693 /** create a directory */
65694 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65695 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65696 index 6bfb2faa..1204767 100644
65697 --- a/include/linux/perf_event.h
65698 +++ b/include/linux/perf_event.h
65699 @@ -328,8 +328,8 @@ struct perf_event {
65700
65701 enum perf_event_active_state state;
65702 unsigned int attach_state;
65703 - local64_t count;
65704 - atomic64_t child_count;
65705 + local64_t count; /* PaX: fix it one day */
65706 + atomic64_unchecked_t child_count;
65707
65708 /*
65709 * These are the total time in nanoseconds that the event
65710 @@ -380,8 +380,8 @@ struct perf_event {
65711 * These accumulate total time (in nanoseconds) that children
65712 * events have been enabled and running, respectively.
65713 */
65714 - atomic64_t child_total_time_enabled;
65715 - atomic64_t child_total_time_running;
65716 + atomic64_unchecked_t child_total_time_enabled;
65717 + atomic64_unchecked_t child_total_time_running;
65718
65719 /*
65720 * Protect attach/detach and child_list:
65721 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65722 index ad1a427..6419649 100644
65723 --- a/include/linux/pipe_fs_i.h
65724 +++ b/include/linux/pipe_fs_i.h
65725 @@ -45,9 +45,9 @@ struct pipe_buffer {
65726 struct pipe_inode_info {
65727 wait_queue_head_t wait;
65728 unsigned int nrbufs, curbuf, buffers;
65729 - unsigned int readers;
65730 - unsigned int writers;
65731 - unsigned int waiting_writers;
65732 + atomic_t readers;
65733 + atomic_t writers;
65734 + atomic_t waiting_writers;
65735 unsigned int r_counter;
65736 unsigned int w_counter;
65737 struct page *tmp_page;
65738 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65739 index 5f28cae..3d23723 100644
65740 --- a/include/linux/platform_data/usb-ehci-s5p.h
65741 +++ b/include/linux/platform_data/usb-ehci-s5p.h
65742 @@ -14,7 +14,7 @@
65743 struct s5p_ehci_platdata {
65744 int (*phy_init)(struct platform_device *pdev, int type);
65745 int (*phy_exit)(struct platform_device *pdev, int type);
65746 -};
65747 +} __no_const;
65748
65749 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65750
65751 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65752 index f271860..6b3bec5 100644
65753 --- a/include/linux/pm_runtime.h
65754 +++ b/include/linux/pm_runtime.h
65755 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65756
65757 static inline void pm_runtime_mark_last_busy(struct device *dev)
65758 {
65759 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
65760 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65761 }
65762
65763 #else /* !CONFIG_PM_RUNTIME */
65764 diff --git a/include/linux/poison.h b/include/linux/poison.h
65765 index 2110a81..13a11bb 100644
65766 --- a/include/linux/poison.h
65767 +++ b/include/linux/poison.h
65768 @@ -19,8 +19,8 @@
65769 * under normal circumstances, used to verify that nobody uses
65770 * non-initialized list entries.
65771 */
65772 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65773 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65774 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65775 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65776
65777 /********** include/linux/timer.h **********/
65778 /*
65779 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65780 index 4a496eb..d9c5659 100644
65781 --- a/include/linux/power/smartreflex.h
65782 +++ b/include/linux/power/smartreflex.h
65783 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
65784 int (*notify)(struct omap_sr *sr, u32 status);
65785 u8 notify_flags;
65786 u8 class_type;
65787 -};
65788 +} __do_const;
65789
65790 /**
65791 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65792 diff --git a/include/linux/printk.h b/include/linux/printk.h
65793 index 9afc01e..92c32e8 100644
65794 --- a/include/linux/printk.h
65795 +++ b/include/linux/printk.h
65796 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65797 extern int printk_needs_cpu(int cpu);
65798 extern void printk_tick(void);
65799
65800 +extern int kptr_restrict;
65801 +
65802 #ifdef CONFIG_PRINTK
65803 asmlinkage __printf(5, 0)
65804 int vprintk_emit(int facility, int level,
65805 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65806
65807 extern int printk_delay_msec;
65808 extern int dmesg_restrict;
65809 -extern int kptr_restrict;
65810
65811 void log_buf_kexec_setup(void);
65812 void __init setup_log_buf(int early);
65813 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65814 index 3fd2e87..75db910 100644
65815 --- a/include/linux/proc_fs.h
65816 +++ b/include/linux/proc_fs.h
65817 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65818 return proc_create_data(name, mode, parent, proc_fops, NULL);
65819 }
65820
65821 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65822 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65823 +{
65824 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65825 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65826 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65827 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65828 +#else
65829 + return proc_create_data(name, mode, parent, proc_fops, NULL);
65830 +#endif
65831 +}
65832 +
65833 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65834 umode_t mode, struct proc_dir_entry *base,
65835 read_proc_t *read_proc, void * data)
65836 diff --git a/include/linux/random.h b/include/linux/random.h
65837 index 6330ed4..419c6c3 100644
65838 --- a/include/linux/random.h
65839 +++ b/include/linux/random.h
65840 @@ -30,12 +30,17 @@ void srandom32(u32 seed);
65841
65842 u32 prandom32(struct rnd_state *);
65843
65844 +static inline unsigned long pax_get_random_long(void)
65845 +{
65846 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65847 +}
65848 +
65849 /*
65850 * Handle minimum values for seeds
65851 */
65852 static inline u32 __seed(u32 x, u32 m)
65853 {
65854 - return (x < m) ? x + m : x;
65855 + return (x <= m) ? x + m + 1 : x;
65856 }
65857
65858 /**
65859 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65860 index 23b3630..e1bc12b 100644
65861 --- a/include/linux/reboot.h
65862 +++ b/include/linux/reboot.h
65863 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65864 * Architecture-specific implementations of sys_reboot commands.
65865 */
65866
65867 -extern void machine_restart(char *cmd);
65868 -extern void machine_halt(void);
65869 -extern void machine_power_off(void);
65870 +extern void machine_restart(char *cmd) __noreturn;
65871 +extern void machine_halt(void) __noreturn;
65872 +extern void machine_power_off(void) __noreturn;
65873
65874 extern void machine_shutdown(void);
65875 struct pt_regs;
65876 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65877 */
65878
65879 extern void kernel_restart_prepare(char *cmd);
65880 -extern void kernel_restart(char *cmd);
65881 -extern void kernel_halt(void);
65882 -extern void kernel_power_off(void);
65883 +extern void kernel_restart(char *cmd) __noreturn;
65884 +extern void kernel_halt(void) __noreturn;
65885 +extern void kernel_power_off(void) __noreturn;
65886
65887 extern int C_A_D; /* for sysctl */
65888 void ctrl_alt_del(void);
65889 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65890 * Emergency restart, callable from an interrupt handler.
65891 */
65892
65893 -extern void emergency_restart(void);
65894 +extern void emergency_restart(void) __noreturn;
65895 #include <asm/emergency-restart.h>
65896
65897 #endif /* _LINUX_REBOOT_H */
65898 diff --git a/include/linux/regset.h b/include/linux/regset.h
65899 index 8e0c9fe..fdb64bc 100644
65900 --- a/include/linux/regset.h
65901 +++ b/include/linux/regset.h
65902 @@ -161,7 +161,7 @@ struct user_regset {
65903 unsigned int align;
65904 unsigned int bias;
65905 unsigned int core_note_type;
65906 -};
65907 +} __do_const;
65908
65909 /**
65910 * struct user_regset_view - available regsets
65911 diff --git a/include/linux/relay.h b/include/linux/relay.h
65912 index 91cacc3..b55ff74 100644
65913 --- a/include/linux/relay.h
65914 +++ b/include/linux/relay.h
65915 @@ -160,7 +160,7 @@ struct rchan_callbacks
65916 * The callback should return 0 if successful, negative if not.
65917 */
65918 int (*remove_buf_file)(struct dentry *dentry);
65919 -};
65920 +} __no_const;
65921
65922 /*
65923 * CONFIG_RELAY kernel API, kernel/relay.c
65924 diff --git a/include/linux/rio.h b/include/linux/rio.h
65925 index a3e7842..d973ca6 100644
65926 --- a/include/linux/rio.h
65927 +++ b/include/linux/rio.h
65928 @@ -339,7 +339,7 @@ struct rio_ops {
65929 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65930 u64 rstart, u32 size, u32 flags);
65931 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65932 -};
65933 +} __no_const;
65934
65935 #define RIO_RESOURCE_MEM 0x00000100
65936 #define RIO_RESOURCE_DOORBELL 0x00000200
65937 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65938 index bfe1f47..6a33ee3 100644
65939 --- a/include/linux/rmap.h
65940 +++ b/include/linux/rmap.h
65941 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65942 void anon_vma_init(void); /* create anon_vma_cachep */
65943 int anon_vma_prepare(struct vm_area_struct *);
65944 void unlink_anon_vmas(struct vm_area_struct *);
65945 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
65946 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
65947 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
65948 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
65949
65950 static inline void anon_vma_merge(struct vm_area_struct *vma,
65951 struct vm_area_struct *next)
65952 diff --git a/include/linux/sched.h b/include/linux/sched.h
65953 index 3e63925..6c93b17 100644
65954 --- a/include/linux/sched.h
65955 +++ b/include/linux/sched.h
65956 @@ -61,6 +61,7 @@ struct bio_list;
65957 struct fs_struct;
65958 struct perf_event_context;
65959 struct blk_plug;
65960 +struct linux_binprm;
65961
65962 /*
65963 * List of flags we want to share for kernel threads,
65964 @@ -344,10 +345,23 @@ struct user_namespace;
65965 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
65966
65967 extern int sysctl_max_map_count;
65968 +extern unsigned long sysctl_heap_stack_gap;
65969
65970 #include <linux/aio.h>
65971
65972 #ifdef CONFIG_MMU
65973 +
65974 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
65975 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
65976 +#else
65977 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
65978 +{
65979 + return 0;
65980 +}
65981 +#endif
65982 +
65983 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
65984 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
65985 extern void arch_pick_mmap_layout(struct mm_struct *mm);
65986 extern unsigned long
65987 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
65988 @@ -614,6 +628,17 @@ struct signal_struct {
65989 #ifdef CONFIG_TASKSTATS
65990 struct taskstats *stats;
65991 #endif
65992 +
65993 +#ifdef CONFIG_GRKERNSEC
65994 + u32 curr_ip;
65995 + u32 saved_ip;
65996 + u32 gr_saddr;
65997 + u32 gr_daddr;
65998 + u16 gr_sport;
65999 + u16 gr_dport;
66000 + u8 used_accept:1;
66001 +#endif
66002 +
66003 #ifdef CONFIG_AUDIT
66004 unsigned audit_tty;
66005 struct tty_audit_buf *tty_audit_buf;
66006 @@ -691,6 +716,11 @@ struct user_struct {
66007 struct key *session_keyring; /* UID's default session keyring */
66008 #endif
66009
66010 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66011 + unsigned int banned;
66012 + unsigned long ban_expires;
66013 +#endif
66014 +
66015 /* Hash table maintenance information */
66016 struct hlist_node uidhash_node;
66017 kuid_t uid;
66018 @@ -1312,8 +1342,8 @@ struct task_struct {
66019 struct list_head thread_group;
66020
66021 struct completion *vfork_done; /* for vfork() */
66022 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66023 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66024 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66025 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66026
66027 cputime_t utime, stime, utimescaled, stimescaled;
66028 cputime_t gtime;
66029 @@ -1329,11 +1359,6 @@ struct task_struct {
66030 struct task_cputime cputime_expires;
66031 struct list_head cpu_timers[3];
66032
66033 -/* process credentials */
66034 - const struct cred __rcu *real_cred; /* objective and real subjective task
66035 - * credentials (COW) */
66036 - const struct cred __rcu *cred; /* effective (overridable) subjective task
66037 - * credentials (COW) */
66038 char comm[TASK_COMM_LEN]; /* executable name excluding path
66039 - access with [gs]et_task_comm (which lock
66040 it with task_lock())
66041 @@ -1350,6 +1375,10 @@ struct task_struct {
66042 #endif
66043 /* CPU-specific state of this task */
66044 struct thread_struct thread;
66045 +/* thread_info moved to task_struct */
66046 +#ifdef CONFIG_X86
66047 + struct thread_info tinfo;
66048 +#endif
66049 /* filesystem information */
66050 struct fs_struct *fs;
66051 /* open file information */
66052 @@ -1423,6 +1452,10 @@ struct task_struct {
66053 gfp_t lockdep_reclaim_gfp;
66054 #endif
66055
66056 +/* process credentials */
66057 + const struct cred __rcu *real_cred; /* objective and real subjective task
66058 + * credentials (COW) */
66059 +
66060 /* journalling filesystem info */
66061 void *journal_info;
66062
66063 @@ -1461,6 +1494,10 @@ struct task_struct {
66064 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66065 struct list_head cg_list;
66066 #endif
66067 +
66068 + const struct cred __rcu *cred; /* effective (overridable) subjective task
66069 + * credentials (COW) */
66070 +
66071 #ifdef CONFIG_FUTEX
66072 struct robust_list_head __user *robust_list;
66073 #ifdef CONFIG_COMPAT
66074 @@ -1548,8 +1585,74 @@ struct task_struct {
66075 #ifdef CONFIG_UPROBES
66076 struct uprobe_task *utask;
66077 #endif
66078 +
66079 +#ifdef CONFIG_GRKERNSEC
66080 + /* grsecurity */
66081 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66082 + u64 exec_id;
66083 +#endif
66084 +#ifdef CONFIG_GRKERNSEC_SETXID
66085 + const struct cred *delayed_cred;
66086 +#endif
66087 + struct dentry *gr_chroot_dentry;
66088 + struct acl_subject_label *acl;
66089 + struct acl_role_label *role;
66090 + struct file *exec_file;
66091 + unsigned long brute_expires;
66092 + u16 acl_role_id;
66093 + /* is this the task that authenticated to the special role */
66094 + u8 acl_sp_role;
66095 + u8 is_writable;
66096 + u8 brute;
66097 + u8 gr_is_chrooted;
66098 +#endif
66099 +
66100 };
66101
66102 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66103 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66104 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66105 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66106 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66107 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66108 +
66109 +#ifdef CONFIG_PAX_SOFTMODE
66110 +extern int pax_softmode;
66111 +#endif
66112 +
66113 +extern int pax_check_flags(unsigned long *);
66114 +
66115 +/* if tsk != current then task_lock must be held on it */
66116 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66117 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
66118 +{
66119 + if (likely(tsk->mm))
66120 + return tsk->mm->pax_flags;
66121 + else
66122 + return 0UL;
66123 +}
66124 +
66125 +/* if tsk != current then task_lock must be held on it */
66126 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66127 +{
66128 + if (likely(tsk->mm)) {
66129 + tsk->mm->pax_flags = flags;
66130 + return 0;
66131 + }
66132 + return -EINVAL;
66133 +}
66134 +#endif
66135 +
66136 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66137 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
66138 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66139 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
66140 +#endif
66141 +
66142 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
66143 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
66144 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
66145 +
66146 /* Future-safe accessor for struct task_struct's cpus_allowed. */
66147 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
66148
66149 @@ -2092,7 +2195,9 @@ void yield(void);
66150 extern struct exec_domain default_exec_domain;
66151
66152 union thread_union {
66153 +#ifndef CONFIG_X86
66154 struct thread_info thread_info;
66155 +#endif
66156 unsigned long stack[THREAD_SIZE/sizeof(long)];
66157 };
66158
66159 @@ -2125,6 +2230,7 @@ extern struct pid_namespace init_pid_ns;
66160 */
66161
66162 extern struct task_struct *find_task_by_vpid(pid_t nr);
66163 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66164 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66165 struct pid_namespace *ns);
66166
66167 @@ -2281,7 +2387,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66168 extern void exit_itimers(struct signal_struct *);
66169 extern void flush_itimer_signals(void);
66170
66171 -extern void do_group_exit(int);
66172 +extern __noreturn void do_group_exit(int);
66173
66174 extern void daemonize(const char *, ...);
66175 extern int allow_signal(int);
66176 @@ -2485,9 +2591,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66177
66178 #endif
66179
66180 -static inline int object_is_on_stack(void *obj)
66181 +static inline int object_starts_on_stack(void *obj)
66182 {
66183 - void *stack = task_stack_page(current);
66184 + const void *stack = task_stack_page(current);
66185
66186 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66187 }
66188 diff --git a/include/linux/security.h b/include/linux/security.h
66189 index 05e88bd..5cda002 100644
66190 --- a/include/linux/security.h
66191 +++ b/include/linux/security.h
66192 @@ -26,6 +26,7 @@
66193 #include <linux/capability.h>
66194 #include <linux/slab.h>
66195 #include <linux/err.h>
66196 +#include <linux/grsecurity.h>
66197
66198 struct linux_binprm;
66199 struct cred;
66200 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66201 index 68a04a3..866e6a1 100644
66202 --- a/include/linux/seq_file.h
66203 +++ b/include/linux/seq_file.h
66204 @@ -26,6 +26,9 @@ struct seq_file {
66205 struct mutex lock;
66206 const struct seq_operations *op;
66207 int poll_event;
66208 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66209 + u64 exec_id;
66210 +#endif
66211 #ifdef CONFIG_USER_NS
66212 struct user_namespace *user_ns;
66213 #endif
66214 @@ -38,6 +41,7 @@ struct seq_operations {
66215 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
66216 int (*show) (struct seq_file *m, void *v);
66217 };
66218 +typedef struct seq_operations __no_const seq_operations_no_const;
66219
66220 #define SEQ_SKIP 1
66221
66222 diff --git a/include/linux/shm.h b/include/linux/shm.h
66223 index bcf8a6a..4d0af77 100644
66224 --- a/include/linux/shm.h
66225 +++ b/include/linux/shm.h
66226 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
66227
66228 /* The task created the shm object. NULL if the task is dead. */
66229 struct task_struct *shm_creator;
66230 +#ifdef CONFIG_GRKERNSEC
66231 + time_t shm_createtime;
66232 + pid_t shm_lapid;
66233 +#endif
66234 };
66235
66236 /* shm_mode upper byte flags */
66237 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
66238 index 6a2c34e..a1f320f 100644
66239 --- a/include/linux/skbuff.h
66240 +++ b/include/linux/skbuff.h
66241 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
66242 extern struct sk_buff *__alloc_skb(unsigned int size,
66243 gfp_t priority, int flags, int node);
66244 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
66245 -static inline struct sk_buff *alloc_skb(unsigned int size,
66246 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
66247 gfp_t priority)
66248 {
66249 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
66250 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
66251 */
66252 static inline int skb_queue_empty(const struct sk_buff_head *list)
66253 {
66254 - return list->next == (struct sk_buff *)list;
66255 + return list->next == (const struct sk_buff *)list;
66256 }
66257
66258 /**
66259 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
66260 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66261 const struct sk_buff *skb)
66262 {
66263 - return skb->next == (struct sk_buff *)list;
66264 + return skb->next == (const struct sk_buff *)list;
66265 }
66266
66267 /**
66268 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66269 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
66270 const struct sk_buff *skb)
66271 {
66272 - return skb->prev == (struct sk_buff *)list;
66273 + return skb->prev == (const struct sk_buff *)list;
66274 }
66275
66276 /**
66277 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
66278 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
66279 */
66280 #ifndef NET_SKB_PAD
66281 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
66282 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
66283 #endif
66284
66285 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
66286 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
66287 int noblock, int *err);
66288 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
66289 struct poll_table_struct *wait);
66290 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
66291 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
66292 int offset, struct iovec *to,
66293 int size);
66294 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
66295 diff --git a/include/linux/slab.h b/include/linux/slab.h
66296 index 83d1a14..e23d723 100644
66297 --- a/include/linux/slab.h
66298 +++ b/include/linux/slab.h
66299 @@ -11,12 +11,20 @@
66300
66301 #include <linux/gfp.h>
66302 #include <linux/types.h>
66303 +#include <linux/err.h>
66304
66305 /*
66306 * Flags to pass to kmem_cache_create().
66307 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
66308 */
66309 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
66310 +
66311 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66312 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
66313 +#else
66314 +#define SLAB_USERCOPY 0x00000000UL
66315 +#endif
66316 +
66317 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
66318 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
66319 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
66320 @@ -87,10 +95,13 @@
66321 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
66322 * Both make kfree a no-op.
66323 */
66324 -#define ZERO_SIZE_PTR ((void *)16)
66325 +#define ZERO_SIZE_PTR \
66326 +({ \
66327 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
66328 + (void *)(-MAX_ERRNO-1L); \
66329 +})
66330
66331 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
66332 - (unsigned long)ZERO_SIZE_PTR)
66333 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
66334
66335 /*
66336 * Common fields provided in kmem_cache by all slab allocators
66337 @@ -110,7 +121,7 @@ struct kmem_cache {
66338 unsigned int align; /* Alignment as calculated */
66339 unsigned long flags; /* Active flags on the slab */
66340 const char *name; /* Slab name for sysfs */
66341 - int refcount; /* Use counter */
66342 + atomic_t refcount; /* Use counter */
66343 void (*ctor)(void *); /* Called on object slot creation */
66344 struct list_head list; /* List of all slab caches on the system */
66345 };
66346 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
66347 void kfree(const void *);
66348 void kzfree(const void *);
66349 size_t ksize(const void *);
66350 +const char *check_heap_object(const void *ptr, unsigned long n);
66351 +bool is_usercopy_object(const void *ptr);
66352
66353 /*
66354 * Allocator specific definitions. These are mainly used to establish optimized
66355 @@ -264,8 +277,18 @@ size_t ksize(const void *);
66356 * for general use, and so are not documented here. For a full list of
66357 * potential flags, always refer to linux/gfp.h.
66358 */
66359 +
66360 +extern void kmalloc_array_error(void)
66361 +#if defined(CONFIG_GCOV_KERNEL) && defined(CONFIG_PAX_SIZE_OVERFLOW)
66362 +__compiletime_warning("kmalloc_array called with swapped arguments?");
66363 +#else
66364 +__compiletime_error("kmalloc_array called with swapped arguments?");
66365 +#endif
66366 +
66367 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
66368 {
66369 + if (__builtin_constant_p(n) && !__builtin_constant_p(size))
66370 + kmalloc_array_error();
66371 if (size != 0 && n > SIZE_MAX / size)
66372 return NULL;
66373 return __kmalloc(n * size, flags);
66374 @@ -323,7 +346,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66375 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66376 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66377 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66378 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66379 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66380 #define kmalloc_track_caller(size, flags) \
66381 __kmalloc_track_caller(size, flags, _RET_IP_)
66382 #else
66383 @@ -343,7 +366,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66384 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66385 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66386 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66387 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66388 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66389 #define kmalloc_node_track_caller(size, flags, node) \
66390 __kmalloc_node_track_caller(size, flags, node, \
66391 _RET_IP_)
66392 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66393 index cc290f0..0ba60931 100644
66394 --- a/include/linux/slab_def.h
66395 +++ b/include/linux/slab_def.h
66396 @@ -52,7 +52,7 @@ struct kmem_cache {
66397 /* 4) cache creation/removal */
66398 const char *name;
66399 struct list_head list;
66400 - int refcount;
66401 + atomic_t refcount;
66402 int object_size;
66403 int align;
66404
66405 @@ -68,10 +68,10 @@ struct kmem_cache {
66406 unsigned long node_allocs;
66407 unsigned long node_frees;
66408 unsigned long node_overflow;
66409 - atomic_t allochit;
66410 - atomic_t allocmiss;
66411 - atomic_t freehit;
66412 - atomic_t freemiss;
66413 + atomic_unchecked_t allochit;
66414 + atomic_unchecked_t allocmiss;
66415 + atomic_unchecked_t freehit;
66416 + atomic_unchecked_t freemiss;
66417
66418 /*
66419 * If debugging is enabled, then the allocator can add additional
66420 @@ -104,11 +104,16 @@ struct cache_sizes {
66421 #ifdef CONFIG_ZONE_DMA
66422 struct kmem_cache *cs_dmacachep;
66423 #endif
66424 +
66425 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66426 + struct kmem_cache *cs_usercopycachep;
66427 +#endif
66428 +
66429 };
66430 extern struct cache_sizes malloc_sizes[];
66431
66432 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66433 -void *__kmalloc(size_t size, gfp_t flags);
66434 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66435
66436 #ifdef CONFIG_TRACING
66437 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66438 @@ -145,6 +150,13 @@ found:
66439 cachep = malloc_sizes[i].cs_dmacachep;
66440 else
66441 #endif
66442 +
66443 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66444 + if (flags & GFP_USERCOPY)
66445 + cachep = malloc_sizes[i].cs_usercopycachep;
66446 + else
66447 +#endif
66448 +
66449 cachep = malloc_sizes[i].cs_cachep;
66450
66451 ret = kmem_cache_alloc_trace(cachep, flags, size);
66452 @@ -155,7 +167,7 @@ found:
66453 }
66454
66455 #ifdef CONFIG_NUMA
66456 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66457 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66458 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66459
66460 #ifdef CONFIG_TRACING
66461 @@ -198,6 +210,13 @@ found:
66462 cachep = malloc_sizes[i].cs_dmacachep;
66463 else
66464 #endif
66465 +
66466 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66467 + if (flags & GFP_USERCOPY)
66468 + cachep = malloc_sizes[i].cs_usercopycachep;
66469 + else
66470 +#endif
66471 +
66472 cachep = malloc_sizes[i].cs_cachep;
66473
66474 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66475 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66476 index f28e14a..7831211 100644
66477 --- a/include/linux/slob_def.h
66478 +++ b/include/linux/slob_def.h
66479 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66480 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66481 }
66482
66483 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66484 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66485
66486 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66487 {
66488 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66489 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66490 }
66491
66492 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66493 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66494 {
66495 return kmalloc(size, flags);
66496 }
66497 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66498 index df448ad..b99e7f6 100644
66499 --- a/include/linux/slub_def.h
66500 +++ b/include/linux/slub_def.h
66501 @@ -91,7 +91,7 @@ struct kmem_cache {
66502 struct kmem_cache_order_objects max;
66503 struct kmem_cache_order_objects min;
66504 gfp_t allocflags; /* gfp flags to use on each alloc */
66505 - int refcount; /* Refcount for slab cache destroy */
66506 + atomic_t refcount; /* Refcount for slab cache destroy */
66507 void (*ctor)(void *);
66508 int inuse; /* Offset to metadata */
66509 int align; /* Alignment */
66510 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66511 * Sorry that the following has to be that ugly but some versions of GCC
66512 * have trouble with constant propagation and loops.
66513 */
66514 -static __always_inline int kmalloc_index(size_t size)
66515 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66516 {
66517 if (!size)
66518 return 0;
66519 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66520 }
66521
66522 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66523 -void *__kmalloc(size_t size, gfp_t flags);
66524 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66525
66526 static __always_inline void *
66527 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66528 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66529 }
66530 #endif
66531
66532 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66533 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66534 {
66535 unsigned int order = get_order(size);
66536 return kmalloc_order_trace(size, flags, order);
66537 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66538 }
66539
66540 #ifdef CONFIG_NUMA
66541 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66542 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66543 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66544
66545 #ifdef CONFIG_TRACING
66546 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66547 index 680f9a3..f13aeb0 100644
66548 --- a/include/linux/sonet.h
66549 +++ b/include/linux/sonet.h
66550 @@ -7,7 +7,7 @@
66551 #include <uapi/linux/sonet.h>
66552
66553 struct k_sonet_stats {
66554 -#define __HANDLE_ITEM(i) atomic_t i
66555 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66556 __SONET_ITEMS
66557 #undef __HANDLE_ITEM
66558 };
66559 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66560 index 34206b8..f019e06 100644
66561 --- a/include/linux/sunrpc/clnt.h
66562 +++ b/include/linux/sunrpc/clnt.h
66563 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66564 {
66565 switch (sap->sa_family) {
66566 case AF_INET:
66567 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
66568 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66569 case AF_INET6:
66570 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66571 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66572 }
66573 return 0;
66574 }
66575 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66576 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66577 const struct sockaddr *src)
66578 {
66579 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66580 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66581 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66582
66583 dsin->sin_family = ssin->sin_family;
66584 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66585 if (sa->sa_family != AF_INET6)
66586 return 0;
66587
66588 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66589 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66590 }
66591
66592 #endif /* __KERNEL__ */
66593 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66594 index 0b8e3e6..33e0a01 100644
66595 --- a/include/linux/sunrpc/svc_rdma.h
66596 +++ b/include/linux/sunrpc/svc_rdma.h
66597 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66598 extern unsigned int svcrdma_max_requests;
66599 extern unsigned int svcrdma_max_req_size;
66600
66601 -extern atomic_t rdma_stat_recv;
66602 -extern atomic_t rdma_stat_read;
66603 -extern atomic_t rdma_stat_write;
66604 -extern atomic_t rdma_stat_sq_starve;
66605 -extern atomic_t rdma_stat_rq_starve;
66606 -extern atomic_t rdma_stat_rq_poll;
66607 -extern atomic_t rdma_stat_rq_prod;
66608 -extern atomic_t rdma_stat_sq_poll;
66609 -extern atomic_t rdma_stat_sq_prod;
66610 +extern atomic_unchecked_t rdma_stat_recv;
66611 +extern atomic_unchecked_t rdma_stat_read;
66612 +extern atomic_unchecked_t rdma_stat_write;
66613 +extern atomic_unchecked_t rdma_stat_sq_starve;
66614 +extern atomic_unchecked_t rdma_stat_rq_starve;
66615 +extern atomic_unchecked_t rdma_stat_rq_poll;
66616 +extern atomic_unchecked_t rdma_stat_rq_prod;
66617 +extern atomic_unchecked_t rdma_stat_sq_poll;
66618 +extern atomic_unchecked_t rdma_stat_sq_prod;
66619
66620 #define RPCRDMA_VERSION 1
66621
66622 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66623 index cd844a6..3ca3592 100644
66624 --- a/include/linux/sysctl.h
66625 +++ b/include/linux/sysctl.h
66626 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66627
66628 extern int proc_dostring(struct ctl_table *, int,
66629 void __user *, size_t *, loff_t *);
66630 +extern int proc_dostring_modpriv(struct ctl_table *, int,
66631 + void __user *, size_t *, loff_t *);
66632 extern int proc_dointvec(struct ctl_table *, int,
66633 void __user *, size_t *, loff_t *);
66634 extern int proc_dointvec_minmax(struct ctl_table *, int,
66635 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66636 index 7faf933..eb6f5e3 100644
66637 --- a/include/linux/sysrq.h
66638 +++ b/include/linux/sysrq.h
66639 @@ -36,7 +36,7 @@ struct sysrq_key_op {
66640 char *help_msg;
66641 char *action_msg;
66642 int enable_mask;
66643 -};
66644 +} __do_const;
66645
66646 #ifdef CONFIG_MAGIC_SYSRQ
66647
66648 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
66649 index ccc1899..b1aaceb 100644
66650 --- a/include/linux/thread_info.h
66651 +++ b/include/linux/thread_info.h
66652 @@ -146,6 +146,15 @@ static inline bool test_and_clear_restore_sigmask(void)
66653 #error "no set_restore_sigmask() provided and default one won't work"
66654 #endif
66655
66656 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
66657 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
66658 +{
66659 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
66660 + if (!__builtin_constant_p(n))
66661 +#endif
66662 + __check_object_size(ptr, n, to);
66663 +}
66664 +
66665 #endif /* __KERNEL__ */
66666
66667 #endif /* _LINUX_THREAD_INFO_H */
66668 diff --git a/include/linux/tty.h b/include/linux/tty.h
66669 index f0b4eb4..1c4854e 100644
66670 --- a/include/linux/tty.h
66671 +++ b/include/linux/tty.h
66672 @@ -192,7 +192,7 @@ struct tty_port {
66673 const struct tty_port_operations *ops; /* Port operations */
66674 spinlock_t lock; /* Lock protecting tty field */
66675 int blocked_open; /* Waiting to open */
66676 - int count; /* Usage count */
66677 + atomic_t count; /* Usage count */
66678 wait_queue_head_t open_wait; /* Open waiters */
66679 wait_queue_head_t close_wait; /* Close waiters */
66680 wait_queue_head_t delta_msr_wait; /* Modem status change */
66681 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66682 struct tty_struct *tty, struct file *filp);
66683 static inline int tty_port_users(struct tty_port *port)
66684 {
66685 - return port->count + port->blocked_open;
66686 + return atomic_read(&port->count) + port->blocked_open;
66687 }
66688
66689 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66690 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66691 index dd976cf..e272742 100644
66692 --- a/include/linux/tty_driver.h
66693 +++ b/include/linux/tty_driver.h
66694 @@ -284,7 +284,7 @@ struct tty_operations {
66695 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66696 #endif
66697 const struct file_operations *proc_fops;
66698 -};
66699 +} __do_const;
66700
66701 struct tty_driver {
66702 int magic; /* magic number for this structure */
66703 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66704 index fb79dd8d..07d4773 100644
66705 --- a/include/linux/tty_ldisc.h
66706 +++ b/include/linux/tty_ldisc.h
66707 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66708
66709 struct module *owner;
66710
66711 - int refcount;
66712 + atomic_t refcount;
66713 };
66714
66715 struct tty_ldisc {
66716 diff --git a/include/linux/types.h b/include/linux/types.h
66717 index 1cc0e4b..0d50edf 100644
66718 --- a/include/linux/types.h
66719 +++ b/include/linux/types.h
66720 @@ -175,10 +175,26 @@ typedef struct {
66721 int counter;
66722 } atomic_t;
66723
66724 +#ifdef CONFIG_PAX_REFCOUNT
66725 +typedef struct {
66726 + int counter;
66727 +} atomic_unchecked_t;
66728 +#else
66729 +typedef atomic_t atomic_unchecked_t;
66730 +#endif
66731 +
66732 #ifdef CONFIG_64BIT
66733 typedef struct {
66734 long counter;
66735 } atomic64_t;
66736 +
66737 +#ifdef CONFIG_PAX_REFCOUNT
66738 +typedef struct {
66739 + long counter;
66740 +} atomic64_unchecked_t;
66741 +#else
66742 +typedef atomic64_t atomic64_unchecked_t;
66743 +#endif
66744 #endif
66745
66746 struct list_head {
66747 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66748 index 5ca0951..ab496a5 100644
66749 --- a/include/linux/uaccess.h
66750 +++ b/include/linux/uaccess.h
66751 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66752 long ret; \
66753 mm_segment_t old_fs = get_fs(); \
66754 \
66755 - set_fs(KERNEL_DS); \
66756 pagefault_disable(); \
66757 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66758 - pagefault_enable(); \
66759 + set_fs(KERNEL_DS); \
66760 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66761 set_fs(old_fs); \
66762 + pagefault_enable(); \
66763 ret; \
66764 })
66765
66766 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66767 index 99c1b4d..bb94261 100644
66768 --- a/include/linux/unaligned/access_ok.h
66769 +++ b/include/linux/unaligned/access_ok.h
66770 @@ -6,32 +6,32 @@
66771
66772 static inline u16 get_unaligned_le16(const void *p)
66773 {
66774 - return le16_to_cpup((__le16 *)p);
66775 + return le16_to_cpup((const __le16 *)p);
66776 }
66777
66778 static inline u32 get_unaligned_le32(const void *p)
66779 {
66780 - return le32_to_cpup((__le32 *)p);
66781 + return le32_to_cpup((const __le32 *)p);
66782 }
66783
66784 static inline u64 get_unaligned_le64(const void *p)
66785 {
66786 - return le64_to_cpup((__le64 *)p);
66787 + return le64_to_cpup((const __le64 *)p);
66788 }
66789
66790 static inline u16 get_unaligned_be16(const void *p)
66791 {
66792 - return be16_to_cpup((__be16 *)p);
66793 + return be16_to_cpup((const __be16 *)p);
66794 }
66795
66796 static inline u32 get_unaligned_be32(const void *p)
66797 {
66798 - return be32_to_cpup((__be32 *)p);
66799 + return be32_to_cpup((const __be32 *)p);
66800 }
66801
66802 static inline u64 get_unaligned_be64(const void *p)
66803 {
66804 - return be64_to_cpup((__be64 *)p);
66805 + return be64_to_cpup((const __be64 *)p);
66806 }
66807
66808 static inline void put_unaligned_le16(u16 val, void *p)
66809 diff --git a/include/linux/usb.h b/include/linux/usb.h
66810 index 10278d1..e21ec3c 100644
66811 --- a/include/linux/usb.h
66812 +++ b/include/linux/usb.h
66813 @@ -551,7 +551,7 @@ struct usb_device {
66814 int maxchild;
66815
66816 u32 quirks;
66817 - atomic_t urbnum;
66818 + atomic_unchecked_t urbnum;
66819
66820 unsigned long active_duration;
66821
66822 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66823 index c5d36c6..108f4f9 100644
66824 --- a/include/linux/usb/renesas_usbhs.h
66825 +++ b/include/linux/usb/renesas_usbhs.h
66826 @@ -39,7 +39,7 @@ enum {
66827 */
66828 struct renesas_usbhs_driver_callback {
66829 int (*notify_hotplug)(struct platform_device *pdev);
66830 -};
66831 +} __no_const;
66832
66833 /*
66834 * callback functions for platform
66835 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66836 index 6f8fbcf..8259001 100644
66837 --- a/include/linux/vermagic.h
66838 +++ b/include/linux/vermagic.h
66839 @@ -25,9 +25,35 @@
66840 #define MODULE_ARCH_VERMAGIC ""
66841 #endif
66842
66843 +#ifdef CONFIG_PAX_REFCOUNT
66844 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
66845 +#else
66846 +#define MODULE_PAX_REFCOUNT ""
66847 +#endif
66848 +
66849 +#ifdef CONSTIFY_PLUGIN
66850 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66851 +#else
66852 +#define MODULE_CONSTIFY_PLUGIN ""
66853 +#endif
66854 +
66855 +#ifdef STACKLEAK_PLUGIN
66856 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66857 +#else
66858 +#define MODULE_STACKLEAK_PLUGIN ""
66859 +#endif
66860 +
66861 +#ifdef CONFIG_GRKERNSEC
66862 +#define MODULE_GRSEC "GRSEC "
66863 +#else
66864 +#define MODULE_GRSEC ""
66865 +#endif
66866 +
66867 #define VERMAGIC_STRING \
66868 UTS_RELEASE " " \
66869 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66870 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66871 - MODULE_ARCH_VERMAGIC
66872 + MODULE_ARCH_VERMAGIC \
66873 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66874 + MODULE_GRSEC
66875
66876 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66877 index 6071e91..ca6a489 100644
66878 --- a/include/linux/vmalloc.h
66879 +++ b/include/linux/vmalloc.h
66880 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66881 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66882 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66883 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66884 +
66885 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66886 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66887 +#endif
66888 +
66889 /* bits [20..32] reserved for arch specific ioremap internals */
66890
66891 /*
66892 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66893 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66894 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66895 unsigned long start, unsigned long end, gfp_t gfp_mask,
66896 - pgprot_t prot, int node, const void *caller);
66897 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
66898 extern void vfree(const void *addr);
66899
66900 extern void *vmap(struct page **pages, unsigned int count,
66901 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66902 extern void free_vm_area(struct vm_struct *area);
66903
66904 /* for /dev/kmem */
66905 -extern long vread(char *buf, char *addr, unsigned long count);
66906 -extern long vwrite(char *buf, char *addr, unsigned long count);
66907 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66908 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66909
66910 /*
66911 * Internals. Dont't use..
66912 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66913 index 92a86b2..1d9eb3c 100644
66914 --- a/include/linux/vmstat.h
66915 +++ b/include/linux/vmstat.h
66916 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66917 /*
66918 * Zone based page accounting with per cpu differentials.
66919 */
66920 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66921 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66922
66923 static inline void zone_page_state_add(long x, struct zone *zone,
66924 enum zone_stat_item item)
66925 {
66926 - atomic_long_add(x, &zone->vm_stat[item]);
66927 - atomic_long_add(x, &vm_stat[item]);
66928 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
66929 + atomic_long_add_unchecked(x, &vm_stat[item]);
66930 }
66931
66932 static inline unsigned long global_page_state(enum zone_stat_item item)
66933 {
66934 - long x = atomic_long_read(&vm_stat[item]);
66935 + long x = atomic_long_read_unchecked(&vm_stat[item]);
66936 #ifdef CONFIG_SMP
66937 if (x < 0)
66938 x = 0;
66939 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
66940 static inline unsigned long zone_page_state(struct zone *zone,
66941 enum zone_stat_item item)
66942 {
66943 - long x = atomic_long_read(&zone->vm_stat[item]);
66944 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66945 #ifdef CONFIG_SMP
66946 if (x < 0)
66947 x = 0;
66948 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
66949 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
66950 enum zone_stat_item item)
66951 {
66952 - long x = atomic_long_read(&zone->vm_stat[item]);
66953 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66954
66955 #ifdef CONFIG_SMP
66956 int cpu;
66957 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
66958
66959 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
66960 {
66961 - atomic_long_inc(&zone->vm_stat[item]);
66962 - atomic_long_inc(&vm_stat[item]);
66963 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
66964 + atomic_long_inc_unchecked(&vm_stat[item]);
66965 }
66966
66967 static inline void __inc_zone_page_state(struct page *page,
66968 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
66969
66970 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
66971 {
66972 - atomic_long_dec(&zone->vm_stat[item]);
66973 - atomic_long_dec(&vm_stat[item]);
66974 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
66975 + atomic_long_dec_unchecked(&vm_stat[item]);
66976 }
66977
66978 static inline void __dec_zone_page_state(struct page *page,
66979 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
66980 index 95d1c91..6798cca 100644
66981 --- a/include/media/v4l2-dev.h
66982 +++ b/include/media/v4l2-dev.h
66983 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
66984 int (*mmap) (struct file *, struct vm_area_struct *);
66985 int (*open) (struct file *);
66986 int (*release) (struct file *);
66987 -};
66988 +} __do_const;
66989
66990 /*
66991 * Newer version of video_device, handled by videodev2.c
66992 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
66993 index e48b571..7e40de4 100644
66994 --- a/include/media/v4l2-ioctl.h
66995 +++ b/include/media/v4l2-ioctl.h
66996 @@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
66997 bool valid_prio, int cmd, void *arg);
66998 };
66999
67000 -
67001 /* v4l debugging and diagnostics */
67002
67003 /* Debug bitmask flags to be used on V4L2 */
67004 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67005 index 9e5425b..8136ffc 100644
67006 --- a/include/net/caif/cfctrl.h
67007 +++ b/include/net/caif/cfctrl.h
67008 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
67009 void (*radioset_rsp)(void);
67010 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67011 struct cflayer *client_layer);
67012 -};
67013 +} __no_const;
67014
67015 /* Link Setup Parameters for CAIF-Links. */
67016 struct cfctrl_link_param {
67017 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
67018 struct cfctrl {
67019 struct cfsrvl serv;
67020 struct cfctrl_rsp res;
67021 - atomic_t req_seq_no;
67022 - atomic_t rsp_seq_no;
67023 + atomic_unchecked_t req_seq_no;
67024 + atomic_unchecked_t rsp_seq_no;
67025 struct list_head list;
67026 /* Protects from simultaneous access to first_req list */
67027 spinlock_t info_list_lock;
67028 diff --git a/include/net/flow.h b/include/net/flow.h
67029 index 628e11b..4c475df 100644
67030 --- a/include/net/flow.h
67031 +++ b/include/net/flow.h
67032 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67033
67034 extern void flow_cache_flush(void);
67035 extern void flow_cache_flush_deferred(void);
67036 -extern atomic_t flow_cache_genid;
67037 +extern atomic_unchecked_t flow_cache_genid;
67038
67039 #endif
67040 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67041 index e5062c9..48a9a4b 100644
67042 --- a/include/net/gro_cells.h
67043 +++ b/include/net/gro_cells.h
67044 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67045 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67046
67047 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67048 - atomic_long_inc(&dev->rx_dropped);
67049 + atomic_long_inc_unchecked(&dev->rx_dropped);
67050 kfree_skb(skb);
67051 return;
67052 }
67053 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67054 int i;
67055
67056 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67057 - gcells->cells = kcalloc(sizeof(struct gro_cell),
67058 - gcells->gro_cells_mask + 1,
67059 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67060 + sizeof(struct gro_cell),
67061 GFP_KERNEL);
67062 if (!gcells->cells)
67063 return -ENOMEM;
67064 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67065 index 1832927..ce39aea 100644
67066 --- a/include/net/inet_connection_sock.h
67067 +++ b/include/net/inet_connection_sock.h
67068 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67069 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67070 int (*bind_conflict)(const struct sock *sk,
67071 const struct inet_bind_bucket *tb, bool relax);
67072 -};
67073 +} __do_const;
67074
67075 /** inet_connection_sock - INET connection oriented sock
67076 *
67077 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67078 index 53f464d..ba76aaa 100644
67079 --- a/include/net/inetpeer.h
67080 +++ b/include/net/inetpeer.h
67081 @@ -47,8 +47,8 @@ struct inet_peer {
67082 */
67083 union {
67084 struct {
67085 - atomic_t rid; /* Frag reception counter */
67086 - atomic_t ip_id_count; /* IP ID for the next packet */
67087 + atomic_unchecked_t rid; /* Frag reception counter */
67088 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67089 };
67090 struct rcu_head rcu;
67091 struct inet_peer *gc_next;
67092 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67093 more++;
67094 inet_peer_refcheck(p);
67095 do {
67096 - old = atomic_read(&p->ip_id_count);
67097 + old = atomic_read_unchecked(&p->ip_id_count);
67098 new = old + more;
67099 if (!new)
67100 new = 1;
67101 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67102 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67103 return new;
67104 }
67105
67106 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67107 index 9497be1..5a4fafe 100644
67108 --- a/include/net/ip_fib.h
67109 +++ b/include/net/ip_fib.h
67110 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67111
67112 #define FIB_RES_SADDR(net, res) \
67113 ((FIB_RES_NH(res).nh_saddr_genid == \
67114 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67115 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67116 FIB_RES_NH(res).nh_saddr : \
67117 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67118 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67119 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67120 index ee75ccd..2cc2b95 100644
67121 --- a/include/net/ip_vs.h
67122 +++ b/include/net/ip_vs.h
67123 @@ -510,7 +510,7 @@ struct ip_vs_conn {
67124 struct ip_vs_conn *control; /* Master control connection */
67125 atomic_t n_control; /* Number of controlled ones */
67126 struct ip_vs_dest *dest; /* real server */
67127 - atomic_t in_pkts; /* incoming packet counter */
67128 + atomic_unchecked_t in_pkts; /* incoming packet counter */
67129
67130 /* packet transmitter for different forwarding methods. If it
67131 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67132 @@ -648,7 +648,7 @@ struct ip_vs_dest {
67133 __be16 port; /* port number of the server */
67134 union nf_inet_addr addr; /* IP address of the server */
67135 volatile unsigned int flags; /* dest status flags */
67136 - atomic_t conn_flags; /* flags to copy to conn */
67137 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
67138 atomic_t weight; /* server weight */
67139
67140 atomic_t refcnt; /* reference counter */
67141 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67142 index 80ffde3..968b0f4 100644
67143 --- a/include/net/irda/ircomm_tty.h
67144 +++ b/include/net/irda/ircomm_tty.h
67145 @@ -35,6 +35,7 @@
67146 #include <linux/termios.h>
67147 #include <linux/timer.h>
67148 #include <linux/tty.h> /* struct tty_struct */
67149 +#include <asm/local.h>
67150
67151 #include <net/irda/irias_object.h>
67152 #include <net/irda/ircomm_core.h>
67153 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67154 index cc7c197..9f2da2a 100644
67155 --- a/include/net/iucv/af_iucv.h
67156 +++ b/include/net/iucv/af_iucv.h
67157 @@ -141,7 +141,7 @@ struct iucv_sock {
67158 struct iucv_sock_list {
67159 struct hlist_head head;
67160 rwlock_t lock;
67161 - atomic_t autobind_name;
67162 + atomic_unchecked_t autobind_name;
67163 };
67164
67165 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67166 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67167 index 0dab173..1b76af0 100644
67168 --- a/include/net/neighbour.h
67169 +++ b/include/net/neighbour.h
67170 @@ -123,7 +123,7 @@ struct neigh_ops {
67171 void (*error_report)(struct neighbour *, struct sk_buff *);
67172 int (*output)(struct neighbour *, struct sk_buff *);
67173 int (*connected_output)(struct neighbour *, struct sk_buff *);
67174 -};
67175 +} __do_const;
67176
67177 struct pneigh_entry {
67178 struct pneigh_entry *next;
67179 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
67180 index 95e6466..251016d 100644
67181 --- a/include/net/net_namespace.h
67182 +++ b/include/net/net_namespace.h
67183 @@ -110,7 +110,7 @@ struct net {
67184 #endif
67185 struct netns_ipvs *ipvs;
67186 struct sock *diag_nlsk;
67187 - atomic_t rt_genid;
67188 + atomic_unchecked_t rt_genid;
67189 };
67190
67191 /*
67192 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
67193
67194 static inline int rt_genid(struct net *net)
67195 {
67196 - return atomic_read(&net->rt_genid);
67197 + return atomic_read_unchecked(&net->rt_genid);
67198 }
67199
67200 static inline void rt_genid_bump(struct net *net)
67201 {
67202 - atomic_inc(&net->rt_genid);
67203 + atomic_inc_unchecked(&net->rt_genid);
67204 }
67205
67206 #endif /* __NET_NET_NAMESPACE_H */
67207 diff --git a/include/net/netdma.h b/include/net/netdma.h
67208 index 8ba8ce2..99b7fff 100644
67209 --- a/include/net/netdma.h
67210 +++ b/include/net/netdma.h
67211 @@ -24,7 +24,7 @@
67212 #include <linux/dmaengine.h>
67213 #include <linux/skbuff.h>
67214
67215 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67216 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67217 struct sk_buff *skb, int offset, struct iovec *to,
67218 size_t len, struct dma_pinned_list *pinned_list);
67219
67220 diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
67221 index 252fd10..aa1421f 100644
67222 --- a/include/net/netfilter/nf_queue.h
67223 +++ b/include/net/netfilter/nf_queue.h
67224 @@ -22,7 +22,7 @@ struct nf_queue_handler {
67225 int (*outfn)(struct nf_queue_entry *entry,
67226 unsigned int queuenum);
67227 char *name;
67228 -};
67229 +} __do_const;
67230
67231 extern int nf_register_queue_handler(u_int8_t pf,
67232 const struct nf_queue_handler *qh);
67233 diff --git a/include/net/netlink.h b/include/net/netlink.h
67234 index 9690b0f..87aded7 100644
67235 --- a/include/net/netlink.h
67236 +++ b/include/net/netlink.h
67237 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
67238 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
67239 {
67240 if (mark)
67241 - skb_trim(skb, (unsigned char *) mark - skb->data);
67242 + skb_trim(skb, (const unsigned char *) mark - skb->data);
67243 }
67244
67245 /**
67246 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
67247 index 2ae2b83..dbdc85e 100644
67248 --- a/include/net/netns/ipv4.h
67249 +++ b/include/net/netns/ipv4.h
67250 @@ -64,7 +64,7 @@ struct netns_ipv4 {
67251 kgid_t sysctl_ping_group_range[2];
67252 long sysctl_tcp_mem[3];
67253
67254 - atomic_t dev_addr_genid;
67255 + atomic_unchecked_t dev_addr_genid;
67256
67257 #ifdef CONFIG_IP_MROUTE
67258 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
67259 diff --git a/include/net/protocol.h b/include/net/protocol.h
67260 index 929528c..c84d4f6 100644
67261 --- a/include/net/protocol.h
67262 +++ b/include/net/protocol.h
67263 @@ -48,7 +48,7 @@ struct net_protocol {
67264 int (*gro_complete)(struct sk_buff *skb);
67265 unsigned int no_policy:1,
67266 netns_ok:1;
67267 -};
67268 +} __do_const;
67269
67270 #if IS_ENABLED(CONFIG_IPV6)
67271 struct inet6_protocol {
67272 @@ -69,7 +69,7 @@ struct inet6_protocol {
67273 int (*gro_complete)(struct sk_buff *skb);
67274
67275 unsigned int flags; /* INET6_PROTO_xxx */
67276 -};
67277 +} __do_const;
67278
67279 #define INET6_PROTO_NOPOLICY 0x1
67280 #define INET6_PROTO_FINAL 0x2
67281 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
67282 index 9c6414f..fbd0524 100644
67283 --- a/include/net/sctp/sctp.h
67284 +++ b/include/net/sctp/sctp.h
67285 @@ -318,9 +318,9 @@ do { \
67286
67287 #else /* SCTP_DEBUG */
67288
67289 -#define SCTP_DEBUG_PRINTK(whatever...)
67290 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
67291 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
67292 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
67293 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
67294 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
67295 #define SCTP_ENABLE_DEBUG
67296 #define SCTP_DISABLE_DEBUG
67297 #define SCTP_ASSERT(expr, str, func)
67298 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
67299 index 64158aa..b65533c 100644
67300 --- a/include/net/sctp/structs.h
67301 +++ b/include/net/sctp/structs.h
67302 @@ -496,7 +496,7 @@ struct sctp_af {
67303 int sockaddr_len;
67304 sa_family_t sa_family;
67305 struct list_head list;
67306 -};
67307 +} __do_const;
67308
67309 struct sctp_af *sctp_get_af_specific(sa_family_t);
67310 int sctp_register_af(struct sctp_af *);
67311 @@ -516,7 +516,7 @@ struct sctp_pf {
67312 struct sctp_association *asoc);
67313 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
67314 struct sctp_af *af;
67315 -};
67316 +} __do_const;
67317
67318
67319 /* Structure to track chunk fragments that have been acked, but peer
67320 diff --git a/include/net/sock.h b/include/net/sock.h
67321 index c945fba..e162e56 100644
67322 --- a/include/net/sock.h
67323 +++ b/include/net/sock.h
67324 @@ -304,7 +304,7 @@ struct sock {
67325 #ifdef CONFIG_RPS
67326 __u32 sk_rxhash;
67327 #endif
67328 - atomic_t sk_drops;
67329 + atomic_unchecked_t sk_drops;
67330 int sk_rcvbuf;
67331
67332 struct sk_filter __rcu *sk_filter;
67333 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
67334 }
67335
67336 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
67337 - char __user *from, char *to,
67338 + char __user *from, unsigned char *to,
67339 int copy, int offset)
67340 {
67341 if (skb->ip_summed == CHECKSUM_NONE) {
67342 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
67343 }
67344 }
67345
67346 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67347 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67348
67349 /**
67350 * sk_page_frag - return an appropriate page_frag
67351 diff --git a/include/net/tcp.h b/include/net/tcp.h
67352 index 4af45e3..af97861 100644
67353 --- a/include/net/tcp.h
67354 +++ b/include/net/tcp.h
67355 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67356 extern void tcp_xmit_retransmit_queue(struct sock *);
67357 extern void tcp_simple_retransmit(struct sock *);
67358 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67359 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67360 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67361
67362 extern void tcp_send_probe0(struct sock *);
67363 extern void tcp_send_partial(struct sock *);
67364 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
67365 struct inet6_skb_parm h6;
67366 #endif
67367 } header; /* For incoming frames */
67368 - __u32 seq; /* Starting sequence number */
67369 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67370 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
67371 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67372 __u32 when; /* used to compute rtt's */
67373 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67374
67375 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
67376
67377 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67378 /* 1 byte hole */
67379 - __u32 ack_seq; /* Sequence number ACK'd */
67380 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67381 };
67382
67383 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67384 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67385 index 63445ed..74ef61d 100644
67386 --- a/include/net/xfrm.h
67387 +++ b/include/net/xfrm.h
67388 @@ -423,7 +423,7 @@ struct xfrm_mode {
67389 struct module *owner;
67390 unsigned int encap;
67391 int flags;
67392 -};
67393 +} __do_const;
67394
67395 /* Flags for xfrm_mode. */
67396 enum {
67397 @@ -514,7 +514,7 @@ struct xfrm_policy {
67398 struct timer_list timer;
67399
67400 struct flow_cache_object flo;
67401 - atomic_t genid;
67402 + atomic_unchecked_t genid;
67403 u32 priority;
67404 u32 index;
67405 struct xfrm_mark mark;
67406 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67407 index 1a046b1..ee0bef0 100644
67408 --- a/include/rdma/iw_cm.h
67409 +++ b/include/rdma/iw_cm.h
67410 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
67411 int backlog);
67412
67413 int (*destroy_listen)(struct iw_cm_id *cm_id);
67414 -};
67415 +} __no_const;
67416
67417 /**
67418 * iw_create_cm_id - Create an IW CM identifier.
67419 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67420 index 399162b..b337f1a 100644
67421 --- a/include/scsi/libfc.h
67422 +++ b/include/scsi/libfc.h
67423 @@ -762,6 +762,7 @@ struct libfc_function_template {
67424 */
67425 void (*disc_stop_final) (struct fc_lport *);
67426 };
67427 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67428
67429 /**
67430 * struct fc_disc - Discovery context
67431 @@ -866,7 +867,7 @@ struct fc_lport {
67432 struct fc_vport *vport;
67433
67434 /* Operational Information */
67435 - struct libfc_function_template tt;
67436 + libfc_function_template_no_const tt;
67437 u8 link_up;
67438 u8 qfull;
67439 enum fc_lport_state state;
67440 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67441 index 55367b0..d97bd2a 100644
67442 --- a/include/scsi/scsi_device.h
67443 +++ b/include/scsi/scsi_device.h
67444 @@ -169,9 +169,9 @@ struct scsi_device {
67445 unsigned int max_device_blocked; /* what device_blocked counts down from */
67446 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67447
67448 - atomic_t iorequest_cnt;
67449 - atomic_t iodone_cnt;
67450 - atomic_t ioerr_cnt;
67451 + atomic_unchecked_t iorequest_cnt;
67452 + atomic_unchecked_t iodone_cnt;
67453 + atomic_unchecked_t ioerr_cnt;
67454
67455 struct device sdev_gendev,
67456 sdev_dev;
67457 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67458 index b797e8f..8e2c3aa 100644
67459 --- a/include/scsi/scsi_transport_fc.h
67460 +++ b/include/scsi/scsi_transport_fc.h
67461 @@ -751,7 +751,8 @@ struct fc_function_template {
67462 unsigned long show_host_system_hostname:1;
67463
67464 unsigned long disable_target_scan:1;
67465 -};
67466 +} __do_const;
67467 +typedef struct fc_function_template __no_const fc_function_template_no_const;
67468
67469
67470 /**
67471 diff --git a/include/sound/soc.h b/include/sound/soc.h
67472 index 91244a0..89ca1a7 100644
67473 --- a/include/sound/soc.h
67474 +++ b/include/sound/soc.h
67475 @@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67476 /* probe ordering - for components with runtime dependencies */
67477 int probe_order;
67478 int remove_order;
67479 -};
67480 +} __do_const;
67481
67482 /* SoC platform interface */
67483 struct snd_soc_platform_driver {
67484 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67485 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67486 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67487 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67488 -};
67489 +} __do_const;
67490
67491 struct snd_soc_platform {
67492 const char *name;
67493 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67494 index fca8bbe..c0242ea 100644
67495 --- a/include/target/target_core_base.h
67496 +++ b/include/target/target_core_base.h
67497 @@ -760,7 +760,7 @@ struct se_device {
67498 spinlock_t stats_lock;
67499 /* Active commands on this virtual SE device */
67500 atomic_t simple_cmds;
67501 - atomic_t dev_ordered_id;
67502 + atomic_unchecked_t dev_ordered_id;
67503 atomic_t dev_ordered_sync;
67504 atomic_t dev_qf_count;
67505 struct se_obj dev_obj;
67506 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67507 new file mode 100644
67508 index 0000000..fb634b7
67509 --- /dev/null
67510 +++ b/include/trace/events/fs.h
67511 @@ -0,0 +1,53 @@
67512 +#undef TRACE_SYSTEM
67513 +#define TRACE_SYSTEM fs
67514 +
67515 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67516 +#define _TRACE_FS_H
67517 +
67518 +#include <linux/fs.h>
67519 +#include <linux/tracepoint.h>
67520 +
67521 +TRACE_EVENT(do_sys_open,
67522 +
67523 + TP_PROTO(const char *filename, int flags, int mode),
67524 +
67525 + TP_ARGS(filename, flags, mode),
67526 +
67527 + TP_STRUCT__entry(
67528 + __string( filename, filename )
67529 + __field( int, flags )
67530 + __field( int, mode )
67531 + ),
67532 +
67533 + TP_fast_assign(
67534 + __assign_str(filename, filename);
67535 + __entry->flags = flags;
67536 + __entry->mode = mode;
67537 + ),
67538 +
67539 + TP_printk("\"%s\" %x %o",
67540 + __get_str(filename), __entry->flags, __entry->mode)
67541 +);
67542 +
67543 +TRACE_EVENT(open_exec,
67544 +
67545 + TP_PROTO(const char *filename),
67546 +
67547 + TP_ARGS(filename),
67548 +
67549 + TP_STRUCT__entry(
67550 + __string( filename, filename )
67551 + ),
67552 +
67553 + TP_fast_assign(
67554 + __assign_str(filename, filename);
67555 + ),
67556 +
67557 + TP_printk("\"%s\"",
67558 + __get_str(filename))
67559 +);
67560 +
67561 +#endif /* _TRACE_FS_H */
67562 +
67563 +/* This part must be outside protection */
67564 +#include <trace/define_trace.h>
67565 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67566 index 1c09820..7f5ec79 100644
67567 --- a/include/trace/events/irq.h
67568 +++ b/include/trace/events/irq.h
67569 @@ -36,7 +36,7 @@ struct softirq_action;
67570 */
67571 TRACE_EVENT(irq_handler_entry,
67572
67573 - TP_PROTO(int irq, struct irqaction *action),
67574 + TP_PROTO(int irq, const struct irqaction *action),
67575
67576 TP_ARGS(irq, action),
67577
67578 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67579 */
67580 TRACE_EVENT(irq_handler_exit,
67581
67582 - TP_PROTO(int irq, struct irqaction *action, int ret),
67583 + TP_PROTO(int irq, const struct irqaction *action, int ret),
67584
67585 TP_ARGS(irq, action, ret),
67586
67587 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67588 index 7caf44c..23c6f27 100644
67589 --- a/include/uapi/linux/a.out.h
67590 +++ b/include/uapi/linux/a.out.h
67591 @@ -39,6 +39,14 @@ enum machine_type {
67592 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67593 };
67594
67595 +/* Constants for the N_FLAGS field */
67596 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67597 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67598 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67599 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67600 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67601 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67602 +
67603 #if !defined (N_MAGIC)
67604 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67605 #endif
67606 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67607 index d876736..b36014e 100644
67608 --- a/include/uapi/linux/byteorder/little_endian.h
67609 +++ b/include/uapi/linux/byteorder/little_endian.h
67610 @@ -42,51 +42,51 @@
67611
67612 static inline __le64 __cpu_to_le64p(const __u64 *p)
67613 {
67614 - return (__force __le64)*p;
67615 + return (__force const __le64)*p;
67616 }
67617 static inline __u64 __le64_to_cpup(const __le64 *p)
67618 {
67619 - return (__force __u64)*p;
67620 + return (__force const __u64)*p;
67621 }
67622 static inline __le32 __cpu_to_le32p(const __u32 *p)
67623 {
67624 - return (__force __le32)*p;
67625 + return (__force const __le32)*p;
67626 }
67627 static inline __u32 __le32_to_cpup(const __le32 *p)
67628 {
67629 - return (__force __u32)*p;
67630 + return (__force const __u32)*p;
67631 }
67632 static inline __le16 __cpu_to_le16p(const __u16 *p)
67633 {
67634 - return (__force __le16)*p;
67635 + return (__force const __le16)*p;
67636 }
67637 static inline __u16 __le16_to_cpup(const __le16 *p)
67638 {
67639 - return (__force __u16)*p;
67640 + return (__force const __u16)*p;
67641 }
67642 static inline __be64 __cpu_to_be64p(const __u64 *p)
67643 {
67644 - return (__force __be64)__swab64p(p);
67645 + return (__force const __be64)__swab64p(p);
67646 }
67647 static inline __u64 __be64_to_cpup(const __be64 *p)
67648 {
67649 - return __swab64p((__u64 *)p);
67650 + return __swab64p((const __u64 *)p);
67651 }
67652 static inline __be32 __cpu_to_be32p(const __u32 *p)
67653 {
67654 - return (__force __be32)__swab32p(p);
67655 + return (__force const __be32)__swab32p(p);
67656 }
67657 static inline __u32 __be32_to_cpup(const __be32 *p)
67658 {
67659 - return __swab32p((__u32 *)p);
67660 + return __swab32p((const __u32 *)p);
67661 }
67662 static inline __be16 __cpu_to_be16p(const __u16 *p)
67663 {
67664 - return (__force __be16)__swab16p(p);
67665 + return (__force const __be16)__swab16p(p);
67666 }
67667 static inline __u16 __be16_to_cpup(const __be16 *p)
67668 {
67669 - return __swab16p((__u16 *)p);
67670 + return __swab16p((const __u16 *)p);
67671 }
67672 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67673 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67674 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67675 index 126a817..d522bd1 100644
67676 --- a/include/uapi/linux/elf.h
67677 +++ b/include/uapi/linux/elf.h
67678 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67679 #define PT_GNU_EH_FRAME 0x6474e550
67680
67681 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67682 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67683 +
67684 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67685 +
67686 +/* Constants for the e_flags field */
67687 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67688 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67689 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67690 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67691 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67692 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67693
67694 /*
67695 * Extended Numbering
67696 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67697 #define DT_DEBUG 21
67698 #define DT_TEXTREL 22
67699 #define DT_JMPREL 23
67700 +#define DT_FLAGS 30
67701 + #define DF_TEXTREL 0x00000004
67702 #define DT_ENCODING 32
67703 #define OLD_DT_LOOS 0x60000000
67704 #define DT_LOOS 0x6000000d
67705 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67706 #define PF_W 0x2
67707 #define PF_X 0x1
67708
67709 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67710 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67711 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67712 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67713 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67714 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67715 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67716 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67717 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67718 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67719 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67720 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67721 +
67722 typedef struct elf32_phdr{
67723 Elf32_Word p_type;
67724 Elf32_Off p_offset;
67725 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67726 #define EI_OSABI 7
67727 #define EI_PAD 8
67728
67729 +#define EI_PAX 14
67730 +
67731 #define ELFMAG0 0x7f /* EI_MAG */
67732 #define ELFMAG1 'E'
67733 #define ELFMAG2 'L'
67734 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67735 index aa169c4..6a2771d 100644
67736 --- a/include/uapi/linux/personality.h
67737 +++ b/include/uapi/linux/personality.h
67738 @@ -30,6 +30,7 @@ enum {
67739 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67740 ADDR_NO_RANDOMIZE | \
67741 ADDR_COMPAT_LAYOUT | \
67742 + ADDR_LIMIT_3GB | \
67743 MMAP_PAGE_ZERO)
67744
67745 /*
67746 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67747 index 7530e74..e714828 100644
67748 --- a/include/uapi/linux/screen_info.h
67749 +++ b/include/uapi/linux/screen_info.h
67750 @@ -43,7 +43,8 @@ struct screen_info {
67751 __u16 pages; /* 0x32 */
67752 __u16 vesa_attributes; /* 0x34 */
67753 __u32 capabilities; /* 0x36 */
67754 - __u8 _reserved[6]; /* 0x3a */
67755 + __u16 vesapm_size; /* 0x3a */
67756 + __u8 _reserved[4]; /* 0x3c */
67757 } __attribute__((packed));
67758
67759 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67760 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67761 index 6d67213..8dab561 100644
67762 --- a/include/uapi/linux/sysctl.h
67763 +++ b/include/uapi/linux/sysctl.h
67764 @@ -155,7 +155,11 @@ enum
67765 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67766 };
67767
67768 -
67769 +#ifdef CONFIG_PAX_SOFTMODE
67770 +enum {
67771 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67772 +};
67773 +#endif
67774
67775 /* CTL_VM names: */
67776 enum
67777 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67778 index 26607bd..588b65f 100644
67779 --- a/include/uapi/linux/xattr.h
67780 +++ b/include/uapi/linux/xattr.h
67781 @@ -60,5 +60,9 @@
67782 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67783 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67784
67785 +/* User namespace */
67786 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67787 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
67788 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67789
67790 #endif /* _UAPI_LINUX_XATTR_H */
67791 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67792 index f9466fa..f4e2b81 100644
67793 --- a/include/video/udlfb.h
67794 +++ b/include/video/udlfb.h
67795 @@ -53,10 +53,10 @@ struct dlfb_data {
67796 u32 pseudo_palette[256];
67797 int blank_mode; /*one of FB_BLANK_ */
67798 /* blit-only rendering path metrics, exposed through sysfs */
67799 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67800 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67801 - atomic_t bytes_sent; /* to usb, after compression including overhead */
67802 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67803 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67804 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67805 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67806 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67807 };
67808
67809 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67810 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67811 index 0993a22..32ba2fe 100644
67812 --- a/include/video/uvesafb.h
67813 +++ b/include/video/uvesafb.h
67814 @@ -177,6 +177,7 @@ struct uvesafb_par {
67815 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67816 u8 pmi_setpal; /* PMI for palette changes */
67817 u16 *pmi_base; /* protected mode interface location */
67818 + u8 *pmi_code; /* protected mode code location */
67819 void *pmi_start;
67820 void *pmi_pal;
67821 u8 *vbe_state_orig; /*
67822 diff --git a/init/Kconfig b/init/Kconfig
67823 index 6fdd6e3..5b01610 100644
67824 --- a/init/Kconfig
67825 +++ b/init/Kconfig
67826 @@ -925,6 +925,7 @@ endif # CGROUPS
67827
67828 config CHECKPOINT_RESTORE
67829 bool "Checkpoint/restore support" if EXPERT
67830 + depends on !GRKERNSEC
67831 default n
67832 help
67833 Enables additional kernel features in a sake of checkpoint/restore.
67834 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67835 depends on OCFS2_FS = n
67836 depends on XFS_FS = n
67837
67838 + depends on GRKERNSEC = n
67839 +
67840 config UIDGID_STRICT_TYPE_CHECKS
67841 bool "Require conversions between uid/gids and their internal representation"
67842 depends on UIDGID_CONVERTED
67843 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67844
67845 config COMPAT_BRK
67846 bool "Disable heap randomization"
67847 - default y
67848 + default n
67849 help
67850 Randomizing heap placement makes heap exploits harder, but it
67851 also breaks ancient binaries (including anything libc5 based).
67852 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67853 config STOP_MACHINE
67854 bool
67855 default y
67856 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67857 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67858 help
67859 Need stop_machine() primitive.
67860
67861 diff --git a/init/Makefile b/init/Makefile
67862 index 7bc47ee..6da2dc7 100644
67863 --- a/init/Makefile
67864 +++ b/init/Makefile
67865 @@ -2,6 +2,9 @@
67866 # Makefile for the linux kernel.
67867 #
67868
67869 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
67870 +asflags-y := $(GCC_PLUGINS_AFLAGS)
67871 +
67872 obj-y := main.o version.o mounts.o
67873 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67874 obj-y += noinitramfs.o
67875 diff --git a/init/do_mounts.c b/init/do_mounts.c
67876 index f8a6642..4e5ee1b 100644
67877 --- a/init/do_mounts.c
67878 +++ b/init/do_mounts.c
67879 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67880 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67881 {
67882 struct super_block *s;
67883 - int err = sys_mount(name, "/root", fs, flags, data);
67884 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67885 if (err)
67886 return err;
67887
67888 - sys_chdir("/root");
67889 + sys_chdir((const char __force_user *)"/root");
67890 s = current->fs->pwd.dentry->d_sb;
67891 ROOT_DEV = s->s_dev;
67892 printk(KERN_INFO
67893 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67894 va_start(args, fmt);
67895 vsprintf(buf, fmt, args);
67896 va_end(args);
67897 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67898 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67899 if (fd >= 0) {
67900 sys_ioctl(fd, FDEJECT, 0);
67901 sys_close(fd);
67902 }
67903 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67904 - fd = sys_open("/dev/console", O_RDWR, 0);
67905 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67906 if (fd >= 0) {
67907 sys_ioctl(fd, TCGETS, (long)&termios);
67908 termios.c_lflag &= ~ICANON;
67909 sys_ioctl(fd, TCSETSF, (long)&termios);
67910 - sys_read(fd, &c, 1);
67911 + sys_read(fd, (char __user *)&c, 1);
67912 termios.c_lflag |= ICANON;
67913 sys_ioctl(fd, TCSETSF, (long)&termios);
67914 sys_close(fd);
67915 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67916 mount_root();
67917 out:
67918 devtmpfs_mount("dev");
67919 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
67920 - sys_chroot(".");
67921 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
67922 + sys_chroot((const char __force_user *)".");
67923 }
67924 diff --git a/init/do_mounts.h b/init/do_mounts.h
67925 index f5b978a..69dbfe8 100644
67926 --- a/init/do_mounts.h
67927 +++ b/init/do_mounts.h
67928 @@ -15,15 +15,15 @@ extern int root_mountflags;
67929
67930 static inline int create_dev(char *name, dev_t dev)
67931 {
67932 - sys_unlink(name);
67933 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
67934 + sys_unlink((char __force_user *)name);
67935 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
67936 }
67937
67938 #if BITS_PER_LONG == 32
67939 static inline u32 bstat(char *name)
67940 {
67941 struct stat64 stat;
67942 - if (sys_stat64(name, &stat) != 0)
67943 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
67944 return 0;
67945 if (!S_ISBLK(stat.st_mode))
67946 return 0;
67947 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
67948 static inline u32 bstat(char *name)
67949 {
67950 struct stat stat;
67951 - if (sys_newstat(name, &stat) != 0)
67952 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
67953 return 0;
67954 if (!S_ISBLK(stat.st_mode))
67955 return 0;
67956 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
67957 index f9acf71..1e19144 100644
67958 --- a/init/do_mounts_initrd.c
67959 +++ b/init/do_mounts_initrd.c
67960 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
67961 create_dev("/dev/root.old", Root_RAM0);
67962 /* mount initrd on rootfs' /root */
67963 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
67964 - sys_mkdir("/old", 0700);
67965 - sys_chdir("/old");
67966 + sys_mkdir((const char __force_user *)"/old", 0700);
67967 + sys_chdir((const char __force_user *)"/old");
67968
67969 /*
67970 * In case that a resume from disk is carried out by linuxrc or one of
67971 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
67972 current->flags &= ~PF_FREEZER_SKIP;
67973
67974 /* move initrd to rootfs' /old */
67975 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
67976 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
67977 /* switch root and cwd back to / of rootfs */
67978 - sys_chroot("..");
67979 + sys_chroot((const char __force_user *)"..");
67980
67981 if (new_decode_dev(real_root_dev) == Root_RAM0) {
67982 - sys_chdir("/old");
67983 + sys_chdir((const char __force_user *)"/old");
67984 return;
67985 }
67986
67987 - sys_chdir("/");
67988 + sys_chdir((const char __force_user *)"/");
67989 ROOT_DEV = new_decode_dev(real_root_dev);
67990 mount_root();
67991
67992 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
67993 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
67994 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
67995 if (!error)
67996 printk("okay\n");
67997 else {
67998 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
67999 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68000 if (error == -ENOENT)
68001 printk("/initrd does not exist. Ignored.\n");
68002 else
68003 printk("failed\n");
68004 printk(KERN_NOTICE "Unmounting old root\n");
68005 - sys_umount("/old", MNT_DETACH);
68006 + sys_umount((char __force_user *)"/old", MNT_DETACH);
68007 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68008 if (fd < 0) {
68009 error = fd;
68010 @@ -120,11 +120,11 @@ int __init initrd_load(void)
68011 * mounted in the normal path.
68012 */
68013 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68014 - sys_unlink("/initrd.image");
68015 + sys_unlink((const char __force_user *)"/initrd.image");
68016 handle_initrd();
68017 return 1;
68018 }
68019 }
68020 - sys_unlink("/initrd.image");
68021 + sys_unlink((const char __force_user *)"/initrd.image");
68022 return 0;
68023 }
68024 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68025 index 8cb6db5..d729f50 100644
68026 --- a/init/do_mounts_md.c
68027 +++ b/init/do_mounts_md.c
68028 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68029 partitioned ? "_d" : "", minor,
68030 md_setup_args[ent].device_names);
68031
68032 - fd = sys_open(name, 0, 0);
68033 + fd = sys_open((char __force_user *)name, 0, 0);
68034 if (fd < 0) {
68035 printk(KERN_ERR "md: open failed - cannot start "
68036 "array %s\n", name);
68037 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68038 * array without it
68039 */
68040 sys_close(fd);
68041 - fd = sys_open(name, 0, 0);
68042 + fd = sys_open((char __force_user *)name, 0, 0);
68043 sys_ioctl(fd, BLKRRPART, 0);
68044 }
68045 sys_close(fd);
68046 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68047
68048 wait_for_device_probe();
68049
68050 - fd = sys_open("/dev/md0", 0, 0);
68051 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68052 if (fd >= 0) {
68053 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68054 sys_close(fd);
68055 diff --git a/init/init_task.c b/init/init_task.c
68056 index 8b2f399..f0797c9 100644
68057 --- a/init/init_task.c
68058 +++ b/init/init_task.c
68059 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68060 * Initial thread structure. Alignment of this is handled by a special
68061 * linker map entry.
68062 */
68063 +#ifdef CONFIG_X86
68064 +union thread_union init_thread_union __init_task_data;
68065 +#else
68066 union thread_union init_thread_union __init_task_data =
68067 { INIT_THREAD_INFO(init_task) };
68068 +#endif
68069 diff --git a/init/initramfs.c b/init/initramfs.c
68070 index 84c6bf1..8899338 100644
68071 --- a/init/initramfs.c
68072 +++ b/init/initramfs.c
68073 @@ -84,7 +84,7 @@ static void __init free_hash(void)
68074 }
68075 }
68076
68077 -static long __init do_utime(char *filename, time_t mtime)
68078 +static long __init do_utime(char __force_user *filename, time_t mtime)
68079 {
68080 struct timespec t[2];
68081
68082 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
68083 struct dir_entry *de, *tmp;
68084 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68085 list_del(&de->list);
68086 - do_utime(de->name, de->mtime);
68087 + do_utime((char __force_user *)de->name, de->mtime);
68088 kfree(de->name);
68089 kfree(de);
68090 }
68091 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
68092 if (nlink >= 2) {
68093 char *old = find_link(major, minor, ino, mode, collected);
68094 if (old)
68095 - return (sys_link(old, collected) < 0) ? -1 : 1;
68096 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68097 }
68098 return 0;
68099 }
68100 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68101 {
68102 struct stat st;
68103
68104 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68105 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68106 if (S_ISDIR(st.st_mode))
68107 - sys_rmdir(path);
68108 + sys_rmdir((char __force_user *)path);
68109 else
68110 - sys_unlink(path);
68111 + sys_unlink((char __force_user *)path);
68112 }
68113 }
68114
68115 @@ -315,7 +315,7 @@ static int __init do_name(void)
68116 int openflags = O_WRONLY|O_CREAT;
68117 if (ml != 1)
68118 openflags |= O_TRUNC;
68119 - wfd = sys_open(collected, openflags, mode);
68120 + wfd = sys_open((char __force_user *)collected, openflags, mode);
68121
68122 if (wfd >= 0) {
68123 sys_fchown(wfd, uid, gid);
68124 @@ -327,17 +327,17 @@ static int __init do_name(void)
68125 }
68126 }
68127 } else if (S_ISDIR(mode)) {
68128 - sys_mkdir(collected, mode);
68129 - sys_chown(collected, uid, gid);
68130 - sys_chmod(collected, mode);
68131 + sys_mkdir((char __force_user *)collected, mode);
68132 + sys_chown((char __force_user *)collected, uid, gid);
68133 + sys_chmod((char __force_user *)collected, mode);
68134 dir_add(collected, mtime);
68135 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68136 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68137 if (maybe_link() == 0) {
68138 - sys_mknod(collected, mode, rdev);
68139 - sys_chown(collected, uid, gid);
68140 - sys_chmod(collected, mode);
68141 - do_utime(collected, mtime);
68142 + sys_mknod((char __force_user *)collected, mode, rdev);
68143 + sys_chown((char __force_user *)collected, uid, gid);
68144 + sys_chmod((char __force_user *)collected, mode);
68145 + do_utime((char __force_user *)collected, mtime);
68146 }
68147 }
68148 return 0;
68149 @@ -346,15 +346,15 @@ static int __init do_name(void)
68150 static int __init do_copy(void)
68151 {
68152 if (count >= body_len) {
68153 - sys_write(wfd, victim, body_len);
68154 + sys_write(wfd, (char __force_user *)victim, body_len);
68155 sys_close(wfd);
68156 - do_utime(vcollected, mtime);
68157 + do_utime((char __force_user *)vcollected, mtime);
68158 kfree(vcollected);
68159 eat(body_len);
68160 state = SkipIt;
68161 return 0;
68162 } else {
68163 - sys_write(wfd, victim, count);
68164 + sys_write(wfd, (char __force_user *)victim, count);
68165 body_len -= count;
68166 eat(count);
68167 return 1;
68168 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
68169 {
68170 collected[N_ALIGN(name_len) + body_len] = '\0';
68171 clean_path(collected, 0);
68172 - sys_symlink(collected + N_ALIGN(name_len), collected);
68173 - sys_lchown(collected, uid, gid);
68174 - do_utime(collected, mtime);
68175 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68176 + sys_lchown((char __force_user *)collected, uid, gid);
68177 + do_utime((char __force_user *)collected, mtime);
68178 state = SkipIt;
68179 next_state = Reset;
68180 return 0;
68181 diff --git a/init/main.c b/init/main.c
68182 index 857166f..9df1d8e 100644
68183 --- a/init/main.c
68184 +++ b/init/main.c
68185 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68186 extern void tc_init(void);
68187 #endif
68188
68189 +extern void grsecurity_init(void);
68190 +
68191 /*
68192 * Debug helper: via this flag we know that we are in 'early bootup code'
68193 * where only the boot processor is running with IRQ disabled. This means
68194 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
68195
68196 __setup("reset_devices", set_reset_devices);
68197
68198 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68199 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
68200 +static int __init setup_grsec_proc_gid(char *str)
68201 +{
68202 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
68203 + return 1;
68204 +}
68205 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
68206 +#endif
68207 +
68208 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
68209 +extern char pax_enter_kernel_user[];
68210 +extern char pax_exit_kernel_user[];
68211 +extern pgdval_t clone_pgd_mask;
68212 +#endif
68213 +
68214 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
68215 +static int __init setup_pax_nouderef(char *str)
68216 +{
68217 +#ifdef CONFIG_X86_32
68218 + unsigned int cpu;
68219 + struct desc_struct *gdt;
68220 +
68221 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
68222 + gdt = get_cpu_gdt_table(cpu);
68223 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
68224 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
68225 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
68226 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
68227 + }
68228 + loadsegment(ds, __KERNEL_DS);
68229 + loadsegment(es, __KERNEL_DS);
68230 + loadsegment(ss, __KERNEL_DS);
68231 +#else
68232 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
68233 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
68234 + clone_pgd_mask = ~(pgdval_t)0UL;
68235 +#endif
68236 +
68237 + return 0;
68238 +}
68239 +early_param("pax_nouderef", setup_pax_nouderef);
68240 +#endif
68241 +
68242 +#ifdef CONFIG_PAX_SOFTMODE
68243 +int pax_softmode;
68244 +
68245 +static int __init setup_pax_softmode(char *str)
68246 +{
68247 + get_option(&str, &pax_softmode);
68248 + return 1;
68249 +}
68250 +__setup("pax_softmode=", setup_pax_softmode);
68251 +#endif
68252 +
68253 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
68254 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
68255 static const char *panic_later, *panic_param;
68256 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
68257 {
68258 int count = preempt_count();
68259 int ret;
68260 + const char *msg1 = "", *msg2 = "";
68261
68262 if (initcall_debug)
68263 ret = do_one_initcall_debug(fn);
68264 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
68265 sprintf(msgbuf, "error code %d ", ret);
68266
68267 if (preempt_count() != count) {
68268 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
68269 + msg1 = " preemption imbalance";
68270 preempt_count() = count;
68271 }
68272 if (irqs_disabled()) {
68273 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
68274 + msg2 = " disabled interrupts";
68275 local_irq_enable();
68276 }
68277 - if (msgbuf[0]) {
68278 - printk("initcall %pF returned with %s\n", fn, msgbuf);
68279 + if (msgbuf[0] || *msg1 || *msg2) {
68280 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
68281 }
68282
68283 return ret;
68284 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
68285 "late",
68286 };
68287
68288 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68289 +u64 latent_entropy;
68290 +#endif
68291 +
68292 static void __init do_initcall_level(int level)
68293 {
68294 extern const struct kernel_param __start___param[], __stop___param[];
68295 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
68296 level, level,
68297 &repair_env_string);
68298
68299 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
68300 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
68301 do_one_initcall(*fn);
68302 +
68303 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68304 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68305 +#endif
68306 +
68307 + }
68308 }
68309
68310 static void __init do_initcalls(void)
68311 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
68312 {
68313 initcall_t *fn;
68314
68315 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
68316 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
68317 do_one_initcall(*fn);
68318 +
68319 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68320 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68321 +#endif
68322 +
68323 + }
68324 }
68325
68326 static int run_init_process(const char *init_filename)
68327 @@ -876,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
68328 do_basic_setup();
68329
68330 /* Open the /dev/console on the rootfs, this should never fail */
68331 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
68332 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
68333 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
68334
68335 (void) sys_dup(0);
68336 @@ -889,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
68337 if (!ramdisk_execute_command)
68338 ramdisk_execute_command = "/init";
68339
68340 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68341 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68342 ramdisk_execute_command = NULL;
68343 prepare_namespace();
68344 }
68345
68346 + grsecurity_init();
68347 +
68348 /*
68349 * Ok, we have completed the initial bootup, and
68350 * we're essentially up and running. Get rid of the
68351 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68352 index 71a3ca1..cc330ee 100644
68353 --- a/ipc/mqueue.c
68354 +++ b/ipc/mqueue.c
68355 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68356 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68357 info->attr.mq_msgsize);
68358
68359 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68360 spin_lock(&mq_lock);
68361 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68362 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68363 diff --git a/ipc/msg.c b/ipc/msg.c
68364 index a71af5a..a90a110 100644
68365 --- a/ipc/msg.c
68366 +++ b/ipc/msg.c
68367 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68368 return security_msg_queue_associate(msq, msgflg);
68369 }
68370
68371 +static struct ipc_ops msg_ops = {
68372 + .getnew = newque,
68373 + .associate = msg_security,
68374 + .more_checks = NULL
68375 +};
68376 +
68377 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68378 {
68379 struct ipc_namespace *ns;
68380 - struct ipc_ops msg_ops;
68381 struct ipc_params msg_params;
68382
68383 ns = current->nsproxy->ipc_ns;
68384
68385 - msg_ops.getnew = newque;
68386 - msg_ops.associate = msg_security;
68387 - msg_ops.more_checks = NULL;
68388 -
68389 msg_params.key = key;
68390 msg_params.flg = msgflg;
68391
68392 diff --git a/ipc/sem.c b/ipc/sem.c
68393 index 58d31f1..cce7a55 100644
68394 --- a/ipc/sem.c
68395 +++ b/ipc/sem.c
68396 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68397 return 0;
68398 }
68399
68400 +static struct ipc_ops sem_ops = {
68401 + .getnew = newary,
68402 + .associate = sem_security,
68403 + .more_checks = sem_more_checks
68404 +};
68405 +
68406 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68407 {
68408 struct ipc_namespace *ns;
68409 - struct ipc_ops sem_ops;
68410 struct ipc_params sem_params;
68411
68412 ns = current->nsproxy->ipc_ns;
68413 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68414 if (nsems < 0 || nsems > ns->sc_semmsl)
68415 return -EINVAL;
68416
68417 - sem_ops.getnew = newary;
68418 - sem_ops.associate = sem_security;
68419 - sem_ops.more_checks = sem_more_checks;
68420 -
68421 sem_params.key = key;
68422 sem_params.flg = semflg;
68423 sem_params.u.nsems = nsems;
68424 diff --git a/ipc/shm.c b/ipc/shm.c
68425 index dff40c9..9450e27 100644
68426 --- a/ipc/shm.c
68427 +++ b/ipc/shm.c
68428 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68429 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68430 #endif
68431
68432 +#ifdef CONFIG_GRKERNSEC
68433 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68434 + const time_t shm_createtime, const uid_t cuid,
68435 + const int shmid);
68436 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68437 + const time_t shm_createtime);
68438 +#endif
68439 +
68440 void shm_init_ns(struct ipc_namespace *ns)
68441 {
68442 ns->shm_ctlmax = SHMMAX;
68443 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68444 shp->shm_lprid = 0;
68445 shp->shm_atim = shp->shm_dtim = 0;
68446 shp->shm_ctim = get_seconds();
68447 +#ifdef CONFIG_GRKERNSEC
68448 + {
68449 + struct timespec timeval;
68450 + do_posix_clock_monotonic_gettime(&timeval);
68451 +
68452 + shp->shm_createtime = timeval.tv_sec;
68453 + }
68454 +#endif
68455 shp->shm_segsz = size;
68456 shp->shm_nattch = 0;
68457 shp->shm_file = file;
68458 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68459 return 0;
68460 }
68461
68462 +static struct ipc_ops shm_ops = {
68463 + .getnew = newseg,
68464 + .associate = shm_security,
68465 + .more_checks = shm_more_checks
68466 +};
68467 +
68468 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68469 {
68470 struct ipc_namespace *ns;
68471 - struct ipc_ops shm_ops;
68472 struct ipc_params shm_params;
68473
68474 ns = current->nsproxy->ipc_ns;
68475
68476 - shm_ops.getnew = newseg;
68477 - shm_ops.associate = shm_security;
68478 - shm_ops.more_checks = shm_more_checks;
68479 -
68480 shm_params.key = key;
68481 shm_params.flg = shmflg;
68482 shm_params.u.size = size;
68483 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68484 f_mode = FMODE_READ | FMODE_WRITE;
68485 }
68486 if (shmflg & SHM_EXEC) {
68487 +
68488 +#ifdef CONFIG_PAX_MPROTECT
68489 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
68490 + goto out;
68491 +#endif
68492 +
68493 prot |= PROT_EXEC;
68494 acc_mode |= S_IXUGO;
68495 }
68496 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68497 if (err)
68498 goto out_unlock;
68499
68500 +#ifdef CONFIG_GRKERNSEC
68501 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68502 + shp->shm_perm.cuid, shmid) ||
68503 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68504 + err = -EACCES;
68505 + goto out_unlock;
68506 + }
68507 +#endif
68508 +
68509 path = shp->shm_file->f_path;
68510 path_get(&path);
68511 shp->shm_nattch++;
68512 +#ifdef CONFIG_GRKERNSEC
68513 + shp->shm_lapid = current->pid;
68514 +#endif
68515 size = i_size_read(path.dentry->d_inode);
68516 shm_unlock(shp);
68517
68518 diff --git a/kernel/acct.c b/kernel/acct.c
68519 index 051e071..15e0920 100644
68520 --- a/kernel/acct.c
68521 +++ b/kernel/acct.c
68522 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68523 */
68524 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68525 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68526 - file->f_op->write(file, (char *)&ac,
68527 + file->f_op->write(file, (char __force_user *)&ac,
68528 sizeof(acct_t), &file->f_pos);
68529 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68530 set_fs(fs);
68531 diff --git a/kernel/audit.c b/kernel/audit.c
68532 index 40414e9..c920b72 100644
68533 --- a/kernel/audit.c
68534 +++ b/kernel/audit.c
68535 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68536 3) suppressed due to audit_rate_limit
68537 4) suppressed due to audit_backlog_limit
68538 */
68539 -static atomic_t audit_lost = ATOMIC_INIT(0);
68540 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68541
68542 /* The netlink socket. */
68543 static struct sock *audit_sock;
68544 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68545 unsigned long now;
68546 int print;
68547
68548 - atomic_inc(&audit_lost);
68549 + atomic_inc_unchecked(&audit_lost);
68550
68551 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68552
68553 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68554 printk(KERN_WARNING
68555 "audit: audit_lost=%d audit_rate_limit=%d "
68556 "audit_backlog_limit=%d\n",
68557 - atomic_read(&audit_lost),
68558 + atomic_read_unchecked(&audit_lost),
68559 audit_rate_limit,
68560 audit_backlog_limit);
68561 audit_panic(message);
68562 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68563 status_set.pid = audit_pid;
68564 status_set.rate_limit = audit_rate_limit;
68565 status_set.backlog_limit = audit_backlog_limit;
68566 - status_set.lost = atomic_read(&audit_lost);
68567 + status_set.lost = atomic_read_unchecked(&audit_lost);
68568 status_set.backlog = skb_queue_len(&audit_skb_queue);
68569 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68570 &status_set, sizeof(status_set));
68571 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68572 index 157e989..b28b365 100644
68573 --- a/kernel/auditsc.c
68574 +++ b/kernel/auditsc.c
68575 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68576 }
68577
68578 /* global counter which is incremented every time something logs in */
68579 -static atomic_t session_id = ATOMIC_INIT(0);
68580 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68581
68582 /**
68583 * audit_set_loginuid - set current task's audit_context loginuid
68584 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68585 return -EPERM;
68586 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68587
68588 - sessionid = atomic_inc_return(&session_id);
68589 + sessionid = atomic_inc_return_unchecked(&session_id);
68590 if (context && context->in_syscall) {
68591 struct audit_buffer *ab;
68592
68593 diff --git a/kernel/capability.c b/kernel/capability.c
68594 index 493d972..ea17248 100644
68595 --- a/kernel/capability.c
68596 +++ b/kernel/capability.c
68597 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68598 * before modification is attempted and the application
68599 * fails.
68600 */
68601 + if (tocopy > ARRAY_SIZE(kdata))
68602 + return -EFAULT;
68603 +
68604 if (copy_to_user(dataptr, kdata, tocopy
68605 * sizeof(struct __user_cap_data_struct))) {
68606 return -EFAULT;
68607 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68608 int ret;
68609
68610 rcu_read_lock();
68611 - ret = security_capable(__task_cred(t), ns, cap);
68612 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68613 + gr_task_is_capable(t, __task_cred(t), cap);
68614 rcu_read_unlock();
68615
68616 - return (ret == 0);
68617 + return ret;
68618 }
68619
68620 /**
68621 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68622 int ret;
68623
68624 rcu_read_lock();
68625 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
68626 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68627 rcu_read_unlock();
68628
68629 - return (ret == 0);
68630 + return ret;
68631 }
68632
68633 /**
68634 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68635 BUG();
68636 }
68637
68638 - if (security_capable(current_cred(), ns, cap) == 0) {
68639 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68640 current->flags |= PF_SUPERPRIV;
68641 return true;
68642 }
68643 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68644 }
68645 EXPORT_SYMBOL(ns_capable);
68646
68647 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
68648 +{
68649 + if (unlikely(!cap_valid(cap))) {
68650 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
68651 + BUG();
68652 + }
68653 +
68654 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68655 + current->flags |= PF_SUPERPRIV;
68656 + return true;
68657 + }
68658 + return false;
68659 +}
68660 +EXPORT_SYMBOL(ns_capable_nolog);
68661 +
68662 /**
68663 * capable - Determine if the current task has a superior capability in effect
68664 * @cap: The capability to be tested for
68665 @@ -408,6 +427,12 @@ bool capable(int cap)
68666 }
68667 EXPORT_SYMBOL(capable);
68668
68669 +bool capable_nolog(int cap)
68670 +{
68671 + return ns_capable_nolog(&init_user_ns, cap);
68672 +}
68673 +EXPORT_SYMBOL(capable_nolog);
68674 +
68675 /**
68676 * nsown_capable - Check superior capability to one's own user_ns
68677 * @cap: The capability in question
68678 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68679
68680 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68681 }
68682 +
68683 +bool inode_capable_nolog(const struct inode *inode, int cap)
68684 +{
68685 + struct user_namespace *ns = current_user_ns();
68686 +
68687 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68688 +}
68689 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68690 index ad99830..992d8a7 100644
68691 --- a/kernel/cgroup.c
68692 +++ b/kernel/cgroup.c
68693 @@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68694 struct css_set *cg = link->cg;
68695 struct task_struct *task;
68696 int count = 0;
68697 - seq_printf(seq, "css_set %p\n", cg);
68698 + seq_printf(seq, "css_set %pK\n", cg);
68699 list_for_each_entry(task, &cg->tasks, cg_list) {
68700 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68701 seq_puts(seq, " ...\n");
68702 diff --git a/kernel/compat.c b/kernel/compat.c
68703 index c28a306..b4d0cf3 100644
68704 --- a/kernel/compat.c
68705 +++ b/kernel/compat.c
68706 @@ -13,6 +13,7 @@
68707
68708 #include <linux/linkage.h>
68709 #include <linux/compat.h>
68710 +#include <linux/module.h>
68711 #include <linux/errno.h>
68712 #include <linux/time.h>
68713 #include <linux/signal.h>
68714 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68715 mm_segment_t oldfs;
68716 long ret;
68717
68718 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68719 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68720 oldfs = get_fs();
68721 set_fs(KERNEL_DS);
68722 ret = hrtimer_nanosleep_restart(restart);
68723 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68724 oldfs = get_fs();
68725 set_fs(KERNEL_DS);
68726 ret = hrtimer_nanosleep(&tu,
68727 - rmtp ? (struct timespec __user *)&rmt : NULL,
68728 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
68729 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68730 set_fs(oldfs);
68731
68732 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68733 mm_segment_t old_fs = get_fs();
68734
68735 set_fs(KERNEL_DS);
68736 - ret = sys_sigpending((old_sigset_t __user *) &s);
68737 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
68738 set_fs(old_fs);
68739 if (ret == 0)
68740 ret = put_user(s, set);
68741 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68742 mm_segment_t old_fs = get_fs();
68743
68744 set_fs(KERNEL_DS);
68745 - ret = sys_old_getrlimit(resource, &r);
68746 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68747 set_fs(old_fs);
68748
68749 if (!ret) {
68750 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68751 mm_segment_t old_fs = get_fs();
68752
68753 set_fs(KERNEL_DS);
68754 - ret = sys_getrusage(who, (struct rusage __user *) &r);
68755 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68756 set_fs(old_fs);
68757
68758 if (ret)
68759 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68760 set_fs (KERNEL_DS);
68761 ret = sys_wait4(pid,
68762 (stat_addr ?
68763 - (unsigned int __user *) &status : NULL),
68764 - options, (struct rusage __user *) &r);
68765 + (unsigned int __force_user *) &status : NULL),
68766 + options, (struct rusage __force_user *) &r);
68767 set_fs (old_fs);
68768
68769 if (ret > 0) {
68770 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68771 memset(&info, 0, sizeof(info));
68772
68773 set_fs(KERNEL_DS);
68774 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68775 - uru ? (struct rusage __user *)&ru : NULL);
68776 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68777 + uru ? (struct rusage __force_user *)&ru : NULL);
68778 set_fs(old_fs);
68779
68780 if ((ret < 0) || (info.si_signo == 0))
68781 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68782 oldfs = get_fs();
68783 set_fs(KERNEL_DS);
68784 err = sys_timer_settime(timer_id, flags,
68785 - (struct itimerspec __user *) &newts,
68786 - (struct itimerspec __user *) &oldts);
68787 + (struct itimerspec __force_user *) &newts,
68788 + (struct itimerspec __force_user *) &oldts);
68789 set_fs(oldfs);
68790 if (!err && old && put_compat_itimerspec(old, &oldts))
68791 return -EFAULT;
68792 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68793 oldfs = get_fs();
68794 set_fs(KERNEL_DS);
68795 err = sys_timer_gettime(timer_id,
68796 - (struct itimerspec __user *) &ts);
68797 + (struct itimerspec __force_user *) &ts);
68798 set_fs(oldfs);
68799 if (!err && put_compat_itimerspec(setting, &ts))
68800 return -EFAULT;
68801 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68802 oldfs = get_fs();
68803 set_fs(KERNEL_DS);
68804 err = sys_clock_settime(which_clock,
68805 - (struct timespec __user *) &ts);
68806 + (struct timespec __force_user *) &ts);
68807 set_fs(oldfs);
68808 return err;
68809 }
68810 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68811 oldfs = get_fs();
68812 set_fs(KERNEL_DS);
68813 err = sys_clock_gettime(which_clock,
68814 - (struct timespec __user *) &ts);
68815 + (struct timespec __force_user *) &ts);
68816 set_fs(oldfs);
68817 if (!err && put_compat_timespec(&ts, tp))
68818 return -EFAULT;
68819 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68820
68821 oldfs = get_fs();
68822 set_fs(KERNEL_DS);
68823 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68824 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68825 set_fs(oldfs);
68826
68827 err = compat_put_timex(utp, &txc);
68828 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68829 oldfs = get_fs();
68830 set_fs(KERNEL_DS);
68831 err = sys_clock_getres(which_clock,
68832 - (struct timespec __user *) &ts);
68833 + (struct timespec __force_user *) &ts);
68834 set_fs(oldfs);
68835 if (!err && tp && put_compat_timespec(&ts, tp))
68836 return -EFAULT;
68837 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68838 long err;
68839 mm_segment_t oldfs;
68840 struct timespec tu;
68841 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68842 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68843
68844 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68845 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68846 oldfs = get_fs();
68847 set_fs(KERNEL_DS);
68848 err = clock_nanosleep_restart(restart);
68849 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68850 oldfs = get_fs();
68851 set_fs(KERNEL_DS);
68852 err = sys_clock_nanosleep(which_clock, flags,
68853 - (struct timespec __user *) &in,
68854 - (struct timespec __user *) &out);
68855 + (struct timespec __force_user *) &in,
68856 + (struct timespec __force_user *) &out);
68857 set_fs(oldfs);
68858
68859 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68860 diff --git a/kernel/configs.c b/kernel/configs.c
68861 index 42e8fa0..9e7406b 100644
68862 --- a/kernel/configs.c
68863 +++ b/kernel/configs.c
68864 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68865 struct proc_dir_entry *entry;
68866
68867 /* create the current config file */
68868 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68869 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68870 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68871 + &ikconfig_file_ops);
68872 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68873 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68874 + &ikconfig_file_ops);
68875 +#endif
68876 +#else
68877 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68878 &ikconfig_file_ops);
68879 +#endif
68880 +
68881 if (!entry)
68882 return -ENOMEM;
68883
68884 diff --git a/kernel/cred.c b/kernel/cred.c
68885 index 48cea3d..3476734 100644
68886 --- a/kernel/cred.c
68887 +++ b/kernel/cred.c
68888 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68889 validate_creds(cred);
68890 alter_cred_subscribers(cred, -1);
68891 put_cred(cred);
68892 +
68893 +#ifdef CONFIG_GRKERNSEC_SETXID
68894 + cred = (struct cred *) tsk->delayed_cred;
68895 + if (cred != NULL) {
68896 + tsk->delayed_cred = NULL;
68897 + validate_creds(cred);
68898 + alter_cred_subscribers(cred, -1);
68899 + put_cred(cred);
68900 + }
68901 +#endif
68902 }
68903
68904 /**
68905 @@ -469,7 +479,7 @@ error_put:
68906 * Always returns 0 thus allowing this function to be tail-called at the end
68907 * of, say, sys_setgid().
68908 */
68909 -int commit_creds(struct cred *new)
68910 +static int __commit_creds(struct cred *new)
68911 {
68912 struct task_struct *task = current;
68913 const struct cred *old = task->real_cred;
68914 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68915
68916 get_cred(new); /* we will require a ref for the subj creds too */
68917
68918 + gr_set_role_label(task, new->uid, new->gid);
68919 +
68920 /* dumpability changes */
68921 if (!uid_eq(old->euid, new->euid) ||
68922 !gid_eq(old->egid, new->egid) ||
68923 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
68924 put_cred(old);
68925 return 0;
68926 }
68927 +#ifdef CONFIG_GRKERNSEC_SETXID
68928 +extern int set_user(struct cred *new);
68929 +
68930 +void gr_delayed_cred_worker(void)
68931 +{
68932 + const struct cred *new = current->delayed_cred;
68933 + struct cred *ncred;
68934 +
68935 + current->delayed_cred = NULL;
68936 +
68937 + if (current_uid() && new != NULL) {
68938 + // from doing get_cred on it when queueing this
68939 + put_cred(new);
68940 + return;
68941 + } else if (new == NULL)
68942 + return;
68943 +
68944 + ncred = prepare_creds();
68945 + if (!ncred)
68946 + goto die;
68947 + // uids
68948 + ncred->uid = new->uid;
68949 + ncred->euid = new->euid;
68950 + ncred->suid = new->suid;
68951 + ncred->fsuid = new->fsuid;
68952 + // gids
68953 + ncred->gid = new->gid;
68954 + ncred->egid = new->egid;
68955 + ncred->sgid = new->sgid;
68956 + ncred->fsgid = new->fsgid;
68957 + // groups
68958 + if (set_groups(ncred, new->group_info) < 0) {
68959 + abort_creds(ncred);
68960 + goto die;
68961 + }
68962 + // caps
68963 + ncred->securebits = new->securebits;
68964 + ncred->cap_inheritable = new->cap_inheritable;
68965 + ncred->cap_permitted = new->cap_permitted;
68966 + ncred->cap_effective = new->cap_effective;
68967 + ncred->cap_bset = new->cap_bset;
68968 +
68969 + if (set_user(ncred)) {
68970 + abort_creds(ncred);
68971 + goto die;
68972 + }
68973 +
68974 + // from doing get_cred on it when queueing this
68975 + put_cred(new);
68976 +
68977 + __commit_creds(ncred);
68978 + return;
68979 +die:
68980 + // from doing get_cred on it when queueing this
68981 + put_cred(new);
68982 + do_group_exit(SIGKILL);
68983 +}
68984 +#endif
68985 +
68986 +int commit_creds(struct cred *new)
68987 +{
68988 +#ifdef CONFIG_GRKERNSEC_SETXID
68989 + int ret;
68990 + int schedule_it = 0;
68991 + struct task_struct *t;
68992 +
68993 + /* we won't get called with tasklist_lock held for writing
68994 + and interrupts disabled as the cred struct in that case is
68995 + init_cred
68996 + */
68997 + if (grsec_enable_setxid && !current_is_single_threaded() &&
68998 + !current_uid() && new->uid) {
68999 + schedule_it = 1;
69000 + }
69001 + ret = __commit_creds(new);
69002 + if (schedule_it) {
69003 + rcu_read_lock();
69004 + read_lock(&tasklist_lock);
69005 + for (t = next_thread(current); t != current;
69006 + t = next_thread(t)) {
69007 + if (t->delayed_cred == NULL) {
69008 + t->delayed_cred = get_cred(new);
69009 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69010 + set_tsk_need_resched(t);
69011 + }
69012 + }
69013 + read_unlock(&tasklist_lock);
69014 + rcu_read_unlock();
69015 + }
69016 + return ret;
69017 +#else
69018 + return __commit_creds(new);
69019 +#endif
69020 +}
69021 +
69022 EXPORT_SYMBOL(commit_creds);
69023
69024 /**
69025 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69026 index 9a61738..c5c8f3a 100644
69027 --- a/kernel/debug/debug_core.c
69028 +++ b/kernel/debug/debug_core.c
69029 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69030 */
69031 static atomic_t masters_in_kgdb;
69032 static atomic_t slaves_in_kgdb;
69033 -static atomic_t kgdb_break_tasklet_var;
69034 +static atomic_unchecked_t kgdb_break_tasklet_var;
69035 atomic_t kgdb_setting_breakpoint;
69036
69037 struct task_struct *kgdb_usethread;
69038 @@ -132,7 +132,7 @@ int kgdb_single_step;
69039 static pid_t kgdb_sstep_pid;
69040
69041 /* to keep track of the CPU which is doing the single stepping*/
69042 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69043 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69044
69045 /*
69046 * If you are debugging a problem where roundup (the collection of
69047 @@ -540,7 +540,7 @@ return_normal:
69048 * kernel will only try for the value of sstep_tries before
69049 * giving up and continuing on.
69050 */
69051 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69052 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69053 (kgdb_info[cpu].task &&
69054 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69055 atomic_set(&kgdb_active, -1);
69056 @@ -634,8 +634,8 @@ cpu_master_loop:
69057 }
69058
69059 kgdb_restore:
69060 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69061 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69062 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69063 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69064 if (kgdb_info[sstep_cpu].task)
69065 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69066 else
69067 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69068 static void kgdb_tasklet_bpt(unsigned long ing)
69069 {
69070 kgdb_breakpoint();
69071 - atomic_set(&kgdb_break_tasklet_var, 0);
69072 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69073 }
69074
69075 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69076
69077 void kgdb_schedule_breakpoint(void)
69078 {
69079 - if (atomic_read(&kgdb_break_tasklet_var) ||
69080 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69081 atomic_read(&kgdb_active) != -1 ||
69082 atomic_read(&kgdb_setting_breakpoint))
69083 return;
69084 - atomic_inc(&kgdb_break_tasklet_var);
69085 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
69086 tasklet_schedule(&kgdb_tasklet_breakpoint);
69087 }
69088 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69089 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69090 index 8875254..7cf4928 100644
69091 --- a/kernel/debug/kdb/kdb_main.c
69092 +++ b/kernel/debug/kdb/kdb_main.c
69093 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69094 continue;
69095
69096 kdb_printf("%-20s%8u 0x%p ", mod->name,
69097 - mod->core_size, (void *)mod);
69098 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
69099 #ifdef CONFIG_MODULE_UNLOAD
69100 kdb_printf("%4ld ", module_refcount(mod));
69101 #endif
69102 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
69103 kdb_printf(" (Loading)");
69104 else
69105 kdb_printf(" (Live)");
69106 - kdb_printf(" 0x%p", mod->module_core);
69107 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69108
69109 #ifdef CONFIG_MODULE_UNLOAD
69110 {
69111 diff --git a/kernel/events/core.c b/kernel/events/core.c
69112 index dbccf83..8c66482 100644
69113 --- a/kernel/events/core.c
69114 +++ b/kernel/events/core.c
69115 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69116 return 0;
69117 }
69118
69119 -static atomic64_t perf_event_id;
69120 +static atomic64_unchecked_t perf_event_id;
69121
69122 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69123 enum event_type_t event_type);
69124 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
69125
69126 static inline u64 perf_event_count(struct perf_event *event)
69127 {
69128 - return local64_read(&event->count) + atomic64_read(&event->child_count);
69129 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69130 }
69131
69132 static u64 perf_event_read(struct perf_event *event)
69133 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69134 mutex_lock(&event->child_mutex);
69135 total += perf_event_read(event);
69136 *enabled += event->total_time_enabled +
69137 - atomic64_read(&event->child_total_time_enabled);
69138 + atomic64_read_unchecked(&event->child_total_time_enabled);
69139 *running += event->total_time_running +
69140 - atomic64_read(&event->child_total_time_running);
69141 + atomic64_read_unchecked(&event->child_total_time_running);
69142
69143 list_for_each_entry(child, &event->child_list, child_list) {
69144 total += perf_event_read(child);
69145 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
69146 userpg->offset -= local64_read(&event->hw.prev_count);
69147
69148 userpg->time_enabled = enabled +
69149 - atomic64_read(&event->child_total_time_enabled);
69150 + atomic64_read_unchecked(&event->child_total_time_enabled);
69151
69152 userpg->time_running = running +
69153 - atomic64_read(&event->child_total_time_running);
69154 + atomic64_read_unchecked(&event->child_total_time_running);
69155
69156 arch_perf_update_userpage(userpg, now);
69157
69158 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69159 values[n++] = perf_event_count(event);
69160 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69161 values[n++] = enabled +
69162 - atomic64_read(&event->child_total_time_enabled);
69163 + atomic64_read_unchecked(&event->child_total_time_enabled);
69164 }
69165 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69166 values[n++] = running +
69167 - atomic64_read(&event->child_total_time_running);
69168 + atomic64_read_unchecked(&event->child_total_time_running);
69169 }
69170 if (read_format & PERF_FORMAT_ID)
69171 values[n++] = primary_event_id(event);
69172 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69173 * need to add enough zero bytes after the string to handle
69174 * the 64bit alignment we do later.
69175 */
69176 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69177 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
69178 if (!buf) {
69179 name = strncpy(tmp, "//enomem", sizeof(tmp));
69180 goto got_name;
69181 }
69182 - name = d_path(&file->f_path, buf, PATH_MAX);
69183 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69184 if (IS_ERR(name)) {
69185 name = strncpy(tmp, "//toolong", sizeof(tmp));
69186 goto got_name;
69187 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69188 event->parent = parent_event;
69189
69190 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69191 - event->id = atomic64_inc_return(&perf_event_id);
69192 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
69193
69194 event->state = PERF_EVENT_STATE_INACTIVE;
69195
69196 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
69197 /*
69198 * Add back the child's count to the parent's count:
69199 */
69200 - atomic64_add(child_val, &parent_event->child_count);
69201 - atomic64_add(child_event->total_time_enabled,
69202 + atomic64_add_unchecked(child_val, &parent_event->child_count);
69203 + atomic64_add_unchecked(child_event->total_time_enabled,
69204 &parent_event->child_total_time_enabled);
69205 - atomic64_add(child_event->total_time_running,
69206 + atomic64_add_unchecked(child_event->total_time_running,
69207 &parent_event->child_total_time_running);
69208
69209 /*
69210 diff --git a/kernel/exit.c b/kernel/exit.c
69211 index 346616c..f103b28 100644
69212 --- a/kernel/exit.c
69213 +++ b/kernel/exit.c
69214 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
69215 struct task_struct *leader;
69216 int zap_leader;
69217 repeat:
69218 +#ifdef CONFIG_NET
69219 + gr_del_task_from_ip_table(p);
69220 +#endif
69221 +
69222 /* don't need to get the RCU readlock here - the process is dead and
69223 * can't be modifying its own credentials. But shut RCU-lockdep up */
69224 rcu_read_lock();
69225 @@ -394,7 +398,7 @@ int allow_signal(int sig)
69226 * know it'll be handled, so that they don't get converted to
69227 * SIGKILL or just silently dropped.
69228 */
69229 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
69230 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
69231 recalc_sigpending();
69232 spin_unlock_irq(&current->sighand->siglock);
69233 return 0;
69234 @@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
69235 vsnprintf(current->comm, sizeof(current->comm), name, args);
69236 va_end(args);
69237
69238 + gr_put_exec_file(current);
69239 + gr_set_kernel_label(current);
69240 +
69241 /*
69242 * If we were started as result of loading a module, close all of the
69243 * user space pages. We don't need them, and if we didn't close them
69244 @@ -812,6 +819,8 @@ void do_exit(long code)
69245 struct task_struct *tsk = current;
69246 int group_dead;
69247
69248 + set_fs(USER_DS);
69249 +
69250 profile_task_exit(tsk);
69251
69252 WARN_ON(blk_needs_flush_plug(tsk));
69253 @@ -828,7 +837,6 @@ void do_exit(long code)
69254 * mm_release()->clear_child_tid() from writing to a user-controlled
69255 * kernel address.
69256 */
69257 - set_fs(USER_DS);
69258
69259 ptrace_event(PTRACE_EVENT_EXIT, code);
69260
69261 @@ -887,6 +895,9 @@ void do_exit(long code)
69262 tsk->exit_code = code;
69263 taskstats_exit(tsk, group_dead);
69264
69265 + gr_acl_handle_psacct(tsk, code);
69266 + gr_acl_handle_exit();
69267 +
69268 exit_mm(tsk);
69269
69270 if (group_dead)
69271 @@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
69272 * Take down every thread in the group. This is called by fatal signals
69273 * as well as by sys_exit_group (below).
69274 */
69275 -void
69276 +__noreturn void
69277 do_group_exit(int exit_code)
69278 {
69279 struct signal_struct *sig = current->signal;
69280 diff --git a/kernel/fork.c b/kernel/fork.c
69281 index acc4cb6..b524cb5 100644
69282 --- a/kernel/fork.c
69283 +++ b/kernel/fork.c
69284 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
69285 *stackend = STACK_END_MAGIC; /* for overflow detection */
69286
69287 #ifdef CONFIG_CC_STACKPROTECTOR
69288 - tsk->stack_canary = get_random_int();
69289 + tsk->stack_canary = pax_get_random_long();
69290 #endif
69291
69292 /*
69293 @@ -344,13 +344,81 @@ free_tsk:
69294 }
69295
69296 #ifdef CONFIG_MMU
69297 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
69298 +{
69299 + struct vm_area_struct *tmp;
69300 + unsigned long charge;
69301 + struct mempolicy *pol;
69302 + struct file *file;
69303 +
69304 + charge = 0;
69305 + if (mpnt->vm_flags & VM_ACCOUNT) {
69306 + unsigned long len = vma_pages(mpnt);
69307 +
69308 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69309 + goto fail_nomem;
69310 + charge = len;
69311 + }
69312 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69313 + if (!tmp)
69314 + goto fail_nomem;
69315 + *tmp = *mpnt;
69316 + tmp->vm_mm = mm;
69317 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
69318 + pol = mpol_dup(vma_policy(mpnt));
69319 + if (IS_ERR(pol))
69320 + goto fail_nomem_policy;
69321 + vma_set_policy(tmp, pol);
69322 + if (anon_vma_fork(tmp, mpnt))
69323 + goto fail_nomem_anon_vma_fork;
69324 + tmp->vm_flags &= ~VM_LOCKED;
69325 + tmp->vm_next = tmp->vm_prev = NULL;
69326 + tmp->vm_mirror = NULL;
69327 + file = tmp->vm_file;
69328 + if (file) {
69329 + struct inode *inode = file->f_path.dentry->d_inode;
69330 + struct address_space *mapping = file->f_mapping;
69331 +
69332 + get_file(file);
69333 + if (tmp->vm_flags & VM_DENYWRITE)
69334 + atomic_dec(&inode->i_writecount);
69335 + mutex_lock(&mapping->i_mmap_mutex);
69336 + if (tmp->vm_flags & VM_SHARED)
69337 + mapping->i_mmap_writable++;
69338 + flush_dcache_mmap_lock(mapping);
69339 + /* insert tmp into the share list, just after mpnt */
69340 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69341 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69342 + else
69343 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69344 + flush_dcache_mmap_unlock(mapping);
69345 + mutex_unlock(&mapping->i_mmap_mutex);
69346 + }
69347 +
69348 + /*
69349 + * Clear hugetlb-related page reserves for children. This only
69350 + * affects MAP_PRIVATE mappings. Faults generated by the child
69351 + * are not guaranteed to succeed, even if read-only
69352 + */
69353 + if (is_vm_hugetlb_page(tmp))
69354 + reset_vma_resv_huge_pages(tmp);
69355 +
69356 + return tmp;
69357 +
69358 +fail_nomem_anon_vma_fork:
69359 + mpol_put(pol);
69360 +fail_nomem_policy:
69361 + kmem_cache_free(vm_area_cachep, tmp);
69362 +fail_nomem:
69363 + vm_unacct_memory(charge);
69364 + return NULL;
69365 +}
69366 +
69367 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69368 {
69369 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69370 struct rb_node **rb_link, *rb_parent;
69371 int retval;
69372 - unsigned long charge;
69373 - struct mempolicy *pol;
69374
69375 down_write(&oldmm->mmap_sem);
69376 flush_cache_dup_mm(oldmm);
69377 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69378 mm->locked_vm = 0;
69379 mm->mmap = NULL;
69380 mm->mmap_cache = NULL;
69381 - mm->free_area_cache = oldmm->mmap_base;
69382 - mm->cached_hole_size = ~0UL;
69383 + mm->free_area_cache = oldmm->free_area_cache;
69384 + mm->cached_hole_size = oldmm->cached_hole_size;
69385 mm->map_count = 0;
69386 cpumask_clear(mm_cpumask(mm));
69387 mm->mm_rb = RB_ROOT;
69388 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69389
69390 prev = NULL;
69391 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69392 - struct file *file;
69393 -
69394 if (mpnt->vm_flags & VM_DONTCOPY) {
69395 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69396 -vma_pages(mpnt));
69397 continue;
69398 }
69399 - charge = 0;
69400 - if (mpnt->vm_flags & VM_ACCOUNT) {
69401 - unsigned long len = vma_pages(mpnt);
69402 -
69403 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69404 - goto fail_nomem;
69405 - charge = len;
69406 - }
69407 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69408 - if (!tmp)
69409 - goto fail_nomem;
69410 - *tmp = *mpnt;
69411 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
69412 - pol = mpol_dup(vma_policy(mpnt));
69413 - retval = PTR_ERR(pol);
69414 - if (IS_ERR(pol))
69415 - goto fail_nomem_policy;
69416 - vma_set_policy(tmp, pol);
69417 - tmp->vm_mm = mm;
69418 - if (anon_vma_fork(tmp, mpnt))
69419 - goto fail_nomem_anon_vma_fork;
69420 - tmp->vm_flags &= ~VM_LOCKED;
69421 - tmp->vm_next = tmp->vm_prev = NULL;
69422 - file = tmp->vm_file;
69423 - if (file) {
69424 - struct inode *inode = file->f_path.dentry->d_inode;
69425 - struct address_space *mapping = file->f_mapping;
69426 -
69427 - get_file(file);
69428 - if (tmp->vm_flags & VM_DENYWRITE)
69429 - atomic_dec(&inode->i_writecount);
69430 - mutex_lock(&mapping->i_mmap_mutex);
69431 - if (tmp->vm_flags & VM_SHARED)
69432 - mapping->i_mmap_writable++;
69433 - flush_dcache_mmap_lock(mapping);
69434 - /* insert tmp into the share list, just after mpnt */
69435 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69436 - vma_nonlinear_insert(tmp,
69437 - &mapping->i_mmap_nonlinear);
69438 - else
69439 - vma_interval_tree_insert_after(tmp, mpnt,
69440 - &mapping->i_mmap);
69441 - flush_dcache_mmap_unlock(mapping);
69442 - mutex_unlock(&mapping->i_mmap_mutex);
69443 + tmp = dup_vma(mm, oldmm, mpnt);
69444 + if (!tmp) {
69445 + retval = -ENOMEM;
69446 + goto out;
69447 }
69448
69449 /*
69450 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69451 if (retval)
69452 goto out;
69453 }
69454 +
69455 +#ifdef CONFIG_PAX_SEGMEXEC
69456 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69457 + struct vm_area_struct *mpnt_m;
69458 +
69459 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69460 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69461 +
69462 + if (!mpnt->vm_mirror)
69463 + continue;
69464 +
69465 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69466 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69467 + mpnt->vm_mirror = mpnt_m;
69468 + } else {
69469 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69470 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69471 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69472 + mpnt->vm_mirror->vm_mirror = mpnt;
69473 + }
69474 + }
69475 + BUG_ON(mpnt_m);
69476 + }
69477 +#endif
69478 +
69479 /* a new mm has just been created */
69480 arch_dup_mmap(oldmm, mm);
69481 retval = 0;
69482 @@ -470,14 +521,6 @@ out:
69483 flush_tlb_mm(oldmm);
69484 up_write(&oldmm->mmap_sem);
69485 return retval;
69486 -fail_nomem_anon_vma_fork:
69487 - mpol_put(pol);
69488 -fail_nomem_policy:
69489 - kmem_cache_free(vm_area_cachep, tmp);
69490 -fail_nomem:
69491 - retval = -ENOMEM;
69492 - vm_unacct_memory(charge);
69493 - goto out;
69494 }
69495
69496 static inline int mm_alloc_pgd(struct mm_struct *mm)
69497 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69498 return ERR_PTR(err);
69499
69500 mm = get_task_mm(task);
69501 - if (mm && mm != current->mm &&
69502 - !ptrace_may_access(task, mode)) {
69503 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69504 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69505 mmput(mm);
69506 mm = ERR_PTR(-EACCES);
69507 }
69508 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69509 spin_unlock(&fs->lock);
69510 return -EAGAIN;
69511 }
69512 - fs->users++;
69513 + atomic_inc(&fs->users);
69514 spin_unlock(&fs->lock);
69515 return 0;
69516 }
69517 tsk->fs = copy_fs_struct(fs);
69518 if (!tsk->fs)
69519 return -ENOMEM;
69520 + /* Carry through gr_chroot_dentry and is_chrooted instead
69521 + of recomputing it here. Already copied when the task struct
69522 + is duplicated. This allows pivot_root to not be treated as
69523 + a chroot
69524 + */
69525 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
69526 +
69527 return 0;
69528 }
69529
69530 @@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69531 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69532 #endif
69533 retval = -EAGAIN;
69534 +
69535 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69536 +
69537 if (atomic_read(&p->real_cred->user->processes) >=
69538 task_rlimit(p, RLIMIT_NPROC)) {
69539 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69540 @@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69541 goto bad_fork_free_pid;
69542 }
69543
69544 + /* synchronizes with gr_set_acls()
69545 + we need to call this past the point of no return for fork()
69546 + */
69547 + gr_copy_label(p);
69548 +
69549 if (clone_flags & CLONE_THREAD) {
69550 current->signal->nr_threads++;
69551 atomic_inc(&current->signal->live);
69552 @@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
69553 bad_fork_free:
69554 free_task(p);
69555 fork_out:
69556 + gr_log_forkfail(retval);
69557 +
69558 return ERR_PTR(retval);
69559 }
69560
69561 @@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
69562 if (clone_flags & CLONE_PARENT_SETTID)
69563 put_user(nr, parent_tidptr);
69564
69565 + gr_handle_brute_check();
69566 +
69567 if (clone_flags & CLONE_VFORK) {
69568 p->vfork_done = &vfork;
69569 init_completion(&vfork);
69570 @@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69571 return 0;
69572
69573 /* don't need lock here; in the worst case we'll do useless copy */
69574 - if (fs->users == 1)
69575 + if (atomic_read(&fs->users) == 1)
69576 return 0;
69577
69578 *new_fsp = copy_fs_struct(fs);
69579 @@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69580 fs = current->fs;
69581 spin_lock(&fs->lock);
69582 current->fs = new_fs;
69583 - if (--fs->users)
69584 + gr_set_chroot_entries(current, &current->fs->root);
69585 + if (atomic_dec_return(&fs->users))
69586 new_fs = NULL;
69587 else
69588 new_fs = fs;
69589 diff --git a/kernel/futex.c b/kernel/futex.c
69590 index 19eb089..b8c65ea 100644
69591 --- a/kernel/futex.c
69592 +++ b/kernel/futex.c
69593 @@ -54,6 +54,7 @@
69594 #include <linux/mount.h>
69595 #include <linux/pagemap.h>
69596 #include <linux/syscalls.h>
69597 +#include <linux/ptrace.h>
69598 #include <linux/signal.h>
69599 #include <linux/export.h>
69600 #include <linux/magic.h>
69601 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69602 struct page *page, *page_head;
69603 int err, ro = 0;
69604
69605 +#ifdef CONFIG_PAX_SEGMEXEC
69606 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69607 + return -EFAULT;
69608 +#endif
69609 +
69610 /*
69611 * The futex address must be "naturally" aligned.
69612 */
69613 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69614 {
69615 u32 curval;
69616 int i;
69617 + mm_segment_t oldfs;
69618
69619 /*
69620 * This will fail and we want it. Some arch implementations do
69621 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69622 * implementation, the non-functional ones will return
69623 * -ENOSYS.
69624 */
69625 + oldfs = get_fs();
69626 + set_fs(USER_DS);
69627 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69628 futex_cmpxchg_enabled = 1;
69629 + set_fs(oldfs);
69630
69631 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69632 plist_head_init(&futex_queues[i].chain);
69633 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69634 index 9b22d03..6295b62 100644
69635 --- a/kernel/gcov/base.c
69636 +++ b/kernel/gcov/base.c
69637 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
69638 }
69639
69640 #ifdef CONFIG_MODULES
69641 -static inline int within(void *addr, void *start, unsigned long size)
69642 -{
69643 - return ((addr >= start) && (addr < start + size));
69644 -}
69645 -
69646 /* Update list and generate events when modules are unloaded. */
69647 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69648 void *data)
69649 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69650 prev = NULL;
69651 /* Remove entries located in module from linked list. */
69652 for (info = gcov_info_head; info; info = info->next) {
69653 - if (within(info, mod->module_core, mod->core_size)) {
69654 + if (within_module_core_rw((unsigned long)info, mod)) {
69655 if (prev)
69656 prev->next = info->next;
69657 else
69658 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69659 index 6db7a5e..25b6648 100644
69660 --- a/kernel/hrtimer.c
69661 +++ b/kernel/hrtimer.c
69662 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69663 local_irq_restore(flags);
69664 }
69665
69666 -static void run_hrtimer_softirq(struct softirq_action *h)
69667 +static void run_hrtimer_softirq(void)
69668 {
69669 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69670
69671 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69672 index 60f48fa..7f3a770 100644
69673 --- a/kernel/jump_label.c
69674 +++ b/kernel/jump_label.c
69675 @@ -13,6 +13,7 @@
69676 #include <linux/sort.h>
69677 #include <linux/err.h>
69678 #include <linux/static_key.h>
69679 +#include <linux/mm.h>
69680
69681 #ifdef HAVE_JUMP_LABEL
69682
69683 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69684
69685 size = (((unsigned long)stop - (unsigned long)start)
69686 / sizeof(struct jump_entry));
69687 + pax_open_kernel();
69688 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69689 + pax_close_kernel();
69690 }
69691
69692 static void jump_label_update(struct static_key *key, int enable);
69693 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69694 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69695 struct jump_entry *iter;
69696
69697 + pax_open_kernel();
69698 for (iter = iter_start; iter < iter_stop; iter++) {
69699 if (within_module_init(iter->code, mod))
69700 iter->code = 0;
69701 }
69702 + pax_close_kernel();
69703 }
69704
69705 static int
69706 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69707 index 2169fee..45c017a 100644
69708 --- a/kernel/kallsyms.c
69709 +++ b/kernel/kallsyms.c
69710 @@ -11,6 +11,9 @@
69711 * Changed the compression method from stem compression to "table lookup"
69712 * compression (see scripts/kallsyms.c for a more complete description)
69713 */
69714 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69715 +#define __INCLUDED_BY_HIDESYM 1
69716 +#endif
69717 #include <linux/kallsyms.h>
69718 #include <linux/module.h>
69719 #include <linux/init.h>
69720 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69721
69722 static inline int is_kernel_inittext(unsigned long addr)
69723 {
69724 + if (system_state != SYSTEM_BOOTING)
69725 + return 0;
69726 +
69727 if (addr >= (unsigned long)_sinittext
69728 && addr <= (unsigned long)_einittext)
69729 return 1;
69730 return 0;
69731 }
69732
69733 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69734 +#ifdef CONFIG_MODULES
69735 +static inline int is_module_text(unsigned long addr)
69736 +{
69737 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69738 + return 1;
69739 +
69740 + addr = ktla_ktva(addr);
69741 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69742 +}
69743 +#else
69744 +static inline int is_module_text(unsigned long addr)
69745 +{
69746 + return 0;
69747 +}
69748 +#endif
69749 +#endif
69750 +
69751 static inline int is_kernel_text(unsigned long addr)
69752 {
69753 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69754 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69755
69756 static inline int is_kernel(unsigned long addr)
69757 {
69758 +
69759 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69760 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
69761 + return 1;
69762 +
69763 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69764 +#else
69765 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69766 +#endif
69767 +
69768 return 1;
69769 return in_gate_area_no_mm(addr);
69770 }
69771
69772 static int is_ksym_addr(unsigned long addr)
69773 {
69774 +
69775 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69776 + if (is_module_text(addr))
69777 + return 0;
69778 +#endif
69779 +
69780 if (all_var)
69781 return is_kernel(addr);
69782
69783 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69784
69785 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69786 {
69787 - iter->name[0] = '\0';
69788 iter->nameoff = get_symbol_offset(new_pos);
69789 iter->pos = new_pos;
69790 }
69791 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69792 {
69793 struct kallsym_iter *iter = m->private;
69794
69795 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69796 + if (current_uid())
69797 + return 0;
69798 +#endif
69799 +
69800 /* Some debugging symbols have no name. Ignore them. */
69801 if (!iter->name[0])
69802 return 0;
69803 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69804 */
69805 type = iter->exported ? toupper(iter->type) :
69806 tolower(iter->type);
69807 +
69808 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69809 type, iter->name, iter->module_name);
69810 } else
69811 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69812 struct kallsym_iter *iter;
69813 int ret;
69814
69815 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69816 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69817 if (!iter)
69818 return -ENOMEM;
69819 reset_iter(iter, 0);
69820 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69821 index 30b7b22..c726387 100644
69822 --- a/kernel/kcmp.c
69823 +++ b/kernel/kcmp.c
69824 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69825 struct task_struct *task1, *task2;
69826 int ret;
69827
69828 +#ifdef CONFIG_GRKERNSEC
69829 + return -ENOSYS;
69830 +#endif
69831 +
69832 rcu_read_lock();
69833
69834 /*
69835 diff --git a/kernel/kexec.c b/kernel/kexec.c
69836 index 5e4bd78..00c5b91 100644
69837 --- a/kernel/kexec.c
69838 +++ b/kernel/kexec.c
69839 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69840 unsigned long flags)
69841 {
69842 struct compat_kexec_segment in;
69843 - struct kexec_segment out, __user *ksegments;
69844 + struct kexec_segment out;
69845 + struct kexec_segment __user *ksegments;
69846 unsigned long i, result;
69847
69848 /* Don't allow clients that don't understand the native
69849 diff --git a/kernel/kmod.c b/kernel/kmod.c
69850 index 1c317e3..4a92a55 100644
69851 --- a/kernel/kmod.c
69852 +++ b/kernel/kmod.c
69853 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69854 kfree(info->argv);
69855 }
69856
69857 -static int call_modprobe(char *module_name, int wait)
69858 +static int call_modprobe(char *module_name, char *module_param, int wait)
69859 {
69860 static char *envp[] = {
69861 "HOME=/",
69862 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69863 NULL
69864 };
69865
69866 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69867 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69868 if (!argv)
69869 goto out;
69870
69871 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69872 argv[1] = "-q";
69873 argv[2] = "--";
69874 argv[3] = module_name; /* check free_modprobe_argv() */
69875 - argv[4] = NULL;
69876 + argv[4] = module_param;
69877 + argv[5] = NULL;
69878
69879 return call_usermodehelper_fns(modprobe_path, argv, envp,
69880 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69881 @@ -120,9 +121,8 @@ out:
69882 * If module auto-loading support is disabled then this function
69883 * becomes a no-operation.
69884 */
69885 -int __request_module(bool wait, const char *fmt, ...)
69886 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69887 {
69888 - va_list args;
69889 char module_name[MODULE_NAME_LEN];
69890 unsigned int max_modprobes;
69891 int ret;
69892 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69893 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69894 static int kmod_loop_msg;
69895
69896 - va_start(args, fmt);
69897 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69898 - va_end(args);
69899 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69900 if (ret >= MODULE_NAME_LEN)
69901 return -ENAMETOOLONG;
69902
69903 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69904 if (ret)
69905 return ret;
69906
69907 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69908 + if (!current_uid()) {
69909 + /* hack to workaround consolekit/udisks stupidity */
69910 + read_lock(&tasklist_lock);
69911 + if (!strcmp(current->comm, "mount") &&
69912 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69913 + read_unlock(&tasklist_lock);
69914 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69915 + return -EPERM;
69916 + }
69917 + read_unlock(&tasklist_lock);
69918 + }
69919 +#endif
69920 +
69921 /* If modprobe needs a service that is in a module, we get a recursive
69922 * loop. Limit the number of running kmod threads to max_threads/2 or
69923 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
69924 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
69925
69926 trace_module_request(module_name, wait, _RET_IP_);
69927
69928 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69929 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69930
69931 atomic_dec(&kmod_concurrent);
69932 return ret;
69933 }
69934 +
69935 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
69936 +{
69937 + va_list args;
69938 + int ret;
69939 +
69940 + va_start(args, fmt);
69941 + ret = ____request_module(wait, module_param, fmt, args);
69942 + va_end(args);
69943 +
69944 + return ret;
69945 +}
69946 +
69947 +int __request_module(bool wait, const char *fmt, ...)
69948 +{
69949 + va_list args;
69950 + int ret;
69951 +
69952 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69953 + if (current_uid()) {
69954 + char module_param[MODULE_NAME_LEN];
69955 +
69956 + memset(module_param, 0, sizeof(module_param));
69957 +
69958 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
69959 +
69960 + va_start(args, fmt);
69961 + ret = ____request_module(wait, module_param, fmt, args);
69962 + va_end(args);
69963 +
69964 + return ret;
69965 + }
69966 +#endif
69967 +
69968 + va_start(args, fmt);
69969 + ret = ____request_module(wait, NULL, fmt, args);
69970 + va_end(args);
69971 +
69972 + return ret;
69973 +}
69974 +
69975 EXPORT_SYMBOL(__request_module);
69976 #endif /* CONFIG_MODULES */
69977
69978 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
69979 *
69980 * Thus the __user pointer cast is valid here.
69981 */
69982 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
69983 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
69984
69985 /*
69986 * If ret is 0, either ____call_usermodehelper failed and the
69987 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
69988 index 098f396..fe85ff1 100644
69989 --- a/kernel/kprobes.c
69990 +++ b/kernel/kprobes.c
69991 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
69992 * kernel image and loaded module images reside. This is required
69993 * so x86_64 can correctly handle the %rip-relative fixups.
69994 */
69995 - kip->insns = module_alloc(PAGE_SIZE);
69996 + kip->insns = module_alloc_exec(PAGE_SIZE);
69997 if (!kip->insns) {
69998 kfree(kip);
69999 return NULL;
70000 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70001 */
70002 if (!list_is_singular(&kip->list)) {
70003 list_del(&kip->list);
70004 - module_free(NULL, kip->insns);
70005 + module_free_exec(NULL, kip->insns);
70006 kfree(kip);
70007 }
70008 return 1;
70009 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70010 {
70011 int i, err = 0;
70012 unsigned long offset = 0, size = 0;
70013 - char *modname, namebuf[128];
70014 + char *modname, namebuf[KSYM_NAME_LEN];
70015 const char *symbol_name;
70016 void *addr;
70017 struct kprobe_blackpoint *kb;
70018 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70019 kprobe_type = "k";
70020
70021 if (sym)
70022 - seq_printf(pi, "%p %s %s+0x%x %s ",
70023 + seq_printf(pi, "%pK %s %s+0x%x %s ",
70024 p->addr, kprobe_type, sym, offset,
70025 (modname ? modname : " "));
70026 else
70027 - seq_printf(pi, "%p %s %p ",
70028 + seq_printf(pi, "%pK %s %pK ",
70029 p->addr, kprobe_type, p->addr);
70030
70031 if (!pp)
70032 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70033 const char *sym = NULL;
70034 unsigned int i = *(loff_t *) v;
70035 unsigned long offset = 0;
70036 - char *modname, namebuf[128];
70037 + char *modname, namebuf[KSYM_NAME_LEN];
70038
70039 head = &kprobe_table[i];
70040 preempt_disable();
70041 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70042 index 4e316e1..5501eef 100644
70043 --- a/kernel/ksysfs.c
70044 +++ b/kernel/ksysfs.c
70045 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70046 {
70047 if (count+1 > UEVENT_HELPER_PATH_LEN)
70048 return -ENOENT;
70049 + if (!capable(CAP_SYS_ADMIN))
70050 + return -EPERM;
70051 memcpy(uevent_helper, buf, count);
70052 uevent_helper[count] = '\0';
70053 if (count && uevent_helper[count-1] == '\n')
70054 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70055 index 7981e5b..7f2105c 100644
70056 --- a/kernel/lockdep.c
70057 +++ b/kernel/lockdep.c
70058 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
70059 end = (unsigned long) &_end,
70060 addr = (unsigned long) obj;
70061
70062 +#ifdef CONFIG_PAX_KERNEXEC
70063 + start = ktla_ktva(start);
70064 +#endif
70065 +
70066 /*
70067 * static variable?
70068 */
70069 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70070 if (!static_obj(lock->key)) {
70071 debug_locks_off();
70072 printk("INFO: trying to register non-static key.\n");
70073 + printk("lock:%pS key:%pS.\n", lock, lock->key);
70074 printk("the code is fine but needs lockdep annotation.\n");
70075 printk("turning off the locking correctness validator.\n");
70076 dump_stack();
70077 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70078 if (!class)
70079 return 0;
70080 }
70081 - atomic_inc((atomic_t *)&class->ops);
70082 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70083 if (very_verbose(class)) {
70084 printk("\nacquire class [%p] %s", class->key, class->name);
70085 if (class->name_version > 1)
70086 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70087 index 91c32a0..7b88d63 100644
70088 --- a/kernel/lockdep_proc.c
70089 +++ b/kernel/lockdep_proc.c
70090 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
70091
70092 static void print_name(struct seq_file *m, struct lock_class *class)
70093 {
70094 - char str[128];
70095 + char str[KSYM_NAME_LEN];
70096 const char *name = class->name;
70097
70098 if (!name) {
70099 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70100 return 0;
70101 }
70102
70103 - seq_printf(m, "%p", class->key);
70104 + seq_printf(m, "%pK", class->key);
70105 #ifdef CONFIG_DEBUG_LOCKDEP
70106 seq_printf(m, " OPS:%8ld", class->ops);
70107 #endif
70108 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70109
70110 list_for_each_entry(entry, &class->locks_after, entry) {
70111 if (entry->distance == 1) {
70112 - seq_printf(m, " -> [%p] ", entry->class->key);
70113 + seq_printf(m, " -> [%pK] ", entry->class->key);
70114 print_name(m, entry->class);
70115 seq_puts(m, "\n");
70116 }
70117 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70118 if (!class->key)
70119 continue;
70120
70121 - seq_printf(m, "[%p] ", class->key);
70122 + seq_printf(m, "[%pK] ", class->key);
70123 print_name(m, class);
70124 seq_puts(m, "\n");
70125 }
70126 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70127 if (!i)
70128 seq_line(m, '-', 40-namelen, namelen);
70129
70130 - snprintf(ip, sizeof(ip), "[<%p>]",
70131 + snprintf(ip, sizeof(ip), "[<%pK>]",
70132 (void *)class->contention_point[i]);
70133 seq_printf(m, "%40s %14lu %29s %pS\n",
70134 name, stats->contention_point[i],
70135 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70136 if (!i)
70137 seq_line(m, '-', 40-namelen, namelen);
70138
70139 - snprintf(ip, sizeof(ip), "[<%p>]",
70140 + snprintf(ip, sizeof(ip), "[<%pK>]",
70141 (void *)class->contending_point[i]);
70142 seq_printf(m, "%40s %14lu %29s %pS\n",
70143 name, stats->contending_point[i],
70144 diff --git a/kernel/module.c b/kernel/module.c
70145 index 3e544f4..34c3008 100644
70146 --- a/kernel/module.c
70147 +++ b/kernel/module.c
70148 @@ -59,6 +59,7 @@
70149 #include <linux/pfn.h>
70150 #include <linux/bsearch.h>
70151 #include <linux/fips.h>
70152 +#include <linux/grsecurity.h>
70153 #include "module-internal.h"
70154
70155 #define CREATE_TRACE_POINTS
70156 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70157
70158 /* Bounds of module allocation, for speeding __module_address.
70159 * Protected by module_mutex. */
70160 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70161 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70162 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70163
70164 int register_module_notifier(struct notifier_block * nb)
70165 {
70166 @@ -319,7 +321,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70167 return true;
70168
70169 list_for_each_entry_rcu(mod, &modules, list) {
70170 - struct symsearch arr[] = {
70171 + struct symsearch modarr[] = {
70172 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70173 NOT_GPL_ONLY, false },
70174 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70175 @@ -344,7 +346,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70176 if (mod->state == MODULE_STATE_UNFORMED)
70177 continue;
70178
70179 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
70180 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
70181 return true;
70182 }
70183 return false;
70184 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
70185 static int percpu_modalloc(struct module *mod,
70186 unsigned long size, unsigned long align)
70187 {
70188 - if (align > PAGE_SIZE) {
70189 + if (align-1 >= PAGE_SIZE) {
70190 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
70191 mod->name, align, PAGE_SIZE);
70192 align = PAGE_SIZE;
70193 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
70194 static ssize_t show_coresize(struct module_attribute *mattr,
70195 struct module_kobject *mk, char *buffer)
70196 {
70197 - return sprintf(buffer, "%u\n", mk->mod->core_size);
70198 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
70199 }
70200
70201 static struct module_attribute modinfo_coresize =
70202 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
70203 static ssize_t show_initsize(struct module_attribute *mattr,
70204 struct module_kobject *mk, char *buffer)
70205 {
70206 - return sprintf(buffer, "%u\n", mk->mod->init_size);
70207 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
70208 }
70209
70210 static struct module_attribute modinfo_initsize =
70211 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
70212 */
70213 #ifdef CONFIG_SYSFS
70214
70215 -#ifdef CONFIG_KALLSYMS
70216 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70217 static inline bool sect_empty(const Elf_Shdr *sect)
70218 {
70219 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
70220 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
70221
70222 static void unset_module_core_ro_nx(struct module *mod)
70223 {
70224 - set_page_attributes(mod->module_core + mod->core_text_size,
70225 - mod->module_core + mod->core_size,
70226 + set_page_attributes(mod->module_core_rw,
70227 + mod->module_core_rw + mod->core_size_rw,
70228 set_memory_x);
70229 - set_page_attributes(mod->module_core,
70230 - mod->module_core + mod->core_ro_size,
70231 + set_page_attributes(mod->module_core_rx,
70232 + mod->module_core_rx + mod->core_size_rx,
70233 set_memory_rw);
70234 }
70235
70236 static void unset_module_init_ro_nx(struct module *mod)
70237 {
70238 - set_page_attributes(mod->module_init + mod->init_text_size,
70239 - mod->module_init + mod->init_size,
70240 + set_page_attributes(mod->module_init_rw,
70241 + mod->module_init_rw + mod->init_size_rw,
70242 set_memory_x);
70243 - set_page_attributes(mod->module_init,
70244 - mod->module_init + mod->init_ro_size,
70245 + set_page_attributes(mod->module_init_rx,
70246 + mod->module_init_rx + mod->init_size_rx,
70247 set_memory_rw);
70248 }
70249
70250 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
70251 list_for_each_entry_rcu(mod, &modules, list) {
70252 if (mod->state == MODULE_STATE_UNFORMED)
70253 continue;
70254 - if ((mod->module_core) && (mod->core_text_size)) {
70255 - set_page_attributes(mod->module_core,
70256 - mod->module_core + mod->core_text_size,
70257 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70258 + set_page_attributes(mod->module_core_rx,
70259 + mod->module_core_rx + mod->core_size_rx,
70260 set_memory_rw);
70261 }
70262 - if ((mod->module_init) && (mod->init_text_size)) {
70263 - set_page_attributes(mod->module_init,
70264 - mod->module_init + mod->init_text_size,
70265 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70266 + set_page_attributes(mod->module_init_rx,
70267 + mod->module_init_rx + mod->init_size_rx,
70268 set_memory_rw);
70269 }
70270 }
70271 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
70272 list_for_each_entry_rcu(mod, &modules, list) {
70273 if (mod->state == MODULE_STATE_UNFORMED)
70274 continue;
70275 - if ((mod->module_core) && (mod->core_text_size)) {
70276 - set_page_attributes(mod->module_core,
70277 - mod->module_core + mod->core_text_size,
70278 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70279 + set_page_attributes(mod->module_core_rx,
70280 + mod->module_core_rx + mod->core_size_rx,
70281 set_memory_ro);
70282 }
70283 - if ((mod->module_init) && (mod->init_text_size)) {
70284 - set_page_attributes(mod->module_init,
70285 - mod->module_init + mod->init_text_size,
70286 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70287 + set_page_attributes(mod->module_init_rx,
70288 + mod->module_init_rx + mod->init_size_rx,
70289 set_memory_ro);
70290 }
70291 }
70292 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
70293
70294 /* This may be NULL, but that's OK */
70295 unset_module_init_ro_nx(mod);
70296 - module_free(mod, mod->module_init);
70297 + module_free(mod, mod->module_init_rw);
70298 + module_free_exec(mod, mod->module_init_rx);
70299 kfree(mod->args);
70300 percpu_modfree(mod);
70301
70302 /* Free lock-classes: */
70303 - lockdep_free_key_range(mod->module_core, mod->core_size);
70304 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
70305 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
70306
70307 /* Finally, free the core (containing the module structure) */
70308 unset_module_core_ro_nx(mod);
70309 - module_free(mod, mod->module_core);
70310 + module_free_exec(mod, mod->module_core_rx);
70311 + module_free(mod, mod->module_core_rw);
70312
70313 #ifdef CONFIG_MPU
70314 update_protections(current->mm);
70315 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70316 int ret = 0;
70317 const struct kernel_symbol *ksym;
70318
70319 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70320 + int is_fs_load = 0;
70321 + int register_filesystem_found = 0;
70322 + char *p;
70323 +
70324 + p = strstr(mod->args, "grsec_modharden_fs");
70325 + if (p) {
70326 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
70327 + /* copy \0 as well */
70328 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
70329 + is_fs_load = 1;
70330 + }
70331 +#endif
70332 +
70333 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
70334 const char *name = info->strtab + sym[i].st_name;
70335
70336 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70337 + /* it's a real shame this will never get ripped and copied
70338 + upstream! ;(
70339 + */
70340 + if (is_fs_load && !strcmp(name, "register_filesystem"))
70341 + register_filesystem_found = 1;
70342 +#endif
70343 +
70344 switch (sym[i].st_shndx) {
70345 case SHN_COMMON:
70346 /* We compiled with -fno-common. These are not
70347 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70348 ksym = resolve_symbol_wait(mod, info, name);
70349 /* Ok if resolved. */
70350 if (ksym && !IS_ERR(ksym)) {
70351 + pax_open_kernel();
70352 sym[i].st_value = ksym->value;
70353 + pax_close_kernel();
70354 break;
70355 }
70356
70357 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70358 secbase = (unsigned long)mod_percpu(mod);
70359 else
70360 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70361 + pax_open_kernel();
70362 sym[i].st_value += secbase;
70363 + pax_close_kernel();
70364 break;
70365 }
70366 }
70367
70368 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70369 + if (is_fs_load && !register_filesystem_found) {
70370 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70371 + ret = -EPERM;
70372 + }
70373 +#endif
70374 +
70375 return ret;
70376 }
70377
70378 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70379 || s->sh_entsize != ~0UL
70380 || strstarts(sname, ".init"))
70381 continue;
70382 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70383 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70384 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70385 + else
70386 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70387 pr_debug("\t%s\n", sname);
70388 }
70389 - switch (m) {
70390 - case 0: /* executable */
70391 - mod->core_size = debug_align(mod->core_size);
70392 - mod->core_text_size = mod->core_size;
70393 - break;
70394 - case 1: /* RO: text and ro-data */
70395 - mod->core_size = debug_align(mod->core_size);
70396 - mod->core_ro_size = mod->core_size;
70397 - break;
70398 - case 3: /* whole core */
70399 - mod->core_size = debug_align(mod->core_size);
70400 - break;
70401 - }
70402 }
70403
70404 pr_debug("Init section allocation order:\n");
70405 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70406 || s->sh_entsize != ~0UL
70407 || !strstarts(sname, ".init"))
70408 continue;
70409 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70410 - | INIT_OFFSET_MASK);
70411 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70412 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70413 + else
70414 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70415 + s->sh_entsize |= INIT_OFFSET_MASK;
70416 pr_debug("\t%s\n", sname);
70417 }
70418 - switch (m) {
70419 - case 0: /* executable */
70420 - mod->init_size = debug_align(mod->init_size);
70421 - mod->init_text_size = mod->init_size;
70422 - break;
70423 - case 1: /* RO: text and ro-data */
70424 - mod->init_size = debug_align(mod->init_size);
70425 - mod->init_ro_size = mod->init_size;
70426 - break;
70427 - case 3: /* whole init */
70428 - mod->init_size = debug_align(mod->init_size);
70429 - break;
70430 - }
70431 }
70432 }
70433
70434 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70435
70436 /* Put symbol section at end of init part of module. */
70437 symsect->sh_flags |= SHF_ALLOC;
70438 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70439 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70440 info->index.sym) | INIT_OFFSET_MASK;
70441 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70442
70443 @@ -2326,13 +2344,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70444 }
70445
70446 /* Append room for core symbols at end of core part. */
70447 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70448 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70449 - mod->core_size += strtab_size;
70450 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70451 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70452 + mod->core_size_rx += strtab_size;
70453
70454 /* Put string table section at end of init part of module. */
70455 strsect->sh_flags |= SHF_ALLOC;
70456 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70457 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70458 info->index.str) | INIT_OFFSET_MASK;
70459 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70460 }
70461 @@ -2350,12 +2368,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70462 /* Make sure we get permanent strtab: don't use info->strtab. */
70463 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70464
70465 + pax_open_kernel();
70466 +
70467 /* Set types up while we still have access to sections. */
70468 for (i = 0; i < mod->num_symtab; i++)
70469 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70470
70471 - mod->core_symtab = dst = mod->module_core + info->symoffs;
70472 - mod->core_strtab = s = mod->module_core + info->stroffs;
70473 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70474 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70475 src = mod->symtab;
70476 *s++ = 0;
70477 for (ndst = i = 0; i < mod->num_symtab; i++) {
70478 @@ -2368,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70479 }
70480 }
70481 mod->core_num_syms = ndst;
70482 +
70483 + pax_close_kernel();
70484 }
70485 #else
70486 static inline void layout_symtab(struct module *mod, struct load_info *info)
70487 @@ -2401,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
70488 return size == 0 ? NULL : vmalloc_exec(size);
70489 }
70490
70491 -static void *module_alloc_update_bounds(unsigned long size)
70492 +static void *module_alloc_update_bounds_rw(unsigned long size)
70493 {
70494 void *ret = module_alloc(size);
70495
70496 if (ret) {
70497 mutex_lock(&module_mutex);
70498 /* Update module bounds. */
70499 - if ((unsigned long)ret < module_addr_min)
70500 - module_addr_min = (unsigned long)ret;
70501 - if ((unsigned long)ret + size > module_addr_max)
70502 - module_addr_max = (unsigned long)ret + size;
70503 + if ((unsigned long)ret < module_addr_min_rw)
70504 + module_addr_min_rw = (unsigned long)ret;
70505 + if ((unsigned long)ret + size > module_addr_max_rw)
70506 + module_addr_max_rw = (unsigned long)ret + size;
70507 + mutex_unlock(&module_mutex);
70508 + }
70509 + return ret;
70510 +}
70511 +
70512 +static void *module_alloc_update_bounds_rx(unsigned long size)
70513 +{
70514 + void *ret = module_alloc_exec(size);
70515 +
70516 + if (ret) {
70517 + mutex_lock(&module_mutex);
70518 + /* Update module bounds. */
70519 + if ((unsigned long)ret < module_addr_min_rx)
70520 + module_addr_min_rx = (unsigned long)ret;
70521 + if ((unsigned long)ret + size > module_addr_max_rx)
70522 + module_addr_max_rx = (unsigned long)ret + size;
70523 mutex_unlock(&module_mutex);
70524 }
70525 return ret;
70526 @@ -2630,8 +2668,14 @@ static struct module *setup_load_info(struct load_info *info)
70527 static int check_modinfo(struct module *mod, struct load_info *info)
70528 {
70529 const char *modmagic = get_modinfo(info, "vermagic");
70530 + const char *license = get_modinfo(info, "license");
70531 int err;
70532
70533 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70534 + if (!license || !license_is_gpl_compatible(license))
70535 + return -ENOEXEC;
70536 +#endif
70537 +
70538 /* This is allowed: modprobe --force will invalidate it. */
70539 if (!modmagic) {
70540 err = try_to_force_load(mod, "bad vermagic");
70541 @@ -2654,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70542 }
70543
70544 /* Set up license info based on the info section */
70545 - set_license(mod, get_modinfo(info, "license"));
70546 + set_license(mod, license);
70547
70548 return 0;
70549 }
70550 @@ -2748,7 +2792,7 @@ static int move_module(struct module *mod, struct load_info *info)
70551 void *ptr;
70552
70553 /* Do the allocs. */
70554 - ptr = module_alloc_update_bounds(mod->core_size);
70555 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70556 /*
70557 * The pointer to this block is stored in the module structure
70558 * which is inside the block. Just mark it as not being a
70559 @@ -2758,10 +2802,10 @@ static int move_module(struct module *mod, struct load_info *info)
70560 if (!ptr)
70561 return -ENOMEM;
70562
70563 - memset(ptr, 0, mod->core_size);
70564 - mod->module_core = ptr;
70565 + memset(ptr, 0, mod->core_size_rw);
70566 + mod->module_core_rw = ptr;
70567
70568 - ptr = module_alloc_update_bounds(mod->init_size);
70569 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70570 /*
70571 * The pointer to this block is stored in the module structure
70572 * which is inside the block. This block doesn't need to be
70573 @@ -2769,12 +2813,39 @@ static int move_module(struct module *mod, struct load_info *info)
70574 * after the module is initialized.
70575 */
70576 kmemleak_ignore(ptr);
70577 - if (!ptr && mod->init_size) {
70578 - module_free(mod, mod->module_core);
70579 + if (!ptr && mod->init_size_rw) {
70580 + module_free(mod, mod->module_core_rw);
70581 return -ENOMEM;
70582 }
70583 - memset(ptr, 0, mod->init_size);
70584 - mod->module_init = ptr;
70585 + memset(ptr, 0, mod->init_size_rw);
70586 + mod->module_init_rw = ptr;
70587 +
70588 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70589 + kmemleak_not_leak(ptr);
70590 + if (!ptr) {
70591 + module_free(mod, mod->module_init_rw);
70592 + module_free(mod, mod->module_core_rw);
70593 + return -ENOMEM;
70594 + }
70595 +
70596 + pax_open_kernel();
70597 + memset(ptr, 0, mod->core_size_rx);
70598 + pax_close_kernel();
70599 + mod->module_core_rx = ptr;
70600 +
70601 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70602 + kmemleak_ignore(ptr);
70603 + if (!ptr && mod->init_size_rx) {
70604 + module_free_exec(mod, mod->module_core_rx);
70605 + module_free(mod, mod->module_init_rw);
70606 + module_free(mod, mod->module_core_rw);
70607 + return -ENOMEM;
70608 + }
70609 +
70610 + pax_open_kernel();
70611 + memset(ptr, 0, mod->init_size_rx);
70612 + pax_close_kernel();
70613 + mod->module_init_rx = ptr;
70614
70615 /* Transfer each section which specifies SHF_ALLOC */
70616 pr_debug("final section addresses:\n");
70617 @@ -2785,16 +2856,45 @@ static int move_module(struct module *mod, struct load_info *info)
70618 if (!(shdr->sh_flags & SHF_ALLOC))
70619 continue;
70620
70621 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
70622 - dest = mod->module_init
70623 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70624 - else
70625 - dest = mod->module_core + shdr->sh_entsize;
70626 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70627 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70628 + dest = mod->module_init_rw
70629 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70630 + else
70631 + dest = mod->module_init_rx
70632 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70633 + } else {
70634 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70635 + dest = mod->module_core_rw + shdr->sh_entsize;
70636 + else
70637 + dest = mod->module_core_rx + shdr->sh_entsize;
70638 + }
70639 +
70640 + if (shdr->sh_type != SHT_NOBITS) {
70641 +
70642 +#ifdef CONFIG_PAX_KERNEXEC
70643 +#ifdef CONFIG_X86_64
70644 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70645 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70646 +#endif
70647 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70648 + pax_open_kernel();
70649 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70650 + pax_close_kernel();
70651 + } else
70652 +#endif
70653
70654 - if (shdr->sh_type != SHT_NOBITS)
70655 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70656 + }
70657 /* Update sh_addr to point to copy in image. */
70658 - shdr->sh_addr = (unsigned long)dest;
70659 +
70660 +#ifdef CONFIG_PAX_KERNEXEC
70661 + if (shdr->sh_flags & SHF_EXECINSTR)
70662 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
70663 + else
70664 +#endif
70665 +
70666 + shdr->sh_addr = (unsigned long)dest;
70667 pr_debug("\t0x%lx %s\n",
70668 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70669 }
70670 @@ -2849,12 +2949,12 @@ static void flush_module_icache(const struct module *mod)
70671 * Do it before processing of module parameters, so the module
70672 * can provide parameter accessor functions of its own.
70673 */
70674 - if (mod->module_init)
70675 - flush_icache_range((unsigned long)mod->module_init,
70676 - (unsigned long)mod->module_init
70677 - + mod->init_size);
70678 - flush_icache_range((unsigned long)mod->module_core,
70679 - (unsigned long)mod->module_core + mod->core_size);
70680 + if (mod->module_init_rx)
70681 + flush_icache_range((unsigned long)mod->module_init_rx,
70682 + (unsigned long)mod->module_init_rx
70683 + + mod->init_size_rx);
70684 + flush_icache_range((unsigned long)mod->module_core_rx,
70685 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
70686
70687 set_fs(old_fs);
70688 }
70689 @@ -2924,8 +3024,10 @@ out:
70690 static void module_deallocate(struct module *mod, struct load_info *info)
70691 {
70692 percpu_modfree(mod);
70693 - module_free(mod, mod->module_init);
70694 - module_free(mod, mod->module_core);
70695 + module_free_exec(mod, mod->module_init_rx);
70696 + module_free_exec(mod, mod->module_core_rx);
70697 + module_free(mod, mod->module_init_rw);
70698 + module_free(mod, mod->module_core_rw);
70699 }
70700
70701 int __weak module_finalize(const Elf_Ehdr *hdr,
70702 @@ -2938,7 +3040,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70703 static int post_relocation(struct module *mod, const struct load_info *info)
70704 {
70705 /* Sort exception table now relocations are done. */
70706 + pax_open_kernel();
70707 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70708 + pax_close_kernel();
70709
70710 /* Copy relocated percpu area over. */
70711 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70712 @@ -3036,9 +3140,38 @@ again:
70713 if (err)
70714 goto free_unload;
70715
70716 + /* Now copy in args */
70717 + mod->args = strndup_user(uargs, ~0UL >> 1);
70718 + if (IS_ERR(mod->args)) {
70719 + err = PTR_ERR(mod->args);
70720 + goto free_unload;
70721 + }
70722 +
70723 /* Set up MODINFO_ATTR fields */
70724 setup_modinfo(mod, &info);
70725
70726 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70727 + {
70728 + char *p, *p2;
70729 +
70730 + if (strstr(mod->args, "grsec_modharden_netdev")) {
70731 + 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);
70732 + err = -EPERM;
70733 + goto free_modinfo;
70734 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70735 + p += sizeof("grsec_modharden_normal") - 1;
70736 + p2 = strstr(p, "_");
70737 + if (p2) {
70738 + *p2 = '\0';
70739 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70740 + *p2 = '_';
70741 + }
70742 + err = -EPERM;
70743 + goto free_modinfo;
70744 + }
70745 + }
70746 +#endif
70747 +
70748 /* Fix up syms, so that st_value is a pointer to location. */
70749 err = simplify_symbols(mod, &info);
70750 if (err < 0)
70751 @@ -3104,11 +3237,11 @@ again:
70752 mutex_unlock(&module_mutex);
70753 dynamic_debug_remove(info.debug);
70754 synchronize_sched();
70755 - kfree(mod->args);
70756 free_arch_cleanup:
70757 module_arch_cleanup(mod);
70758 free_modinfo:
70759 free_modinfo(mod);
70760 + kfree(mod->args);
70761 free_unload:
70762 module_unload_free(mod);
70763 unlink_mod:
70764 @@ -3155,16 +3288,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70765 MODULE_STATE_COMING, mod);
70766
70767 /* Set RO and NX regions for core */
70768 - set_section_ro_nx(mod->module_core,
70769 - mod->core_text_size,
70770 - mod->core_ro_size,
70771 - mod->core_size);
70772 + set_section_ro_nx(mod->module_core_rx,
70773 + mod->core_size_rx,
70774 + mod->core_size_rx,
70775 + mod->core_size_rx);
70776
70777 /* Set RO and NX regions for init */
70778 - set_section_ro_nx(mod->module_init,
70779 - mod->init_text_size,
70780 - mod->init_ro_size,
70781 - mod->init_size);
70782 + set_section_ro_nx(mod->module_init_rx,
70783 + mod->init_size_rx,
70784 + mod->init_size_rx,
70785 + mod->init_size_rx);
70786
70787 do_mod_ctors(mod);
70788 /* Start the module */
70789 @@ -3209,11 +3342,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70790 mod->strtab = mod->core_strtab;
70791 #endif
70792 unset_module_init_ro_nx(mod);
70793 - module_free(mod, mod->module_init);
70794 - mod->module_init = NULL;
70795 - mod->init_size = 0;
70796 - mod->init_ro_size = 0;
70797 - mod->init_text_size = 0;
70798 + module_free(mod, mod->module_init_rw);
70799 + module_free_exec(mod, mod->module_init_rx);
70800 + mod->module_init_rw = NULL;
70801 + mod->module_init_rx = NULL;
70802 + mod->init_size_rw = 0;
70803 + mod->init_size_rx = 0;
70804 mutex_unlock(&module_mutex);
70805 wake_up_all(&module_wq);
70806
70807 @@ -3245,10 +3379,16 @@ static const char *get_ksymbol(struct module *mod,
70808 unsigned long nextval;
70809
70810 /* At worse, next value is at end of module */
70811 - if (within_module_init(addr, mod))
70812 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
70813 + if (within_module_init_rx(addr, mod))
70814 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70815 + else if (within_module_init_rw(addr, mod))
70816 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70817 + else if (within_module_core_rx(addr, mod))
70818 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70819 + else if (within_module_core_rw(addr, mod))
70820 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70821 else
70822 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
70823 + return NULL;
70824
70825 /* Scan for closest preceding symbol, and next symbol. (ELF
70826 starts real symbols at 1). */
70827 @@ -3501,7 +3641,7 @@ static int m_show(struct seq_file *m, void *p)
70828 return 0;
70829
70830 seq_printf(m, "%s %u",
70831 - mod->name, mod->init_size + mod->core_size);
70832 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70833 print_unload_info(m, mod);
70834
70835 /* Informative for users. */
70836 @@ -3510,7 +3650,7 @@ static int m_show(struct seq_file *m, void *p)
70837 mod->state == MODULE_STATE_COMING ? "Loading":
70838 "Live");
70839 /* Used by oprofile and other similar tools. */
70840 - seq_printf(m, " 0x%pK", mod->module_core);
70841 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70842
70843 /* Taints info */
70844 if (mod->taints)
70845 @@ -3546,7 +3686,17 @@ static const struct file_operations proc_modules_operations = {
70846
70847 static int __init proc_modules_init(void)
70848 {
70849 +#ifndef CONFIG_GRKERNSEC_HIDESYM
70850 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70851 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70852 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70853 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70854 +#else
70855 proc_create("modules", 0, NULL, &proc_modules_operations);
70856 +#endif
70857 +#else
70858 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70859 +#endif
70860 return 0;
70861 }
70862 module_init(proc_modules_init);
70863 @@ -3607,14 +3757,14 @@ struct module *__module_address(unsigned long addr)
70864 {
70865 struct module *mod;
70866
70867 - if (addr < module_addr_min || addr > module_addr_max)
70868 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70869 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
70870 return NULL;
70871
70872 list_for_each_entry_rcu(mod, &modules, list) {
70873 if (mod->state == MODULE_STATE_UNFORMED)
70874 continue;
70875 - if (within_module_core(addr, mod)
70876 - || within_module_init(addr, mod))
70877 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
70878 return mod;
70879 }
70880 return NULL;
70881 @@ -3649,11 +3799,20 @@ bool is_module_text_address(unsigned long addr)
70882 */
70883 struct module *__module_text_address(unsigned long addr)
70884 {
70885 - struct module *mod = __module_address(addr);
70886 + struct module *mod;
70887 +
70888 +#ifdef CONFIG_X86_32
70889 + addr = ktla_ktva(addr);
70890 +#endif
70891 +
70892 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70893 + return NULL;
70894 +
70895 + mod = __module_address(addr);
70896 +
70897 if (mod) {
70898 /* Make sure it's within the text section. */
70899 - if (!within(addr, mod->module_init, mod->init_text_size)
70900 - && !within(addr, mod->module_core, mod->core_text_size))
70901 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70902 mod = NULL;
70903 }
70904 return mod;
70905 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70906 index 7e3443f..b2a1e6b 100644
70907 --- a/kernel/mutex-debug.c
70908 +++ b/kernel/mutex-debug.c
70909 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70910 }
70911
70912 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70913 - struct thread_info *ti)
70914 + struct task_struct *task)
70915 {
70916 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70917
70918 /* Mark the current thread as blocked on the lock: */
70919 - ti->task->blocked_on = waiter;
70920 + task->blocked_on = waiter;
70921 }
70922
70923 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70924 - struct thread_info *ti)
70925 + struct task_struct *task)
70926 {
70927 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
70928 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
70929 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
70930 - ti->task->blocked_on = NULL;
70931 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
70932 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
70933 + task->blocked_on = NULL;
70934
70935 list_del_init(&waiter->list);
70936 waiter->task = NULL;
70937 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
70938 index 0799fd3..d06ae3b 100644
70939 --- a/kernel/mutex-debug.h
70940 +++ b/kernel/mutex-debug.h
70941 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
70942 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
70943 extern void debug_mutex_add_waiter(struct mutex *lock,
70944 struct mutex_waiter *waiter,
70945 - struct thread_info *ti);
70946 + struct task_struct *task);
70947 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70948 - struct thread_info *ti);
70949 + struct task_struct *task);
70950 extern void debug_mutex_unlock(struct mutex *lock);
70951 extern void debug_mutex_init(struct mutex *lock, const char *name,
70952 struct lock_class_key *key);
70953 diff --git a/kernel/mutex.c b/kernel/mutex.c
70954 index a307cc9..27fd2e9 100644
70955 --- a/kernel/mutex.c
70956 +++ b/kernel/mutex.c
70957 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70958 spin_lock_mutex(&lock->wait_lock, flags);
70959
70960 debug_mutex_lock_common(lock, &waiter);
70961 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
70962 + debug_mutex_add_waiter(lock, &waiter, task);
70963
70964 /* add waiting tasks to the end of the waitqueue (FIFO): */
70965 list_add_tail(&waiter.list, &lock->wait_list);
70966 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70967 * TASK_UNINTERRUPTIBLE case.)
70968 */
70969 if (unlikely(signal_pending_state(state, task))) {
70970 - mutex_remove_waiter(lock, &waiter,
70971 - task_thread_info(task));
70972 + mutex_remove_waiter(lock, &waiter, task);
70973 mutex_release(&lock->dep_map, 1, ip);
70974 spin_unlock_mutex(&lock->wait_lock, flags);
70975
70976 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70977 done:
70978 lock_acquired(&lock->dep_map, ip);
70979 /* got the lock - rejoice! */
70980 - mutex_remove_waiter(lock, &waiter, current_thread_info());
70981 + mutex_remove_waiter(lock, &waiter, task);
70982 mutex_set_owner(lock);
70983
70984 /* set it to 0 if there are no waiters left: */
70985 diff --git a/kernel/notifier.c b/kernel/notifier.c
70986 index 2d5cc4c..d9ea600 100644
70987 --- a/kernel/notifier.c
70988 +++ b/kernel/notifier.c
70989 @@ -5,6 +5,7 @@
70990 #include <linux/rcupdate.h>
70991 #include <linux/vmalloc.h>
70992 #include <linux/reboot.h>
70993 +#include <linux/mm.h>
70994
70995 /*
70996 * Notifier list for kernel code which wants to be called
70997 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
70998 while ((*nl) != NULL) {
70999 if (n->priority > (*nl)->priority)
71000 break;
71001 - nl = &((*nl)->next);
71002 + nl = (struct notifier_block **)&((*nl)->next);
71003 }
71004 - n->next = *nl;
71005 + pax_open_kernel();
71006 + *(const void **)&n->next = *nl;
71007 rcu_assign_pointer(*nl, n);
71008 + pax_close_kernel();
71009 return 0;
71010 }
71011
71012 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71013 return 0;
71014 if (n->priority > (*nl)->priority)
71015 break;
71016 - nl = &((*nl)->next);
71017 + nl = (struct notifier_block **)&((*nl)->next);
71018 }
71019 - n->next = *nl;
71020 + pax_open_kernel();
71021 + *(const void **)&n->next = *nl;
71022 rcu_assign_pointer(*nl, n);
71023 + pax_close_kernel();
71024 return 0;
71025 }
71026
71027 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71028 {
71029 while ((*nl) != NULL) {
71030 if ((*nl) == n) {
71031 + pax_open_kernel();
71032 rcu_assign_pointer(*nl, n->next);
71033 + pax_close_kernel();
71034 return 0;
71035 }
71036 - nl = &((*nl)->next);
71037 + nl = (struct notifier_block **)&((*nl)->next);
71038 }
71039 return -ENOENT;
71040 }
71041 diff --git a/kernel/panic.c b/kernel/panic.c
71042 index e1b2822..5edc1d9 100644
71043 --- a/kernel/panic.c
71044 +++ b/kernel/panic.c
71045 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71046 const char *board;
71047
71048 printk(KERN_WARNING "------------[ cut here ]------------\n");
71049 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71050 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71051 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71052 if (board)
71053 printk(KERN_WARNING "Hardware name: %s\n", board);
71054 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71055 */
71056 void __stack_chk_fail(void)
71057 {
71058 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
71059 + dump_stack();
71060 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71061 __builtin_return_address(0));
71062 }
71063 EXPORT_SYMBOL(__stack_chk_fail);
71064 diff --git a/kernel/pid.c b/kernel/pid.c
71065 index aebd4f5..1693c13 100644
71066 --- a/kernel/pid.c
71067 +++ b/kernel/pid.c
71068 @@ -33,6 +33,7 @@
71069 #include <linux/rculist.h>
71070 #include <linux/bootmem.h>
71071 #include <linux/hash.h>
71072 +#include <linux/security.h>
71073 #include <linux/pid_namespace.h>
71074 #include <linux/init_task.h>
71075 #include <linux/syscalls.h>
71076 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71077
71078 int pid_max = PID_MAX_DEFAULT;
71079
71080 -#define RESERVED_PIDS 300
71081 +#define RESERVED_PIDS 500
71082
71083 int pid_max_min = RESERVED_PIDS + 1;
71084 int pid_max_max = PID_MAX_LIMIT;
71085 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
71086 */
71087 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71088 {
71089 + struct task_struct *task;
71090 +
71091 rcu_lockdep_assert(rcu_read_lock_held(),
71092 "find_task_by_pid_ns() needs rcu_read_lock()"
71093 " protection");
71094 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71095 +
71096 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71097 +
71098 + if (gr_pid_is_chrooted(task))
71099 + return NULL;
71100 +
71101 + return task;
71102 }
71103
71104 struct task_struct *find_task_by_vpid(pid_t vnr)
71105 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71106 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
71107 }
71108
71109 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71110 +{
71111 + rcu_lockdep_assert(rcu_read_lock_held(),
71112 + "find_task_by_pid_ns() needs rcu_read_lock()"
71113 + " protection");
71114 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
71115 +}
71116 +
71117 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71118 {
71119 struct pid *pid;
71120 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71121 index 125cb67..2e5c8ad 100644
71122 --- a/kernel/posix-cpu-timers.c
71123 +++ b/kernel/posix-cpu-timers.c
71124 @@ -6,9 +6,11 @@
71125 #include <linux/posix-timers.h>
71126 #include <linux/errno.h>
71127 #include <linux/math64.h>
71128 +#include <linux/security.h>
71129 #include <asm/uaccess.h>
71130 #include <linux/kernel_stat.h>
71131 #include <trace/events/timer.h>
71132 +#include <linux/random.h>
71133
71134 /*
71135 * Called after updating RLIMIT_CPU to run cpu timer and update
71136 @@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
71137 */
71138 void posix_cpu_timers_exit(struct task_struct *tsk)
71139 {
71140 + add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
71141 + sizeof(unsigned long long));
71142 cleanup_timers(tsk->cpu_timers,
71143 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
71144
71145 @@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
71146
71147 static __init int init_posix_cpu_timers(void)
71148 {
71149 - struct k_clock process = {
71150 + static struct k_clock process = {
71151 .clock_getres = process_cpu_clock_getres,
71152 .clock_get = process_cpu_clock_get,
71153 .timer_create = process_cpu_timer_create,
71154 .nsleep = process_cpu_nsleep,
71155 .nsleep_restart = process_cpu_nsleep_restart,
71156 };
71157 - struct k_clock thread = {
71158 + static struct k_clock thread = {
71159 .clock_getres = thread_cpu_clock_getres,
71160 .clock_get = thread_cpu_clock_get,
71161 .timer_create = thread_cpu_timer_create,
71162 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71163 index 69185ae..cc2847a 100644
71164 --- a/kernel/posix-timers.c
71165 +++ b/kernel/posix-timers.c
71166 @@ -43,6 +43,7 @@
71167 #include <linux/idr.h>
71168 #include <linux/posix-clock.h>
71169 #include <linux/posix-timers.h>
71170 +#include <linux/grsecurity.h>
71171 #include <linux/syscalls.h>
71172 #include <linux/wait.h>
71173 #include <linux/workqueue.h>
71174 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71175 * which we beg off on and pass to do_sys_settimeofday().
71176 */
71177
71178 -static struct k_clock posix_clocks[MAX_CLOCKS];
71179 +static struct k_clock *posix_clocks[MAX_CLOCKS];
71180
71181 /*
71182 * These ones are defined below.
71183 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
71184 */
71185 static __init int init_posix_timers(void)
71186 {
71187 - struct k_clock clock_realtime = {
71188 + static struct k_clock clock_realtime = {
71189 .clock_getres = hrtimer_get_res,
71190 .clock_get = posix_clock_realtime_get,
71191 .clock_set = posix_clock_realtime_set,
71192 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
71193 .timer_get = common_timer_get,
71194 .timer_del = common_timer_del,
71195 };
71196 - struct k_clock clock_monotonic = {
71197 + static struct k_clock clock_monotonic = {
71198 .clock_getres = hrtimer_get_res,
71199 .clock_get = posix_ktime_get_ts,
71200 .nsleep = common_nsleep,
71201 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
71202 .timer_get = common_timer_get,
71203 .timer_del = common_timer_del,
71204 };
71205 - struct k_clock clock_monotonic_raw = {
71206 + static struct k_clock clock_monotonic_raw = {
71207 .clock_getres = hrtimer_get_res,
71208 .clock_get = posix_get_monotonic_raw,
71209 };
71210 - struct k_clock clock_realtime_coarse = {
71211 + static struct k_clock clock_realtime_coarse = {
71212 .clock_getres = posix_get_coarse_res,
71213 .clock_get = posix_get_realtime_coarse,
71214 };
71215 - struct k_clock clock_monotonic_coarse = {
71216 + static struct k_clock clock_monotonic_coarse = {
71217 .clock_getres = posix_get_coarse_res,
71218 .clock_get = posix_get_monotonic_coarse,
71219 };
71220 - struct k_clock clock_boottime = {
71221 + static struct k_clock clock_boottime = {
71222 .clock_getres = hrtimer_get_res,
71223 .clock_get = posix_get_boottime,
71224 .nsleep = common_nsleep,
71225 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
71226 return;
71227 }
71228
71229 - posix_clocks[clock_id] = *new_clock;
71230 + posix_clocks[clock_id] = new_clock;
71231 }
71232 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
71233
71234 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
71235 return (id & CLOCKFD_MASK) == CLOCKFD ?
71236 &clock_posix_dynamic : &clock_posix_cpu;
71237
71238 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
71239 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
71240 return NULL;
71241 - return &posix_clocks[id];
71242 + return posix_clocks[id];
71243 }
71244
71245 static int common_timer_create(struct k_itimer *new_timer)
71246 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
71247 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
71248 return -EFAULT;
71249
71250 + /* only the CLOCK_REALTIME clock can be set, all other clocks
71251 + have their clock_set fptr set to a nosettime dummy function
71252 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
71253 + call common_clock_set, which calls do_sys_settimeofday, which
71254 + we hook
71255 + */
71256 +
71257 return kc->clock_set(which_clock, &new_tp);
71258 }
71259
71260 diff --git a/kernel/power/process.c b/kernel/power/process.c
71261 index 87da817..30ddd13 100644
71262 --- a/kernel/power/process.c
71263 +++ b/kernel/power/process.c
71264 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
71265 u64 elapsed_csecs64;
71266 unsigned int elapsed_csecs;
71267 bool wakeup = false;
71268 + bool timedout = false;
71269
71270 do_gettimeofday(&start);
71271
71272 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
71273
71274 while (true) {
71275 todo = 0;
71276 + if (time_after(jiffies, end_time))
71277 + timedout = true;
71278 read_lock(&tasklist_lock);
71279 do_each_thread(g, p) {
71280 if (p == current || !freeze_task(p))
71281 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
71282 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
71283 * transition can't race with task state testing here.
71284 */
71285 - if (!task_is_stopped_or_traced(p) &&
71286 - !freezer_should_skip(p))
71287 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
71288 todo++;
71289 + if (timedout) {
71290 + printk(KERN_ERR "Task refusing to freeze:\n");
71291 + sched_show_task(p);
71292 + }
71293 + }
71294 } while_each_thread(g, p);
71295 read_unlock(&tasklist_lock);
71296
71297 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
71298 todo += wq_busy;
71299 }
71300
71301 - if (!todo || time_after(jiffies, end_time))
71302 + if (!todo || timedout)
71303 break;
71304
71305 if (pm_wakeup_pending()) {
71306 diff --git a/kernel/printk.c b/kernel/printk.c
71307 index f8e0b5a..dda2a5c 100644
71308 --- a/kernel/printk.c
71309 +++ b/kernel/printk.c
71310 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
71311 if (from_file && type != SYSLOG_ACTION_OPEN)
71312 return 0;
71313
71314 +#ifdef CONFIG_GRKERNSEC_DMESG
71315 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
71316 + return -EPERM;
71317 +#endif
71318 +
71319 if (syslog_action_restricted(type)) {
71320 if (capable(CAP_SYSLOG))
71321 return 0;
71322 diff --git a/kernel/profile.c b/kernel/profile.c
71323 index 76b8e77..a2930e8 100644
71324 --- a/kernel/profile.c
71325 +++ b/kernel/profile.c
71326 @@ -39,7 +39,7 @@ struct profile_hit {
71327 /* Oprofile timer tick hook */
71328 static int (*timer_hook)(struct pt_regs *) __read_mostly;
71329
71330 -static atomic_t *prof_buffer;
71331 +static atomic_unchecked_t *prof_buffer;
71332 static unsigned long prof_len, prof_shift;
71333
71334 int prof_on __read_mostly;
71335 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
71336 hits[i].pc = 0;
71337 continue;
71338 }
71339 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71340 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71341 hits[i].hits = hits[i].pc = 0;
71342 }
71343 }
71344 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71345 * Add the current hit(s) and flush the write-queue out
71346 * to the global buffer:
71347 */
71348 - atomic_add(nr_hits, &prof_buffer[pc]);
71349 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71350 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71351 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71352 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71353 hits[i].pc = hits[i].hits = 0;
71354 }
71355 out:
71356 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71357 {
71358 unsigned long pc;
71359 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71360 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71361 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71362 }
71363 #endif /* !CONFIG_SMP */
71364
71365 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71366 return -EFAULT;
71367 buf++; p++; count--; read++;
71368 }
71369 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71370 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71371 if (copy_to_user(buf, (void *)pnt, count))
71372 return -EFAULT;
71373 read += count;
71374 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71375 }
71376 #endif
71377 profile_discard_flip_buffers();
71378 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71379 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71380 return count;
71381 }
71382
71383 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71384 index fbea91d..9bf15e8 100644
71385 --- a/kernel/ptrace.c
71386 +++ b/kernel/ptrace.c
71387 @@ -319,7 +319,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71388
71389 if (seize)
71390 flags |= PT_SEIZED;
71391 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71392 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71393 flags |= PT_PTRACE_CAP;
71394 task->ptrace = flags;
71395
71396 @@ -526,7 +526,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71397 break;
71398 return -EIO;
71399 }
71400 - if (copy_to_user(dst, buf, retval))
71401 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71402 return -EFAULT;
71403 copied += retval;
71404 src += retval;
71405 @@ -711,7 +711,7 @@ int ptrace_request(struct task_struct *child, long request,
71406 bool seized = child->ptrace & PT_SEIZED;
71407 int ret = -EIO;
71408 siginfo_t siginfo, *si;
71409 - void __user *datavp = (void __user *) data;
71410 + void __user *datavp = (__force void __user *) data;
71411 unsigned long __user *datalp = datavp;
71412 unsigned long flags;
71413
71414 @@ -913,14 +913,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71415 goto out;
71416 }
71417
71418 + if (gr_handle_ptrace(child, request)) {
71419 + ret = -EPERM;
71420 + goto out_put_task_struct;
71421 + }
71422 +
71423 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71424 ret = ptrace_attach(child, request, addr, data);
71425 /*
71426 * Some architectures need to do book-keeping after
71427 * a ptrace attach.
71428 */
71429 - if (!ret)
71430 + if (!ret) {
71431 arch_ptrace_attach(child);
71432 + gr_audit_ptrace(child);
71433 + }
71434 goto out_put_task_struct;
71435 }
71436
71437 @@ -948,7 +955,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71438 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71439 if (copied != sizeof(tmp))
71440 return -EIO;
71441 - return put_user(tmp, (unsigned long __user *)data);
71442 + return put_user(tmp, (__force unsigned long __user *)data);
71443 }
71444
71445 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71446 @@ -1058,14 +1065,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71447 goto out;
71448 }
71449
71450 + if (gr_handle_ptrace(child, request)) {
71451 + ret = -EPERM;
71452 + goto out_put_task_struct;
71453 + }
71454 +
71455 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71456 ret = ptrace_attach(child, request, addr, data);
71457 /*
71458 * Some architectures need to do book-keeping after
71459 * a ptrace attach.
71460 */
71461 - if (!ret)
71462 + if (!ret) {
71463 arch_ptrace_attach(child);
71464 + gr_audit_ptrace(child);
71465 + }
71466 goto out_put_task_struct;
71467 }
71468
71469 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71470 index e4c6a59..c86621a 100644
71471 --- a/kernel/rcutiny.c
71472 +++ b/kernel/rcutiny.c
71473 @@ -46,7 +46,7 @@
71474 struct rcu_ctrlblk;
71475 static void invoke_rcu_callbacks(void);
71476 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71477 -static void rcu_process_callbacks(struct softirq_action *unused);
71478 +static void rcu_process_callbacks(void);
71479 static void __call_rcu(struct rcu_head *head,
71480 void (*func)(struct rcu_head *rcu),
71481 struct rcu_ctrlblk *rcp);
71482 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71483 rcu_is_callbacks_kthread()));
71484 }
71485
71486 -static void rcu_process_callbacks(struct softirq_action *unused)
71487 +static void rcu_process_callbacks(void)
71488 {
71489 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71490 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71491 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71492 index 3d01902..afbf46e 100644
71493 --- a/kernel/rcutiny_plugin.h
71494 +++ b/kernel/rcutiny_plugin.h
71495 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71496 have_rcu_kthread_work = morework;
71497 local_irq_restore(flags);
71498 if (work)
71499 - rcu_process_callbacks(NULL);
71500 + rcu_process_callbacks();
71501 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71502 }
71503
71504 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71505 index aaa7b9f..055ff1e 100644
71506 --- a/kernel/rcutorture.c
71507 +++ b/kernel/rcutorture.c
71508 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71509 { 0 };
71510 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71511 { 0 };
71512 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71513 -static atomic_t n_rcu_torture_alloc;
71514 -static atomic_t n_rcu_torture_alloc_fail;
71515 -static atomic_t n_rcu_torture_free;
71516 -static atomic_t n_rcu_torture_mberror;
71517 -static atomic_t n_rcu_torture_error;
71518 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71519 +static atomic_unchecked_t n_rcu_torture_alloc;
71520 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
71521 +static atomic_unchecked_t n_rcu_torture_free;
71522 +static atomic_unchecked_t n_rcu_torture_mberror;
71523 +static atomic_unchecked_t n_rcu_torture_error;
71524 static long n_rcu_torture_barrier_error;
71525 static long n_rcu_torture_boost_ktrerror;
71526 static long n_rcu_torture_boost_rterror;
71527 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71528
71529 spin_lock_bh(&rcu_torture_lock);
71530 if (list_empty(&rcu_torture_freelist)) {
71531 - atomic_inc(&n_rcu_torture_alloc_fail);
71532 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71533 spin_unlock_bh(&rcu_torture_lock);
71534 return NULL;
71535 }
71536 - atomic_inc(&n_rcu_torture_alloc);
71537 + atomic_inc_unchecked(&n_rcu_torture_alloc);
71538 p = rcu_torture_freelist.next;
71539 list_del_init(p);
71540 spin_unlock_bh(&rcu_torture_lock);
71541 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71542 static void
71543 rcu_torture_free(struct rcu_torture *p)
71544 {
71545 - atomic_inc(&n_rcu_torture_free);
71546 + atomic_inc_unchecked(&n_rcu_torture_free);
71547 spin_lock_bh(&rcu_torture_lock);
71548 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71549 spin_unlock_bh(&rcu_torture_lock);
71550 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
71551 i = rp->rtort_pipe_count;
71552 if (i > RCU_TORTURE_PIPE_LEN)
71553 i = RCU_TORTURE_PIPE_LEN;
71554 - atomic_inc(&rcu_torture_wcount[i]);
71555 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71556 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71557 rp->rtort_mbtest = 0;
71558 rcu_torture_free(rp);
71559 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71560 i = rp->rtort_pipe_count;
71561 if (i > RCU_TORTURE_PIPE_LEN)
71562 i = RCU_TORTURE_PIPE_LEN;
71563 - atomic_inc(&rcu_torture_wcount[i]);
71564 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71565 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71566 rp->rtort_mbtest = 0;
71567 list_del(&rp->rtort_free);
71568 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71569 i = old_rp->rtort_pipe_count;
71570 if (i > RCU_TORTURE_PIPE_LEN)
71571 i = RCU_TORTURE_PIPE_LEN;
71572 - atomic_inc(&rcu_torture_wcount[i]);
71573 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71574 old_rp->rtort_pipe_count++;
71575 cur_ops->deferred_free(old_rp);
71576 }
71577 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
71578 }
71579 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71580 if (p->rtort_mbtest == 0)
71581 - atomic_inc(&n_rcu_torture_mberror);
71582 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71583 spin_lock(&rand_lock);
71584 cur_ops->read_delay(&rand);
71585 n_rcu_torture_timers++;
71586 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71587 }
71588 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71589 if (p->rtort_mbtest == 0)
71590 - atomic_inc(&n_rcu_torture_mberror);
71591 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71592 cur_ops->read_delay(&rand);
71593 preempt_disable();
71594 pipe_count = p->rtort_pipe_count;
71595 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71596 rcu_torture_current,
71597 rcu_torture_current_version,
71598 list_empty(&rcu_torture_freelist),
71599 - atomic_read(&n_rcu_torture_alloc),
71600 - atomic_read(&n_rcu_torture_alloc_fail),
71601 - atomic_read(&n_rcu_torture_free));
71602 + atomic_read_unchecked(&n_rcu_torture_alloc),
71603 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71604 + atomic_read_unchecked(&n_rcu_torture_free));
71605 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71606 - atomic_read(&n_rcu_torture_mberror),
71607 + atomic_read_unchecked(&n_rcu_torture_mberror),
71608 n_rcu_torture_boost_ktrerror,
71609 n_rcu_torture_boost_rterror);
71610 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71611 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71612 n_barrier_attempts,
71613 n_rcu_torture_barrier_error);
71614 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71615 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71616 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71617 n_rcu_torture_barrier_error != 0 ||
71618 n_rcu_torture_boost_ktrerror != 0 ||
71619 n_rcu_torture_boost_rterror != 0 ||
71620 n_rcu_torture_boost_failure != 0 ||
71621 i > 1) {
71622 cnt += sprintf(&page[cnt], "!!! ");
71623 - atomic_inc(&n_rcu_torture_error);
71624 + atomic_inc_unchecked(&n_rcu_torture_error);
71625 WARN_ON_ONCE(1);
71626 }
71627 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71628 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71629 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71630 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71631 cnt += sprintf(&page[cnt], " %d",
71632 - atomic_read(&rcu_torture_wcount[i]));
71633 + atomic_read_unchecked(&rcu_torture_wcount[i]));
71634 }
71635 cnt += sprintf(&page[cnt], "\n");
71636 if (cur_ops->stats)
71637 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71638
71639 if (cur_ops->cleanup)
71640 cur_ops->cleanup();
71641 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71642 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71643 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71644 else if (n_online_successes != n_online_attempts ||
71645 n_offline_successes != n_offline_attempts)
71646 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71647
71648 rcu_torture_current = NULL;
71649 rcu_torture_current_version = 0;
71650 - atomic_set(&n_rcu_torture_alloc, 0);
71651 - atomic_set(&n_rcu_torture_alloc_fail, 0);
71652 - atomic_set(&n_rcu_torture_free, 0);
71653 - atomic_set(&n_rcu_torture_mberror, 0);
71654 - atomic_set(&n_rcu_torture_error, 0);
71655 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71656 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71657 + atomic_set_unchecked(&n_rcu_torture_free, 0);
71658 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71659 + atomic_set_unchecked(&n_rcu_torture_error, 0);
71660 n_rcu_torture_barrier_error = 0;
71661 n_rcu_torture_boost_ktrerror = 0;
71662 n_rcu_torture_boost_rterror = 0;
71663 n_rcu_torture_boost_failure = 0;
71664 n_rcu_torture_boosts = 0;
71665 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71666 - atomic_set(&rcu_torture_wcount[i], 0);
71667 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71668 for_each_possible_cpu(cpu) {
71669 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71670 per_cpu(rcu_torture_count, cpu)[i] = 0;
71671 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71672 index 2682295..0f2297e 100644
71673 --- a/kernel/rcutree.c
71674 +++ b/kernel/rcutree.c
71675 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71676 rcu_prepare_for_idle(smp_processor_id());
71677 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71678 smp_mb__before_atomic_inc(); /* See above. */
71679 - atomic_inc(&rdtp->dynticks);
71680 + atomic_inc_unchecked(&rdtp->dynticks);
71681 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71682 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71683 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71684
71685 /*
71686 * It is illegal to enter an extended quiescent state while
71687 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71688 int user)
71689 {
71690 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71691 - atomic_inc(&rdtp->dynticks);
71692 + atomic_inc_unchecked(&rdtp->dynticks);
71693 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71694 smp_mb__after_atomic_inc(); /* See above. */
71695 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71696 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71697 rcu_cleanup_after_idle(smp_processor_id());
71698 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71699 if (!user && !is_idle_task(current)) {
71700 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71701 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71702
71703 if (rdtp->dynticks_nmi_nesting == 0 &&
71704 - (atomic_read(&rdtp->dynticks) & 0x1))
71705 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71706 return;
71707 rdtp->dynticks_nmi_nesting++;
71708 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71709 - atomic_inc(&rdtp->dynticks);
71710 + atomic_inc_unchecked(&rdtp->dynticks);
71711 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71712 smp_mb__after_atomic_inc(); /* See above. */
71713 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71714 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71715 }
71716
71717 /**
71718 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71719 return;
71720 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71721 smp_mb__before_atomic_inc(); /* See above. */
71722 - atomic_inc(&rdtp->dynticks);
71723 + atomic_inc_unchecked(&rdtp->dynticks);
71724 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71725 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71726 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71727 }
71728
71729 /**
71730 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71731 int ret;
71732
71733 preempt_disable();
71734 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71735 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71736 preempt_enable();
71737 return ret;
71738 }
71739 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71740 */
71741 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71742 {
71743 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71744 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71745 return (rdp->dynticks_snap & 0x1) == 0;
71746 }
71747
71748 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71749 unsigned int curr;
71750 unsigned int snap;
71751
71752 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71753 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71754 snap = (unsigned int)rdp->dynticks_snap;
71755
71756 /*
71757 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71758 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71759 */
71760 if (till_stall_check < 3) {
71761 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71762 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71763 till_stall_check = 3;
71764 } else if (till_stall_check > 300) {
71765 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71766 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71767 till_stall_check = 300;
71768 }
71769 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71770 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71771 rsp->qlen += rdp->qlen;
71772 rdp->n_cbs_orphaned += rdp->qlen;
71773 rdp->qlen_lazy = 0;
71774 - ACCESS_ONCE(rdp->qlen) = 0;
71775 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71776 }
71777
71778 /*
71779 @@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71780 }
71781 smp_mb(); /* List handling before counting for rcu_barrier(). */
71782 rdp->qlen_lazy -= count_lazy;
71783 - ACCESS_ONCE(rdp->qlen) -= count;
71784 + ACCESS_ONCE_RW(rdp->qlen) -= count;
71785 rdp->n_cbs_invoked += count;
71786
71787 /* Reinstate batch limit if we have worked down the excess. */
71788 @@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71789 /*
71790 * Do RCU core processing for the current CPU.
71791 */
71792 -static void rcu_process_callbacks(struct softirq_action *unused)
71793 +static void rcu_process_callbacks(void)
71794 {
71795 struct rcu_state *rsp;
71796
71797 @@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71798 local_irq_restore(flags);
71799 return;
71800 }
71801 - ACCESS_ONCE(rdp->qlen)++;
71802 + ACCESS_ONCE_RW(rdp->qlen)++;
71803 if (lazy)
71804 rdp->qlen_lazy++;
71805 else
71806 @@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71807 }
71808 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71809
71810 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71811 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71812 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71813 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71814
71815 static int synchronize_sched_expedited_cpu_stop(void *data)
71816 {
71817 @@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71818 int firstsnap, s, snap, trycount = 0;
71819
71820 /* Note that atomic_inc_return() implies full memory barrier. */
71821 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71822 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71823 get_online_cpus();
71824 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71825
71826 @@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71827 }
71828
71829 /* Check to see if someone else did our work for us. */
71830 - s = atomic_read(&sync_sched_expedited_done);
71831 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71832 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71833 smp_mb(); /* ensure test happens before caller kfree */
71834 return;
71835 @@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71836 * grace period works for us.
71837 */
71838 get_online_cpus();
71839 - snap = atomic_read(&sync_sched_expedited_started);
71840 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
71841 smp_mb(); /* ensure read is before try_stop_cpus(). */
71842 }
71843
71844 @@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71845 * than we did beat us to the punch.
71846 */
71847 do {
71848 - s = atomic_read(&sync_sched_expedited_done);
71849 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71850 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71851 smp_mb(); /* ensure test happens before caller kfree */
71852 break;
71853 }
71854 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71855 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71856
71857 put_online_cpus();
71858 }
71859 @@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71860 * ACCESS_ONCE() to prevent the compiler from speculating
71861 * the increment to precede the early-exit check.
71862 */
71863 - ACCESS_ONCE(rsp->n_barrier_done)++;
71864 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71865 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71866 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71867 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71868 @@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71869
71870 /* Increment ->n_barrier_done to prevent duplicate work. */
71871 smp_mb(); /* Keep increment after above mechanism. */
71872 - ACCESS_ONCE(rsp->n_barrier_done)++;
71873 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71874 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71875 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71876 smp_mb(); /* Keep increment before caller's subsequent code. */
71877 @@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71878 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71879 init_callback_list(rdp);
71880 rdp->qlen_lazy = 0;
71881 - ACCESS_ONCE(rdp->qlen) = 0;
71882 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71883 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71884 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71885 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71886 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71887 #ifdef CONFIG_RCU_USER_QS
71888 WARN_ON_ONCE(rdp->dynticks->in_user);
71889 #endif
71890 @@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71891 rdp->blimit = blimit;
71892 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71893 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71894 - atomic_set(&rdp->dynticks->dynticks,
71895 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71896 + atomic_set_unchecked(&rdp->dynticks->dynticks,
71897 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71898 rcu_prepare_for_idle_init(cpu);
71899 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71900
71901 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71902 index a240f03..d469618 100644
71903 --- a/kernel/rcutree.h
71904 +++ b/kernel/rcutree.h
71905 @@ -86,7 +86,7 @@ struct rcu_dynticks {
71906 long long dynticks_nesting; /* Track irq/process nesting level. */
71907 /* Process level is worth LLONG_MAX/2. */
71908 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71909 - atomic_t dynticks; /* Even value for idle, else odd. */
71910 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71911 #ifdef CONFIG_RCU_FAST_NO_HZ
71912 int dyntick_drain; /* Prepare-for-idle state variable. */
71913 unsigned long dyntick_holdoff;
71914 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71915 index f921154..34c4873 100644
71916 --- a/kernel/rcutree_plugin.h
71917 +++ b/kernel/rcutree_plugin.h
71918 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71919
71920 /* Clean up and exit. */
71921 smp_mb(); /* ensure expedited GP seen before counter increment. */
71922 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
71923 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
71924 unlock_mb_ret:
71925 mutex_unlock(&sync_rcu_preempt_exp_mutex);
71926 mb_ret:
71927 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
71928 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
71929 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
71930 cpu, ticks_value, ticks_title,
71931 - atomic_read(&rdtp->dynticks) & 0xfff,
71932 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
71933 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
71934 fast_no_hz);
71935 }
71936 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
71937 index 693513b..b9f1d63 100644
71938 --- a/kernel/rcutree_trace.c
71939 +++ b/kernel/rcutree_trace.c
71940 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
71941 rdp->completed, rdp->gpnum,
71942 rdp->passed_quiesce, rdp->qs_pending);
71943 seq_printf(m, " dt=%d/%llx/%d df=%lu",
71944 - atomic_read(&rdp->dynticks->dynticks),
71945 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71946 rdp->dynticks->dynticks_nesting,
71947 rdp->dynticks->dynticks_nmi_nesting,
71948 rdp->dynticks_fqs);
71949 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
71950 rdp->completed, rdp->gpnum,
71951 rdp->passed_quiesce, rdp->qs_pending);
71952 seq_printf(m, ",%d,%llx,%d,%lu",
71953 - atomic_read(&rdp->dynticks->dynticks),
71954 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71955 rdp->dynticks->dynticks_nesting,
71956 rdp->dynticks->dynticks_nmi_nesting,
71957 rdp->dynticks_fqs);
71958 diff --git a/kernel/resource.c b/kernel/resource.c
71959 index 73f35d4..4684fc4 100644
71960 --- a/kernel/resource.c
71961 +++ b/kernel/resource.c
71962 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
71963
71964 static int __init ioresources_init(void)
71965 {
71966 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71967 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71968 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
71969 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
71970 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71971 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
71972 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
71973 +#endif
71974 +#else
71975 proc_create("ioports", 0, NULL, &proc_ioports_operations);
71976 proc_create("iomem", 0, NULL, &proc_iomem_operations);
71977 +#endif
71978 return 0;
71979 }
71980 __initcall(ioresources_init);
71981 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
71982 index 98ec494..4241d6d 100644
71983 --- a/kernel/rtmutex-tester.c
71984 +++ b/kernel/rtmutex-tester.c
71985 @@ -20,7 +20,7 @@
71986 #define MAX_RT_TEST_MUTEXES 8
71987
71988 static spinlock_t rttest_lock;
71989 -static atomic_t rttest_event;
71990 +static atomic_unchecked_t rttest_event;
71991
71992 struct test_thread_data {
71993 int opcode;
71994 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71995
71996 case RTTEST_LOCKCONT:
71997 td->mutexes[td->opdata] = 1;
71998 - td->event = atomic_add_return(1, &rttest_event);
71999 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72000 return 0;
72001
72002 case RTTEST_RESET:
72003 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72004 return 0;
72005
72006 case RTTEST_RESETEVENT:
72007 - atomic_set(&rttest_event, 0);
72008 + atomic_set_unchecked(&rttest_event, 0);
72009 return 0;
72010
72011 default:
72012 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72013 return ret;
72014
72015 td->mutexes[id] = 1;
72016 - td->event = atomic_add_return(1, &rttest_event);
72017 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72018 rt_mutex_lock(&mutexes[id]);
72019 - td->event = atomic_add_return(1, &rttest_event);
72020 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72021 td->mutexes[id] = 4;
72022 return 0;
72023
72024 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72025 return ret;
72026
72027 td->mutexes[id] = 1;
72028 - td->event = atomic_add_return(1, &rttest_event);
72029 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72030 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
72031 - td->event = atomic_add_return(1, &rttest_event);
72032 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72033 td->mutexes[id] = ret ? 0 : 4;
72034 return ret ? -EINTR : 0;
72035
72036 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72037 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
72038 return ret;
72039
72040 - td->event = atomic_add_return(1, &rttest_event);
72041 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72042 rt_mutex_unlock(&mutexes[id]);
72043 - td->event = atomic_add_return(1, &rttest_event);
72044 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72045 td->mutexes[id] = 0;
72046 return 0;
72047
72048 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72049 break;
72050
72051 td->mutexes[dat] = 2;
72052 - td->event = atomic_add_return(1, &rttest_event);
72053 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72054 break;
72055
72056 default:
72057 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72058 return;
72059
72060 td->mutexes[dat] = 3;
72061 - td->event = atomic_add_return(1, &rttest_event);
72062 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72063 break;
72064
72065 case RTTEST_LOCKNOWAIT:
72066 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72067 return;
72068
72069 td->mutexes[dat] = 1;
72070 - td->event = atomic_add_return(1, &rttest_event);
72071 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72072 return;
72073
72074 default:
72075 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
72076 index 15f60d0..7e50319 100644
72077 --- a/kernel/sched/auto_group.c
72078 +++ b/kernel/sched/auto_group.c
72079 @@ -11,7 +11,7 @@
72080
72081 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
72082 static struct autogroup autogroup_default;
72083 -static atomic_t autogroup_seq_nr;
72084 +static atomic_unchecked_t autogroup_seq_nr;
72085
72086 void __init autogroup_init(struct task_struct *init_task)
72087 {
72088 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
72089
72090 kref_init(&ag->kref);
72091 init_rwsem(&ag->lock);
72092 - ag->id = atomic_inc_return(&autogroup_seq_nr);
72093 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
72094 ag->tg = tg;
72095 #ifdef CONFIG_RT_GROUP_SCHED
72096 /*
72097 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
72098 index c529d00..d00b4f3 100644
72099 --- a/kernel/sched/core.c
72100 +++ b/kernel/sched/core.c
72101 @@ -3563,6 +3563,8 @@ int can_nice(const struct task_struct *p, const int nice)
72102 /* convert nice value [19,-20] to rlimit style value [1,40] */
72103 int nice_rlim = 20 - nice;
72104
72105 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
72106 +
72107 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
72108 capable(CAP_SYS_NICE));
72109 }
72110 @@ -3596,7 +3598,8 @@ SYSCALL_DEFINE1(nice, int, increment)
72111 if (nice > 19)
72112 nice = 19;
72113
72114 - if (increment < 0 && !can_nice(current, nice))
72115 + if (increment < 0 && (!can_nice(current, nice) ||
72116 + gr_handle_chroot_nice()))
72117 return -EPERM;
72118
72119 retval = security_task_setnice(current, nice);
72120 @@ -3750,6 +3753,7 @@ recheck:
72121 unsigned long rlim_rtprio =
72122 task_rlimit(p, RLIMIT_RTPRIO);
72123
72124 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
72125 /* can't set/change the rt policy */
72126 if (policy != p->policy && !rlim_rtprio)
72127 return -EPERM;
72128 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
72129 index 6b800a1..0c36227 100644
72130 --- a/kernel/sched/fair.c
72131 +++ b/kernel/sched/fair.c
72132 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
72133 * run_rebalance_domains is triggered when needed from the scheduler tick.
72134 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
72135 */
72136 -static void run_rebalance_domains(struct softirq_action *h)
72137 +static void run_rebalance_domains(void)
72138 {
72139 int this_cpu = smp_processor_id();
72140 struct rq *this_rq = cpu_rq(this_cpu);
72141 diff --git a/kernel/signal.c b/kernel/signal.c
72142 index 57dde52..2c561f0 100644
72143 --- a/kernel/signal.c
72144 +++ b/kernel/signal.c
72145 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
72146
72147 int print_fatal_signals __read_mostly;
72148
72149 -static void __user *sig_handler(struct task_struct *t, int sig)
72150 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
72151 {
72152 return t->sighand->action[sig - 1].sa.sa_handler;
72153 }
72154
72155 -static int sig_handler_ignored(void __user *handler, int sig)
72156 +static int sig_handler_ignored(__sighandler_t handler, int sig)
72157 {
72158 /* Is it explicitly or implicitly ignored? */
72159 return handler == SIG_IGN ||
72160 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
72161
72162 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
72163 {
72164 - void __user *handler;
72165 + __sighandler_t handler;
72166
72167 handler = sig_handler(t, sig);
72168
72169 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
72170 atomic_inc(&user->sigpending);
72171 rcu_read_unlock();
72172
72173 + if (!override_rlimit)
72174 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
72175 +
72176 if (override_rlimit ||
72177 atomic_read(&user->sigpending) <=
72178 task_rlimit(t, RLIMIT_SIGPENDING)) {
72179 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
72180
72181 int unhandled_signal(struct task_struct *tsk, int sig)
72182 {
72183 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
72184 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
72185 if (is_global_init(tsk))
72186 return 1;
72187 if (handler != SIG_IGN && handler != SIG_DFL)
72188 @@ -811,6 +814,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
72189 }
72190 }
72191
72192 + /* allow glibc communication via tgkill to other threads in our
72193 + thread group */
72194 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
72195 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
72196 + && gr_handle_signal(t, sig))
72197 + return -EPERM;
72198 +
72199 return security_task_kill(t, info, sig, 0);
72200 }
72201
72202 @@ -1192,7 +1202,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72203 return send_signal(sig, info, p, 1);
72204 }
72205
72206 -static int
72207 +int
72208 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72209 {
72210 return send_signal(sig, info, t, 0);
72211 @@ -1229,6 +1239,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72212 unsigned long int flags;
72213 int ret, blocked, ignored;
72214 struct k_sigaction *action;
72215 + int is_unhandled = 0;
72216
72217 spin_lock_irqsave(&t->sighand->siglock, flags);
72218 action = &t->sighand->action[sig-1];
72219 @@ -1243,9 +1254,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72220 }
72221 if (action->sa.sa_handler == SIG_DFL)
72222 t->signal->flags &= ~SIGNAL_UNKILLABLE;
72223 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
72224 + is_unhandled = 1;
72225 ret = specific_send_sig_info(sig, info, t);
72226 spin_unlock_irqrestore(&t->sighand->siglock, flags);
72227
72228 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
72229 + normal operation */
72230 + if (is_unhandled) {
72231 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
72232 + gr_handle_crash(t, sig);
72233 + }
72234 +
72235 return ret;
72236 }
72237
72238 @@ -1312,8 +1332,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72239 ret = check_kill_permission(sig, info, p);
72240 rcu_read_unlock();
72241
72242 - if (!ret && sig)
72243 + if (!ret && sig) {
72244 ret = do_send_sig_info(sig, info, p, true);
72245 + if (!ret)
72246 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
72247 + }
72248
72249 return ret;
72250 }
72251 @@ -2863,7 +2886,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
72252 int error = -ESRCH;
72253
72254 rcu_read_lock();
72255 - p = find_task_by_vpid(pid);
72256 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72257 + /* allow glibc communication via tgkill to other threads in our
72258 + thread group */
72259 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
72260 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
72261 + p = find_task_by_vpid_unrestricted(pid);
72262 + else
72263 +#endif
72264 + p = find_task_by_vpid(pid);
72265 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
72266 error = check_kill_permission(sig, info, p);
72267 /*
72268 diff --git a/kernel/softirq.c b/kernel/softirq.c
72269 index cc96bdc..8bb9750 100644
72270 --- a/kernel/softirq.c
72271 +++ b/kernel/softirq.c
72272 @@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
72273
72274 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
72275
72276 -char *softirq_to_name[NR_SOFTIRQS] = {
72277 +const char * const softirq_to_name[NR_SOFTIRQS] = {
72278 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
72279 "TASKLET", "SCHED", "HRTIMER", "RCU"
72280 };
72281 @@ -244,7 +244,7 @@ restart:
72282 kstat_incr_softirqs_this_cpu(vec_nr);
72283
72284 trace_softirq_entry(vec_nr);
72285 - h->action(h);
72286 + h->action();
72287 trace_softirq_exit(vec_nr);
72288 if (unlikely(prev_count != preempt_count())) {
72289 printk(KERN_ERR "huh, entered softirq %u %s %p"
72290 @@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
72291 or_softirq_pending(1UL << nr);
72292 }
72293
72294 -void open_softirq(int nr, void (*action)(struct softirq_action *))
72295 +void open_softirq(int nr, void (*action)(void))
72296 {
72297 - softirq_vec[nr].action = action;
72298 + pax_open_kernel();
72299 + *(void **)&softirq_vec[nr].action = action;
72300 + pax_close_kernel();
72301 }
72302
72303 /*
72304 @@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
72305
72306 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
72307
72308 -static void tasklet_action(struct softirq_action *a)
72309 +static void tasklet_action(void)
72310 {
72311 struct tasklet_struct *list;
72312
72313 @@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
72314 }
72315 }
72316
72317 -static void tasklet_hi_action(struct softirq_action *a)
72318 +static void tasklet_hi_action(void)
72319 {
72320 struct tasklet_struct *list;
72321
72322 diff --git a/kernel/srcu.c b/kernel/srcu.c
72323 index 97c465e..d83f3bb 100644
72324 --- a/kernel/srcu.c
72325 +++ b/kernel/srcu.c
72326 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
72327 preempt_disable();
72328 idx = rcu_dereference_index_check(sp->completed,
72329 rcu_read_lock_sched_held()) & 0x1;
72330 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72331 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72332 smp_mb(); /* B */ /* Avoid leaking the critical section. */
72333 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72334 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72335 preempt_enable();
72336 return idx;
72337 }
72338 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
72339 {
72340 preempt_disable();
72341 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72342 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72343 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72344 preempt_enable();
72345 }
72346 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72347 diff --git a/kernel/sys.c b/kernel/sys.c
72348 index e6e0ece..1f2e413 100644
72349 --- a/kernel/sys.c
72350 +++ b/kernel/sys.c
72351 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72352 error = -EACCES;
72353 goto out;
72354 }
72355 +
72356 + if (gr_handle_chroot_setpriority(p, niceval)) {
72357 + error = -EACCES;
72358 + goto out;
72359 + }
72360 +
72361 no_nice = security_task_setnice(p, niceval);
72362 if (no_nice) {
72363 error = no_nice;
72364 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72365 goto error;
72366 }
72367
72368 + if (gr_check_group_change(new->gid, new->egid, -1))
72369 + goto error;
72370 +
72371 if (rgid != (gid_t) -1 ||
72372 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72373 new->sgid = new->egid;
72374 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72375 old = current_cred();
72376
72377 retval = -EPERM;
72378 +
72379 + if (gr_check_group_change(kgid, kgid, kgid))
72380 + goto error;
72381 +
72382 if (nsown_capable(CAP_SETGID))
72383 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72384 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72385 @@ -647,7 +660,7 @@ error:
72386 /*
72387 * change the user struct in a credentials set to match the new UID
72388 */
72389 -static int set_user(struct cred *new)
72390 +int set_user(struct cred *new)
72391 {
72392 struct user_struct *new_user;
72393
72394 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72395 goto error;
72396 }
72397
72398 + if (gr_check_user_change(new->uid, new->euid, -1))
72399 + goto error;
72400 +
72401 if (!uid_eq(new->uid, old->uid)) {
72402 retval = set_user(new);
72403 if (retval < 0)
72404 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72405 old = current_cred();
72406
72407 retval = -EPERM;
72408 +
72409 + if (gr_check_crash_uid(kuid))
72410 + goto error;
72411 + if (gr_check_user_change(kuid, kuid, kuid))
72412 + goto error;
72413 +
72414 if (nsown_capable(CAP_SETUID)) {
72415 new->suid = new->uid = kuid;
72416 if (!uid_eq(kuid, old->uid)) {
72417 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72418 goto error;
72419 }
72420
72421 + if (gr_check_user_change(kruid, keuid, -1))
72422 + goto error;
72423 +
72424 if (ruid != (uid_t) -1) {
72425 new->uid = kruid;
72426 if (!uid_eq(kruid, old->uid)) {
72427 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72428 goto error;
72429 }
72430
72431 + if (gr_check_group_change(krgid, kegid, -1))
72432 + goto error;
72433 +
72434 if (rgid != (gid_t) -1)
72435 new->gid = krgid;
72436 if (egid != (gid_t) -1)
72437 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72438 if (!uid_valid(kuid))
72439 return old_fsuid;
72440
72441 + if (gr_check_user_change(-1, -1, kuid))
72442 + goto error;
72443 +
72444 new = prepare_creds();
72445 if (!new)
72446 return old_fsuid;
72447 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72448 }
72449 }
72450
72451 +error:
72452 abort_creds(new);
72453 return old_fsuid;
72454
72455 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72456 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72457 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72458 nsown_capable(CAP_SETGID)) {
72459 + if (gr_check_group_change(-1, -1, kgid))
72460 + goto error;
72461 +
72462 if (!gid_eq(kgid, old->fsgid)) {
72463 new->fsgid = kgid;
72464 goto change_okay;
72465 }
72466 }
72467
72468 +error:
72469 abort_creds(new);
72470 return old_fsgid;
72471
72472 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72473 return -EFAULT;
72474
72475 down_read(&uts_sem);
72476 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
72477 + error = __copy_to_user(name->sysname, &utsname()->sysname,
72478 __OLD_UTS_LEN);
72479 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72480 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72481 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
72482 __OLD_UTS_LEN);
72483 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72484 - error |= __copy_to_user(&name->release, &utsname()->release,
72485 + error |= __copy_to_user(name->release, &utsname()->release,
72486 __OLD_UTS_LEN);
72487 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72488 - error |= __copy_to_user(&name->version, &utsname()->version,
72489 + error |= __copy_to_user(name->version, &utsname()->version,
72490 __OLD_UTS_LEN);
72491 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72492 - error |= __copy_to_user(&name->machine, &utsname()->machine,
72493 + error |= __copy_to_user(name->machine, &utsname()->machine,
72494 __OLD_UTS_LEN);
72495 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72496 up_read(&uts_sem);
72497 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72498 error = get_dumpable(me->mm);
72499 break;
72500 case PR_SET_DUMPABLE:
72501 - if (arg2 < 0 || arg2 > 1) {
72502 + if (arg2 > 1) {
72503 error = -EINVAL;
72504 break;
72505 }
72506 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72507 index 26f65ea..df8e5ad 100644
72508 --- a/kernel/sysctl.c
72509 +++ b/kernel/sysctl.c
72510 @@ -92,7 +92,6 @@
72511
72512
72513 #if defined(CONFIG_SYSCTL)
72514 -
72515 /* External variables not in a header file. */
72516 extern int sysctl_overcommit_memory;
72517 extern int sysctl_overcommit_ratio;
72518 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72519 void __user *buffer, size_t *lenp, loff_t *ppos);
72520 #endif
72521
72522 -#ifdef CONFIG_PRINTK
72523 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72524 void __user *buffer, size_t *lenp, loff_t *ppos);
72525 -#endif
72526
72527 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72528 void __user *buffer, size_t *lenp, loff_t *ppos);
72529 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72530
72531 #endif
72532
72533 +extern struct ctl_table grsecurity_table[];
72534 +
72535 static struct ctl_table kern_table[];
72536 static struct ctl_table vm_table[];
72537 static struct ctl_table fs_table[];
72538 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72539 int sysctl_legacy_va_layout;
72540 #endif
72541
72542 +#ifdef CONFIG_PAX_SOFTMODE
72543 +static ctl_table pax_table[] = {
72544 + {
72545 + .procname = "softmode",
72546 + .data = &pax_softmode,
72547 + .maxlen = sizeof(unsigned int),
72548 + .mode = 0600,
72549 + .proc_handler = &proc_dointvec,
72550 + },
72551 +
72552 + { }
72553 +};
72554 +#endif
72555 +
72556 /* The default sysctl tables: */
72557
72558 static struct ctl_table sysctl_base_table[] = {
72559 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72560 #endif
72561
72562 static struct ctl_table kern_table[] = {
72563 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72564 + {
72565 + .procname = "grsecurity",
72566 + .mode = 0500,
72567 + .child = grsecurity_table,
72568 + },
72569 +#endif
72570 +
72571 +#ifdef CONFIG_PAX_SOFTMODE
72572 + {
72573 + .procname = "pax",
72574 + .mode = 0500,
72575 + .child = pax_table,
72576 + },
72577 +#endif
72578 +
72579 {
72580 .procname = "sched_child_runs_first",
72581 .data = &sysctl_sched_child_runs_first,
72582 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72583 .data = &modprobe_path,
72584 .maxlen = KMOD_PATH_LEN,
72585 .mode = 0644,
72586 - .proc_handler = proc_dostring,
72587 + .proc_handler = proc_dostring_modpriv,
72588 },
72589 {
72590 .procname = "modules_disabled",
72591 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72592 .extra1 = &zero,
72593 .extra2 = &one,
72594 },
72595 +#endif
72596 {
72597 .procname = "kptr_restrict",
72598 .data = &kptr_restrict,
72599 .maxlen = sizeof(int),
72600 .mode = 0644,
72601 .proc_handler = proc_dointvec_minmax_sysadmin,
72602 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72603 + .extra1 = &two,
72604 +#else
72605 .extra1 = &zero,
72606 +#endif
72607 .extra2 = &two,
72608 },
72609 -#endif
72610 {
72611 .procname = "ngroups_max",
72612 .data = &ngroups_max,
72613 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72614 .proc_handler = proc_dointvec_minmax,
72615 .extra1 = &zero,
72616 },
72617 + {
72618 + .procname = "heap_stack_gap",
72619 + .data = &sysctl_heap_stack_gap,
72620 + .maxlen = sizeof(sysctl_heap_stack_gap),
72621 + .mode = 0644,
72622 + .proc_handler = proc_doulongvec_minmax,
72623 + },
72624 #else
72625 {
72626 .procname = "nr_trim_pages",
72627 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72628 buffer, lenp, ppos);
72629 }
72630
72631 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72632 + void __user *buffer, size_t *lenp, loff_t *ppos)
72633 +{
72634 + if (write && !capable(CAP_SYS_MODULE))
72635 + return -EPERM;
72636 +
72637 + return _proc_do_string(table->data, table->maxlen, write,
72638 + buffer, lenp, ppos);
72639 +}
72640 +
72641 static size_t proc_skip_spaces(char **buf)
72642 {
72643 size_t ret;
72644 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72645 len = strlen(tmp);
72646 if (len > *size)
72647 len = *size;
72648 + if (len > sizeof(tmp))
72649 + len = sizeof(tmp);
72650 if (copy_to_user(*buf, tmp, len))
72651 return -EFAULT;
72652 *size -= len;
72653 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72654 return err;
72655 }
72656
72657 -#ifdef CONFIG_PRINTK
72658 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72659 void __user *buffer, size_t *lenp, loff_t *ppos)
72660 {
72661 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72662
72663 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72664 }
72665 -#endif
72666
72667 struct do_proc_dointvec_minmax_conv_param {
72668 int *min;
72669 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72670 *i = val;
72671 } else {
72672 val = convdiv * (*i) / convmul;
72673 - if (!first)
72674 + if (!first) {
72675 err = proc_put_char(&buffer, &left, '\t');
72676 + if (err)
72677 + break;
72678 + }
72679 err = proc_put_long(&buffer, &left, val, false);
72680 if (err)
72681 break;
72682 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72683 return -ENOSYS;
72684 }
72685
72686 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72687 + void __user *buffer, size_t *lenp, loff_t *ppos)
72688 +{
72689 + return -ENOSYS;
72690 +}
72691 +
72692 int proc_dointvec(struct ctl_table *table, int write,
72693 void __user *buffer, size_t *lenp, loff_t *ppos)
72694 {
72695 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72696 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72697 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72698 EXPORT_SYMBOL(proc_dostring);
72699 +EXPORT_SYMBOL(proc_dostring_modpriv);
72700 EXPORT_SYMBOL(proc_doulongvec_minmax);
72701 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72702 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72703 index 65bdcf1..21eb831 100644
72704 --- a/kernel/sysctl_binary.c
72705 +++ b/kernel/sysctl_binary.c
72706 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72707 int i;
72708
72709 set_fs(KERNEL_DS);
72710 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72711 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72712 set_fs(old_fs);
72713 if (result < 0)
72714 goto out_kfree;
72715 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72716 }
72717
72718 set_fs(KERNEL_DS);
72719 - result = vfs_write(file, buffer, str - buffer, &pos);
72720 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72721 set_fs(old_fs);
72722 if (result < 0)
72723 goto out_kfree;
72724 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72725 int i;
72726
72727 set_fs(KERNEL_DS);
72728 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72729 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72730 set_fs(old_fs);
72731 if (result < 0)
72732 goto out_kfree;
72733 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72734 }
72735
72736 set_fs(KERNEL_DS);
72737 - result = vfs_write(file, buffer, str - buffer, &pos);
72738 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72739 set_fs(old_fs);
72740 if (result < 0)
72741 goto out_kfree;
72742 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72743 int i;
72744
72745 set_fs(KERNEL_DS);
72746 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72747 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72748 set_fs(old_fs);
72749 if (result < 0)
72750 goto out;
72751 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72752 __le16 dnaddr;
72753
72754 set_fs(KERNEL_DS);
72755 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72756 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72757 set_fs(old_fs);
72758 if (result < 0)
72759 goto out;
72760 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72761 le16_to_cpu(dnaddr) & 0x3ff);
72762
72763 set_fs(KERNEL_DS);
72764 - result = vfs_write(file, buf, len, &pos);
72765 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72766 set_fs(old_fs);
72767 if (result < 0)
72768 goto out;
72769 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72770 index 145bb4d..b2aa969 100644
72771 --- a/kernel/taskstats.c
72772 +++ b/kernel/taskstats.c
72773 @@ -28,9 +28,12 @@
72774 #include <linux/fs.h>
72775 #include <linux/file.h>
72776 #include <linux/pid_namespace.h>
72777 +#include <linux/grsecurity.h>
72778 #include <net/genetlink.h>
72779 #include <linux/atomic.h>
72780
72781 +extern int gr_is_taskstats_denied(int pid);
72782 +
72783 /*
72784 * Maximum length of a cpumask that can be specified in
72785 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72786 @@ -570,6 +573,9 @@ err:
72787
72788 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72789 {
72790 + if (gr_is_taskstats_denied(current->pid))
72791 + return -EACCES;
72792 +
72793 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72794 return cmd_attr_register_cpumask(info);
72795 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72796 diff --git a/kernel/time.c b/kernel/time.c
72797 index d226c6a..c7c0960 100644
72798 --- a/kernel/time.c
72799 +++ b/kernel/time.c
72800 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72801 return error;
72802
72803 if (tz) {
72804 + /* we log in do_settimeofday called below, so don't log twice
72805 + */
72806 + if (!tv)
72807 + gr_log_timechange();
72808 +
72809 sys_tz = *tz;
72810 update_vsyscall_tz();
72811 if (firsttime) {
72812 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72813 index f11d83b..d016d91 100644
72814 --- a/kernel/time/alarmtimer.c
72815 +++ b/kernel/time/alarmtimer.c
72816 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72817 struct platform_device *pdev;
72818 int error = 0;
72819 int i;
72820 - struct k_clock alarm_clock = {
72821 + static struct k_clock alarm_clock = {
72822 .clock_getres = alarm_clock_getres,
72823 .clock_get = alarm_clock_get,
72824 .timer_create = alarm_timer_create,
72825 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72826 index f113755..ec24223 100644
72827 --- a/kernel/time/tick-broadcast.c
72828 +++ b/kernel/time/tick-broadcast.c
72829 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72830 * then clear the broadcast bit.
72831 */
72832 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72833 - int cpu = smp_processor_id();
72834 + cpu = smp_processor_id();
72835
72836 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72837 tick_broadcast_clear_oneshot(cpu);
72838 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72839 index e424970..4c7962b 100644
72840 --- a/kernel/time/timekeeping.c
72841 +++ b/kernel/time/timekeeping.c
72842 @@ -15,6 +15,7 @@
72843 #include <linux/init.h>
72844 #include <linux/mm.h>
72845 #include <linux/sched.h>
72846 +#include <linux/grsecurity.h>
72847 #include <linux/syscore_ops.h>
72848 #include <linux/clocksource.h>
72849 #include <linux/jiffies.h>
72850 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72851 if (!timespec_valid_strict(tv))
72852 return -EINVAL;
72853
72854 + gr_log_timechange();
72855 +
72856 write_seqlock_irqsave(&tk->lock, flags);
72857
72858 timekeeping_forward_now(tk);
72859 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72860 index af5a7e9..715611a 100644
72861 --- a/kernel/time/timer_list.c
72862 +++ b/kernel/time/timer_list.c
72863 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72864
72865 static void print_name_offset(struct seq_file *m, void *sym)
72866 {
72867 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72868 + SEQ_printf(m, "<%p>", NULL);
72869 +#else
72870 char symname[KSYM_NAME_LEN];
72871
72872 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72873 SEQ_printf(m, "<%pK>", sym);
72874 else
72875 SEQ_printf(m, "%s", symname);
72876 +#endif
72877 }
72878
72879 static void
72880 @@ -112,7 +116,11 @@ next_one:
72881 static void
72882 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72883 {
72884 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72885 + SEQ_printf(m, " .base: %p\n", NULL);
72886 +#else
72887 SEQ_printf(m, " .base: %pK\n", base);
72888 +#endif
72889 SEQ_printf(m, " .index: %d\n",
72890 base->index);
72891 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72892 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72893 {
72894 struct proc_dir_entry *pe;
72895
72896 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72897 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72898 +#else
72899 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72900 +#endif
72901 if (!pe)
72902 return -ENOMEM;
72903 return 0;
72904 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72905 index 0b537f2..40d6c20 100644
72906 --- a/kernel/time/timer_stats.c
72907 +++ b/kernel/time/timer_stats.c
72908 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72909 static unsigned long nr_entries;
72910 static struct entry entries[MAX_ENTRIES];
72911
72912 -static atomic_t overflow_count;
72913 +static atomic_unchecked_t overflow_count;
72914
72915 /*
72916 * The entries are in a hash-table, for fast lookup:
72917 @@ -140,7 +140,7 @@ static void reset_entries(void)
72918 nr_entries = 0;
72919 memset(entries, 0, sizeof(entries));
72920 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72921 - atomic_set(&overflow_count, 0);
72922 + atomic_set_unchecked(&overflow_count, 0);
72923 }
72924
72925 static struct entry *alloc_entry(void)
72926 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72927 if (likely(entry))
72928 entry->count++;
72929 else
72930 - atomic_inc(&overflow_count);
72931 + atomic_inc_unchecked(&overflow_count);
72932
72933 out_unlock:
72934 raw_spin_unlock_irqrestore(lock, flags);
72935 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72936
72937 static void print_name_offset(struct seq_file *m, unsigned long addr)
72938 {
72939 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72940 + seq_printf(m, "<%p>", NULL);
72941 +#else
72942 char symname[KSYM_NAME_LEN];
72943
72944 if (lookup_symbol_name(addr, symname) < 0)
72945 - seq_printf(m, "<%p>", (void *)addr);
72946 + seq_printf(m, "<%pK>", (void *)addr);
72947 else
72948 seq_printf(m, "%s", symname);
72949 +#endif
72950 }
72951
72952 static int tstats_show(struct seq_file *m, void *v)
72953 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
72954
72955 seq_puts(m, "Timer Stats Version: v0.2\n");
72956 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
72957 - if (atomic_read(&overflow_count))
72958 + if (atomic_read_unchecked(&overflow_count))
72959 seq_printf(m, "Overflow: %d entries\n",
72960 - atomic_read(&overflow_count));
72961 + atomic_read_unchecked(&overflow_count));
72962
72963 for (i = 0; i < nr_entries; i++) {
72964 entry = entries + i;
72965 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
72966 {
72967 struct proc_dir_entry *pe;
72968
72969 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72970 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
72971 +#else
72972 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
72973 +#endif
72974 if (!pe)
72975 return -ENOMEM;
72976 return 0;
72977 diff --git a/kernel/timer.c b/kernel/timer.c
72978 index 367d008..46857a0 100644
72979 --- a/kernel/timer.c
72980 +++ b/kernel/timer.c
72981 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
72982 /*
72983 * This function runs timers and the timer-tq in bottom half context.
72984 */
72985 -static void run_timer_softirq(struct softirq_action *h)
72986 +static void run_timer_softirq(void)
72987 {
72988 struct tvec_base *base = __this_cpu_read(tvec_bases);
72989
72990 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
72991 return NOTIFY_OK;
72992 }
72993
72994 -static struct notifier_block __cpuinitdata timers_nb = {
72995 +static struct notifier_block __cpuinitconst timers_nb = {
72996 .notifier_call = timer_cpu_notify,
72997 };
72998
72999 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
73000 index c0bd030..62a1927 100644
73001 --- a/kernel/trace/blktrace.c
73002 +++ b/kernel/trace/blktrace.c
73003 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
73004 struct blk_trace *bt = filp->private_data;
73005 char buf[16];
73006
73007 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
73008 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
73009
73010 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
73011 }
73012 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
73013 return 1;
73014
73015 bt = buf->chan->private_data;
73016 - atomic_inc(&bt->dropped);
73017 + atomic_inc_unchecked(&bt->dropped);
73018 return 0;
73019 }
73020
73021 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
73022
73023 bt->dir = dir;
73024 bt->dev = dev;
73025 - atomic_set(&bt->dropped, 0);
73026 + atomic_set_unchecked(&bt->dropped, 0);
73027
73028 ret = -EIO;
73029 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
73030 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
73031 index 356bc2f..7c94fc0 100644
73032 --- a/kernel/trace/ftrace.c
73033 +++ b/kernel/trace/ftrace.c
73034 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
73035 if (unlikely(ftrace_disabled))
73036 return 0;
73037
73038 + ret = ftrace_arch_code_modify_prepare();
73039 + FTRACE_WARN_ON(ret);
73040 + if (ret)
73041 + return 0;
73042 +
73043 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
73044 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
73045 if (ret) {
73046 ftrace_bug(ret, ip);
73047 - return 0;
73048 }
73049 - return 1;
73050 + return ret ? 0 : 1;
73051 }
73052
73053 /*
73054 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
73055
73056 int
73057 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
73058 - void *data)
73059 + void *data)
73060 {
73061 struct ftrace_func_probe *entry;
73062 struct ftrace_page *pg;
73063 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
73064 if (!count)
73065 return 0;
73066
73067 + pax_open_kernel();
73068 sort(start, count, sizeof(*start),
73069 ftrace_cmp_ips, ftrace_swap_ips);
73070 + pax_close_kernel();
73071
73072 start_pg = ftrace_allocate_pages(count);
73073 if (!start_pg)
73074 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
73075 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
73076
73077 static int ftrace_graph_active;
73078 -static struct notifier_block ftrace_suspend_notifier;
73079 -
73080 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
73081 {
73082 return 0;
73083 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
73084 return NOTIFY_DONE;
73085 }
73086
73087 +static struct notifier_block ftrace_suspend_notifier = {
73088 + .notifier_call = ftrace_suspend_notifier_call
73089 +};
73090 +
73091 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73092 trace_func_graph_ent_t entryfunc)
73093 {
73094 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73095 goto out;
73096 }
73097
73098 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
73099 register_pm_notifier(&ftrace_suspend_notifier);
73100
73101 ftrace_graph_active++;
73102 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
73103 index 4cb5e51..e7e05d9 100644
73104 --- a/kernel/trace/ring_buffer.c
73105 +++ b/kernel/trace/ring_buffer.c
73106 @@ -346,9 +346,9 @@ struct buffer_data_page {
73107 */
73108 struct buffer_page {
73109 struct list_head list; /* list of buffer pages */
73110 - local_t write; /* index for next write */
73111 + local_unchecked_t write; /* index for next write */
73112 unsigned read; /* index for next read */
73113 - local_t entries; /* entries on this page */
73114 + local_unchecked_t entries; /* entries on this page */
73115 unsigned long real_end; /* real end of data */
73116 struct buffer_data_page *page; /* Actual data page */
73117 };
73118 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
73119 unsigned long lost_events;
73120 unsigned long last_overrun;
73121 local_t entries_bytes;
73122 - local_t commit_overrun;
73123 - local_t overrun;
73124 + local_unchecked_t commit_overrun;
73125 + local_unchecked_t overrun;
73126 local_t entries;
73127 local_t committing;
73128 local_t commits;
73129 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73130 *
73131 * We add a counter to the write field to denote this.
73132 */
73133 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
73134 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
73135 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
73136 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
73137
73138 /*
73139 * Just make sure we have seen our old_write and synchronize
73140 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73141 * cmpxchg to only update if an interrupt did not already
73142 * do it for us. If the cmpxchg fails, we don't care.
73143 */
73144 - (void)local_cmpxchg(&next_page->write, old_write, val);
73145 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
73146 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
73147 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
73148
73149 /*
73150 * No need to worry about races with clearing out the commit.
73151 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
73152
73153 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
73154 {
73155 - return local_read(&bpage->entries) & RB_WRITE_MASK;
73156 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
73157 }
73158
73159 static inline unsigned long rb_page_write(struct buffer_page *bpage)
73160 {
73161 - return local_read(&bpage->write) & RB_WRITE_MASK;
73162 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
73163 }
73164
73165 static int
73166 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
73167 * bytes consumed in ring buffer from here.
73168 * Increment overrun to account for the lost events.
73169 */
73170 - local_add(page_entries, &cpu_buffer->overrun);
73171 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
73172 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73173 }
73174
73175 @@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
73176 * it is our responsibility to update
73177 * the counters.
73178 */
73179 - local_add(entries, &cpu_buffer->overrun);
73180 + local_add_unchecked(entries, &cpu_buffer->overrun);
73181 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73182
73183 /*
73184 @@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73185 if (tail == BUF_PAGE_SIZE)
73186 tail_page->real_end = 0;
73187
73188 - local_sub(length, &tail_page->write);
73189 + local_sub_unchecked(length, &tail_page->write);
73190 return;
73191 }
73192
73193 @@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73194 rb_event_set_padding(event);
73195
73196 /* Set the write back to the previous setting */
73197 - local_sub(length, &tail_page->write);
73198 + local_sub_unchecked(length, &tail_page->write);
73199 return;
73200 }
73201
73202 @@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73203
73204 /* Set write to end of buffer */
73205 length = (tail + length) - BUF_PAGE_SIZE;
73206 - local_sub(length, &tail_page->write);
73207 + local_sub_unchecked(length, &tail_page->write);
73208 }
73209
73210 /*
73211 @@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73212 * about it.
73213 */
73214 if (unlikely(next_page == commit_page)) {
73215 - local_inc(&cpu_buffer->commit_overrun);
73216 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73217 goto out_reset;
73218 }
73219
73220 @@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73221 cpu_buffer->tail_page) &&
73222 (cpu_buffer->commit_page ==
73223 cpu_buffer->reader_page))) {
73224 - local_inc(&cpu_buffer->commit_overrun);
73225 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73226 goto out_reset;
73227 }
73228 }
73229 @@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73230 length += RB_LEN_TIME_EXTEND;
73231
73232 tail_page = cpu_buffer->tail_page;
73233 - write = local_add_return(length, &tail_page->write);
73234 + write = local_add_return_unchecked(length, &tail_page->write);
73235
73236 /* set write to only the index of the write */
73237 write &= RB_WRITE_MASK;
73238 @@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73239 kmemcheck_annotate_bitfield(event, bitfield);
73240 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
73241
73242 - local_inc(&tail_page->entries);
73243 + local_inc_unchecked(&tail_page->entries);
73244
73245 /*
73246 * If this is the first commit on the page, then update
73247 @@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73248
73249 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
73250 unsigned long write_mask =
73251 - local_read(&bpage->write) & ~RB_WRITE_MASK;
73252 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
73253 unsigned long event_length = rb_event_length(event);
73254 /*
73255 * This is on the tail page. It is possible that
73256 @@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73257 */
73258 old_index += write_mask;
73259 new_index += write_mask;
73260 - index = local_cmpxchg(&bpage->write, old_index, new_index);
73261 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
73262 if (index == old_index) {
73263 /* update counters */
73264 local_sub(event_length, &cpu_buffer->entries_bytes);
73265 @@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73266
73267 /* Do the likely case first */
73268 if (likely(bpage->page == (void *)addr)) {
73269 - local_dec(&bpage->entries);
73270 + local_dec_unchecked(&bpage->entries);
73271 return;
73272 }
73273
73274 @@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73275 start = bpage;
73276 do {
73277 if (bpage->page == (void *)addr) {
73278 - local_dec(&bpage->entries);
73279 + local_dec_unchecked(&bpage->entries);
73280 return;
73281 }
73282 rb_inc_page(cpu_buffer, &bpage);
73283 @@ -2923,7 +2923,7 @@ static inline unsigned long
73284 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
73285 {
73286 return local_read(&cpu_buffer->entries) -
73287 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
73288 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
73289 }
73290
73291 /**
73292 @@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
73293 return 0;
73294
73295 cpu_buffer = buffer->buffers[cpu];
73296 - ret = local_read(&cpu_buffer->overrun);
73297 + ret = local_read_unchecked(&cpu_buffer->overrun);
73298
73299 return ret;
73300 }
73301 @@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
73302 return 0;
73303
73304 cpu_buffer = buffer->buffers[cpu];
73305 - ret = local_read(&cpu_buffer->commit_overrun);
73306 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
73307
73308 return ret;
73309 }
73310 @@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
73311 /* if you care about this being correct, lock the buffer */
73312 for_each_buffer_cpu(buffer, cpu) {
73313 cpu_buffer = buffer->buffers[cpu];
73314 - overruns += local_read(&cpu_buffer->overrun);
73315 + overruns += local_read_unchecked(&cpu_buffer->overrun);
73316 }
73317
73318 return overruns;
73319 @@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73320 /*
73321 * Reset the reader page to size zero.
73322 */
73323 - local_set(&cpu_buffer->reader_page->write, 0);
73324 - local_set(&cpu_buffer->reader_page->entries, 0);
73325 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73326 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73327 local_set(&cpu_buffer->reader_page->page->commit, 0);
73328 cpu_buffer->reader_page->real_end = 0;
73329
73330 @@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73331 * want to compare with the last_overrun.
73332 */
73333 smp_mb();
73334 - overwrite = local_read(&(cpu_buffer->overrun));
73335 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
73336
73337 /*
73338 * Here's the tricky part.
73339 @@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73340
73341 cpu_buffer->head_page
73342 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73343 - local_set(&cpu_buffer->head_page->write, 0);
73344 - local_set(&cpu_buffer->head_page->entries, 0);
73345 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
73346 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73347 local_set(&cpu_buffer->head_page->page->commit, 0);
73348
73349 cpu_buffer->head_page->read = 0;
73350 @@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73351
73352 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73353 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73354 - local_set(&cpu_buffer->reader_page->write, 0);
73355 - local_set(&cpu_buffer->reader_page->entries, 0);
73356 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73357 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73358 local_set(&cpu_buffer->reader_page->page->commit, 0);
73359 cpu_buffer->reader_page->read = 0;
73360
73361 - local_set(&cpu_buffer->commit_overrun, 0);
73362 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73363 local_set(&cpu_buffer->entries_bytes, 0);
73364 - local_set(&cpu_buffer->overrun, 0);
73365 + local_set_unchecked(&cpu_buffer->overrun, 0);
73366 local_set(&cpu_buffer->entries, 0);
73367 local_set(&cpu_buffer->committing, 0);
73368 local_set(&cpu_buffer->commits, 0);
73369 @@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73370 rb_init_page(bpage);
73371 bpage = reader->page;
73372 reader->page = *data_page;
73373 - local_set(&reader->write, 0);
73374 - local_set(&reader->entries, 0);
73375 + local_set_unchecked(&reader->write, 0);
73376 + local_set_unchecked(&reader->entries, 0);
73377 reader->read = 0;
73378 *data_page = bpage;
73379
73380 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73381 index 31e4f55..62da00f 100644
73382 --- a/kernel/trace/trace.c
73383 +++ b/kernel/trace/trace.c
73384 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73385 };
73386 #endif
73387
73388 -static struct dentry *d_tracer;
73389 -
73390 struct dentry *tracing_init_dentry(void)
73391 {
73392 + static struct dentry *d_tracer;
73393 static int once;
73394
73395 if (d_tracer)
73396 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73397 return d_tracer;
73398 }
73399
73400 -static struct dentry *d_percpu;
73401 -
73402 struct dentry *tracing_dentry_percpu(void)
73403 {
73404 + static struct dentry *d_percpu;
73405 static int once;
73406 struct dentry *d_tracer;
73407
73408 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73409 index d608d09..7eddcb1 100644
73410 --- a/kernel/trace/trace_events.c
73411 +++ b/kernel/trace/trace_events.c
73412 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73413 struct ftrace_module_file_ops {
73414 struct list_head list;
73415 struct module *mod;
73416 - struct file_operations id;
73417 - struct file_operations enable;
73418 - struct file_operations format;
73419 - struct file_operations filter;
73420 };
73421
73422 static struct ftrace_module_file_ops *
73423 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73424
73425 file_ops->mod = mod;
73426
73427 - file_ops->id = ftrace_event_id_fops;
73428 - file_ops->id.owner = mod;
73429 -
73430 - file_ops->enable = ftrace_enable_fops;
73431 - file_ops->enable.owner = mod;
73432 -
73433 - file_ops->filter = ftrace_event_filter_fops;
73434 - file_ops->filter.owner = mod;
73435 -
73436 - file_ops->format = ftrace_event_format_fops;
73437 - file_ops->format.owner = mod;
73438 + pax_open_kernel();
73439 + *(void **)&mod->trace_id.owner = mod;
73440 + *(void **)&mod->trace_enable.owner = mod;
73441 + *(void **)&mod->trace_filter.owner = mod;
73442 + *(void **)&mod->trace_format.owner = mod;
73443 + pax_close_kernel();
73444
73445 list_add(&file_ops->list, &ftrace_module_file_list);
73446
73447 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73448
73449 for_each_event(call, start, end) {
73450 __trace_add_event_call(*call, mod,
73451 - &file_ops->id, &file_ops->enable,
73452 - &file_ops->filter, &file_ops->format);
73453 + &mod->trace_id, &mod->trace_enable,
73454 + &mod->trace_filter, &mod->trace_format);
73455 }
73456 }
73457
73458 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73459 index fd3c8aa..5f324a6 100644
73460 --- a/kernel/trace/trace_mmiotrace.c
73461 +++ b/kernel/trace/trace_mmiotrace.c
73462 @@ -24,7 +24,7 @@ struct header_iter {
73463 static struct trace_array *mmio_trace_array;
73464 static bool overrun_detected;
73465 static unsigned long prev_overruns;
73466 -static atomic_t dropped_count;
73467 +static atomic_unchecked_t dropped_count;
73468
73469 static void mmio_reset_data(struct trace_array *tr)
73470 {
73471 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73472
73473 static unsigned long count_overruns(struct trace_iterator *iter)
73474 {
73475 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
73476 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73477 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73478
73479 if (over > prev_overruns)
73480 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73481 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
73482 sizeof(*entry), 0, pc);
73483 if (!event) {
73484 - atomic_inc(&dropped_count);
73485 + atomic_inc_unchecked(&dropped_count);
73486 return;
73487 }
73488 entry = ring_buffer_event_data(event);
73489 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73490 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73491 sizeof(*entry), 0, pc);
73492 if (!event) {
73493 - atomic_inc(&dropped_count);
73494 + atomic_inc_unchecked(&dropped_count);
73495 return;
73496 }
73497 entry = ring_buffer_event_data(event);
73498 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73499 index 123b189..1e9e2a6 100644
73500 --- a/kernel/trace/trace_output.c
73501 +++ b/kernel/trace/trace_output.c
73502 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73503
73504 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73505 if (!IS_ERR(p)) {
73506 - p = mangle_path(s->buffer + s->len, p, "\n");
73507 + p = mangle_path(s->buffer + s->len, p, "\n\\");
73508 if (p) {
73509 s->len = p - s->buffer;
73510 return 1;
73511 @@ -824,14 +824,16 @@ int register_ftrace_event(struct trace_event *event)
73512 goto out;
73513 }
73514
73515 + pax_open_kernel();
73516 if (event->funcs->trace == NULL)
73517 - event->funcs->trace = trace_nop_print;
73518 + *(void **)&event->funcs->trace = trace_nop_print;
73519 if (event->funcs->raw == NULL)
73520 - event->funcs->raw = trace_nop_print;
73521 + *(void **)&event->funcs->raw = trace_nop_print;
73522 if (event->funcs->hex == NULL)
73523 - event->funcs->hex = trace_nop_print;
73524 + *(void **)&event->funcs->hex = trace_nop_print;
73525 if (event->funcs->binary == NULL)
73526 - event->funcs->binary = trace_nop_print;
73527 + *(void **)&event->funcs->binary = trace_nop_print;
73528 + pax_close_kernel();
73529
73530 key = event->type & (EVENT_HASHSIZE - 1);
73531
73532 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73533 index 0c1b1657..95337e9 100644
73534 --- a/kernel/trace/trace_stack.c
73535 +++ b/kernel/trace/trace_stack.c
73536 @@ -53,7 +53,7 @@ static inline void check_stack(void)
73537 return;
73538
73539 /* we do not handle interrupt stacks yet */
73540 - if (!object_is_on_stack(&this_size))
73541 + if (!object_starts_on_stack(&this_size))
73542 return;
73543
73544 local_irq_save(flags);
73545 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73546 index 28e9d6c9..50381bd 100644
73547 --- a/lib/Kconfig.debug
73548 +++ b/lib/Kconfig.debug
73549 @@ -1278,6 +1278,7 @@ config LATENCYTOP
73550 depends on DEBUG_KERNEL
73551 depends on STACKTRACE_SUPPORT
73552 depends on PROC_FS
73553 + depends on !GRKERNSEC_HIDESYM
73554 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73555 select KALLSYMS
73556 select KALLSYMS_ALL
73557 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73558
73559 config PROVIDE_OHCI1394_DMA_INIT
73560 bool "Remote debugging over FireWire early on boot"
73561 - depends on PCI && X86
73562 + depends on PCI && X86 && !GRKERNSEC
73563 help
73564 If you want to debug problems which hang or crash the kernel early
73565 on boot and the crashing machine has a FireWire port, you can use
73566 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73567
73568 config FIREWIRE_OHCI_REMOTE_DMA
73569 bool "Remote debugging over FireWire with firewire-ohci"
73570 - depends on FIREWIRE_OHCI
73571 + depends on FIREWIRE_OHCI && !GRKERNSEC
73572 help
73573 This option lets you use the FireWire bus for remote debugging
73574 with help of the firewire-ohci driver. It enables unfiltered
73575 diff --git a/lib/Makefile b/lib/Makefile
73576 index a08b791..a3ff1eb 100644
73577 --- a/lib/Makefile
73578 +++ b/lib/Makefile
73579 @@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73580
73581 obj-$(CONFIG_BTREE) += btree.o
73582 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73583 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73584 +obj-y += list_debug.o
73585 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73586
73587 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73588 diff --git a/lib/bitmap.c b/lib/bitmap.c
73589 index 06fdfa1..97c5c7d 100644
73590 --- a/lib/bitmap.c
73591 +++ b/lib/bitmap.c
73592 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73593 {
73594 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73595 u32 chunk;
73596 - const char __user __force *ubuf = (const char __user __force *)buf;
73597 + const char __user *ubuf = (const char __force_user *)buf;
73598
73599 bitmap_zero(maskp, nmaskbits);
73600
73601 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73602 {
73603 if (!access_ok(VERIFY_READ, ubuf, ulen))
73604 return -EFAULT;
73605 - return __bitmap_parse((const char __force *)ubuf,
73606 + return __bitmap_parse((const char __force_kernel *)ubuf,
73607 ulen, 1, maskp, nmaskbits);
73608
73609 }
73610 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73611 {
73612 unsigned a, b;
73613 int c, old_c, totaldigits;
73614 - const char __user __force *ubuf = (const char __user __force *)buf;
73615 + const char __user *ubuf = (const char __force_user *)buf;
73616 int exp_digit, in_range;
73617
73618 totaldigits = c = 0;
73619 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73620 {
73621 if (!access_ok(VERIFY_READ, ubuf, ulen))
73622 return -EFAULT;
73623 - return __bitmap_parselist((const char __force *)ubuf,
73624 + return __bitmap_parselist((const char __force_kernel *)ubuf,
73625 ulen, 1, maskp, nmaskbits);
73626 }
73627 EXPORT_SYMBOL(bitmap_parselist_user);
73628 diff --git a/lib/bug.c b/lib/bug.c
73629 index d0cdf14..4d07bd2 100644
73630 --- a/lib/bug.c
73631 +++ b/lib/bug.c
73632 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73633 return BUG_TRAP_TYPE_NONE;
73634
73635 bug = find_bug(bugaddr);
73636 + if (!bug)
73637 + return BUG_TRAP_TYPE_NONE;
73638
73639 file = NULL;
73640 line = 0;
73641 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73642 index d11808c..dc2d6f8 100644
73643 --- a/lib/debugobjects.c
73644 +++ b/lib/debugobjects.c
73645 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73646 if (limit > 4)
73647 return;
73648
73649 - is_on_stack = object_is_on_stack(addr);
73650 + is_on_stack = object_starts_on_stack(addr);
73651 if (is_on_stack == onstack)
73652 return;
73653
73654 diff --git a/lib/devres.c b/lib/devres.c
73655 index 80b9c76..9e32279 100644
73656 --- a/lib/devres.c
73657 +++ b/lib/devres.c
73658 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73659 void devm_iounmap(struct device *dev, void __iomem *addr)
73660 {
73661 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73662 - (void *)addr));
73663 + (void __force *)addr));
73664 iounmap(addr);
73665 }
73666 EXPORT_SYMBOL(devm_iounmap);
73667 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73668 {
73669 ioport_unmap(addr);
73670 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73671 - devm_ioport_map_match, (void *)addr));
73672 + devm_ioport_map_match, (void __force *)addr));
73673 }
73674 EXPORT_SYMBOL(devm_ioport_unmap);
73675
73676 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73677 index d84beb9..da44791 100644
73678 --- a/lib/dma-debug.c
73679 +++ b/lib/dma-debug.c
73680 @@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73681
73682 void dma_debug_add_bus(struct bus_type *bus)
73683 {
73684 - struct notifier_block *nb;
73685 + notifier_block_no_const *nb;
73686
73687 if (global_disable)
73688 return;
73689 @@ -919,7 +919,7 @@ out:
73690
73691 static void check_for_stack(struct device *dev, void *addr)
73692 {
73693 - if (object_is_on_stack(addr))
73694 + if (object_starts_on_stack(addr))
73695 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73696 "stack [addr=%p]\n", addr);
73697 }
73698 diff --git a/lib/inflate.c b/lib/inflate.c
73699 index 013a761..c28f3fc 100644
73700 --- a/lib/inflate.c
73701 +++ b/lib/inflate.c
73702 @@ -269,7 +269,7 @@ static void free(void *where)
73703 malloc_ptr = free_mem_ptr;
73704 }
73705 #else
73706 -#define malloc(a) kmalloc(a, GFP_KERNEL)
73707 +#define malloc(a) kmalloc((a), GFP_KERNEL)
73708 #define free(a) kfree(a)
73709 #endif
73710
73711 diff --git a/lib/ioremap.c b/lib/ioremap.c
73712 index 0c9216c..863bd89 100644
73713 --- a/lib/ioremap.c
73714 +++ b/lib/ioremap.c
73715 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73716 unsigned long next;
73717
73718 phys_addr -= addr;
73719 - pmd = pmd_alloc(&init_mm, pud, addr);
73720 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73721 if (!pmd)
73722 return -ENOMEM;
73723 do {
73724 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73725 unsigned long next;
73726
73727 phys_addr -= addr;
73728 - pud = pud_alloc(&init_mm, pgd, addr);
73729 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
73730 if (!pud)
73731 return -ENOMEM;
73732 do {
73733 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73734 index bd2bea9..6b3c95e 100644
73735 --- a/lib/is_single_threaded.c
73736 +++ b/lib/is_single_threaded.c
73737 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73738 struct task_struct *p, *t;
73739 bool ret;
73740
73741 + if (!mm)
73742 + return true;
73743 +
73744 if (atomic_read(&task->signal->live) != 1)
73745 return false;
73746
73747 diff --git a/lib/list_debug.c b/lib/list_debug.c
73748 index c24c2f7..3fc5da0 100644
73749 --- a/lib/list_debug.c
73750 +++ b/lib/list_debug.c
73751 @@ -11,7 +11,9 @@
73752 #include <linux/bug.h>
73753 #include <linux/kernel.h>
73754 #include <linux/rculist.h>
73755 +#include <linux/mm.h>
73756
73757 +#ifdef CONFIG_DEBUG_LIST
73758 /*
73759 * Insert a new entry between two known consecutive entries.
73760 *
73761 @@ -19,21 +21,32 @@
73762 * the prev/next entries already!
73763 */
73764
73765 -void __list_add(struct list_head *new,
73766 - struct list_head *prev,
73767 - struct list_head *next)
73768 +static bool __list_add_debug(struct list_head *new,
73769 + struct list_head *prev,
73770 + struct list_head *next)
73771 {
73772 - WARN(next->prev != prev,
73773 + if (WARN(next->prev != prev,
73774 "list_add corruption. next->prev should be "
73775 "prev (%p), but was %p. (next=%p).\n",
73776 - prev, next->prev, next);
73777 - WARN(prev->next != next,
73778 + prev, next->prev, next) ||
73779 + WARN(prev->next != next,
73780 "list_add corruption. prev->next should be "
73781 "next (%p), but was %p. (prev=%p).\n",
73782 - next, prev->next, prev);
73783 - WARN(new == prev || new == next,
73784 + next, prev->next, prev) ||
73785 + WARN(new == prev || new == next,
73786 "list_add double add: new=%p, prev=%p, next=%p.\n",
73787 - new, prev, next);
73788 + new, prev, next))
73789 + return false;
73790 + return true;
73791 +}
73792 +
73793 +void __list_add(struct list_head *new,
73794 + struct list_head *prev,
73795 + struct list_head *next)
73796 +{
73797 + if (!__list_add_debug(new, prev, next))
73798 + return;
73799 +
73800 next->prev = new;
73801 new->next = next;
73802 new->prev = prev;
73803 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73804 }
73805 EXPORT_SYMBOL(__list_add);
73806
73807 -void __list_del_entry(struct list_head *entry)
73808 +static bool __list_del_entry_debug(struct list_head *entry)
73809 {
73810 struct list_head *prev, *next;
73811
73812 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73813 WARN(next->prev != entry,
73814 "list_del corruption. next->prev should be %p, "
73815 "but was %p\n", entry, next->prev))
73816 + return false;
73817 + return true;
73818 +}
73819 +
73820 +void __list_del_entry(struct list_head *entry)
73821 +{
73822 + if (!__list_del_entry_debug(entry))
73823 return;
73824
73825 - __list_del(prev, next);
73826 + __list_del(entry->prev, entry->next);
73827 }
73828 EXPORT_SYMBOL(__list_del_entry);
73829
73830 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73831 void __list_add_rcu(struct list_head *new,
73832 struct list_head *prev, struct list_head *next)
73833 {
73834 - WARN(next->prev != prev,
73835 + if (WARN(next->prev != prev,
73836 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73837 - prev, next->prev, next);
73838 - WARN(prev->next != next,
73839 + prev, next->prev, next) ||
73840 + WARN(prev->next != next,
73841 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73842 - next, prev->next, prev);
73843 + next, prev->next, prev))
73844 + return;
73845 +
73846 new->next = next;
73847 new->prev = prev;
73848 rcu_assign_pointer(list_next_rcu(prev), new);
73849 next->prev = new;
73850 }
73851 EXPORT_SYMBOL(__list_add_rcu);
73852 +#endif
73853 +
73854 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
73855 +{
73856 + struct list_head *prev, *next;
73857 +
73858 + prev = head->prev;
73859 + next = head;
73860 +
73861 +#ifdef CONFIG_DEBUG_LIST
73862 + if (!__list_add_debug(new, prev, next))
73863 + return;
73864 +#endif
73865 +
73866 + pax_open_kernel();
73867 + next->prev = new;
73868 + new->next = next;
73869 + new->prev = prev;
73870 + prev->next = new;
73871 + pax_close_kernel();
73872 +}
73873 +EXPORT_SYMBOL(pax_list_add_tail);
73874 +
73875 +void pax_list_del(struct list_head *entry)
73876 +{
73877 +#ifdef CONFIG_DEBUG_LIST
73878 + if (!__list_del_entry_debug(entry))
73879 + return;
73880 +#endif
73881 +
73882 + pax_open_kernel();
73883 + __list_del(entry->prev, entry->next);
73884 + entry->next = LIST_POISON1;
73885 + entry->prev = LIST_POISON2;
73886 + pax_close_kernel();
73887 +}
73888 +EXPORT_SYMBOL(pax_list_del);
73889 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73890 index e796429..6e38f9f 100644
73891 --- a/lib/radix-tree.c
73892 +++ b/lib/radix-tree.c
73893 @@ -92,7 +92,7 @@ struct radix_tree_preload {
73894 int nr;
73895 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73896 };
73897 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73898 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73899
73900 static inline void *ptr_to_indirect(void *ptr)
73901 {
73902 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73903 index bb2b201..46abaf9 100644
73904 --- a/lib/strncpy_from_user.c
73905 +++ b/lib/strncpy_from_user.c
73906 @@ -21,7 +21,7 @@
73907 */
73908 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73909 {
73910 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73911 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73912 long res = 0;
73913
73914 /*
73915 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73916 index a28df52..3d55877 100644
73917 --- a/lib/strnlen_user.c
73918 +++ b/lib/strnlen_user.c
73919 @@ -26,7 +26,7 @@
73920 */
73921 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
73922 {
73923 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73924 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73925 long align, res = 0;
73926 unsigned long c;
73927
73928 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
73929 index 39c99fe..18f060b 100644
73930 --- a/lib/vsprintf.c
73931 +++ b/lib/vsprintf.c
73932 @@ -16,6 +16,9 @@
73933 * - scnprintf and vscnprintf
73934 */
73935
73936 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73937 +#define __INCLUDED_BY_HIDESYM 1
73938 +#endif
73939 #include <stdarg.h>
73940 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
73941 #include <linux/types.h>
73942 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
73943 char sym[KSYM_SYMBOL_LEN];
73944 if (ext == 'B')
73945 sprint_backtrace(sym, value);
73946 - else if (ext != 'f' && ext != 's')
73947 + else if (ext != 'f' && ext != 's' && ext != 'a')
73948 sprint_symbol(sym, value);
73949 else
73950 sprint_symbol_no_offset(sym, value);
73951 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
73952 return number(buf, end, *(const netdev_features_t *)addr, spec);
73953 }
73954
73955 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73956 +int kptr_restrict __read_mostly = 2;
73957 +#else
73958 int kptr_restrict __read_mostly;
73959 +#endif
73960
73961 /*
73962 * Show a '%p' thing. A kernel extension is that the '%p' is followed
73963 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
73964 * - 'S' For symbolic direct pointers with offset
73965 * - 's' For symbolic direct pointers without offset
73966 * - 'B' For backtraced symbolic direct pointers with offset
73967 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
73968 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
73969 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
73970 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
73971 * - 'M' For a 6-byte MAC address, it prints the address in the
73972 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73973
73974 if (!ptr && *fmt != 'K') {
73975 /*
73976 - * Print (null) with the same width as a pointer so it makes
73977 + * Print (nil) with the same width as a pointer so it makes
73978 * tabular output look nice.
73979 */
73980 if (spec.field_width == -1)
73981 spec.field_width = default_width;
73982 - return string(buf, end, "(null)", spec);
73983 + return string(buf, end, "(nil)", spec);
73984 }
73985
73986 switch (*fmt) {
73987 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73988 /* Fallthrough */
73989 case 'S':
73990 case 's':
73991 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73992 + break;
73993 +#else
73994 + return symbol_string(buf, end, ptr, spec, *fmt);
73995 +#endif
73996 + case 'A':
73997 + case 'a':
73998 case 'B':
73999 return symbol_string(buf, end, ptr, spec, *fmt);
74000 case 'R':
74001 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74002 va_end(va);
74003 return buf;
74004 }
74005 + case 'P':
74006 + break;
74007 case 'K':
74008 /*
74009 * %pK cannot be used in IRQ context because its test
74010 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74011 }
74012 break;
74013 }
74014 +
74015 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74016 + /* 'P' = approved pointers to copy to userland,
74017 + as in the /proc/kallsyms case, as we make it display nothing
74018 + for non-root users, and the real contents for root users
74019 + Also ignore 'K' pointers, since we force their NULLing for non-root users
74020 + above
74021 + */
74022 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
74023 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
74024 + dump_stack();
74025 + ptr = NULL;
74026 + }
74027 +#endif
74028 +
74029 spec.flags |= SMALL;
74030 if (spec.field_width == -1) {
74031 spec.field_width = default_width;
74032 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74033 typeof(type) value; \
74034 if (sizeof(type) == 8) { \
74035 args = PTR_ALIGN(args, sizeof(u32)); \
74036 - *(u32 *)&value = *(u32 *)args; \
74037 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
74038 + *(u32 *)&value = *(const u32 *)args; \
74039 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
74040 } else { \
74041 args = PTR_ALIGN(args, sizeof(type)); \
74042 - value = *(typeof(type) *)args; \
74043 + value = *(const typeof(type) *)args; \
74044 } \
74045 args += sizeof(type); \
74046 value; \
74047 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74048 case FORMAT_TYPE_STR: {
74049 const char *str_arg = args;
74050 args += strlen(str_arg) + 1;
74051 - str = string(str, end, (char *)str_arg, spec);
74052 + str = string(str, end, str_arg, spec);
74053 break;
74054 }
74055
74056 diff --git a/localversion-grsec b/localversion-grsec
74057 new file mode 100644
74058 index 0000000..7cd6065
74059 --- /dev/null
74060 +++ b/localversion-grsec
74061 @@ -0,0 +1 @@
74062 +-grsec
74063 diff --git a/mm/Kconfig b/mm/Kconfig
74064 index a3f8ddd..f31e92e 100644
74065 --- a/mm/Kconfig
74066 +++ b/mm/Kconfig
74067 @@ -252,10 +252,10 @@ config KSM
74068 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
74069
74070 config DEFAULT_MMAP_MIN_ADDR
74071 - int "Low address space to protect from user allocation"
74072 + int "Low address space to protect from user allocation"
74073 depends on MMU
74074 - default 4096
74075 - help
74076 + default 65536
74077 + help
74078 This is the portion of low virtual memory which should be protected
74079 from userspace allocation. Keeping a user from writing to low pages
74080 can help reduce the impact of kernel NULL pointer bugs.
74081 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
74082
74083 config HWPOISON_INJECT
74084 tristate "HWPoison pages injector"
74085 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
74086 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
74087 select PROC_PAGE_MONITOR
74088
74089 config NOMMU_INITIAL_TRIM_EXCESS
74090 diff --git a/mm/filemap.c b/mm/filemap.c
74091 index 83efee7..3f99381 100644
74092 --- a/mm/filemap.c
74093 +++ b/mm/filemap.c
74094 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
74095 struct address_space *mapping = file->f_mapping;
74096
74097 if (!mapping->a_ops->readpage)
74098 - return -ENOEXEC;
74099 + return -ENODEV;
74100 file_accessed(file);
74101 vma->vm_ops = &generic_file_vm_ops;
74102 return 0;
74103 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
74104 *pos = i_size_read(inode);
74105
74106 if (limit != RLIM_INFINITY) {
74107 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
74108 if (*pos >= limit) {
74109 send_sig(SIGXFSZ, current, 0);
74110 return -EFBIG;
74111 diff --git a/mm/fremap.c b/mm/fremap.c
74112 index a0aaf0e..20325c3 100644
74113 --- a/mm/fremap.c
74114 +++ b/mm/fremap.c
74115 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
74116 retry:
74117 vma = find_vma(mm, start);
74118
74119 +#ifdef CONFIG_PAX_SEGMEXEC
74120 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
74121 + goto out;
74122 +#endif
74123 +
74124 /*
74125 * Make sure the vma is shared, that it supports prefaulting,
74126 * and that the remapped range is valid and fully within
74127 diff --git a/mm/highmem.c b/mm/highmem.c
74128 index 09fc744..3936897 100644
74129 --- a/mm/highmem.c
74130 +++ b/mm/highmem.c
74131 @@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
74132 * So no dangers, even with speculative execution.
74133 */
74134 page = pte_page(pkmap_page_table[i]);
74135 + pax_open_kernel();
74136 pte_clear(&init_mm, (unsigned long)page_address(page),
74137 &pkmap_page_table[i]);
74138 -
74139 + pax_close_kernel();
74140 set_page_address(page, NULL);
74141 need_flush = 1;
74142 }
74143 @@ -199,9 +200,11 @@ start:
74144 }
74145 }
74146 vaddr = PKMAP_ADDR(last_pkmap_nr);
74147 +
74148 + pax_open_kernel();
74149 set_pte_at(&init_mm, vaddr,
74150 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
74151 -
74152 + pax_close_kernel();
74153 pkmap_count[last_pkmap_nr] = 1;
74154 set_page_address(page, (void *)vaddr);
74155
74156 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
74157 index 40f17c3..c1cc011 100644
74158 --- a/mm/huge_memory.c
74159 +++ b/mm/huge_memory.c
74160 @@ -710,7 +710,7 @@ out:
74161 * run pte_offset_map on the pmd, if an huge pmd could
74162 * materialize from under us from a different thread.
74163 */
74164 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
74165 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74166 return VM_FAULT_OOM;
74167 /* if an huge pmd materialized from under us just retry later */
74168 if (unlikely(pmd_trans_huge(*pmd)))
74169 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
74170 index f198aca..10e3e37 100644
74171 --- a/mm/hugetlb.c
74172 +++ b/mm/hugetlb.c
74173 @@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
74174 return 1;
74175 }
74176
74177 +#ifdef CONFIG_PAX_SEGMEXEC
74178 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
74179 +{
74180 + struct mm_struct *mm = vma->vm_mm;
74181 + struct vm_area_struct *vma_m;
74182 + unsigned long address_m;
74183 + pte_t *ptep_m;
74184 +
74185 + vma_m = pax_find_mirror_vma(vma);
74186 + if (!vma_m)
74187 + return;
74188 +
74189 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74190 + address_m = address + SEGMEXEC_TASK_SIZE;
74191 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
74192 + get_page(page_m);
74193 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
74194 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
74195 +}
74196 +#endif
74197 +
74198 /*
74199 * Hugetlb_cow() should be called with page lock of the original hugepage held.
74200 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
74201 @@ -2627,6 +2648,11 @@ retry_avoidcopy:
74202 make_huge_pte(vma, new_page, 1));
74203 page_remove_rmap(old_page);
74204 hugepage_add_new_anon_rmap(new_page, vma, address);
74205 +
74206 +#ifdef CONFIG_PAX_SEGMEXEC
74207 + pax_mirror_huge_pte(vma, address, new_page);
74208 +#endif
74209 +
74210 /* Make the old page be freed below */
74211 new_page = old_page;
74212 }
74213 @@ -2786,6 +2812,10 @@ retry:
74214 && (vma->vm_flags & VM_SHARED)));
74215 set_huge_pte_at(mm, address, ptep, new_pte);
74216
74217 +#ifdef CONFIG_PAX_SEGMEXEC
74218 + pax_mirror_huge_pte(vma, address, page);
74219 +#endif
74220 +
74221 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
74222 /* Optimization, do the COW without a second fault */
74223 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
74224 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74225 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
74226 struct hstate *h = hstate_vma(vma);
74227
74228 +#ifdef CONFIG_PAX_SEGMEXEC
74229 + struct vm_area_struct *vma_m;
74230 +#endif
74231 +
74232 address &= huge_page_mask(h);
74233
74234 ptep = huge_pte_offset(mm, address);
74235 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74236 VM_FAULT_SET_HINDEX(hstate_index(h));
74237 }
74238
74239 +#ifdef CONFIG_PAX_SEGMEXEC
74240 + vma_m = pax_find_mirror_vma(vma);
74241 + if (vma_m) {
74242 + unsigned long address_m;
74243 +
74244 + if (vma->vm_start > vma_m->vm_start) {
74245 + address_m = address;
74246 + address -= SEGMEXEC_TASK_SIZE;
74247 + vma = vma_m;
74248 + h = hstate_vma(vma);
74249 + } else
74250 + address_m = address + SEGMEXEC_TASK_SIZE;
74251 +
74252 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
74253 + return VM_FAULT_OOM;
74254 + address_m &= HPAGE_MASK;
74255 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
74256 + }
74257 +#endif
74258 +
74259 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
74260 if (!ptep)
74261 return VM_FAULT_OOM;
74262 @@ -3028,6 +3082,7 @@ void hugetlb_change_protection(struct vm_area_struct *vma,
74263 if (!huge_pte_none(huge_ptep_get(ptep))) {
74264 pte = huge_ptep_get_and_clear(mm, address, ptep);
74265 pte = pte_mkhuge(pte_modify(pte, newprot));
74266 + pte = arch_make_huge_pte(pte, vma, NULL, 0);
74267 set_huge_pte_at(mm, address, ptep, pte);
74268 }
74269 }
74270 diff --git a/mm/internal.h b/mm/internal.h
74271 index 3c5197d..08d0065 100644
74272 --- a/mm/internal.h
74273 +++ b/mm/internal.h
74274 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
74275 * in mm/page_alloc.c
74276 */
74277 extern void __free_pages_bootmem(struct page *page, unsigned int order);
74278 +extern void free_compound_page(struct page *page);
74279 extern void prep_compound_page(struct page *page, unsigned long order);
74280 #ifdef CONFIG_MEMORY_FAILURE
74281 extern bool is_free_buddy_page(struct page *page);
74282 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
74283 index a217cc5..44b2b35 100644
74284 --- a/mm/kmemleak.c
74285 +++ b/mm/kmemleak.c
74286 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
74287
74288 for (i = 0; i < object->trace_len; i++) {
74289 void *ptr = (void *)object->trace[i];
74290 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
74291 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
74292 }
74293 }
74294
74295 @@ -1852,7 +1852,7 @@ static int __init kmemleak_late_init(void)
74296 return -ENOMEM;
74297 }
74298
74299 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
74300 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
74301 &kmemleak_fops);
74302 if (!dentry)
74303 pr_warning("Failed to create the debugfs kmemleak file\n");
74304 diff --git a/mm/maccess.c b/mm/maccess.c
74305 index d53adf9..03a24bf 100644
74306 --- a/mm/maccess.c
74307 +++ b/mm/maccess.c
74308 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
74309 set_fs(KERNEL_DS);
74310 pagefault_disable();
74311 ret = __copy_from_user_inatomic(dst,
74312 - (__force const void __user *)src, size);
74313 + (const void __force_user *)src, size);
74314 pagefault_enable();
74315 set_fs(old_fs);
74316
74317 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
74318
74319 set_fs(KERNEL_DS);
74320 pagefault_disable();
74321 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
74322 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
74323 pagefault_enable();
74324 set_fs(old_fs);
74325
74326 diff --git a/mm/madvise.c b/mm/madvise.c
74327 index 03dfa5c..b032917 100644
74328 --- a/mm/madvise.c
74329 +++ b/mm/madvise.c
74330 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
74331 pgoff_t pgoff;
74332 unsigned long new_flags = vma->vm_flags;
74333
74334 +#ifdef CONFIG_PAX_SEGMEXEC
74335 + struct vm_area_struct *vma_m;
74336 +#endif
74337 +
74338 switch (behavior) {
74339 case MADV_NORMAL:
74340 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
74341 @@ -123,6 +127,13 @@ success:
74342 /*
74343 * vm_flags is protected by the mmap_sem held in write mode.
74344 */
74345 +
74346 +#ifdef CONFIG_PAX_SEGMEXEC
74347 + vma_m = pax_find_mirror_vma(vma);
74348 + if (vma_m)
74349 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74350 +#endif
74351 +
74352 vma->vm_flags = new_flags;
74353
74354 out:
74355 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74356 struct vm_area_struct ** prev,
74357 unsigned long start, unsigned long end)
74358 {
74359 +
74360 +#ifdef CONFIG_PAX_SEGMEXEC
74361 + struct vm_area_struct *vma_m;
74362 +#endif
74363 +
74364 *prev = vma;
74365 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74366 return -EINVAL;
74367 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74368 zap_page_range(vma, start, end - start, &details);
74369 } else
74370 zap_page_range(vma, start, end - start, NULL);
74371 +
74372 +#ifdef CONFIG_PAX_SEGMEXEC
74373 + vma_m = pax_find_mirror_vma(vma);
74374 + if (vma_m) {
74375 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74376 + struct zap_details details = {
74377 + .nonlinear_vma = vma_m,
74378 + .last_index = ULONG_MAX,
74379 + };
74380 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74381 + } else
74382 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74383 + }
74384 +#endif
74385 +
74386 return 0;
74387 }
74388
74389 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74390 if (end < start)
74391 goto out;
74392
74393 +#ifdef CONFIG_PAX_SEGMEXEC
74394 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74395 + if (end > SEGMEXEC_TASK_SIZE)
74396 + goto out;
74397 + } else
74398 +#endif
74399 +
74400 + if (end > TASK_SIZE)
74401 + goto out;
74402 +
74403 error = 0;
74404 if (end == start)
74405 goto out;
74406 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74407 index 8b20278..05dac18 100644
74408 --- a/mm/memory-failure.c
74409 +++ b/mm/memory-failure.c
74410 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74411
74412 int sysctl_memory_failure_recovery __read_mostly = 1;
74413
74414 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74415 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74416
74417 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74418
74419 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74420 pfn, t->comm, t->pid);
74421 si.si_signo = SIGBUS;
74422 si.si_errno = 0;
74423 - si.si_addr = (void *)addr;
74424 + si.si_addr = (void __user *)addr;
74425 #ifdef __ARCH_SI_TRAPNO
74426 si.si_trapno = trapno;
74427 #endif
74428 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74429 }
74430
74431 nr_pages = 1 << compound_trans_order(hpage);
74432 - atomic_long_add(nr_pages, &mce_bad_pages);
74433 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74434
74435 /*
74436 * We need/can do nothing about count=0 pages.
74437 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74438 if (!PageHWPoison(hpage)
74439 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74440 || (p != hpage && TestSetPageHWPoison(hpage))) {
74441 - atomic_long_sub(nr_pages, &mce_bad_pages);
74442 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74443 return 0;
74444 }
74445 set_page_hwpoison_huge_page(hpage);
74446 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74447 }
74448 if (hwpoison_filter(p)) {
74449 if (TestClearPageHWPoison(p))
74450 - atomic_long_sub(nr_pages, &mce_bad_pages);
74451 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74452 unlock_page(hpage);
74453 put_page(hpage);
74454 return 0;
74455 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74456 return 0;
74457 }
74458 if (TestClearPageHWPoison(p))
74459 - atomic_long_sub(nr_pages, &mce_bad_pages);
74460 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74461 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74462 return 0;
74463 }
74464 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74465 */
74466 if (TestClearPageHWPoison(page)) {
74467 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74468 - atomic_long_sub(nr_pages, &mce_bad_pages);
74469 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74470 freeit = 1;
74471 if (PageHuge(page))
74472 clear_page_hwpoison_huge_page(page);
74473 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74474 }
74475 done:
74476 if (!PageHWPoison(hpage))
74477 - atomic_long_add(1 << compound_trans_order(hpage),
74478 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74479 &mce_bad_pages);
74480 set_page_hwpoison_huge_page(hpage);
74481 dequeue_hwpoisoned_huge_page(hpage);
74482 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74483 return ret;
74484
74485 done:
74486 - atomic_long_add(1, &mce_bad_pages);
74487 + atomic_long_add_unchecked(1, &mce_bad_pages);
74488 SetPageHWPoison(page);
74489 /* keep elevated page count for bad page */
74490 return ret;
74491 diff --git a/mm/memory.c b/mm/memory.c
74492 index f2973b2..fd020a7 100644
74493 --- a/mm/memory.c
74494 +++ b/mm/memory.c
74495 @@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74496 free_pte_range(tlb, pmd, addr);
74497 } while (pmd++, addr = next, addr != end);
74498
74499 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74500 start &= PUD_MASK;
74501 if (start < floor)
74502 return;
74503 @@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74504 pmd = pmd_offset(pud, start);
74505 pud_clear(pud);
74506 pmd_free_tlb(tlb, pmd, start);
74507 +#endif
74508 +
74509 }
74510
74511 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74512 @@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74513 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74514 } while (pud++, addr = next, addr != end);
74515
74516 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74517 start &= PGDIR_MASK;
74518 if (start < floor)
74519 return;
74520 @@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74521 pud = pud_offset(pgd, start);
74522 pgd_clear(pgd);
74523 pud_free_tlb(tlb, pud, start);
74524 +#endif
74525 +
74526 }
74527
74528 /*
74529 @@ -1626,12 +1632,6 @@ no_page_table:
74530 return page;
74531 }
74532
74533 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74534 -{
74535 - return stack_guard_page_start(vma, addr) ||
74536 - stack_guard_page_end(vma, addr+PAGE_SIZE);
74537 -}
74538 -
74539 /**
74540 * __get_user_pages() - pin user pages in memory
74541 * @tsk: task_struct of target task
74542 @@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74543 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74544 i = 0;
74545
74546 - do {
74547 + while (nr_pages) {
74548 struct vm_area_struct *vma;
74549
74550 - vma = find_extend_vma(mm, start);
74551 + vma = find_vma(mm, start);
74552 if (!vma && in_gate_area(mm, start)) {
74553 unsigned long pg = start & PAGE_MASK;
74554 pgd_t *pgd;
74555 @@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74556 goto next_page;
74557 }
74558
74559 - if (!vma ||
74560 + if (!vma || start < vma->vm_start ||
74561 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74562 !(vm_flags & vma->vm_flags))
74563 return i ? : -EFAULT;
74564 @@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74565 int ret;
74566 unsigned int fault_flags = 0;
74567
74568 - /* For mlock, just skip the stack guard page. */
74569 - if (foll_flags & FOLL_MLOCK) {
74570 - if (stack_guard_page(vma, start))
74571 - goto next_page;
74572 - }
74573 if (foll_flags & FOLL_WRITE)
74574 fault_flags |= FAULT_FLAG_WRITE;
74575 if (nonblocking)
74576 @@ -1860,7 +1855,7 @@ next_page:
74577 start += PAGE_SIZE;
74578 nr_pages--;
74579 } while (nr_pages && start < vma->vm_end);
74580 - } while (nr_pages);
74581 + }
74582 return i;
74583 }
74584 EXPORT_SYMBOL(__get_user_pages);
74585 @@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74586 page_add_file_rmap(page);
74587 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74588
74589 +#ifdef CONFIG_PAX_SEGMEXEC
74590 + pax_mirror_file_pte(vma, addr, page, ptl);
74591 +#endif
74592 +
74593 retval = 0;
74594 pte_unmap_unlock(pte, ptl);
74595 return retval;
74596 @@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74597 if (!page_count(page))
74598 return -EINVAL;
74599 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74600 +
74601 +#ifdef CONFIG_PAX_SEGMEXEC
74602 + struct vm_area_struct *vma_m;
74603 +#endif
74604 +
74605 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74606 BUG_ON(vma->vm_flags & VM_PFNMAP);
74607 vma->vm_flags |= VM_MIXEDMAP;
74608 +
74609 +#ifdef CONFIG_PAX_SEGMEXEC
74610 + vma_m = pax_find_mirror_vma(vma);
74611 + if (vma_m)
74612 + vma_m->vm_flags |= VM_MIXEDMAP;
74613 +#endif
74614 +
74615 }
74616 return insert_page(vma, addr, page, vma->vm_page_prot);
74617 }
74618 @@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74619 unsigned long pfn)
74620 {
74621 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74622 + BUG_ON(vma->vm_mirror);
74623
74624 if (addr < vma->vm_start || addr >= vma->vm_end)
74625 return -EFAULT;
74626 @@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74627
74628 BUG_ON(pud_huge(*pud));
74629
74630 - pmd = pmd_alloc(mm, pud, addr);
74631 + pmd = (mm == &init_mm) ?
74632 + pmd_alloc_kernel(mm, pud, addr) :
74633 + pmd_alloc(mm, pud, addr);
74634 if (!pmd)
74635 return -ENOMEM;
74636 do {
74637 @@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74638 unsigned long next;
74639 int err;
74640
74641 - pud = pud_alloc(mm, pgd, addr);
74642 + pud = (mm == &init_mm) ?
74643 + pud_alloc_kernel(mm, pgd, addr) :
74644 + pud_alloc(mm, pgd, addr);
74645 if (!pud)
74646 return -ENOMEM;
74647 do {
74648 @@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74649 copy_user_highpage(dst, src, va, vma);
74650 }
74651
74652 +#ifdef CONFIG_PAX_SEGMEXEC
74653 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74654 +{
74655 + struct mm_struct *mm = vma->vm_mm;
74656 + spinlock_t *ptl;
74657 + pte_t *pte, entry;
74658 +
74659 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74660 + entry = *pte;
74661 + if (!pte_present(entry)) {
74662 + if (!pte_none(entry)) {
74663 + BUG_ON(pte_file(entry));
74664 + free_swap_and_cache(pte_to_swp_entry(entry));
74665 + pte_clear_not_present_full(mm, address, pte, 0);
74666 + }
74667 + } else {
74668 + struct page *page;
74669 +
74670 + flush_cache_page(vma, address, pte_pfn(entry));
74671 + entry = ptep_clear_flush(vma, address, pte);
74672 + BUG_ON(pte_dirty(entry));
74673 + page = vm_normal_page(vma, address, entry);
74674 + if (page) {
74675 + update_hiwater_rss(mm);
74676 + if (PageAnon(page))
74677 + dec_mm_counter_fast(mm, MM_ANONPAGES);
74678 + else
74679 + dec_mm_counter_fast(mm, MM_FILEPAGES);
74680 + page_remove_rmap(page);
74681 + page_cache_release(page);
74682 + }
74683 + }
74684 + pte_unmap_unlock(pte, ptl);
74685 +}
74686 +
74687 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
74688 + *
74689 + * the ptl of the lower mapped page is held on entry and is not released on exit
74690 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74691 + */
74692 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74693 +{
74694 + struct mm_struct *mm = vma->vm_mm;
74695 + unsigned long address_m;
74696 + spinlock_t *ptl_m;
74697 + struct vm_area_struct *vma_m;
74698 + pmd_t *pmd_m;
74699 + pte_t *pte_m, entry_m;
74700 +
74701 + BUG_ON(!page_m || !PageAnon(page_m));
74702 +
74703 + vma_m = pax_find_mirror_vma(vma);
74704 + if (!vma_m)
74705 + return;
74706 +
74707 + BUG_ON(!PageLocked(page_m));
74708 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74709 + address_m = address + SEGMEXEC_TASK_SIZE;
74710 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74711 + pte_m = pte_offset_map(pmd_m, address_m);
74712 + ptl_m = pte_lockptr(mm, pmd_m);
74713 + if (ptl != ptl_m) {
74714 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74715 + if (!pte_none(*pte_m))
74716 + goto out;
74717 + }
74718 +
74719 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74720 + page_cache_get(page_m);
74721 + page_add_anon_rmap(page_m, vma_m, address_m);
74722 + inc_mm_counter_fast(mm, MM_ANONPAGES);
74723 + set_pte_at(mm, address_m, pte_m, entry_m);
74724 + update_mmu_cache(vma_m, address_m, entry_m);
74725 +out:
74726 + if (ptl != ptl_m)
74727 + spin_unlock(ptl_m);
74728 + pte_unmap(pte_m);
74729 + unlock_page(page_m);
74730 +}
74731 +
74732 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74733 +{
74734 + struct mm_struct *mm = vma->vm_mm;
74735 + unsigned long address_m;
74736 + spinlock_t *ptl_m;
74737 + struct vm_area_struct *vma_m;
74738 + pmd_t *pmd_m;
74739 + pte_t *pte_m, entry_m;
74740 +
74741 + BUG_ON(!page_m || PageAnon(page_m));
74742 +
74743 + vma_m = pax_find_mirror_vma(vma);
74744 + if (!vma_m)
74745 + return;
74746 +
74747 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74748 + address_m = address + SEGMEXEC_TASK_SIZE;
74749 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74750 + pte_m = pte_offset_map(pmd_m, address_m);
74751 + ptl_m = pte_lockptr(mm, pmd_m);
74752 + if (ptl != ptl_m) {
74753 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74754 + if (!pte_none(*pte_m))
74755 + goto out;
74756 + }
74757 +
74758 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74759 + page_cache_get(page_m);
74760 + page_add_file_rmap(page_m);
74761 + inc_mm_counter_fast(mm, MM_FILEPAGES);
74762 + set_pte_at(mm, address_m, pte_m, entry_m);
74763 + update_mmu_cache(vma_m, address_m, entry_m);
74764 +out:
74765 + if (ptl != ptl_m)
74766 + spin_unlock(ptl_m);
74767 + pte_unmap(pte_m);
74768 +}
74769 +
74770 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74771 +{
74772 + struct mm_struct *mm = vma->vm_mm;
74773 + unsigned long address_m;
74774 + spinlock_t *ptl_m;
74775 + struct vm_area_struct *vma_m;
74776 + pmd_t *pmd_m;
74777 + pte_t *pte_m, entry_m;
74778 +
74779 + vma_m = pax_find_mirror_vma(vma);
74780 + if (!vma_m)
74781 + return;
74782 +
74783 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74784 + address_m = address + SEGMEXEC_TASK_SIZE;
74785 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74786 + pte_m = pte_offset_map(pmd_m, address_m);
74787 + ptl_m = pte_lockptr(mm, pmd_m);
74788 + if (ptl != ptl_m) {
74789 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74790 + if (!pte_none(*pte_m))
74791 + goto out;
74792 + }
74793 +
74794 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74795 + set_pte_at(mm, address_m, pte_m, entry_m);
74796 +out:
74797 + if (ptl != ptl_m)
74798 + spin_unlock(ptl_m);
74799 + pte_unmap(pte_m);
74800 +}
74801 +
74802 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74803 +{
74804 + struct page *page_m;
74805 + pte_t entry;
74806 +
74807 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74808 + goto out;
74809 +
74810 + entry = *pte;
74811 + page_m = vm_normal_page(vma, address, entry);
74812 + if (!page_m)
74813 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74814 + else if (PageAnon(page_m)) {
74815 + if (pax_find_mirror_vma(vma)) {
74816 + pte_unmap_unlock(pte, ptl);
74817 + lock_page(page_m);
74818 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74819 + if (pte_same(entry, *pte))
74820 + pax_mirror_anon_pte(vma, address, page_m, ptl);
74821 + else
74822 + unlock_page(page_m);
74823 + }
74824 + } else
74825 + pax_mirror_file_pte(vma, address, page_m, ptl);
74826 +
74827 +out:
74828 + pte_unmap_unlock(pte, ptl);
74829 +}
74830 +#endif
74831 +
74832 /*
74833 * This routine handles present pages, when users try to write
74834 * to a shared page. It is done by copying the page to a new address
74835 @@ -2720,6 +2916,12 @@ gotten:
74836 */
74837 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74838 if (likely(pte_same(*page_table, orig_pte))) {
74839 +
74840 +#ifdef CONFIG_PAX_SEGMEXEC
74841 + if (pax_find_mirror_vma(vma))
74842 + BUG_ON(!trylock_page(new_page));
74843 +#endif
74844 +
74845 if (old_page) {
74846 if (!PageAnon(old_page)) {
74847 dec_mm_counter_fast(mm, MM_FILEPAGES);
74848 @@ -2771,6 +2973,10 @@ gotten:
74849 page_remove_rmap(old_page);
74850 }
74851
74852 +#ifdef CONFIG_PAX_SEGMEXEC
74853 + pax_mirror_anon_pte(vma, address, new_page, ptl);
74854 +#endif
74855 +
74856 /* Free the old page.. */
74857 new_page = old_page;
74858 ret |= VM_FAULT_WRITE;
74859 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74860 swap_free(entry);
74861 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74862 try_to_free_swap(page);
74863 +
74864 +#ifdef CONFIG_PAX_SEGMEXEC
74865 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74866 +#endif
74867 +
74868 unlock_page(page);
74869 if (swapcache) {
74870 /*
74871 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74872
74873 /* No need to invalidate - it was non-present before */
74874 update_mmu_cache(vma, address, page_table);
74875 +
74876 +#ifdef CONFIG_PAX_SEGMEXEC
74877 + pax_mirror_anon_pte(vma, address, page, ptl);
74878 +#endif
74879 +
74880 unlock:
74881 pte_unmap_unlock(page_table, ptl);
74882 out:
74883 @@ -3093,40 +3309,6 @@ out_release:
74884 }
74885
74886 /*
74887 - * This is like a special single-page "expand_{down|up}wards()",
74888 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
74889 - * doesn't hit another vma.
74890 - */
74891 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74892 -{
74893 - address &= PAGE_MASK;
74894 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74895 - struct vm_area_struct *prev = vma->vm_prev;
74896 -
74897 - /*
74898 - * Is there a mapping abutting this one below?
74899 - *
74900 - * That's only ok if it's the same stack mapping
74901 - * that has gotten split..
74902 - */
74903 - if (prev && prev->vm_end == address)
74904 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74905 -
74906 - expand_downwards(vma, address - PAGE_SIZE);
74907 - }
74908 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74909 - struct vm_area_struct *next = vma->vm_next;
74910 -
74911 - /* As VM_GROWSDOWN but s/below/above/ */
74912 - if (next && next->vm_start == address + PAGE_SIZE)
74913 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74914 -
74915 - expand_upwards(vma, address + PAGE_SIZE);
74916 - }
74917 - return 0;
74918 -}
74919 -
74920 -/*
74921 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74922 * but allow concurrent faults), and pte mapped but not yet locked.
74923 * We return with mmap_sem still held, but pte unmapped and unlocked.
74924 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74925 unsigned long address, pte_t *page_table, pmd_t *pmd,
74926 unsigned int flags)
74927 {
74928 - struct page *page;
74929 + struct page *page = NULL;
74930 spinlock_t *ptl;
74931 pte_t entry;
74932
74933 - pte_unmap(page_table);
74934 -
74935 - /* Check if we need to add a guard page to the stack */
74936 - if (check_stack_guard_page(vma, address) < 0)
74937 - return VM_FAULT_SIGBUS;
74938 -
74939 - /* Use the zero-page for reads */
74940 if (!(flags & FAULT_FLAG_WRITE)) {
74941 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
74942 vma->vm_page_prot));
74943 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74944 + ptl = pte_lockptr(mm, pmd);
74945 + spin_lock(ptl);
74946 if (!pte_none(*page_table))
74947 goto unlock;
74948 goto setpte;
74949 }
74950
74951 /* Allocate our own private page. */
74952 + pte_unmap(page_table);
74953 +
74954 if (unlikely(anon_vma_prepare(vma)))
74955 goto oom;
74956 page = alloc_zeroed_user_highpage_movable(vma, address);
74957 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74958 if (!pte_none(*page_table))
74959 goto release;
74960
74961 +#ifdef CONFIG_PAX_SEGMEXEC
74962 + if (pax_find_mirror_vma(vma))
74963 + BUG_ON(!trylock_page(page));
74964 +#endif
74965 +
74966 inc_mm_counter_fast(mm, MM_ANONPAGES);
74967 page_add_new_anon_rmap(page, vma, address);
74968 setpte:
74969 @@ -3181,6 +3364,12 @@ setpte:
74970
74971 /* No need to invalidate - it was non-present before */
74972 update_mmu_cache(vma, address, page_table);
74973 +
74974 +#ifdef CONFIG_PAX_SEGMEXEC
74975 + if (page)
74976 + pax_mirror_anon_pte(vma, address, page, ptl);
74977 +#endif
74978 +
74979 unlock:
74980 pte_unmap_unlock(page_table, ptl);
74981 return 0;
74982 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74983 */
74984 /* Only go through if we didn't race with anybody else... */
74985 if (likely(pte_same(*page_table, orig_pte))) {
74986 +
74987 +#ifdef CONFIG_PAX_SEGMEXEC
74988 + if (anon && pax_find_mirror_vma(vma))
74989 + BUG_ON(!trylock_page(page));
74990 +#endif
74991 +
74992 flush_icache_page(vma, page);
74993 entry = mk_pte(page, vma->vm_page_prot);
74994 if (flags & FAULT_FLAG_WRITE)
74995 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74996
74997 /* no need to invalidate: a not-present page won't be cached */
74998 update_mmu_cache(vma, address, page_table);
74999 +
75000 +#ifdef CONFIG_PAX_SEGMEXEC
75001 + if (anon)
75002 + pax_mirror_anon_pte(vma, address, page, ptl);
75003 + else
75004 + pax_mirror_file_pte(vma, address, page, ptl);
75005 +#endif
75006 +
75007 } else {
75008 if (cow_page)
75009 mem_cgroup_uncharge_page(cow_page);
75010 @@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
75011 if (flags & FAULT_FLAG_WRITE)
75012 flush_tlb_fix_spurious_fault(vma, address);
75013 }
75014 +
75015 +#ifdef CONFIG_PAX_SEGMEXEC
75016 + pax_mirror_pte(vma, address, pte, pmd, ptl);
75017 + return 0;
75018 +#endif
75019 +
75020 unlock:
75021 pte_unmap_unlock(pte, ptl);
75022 return 0;
75023 @@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75024 pmd_t *pmd;
75025 pte_t *pte;
75026
75027 +#ifdef CONFIG_PAX_SEGMEXEC
75028 + struct vm_area_struct *vma_m;
75029 +#endif
75030 +
75031 __set_current_state(TASK_RUNNING);
75032
75033 count_vm_event(PGFAULT);
75034 @@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75035 if (unlikely(is_vm_hugetlb_page(vma)))
75036 return hugetlb_fault(mm, vma, address, flags);
75037
75038 +#ifdef CONFIG_PAX_SEGMEXEC
75039 + vma_m = pax_find_mirror_vma(vma);
75040 + if (vma_m) {
75041 + unsigned long address_m;
75042 + pgd_t *pgd_m;
75043 + pud_t *pud_m;
75044 + pmd_t *pmd_m;
75045 +
75046 + if (vma->vm_start > vma_m->vm_start) {
75047 + address_m = address;
75048 + address -= SEGMEXEC_TASK_SIZE;
75049 + vma = vma_m;
75050 + } else
75051 + address_m = address + SEGMEXEC_TASK_SIZE;
75052 +
75053 + pgd_m = pgd_offset(mm, address_m);
75054 + pud_m = pud_alloc(mm, pgd_m, address_m);
75055 + if (!pud_m)
75056 + return VM_FAULT_OOM;
75057 + pmd_m = pmd_alloc(mm, pud_m, address_m);
75058 + if (!pmd_m)
75059 + return VM_FAULT_OOM;
75060 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
75061 + return VM_FAULT_OOM;
75062 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
75063 + }
75064 +#endif
75065 +
75066 retry:
75067 pgd = pgd_offset(mm, address);
75068 pud = pud_alloc(mm, pgd, address);
75069 @@ -3565,7 +3806,7 @@ retry:
75070 * run pte_offset_map on the pmd, if an huge pmd could
75071 * materialize from under us from a different thread.
75072 */
75073 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
75074 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
75075 return VM_FAULT_OOM;
75076 /* if an huge pmd materialized from under us just retry later */
75077 if (unlikely(pmd_trans_huge(*pmd)))
75078 @@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75079 spin_unlock(&mm->page_table_lock);
75080 return 0;
75081 }
75082 +
75083 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75084 +{
75085 + pud_t *new = pud_alloc_one(mm, address);
75086 + if (!new)
75087 + return -ENOMEM;
75088 +
75089 + smp_wmb(); /* See comment in __pte_alloc */
75090 +
75091 + spin_lock(&mm->page_table_lock);
75092 + if (pgd_present(*pgd)) /* Another has populated it */
75093 + pud_free(mm, new);
75094 + else
75095 + pgd_populate_kernel(mm, pgd, new);
75096 + spin_unlock(&mm->page_table_lock);
75097 + return 0;
75098 +}
75099 #endif /* __PAGETABLE_PUD_FOLDED */
75100
75101 #ifndef __PAGETABLE_PMD_FOLDED
75102 @@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75103 spin_unlock(&mm->page_table_lock);
75104 return 0;
75105 }
75106 +
75107 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75108 +{
75109 + pmd_t *new = pmd_alloc_one(mm, address);
75110 + if (!new)
75111 + return -ENOMEM;
75112 +
75113 + smp_wmb(); /* See comment in __pte_alloc */
75114 +
75115 + spin_lock(&mm->page_table_lock);
75116 +#ifndef __ARCH_HAS_4LEVEL_HACK
75117 + if (pud_present(*pud)) /* Another has populated it */
75118 + pmd_free(mm, new);
75119 + else
75120 + pud_populate_kernel(mm, pud, new);
75121 +#else
75122 + if (pgd_present(*pud)) /* Another has populated it */
75123 + pmd_free(mm, new);
75124 + else
75125 + pgd_populate_kernel(mm, pud, new);
75126 +#endif /* __ARCH_HAS_4LEVEL_HACK */
75127 + spin_unlock(&mm->page_table_lock);
75128 + return 0;
75129 +}
75130 #endif /* __PAGETABLE_PMD_FOLDED */
75131
75132 int make_pages_present(unsigned long addr, unsigned long end)
75133 @@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
75134 gate_vma.vm_start = FIXADDR_USER_START;
75135 gate_vma.vm_end = FIXADDR_USER_END;
75136 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
75137 - gate_vma.vm_page_prot = __P101;
75138 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
75139
75140 return 0;
75141 }
75142 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
75143 index 002c281..9429765 100644
75144 --- a/mm/mempolicy.c
75145 +++ b/mm/mempolicy.c
75146 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75147 unsigned long vmstart;
75148 unsigned long vmend;
75149
75150 +#ifdef CONFIG_PAX_SEGMEXEC
75151 + struct vm_area_struct *vma_m;
75152 +#endif
75153 +
75154 vma = find_vma(mm, start);
75155 if (!vma || vma->vm_start > start)
75156 return -EFAULT;
75157 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75158 if (err)
75159 goto out;
75160 }
75161 +
75162 err = vma_replace_policy(vma, new_pol);
75163 if (err)
75164 goto out;
75165 +
75166 +#ifdef CONFIG_PAX_SEGMEXEC
75167 + vma_m = pax_find_mirror_vma(vma);
75168 + if (vma_m) {
75169 + err = vma_replace_policy(vma_m, new_pol);
75170 + if (err)
75171 + goto out;
75172 + }
75173 +#endif
75174 +
75175 }
75176
75177 out:
75178 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
75179
75180 if (end < start)
75181 return -EINVAL;
75182 +
75183 +#ifdef CONFIG_PAX_SEGMEXEC
75184 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75185 + if (end > SEGMEXEC_TASK_SIZE)
75186 + return -EINVAL;
75187 + } else
75188 +#endif
75189 +
75190 + if (end > TASK_SIZE)
75191 + return -EINVAL;
75192 +
75193 if (end == start)
75194 return 0;
75195
75196 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75197 */
75198 tcred = __task_cred(task);
75199 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75200 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75201 - !capable(CAP_SYS_NICE)) {
75202 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75203 rcu_read_unlock();
75204 err = -EPERM;
75205 goto out_put;
75206 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75207 goto out;
75208 }
75209
75210 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
75211 + if (mm != current->mm &&
75212 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
75213 + mmput(mm);
75214 + err = -EPERM;
75215 + goto out;
75216 + }
75217 +#endif
75218 +
75219 err = do_migrate_pages(mm, old, new,
75220 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
75221
75222 diff --git a/mm/migrate.c b/mm/migrate.c
75223 index 77ed2d7..d7adff2 100644
75224 --- a/mm/migrate.c
75225 +++ b/mm/migrate.c
75226 @@ -143,8 +143,10 @@ static int remove_migration_pte(struct page *new, struct vm_area_struct *vma,
75227 if (is_write_migration_entry(entry))
75228 pte = pte_mkwrite(pte);
75229 #ifdef CONFIG_HUGETLB_PAGE
75230 - if (PageHuge(new))
75231 + if (PageHuge(new)) {
75232 pte = pte_mkhuge(pte);
75233 + pte = arch_make_huge_pte(pte, vma, new, 0);
75234 + }
75235 #endif
75236 flush_cache_page(vma, addr, pte_pfn(pte));
75237 set_pte_at(mm, addr, ptep, pte);
75238 @@ -1350,8 +1352,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
75239 */
75240 tcred = __task_cred(task);
75241 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75242 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75243 - !capable(CAP_SYS_NICE)) {
75244 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75245 rcu_read_unlock();
75246 err = -EPERM;
75247 goto out;
75248 diff --git a/mm/mlock.c b/mm/mlock.c
75249 index f0b9ce5..da8d069 100644
75250 --- a/mm/mlock.c
75251 +++ b/mm/mlock.c
75252 @@ -13,6 +13,7 @@
75253 #include <linux/pagemap.h>
75254 #include <linux/mempolicy.h>
75255 #include <linux/syscalls.h>
75256 +#include <linux/security.h>
75257 #include <linux/sched.h>
75258 #include <linux/export.h>
75259 #include <linux/rmap.h>
75260 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
75261 {
75262 unsigned long nstart, end, tmp;
75263 struct vm_area_struct * vma, * prev;
75264 - int error;
75265 + int error = 0;
75266
75267 VM_BUG_ON(start & ~PAGE_MASK);
75268 VM_BUG_ON(len != PAGE_ALIGN(len));
75269 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
75270 return -EINVAL;
75271 if (end == start)
75272 return 0;
75273 + if (end > TASK_SIZE)
75274 + return -EINVAL;
75275 +
75276 vma = find_vma(current->mm, start);
75277 if (!vma || vma->vm_start > start)
75278 return -ENOMEM;
75279 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
75280 for (nstart = start ; ; ) {
75281 vm_flags_t newflags;
75282
75283 +#ifdef CONFIG_PAX_SEGMEXEC
75284 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75285 + break;
75286 +#endif
75287 +
75288 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
75289
75290 newflags = vma->vm_flags | VM_LOCKED;
75291 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
75292 lock_limit >>= PAGE_SHIFT;
75293
75294 /* check against resource limits */
75295 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
75296 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
75297 error = do_mlock(start, len, 1);
75298 up_write(&current->mm->mmap_sem);
75299 @@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
75300 static int do_mlockall(int flags)
75301 {
75302 struct vm_area_struct * vma, * prev = NULL;
75303 - unsigned int def_flags = 0;
75304
75305 if (flags & MCL_FUTURE)
75306 - def_flags = VM_LOCKED;
75307 - current->mm->def_flags = def_flags;
75308 + current->mm->def_flags |= VM_LOCKED;
75309 + else
75310 + current->mm->def_flags &= ~VM_LOCKED;
75311 if (flags == MCL_FUTURE)
75312 goto out;
75313
75314 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
75315 vm_flags_t newflags;
75316
75317 +#ifdef CONFIG_PAX_SEGMEXEC
75318 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75319 + break;
75320 +#endif
75321 +
75322 + BUG_ON(vma->vm_end > TASK_SIZE);
75323 newflags = vma->vm_flags | VM_LOCKED;
75324 if (!(flags & MCL_CURRENT))
75325 newflags &= ~VM_LOCKED;
75326 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
75327 lock_limit >>= PAGE_SHIFT;
75328
75329 ret = -ENOMEM;
75330 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
75331 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
75332 capable(CAP_IPC_LOCK))
75333 ret = do_mlockall(flags);
75334 diff --git a/mm/mmap.c b/mm/mmap.c
75335 index 9a796c4..e2c9724 100644
75336 --- a/mm/mmap.c
75337 +++ b/mm/mmap.c
75338 @@ -31,6 +31,7 @@
75339 #include <linux/audit.h>
75340 #include <linux/khugepaged.h>
75341 #include <linux/uprobes.h>
75342 +#include <linux/random.h>
75343
75344 #include <asm/uaccess.h>
75345 #include <asm/cacheflush.h>
75346 @@ -47,6 +48,16 @@
75347 #define arch_rebalance_pgtables(addr, len) (addr)
75348 #endif
75349
75350 +static inline void verify_mm_writelocked(struct mm_struct *mm)
75351 +{
75352 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
75353 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75354 + up_read(&mm->mmap_sem);
75355 + BUG();
75356 + }
75357 +#endif
75358 +}
75359 +
75360 static void unmap_region(struct mm_struct *mm,
75361 struct vm_area_struct *vma, struct vm_area_struct *prev,
75362 unsigned long start, unsigned long end);
75363 @@ -66,22 +77,32 @@ static void unmap_region(struct mm_struct *mm,
75364 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75365 *
75366 */
75367 -pgprot_t protection_map[16] = {
75368 +pgprot_t protection_map[16] __read_only = {
75369 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75370 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75371 };
75372
75373 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
75374 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75375 {
75376 - return __pgprot(pgprot_val(protection_map[vm_flags &
75377 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75378 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75379 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75380 +
75381 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75382 + if (!(__supported_pte_mask & _PAGE_NX) &&
75383 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75384 + (vm_flags & (VM_READ | VM_WRITE)))
75385 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75386 +#endif
75387 +
75388 + return prot;
75389 }
75390 EXPORT_SYMBOL(vm_get_page_prot);
75391
75392 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75393 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75394 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75395 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75396 /*
75397 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75398 * other variables. It can be updated by several CPUs frequently.
75399 @@ -223,6 +244,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75400 struct vm_area_struct *next = vma->vm_next;
75401
75402 might_sleep();
75403 + BUG_ON(vma->vm_mirror);
75404 if (vma->vm_ops && vma->vm_ops->close)
75405 vma->vm_ops->close(vma);
75406 if (vma->vm_file)
75407 @@ -266,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75408 * not page aligned -Ram Gupta
75409 */
75410 rlim = rlimit(RLIMIT_DATA);
75411 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75412 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75413 (mm->end_data - mm->start_data) > rlim)
75414 goto out;
75415 @@ -736,6 +759,12 @@ static int
75416 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75417 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75418 {
75419 +
75420 +#ifdef CONFIG_PAX_SEGMEXEC
75421 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75422 + return 0;
75423 +#endif
75424 +
75425 if (is_mergeable_vma(vma, file, vm_flags) &&
75426 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75427 if (vma->vm_pgoff == vm_pgoff)
75428 @@ -755,6 +784,12 @@ static int
75429 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75430 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75431 {
75432 +
75433 +#ifdef CONFIG_PAX_SEGMEXEC
75434 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75435 + return 0;
75436 +#endif
75437 +
75438 if (is_mergeable_vma(vma, file, vm_flags) &&
75439 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75440 pgoff_t vm_pglen;
75441 @@ -797,13 +832,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75442 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75443 struct vm_area_struct *prev, unsigned long addr,
75444 unsigned long end, unsigned long vm_flags,
75445 - struct anon_vma *anon_vma, struct file *file,
75446 + struct anon_vma *anon_vma, struct file *file,
75447 pgoff_t pgoff, struct mempolicy *policy)
75448 {
75449 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75450 struct vm_area_struct *area, *next;
75451 int err;
75452
75453 +#ifdef CONFIG_PAX_SEGMEXEC
75454 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75455 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75456 +
75457 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75458 +#endif
75459 +
75460 /*
75461 * We later require that vma->vm_flags == vm_flags,
75462 * so this tests vma->vm_flags & VM_SPECIAL, too.
75463 @@ -819,6 +861,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75464 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75465 next = next->vm_next;
75466
75467 +#ifdef CONFIG_PAX_SEGMEXEC
75468 + if (prev)
75469 + prev_m = pax_find_mirror_vma(prev);
75470 + if (area)
75471 + area_m = pax_find_mirror_vma(area);
75472 + if (next)
75473 + next_m = pax_find_mirror_vma(next);
75474 +#endif
75475 +
75476 /*
75477 * Can it merge with the predecessor?
75478 */
75479 @@ -838,9 +889,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75480 /* cases 1, 6 */
75481 err = vma_adjust(prev, prev->vm_start,
75482 next->vm_end, prev->vm_pgoff, NULL);
75483 - } else /* cases 2, 5, 7 */
75484 +
75485 +#ifdef CONFIG_PAX_SEGMEXEC
75486 + if (!err && prev_m)
75487 + err = vma_adjust(prev_m, prev_m->vm_start,
75488 + next_m->vm_end, prev_m->vm_pgoff, NULL);
75489 +#endif
75490 +
75491 + } else { /* cases 2, 5, 7 */
75492 err = vma_adjust(prev, prev->vm_start,
75493 end, prev->vm_pgoff, NULL);
75494 +
75495 +#ifdef CONFIG_PAX_SEGMEXEC
75496 + if (!err && prev_m)
75497 + err = vma_adjust(prev_m, prev_m->vm_start,
75498 + end_m, prev_m->vm_pgoff, NULL);
75499 +#endif
75500 +
75501 + }
75502 if (err)
75503 return NULL;
75504 khugepaged_enter_vma_merge(prev);
75505 @@ -854,12 +920,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75506 mpol_equal(policy, vma_policy(next)) &&
75507 can_vma_merge_before(next, vm_flags,
75508 anon_vma, file, pgoff+pglen)) {
75509 - if (prev && addr < prev->vm_end) /* case 4 */
75510 + if (prev && addr < prev->vm_end) { /* case 4 */
75511 err = vma_adjust(prev, prev->vm_start,
75512 addr, prev->vm_pgoff, NULL);
75513 - else /* cases 3, 8 */
75514 +
75515 +#ifdef CONFIG_PAX_SEGMEXEC
75516 + if (!err && prev_m)
75517 + err = vma_adjust(prev_m, prev_m->vm_start,
75518 + addr_m, prev_m->vm_pgoff, NULL);
75519 +#endif
75520 +
75521 + } else { /* cases 3, 8 */
75522 err = vma_adjust(area, addr, next->vm_end,
75523 next->vm_pgoff - pglen, NULL);
75524 +
75525 +#ifdef CONFIG_PAX_SEGMEXEC
75526 + if (!err && area_m)
75527 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
75528 + next_m->vm_pgoff - pglen, NULL);
75529 +#endif
75530 +
75531 + }
75532 if (err)
75533 return NULL;
75534 khugepaged_enter_vma_merge(area);
75535 @@ -968,16 +1049,13 @@ none:
75536 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75537 struct file *file, long pages)
75538 {
75539 - const unsigned long stack_flags
75540 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75541 -
75542 mm->total_vm += pages;
75543
75544 if (file) {
75545 mm->shared_vm += pages;
75546 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75547 mm->exec_vm += pages;
75548 - } else if (flags & stack_flags)
75549 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75550 mm->stack_vm += pages;
75551 }
75552 #endif /* CONFIG_PROC_FS */
75553 @@ -1013,7 +1091,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75554 * (the exception is when the underlying filesystem is noexec
75555 * mounted, in which case we dont add PROT_EXEC.)
75556 */
75557 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75558 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75559 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75560 prot |= PROT_EXEC;
75561
75562 @@ -1039,7 +1117,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75563 /* Obtain the address to map to. we verify (or select) it and ensure
75564 * that it represents a valid section of the address space.
75565 */
75566 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
75567 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75568 if (addr & ~PAGE_MASK)
75569 return addr;
75570
75571 @@ -1050,6 +1128,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75572 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75573 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75574
75575 +#ifdef CONFIG_PAX_MPROTECT
75576 + if (mm->pax_flags & MF_PAX_MPROTECT) {
75577 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
75578 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75579 + gr_log_rwxmmap(file);
75580 +
75581 +#ifdef CONFIG_PAX_EMUPLT
75582 + vm_flags &= ~VM_EXEC;
75583 +#else
75584 + return -EPERM;
75585 +#endif
75586 +
75587 + }
75588 +
75589 + if (!(vm_flags & VM_EXEC))
75590 + vm_flags &= ~VM_MAYEXEC;
75591 +#else
75592 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75593 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75594 +#endif
75595 + else
75596 + vm_flags &= ~VM_MAYWRITE;
75597 + }
75598 +#endif
75599 +
75600 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75601 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75602 + vm_flags &= ~VM_PAGEEXEC;
75603 +#endif
75604 +
75605 if (flags & MAP_LOCKED)
75606 if (!can_do_mlock())
75607 return -EPERM;
75608 @@ -1061,6 +1169,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75609 locked += mm->locked_vm;
75610 lock_limit = rlimit(RLIMIT_MEMLOCK);
75611 lock_limit >>= PAGE_SHIFT;
75612 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75613 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75614 return -EAGAIN;
75615 }
75616 @@ -1127,6 +1236,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75617 }
75618 }
75619
75620 + if (!gr_acl_handle_mmap(file, prot))
75621 + return -EACCES;
75622 +
75623 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75624 }
75625
75626 @@ -1203,7 +1315,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75627 vm_flags_t vm_flags = vma->vm_flags;
75628
75629 /* If it was private or non-writable, the write bit is already clear */
75630 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75631 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75632 return 0;
75633
75634 /* The backer wishes to know when pages are first written to? */
75635 @@ -1252,13 +1364,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75636 unsigned long charged = 0;
75637 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75638
75639 +#ifdef CONFIG_PAX_SEGMEXEC
75640 + struct vm_area_struct *vma_m = NULL;
75641 +#endif
75642 +
75643 + /*
75644 + * mm->mmap_sem is required to protect against another thread
75645 + * changing the mappings in case we sleep.
75646 + */
75647 + verify_mm_writelocked(mm);
75648 +
75649 /* Clear old maps */
75650 error = -ENOMEM;
75651 -munmap_back:
75652 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75653 if (do_munmap(mm, addr, len))
75654 return -ENOMEM;
75655 - goto munmap_back;
75656 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75657 }
75658
75659 /* Check against address space limit. */
75660 @@ -1307,6 +1428,16 @@ munmap_back:
75661 goto unacct_error;
75662 }
75663
75664 +#ifdef CONFIG_PAX_SEGMEXEC
75665 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75666 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75667 + if (!vma_m) {
75668 + error = -ENOMEM;
75669 + goto free_vma;
75670 + }
75671 + }
75672 +#endif
75673 +
75674 vma->vm_mm = mm;
75675 vma->vm_start = addr;
75676 vma->vm_end = addr + len;
75677 @@ -1331,6 +1462,13 @@ munmap_back:
75678 if (error)
75679 goto unmap_and_free_vma;
75680
75681 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75682 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75683 + vma->vm_flags |= VM_PAGEEXEC;
75684 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75685 + }
75686 +#endif
75687 +
75688 /* Can addr have changed??
75689 *
75690 * Answer: Yes, several device drivers can do it in their
75691 @@ -1365,6 +1503,11 @@ munmap_back:
75692 vma_link(mm, vma, prev, rb_link, rb_parent);
75693 file = vma->vm_file;
75694
75695 +#ifdef CONFIG_PAX_SEGMEXEC
75696 + if (vma_m)
75697 + BUG_ON(pax_mirror_vma(vma_m, vma));
75698 +#endif
75699 +
75700 /* Once vma denies write, undo our temporary denial count */
75701 if (correct_wcount)
75702 atomic_inc(&inode->i_writecount);
75703 @@ -1372,6 +1515,7 @@ out:
75704 perf_event_mmap(vma);
75705
75706 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75707 + track_exec_limit(mm, addr, addr + len, vm_flags);
75708 if (vm_flags & VM_LOCKED) {
75709 if (!mlock_vma_pages_range(vma, addr, addr + len))
75710 mm->locked_vm += (len >> PAGE_SHIFT);
75711 @@ -1393,6 +1537,12 @@ unmap_and_free_vma:
75712 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75713 charged = 0;
75714 free_vma:
75715 +
75716 +#ifdef CONFIG_PAX_SEGMEXEC
75717 + if (vma_m)
75718 + kmem_cache_free(vm_area_cachep, vma_m);
75719 +#endif
75720 +
75721 kmem_cache_free(vm_area_cachep, vma);
75722 unacct_error:
75723 if (charged)
75724 @@ -1400,6 +1550,62 @@ unacct_error:
75725 return error;
75726 }
75727
75728 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75729 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75730 +{
75731 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
75732 + return (random32() & 0xFF) << PAGE_SHIFT;
75733 +
75734 + return 0;
75735 +}
75736 +#endif
75737 +
75738 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
75739 +{
75740 + if (!vma) {
75741 +#ifdef CONFIG_STACK_GROWSUP
75742 + if (addr > sysctl_heap_stack_gap)
75743 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75744 + else
75745 + vma = find_vma(current->mm, 0);
75746 + if (vma && (vma->vm_flags & VM_GROWSUP))
75747 + return false;
75748 +#endif
75749 + return true;
75750 + }
75751 +
75752 + if (addr + len > vma->vm_start)
75753 + return false;
75754 +
75755 + if (vma->vm_flags & VM_GROWSDOWN)
75756 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75757 +#ifdef CONFIG_STACK_GROWSUP
75758 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75759 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75760 +#endif
75761 + else if (offset)
75762 + return offset <= vma->vm_start - addr - len;
75763 +
75764 + return true;
75765 +}
75766 +
75767 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
75768 +{
75769 + if (vma->vm_start < len)
75770 + return -ENOMEM;
75771 +
75772 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
75773 + if (offset <= vma->vm_start - len)
75774 + return vma->vm_start - len - offset;
75775 + else
75776 + return -ENOMEM;
75777 + }
75778 +
75779 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
75780 + return vma->vm_start - len - sysctl_heap_stack_gap;
75781 + return -ENOMEM;
75782 +}
75783 +
75784 /* Get an address range which is currently unmapped.
75785 * For shmat() with addr=0.
75786 *
75787 @@ -1419,6 +1625,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75788 struct mm_struct *mm = current->mm;
75789 struct vm_area_struct *vma;
75790 unsigned long start_addr;
75791 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75792
75793 if (len > TASK_SIZE)
75794 return -ENOMEM;
75795 @@ -1426,18 +1633,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75796 if (flags & MAP_FIXED)
75797 return addr;
75798
75799 +#ifdef CONFIG_PAX_RANDMMAP
75800 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75801 +#endif
75802 +
75803 if (addr) {
75804 addr = PAGE_ALIGN(addr);
75805 - vma = find_vma(mm, addr);
75806 - if (TASK_SIZE - len >= addr &&
75807 - (!vma || addr + len <= vma->vm_start))
75808 - return addr;
75809 + if (TASK_SIZE - len >= addr) {
75810 + vma = find_vma(mm, addr);
75811 + if (check_heap_stack_gap(vma, addr, len, offset))
75812 + return addr;
75813 + }
75814 }
75815 if (len > mm->cached_hole_size) {
75816 - start_addr = addr = mm->free_area_cache;
75817 + start_addr = addr = mm->free_area_cache;
75818 } else {
75819 - start_addr = addr = TASK_UNMAPPED_BASE;
75820 - mm->cached_hole_size = 0;
75821 + start_addr = addr = mm->mmap_base;
75822 + mm->cached_hole_size = 0;
75823 }
75824
75825 full_search:
75826 @@ -1448,34 +1660,40 @@ full_search:
75827 * Start a new search - just in case we missed
75828 * some holes.
75829 */
75830 - if (start_addr != TASK_UNMAPPED_BASE) {
75831 - addr = TASK_UNMAPPED_BASE;
75832 - start_addr = addr;
75833 + if (start_addr != mm->mmap_base) {
75834 + start_addr = addr = mm->mmap_base;
75835 mm->cached_hole_size = 0;
75836 goto full_search;
75837 }
75838 return -ENOMEM;
75839 }
75840 - if (!vma || addr + len <= vma->vm_start) {
75841 - /*
75842 - * Remember the place where we stopped the search:
75843 - */
75844 - mm->free_area_cache = addr + len;
75845 - return addr;
75846 - }
75847 + if (check_heap_stack_gap(vma, addr, len, offset))
75848 + break;
75849 if (addr + mm->cached_hole_size < vma->vm_start)
75850 mm->cached_hole_size = vma->vm_start - addr;
75851 addr = vma->vm_end;
75852 }
75853 +
75854 + /*
75855 + * Remember the place where we stopped the search:
75856 + */
75857 + mm->free_area_cache = addr + len;
75858 + return addr;
75859 }
75860 #endif
75861
75862 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75863 {
75864 +
75865 +#ifdef CONFIG_PAX_SEGMEXEC
75866 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75867 + return;
75868 +#endif
75869 +
75870 /*
75871 * Is this a new hole at the lowest possible address?
75872 */
75873 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75874 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75875 mm->free_area_cache = addr;
75876 }
75877
75878 @@ -1491,7 +1709,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75879 {
75880 struct vm_area_struct *vma;
75881 struct mm_struct *mm = current->mm;
75882 - unsigned long addr = addr0, start_addr;
75883 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75884 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75885
75886 /* requested length too big for entire address space */
75887 if (len > TASK_SIZE)
75888 @@ -1500,13 +1719,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75889 if (flags & MAP_FIXED)
75890 return addr;
75891
75892 +#ifdef CONFIG_PAX_RANDMMAP
75893 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75894 +#endif
75895 +
75896 /* requesting a specific address */
75897 if (addr) {
75898 addr = PAGE_ALIGN(addr);
75899 - vma = find_vma(mm, addr);
75900 - if (TASK_SIZE - len >= addr &&
75901 - (!vma || addr + len <= vma->vm_start))
75902 - return addr;
75903 + if (TASK_SIZE - len >= addr) {
75904 + vma = find_vma(mm, addr);
75905 + if (check_heap_stack_gap(vma, addr, len, offset))
75906 + return addr;
75907 + }
75908 }
75909
75910 /* check if free_area_cache is useful for us */
75911 @@ -1530,7 +1754,7 @@ try_again:
75912 * return with success:
75913 */
75914 vma = find_vma(mm, addr);
75915 - if (!vma || addr+len <= vma->vm_start)
75916 + if (check_heap_stack_gap(vma, addr, len, offset))
75917 /* remember the address as a hint for next time */
75918 return (mm->free_area_cache = addr);
75919
75920 @@ -1539,8 +1763,8 @@ try_again:
75921 mm->cached_hole_size = vma->vm_start - addr;
75922
75923 /* try just below the current vma->vm_start */
75924 - addr = vma->vm_start-len;
75925 - } while (len < vma->vm_start);
75926 + addr = skip_heap_stack_gap(vma, len, offset);
75927 + } while (!IS_ERR_VALUE(addr));
75928
75929 fail:
75930 /*
75931 @@ -1563,13 +1787,21 @@ fail:
75932 * can happen with large stack limits and large mmap()
75933 * allocations.
75934 */
75935 + mm->mmap_base = TASK_UNMAPPED_BASE;
75936 +
75937 +#ifdef CONFIG_PAX_RANDMMAP
75938 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75939 + mm->mmap_base += mm->delta_mmap;
75940 +#endif
75941 +
75942 + mm->free_area_cache = mm->mmap_base;
75943 mm->cached_hole_size = ~0UL;
75944 - mm->free_area_cache = TASK_UNMAPPED_BASE;
75945 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
75946 /*
75947 * Restore the topdown base:
75948 */
75949 - mm->free_area_cache = mm->mmap_base;
75950 + mm->mmap_base = base;
75951 + mm->free_area_cache = base;
75952 mm->cached_hole_size = ~0UL;
75953
75954 return addr;
75955 @@ -1578,6 +1810,12 @@ fail:
75956
75957 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75958 {
75959 +
75960 +#ifdef CONFIG_PAX_SEGMEXEC
75961 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75962 + return;
75963 +#endif
75964 +
75965 /*
75966 * Is this a new hole at the highest possible address?
75967 */
75968 @@ -1585,8 +1823,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75969 mm->free_area_cache = addr;
75970
75971 /* dont allow allocations above current base */
75972 - if (mm->free_area_cache > mm->mmap_base)
75973 + if (mm->free_area_cache > mm->mmap_base) {
75974 mm->free_area_cache = mm->mmap_base;
75975 + mm->cached_hole_size = ~0UL;
75976 + }
75977 }
75978
75979 unsigned long
75980 @@ -1685,6 +1925,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
75981 return vma;
75982 }
75983
75984 +#ifdef CONFIG_PAX_SEGMEXEC
75985 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
75986 +{
75987 + struct vm_area_struct *vma_m;
75988 +
75989 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
75990 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
75991 + BUG_ON(vma->vm_mirror);
75992 + return NULL;
75993 + }
75994 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
75995 + vma_m = vma->vm_mirror;
75996 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
75997 + BUG_ON(vma->vm_file != vma_m->vm_file);
75998 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
75999 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
76000 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
76001 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
76002 + return vma_m;
76003 +}
76004 +#endif
76005 +
76006 /*
76007 * Verify that the stack growth is acceptable and
76008 * update accounting. This is shared with both the
76009 @@ -1701,6 +1963,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76010 return -ENOMEM;
76011
76012 /* Stack limit test */
76013 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
76014 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
76015 return -ENOMEM;
76016
76017 @@ -1711,6 +1974,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76018 locked = mm->locked_vm + grow;
76019 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
76020 limit >>= PAGE_SHIFT;
76021 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76022 if (locked > limit && !capable(CAP_IPC_LOCK))
76023 return -ENOMEM;
76024 }
76025 @@ -1740,37 +2004,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76026 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
76027 * vma is the last one with address > vma->vm_end. Have to extend vma.
76028 */
76029 +#ifndef CONFIG_IA64
76030 +static
76031 +#endif
76032 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76033 {
76034 int error;
76035 + bool locknext;
76036
76037 if (!(vma->vm_flags & VM_GROWSUP))
76038 return -EFAULT;
76039
76040 + /* Also guard against wrapping around to address 0. */
76041 + if (address < PAGE_ALIGN(address+1))
76042 + address = PAGE_ALIGN(address+1);
76043 + else
76044 + return -ENOMEM;
76045 +
76046 /*
76047 * We must make sure the anon_vma is allocated
76048 * so that the anon_vma locking is not a noop.
76049 */
76050 if (unlikely(anon_vma_prepare(vma)))
76051 return -ENOMEM;
76052 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
76053 + if (locknext && anon_vma_prepare(vma->vm_next))
76054 + return -ENOMEM;
76055 vma_lock_anon_vma(vma);
76056 + if (locknext)
76057 + vma_lock_anon_vma(vma->vm_next);
76058
76059 /*
76060 * vma->vm_start/vm_end cannot change under us because the caller
76061 * is required to hold the mmap_sem in read mode. We need the
76062 - * anon_vma lock to serialize against concurrent expand_stacks.
76063 - * Also guard against wrapping around to address 0.
76064 + * anon_vma locks to serialize against concurrent expand_stacks
76065 + * and expand_upwards.
76066 */
76067 - if (address < PAGE_ALIGN(address+4))
76068 - address = PAGE_ALIGN(address+4);
76069 - else {
76070 - vma_unlock_anon_vma(vma);
76071 - return -ENOMEM;
76072 - }
76073 error = 0;
76074
76075 /* Somebody else might have raced and expanded it already */
76076 - if (address > vma->vm_end) {
76077 + 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)
76078 + error = -ENOMEM;
76079 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
76080 unsigned long size, grow;
76081
76082 size = address - vma->vm_start;
76083 @@ -1787,6 +2062,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76084 }
76085 }
76086 }
76087 + if (locknext)
76088 + vma_unlock_anon_vma(vma->vm_next);
76089 vma_unlock_anon_vma(vma);
76090 khugepaged_enter_vma_merge(vma);
76091 validate_mm(vma->vm_mm);
76092 @@ -1801,6 +2078,8 @@ int expand_downwards(struct vm_area_struct *vma,
76093 unsigned long address)
76094 {
76095 int error;
76096 + bool lockprev = false;
76097 + struct vm_area_struct *prev;
76098
76099 /*
76100 * We must make sure the anon_vma is allocated
76101 @@ -1814,6 +2093,15 @@ int expand_downwards(struct vm_area_struct *vma,
76102 if (error)
76103 return error;
76104
76105 + prev = vma->vm_prev;
76106 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
76107 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
76108 +#endif
76109 + if (lockprev && anon_vma_prepare(prev))
76110 + return -ENOMEM;
76111 + if (lockprev)
76112 + vma_lock_anon_vma(prev);
76113 +
76114 vma_lock_anon_vma(vma);
76115
76116 /*
76117 @@ -1823,9 +2111,17 @@ int expand_downwards(struct vm_area_struct *vma,
76118 */
76119
76120 /* Somebody else might have raced and expanded it already */
76121 - if (address < vma->vm_start) {
76122 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
76123 + error = -ENOMEM;
76124 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
76125 unsigned long size, grow;
76126
76127 +#ifdef CONFIG_PAX_SEGMEXEC
76128 + struct vm_area_struct *vma_m;
76129 +
76130 + vma_m = pax_find_mirror_vma(vma);
76131 +#endif
76132 +
76133 size = vma->vm_end - address;
76134 grow = (vma->vm_start - address) >> PAGE_SHIFT;
76135
76136 @@ -1837,6 +2133,17 @@ int expand_downwards(struct vm_area_struct *vma,
76137 vma->vm_start = address;
76138 vma->vm_pgoff -= grow;
76139 anon_vma_interval_tree_post_update_vma(vma);
76140 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
76141 +
76142 +#ifdef CONFIG_PAX_SEGMEXEC
76143 + if (vma_m) {
76144 + anon_vma_interval_tree_pre_update_vma(vma_m);
76145 + vma_m->vm_start -= grow << PAGE_SHIFT;
76146 + vma_m->vm_pgoff -= grow;
76147 + anon_vma_interval_tree_post_update_vma(vma_m);
76148 + }
76149 +#endif
76150 +
76151 perf_event_mmap(vma);
76152 }
76153 }
76154 @@ -1914,6 +2221,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
76155 do {
76156 long nrpages = vma_pages(vma);
76157
76158 +#ifdef CONFIG_PAX_SEGMEXEC
76159 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
76160 + vma = remove_vma(vma);
76161 + continue;
76162 + }
76163 +#endif
76164 +
76165 if (vma->vm_flags & VM_ACCOUNT)
76166 nr_accounted += nrpages;
76167 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
76168 @@ -1959,6 +2273,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
76169 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
76170 vma->vm_prev = NULL;
76171 do {
76172 +
76173 +#ifdef CONFIG_PAX_SEGMEXEC
76174 + if (vma->vm_mirror) {
76175 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
76176 + vma->vm_mirror->vm_mirror = NULL;
76177 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
76178 + vma->vm_mirror = NULL;
76179 + }
76180 +#endif
76181 +
76182 rb_erase(&vma->vm_rb, &mm->mm_rb);
76183 mm->map_count--;
76184 tail_vma = vma;
76185 @@ -1987,14 +2311,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76186 struct vm_area_struct *new;
76187 int err = -ENOMEM;
76188
76189 +#ifdef CONFIG_PAX_SEGMEXEC
76190 + struct vm_area_struct *vma_m, *new_m = NULL;
76191 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
76192 +#endif
76193 +
76194 if (is_vm_hugetlb_page(vma) && (addr &
76195 ~(huge_page_mask(hstate_vma(vma)))))
76196 return -EINVAL;
76197
76198 +#ifdef CONFIG_PAX_SEGMEXEC
76199 + vma_m = pax_find_mirror_vma(vma);
76200 +#endif
76201 +
76202 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76203 if (!new)
76204 goto out_err;
76205
76206 +#ifdef CONFIG_PAX_SEGMEXEC
76207 + if (vma_m) {
76208 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76209 + if (!new_m) {
76210 + kmem_cache_free(vm_area_cachep, new);
76211 + goto out_err;
76212 + }
76213 + }
76214 +#endif
76215 +
76216 /* most fields are the same, copy all, and then fixup */
76217 *new = *vma;
76218
76219 @@ -2007,6 +2350,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76220 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
76221 }
76222
76223 +#ifdef CONFIG_PAX_SEGMEXEC
76224 + if (vma_m) {
76225 + *new_m = *vma_m;
76226 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
76227 + new_m->vm_mirror = new;
76228 + new->vm_mirror = new_m;
76229 +
76230 + if (new_below)
76231 + new_m->vm_end = addr_m;
76232 + else {
76233 + new_m->vm_start = addr_m;
76234 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
76235 + }
76236 + }
76237 +#endif
76238 +
76239 pol = mpol_dup(vma_policy(vma));
76240 if (IS_ERR(pol)) {
76241 err = PTR_ERR(pol);
76242 @@ -2029,6 +2388,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76243 else
76244 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
76245
76246 +#ifdef CONFIG_PAX_SEGMEXEC
76247 + if (!err && vma_m) {
76248 + if (anon_vma_clone(new_m, vma_m))
76249 + goto out_free_mpol;
76250 +
76251 + mpol_get(pol);
76252 + vma_set_policy(new_m, pol);
76253 +
76254 + if (new_m->vm_file)
76255 + get_file(new_m->vm_file);
76256 +
76257 + if (new_m->vm_ops && new_m->vm_ops->open)
76258 + new_m->vm_ops->open(new_m);
76259 +
76260 + if (new_below)
76261 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
76262 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
76263 + else
76264 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
76265 +
76266 + if (err) {
76267 + if (new_m->vm_ops && new_m->vm_ops->close)
76268 + new_m->vm_ops->close(new_m);
76269 + if (new_m->vm_file)
76270 + fput(new_m->vm_file);
76271 + mpol_put(pol);
76272 + }
76273 + }
76274 +#endif
76275 +
76276 /* Success. */
76277 if (!err)
76278 return 0;
76279 @@ -2038,10 +2427,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76280 new->vm_ops->close(new);
76281 if (new->vm_file)
76282 fput(new->vm_file);
76283 - unlink_anon_vmas(new);
76284 out_free_mpol:
76285 mpol_put(pol);
76286 out_free_vma:
76287 +
76288 +#ifdef CONFIG_PAX_SEGMEXEC
76289 + if (new_m) {
76290 + unlink_anon_vmas(new_m);
76291 + kmem_cache_free(vm_area_cachep, new_m);
76292 + }
76293 +#endif
76294 +
76295 + unlink_anon_vmas(new);
76296 kmem_cache_free(vm_area_cachep, new);
76297 out_err:
76298 return err;
76299 @@ -2054,6 +2451,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76300 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76301 unsigned long addr, int new_below)
76302 {
76303 +
76304 +#ifdef CONFIG_PAX_SEGMEXEC
76305 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76306 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
76307 + if (mm->map_count >= sysctl_max_map_count-1)
76308 + return -ENOMEM;
76309 + } else
76310 +#endif
76311 +
76312 if (mm->map_count >= sysctl_max_map_count)
76313 return -ENOMEM;
76314
76315 @@ -2065,11 +2471,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76316 * work. This now handles partial unmappings.
76317 * Jeremy Fitzhardinge <jeremy@goop.org>
76318 */
76319 +#ifdef CONFIG_PAX_SEGMEXEC
76320 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76321 {
76322 + int ret = __do_munmap(mm, start, len);
76323 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
76324 + return ret;
76325 +
76326 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
76327 +}
76328 +
76329 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76330 +#else
76331 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76332 +#endif
76333 +{
76334 unsigned long end;
76335 struct vm_area_struct *vma, *prev, *last;
76336
76337 + /*
76338 + * mm->mmap_sem is required to protect against another thread
76339 + * changing the mappings in case we sleep.
76340 + */
76341 + verify_mm_writelocked(mm);
76342 +
76343 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
76344 return -EINVAL;
76345
76346 @@ -2144,6 +2569,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76347 /* Fix up all other VM information */
76348 remove_vma_list(mm, vma);
76349
76350 + track_exec_limit(mm, start, end, 0UL);
76351 +
76352 return 0;
76353 }
76354
76355 @@ -2152,6 +2579,13 @@ int vm_munmap(unsigned long start, size_t len)
76356 int ret;
76357 struct mm_struct *mm = current->mm;
76358
76359 +
76360 +#ifdef CONFIG_PAX_SEGMEXEC
76361 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
76362 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
76363 + return -EINVAL;
76364 +#endif
76365 +
76366 down_write(&mm->mmap_sem);
76367 ret = do_munmap(mm, start, len);
76368 up_write(&mm->mmap_sem);
76369 @@ -2165,16 +2599,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
76370 return vm_munmap(addr, len);
76371 }
76372
76373 -static inline void verify_mm_writelocked(struct mm_struct *mm)
76374 -{
76375 -#ifdef CONFIG_DEBUG_VM
76376 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76377 - WARN_ON(1);
76378 - up_read(&mm->mmap_sem);
76379 - }
76380 -#endif
76381 -}
76382 -
76383 /*
76384 * this is really a simplified "do_mmap". it only handles
76385 * anonymous maps. eventually we may be able to do some
76386 @@ -2188,6 +2612,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76387 struct rb_node ** rb_link, * rb_parent;
76388 pgoff_t pgoff = addr >> PAGE_SHIFT;
76389 int error;
76390 + unsigned long charged;
76391
76392 len = PAGE_ALIGN(len);
76393 if (!len)
76394 @@ -2195,16 +2620,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76395
76396 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
76397
76398 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
76399 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
76400 + flags &= ~VM_EXEC;
76401 +
76402 +#ifdef CONFIG_PAX_MPROTECT
76403 + if (mm->pax_flags & MF_PAX_MPROTECT)
76404 + flags &= ~VM_MAYEXEC;
76405 +#endif
76406 +
76407 + }
76408 +#endif
76409 +
76410 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
76411 if (error & ~PAGE_MASK)
76412 return error;
76413
76414 + charged = len >> PAGE_SHIFT;
76415 +
76416 /*
76417 * mlock MCL_FUTURE?
76418 */
76419 if (mm->def_flags & VM_LOCKED) {
76420 unsigned long locked, lock_limit;
76421 - locked = len >> PAGE_SHIFT;
76422 + locked = charged;
76423 locked += mm->locked_vm;
76424 lock_limit = rlimit(RLIMIT_MEMLOCK);
76425 lock_limit >>= PAGE_SHIFT;
76426 @@ -2221,21 +2660,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76427 /*
76428 * Clear old maps. this also does some error checking for us
76429 */
76430 - munmap_back:
76431 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76432 if (do_munmap(mm, addr, len))
76433 return -ENOMEM;
76434 - goto munmap_back;
76435 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76436 }
76437
76438 /* Check against address space limits *after* clearing old maps... */
76439 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
76440 + if (!may_expand_vm(mm, charged))
76441 return -ENOMEM;
76442
76443 if (mm->map_count > sysctl_max_map_count)
76444 return -ENOMEM;
76445
76446 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
76447 + if (security_vm_enough_memory_mm(mm, charged))
76448 return -ENOMEM;
76449
76450 /* Can we just expand an old private anonymous mapping? */
76451 @@ -2249,7 +2687,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76452 */
76453 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76454 if (!vma) {
76455 - vm_unacct_memory(len >> PAGE_SHIFT);
76456 + vm_unacct_memory(charged);
76457 return -ENOMEM;
76458 }
76459
76460 @@ -2263,11 +2701,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76461 vma_link(mm, vma, prev, rb_link, rb_parent);
76462 out:
76463 perf_event_mmap(vma);
76464 - mm->total_vm += len >> PAGE_SHIFT;
76465 + mm->total_vm += charged;
76466 if (flags & VM_LOCKED) {
76467 if (!mlock_vma_pages_range(vma, addr, addr + len))
76468 - mm->locked_vm += (len >> PAGE_SHIFT);
76469 + mm->locked_vm += charged;
76470 }
76471 + track_exec_limit(mm, addr, addr + len, flags);
76472 return addr;
76473 }
76474
76475 @@ -2325,6 +2764,7 @@ void exit_mmap(struct mm_struct *mm)
76476 while (vma) {
76477 if (vma->vm_flags & VM_ACCOUNT)
76478 nr_accounted += vma_pages(vma);
76479 + vma->vm_mirror = NULL;
76480 vma = remove_vma(vma);
76481 }
76482 vm_unacct_memory(nr_accounted);
76483 @@ -2341,6 +2781,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76484 struct vm_area_struct *prev;
76485 struct rb_node **rb_link, *rb_parent;
76486
76487 +#ifdef CONFIG_PAX_SEGMEXEC
76488 + struct vm_area_struct *vma_m = NULL;
76489 +#endif
76490 +
76491 + if (security_mmap_addr(vma->vm_start))
76492 + return -EPERM;
76493 +
76494 /*
76495 * The vm_pgoff of a purely anonymous vma should be irrelevant
76496 * until its first write fault, when page's anon_vma and index
76497 @@ -2364,7 +2811,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76498 security_vm_enough_memory_mm(mm, vma_pages(vma)))
76499 return -ENOMEM;
76500
76501 +#ifdef CONFIG_PAX_SEGMEXEC
76502 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
76503 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76504 + if (!vma_m)
76505 + return -ENOMEM;
76506 + }
76507 +#endif
76508 +
76509 vma_link(mm, vma, prev, rb_link, rb_parent);
76510 +
76511 +#ifdef CONFIG_PAX_SEGMEXEC
76512 + if (vma_m)
76513 + BUG_ON(pax_mirror_vma(vma_m, vma));
76514 +#endif
76515 +
76516 return 0;
76517 }
76518
76519 @@ -2384,6 +2845,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76520 struct mempolicy *pol;
76521 bool faulted_in_anon_vma = true;
76522
76523 + BUG_ON(vma->vm_mirror);
76524 +
76525 /*
76526 * If anonymous vma has not yet been faulted, update new pgoff
76527 * to match new location, to increase its chance of merging.
76528 @@ -2450,6 +2913,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76529 return NULL;
76530 }
76531
76532 +#ifdef CONFIG_PAX_SEGMEXEC
76533 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
76534 +{
76535 + struct vm_area_struct *prev_m;
76536 + struct rb_node **rb_link_m, *rb_parent_m;
76537 + struct mempolicy *pol_m;
76538 +
76539 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
76540 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
76541 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
76542 + *vma_m = *vma;
76543 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
76544 + if (anon_vma_clone(vma_m, vma))
76545 + return -ENOMEM;
76546 + pol_m = vma_policy(vma_m);
76547 + mpol_get(pol_m);
76548 + vma_set_policy(vma_m, pol_m);
76549 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
76550 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
76551 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
76552 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
76553 + if (vma_m->vm_file)
76554 + get_file(vma_m->vm_file);
76555 + if (vma_m->vm_ops && vma_m->vm_ops->open)
76556 + vma_m->vm_ops->open(vma_m);
76557 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
76558 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
76559 + vma_m->vm_mirror = vma;
76560 + vma->vm_mirror = vma_m;
76561 + return 0;
76562 +}
76563 +#endif
76564 +
76565 /*
76566 * Return true if the calling process may expand its vm space by the passed
76567 * number of pages
76568 @@ -2461,6 +2957,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
76569
76570 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
76571
76572 +#ifdef CONFIG_PAX_RANDMMAP
76573 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76574 + cur -= mm->brk_gap;
76575 +#endif
76576 +
76577 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
76578 if (cur + npages > lim)
76579 return 0;
76580 return 1;
76581 @@ -2531,6 +3033,22 @@ int install_special_mapping(struct mm_struct *mm,
76582 vma->vm_start = addr;
76583 vma->vm_end = addr + len;
76584
76585 +#ifdef CONFIG_PAX_MPROTECT
76586 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76587 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76588 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
76589 + return -EPERM;
76590 + if (!(vm_flags & VM_EXEC))
76591 + vm_flags &= ~VM_MAYEXEC;
76592 +#else
76593 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76594 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76595 +#endif
76596 + else
76597 + vm_flags &= ~VM_MAYWRITE;
76598 + }
76599 +#endif
76600 +
76601 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
76602 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76603
76604 diff --git a/mm/mprotect.c b/mm/mprotect.c
76605 index a409926..8b32e6d 100644
76606 --- a/mm/mprotect.c
76607 +++ b/mm/mprotect.c
76608 @@ -23,10 +23,17 @@
76609 #include <linux/mmu_notifier.h>
76610 #include <linux/migrate.h>
76611 #include <linux/perf_event.h>
76612 +
76613 +#ifdef CONFIG_PAX_MPROTECT
76614 +#include <linux/elf.h>
76615 +#include <linux/binfmts.h>
76616 +#endif
76617 +
76618 #include <asm/uaccess.h>
76619 #include <asm/pgtable.h>
76620 #include <asm/cacheflush.h>
76621 #include <asm/tlbflush.h>
76622 +#include <asm/mmu_context.h>
76623
76624 #ifndef pgprot_modify
76625 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
76626 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
76627 flush_tlb_range(vma, start, end);
76628 }
76629
76630 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76631 +/* called while holding the mmap semaphor for writing except stack expansion */
76632 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
76633 +{
76634 + unsigned long oldlimit, newlimit = 0UL;
76635 +
76636 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
76637 + return;
76638 +
76639 + spin_lock(&mm->page_table_lock);
76640 + oldlimit = mm->context.user_cs_limit;
76641 + if ((prot & VM_EXEC) && oldlimit < end)
76642 + /* USER_CS limit moved up */
76643 + newlimit = end;
76644 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
76645 + /* USER_CS limit moved down */
76646 + newlimit = start;
76647 +
76648 + if (newlimit) {
76649 + mm->context.user_cs_limit = newlimit;
76650 +
76651 +#ifdef CONFIG_SMP
76652 + wmb();
76653 + cpus_clear(mm->context.cpu_user_cs_mask);
76654 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
76655 +#endif
76656 +
76657 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
76658 + }
76659 + spin_unlock(&mm->page_table_lock);
76660 + if (newlimit == end) {
76661 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
76662 +
76663 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
76664 + if (is_vm_hugetlb_page(vma))
76665 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
76666 + else
76667 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
76668 + }
76669 +}
76670 +#endif
76671 +
76672 int
76673 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76674 unsigned long start, unsigned long end, unsigned long newflags)
76675 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76676 int error;
76677 int dirty_accountable = 0;
76678
76679 +#ifdef CONFIG_PAX_SEGMEXEC
76680 + struct vm_area_struct *vma_m = NULL;
76681 + unsigned long start_m, end_m;
76682 +
76683 + start_m = start + SEGMEXEC_TASK_SIZE;
76684 + end_m = end + SEGMEXEC_TASK_SIZE;
76685 +#endif
76686 +
76687 if (newflags == oldflags) {
76688 *pprev = vma;
76689 return 0;
76690 }
76691
76692 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
76693 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
76694 +
76695 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
76696 + return -ENOMEM;
76697 +
76698 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
76699 + return -ENOMEM;
76700 + }
76701 +
76702 /*
76703 * If we make a private mapping writable we increase our commit;
76704 * but (without finer accounting) cannot reduce our commit if we
76705 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76706 }
76707 }
76708
76709 +#ifdef CONFIG_PAX_SEGMEXEC
76710 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
76711 + if (start != vma->vm_start) {
76712 + error = split_vma(mm, vma, start, 1);
76713 + if (error)
76714 + goto fail;
76715 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
76716 + *pprev = (*pprev)->vm_next;
76717 + }
76718 +
76719 + if (end != vma->vm_end) {
76720 + error = split_vma(mm, vma, end, 0);
76721 + if (error)
76722 + goto fail;
76723 + }
76724 +
76725 + if (pax_find_mirror_vma(vma)) {
76726 + error = __do_munmap(mm, start_m, end_m - start_m);
76727 + if (error)
76728 + goto fail;
76729 + } else {
76730 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76731 + if (!vma_m) {
76732 + error = -ENOMEM;
76733 + goto fail;
76734 + }
76735 + vma->vm_flags = newflags;
76736 + error = pax_mirror_vma(vma_m, vma);
76737 + if (error) {
76738 + vma->vm_flags = oldflags;
76739 + goto fail;
76740 + }
76741 + }
76742 + }
76743 +#endif
76744 +
76745 /*
76746 * First try to merge with previous and/or next vma.
76747 */
76748 @@ -204,9 +307,21 @@ success:
76749 * vm_flags and vm_page_prot are protected by the mmap_sem
76750 * held in write mode.
76751 */
76752 +
76753 +#ifdef CONFIG_PAX_SEGMEXEC
76754 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
76755 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
76756 +#endif
76757 +
76758 vma->vm_flags = newflags;
76759 +
76760 +#ifdef CONFIG_PAX_MPROTECT
76761 + if (mm->binfmt && mm->binfmt->handle_mprotect)
76762 + mm->binfmt->handle_mprotect(vma, newflags);
76763 +#endif
76764 +
76765 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
76766 - vm_get_page_prot(newflags));
76767 + vm_get_page_prot(vma->vm_flags));
76768
76769 if (vma_wants_writenotify(vma)) {
76770 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
76771 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76772 end = start + len;
76773 if (end <= start)
76774 return -ENOMEM;
76775 +
76776 +#ifdef CONFIG_PAX_SEGMEXEC
76777 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76778 + if (end > SEGMEXEC_TASK_SIZE)
76779 + return -EINVAL;
76780 + } else
76781 +#endif
76782 +
76783 + if (end > TASK_SIZE)
76784 + return -EINVAL;
76785 +
76786 if (!arch_validate_prot(prot))
76787 return -EINVAL;
76788
76789 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76790 /*
76791 * Does the application expect PROT_READ to imply PROT_EXEC:
76792 */
76793 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76794 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76795 prot |= PROT_EXEC;
76796
76797 vm_flags = calc_vm_prot_bits(prot);
76798 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76799 if (start > vma->vm_start)
76800 prev = vma;
76801
76802 +#ifdef CONFIG_PAX_MPROTECT
76803 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
76804 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
76805 +#endif
76806 +
76807 for (nstart = start ; ; ) {
76808 unsigned long newflags;
76809
76810 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76811
76812 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76813 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76814 + if (prot & (PROT_WRITE | PROT_EXEC))
76815 + gr_log_rwxmprotect(vma->vm_file);
76816 +
76817 + error = -EACCES;
76818 + goto out;
76819 + }
76820 +
76821 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76822 error = -EACCES;
76823 goto out;
76824 }
76825 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76826 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76827 if (error)
76828 goto out;
76829 +
76830 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
76831 +
76832 nstart = tmp;
76833
76834 if (nstart < prev->vm_end)
76835 diff --git a/mm/mremap.c b/mm/mremap.c
76836 index 1b61c2d..1cc0e3c 100644
76837 --- a/mm/mremap.c
76838 +++ b/mm/mremap.c
76839 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76840 continue;
76841 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76842 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76843 +
76844 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76845 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76846 + pte = pte_exprotect(pte);
76847 +#endif
76848 +
76849 set_pte_at(mm, new_addr, new_pte, pte);
76850 }
76851
76852 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76853 if (is_vm_hugetlb_page(vma))
76854 goto Einval;
76855
76856 +#ifdef CONFIG_PAX_SEGMEXEC
76857 + if (pax_find_mirror_vma(vma))
76858 + goto Einval;
76859 +#endif
76860 +
76861 /* We can't remap across vm area boundaries */
76862 if (old_len > vma->vm_end - addr)
76863 goto Efault;
76864 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76865 unsigned long ret = -EINVAL;
76866 unsigned long charged = 0;
76867 unsigned long map_flags;
76868 + unsigned long pax_task_size = TASK_SIZE;
76869
76870 if (new_addr & ~PAGE_MASK)
76871 goto out;
76872
76873 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76874 +#ifdef CONFIG_PAX_SEGMEXEC
76875 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76876 + pax_task_size = SEGMEXEC_TASK_SIZE;
76877 +#endif
76878 +
76879 + pax_task_size -= PAGE_SIZE;
76880 +
76881 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76882 goto out;
76883
76884 /* Check if the location we're moving into overlaps the
76885 * old location at all, and fail if it does.
76886 */
76887 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
76888 - goto out;
76889 -
76890 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
76891 + if (addr + old_len > new_addr && new_addr + new_len > addr)
76892 goto out;
76893
76894 ret = do_munmap(mm, new_addr, new_len);
76895 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76896 struct vm_area_struct *vma;
76897 unsigned long ret = -EINVAL;
76898 unsigned long charged = 0;
76899 + unsigned long pax_task_size = TASK_SIZE;
76900
76901 down_write(&current->mm->mmap_sem);
76902
76903 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76904 if (!new_len)
76905 goto out;
76906
76907 +#ifdef CONFIG_PAX_SEGMEXEC
76908 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76909 + pax_task_size = SEGMEXEC_TASK_SIZE;
76910 +#endif
76911 +
76912 + pax_task_size -= PAGE_SIZE;
76913 +
76914 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
76915 + old_len > pax_task_size || addr > pax_task_size-old_len)
76916 + goto out;
76917 +
76918 if (flags & MREMAP_FIXED) {
76919 if (flags & MREMAP_MAYMOVE)
76920 ret = mremap_to(addr, old_len, new_addr, new_len);
76921 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76922 addr + new_len);
76923 }
76924 ret = addr;
76925 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
76926 goto out;
76927 }
76928 }
76929 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76930 goto out;
76931 }
76932
76933 + map_flags = vma->vm_flags;
76934 ret = move_vma(vma, addr, old_len, new_len, new_addr);
76935 + if (!(ret & ~PAGE_MASK)) {
76936 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
76937 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
76938 + }
76939 }
76940 out:
76941 if (ret & ~PAGE_MASK)
76942 diff --git a/mm/nommu.c b/mm/nommu.c
76943 index 45131b4..c521665 100644
76944 --- a/mm/nommu.c
76945 +++ b/mm/nommu.c
76946 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76947 int sysctl_overcommit_ratio = 50; /* default is 50% */
76948 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
76949 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
76950 -int heap_stack_gap = 0;
76951
76952 atomic_long_t mmap_pages_allocated;
76953
76954 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
76955 EXPORT_SYMBOL(find_vma);
76956
76957 /*
76958 - * find a VMA
76959 - * - we don't extend stack VMAs under NOMMU conditions
76960 - */
76961 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
76962 -{
76963 - return find_vma(mm, addr);
76964 -}
76965 -
76966 -/*
76967 * expand a stack to a given address
76968 * - not supported under NOMMU conditions
76969 */
76970 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76971
76972 /* most fields are the same, copy all, and then fixup */
76973 *new = *vma;
76974 + INIT_LIST_HEAD(&new->anon_vma_chain);
76975 *region = *vma->vm_region;
76976 new->vm_region = region;
76977
76978 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
76979 index ceb4168..d7774f2 100644
76980 --- a/mm/page_alloc.c
76981 +++ b/mm/page_alloc.c
76982 @@ -340,7 +340,7 @@ out:
76983 * This usage means that zero-order pages may not be compound.
76984 */
76985
76986 -static void free_compound_page(struct page *page)
76987 +void free_compound_page(struct page *page)
76988 {
76989 __free_pages_ok(page, compound_order(page));
76990 }
76991 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76992 int i;
76993 int bad = 0;
76994
76995 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
76996 + unsigned long index = 1UL << order;
76997 +#endif
76998 +
76999 trace_mm_page_free(page, order);
77000 kmemcheck_free_shadow(page, order);
77001
77002 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77003 debug_check_no_obj_freed(page_address(page),
77004 PAGE_SIZE << order);
77005 }
77006 +
77007 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
77008 + for (; index; --index)
77009 + sanitize_highpage(page + index - 1);
77010 +#endif
77011 +
77012 arch_free_page(page, order);
77013 kernel_map_pages(page, 1 << order, 0);
77014
77015 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
77016 arch_alloc_page(page, order);
77017 kernel_map_pages(page, 1 << order, 1);
77018
77019 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
77020 if (gfp_flags & __GFP_ZERO)
77021 prep_zero_page(page, order, gfp_flags);
77022 +#endif
77023
77024 if (order && (gfp_flags & __GFP_COMP))
77025 prep_compound_page(page, order);
77026 @@ -3684,7 +3696,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
77027 unsigned long pfn;
77028
77029 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
77030 +#ifdef CONFIG_X86_32
77031 + /* boot failures in VMware 8 on 32bit vanilla since
77032 + this change */
77033 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
77034 +#else
77035 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
77036 +#endif
77037 return 1;
77038 }
77039 return 0;
77040 diff --git a/mm/percpu.c b/mm/percpu.c
77041 index ddc5efb..f632d2c 100644
77042 --- a/mm/percpu.c
77043 +++ b/mm/percpu.c
77044 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
77045 static unsigned int pcpu_high_unit_cpu __read_mostly;
77046
77047 /* the address of the first chunk which starts with the kernel static area */
77048 -void *pcpu_base_addr __read_mostly;
77049 +void *pcpu_base_addr __read_only;
77050 EXPORT_SYMBOL_GPL(pcpu_base_addr);
77051
77052 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
77053 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
77054 index 926b466..b23df53 100644
77055 --- a/mm/process_vm_access.c
77056 +++ b/mm/process_vm_access.c
77057 @@ -13,6 +13,7 @@
77058 #include <linux/uio.h>
77059 #include <linux/sched.h>
77060 #include <linux/highmem.h>
77061 +#include <linux/security.h>
77062 #include <linux/ptrace.h>
77063 #include <linux/slab.h>
77064 #include <linux/syscalls.h>
77065 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77066 size_t iov_l_curr_offset = 0;
77067 ssize_t iov_len;
77068
77069 + return -ENOSYS; // PaX: until properly audited
77070 +
77071 /*
77072 * Work out how many pages of struct pages we're going to need
77073 * when eventually calling get_user_pages
77074 */
77075 for (i = 0; i < riovcnt; i++) {
77076 iov_len = rvec[i].iov_len;
77077 - if (iov_len > 0) {
77078 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
77079 - + iov_len)
77080 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
77081 - / PAGE_SIZE + 1;
77082 - nr_pages = max(nr_pages, nr_pages_iov);
77083 - }
77084 + if (iov_len <= 0)
77085 + continue;
77086 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
77087 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
77088 + nr_pages = max(nr_pages, nr_pages_iov);
77089 }
77090
77091 if (nr_pages == 0)
77092 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77093 goto free_proc_pages;
77094 }
77095
77096 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
77097 + rc = -EPERM;
77098 + goto put_task_struct;
77099 + }
77100 +
77101 mm = mm_access(task, PTRACE_MODE_ATTACH);
77102 if (!mm || IS_ERR(mm)) {
77103 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
77104 diff --git a/mm/rmap.c b/mm/rmap.c
77105 index 2ee1ef0..2e175ba 100644
77106 --- a/mm/rmap.c
77107 +++ b/mm/rmap.c
77108 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77109 struct anon_vma *anon_vma = vma->anon_vma;
77110 struct anon_vma_chain *avc;
77111
77112 +#ifdef CONFIG_PAX_SEGMEXEC
77113 + struct anon_vma_chain *avc_m = NULL;
77114 +#endif
77115 +
77116 might_sleep();
77117 if (unlikely(!anon_vma)) {
77118 struct mm_struct *mm = vma->vm_mm;
77119 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77120 if (!avc)
77121 goto out_enomem;
77122
77123 +#ifdef CONFIG_PAX_SEGMEXEC
77124 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
77125 + if (!avc_m)
77126 + goto out_enomem_free_avc;
77127 +#endif
77128 +
77129 anon_vma = find_mergeable_anon_vma(vma);
77130 allocated = NULL;
77131 if (!anon_vma) {
77132 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77133 /* page_table_lock to protect against threads */
77134 spin_lock(&mm->page_table_lock);
77135 if (likely(!vma->anon_vma)) {
77136 +
77137 +#ifdef CONFIG_PAX_SEGMEXEC
77138 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
77139 +
77140 + if (vma_m) {
77141 + BUG_ON(vma_m->anon_vma);
77142 + vma_m->anon_vma = anon_vma;
77143 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
77144 + avc_m = NULL;
77145 + }
77146 +#endif
77147 +
77148 vma->anon_vma = anon_vma;
77149 anon_vma_chain_link(vma, avc, anon_vma);
77150 allocated = NULL;
77151 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77152
77153 if (unlikely(allocated))
77154 put_anon_vma(allocated);
77155 +
77156 +#ifdef CONFIG_PAX_SEGMEXEC
77157 + if (unlikely(avc_m))
77158 + anon_vma_chain_free(avc_m);
77159 +#endif
77160 +
77161 if (unlikely(avc))
77162 anon_vma_chain_free(avc);
77163 }
77164 return 0;
77165
77166 out_enomem_free_avc:
77167 +
77168 +#ifdef CONFIG_PAX_SEGMEXEC
77169 + if (avc_m)
77170 + anon_vma_chain_free(avc_m);
77171 +#endif
77172 +
77173 anon_vma_chain_free(avc);
77174 out_enomem:
77175 return -ENOMEM;
77176 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
77177 * Attach the anon_vmas from src to dst.
77178 * Returns 0 on success, -ENOMEM on failure.
77179 */
77180 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77181 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
77182 {
77183 struct anon_vma_chain *avc, *pavc;
77184 struct anon_vma *root = NULL;
77185 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77186 * the corresponding VMA in the parent process is attached to.
77187 * Returns 0 on success, non-zero on failure.
77188 */
77189 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
77190 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
77191 {
77192 struct anon_vma_chain *avc;
77193 struct anon_vma *anon_vma;
77194 diff --git a/mm/shmem.c b/mm/shmem.c
77195 index 50c5b8f..0bc87f7 100644
77196 --- a/mm/shmem.c
77197 +++ b/mm/shmem.c
77198 @@ -31,7 +31,7 @@
77199 #include <linux/export.h>
77200 #include <linux/swap.h>
77201
77202 -static struct vfsmount *shm_mnt;
77203 +struct vfsmount *shm_mnt;
77204
77205 #ifdef CONFIG_SHMEM
77206 /*
77207 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
77208 #define BOGO_DIRENT_SIZE 20
77209
77210 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
77211 -#define SHORT_SYMLINK_LEN 128
77212 +#define SHORT_SYMLINK_LEN 64
77213
77214 /*
77215 * shmem_fallocate and shmem_writepage communicate via inode->i_private
77216 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
77217 static int shmem_xattr_validate(const char *name)
77218 {
77219 struct { const char *prefix; size_t len; } arr[] = {
77220 +
77221 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77222 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
77223 +#endif
77224 +
77225 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
77226 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
77227 };
77228 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
77229 if (err)
77230 return err;
77231
77232 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77233 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
77234 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
77235 + return -EOPNOTSUPP;
77236 + if (size > 8)
77237 + return -EINVAL;
77238 + }
77239 +#endif
77240 +
77241 return simple_xattr_set(&info->xattrs, name, value, size, flags);
77242 }
77243
77244 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
77245 int err = -ENOMEM;
77246
77247 /* Round up to L1_CACHE_BYTES to resist false sharing */
77248 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
77249 - L1_CACHE_BYTES), GFP_KERNEL);
77250 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
77251 if (!sbinfo)
77252 return -ENOMEM;
77253
77254 diff --git a/mm/slab.c b/mm/slab.c
77255 index 33d3363..3851c61 100644
77256 --- a/mm/slab.c
77257 +++ b/mm/slab.c
77258 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
77259
77260 /* Legal flag mask for kmem_cache_create(). */
77261 #if DEBUG
77262 -# define CREATE_MASK (SLAB_RED_ZONE | \
77263 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
77264 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
77265 SLAB_CACHE_DMA | \
77266 SLAB_STORE_USER | \
77267 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
77268 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77269 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
77270 #else
77271 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
77272 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
77273 SLAB_CACHE_DMA | \
77274 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
77275 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77276 @@ -322,7 +322,7 @@ struct kmem_list3 {
77277 * Need this for bootstrapping a per node allocator.
77278 */
77279 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
77280 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
77281 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
77282 #define CACHE_CACHE 0
77283 #define SIZE_AC MAX_NUMNODES
77284 #define SIZE_L3 (2 * MAX_NUMNODES)
77285 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
77286 if ((x)->max_freeable < i) \
77287 (x)->max_freeable = i; \
77288 } while (0)
77289 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
77290 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
77291 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
77292 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
77293 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
77294 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
77295 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
77296 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
77297 #else
77298 #define STATS_INC_ACTIVE(x) do { } while (0)
77299 #define STATS_DEC_ACTIVE(x) do { } while (0)
77300 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
77301 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
77302 */
77303 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
77304 - const struct slab *slab, void *obj)
77305 + const struct slab *slab, const void *obj)
77306 {
77307 u32 offset = (obj - slab->s_mem);
77308 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
77309 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
77310 struct cache_names {
77311 char *name;
77312 char *name_dma;
77313 + char *name_usercopy;
77314 };
77315
77316 static struct cache_names __initdata cache_names[] = {
77317 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
77318 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
77319 #include <linux/kmalloc_sizes.h>
77320 - {NULL,}
77321 + {NULL}
77322 #undef CACHE
77323 };
77324
77325 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
77326 if (unlikely(gfpflags & GFP_DMA))
77327 return csizep->cs_dmacachep;
77328 #endif
77329 +
77330 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77331 + if (unlikely(gfpflags & GFP_USERCOPY))
77332 + return csizep->cs_usercopycachep;
77333 +#endif
77334 +
77335 return csizep->cs_cachep;
77336 }
77337
77338 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
77339 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
77340 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
77341 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77342 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77343 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77344 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
77345
77346 if (INDEX_AC != INDEX_L3) {
77347 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
77348 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
77349 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
77350 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77351 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77352 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77353 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
77354 }
77355
77356 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
77357 sizes->cs_cachep->size = sizes->cs_size;
77358 sizes->cs_cachep->object_size = sizes->cs_size;
77359 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77360 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77361 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77362 list_add(&sizes->cs_cachep->list, &slab_caches);
77363 }
77364 #ifdef CONFIG_ZONE_DMA
77365 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
77366 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
77367 list_add(&sizes->cs_dmacachep->list, &slab_caches);
77368 #endif
77369 +
77370 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77371 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
77372 + sizes->cs_usercopycachep->name = names->name_usercopy;
77373 + sizes->cs_usercopycachep->size = sizes->cs_size;
77374 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
77375 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
77376 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
77377 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
77378 +#endif
77379 +
77380 sizes++;
77381 names++;
77382 }
77383 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
77384 }
77385 /* cpu stats */
77386 {
77387 - unsigned long allochit = atomic_read(&cachep->allochit);
77388 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
77389 - unsigned long freehit = atomic_read(&cachep->freehit);
77390 - unsigned long freemiss = atomic_read(&cachep->freemiss);
77391 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
77392 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
77393 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
77394 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
77395
77396 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
77397 allochit, allocmiss, freehit, freemiss);
77398 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
77399 {
77400 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
77401 #ifdef CONFIG_DEBUG_SLAB_LEAK
77402 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
77403 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
77404 #endif
77405 return 0;
77406 }
77407 module_init(slab_proc_init);
77408 #endif
77409
77410 +bool is_usercopy_object(const void *ptr)
77411 +{
77412 + struct page *page;
77413 + struct kmem_cache *cachep;
77414 +
77415 + if (ZERO_OR_NULL_PTR(ptr))
77416 + return false;
77417 +
77418 + if (!slab_is_available())
77419 + return false;
77420 +
77421 + if (!virt_addr_valid(ptr))
77422 + return false;
77423 +
77424 + page = virt_to_head_page(ptr);
77425 +
77426 + if (!PageSlab(page))
77427 + return false;
77428 +
77429 + cachep = page->slab_cache;
77430 + return cachep->flags & SLAB_USERCOPY;
77431 +}
77432 +
77433 +#ifdef CONFIG_PAX_USERCOPY
77434 +const char *check_heap_object(const void *ptr, unsigned long n)
77435 +{
77436 + struct page *page;
77437 + struct kmem_cache *cachep;
77438 + struct slab *slabp;
77439 + unsigned int objnr;
77440 + unsigned long offset;
77441 +
77442 + if (ZERO_OR_NULL_PTR(ptr))
77443 + return "<null>";
77444 +
77445 + if (!virt_addr_valid(ptr))
77446 + return NULL;
77447 +
77448 + page = virt_to_head_page(ptr);
77449 +
77450 + if (!PageSlab(page))
77451 + return NULL;
77452 +
77453 + cachep = page->slab_cache;
77454 + if (!(cachep->flags & SLAB_USERCOPY))
77455 + return cachep->name;
77456 +
77457 + slabp = page->slab_page;
77458 + objnr = obj_to_index(cachep, slabp, ptr);
77459 + BUG_ON(objnr >= cachep->num);
77460 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
77461 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
77462 + return NULL;
77463 +
77464 + return cachep->name;
77465 +}
77466 +#endif
77467 +
77468 /**
77469 * ksize - get the actual amount of memory allocated for a given object
77470 * @objp: Pointer to the object
77471 diff --git a/mm/slab_common.c b/mm/slab_common.c
77472 index 069a24e6..226a310 100644
77473 --- a/mm/slab_common.c
77474 +++ b/mm/slab_common.c
77475 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
77476 err = __kmem_cache_create(s, flags);
77477 if (!err) {
77478
77479 - s->refcount = 1;
77480 + atomic_set(&s->refcount, 1);
77481 list_add(&s->list, &slab_caches);
77482
77483 } else {
77484 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
77485 {
77486 get_online_cpus();
77487 mutex_lock(&slab_mutex);
77488 - s->refcount--;
77489 - if (!s->refcount) {
77490 + if (atomic_dec_and_test(&s->refcount)) {
77491 list_del(&s->list);
77492
77493 if (!__kmem_cache_shutdown(s)) {
77494 diff --git a/mm/slob.c b/mm/slob.c
77495 index 1e921c5..1ce12c2 100644
77496 --- a/mm/slob.c
77497 +++ b/mm/slob.c
77498 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
77499 /*
77500 * Return the size of a slob block.
77501 */
77502 -static slobidx_t slob_units(slob_t *s)
77503 +static slobidx_t slob_units(const slob_t *s)
77504 {
77505 if (s->units > 0)
77506 return s->units;
77507 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
77508 /*
77509 * Return the next free slob block pointer after this one.
77510 */
77511 -static slob_t *slob_next(slob_t *s)
77512 +static slob_t *slob_next(const slob_t *s)
77513 {
77514 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
77515 slobidx_t next;
77516 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
77517 /*
77518 * Returns true if s is the last free block in its page.
77519 */
77520 -static int slob_last(slob_t *s)
77521 +static int slob_last(const slob_t *s)
77522 {
77523 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
77524 }
77525
77526 -static void *slob_new_pages(gfp_t gfp, int order, int node)
77527 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
77528 {
77529 - void *page;
77530 + struct page *page;
77531
77532 #ifdef CONFIG_NUMA
77533 if (node != NUMA_NO_NODE)
77534 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
77535 if (!page)
77536 return NULL;
77537
77538 - return page_address(page);
77539 + __SetPageSlab(page);
77540 + return page;
77541 }
77542
77543 -static void slob_free_pages(void *b, int order)
77544 +static void slob_free_pages(struct page *sp, int order)
77545 {
77546 if (current->reclaim_state)
77547 current->reclaim_state->reclaimed_slab += 1 << order;
77548 - free_pages((unsigned long)b, order);
77549 + __ClearPageSlab(sp);
77550 + reset_page_mapcount(sp);
77551 + sp->private = 0;
77552 + __free_pages(sp, order);
77553 }
77554
77555 /*
77556 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
77557
77558 /* Not enough space: must allocate a new page */
77559 if (!b) {
77560 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77561 - if (!b)
77562 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77563 + if (!sp)
77564 return NULL;
77565 - sp = virt_to_page(b);
77566 - __SetPageSlab(sp);
77567 + b = page_address(sp);
77568
77569 spin_lock_irqsave(&slob_lock, flags);
77570 sp->units = SLOB_UNITS(PAGE_SIZE);
77571 sp->freelist = b;
77572 + sp->private = 0;
77573 INIT_LIST_HEAD(&sp->list);
77574 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
77575 set_slob_page_free(sp, slob_list);
77576 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
77577 if (slob_page_free(sp))
77578 clear_slob_page_free(sp);
77579 spin_unlock_irqrestore(&slob_lock, flags);
77580 - __ClearPageSlab(sp);
77581 - reset_page_mapcount(sp);
77582 - slob_free_pages(b, 0);
77583 + slob_free_pages(sp, 0);
77584 return;
77585 }
77586
77587 @@ -426,11 +428,10 @@ out:
77588 */
77589
77590 static __always_inline void *
77591 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77592 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
77593 {
77594 - unsigned int *m;
77595 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77596 - void *ret;
77597 + slob_t *m;
77598 + void *ret = NULL;
77599
77600 gfp &= gfp_allowed_mask;
77601
77602 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77603
77604 if (!m)
77605 return NULL;
77606 - *m = size;
77607 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
77608 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
77609 + m[0].units = size;
77610 + m[1].units = align;
77611 ret = (void *)m + align;
77612
77613 trace_kmalloc_node(caller, ret,
77614 size, size + align, gfp, node);
77615 } else {
77616 unsigned int order = get_order(size);
77617 + struct page *page;
77618
77619 if (likely(order))
77620 gfp |= __GFP_COMP;
77621 - ret = slob_new_pages(gfp, order, node);
77622 - if (ret) {
77623 - struct page *page;
77624 - page = virt_to_page(ret);
77625 + page = slob_new_pages(gfp, order, node);
77626 + if (page) {
77627 + ret = page_address(page);
77628 page->private = size;
77629 }
77630
77631 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77632 size, PAGE_SIZE << order, gfp, node);
77633 }
77634
77635 - kmemleak_alloc(ret, size, 1, gfp);
77636 + return ret;
77637 +}
77638 +
77639 +static __always_inline void *
77640 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77641 +{
77642 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77643 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
77644 +
77645 + if (!ZERO_OR_NULL_PTR(ret))
77646 + kmemleak_alloc(ret, size, 1, gfp);
77647 return ret;
77648 }
77649
77650 @@ -501,15 +515,91 @@ void kfree(const void *block)
77651 kmemleak_free(block);
77652
77653 sp = virt_to_page(block);
77654 - if (PageSlab(sp)) {
77655 + VM_BUG_ON(!PageSlab(sp));
77656 + if (!sp->private) {
77657 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77658 - unsigned int *m = (unsigned int *)(block - align);
77659 - slob_free(m, *m + align);
77660 - } else
77661 + slob_t *m = (slob_t *)(block - align);
77662 + slob_free(m, m[0].units + align);
77663 + } else {
77664 + __ClearPageSlab(sp);
77665 + reset_page_mapcount(sp);
77666 + sp->private = 0;
77667 put_page(sp);
77668 + }
77669 }
77670 EXPORT_SYMBOL(kfree);
77671
77672 +bool is_usercopy_object(const void *ptr)
77673 +{
77674 + if (!slab_is_available())
77675 + return false;
77676 +
77677 + // PAX: TODO
77678 +
77679 + return false;
77680 +}
77681 +
77682 +#ifdef CONFIG_PAX_USERCOPY
77683 +const char *check_heap_object(const void *ptr, unsigned long n)
77684 +{
77685 + struct page *page;
77686 + const slob_t *free;
77687 + const void *base;
77688 + unsigned long flags;
77689 +
77690 + if (ZERO_OR_NULL_PTR(ptr))
77691 + return "<null>";
77692 +
77693 + if (!virt_addr_valid(ptr))
77694 + return NULL;
77695 +
77696 + page = virt_to_head_page(ptr);
77697 + if (!PageSlab(page))
77698 + return NULL;
77699 +
77700 + if (page->private) {
77701 + base = page;
77702 + if (base <= ptr && n <= page->private - (ptr - base))
77703 + return NULL;
77704 + return "<slob>";
77705 + }
77706 +
77707 + /* some tricky double walking to find the chunk */
77708 + spin_lock_irqsave(&slob_lock, flags);
77709 + base = (void *)((unsigned long)ptr & PAGE_MASK);
77710 + free = page->freelist;
77711 +
77712 + while (!slob_last(free) && (void *)free <= ptr) {
77713 + base = free + slob_units(free);
77714 + free = slob_next(free);
77715 + }
77716 +
77717 + while (base < (void *)free) {
77718 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
77719 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
77720 + int offset;
77721 +
77722 + if (ptr < base + align)
77723 + break;
77724 +
77725 + offset = ptr - base - align;
77726 + if (offset >= m) {
77727 + base += size;
77728 + continue;
77729 + }
77730 +
77731 + if (n > m - offset)
77732 + break;
77733 +
77734 + spin_unlock_irqrestore(&slob_lock, flags);
77735 + return NULL;
77736 + }
77737 +
77738 + spin_unlock_irqrestore(&slob_lock, flags);
77739 + return "<slob>";
77740 +}
77741 +#endif
77742 +
77743 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
77744 size_t ksize(const void *block)
77745 {
77746 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
77747 return 0;
77748
77749 sp = virt_to_page(block);
77750 - if (PageSlab(sp)) {
77751 + VM_BUG_ON(!PageSlab(sp));
77752 + if (!sp->private) {
77753 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77754 - unsigned int *m = (unsigned int *)(block - align);
77755 - return SLOB_UNITS(*m) * SLOB_UNIT;
77756 + slob_t *m = (slob_t *)(block - align);
77757 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
77758 } else
77759 return sp->private;
77760 }
77761 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
77762
77763 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
77764 {
77765 - void *b;
77766 + void *b = NULL;
77767
77768 flags &= gfp_allowed_mask;
77769
77770 lockdep_trace_alloc(flags);
77771
77772 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77773 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
77774 +#else
77775 if (c->size < PAGE_SIZE) {
77776 b = slob_alloc(c->size, flags, c->align, node);
77777 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77778 SLOB_UNITS(c->size) * SLOB_UNIT,
77779 flags, node);
77780 } else {
77781 - b = slob_new_pages(flags, get_order(c->size), node);
77782 + struct page *sp;
77783 +
77784 + sp = slob_new_pages(flags, get_order(c->size), node);
77785 + if (sp) {
77786 + b = page_address(sp);
77787 + sp->private = c->size;
77788 + }
77789 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77790 PAGE_SIZE << get_order(c->size),
77791 flags, node);
77792 }
77793 +#endif
77794
77795 if (c->ctor)
77796 c->ctor(b);
77797 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
77798
77799 static void __kmem_cache_free(void *b, int size)
77800 {
77801 - if (size < PAGE_SIZE)
77802 + struct page *sp;
77803 +
77804 + sp = virt_to_page(b);
77805 + BUG_ON(!PageSlab(sp));
77806 + if (!sp->private)
77807 slob_free(b, size);
77808 else
77809 - slob_free_pages(b, get_order(size));
77810 + slob_free_pages(sp, get_order(size));
77811 }
77812
77813 static void kmem_rcu_free(struct rcu_head *head)
77814 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77815
77816 void kmem_cache_free(struct kmem_cache *c, void *b)
77817 {
77818 + int size = c->size;
77819 +
77820 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77821 + if (size + c->align < PAGE_SIZE) {
77822 + size += c->align;
77823 + b -= c->align;
77824 + }
77825 +#endif
77826 +
77827 kmemleak_free_recursive(b, c->flags);
77828 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77829 struct slob_rcu *slob_rcu;
77830 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77831 - slob_rcu->size = c->size;
77832 + slob_rcu = b + (size - sizeof(struct slob_rcu));
77833 + slob_rcu->size = size;
77834 call_rcu(&slob_rcu->head, kmem_rcu_free);
77835 } else {
77836 - __kmem_cache_free(b, c->size);
77837 + __kmem_cache_free(b, size);
77838 }
77839
77840 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77841 + trace_kfree(_RET_IP_, b);
77842 +#else
77843 trace_kmem_cache_free(_RET_IP_, b);
77844 +#endif
77845 +
77846 }
77847 EXPORT_SYMBOL(kmem_cache_free);
77848
77849 diff --git a/mm/slub.c b/mm/slub.c
77850 index 321afab..9595170 100644
77851 --- a/mm/slub.c
77852 +++ b/mm/slub.c
77853 @@ -201,7 +201,7 @@ struct track {
77854
77855 enum track_item { TRACK_ALLOC, TRACK_FREE };
77856
77857 -#ifdef CONFIG_SYSFS
77858 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77859 static int sysfs_slab_add(struct kmem_cache *);
77860 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77861 static void sysfs_slab_remove(struct kmem_cache *);
77862 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77863 if (!t->addr)
77864 return;
77865
77866 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77867 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77868 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77869 #ifdef CONFIG_STACKTRACE
77870 {
77871 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77872
77873 page = virt_to_head_page(x);
77874
77875 + BUG_ON(!PageSlab(page));
77876 +
77877 if (kmem_cache_debug(s) && page->slab != s) {
77878 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77879 " is from %s\n", page->slab->name, s->name);
77880 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
77881 * Merge control. If this is set then no merging of slab caches will occur.
77882 * (Could be removed. This was introduced to pacify the merge skeptics.)
77883 */
77884 -static int slub_nomerge;
77885 +static int slub_nomerge = 1;
77886
77887 /*
77888 * Calculate the order of allocation given an slab object size.
77889 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
77890 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
77891 #endif
77892
77893 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77894 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
77895 +#endif
77896 +
77897 static int __init setup_slub_min_order(char *str)
77898 {
77899 get_option(&str, &slub_min_order);
77900 @@ -3279,7 +3285,7 @@ static struct kmem_cache *__init create_kmalloc_cache(const char *name,
77901 if (kmem_cache_open(s, flags))
77902 goto panic;
77903
77904 - s->refcount = 1;
77905 + atomic_set(&s->refcount, 1);
77906 list_add(&s->list, &slab_caches);
77907 return s;
77908
77909 @@ -3343,6 +3349,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77910 return kmalloc_dma_caches[index];
77911
77912 #endif
77913 +
77914 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77915 + if (flags & SLAB_USERCOPY)
77916 + return kmalloc_usercopy_caches[index];
77917 +
77918 +#endif
77919 +
77920 return kmalloc_caches[index];
77921 }
77922
77923 @@ -3411,6 +3424,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
77924 EXPORT_SYMBOL(__kmalloc_node);
77925 #endif
77926
77927 +bool is_usercopy_object(const void *ptr)
77928 +{
77929 + struct page *page;
77930 + struct kmem_cache *s;
77931 +
77932 + if (ZERO_OR_NULL_PTR(ptr))
77933 + return false;
77934 +
77935 + if (!slab_is_available())
77936 + return false;
77937 +
77938 + if (!virt_addr_valid(ptr))
77939 + return false;
77940 +
77941 + page = virt_to_head_page(ptr);
77942 +
77943 + if (!PageSlab(page))
77944 + return false;
77945 +
77946 + s = page->slab;
77947 + return s->flags & SLAB_USERCOPY;
77948 +}
77949 +
77950 +#ifdef CONFIG_PAX_USERCOPY
77951 +const char *check_heap_object(const void *ptr, unsigned long n)
77952 +{
77953 + struct page *page;
77954 + struct kmem_cache *s;
77955 + unsigned long offset;
77956 +
77957 + if (ZERO_OR_NULL_PTR(ptr))
77958 + return "<null>";
77959 +
77960 + if (!virt_addr_valid(ptr))
77961 + return NULL;
77962 +
77963 + page = virt_to_head_page(ptr);
77964 +
77965 + if (!PageSlab(page))
77966 + return NULL;
77967 +
77968 + s = page->slab;
77969 + if (!(s->flags & SLAB_USERCOPY))
77970 + return s->name;
77971 +
77972 + offset = (ptr - page_address(page)) % s->size;
77973 + if (offset <= s->object_size && n <= s->object_size - offset)
77974 + return NULL;
77975 +
77976 + return s->name;
77977 +}
77978 +#endif
77979 +
77980 size_t ksize(const void *object)
77981 {
77982 struct page *page;
77983 @@ -3685,7 +3751,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
77984 int node;
77985
77986 list_add(&s->list, &slab_caches);
77987 - s->refcount = -1;
77988 + atomic_set(&s->refcount, -1);
77989
77990 for_each_node_state(node, N_NORMAL_MEMORY) {
77991 struct kmem_cache_node *n = get_node(s, node);
77992 @@ -3808,17 +3874,17 @@ void __init kmem_cache_init(void)
77993
77994 /* Caches that are not of the two-to-the-power-of size */
77995 if (KMALLOC_MIN_SIZE <= 32) {
77996 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
77997 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
77998 caches++;
77999 }
78000
78001 if (KMALLOC_MIN_SIZE <= 64) {
78002 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
78003 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
78004 caches++;
78005 }
78006
78007 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
78008 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
78009 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
78010 caches++;
78011 }
78012
78013 @@ -3860,6 +3926,22 @@ void __init kmem_cache_init(void)
78014 }
78015 }
78016 #endif
78017 +
78018 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78019 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
78020 + struct kmem_cache *s = kmalloc_caches[i];
78021 +
78022 + if (s && s->size) {
78023 + char *name = kasprintf(GFP_NOWAIT,
78024 + "usercopy-kmalloc-%d", s->object_size);
78025 +
78026 + BUG_ON(!name);
78027 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
78028 + s->object_size, SLAB_USERCOPY);
78029 + }
78030 + }
78031 +#endif
78032 +
78033 printk(KERN_INFO
78034 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
78035 " CPUs=%d, Nodes=%d\n",
78036 @@ -3886,7 +3968,7 @@ static int slab_unmergeable(struct kmem_cache *s)
78037 /*
78038 * We may have set a slab to be unmergeable during bootstrap.
78039 */
78040 - if (s->refcount < 0)
78041 + if (atomic_read(&s->refcount) < 0)
78042 return 1;
78043
78044 return 0;
78045 @@ -3940,7 +4022,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78046
78047 s = find_mergeable(size, align, flags, name, ctor);
78048 if (s) {
78049 - s->refcount++;
78050 + atomic_inc(&s->refcount);
78051 /*
78052 * Adjust the object sizes so that we clear
78053 * the complete object on kzalloc.
78054 @@ -3949,7 +4031,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78055 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
78056
78057 if (sysfs_slab_alias(s, name)) {
78058 - s->refcount--;
78059 + atomic_dec(&s->refcount);
78060 s = NULL;
78061 }
78062 }
78063 @@ -4064,7 +4146,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
78064 }
78065 #endif
78066
78067 -#ifdef CONFIG_SYSFS
78068 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78069 static int count_inuse(struct page *page)
78070 {
78071 return page->inuse;
78072 @@ -4451,12 +4533,12 @@ static void resiliency_test(void)
78073 validate_slab_cache(kmalloc_caches[9]);
78074 }
78075 #else
78076 -#ifdef CONFIG_SYSFS
78077 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78078 static void resiliency_test(void) {};
78079 #endif
78080 #endif
78081
78082 -#ifdef CONFIG_SYSFS
78083 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78084 enum slab_stat_type {
78085 SL_ALL, /* All slabs */
78086 SL_PARTIAL, /* Only partially allocated slabs */
78087 @@ -4700,7 +4782,7 @@ SLAB_ATTR_RO(ctor);
78088
78089 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
78090 {
78091 - return sprintf(buf, "%d\n", s->refcount - 1);
78092 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
78093 }
78094 SLAB_ATTR_RO(aliases);
78095
78096 @@ -5262,6 +5344,7 @@ static char *create_unique_id(struct kmem_cache *s)
78097 return name;
78098 }
78099
78100 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78101 static int sysfs_slab_add(struct kmem_cache *s)
78102 {
78103 int err;
78104 @@ -5324,6 +5407,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78105 kobject_del(&s->kobj);
78106 kobject_put(&s->kobj);
78107 }
78108 +#endif
78109
78110 /*
78111 * Need to buffer aliases during bootup until sysfs becomes
78112 @@ -5337,6 +5421,7 @@ struct saved_alias {
78113
78114 static struct saved_alias *alias_list;
78115
78116 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78117 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78118 {
78119 struct saved_alias *al;
78120 @@ -5359,6 +5444,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78121 alias_list = al;
78122 return 0;
78123 }
78124 +#endif
78125
78126 static int __init slab_sysfs_init(void)
78127 {
78128 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
78129 index 1b7e22a..3fcd4f3 100644
78130 --- a/mm/sparse-vmemmap.c
78131 +++ b/mm/sparse-vmemmap.c
78132 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
78133 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78134 if (!p)
78135 return NULL;
78136 - pud_populate(&init_mm, pud, p);
78137 + pud_populate_kernel(&init_mm, pud, p);
78138 }
78139 return pud;
78140 }
78141 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
78142 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78143 if (!p)
78144 return NULL;
78145 - pgd_populate(&init_mm, pgd, p);
78146 + pgd_populate_kernel(&init_mm, pgd, p);
78147 }
78148 return pgd;
78149 }
78150 diff --git a/mm/swap.c b/mm/swap.c
78151 index 6310dc2..3662b3f 100644
78152 --- a/mm/swap.c
78153 +++ b/mm/swap.c
78154 @@ -30,6 +30,7 @@
78155 #include <linux/backing-dev.h>
78156 #include <linux/memcontrol.h>
78157 #include <linux/gfp.h>
78158 +#include <linux/hugetlb.h>
78159
78160 #include "internal.h"
78161
78162 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
78163
78164 __page_cache_release(page);
78165 dtor = get_compound_page_dtor(page);
78166 + if (!PageHuge(page))
78167 + BUG_ON(dtor != free_compound_page);
78168 (*dtor)(page);
78169 }
78170
78171 diff --git a/mm/swapfile.c b/mm/swapfile.c
78172 index f91a255..9dcac21 100644
78173 --- a/mm/swapfile.c
78174 +++ b/mm/swapfile.c
78175 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
78176
78177 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
78178 /* Activity counter to indicate that a swapon or swapoff has occurred */
78179 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
78180 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
78181
78182 static inline unsigned char swap_count(unsigned char ent)
78183 {
78184 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
78185 }
78186 filp_close(swap_file, NULL);
78187 err = 0;
78188 - atomic_inc(&proc_poll_event);
78189 + atomic_inc_unchecked(&proc_poll_event);
78190 wake_up_interruptible(&proc_poll_wait);
78191
78192 out_dput:
78193 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
78194
78195 poll_wait(file, &proc_poll_wait, wait);
78196
78197 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
78198 - seq->poll_event = atomic_read(&proc_poll_event);
78199 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
78200 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78201 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
78202 }
78203
78204 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
78205 return ret;
78206
78207 seq = file->private_data;
78208 - seq->poll_event = atomic_read(&proc_poll_event);
78209 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78210 return 0;
78211 }
78212
78213 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
78214 (frontswap_map) ? "FS" : "");
78215
78216 mutex_unlock(&swapon_mutex);
78217 - atomic_inc(&proc_poll_event);
78218 + atomic_inc_unchecked(&proc_poll_event);
78219 wake_up_interruptible(&proc_poll_wait);
78220
78221 if (S_ISREG(inode->i_mode))
78222 diff --git a/mm/util.c b/mm/util.c
78223 index dc3036c..b6c7c9d 100644
78224 --- a/mm/util.c
78225 +++ b/mm/util.c
78226 @@ -292,6 +292,12 @@ done:
78227 void arch_pick_mmap_layout(struct mm_struct *mm)
78228 {
78229 mm->mmap_base = TASK_UNMAPPED_BASE;
78230 +
78231 +#ifdef CONFIG_PAX_RANDMMAP
78232 + if (mm->pax_flags & MF_PAX_RANDMMAP)
78233 + mm->mmap_base += mm->delta_mmap;
78234 +#endif
78235 +
78236 mm->get_unmapped_area = arch_get_unmapped_area;
78237 mm->unmap_area = arch_unmap_area;
78238 }
78239 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
78240 index 78e0830..bc6bbd8 100644
78241 --- a/mm/vmalloc.c
78242 +++ b/mm/vmalloc.c
78243 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
78244
78245 pte = pte_offset_kernel(pmd, addr);
78246 do {
78247 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78248 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78249 +
78250 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78251 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
78252 + BUG_ON(!pte_exec(*pte));
78253 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
78254 + continue;
78255 + }
78256 +#endif
78257 +
78258 + {
78259 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78260 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78261 + }
78262 } while (pte++, addr += PAGE_SIZE, addr != end);
78263 }
78264
78265 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78266 pte = pte_alloc_kernel(pmd, addr);
78267 if (!pte)
78268 return -ENOMEM;
78269 +
78270 + pax_open_kernel();
78271 do {
78272 struct page *page = pages[*nr];
78273
78274 - if (WARN_ON(!pte_none(*pte)))
78275 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78276 + if (pgprot_val(prot) & _PAGE_NX)
78277 +#endif
78278 +
78279 + if (!pte_none(*pte)) {
78280 + pax_close_kernel();
78281 + WARN_ON(1);
78282 return -EBUSY;
78283 - if (WARN_ON(!page))
78284 + }
78285 + if (!page) {
78286 + pax_close_kernel();
78287 + WARN_ON(1);
78288 return -ENOMEM;
78289 + }
78290 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
78291 (*nr)++;
78292 } while (pte++, addr += PAGE_SIZE, addr != end);
78293 + pax_close_kernel();
78294 return 0;
78295 }
78296
78297 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
78298 pmd_t *pmd;
78299 unsigned long next;
78300
78301 - pmd = pmd_alloc(&init_mm, pud, addr);
78302 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78303 if (!pmd)
78304 return -ENOMEM;
78305 do {
78306 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
78307 pud_t *pud;
78308 unsigned long next;
78309
78310 - pud = pud_alloc(&init_mm, pgd, addr);
78311 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
78312 if (!pud)
78313 return -ENOMEM;
78314 do {
78315 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
78316 * and fall back on vmalloc() if that fails. Others
78317 * just put it in the vmalloc space.
78318 */
78319 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
78320 +#ifdef CONFIG_MODULES
78321 +#ifdef MODULES_VADDR
78322 unsigned long addr = (unsigned long)x;
78323 if (addr >= MODULES_VADDR && addr < MODULES_END)
78324 return 1;
78325 #endif
78326 +
78327 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78328 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
78329 + return 1;
78330 +#endif
78331 +
78332 +#endif
78333 +
78334 return is_vmalloc_addr(x);
78335 }
78336
78337 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
78338
78339 if (!pgd_none(*pgd)) {
78340 pud_t *pud = pud_offset(pgd, addr);
78341 +#ifdef CONFIG_X86
78342 + if (!pud_large(*pud))
78343 +#endif
78344 if (!pud_none(*pud)) {
78345 pmd_t *pmd = pmd_offset(pud, addr);
78346 +#ifdef CONFIG_X86
78347 + if (!pmd_large(*pmd))
78348 +#endif
78349 if (!pmd_none(*pmd)) {
78350 pte_t *ptep, pte;
78351
78352 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
78353 * Allocate a region of KVA of the specified size and alignment, within the
78354 * vstart and vend.
78355 */
78356 -static struct vmap_area *alloc_vmap_area(unsigned long size,
78357 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
78358 unsigned long align,
78359 unsigned long vstart, unsigned long vend,
78360 int node, gfp_t gfp_mask)
78361 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
78362 struct vm_struct *area;
78363
78364 BUG_ON(in_interrupt());
78365 +
78366 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78367 + if (flags & VM_KERNEXEC) {
78368 + if (start != VMALLOC_START || end != VMALLOC_END)
78369 + return NULL;
78370 + start = (unsigned long)MODULES_EXEC_VADDR;
78371 + end = (unsigned long)MODULES_EXEC_END;
78372 + }
78373 +#endif
78374 +
78375 if (flags & VM_IOREMAP) {
78376 int bit = fls(size);
78377
78378 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78379 if (count > totalram_pages)
78380 return NULL;
78381
78382 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78383 + if (!(pgprot_val(prot) & _PAGE_NX))
78384 + flags |= VM_KERNEXEC;
78385 +#endif
78386 +
78387 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78388 __builtin_return_address(0));
78389 if (!area)
78390 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78391 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78392 goto fail;
78393
78394 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78395 + if (!(pgprot_val(prot) & _PAGE_NX))
78396 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78397 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78398 + else
78399 +#endif
78400 +
78401 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78402 start, end, node, gfp_mask, caller);
78403 if (!area)
78404 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78405 * For tight control over page level allocator and protection flags
78406 * use __vmalloc() instead.
78407 */
78408 -
78409 void *vmalloc_exec(unsigned long size)
78410 {
78411 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78412 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78413 -1, __builtin_return_address(0));
78414 }
78415
78416 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78417 unsigned long uaddr = vma->vm_start;
78418 unsigned long usize = vma->vm_end - vma->vm_start;
78419
78420 + BUG_ON(vma->vm_mirror);
78421 +
78422 if ((PAGE_SIZE-1) & (unsigned long)addr)
78423 return -EINVAL;
78424
78425 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78426 v->addr, v->addr + v->size, v->size);
78427
78428 if (v->caller)
78429 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78430 + seq_printf(m, " %pK", v->caller);
78431 +#else
78432 seq_printf(m, " %pS", v->caller);
78433 +#endif
78434
78435 if (v->nr_pages)
78436 seq_printf(m, " pages=%d", v->nr_pages);
78437 diff --git a/mm/vmstat.c b/mm/vmstat.c
78438 index c737057..a49753a 100644
78439 --- a/mm/vmstat.c
78440 +++ b/mm/vmstat.c
78441 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78442 *
78443 * vm_stat contains the global counters
78444 */
78445 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78446 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78447 EXPORT_SYMBOL(vm_stat);
78448
78449 #ifdef CONFIG_SMP
78450 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78451 v = p->vm_stat_diff[i];
78452 p->vm_stat_diff[i] = 0;
78453 local_irq_restore(flags);
78454 - atomic_long_add(v, &zone->vm_stat[i]);
78455 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78456 global_diff[i] += v;
78457 #ifdef CONFIG_NUMA
78458 /* 3 seconds idle till flush */
78459 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78460
78461 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78462 if (global_diff[i])
78463 - atomic_long_add(global_diff[i], &vm_stat[i]);
78464 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78465 }
78466
78467 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78468 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78469 if (pset->vm_stat_diff[i]) {
78470 int v = pset->vm_stat_diff[i];
78471 pset->vm_stat_diff[i] = 0;
78472 - atomic_long_add(v, &zone->vm_stat[i]);
78473 - atomic_long_add(v, &vm_stat[i]);
78474 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78475 + atomic_long_add_unchecked(v, &vm_stat[i]);
78476 }
78477 }
78478 #endif
78479 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78480 start_cpu_timer(cpu);
78481 #endif
78482 #ifdef CONFIG_PROC_FS
78483 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78484 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78485 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78486 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78487 + {
78488 + mode_t gr_mode = S_IRUGO;
78489 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
78490 + gr_mode = S_IRUSR;
78491 +#endif
78492 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78493 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78494 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78495 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78496 +#else
78497 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78498 +#endif
78499 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78500 + }
78501 #endif
78502 return 0;
78503 }
78504 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78505 index ee07072..593e3fd 100644
78506 --- a/net/8021q/vlan.c
78507 +++ b/net/8021q/vlan.c
78508 @@ -484,7 +484,7 @@ out:
78509 return NOTIFY_DONE;
78510 }
78511
78512 -static struct notifier_block vlan_notifier_block __read_mostly = {
78513 +static struct notifier_block vlan_notifier_block = {
78514 .notifier_call = vlan_device_event,
78515 };
78516
78517 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78518 err = -EPERM;
78519 if (!capable(CAP_NET_ADMIN))
78520 break;
78521 - if ((args.u.name_type >= 0) &&
78522 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78523 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78524 struct vlan_net *vn;
78525
78526 vn = net_generic(net, vlan_net_id);
78527 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78528 index 02efb25..41541a9 100644
78529 --- a/net/9p/trans_fd.c
78530 +++ b/net/9p/trans_fd.c
78531 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78532 oldfs = get_fs();
78533 set_fs(get_ds());
78534 /* The cast to a user pointer is valid due to the set_fs() */
78535 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78536 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78537 set_fs(oldfs);
78538
78539 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78540 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78541 index 876fbe8..8bbea9f 100644
78542 --- a/net/atm/atm_misc.c
78543 +++ b/net/atm/atm_misc.c
78544 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78545 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78546 return 1;
78547 atm_return(vcc, truesize);
78548 - atomic_inc(&vcc->stats->rx_drop);
78549 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78550 return 0;
78551 }
78552 EXPORT_SYMBOL(atm_charge);
78553 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78554 }
78555 }
78556 atm_return(vcc, guess);
78557 - atomic_inc(&vcc->stats->rx_drop);
78558 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78559 return NULL;
78560 }
78561 EXPORT_SYMBOL(atm_alloc_charge);
78562 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78563
78564 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78565 {
78566 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78567 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78568 __SONET_ITEMS
78569 #undef __HANDLE_ITEM
78570 }
78571 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78572
78573 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78574 {
78575 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78576 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78577 __SONET_ITEMS
78578 #undef __HANDLE_ITEM
78579 }
78580 diff --git a/net/atm/lec.h b/net/atm/lec.h
78581 index a86aff9..3a0d6f6 100644
78582 --- a/net/atm/lec.h
78583 +++ b/net/atm/lec.h
78584 @@ -48,7 +48,7 @@ struct lane2_ops {
78585 const u8 *tlvs, u32 sizeoftlvs);
78586 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78587 const u8 *tlvs, u32 sizeoftlvs);
78588 -};
78589 +} __no_const;
78590
78591 /*
78592 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78593 diff --git a/net/atm/proc.c b/net/atm/proc.c
78594 index 0d020de..011c7bb 100644
78595 --- a/net/atm/proc.c
78596 +++ b/net/atm/proc.c
78597 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78598 const struct k_atm_aal_stats *stats)
78599 {
78600 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78601 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78602 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78603 - atomic_read(&stats->rx_drop));
78604 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78605 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78606 + atomic_read_unchecked(&stats->rx_drop));
78607 }
78608
78609 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78610 diff --git a/net/atm/resources.c b/net/atm/resources.c
78611 index 0447d5d..3cf4728 100644
78612 --- a/net/atm/resources.c
78613 +++ b/net/atm/resources.c
78614 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78615 static void copy_aal_stats(struct k_atm_aal_stats *from,
78616 struct atm_aal_stats *to)
78617 {
78618 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78619 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78620 __AAL_STAT_ITEMS
78621 #undef __HANDLE_ITEM
78622 }
78623 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78624 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78625 struct atm_aal_stats *to)
78626 {
78627 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78628 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78629 __AAL_STAT_ITEMS
78630 #undef __HANDLE_ITEM
78631 }
78632 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78633 index c6fcc76..1270d14 100644
78634 --- a/net/batman-adv/bat_iv_ogm.c
78635 +++ b/net/batman-adv/bat_iv_ogm.c
78636 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78637
78638 /* randomize initial seqno to avoid collision */
78639 get_random_bytes(&random_seqno, sizeof(random_seqno));
78640 - atomic_set(&hard_iface->seqno, random_seqno);
78641 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78642
78643 hard_iface->packet_len = BATADV_OGM_HLEN;
78644 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78645 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78646 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78647
78648 /* change sequence number to network order */
78649 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78650 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78651 batadv_ogm_packet->seqno = htonl(seqno);
78652 - atomic_inc(&hard_iface->seqno);
78653 + atomic_inc_unchecked(&hard_iface->seqno);
78654
78655 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78656 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78657 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78658 return;
78659
78660 /* could be changed by schedule_own_packet() */
78661 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
78662 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78663
78664 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78665 has_directlink_flag = 1;
78666 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78667 index d112fd6..686a447 100644
78668 --- a/net/batman-adv/hard-interface.c
78669 +++ b/net/batman-adv/hard-interface.c
78670 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78671 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78672 dev_add_pack(&hard_iface->batman_adv_ptype);
78673
78674 - atomic_set(&hard_iface->frag_seqno, 1);
78675 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78676 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78677 hard_iface->net_dev->name);
78678
78679 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78680 /* This can't be called via a bat_priv callback because
78681 * we have no bat_priv yet.
78682 */
78683 - atomic_set(&hard_iface->seqno, 1);
78684 + atomic_set_unchecked(&hard_iface->seqno, 1);
78685 hard_iface->packet_buff = NULL;
78686
78687 return hard_iface;
78688 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78689 index ce0684a..4a0cbf1 100644
78690 --- a/net/batman-adv/soft-interface.c
78691 +++ b/net/batman-adv/soft-interface.c
78692 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78693 primary_if->net_dev->dev_addr, ETH_ALEN);
78694
78695 /* set broadcast sequence number */
78696 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78697 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78698 bcast_packet->seqno = htonl(seqno);
78699
78700 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78701 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78702 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78703
78704 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78705 - atomic_set(&bat_priv->bcast_seqno, 1);
78706 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78707 atomic_set(&bat_priv->tt.vn, 0);
78708 atomic_set(&bat_priv->tt.local_changes, 0);
78709 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78710 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78711 index ac1e07a..4c846e2 100644
78712 --- a/net/batman-adv/types.h
78713 +++ b/net/batman-adv/types.h
78714 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
78715 int16_t if_num;
78716 char if_status;
78717 struct net_device *net_dev;
78718 - atomic_t seqno;
78719 - atomic_t frag_seqno;
78720 + atomic_unchecked_t seqno;
78721 + atomic_unchecked_t frag_seqno;
78722 unsigned char *packet_buff;
78723 int packet_len;
78724 struct kobject *hardif_obj;
78725 @@ -244,7 +244,7 @@ struct batadv_priv {
78726 atomic_t orig_interval; /* uint */
78727 atomic_t hop_penalty; /* uint */
78728 atomic_t log_level; /* uint */
78729 - atomic_t bcast_seqno;
78730 + atomic_unchecked_t bcast_seqno;
78731 atomic_t bcast_queue_left;
78732 atomic_t batman_queue_left;
78733 char num_ifaces;
78734 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78735 index f397232..3206a33 100644
78736 --- a/net/batman-adv/unicast.c
78737 +++ b/net/batman-adv/unicast.c
78738 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78739 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78740 frag2->flags = large_tail;
78741
78742 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78743 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78744 frag1->seqno = htons(seqno - 1);
78745 frag2->seqno = htons(seqno);
78746
78747 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78748 index 07f0739..3c42e34 100644
78749 --- a/net/bluetooth/hci_sock.c
78750 +++ b/net/bluetooth/hci_sock.c
78751 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78752 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78753 }
78754
78755 - len = min_t(unsigned int, len, sizeof(uf));
78756 + len = min((size_t)len, sizeof(uf));
78757 if (copy_from_user(&uf, optval, len)) {
78758 err = -EFAULT;
78759 break;
78760 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78761 index a91239d..d7ed533 100644
78762 --- a/net/bluetooth/l2cap_core.c
78763 +++ b/net/bluetooth/l2cap_core.c
78764 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78765 break;
78766
78767 case L2CAP_CONF_RFC:
78768 - if (olen == sizeof(rfc))
78769 - memcpy(&rfc, (void *)val, olen);
78770 + if (olen != sizeof(rfc))
78771 + break;
78772 +
78773 + memcpy(&rfc, (void *)val, olen);
78774
78775 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78776 rfc.mode != chan->mode)
78777 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78778 index 083f2bf..799f9448 100644
78779 --- a/net/bluetooth/l2cap_sock.c
78780 +++ b/net/bluetooth/l2cap_sock.c
78781 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78782 struct sock *sk = sock->sk;
78783 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78784 struct l2cap_options opts;
78785 - int len, err = 0;
78786 + int err = 0;
78787 + size_t len = optlen;
78788 u32 opt;
78789
78790 BT_DBG("sk %p", sk);
78791 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78792 opts.max_tx = chan->max_tx;
78793 opts.txwin_size = chan->tx_win;
78794
78795 - len = min_t(unsigned int, sizeof(opts), optlen);
78796 + len = min(sizeof(opts), len);
78797 if (copy_from_user((char *) &opts, optval, len)) {
78798 err = -EFAULT;
78799 break;
78800 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78801 struct bt_security sec;
78802 struct bt_power pwr;
78803 struct l2cap_conn *conn;
78804 - int len, err = 0;
78805 + int err = 0;
78806 + size_t len = optlen;
78807 u32 opt;
78808
78809 BT_DBG("sk %p", sk);
78810 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78811
78812 sec.level = BT_SECURITY_LOW;
78813
78814 - len = min_t(unsigned int, sizeof(sec), optlen);
78815 + len = min(sizeof(sec), len);
78816 if (copy_from_user((char *) &sec, optval, len)) {
78817 err = -EFAULT;
78818 break;
78819 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78820
78821 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78822
78823 - len = min_t(unsigned int, sizeof(pwr), optlen);
78824 + len = min(sizeof(pwr), len);
78825 if (copy_from_user((char *) &pwr, optval, len)) {
78826 err = -EFAULT;
78827 break;
78828 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78829 index 868a909..d044bc3 100644
78830 --- a/net/bluetooth/rfcomm/sock.c
78831 +++ b/net/bluetooth/rfcomm/sock.c
78832 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78833 struct sock *sk = sock->sk;
78834 struct bt_security sec;
78835 int err = 0;
78836 - size_t len;
78837 + size_t len = optlen;
78838 u32 opt;
78839
78840 BT_DBG("sk %p", sk);
78841 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78842
78843 sec.level = BT_SECURITY_LOW;
78844
78845 - len = min_t(unsigned int, sizeof(sec), optlen);
78846 + len = min(sizeof(sec), len);
78847 if (copy_from_user((char *) &sec, optval, len)) {
78848 err = -EFAULT;
78849 break;
78850 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78851 index ccc2487..921073d 100644
78852 --- a/net/bluetooth/rfcomm/tty.c
78853 +++ b/net/bluetooth/rfcomm/tty.c
78854 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78855 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78856
78857 spin_lock_irqsave(&dev->port.lock, flags);
78858 - if (dev->port.count > 0) {
78859 + if (atomic_read(&dev->port.count) > 0) {
78860 spin_unlock_irqrestore(&dev->port.lock, flags);
78861 return;
78862 }
78863 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78864 return -ENODEV;
78865
78866 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78867 - dev->channel, dev->port.count);
78868 + dev->channel, atomic_read(&dev->port.count));
78869
78870 spin_lock_irqsave(&dev->port.lock, flags);
78871 - if (++dev->port.count > 1) {
78872 + if (atomic_inc_return(&dev->port.count) > 1) {
78873 spin_unlock_irqrestore(&dev->port.lock, flags);
78874 return 0;
78875 }
78876 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78877 return;
78878
78879 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78880 - dev->port.count);
78881 + atomic_read(&dev->port.count));
78882
78883 spin_lock_irqsave(&dev->port.lock, flags);
78884 - if (!--dev->port.count) {
78885 + if (!atomic_dec_return(&dev->port.count)) {
78886 spin_unlock_irqrestore(&dev->port.lock, flags);
78887 if (dev->tty_dev->parent)
78888 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78889 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78890 index 5fe2ff3..121d696 100644
78891 --- a/net/bridge/netfilter/ebtables.c
78892 +++ b/net/bridge/netfilter/ebtables.c
78893 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78894 tmp.valid_hooks = t->table->valid_hooks;
78895 }
78896 mutex_unlock(&ebt_mutex);
78897 - if (copy_to_user(user, &tmp, *len) != 0){
78898 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78899 BUGPRINT("c2u Didn't work\n");
78900 ret = -EFAULT;
78901 break;
78902 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78903 goto out;
78904 tmp.valid_hooks = t->valid_hooks;
78905
78906 - if (copy_to_user(user, &tmp, *len) != 0) {
78907 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78908 ret = -EFAULT;
78909 break;
78910 }
78911 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78912 tmp.entries_size = t->table->entries_size;
78913 tmp.valid_hooks = t->table->valid_hooks;
78914
78915 - if (copy_to_user(user, &tmp, *len) != 0) {
78916 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78917 ret = -EFAULT;
78918 break;
78919 }
78920 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
78921 index 44f270f..1f5602d 100644
78922 --- a/net/caif/cfctrl.c
78923 +++ b/net/caif/cfctrl.c
78924 @@ -10,6 +10,7 @@
78925 #include <linux/spinlock.h>
78926 #include <linux/slab.h>
78927 #include <linux/pkt_sched.h>
78928 +#include <linux/sched.h>
78929 #include <net/caif/caif_layer.h>
78930 #include <net/caif/cfpkt.h>
78931 #include <net/caif/cfctrl.h>
78932 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
78933 memset(&dev_info, 0, sizeof(dev_info));
78934 dev_info.id = 0xff;
78935 cfsrvl_init(&this->serv, 0, &dev_info, false);
78936 - atomic_set(&this->req_seq_no, 1);
78937 - atomic_set(&this->rsp_seq_no, 1);
78938 + atomic_set_unchecked(&this->req_seq_no, 1);
78939 + atomic_set_unchecked(&this->rsp_seq_no, 1);
78940 this->serv.layer.receive = cfctrl_recv;
78941 sprintf(this->serv.layer.name, "ctrl");
78942 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
78943 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
78944 struct cfctrl_request_info *req)
78945 {
78946 spin_lock_bh(&ctrl->info_list_lock);
78947 - atomic_inc(&ctrl->req_seq_no);
78948 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
78949 + atomic_inc_unchecked(&ctrl->req_seq_no);
78950 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
78951 list_add_tail(&req->list, &ctrl->list);
78952 spin_unlock_bh(&ctrl->info_list_lock);
78953 }
78954 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
78955 if (p != first)
78956 pr_warn("Requests are not received in order\n");
78957
78958 - atomic_set(&ctrl->rsp_seq_no,
78959 + atomic_set_unchecked(&ctrl->rsp_seq_no,
78960 p->sequence_no);
78961 list_del(&p->list);
78962 goto out;
78963 diff --git a/net/can/af_can.c b/net/can/af_can.c
78964 index ddac1ee..3ee0a78 100644
78965 --- a/net/can/af_can.c
78966 +++ b/net/can/af_can.c
78967 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
78968 };
78969
78970 /* notifier block for netdevice event */
78971 -static struct notifier_block can_netdev_notifier __read_mostly = {
78972 +static struct notifier_block can_netdev_notifier = {
78973 .notifier_call = can_notifier,
78974 };
78975
78976 diff --git a/net/can/gw.c b/net/can/gw.c
78977 index 1f5c978..ef714c7 100644
78978 --- a/net/can/gw.c
78979 +++ b/net/can/gw.c
78980 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78981 MODULE_ALIAS("can-gw");
78982
78983 static HLIST_HEAD(cgw_list);
78984 -static struct notifier_block notifier;
78985
78986 static struct kmem_cache *cgw_cache __read_mostly;
78987
78988 @@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
78989 return err;
78990 }
78991
78992 +static struct notifier_block notifier = {
78993 + .notifier_call = cgw_notifier
78994 +};
78995 +
78996 static __init int cgw_module_init(void)
78997 {
78998 printk(banner);
78999 @@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
79000 return -ENOMEM;
79001
79002 /* set notifier */
79003 - notifier.notifier_call = cgw_notifier;
79004 register_netdevice_notifier(&notifier);
79005
79006 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
79007 diff --git a/net/compat.c b/net/compat.c
79008 index 79ae884..17c5c09 100644
79009 --- a/net/compat.c
79010 +++ b/net/compat.c
79011 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79012 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79013 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79014 return -EFAULT;
79015 - kmsg->msg_name = compat_ptr(tmp1);
79016 - kmsg->msg_iov = compat_ptr(tmp2);
79017 - kmsg->msg_control = compat_ptr(tmp3);
79018 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79019 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79020 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79021 return 0;
79022 }
79023
79024 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79025
79026 if (kern_msg->msg_namelen) {
79027 if (mode == VERIFY_READ) {
79028 - int err = move_addr_to_kernel(kern_msg->msg_name,
79029 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
79030 kern_msg->msg_namelen,
79031 kern_address);
79032 if (err < 0)
79033 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79034 kern_msg->msg_name = NULL;
79035
79036 tot_len = iov_from_user_compat_to_kern(kern_iov,
79037 - (struct compat_iovec __user *)kern_msg->msg_iov,
79038 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
79039 kern_msg->msg_iovlen);
79040 if (tot_len >= 0)
79041 kern_msg->msg_iov = kern_iov;
79042 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79043
79044 #define CMSG_COMPAT_FIRSTHDR(msg) \
79045 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79046 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79047 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79048 (struct compat_cmsghdr __user *)NULL)
79049
79050 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79051 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79052 (ucmlen) <= (unsigned long) \
79053 ((mhdr)->msg_controllen - \
79054 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79055 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79056
79057 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79058 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79059 {
79060 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79061 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79062 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79063 msg->msg_controllen)
79064 return NULL;
79065 return (struct compat_cmsghdr __user *)ptr;
79066 @@ -219,7 +219,7 @@ Efault:
79067
79068 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
79069 {
79070 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79071 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79072 struct compat_cmsghdr cmhdr;
79073 struct compat_timeval ctv;
79074 struct compat_timespec cts[3];
79075 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79076
79077 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79078 {
79079 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79080 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79081 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79082 int fdnum = scm->fp->count;
79083 struct file **fp = scm->fp->fp;
79084 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
79085 return -EFAULT;
79086 old_fs = get_fs();
79087 set_fs(KERNEL_DS);
79088 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
79089 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
79090 set_fs(old_fs);
79091
79092 return err;
79093 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79094 len = sizeof(ktime);
79095 old_fs = get_fs();
79096 set_fs(KERNEL_DS);
79097 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79098 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79099 set_fs(old_fs);
79100
79101 if (!err) {
79102 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79103 case MCAST_JOIN_GROUP:
79104 case MCAST_LEAVE_GROUP:
79105 {
79106 - struct compat_group_req __user *gr32 = (void *)optval;
79107 + struct compat_group_req __user *gr32 = (void __user *)optval;
79108 struct group_req __user *kgr =
79109 compat_alloc_user_space(sizeof(struct group_req));
79110 u32 interface;
79111 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79112 case MCAST_BLOCK_SOURCE:
79113 case MCAST_UNBLOCK_SOURCE:
79114 {
79115 - struct compat_group_source_req __user *gsr32 = (void *)optval;
79116 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
79117 struct group_source_req __user *kgsr = compat_alloc_user_space(
79118 sizeof(struct group_source_req));
79119 u32 interface;
79120 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79121 }
79122 case MCAST_MSFILTER:
79123 {
79124 - struct compat_group_filter __user *gf32 = (void *)optval;
79125 + struct compat_group_filter __user *gf32 = (void __user *)optval;
79126 struct group_filter __user *kgf;
79127 u32 interface, fmode, numsrc;
79128
79129 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
79130 char __user *optval, int __user *optlen,
79131 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
79132 {
79133 - struct compat_group_filter __user *gf32 = (void *)optval;
79134 + struct compat_group_filter __user *gf32 = (void __user *)optval;
79135 struct group_filter __user *kgf;
79136 int __user *koptlen;
79137 u32 interface, fmode, numsrc;
79138 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
79139
79140 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
79141 return -EINVAL;
79142 - if (copy_from_user(a, args, nas[call]))
79143 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
79144 return -EFAULT;
79145 a0 = a[0];
79146 a1 = a[1];
79147 diff --git a/net/core/datagram.c b/net/core/datagram.c
79148 index 0337e2b..47914a0 100644
79149 --- a/net/core/datagram.c
79150 +++ b/net/core/datagram.c
79151 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
79152 }
79153
79154 kfree_skb(skb);
79155 - atomic_inc(&sk->sk_drops);
79156 + atomic_inc_unchecked(&sk->sk_drops);
79157 sk_mem_reclaim_partial(sk);
79158
79159 return err;
79160 diff --git a/net/core/dev.c b/net/core/dev.c
79161 index e5942bf..25998c3 100644
79162 --- a/net/core/dev.c
79163 +++ b/net/core/dev.c
79164 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
79165 if (no_module && capable(CAP_NET_ADMIN))
79166 no_module = request_module("netdev-%s", name);
79167 if (no_module && capable(CAP_SYS_MODULE)) {
79168 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
79169 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
79170 +#else
79171 if (!request_module("%s", name))
79172 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
79173 name);
79174 +#endif
79175 }
79176 }
79177 EXPORT_SYMBOL(dev_load);
79178 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79179 {
79180 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
79181 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
79182 - atomic_long_inc(&dev->rx_dropped);
79183 + atomic_long_inc_unchecked(&dev->rx_dropped);
79184 kfree_skb(skb);
79185 return NET_RX_DROP;
79186 }
79187 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79188 nf_reset(skb);
79189
79190 if (unlikely(!is_skb_forwardable(dev, skb))) {
79191 - atomic_long_inc(&dev->rx_dropped);
79192 + atomic_long_inc_unchecked(&dev->rx_dropped);
79193 kfree_skb(skb);
79194 return NET_RX_DROP;
79195 }
79196 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79197
79198 struct dev_gso_cb {
79199 void (*destructor)(struct sk_buff *skb);
79200 -};
79201 +} __no_const;
79202
79203 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79204
79205 @@ -2955,7 +2959,7 @@ enqueue:
79206
79207 local_irq_restore(flags);
79208
79209 - atomic_long_inc(&skb->dev->rx_dropped);
79210 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79211 kfree_skb(skb);
79212 return NET_RX_DROP;
79213 }
79214 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
79215 }
79216 EXPORT_SYMBOL(netif_rx_ni);
79217
79218 -static void net_tx_action(struct softirq_action *h)
79219 +static void net_tx_action(void)
79220 {
79221 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79222
79223 @@ -3358,7 +3362,7 @@ ncls:
79224 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
79225 } else {
79226 drop:
79227 - atomic_long_inc(&skb->dev->rx_dropped);
79228 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79229 kfree_skb(skb);
79230 /* Jamal, now you will not able to escape explaining
79231 * me how you were going to use this. :-)
79232 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
79233 }
79234 EXPORT_SYMBOL(netif_napi_del);
79235
79236 -static void net_rx_action(struct softirq_action *h)
79237 +static void net_rx_action(void)
79238 {
79239 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79240 unsigned long time_limit = jiffies + 2;
79241 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
79242 else
79243 seq_printf(seq, "%04x", ntohs(pt->type));
79244
79245 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79246 + seq_printf(seq, " %-8s %p\n",
79247 + pt->dev ? pt->dev->name : "", NULL);
79248 +#else
79249 seq_printf(seq, " %-8s %pF\n",
79250 pt->dev ? pt->dev->name : "", pt->func);
79251 +#endif
79252 }
79253
79254 return 0;
79255 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
79256 } else {
79257 netdev_stats_to_stats64(storage, &dev->stats);
79258 }
79259 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
79260 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
79261 return storage;
79262 }
79263 EXPORT_SYMBOL(dev_get_stats);
79264 diff --git a/net/core/flow.c b/net/core/flow.c
79265 index e318c7e..168b1d0 100644
79266 --- a/net/core/flow.c
79267 +++ b/net/core/flow.c
79268 @@ -61,7 +61,7 @@ struct flow_cache {
79269 struct timer_list rnd_timer;
79270 };
79271
79272 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
79273 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79274 EXPORT_SYMBOL(flow_cache_genid);
79275 static struct flow_cache flow_cache_global;
79276 static struct kmem_cache *flow_cachep __read_mostly;
79277 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
79278
79279 static int flow_entry_valid(struct flow_cache_entry *fle)
79280 {
79281 - if (atomic_read(&flow_cache_genid) != fle->genid)
79282 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
79283 return 0;
79284 if (fle->object && !fle->object->ops->check(fle->object))
79285 return 0;
79286 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
79287 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
79288 fcp->hash_count++;
79289 }
79290 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
79291 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
79292 flo = fle->object;
79293 if (!flo)
79294 goto ret_object;
79295 @@ -280,7 +280,7 @@ nocache:
79296 }
79297 flo = resolver(net, key, family, dir, flo, ctx);
79298 if (fle) {
79299 - fle->genid = atomic_read(&flow_cache_genid);
79300 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
79301 if (!IS_ERR(flo))
79302 fle->object = flo;
79303 else
79304 diff --git a/net/core/iovec.c b/net/core/iovec.c
79305 index 7e7aeb0..2a998cb 100644
79306 --- a/net/core/iovec.c
79307 +++ b/net/core/iovec.c
79308 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79309 if (m->msg_namelen) {
79310 if (mode == VERIFY_READ) {
79311 void __user *namep;
79312 - namep = (void __user __force *) m->msg_name;
79313 + namep = (void __force_user *) m->msg_name;
79314 err = move_addr_to_kernel(namep, m->msg_namelen,
79315 address);
79316 if (err < 0)
79317 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79318 }
79319
79320 size = m->msg_iovlen * sizeof(struct iovec);
79321 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
79322 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
79323 return -EFAULT;
79324
79325 m->msg_iov = iov;
79326 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79327 index fad649a..f2fdac4 100644
79328 --- a/net/core/rtnetlink.c
79329 +++ b/net/core/rtnetlink.c
79330 @@ -198,14 +198,16 @@ int __rtnl_register(int protocol, int msgtype,
79331 rtnl_msg_handlers[protocol] = tab;
79332 }
79333
79334 + pax_open_kernel();
79335 if (doit)
79336 - tab[msgindex].doit = doit;
79337 + *(void **)&tab[msgindex].doit = doit;
79338
79339 if (dumpit)
79340 - tab[msgindex].dumpit = dumpit;
79341 + *(void **)&tab[msgindex].dumpit = dumpit;
79342
79343 if (calcit)
79344 - tab[msgindex].calcit = calcit;
79345 + *(void **)&tab[msgindex].calcit = calcit;
79346 + pax_close_kernel();
79347
79348 return 0;
79349 }
79350 @@ -248,8 +250,10 @@ int rtnl_unregister(int protocol, int msgtype)
79351 if (rtnl_msg_handlers[protocol] == NULL)
79352 return -ENOENT;
79353
79354 - rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79355 - rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79356 + pax_open_kernel();
79357 + *(void **)&rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79358 + *(void **)&rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79359 + pax_close_kernel();
79360
79361 return 0;
79362 }
79363 diff --git a/net/core/scm.c b/net/core/scm.c
79364 index ab57084..0190c8f 100644
79365 --- a/net/core/scm.c
79366 +++ b/net/core/scm.c
79367 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
79368 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79369 {
79370 struct cmsghdr __user *cm
79371 - = (__force struct cmsghdr __user *)msg->msg_control;
79372 + = (struct cmsghdr __force_user *)msg->msg_control;
79373 struct cmsghdr cmhdr;
79374 int cmlen = CMSG_LEN(len);
79375 int err;
79376 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79377 err = -EFAULT;
79378 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79379 goto out;
79380 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79381 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79382 goto out;
79383 cmlen = CMSG_SPACE(len);
79384 if (msg->msg_controllen < cmlen)
79385 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79386 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79387 {
79388 struct cmsghdr __user *cm
79389 - = (__force struct cmsghdr __user*)msg->msg_control;
79390 + = (struct cmsghdr __force_user *)msg->msg_control;
79391
79392 int fdmax = 0;
79393 int fdnum = scm->fp->count;
79394 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79395 if (fdnum < fdmax)
79396 fdmax = fdnum;
79397
79398 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79399 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79400 i++, cmfptr++)
79401 {
79402 struct socket *sock;
79403 diff --git a/net/core/sock.c b/net/core/sock.c
79404 index 8a146cf..ee08914d 100644
79405 --- a/net/core/sock.c
79406 +++ b/net/core/sock.c
79407 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79408 struct sk_buff_head *list = &sk->sk_receive_queue;
79409
79410 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79411 - atomic_inc(&sk->sk_drops);
79412 + atomic_inc_unchecked(&sk->sk_drops);
79413 trace_sock_rcvqueue_full(sk, skb);
79414 return -ENOMEM;
79415 }
79416 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79417 return err;
79418
79419 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79420 - atomic_inc(&sk->sk_drops);
79421 + atomic_inc_unchecked(&sk->sk_drops);
79422 return -ENOBUFS;
79423 }
79424
79425 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79426 skb_dst_force(skb);
79427
79428 spin_lock_irqsave(&list->lock, flags);
79429 - skb->dropcount = atomic_read(&sk->sk_drops);
79430 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79431 __skb_queue_tail(list, skb);
79432 spin_unlock_irqrestore(&list->lock, flags);
79433
79434 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79435 skb->dev = NULL;
79436
79437 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79438 - atomic_inc(&sk->sk_drops);
79439 + atomic_inc_unchecked(&sk->sk_drops);
79440 goto discard_and_relse;
79441 }
79442 if (nested)
79443 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79444 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79445 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79446 bh_unlock_sock(sk);
79447 - atomic_inc(&sk->sk_drops);
79448 + atomic_inc_unchecked(&sk->sk_drops);
79449 goto discard_and_relse;
79450 }
79451
79452 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79453 struct timeval tm;
79454 } v;
79455
79456 - int lv = sizeof(int);
79457 - int len;
79458 + unsigned int lv = sizeof(int);
79459 + unsigned int len;
79460
79461 if (get_user(len, optlen))
79462 return -EFAULT;
79463 - if (len < 0)
79464 + if (len > INT_MAX)
79465 return -EINVAL;
79466
79467 memset(&v, 0, sizeof(v));
79468 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79469
79470 case SO_PEERNAME:
79471 {
79472 - char address[128];
79473 + char address[_K_SS_MAXSIZE];
79474
79475 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79476 return -ENOTCONN;
79477 - if (lv < len)
79478 + if (lv < len || sizeof address < len)
79479 return -EINVAL;
79480 if (copy_to_user(optval, address, len))
79481 return -EFAULT;
79482 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79483
79484 if (len > lv)
79485 len = lv;
79486 - if (copy_to_user(optval, &v, len))
79487 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
79488 return -EFAULT;
79489 lenout:
79490 if (put_user(len, optlen))
79491 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79492 */
79493 smp_wmb();
79494 atomic_set(&sk->sk_refcnt, 1);
79495 - atomic_set(&sk->sk_drops, 0);
79496 + atomic_set_unchecked(&sk->sk_drops, 0);
79497 }
79498 EXPORT_SYMBOL(sock_init_data);
79499
79500 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79501 index 602cd63..05c6c60 100644
79502 --- a/net/core/sock_diag.c
79503 +++ b/net/core/sock_diag.c
79504 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79505
79506 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79507 {
79508 +#ifndef CONFIG_GRKERNSEC_HIDESYM
79509 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79510 cookie[1] != INET_DIAG_NOCOOKIE) &&
79511 ((u32)(unsigned long)sk != cookie[0] ||
79512 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79513 return -ESTALE;
79514 else
79515 +#endif
79516 return 0;
79517 }
79518 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79519
79520 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79521 {
79522 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79523 + cookie[0] = 0;
79524 + cookie[1] = 0;
79525 +#else
79526 cookie[0] = (u32)(unsigned long)sk;
79527 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79528 +#endif
79529 }
79530 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79531
79532 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79533 index a55eecc..dd8428c 100644
79534 --- a/net/decnet/sysctl_net_decnet.c
79535 +++ b/net/decnet/sysctl_net_decnet.c
79536 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79537
79538 if (len > *lenp) len = *lenp;
79539
79540 - if (copy_to_user(buffer, addr, len))
79541 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
79542 return -EFAULT;
79543
79544 *lenp = len;
79545 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79546
79547 if (len > *lenp) len = *lenp;
79548
79549 - if (copy_to_user(buffer, devname, len))
79550 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
79551 return -EFAULT;
79552
79553 *lenp = len;
79554 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
79555 index 2a6abc1..c379ba7 100644
79556 --- a/net/ipv4/devinet.c
79557 +++ b/net/ipv4/devinet.c
79558 @@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
79559 if (!ifa) {
79560 ret = -ENOBUFS;
79561 ifa = inet_alloc_ifa();
79562 + if (!ifa)
79563 + break;
79564 INIT_HLIST_NODE(&ifa->hash);
79565 - if (!ifa)
79566 - break;
79567 if (colon)
79568 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
79569 else
79570 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79571 index 825c608..750ff29 100644
79572 --- a/net/ipv4/fib_frontend.c
79573 +++ b/net/ipv4/fib_frontend.c
79574 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79575 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79576 fib_sync_up(dev);
79577 #endif
79578 - atomic_inc(&net->ipv4.dev_addr_genid);
79579 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79580 rt_cache_flush(dev_net(dev));
79581 break;
79582 case NETDEV_DOWN:
79583 fib_del_ifaddr(ifa, NULL);
79584 - atomic_inc(&net->ipv4.dev_addr_genid);
79585 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79586 if (ifa->ifa_dev->ifa_list == NULL) {
79587 /* Last address was deleted from this interface.
79588 * Disable IP.
79589 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79590 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79591 fib_sync_up(dev);
79592 #endif
79593 - atomic_inc(&net->ipv4.dev_addr_genid);
79594 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79595 rt_cache_flush(net);
79596 break;
79597 case NETDEV_DOWN:
79598 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79599 index 71b125c..f4c70b0 100644
79600 --- a/net/ipv4/fib_semantics.c
79601 +++ b/net/ipv4/fib_semantics.c
79602 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79603 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79604 nh->nh_gw,
79605 nh->nh_parent->fib_scope);
79606 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79607 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79608
79609 return nh->nh_saddr;
79610 }
79611 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79612 index 7880af9..70f92a3 100644
79613 --- a/net/ipv4/inet_hashtables.c
79614 +++ b/net/ipv4/inet_hashtables.c
79615 @@ -18,12 +18,15 @@
79616 #include <linux/sched.h>
79617 #include <linux/slab.h>
79618 #include <linux/wait.h>
79619 +#include <linux/security.h>
79620
79621 #include <net/inet_connection_sock.h>
79622 #include <net/inet_hashtables.h>
79623 #include <net/secure_seq.h>
79624 #include <net/ip.h>
79625
79626 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79627 +
79628 /*
79629 * Allocate and initialize a new local port bind bucket.
79630 * The bindhash mutex for snum's hash chain must be held here.
79631 @@ -530,6 +533,8 @@ ok:
79632 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79633 spin_unlock(&head->lock);
79634
79635 + gr_update_task_in_ip_table(current, inet_sk(sk));
79636 +
79637 if (tw) {
79638 inet_twsk_deschedule(tw, death_row);
79639 while (twrefcnt) {
79640 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79641 index 000e3d2..5472da3 100644
79642 --- a/net/ipv4/inetpeer.c
79643 +++ b/net/ipv4/inetpeer.c
79644 @@ -503,8 +503,8 @@ relookup:
79645 if (p) {
79646 p->daddr = *daddr;
79647 atomic_set(&p->refcnt, 1);
79648 - atomic_set(&p->rid, 0);
79649 - atomic_set(&p->ip_id_count,
79650 + atomic_set_unchecked(&p->rid, 0);
79651 + atomic_set_unchecked(&p->ip_id_count,
79652 (daddr->family == AF_INET) ?
79653 secure_ip_id(daddr->addr.a4) :
79654 secure_ipv6_id(daddr->addr.a6));
79655 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79656 index 8d5cc75..821fd11 100644
79657 --- a/net/ipv4/ip_fragment.c
79658 +++ b/net/ipv4/ip_fragment.c
79659 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79660 return 0;
79661
79662 start = qp->rid;
79663 - end = atomic_inc_return(&peer->rid);
79664 + end = atomic_inc_return_unchecked(&peer->rid);
79665 qp->rid = end;
79666
79667 rc = qp->q.fragments && (end - start) > max;
79668 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79669 index 14bbfcf..644f472 100644
79670 --- a/net/ipv4/ip_sockglue.c
79671 +++ b/net/ipv4/ip_sockglue.c
79672 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79673 len = min_t(unsigned int, len, opt->optlen);
79674 if (put_user(len, optlen))
79675 return -EFAULT;
79676 - if (copy_to_user(optval, opt->__data, len))
79677 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79678 + copy_to_user(optval, opt->__data, len))
79679 return -EFAULT;
79680 return 0;
79681 }
79682 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79683 if (sk->sk_type != SOCK_STREAM)
79684 return -ENOPROTOOPT;
79685
79686 - msg.msg_control = optval;
79687 + msg.msg_control = (void __force_kernel *)optval;
79688 msg.msg_controllen = len;
79689 msg.msg_flags = flags;
79690
79691 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79692 index 798358b..73570b7 100644
79693 --- a/net/ipv4/ipconfig.c
79694 +++ b/net/ipv4/ipconfig.c
79695 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79696
79697 mm_segment_t oldfs = get_fs();
79698 set_fs(get_ds());
79699 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79700 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79701 set_fs(oldfs);
79702 return res;
79703 }
79704 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79705
79706 mm_segment_t oldfs = get_fs();
79707 set_fs(get_ds());
79708 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79709 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79710 set_fs(oldfs);
79711 return res;
79712 }
79713 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79714
79715 mm_segment_t oldfs = get_fs();
79716 set_fs(get_ds());
79717 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79718 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79719 set_fs(oldfs);
79720 return res;
79721 }
79722 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79723 index 97e61ea..cac1bbb 100644
79724 --- a/net/ipv4/netfilter/arp_tables.c
79725 +++ b/net/ipv4/netfilter/arp_tables.c
79726 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79727 #endif
79728
79729 static int get_info(struct net *net, void __user *user,
79730 - const int *len, int compat)
79731 + int len, int compat)
79732 {
79733 char name[XT_TABLE_MAXNAMELEN];
79734 struct xt_table *t;
79735 int ret;
79736
79737 - if (*len != sizeof(struct arpt_getinfo)) {
79738 - duprintf("length %u != %Zu\n", *len,
79739 + if (len != sizeof(struct arpt_getinfo)) {
79740 + duprintf("length %u != %Zu\n", len,
79741 sizeof(struct arpt_getinfo));
79742 return -EINVAL;
79743 }
79744 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79745 info.size = private->size;
79746 strcpy(info.name, name);
79747
79748 - if (copy_to_user(user, &info, *len) != 0)
79749 + if (copy_to_user(user, &info, len) != 0)
79750 ret = -EFAULT;
79751 else
79752 ret = 0;
79753 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79754
79755 switch (cmd) {
79756 case ARPT_SO_GET_INFO:
79757 - ret = get_info(sock_net(sk), user, len, 1);
79758 + ret = get_info(sock_net(sk), user, *len, 1);
79759 break;
79760 case ARPT_SO_GET_ENTRIES:
79761 ret = compat_get_entries(sock_net(sk), user, len);
79762 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79763
79764 switch (cmd) {
79765 case ARPT_SO_GET_INFO:
79766 - ret = get_info(sock_net(sk), user, len, 0);
79767 + ret = get_info(sock_net(sk), user, *len, 0);
79768 break;
79769
79770 case ARPT_SO_GET_ENTRIES:
79771 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79772 index 170b1fd..6105b91 100644
79773 --- a/net/ipv4/netfilter/ip_tables.c
79774 +++ b/net/ipv4/netfilter/ip_tables.c
79775 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79776 #endif
79777
79778 static int get_info(struct net *net, void __user *user,
79779 - const int *len, int compat)
79780 + int len, int compat)
79781 {
79782 char name[XT_TABLE_MAXNAMELEN];
79783 struct xt_table *t;
79784 int ret;
79785
79786 - if (*len != sizeof(struct ipt_getinfo)) {
79787 - duprintf("length %u != %zu\n", *len,
79788 + if (len != sizeof(struct ipt_getinfo)) {
79789 + duprintf("length %u != %zu\n", len,
79790 sizeof(struct ipt_getinfo));
79791 return -EINVAL;
79792 }
79793 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79794 info.size = private->size;
79795 strcpy(info.name, name);
79796
79797 - if (copy_to_user(user, &info, *len) != 0)
79798 + if (copy_to_user(user, &info, len) != 0)
79799 ret = -EFAULT;
79800 else
79801 ret = 0;
79802 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79803
79804 switch (cmd) {
79805 case IPT_SO_GET_INFO:
79806 - ret = get_info(sock_net(sk), user, len, 1);
79807 + ret = get_info(sock_net(sk), user, *len, 1);
79808 break;
79809 case IPT_SO_GET_ENTRIES:
79810 ret = compat_get_entries(sock_net(sk), user, len);
79811 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79812
79813 switch (cmd) {
79814 case IPT_SO_GET_INFO:
79815 - ret = get_info(sock_net(sk), user, len, 0);
79816 + ret = get_info(sock_net(sk), user, *len, 0);
79817 break;
79818
79819 case IPT_SO_GET_ENTRIES:
79820 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79821 index 8f3d054..c58d05d 100644
79822 --- a/net/ipv4/ping.c
79823 +++ b/net/ipv4/ping.c
79824 @@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79825 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79826 0, sock_i_ino(sp),
79827 atomic_read(&sp->sk_refcnt), sp,
79828 - atomic_read(&sp->sk_drops), len);
79829 + atomic_read_unchecked(&sp->sk_drops), len);
79830 }
79831
79832 static int ping_seq_show(struct seq_file *seq, void *v)
79833 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79834 index 73d1e4d..3af0e8f 100644
79835 --- a/net/ipv4/raw.c
79836 +++ b/net/ipv4/raw.c
79837 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79838 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79839 {
79840 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79841 - atomic_inc(&sk->sk_drops);
79842 + atomic_inc_unchecked(&sk->sk_drops);
79843 kfree_skb(skb);
79844 return NET_RX_DROP;
79845 }
79846 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79847
79848 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79849 {
79850 + struct icmp_filter filter;
79851 +
79852 if (optlen > sizeof(struct icmp_filter))
79853 optlen = sizeof(struct icmp_filter);
79854 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79855 + if (copy_from_user(&filter, optval, optlen))
79856 return -EFAULT;
79857 + raw_sk(sk)->filter = filter;
79858 return 0;
79859 }
79860
79861 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79862 {
79863 int len, ret = -EFAULT;
79864 + struct icmp_filter filter;
79865
79866 if (get_user(len, optlen))
79867 goto out;
79868 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79869 if (len > sizeof(struct icmp_filter))
79870 len = sizeof(struct icmp_filter);
79871 ret = -EFAULT;
79872 - if (put_user(len, optlen) ||
79873 - copy_to_user(optval, &raw_sk(sk)->filter, len))
79874 + filter = raw_sk(sk)->filter;
79875 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79876 goto out;
79877 ret = 0;
79878 out: return ret;
79879 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79880 0, 0L, 0,
79881 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79882 0, sock_i_ino(sp),
79883 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79884 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79885 }
79886
79887 static int raw_seq_show(struct seq_file *seq, void *v)
79888 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79889 index df25142..e92a82a 100644
79890 --- a/net/ipv4/route.c
79891 +++ b/net/ipv4/route.c
79892 @@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79893
79894 static __net_init int rt_genid_init(struct net *net)
79895 {
79896 - atomic_set(&net->rt_genid, 0);
79897 + atomic_set_unchecked(&net->rt_genid, 0);
79898 get_random_bytes(&net->ipv4.dev_addr_genid,
79899 sizeof(net->ipv4.dev_addr_genid));
79900 return 0;
79901 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
79902 index 181fc82..cc95f8c 100644
79903 --- a/net/ipv4/tcp_input.c
79904 +++ b/net/ipv4/tcp_input.c
79905 @@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
79906 * simplifies code)
79907 */
79908 static void
79909 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79910 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79911 struct sk_buff *head, struct sk_buff *tail,
79912 u32 start, u32 end)
79913 {
79914 @@ -5536,6 +5536,9 @@ slow_path:
79915 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
79916 goto csum_error;
79917
79918 + if (!th->ack)
79919 + goto discard;
79920 +
79921 /*
79922 * Standard slow path.
79923 */
79924 @@ -5544,7 +5547,7 @@ slow_path:
79925 return 0;
79926
79927 step5:
79928 - if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79929 + if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79930 goto discard;
79931
79932 /* ts_recent update must be made after we are sure that the packet
79933 @@ -5836,6 +5839,7 @@ discard:
79934 tcp_paws_reject(&tp->rx_opt, 0))
79935 goto discard_and_undo;
79936
79937 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
79938 if (th->syn) {
79939 /* We see SYN without ACK. It is attempt of
79940 * simultaneous connect with crossed SYNs.
79941 @@ -5886,6 +5890,7 @@ discard:
79942 goto discard;
79943 #endif
79944 }
79945 +#endif
79946 /* "fifth, if neither of the SYN or RST bits is set then
79947 * drop the segment and return."
79948 */
79949 @@ -5930,7 +5935,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79950 goto discard;
79951
79952 if (th->syn) {
79953 - if (th->fin)
79954 + if (th->fin || th->urg || th->psh)
79955 goto discard;
79956 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
79957 return 1;
79958 @@ -5977,11 +5982,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79959 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
79960 goto discard;
79961 }
79962 +
79963 + if (!th->ack)
79964 + goto discard;
79965 +
79966 if (!tcp_validate_incoming(sk, skb, th, 0))
79967 return 0;
79968
79969 /* step 5: check the ACK field */
79970 - if (th->ack) {
79971 + if (true) {
79972 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
79973
79974 switch (sk->sk_state) {
79975 @@ -6131,8 +6140,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79976 }
79977 break;
79978 }
79979 - } else
79980 - goto discard;
79981 + }
79982
79983 /* ts_recent update must be made after we are sure that the packet
79984 * is in window.
79985 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
79986 index bc3cb46..815ccd6 100644
79987 --- a/net/ipv4/tcp_ipv4.c
79988 +++ b/net/ipv4/tcp_ipv4.c
79989 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
79990 EXPORT_SYMBOL(sysctl_tcp_low_latency);
79991
79992
79993 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79994 +extern int grsec_enable_blackhole;
79995 +#endif
79996 +
79997 #ifdef CONFIG_TCP_MD5SIG
79998 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
79999 __be32 daddr, __be32 saddr, const struct tcphdr *th);
80000 @@ -1899,6 +1903,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80001 return 0;
80002
80003 reset:
80004 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80005 + if (!grsec_enable_blackhole)
80006 +#endif
80007 tcp_v4_send_reset(rsk, skb);
80008 discard:
80009 kfree_skb(skb);
80010 @@ -1999,12 +2006,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
80011 TCP_SKB_CB(skb)->sacked = 0;
80012
80013 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80014 - if (!sk)
80015 + if (!sk) {
80016 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80017 + ret = 1;
80018 +#endif
80019 goto no_tcp_socket;
80020 -
80021 + }
80022 process:
80023 - if (sk->sk_state == TCP_TIME_WAIT)
80024 + if (sk->sk_state == TCP_TIME_WAIT) {
80025 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80026 + ret = 2;
80027 +#endif
80028 goto do_time_wait;
80029 + }
80030
80031 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
80032 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80033 @@ -2055,6 +2069,10 @@ no_tcp_socket:
80034 bad_packet:
80035 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80036 } else {
80037 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80038 + if (!grsec_enable_blackhole || (ret == 1 &&
80039 + (skb->dev->flags & IFF_LOOPBACK)))
80040 +#endif
80041 tcp_v4_send_reset(NULL, skb);
80042 }
80043
80044 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80045 index a7302d9..e3ec754 100644
80046 --- a/net/ipv4/tcp_minisocks.c
80047 +++ b/net/ipv4/tcp_minisocks.c
80048 @@ -27,6 +27,10 @@
80049 #include <net/inet_common.h>
80050 #include <net/xfrm.h>
80051
80052 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80053 +extern int grsec_enable_blackhole;
80054 +#endif
80055 +
80056 int sysctl_tcp_syncookies __read_mostly = 1;
80057 EXPORT_SYMBOL(sysctl_tcp_syncookies);
80058
80059 @@ -742,7 +746,10 @@ embryonic_reset:
80060 * avoid becoming vulnerable to outside attack aiming at
80061 * resetting legit local connections.
80062 */
80063 - req->rsk_ops->send_reset(sk, skb);
80064 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80065 + if (!grsec_enable_blackhole)
80066 +#endif
80067 + req->rsk_ops->send_reset(sk, skb);
80068 } else if (fastopen) { /* received a valid RST pkt */
80069 reqsk_fastopen_remove(sk, req, true);
80070 tcp_reset(sk);
80071 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80072 index 4526fe6..1a34e43 100644
80073 --- a/net/ipv4/tcp_probe.c
80074 +++ b/net/ipv4/tcp_probe.c
80075 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80076 if (cnt + width >= len)
80077 break;
80078
80079 - if (copy_to_user(buf + cnt, tbuf, width))
80080 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80081 return -EFAULT;
80082 cnt += width;
80083 }
80084 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80085 index d47c1b4..b0584de 100644
80086 --- a/net/ipv4/tcp_timer.c
80087 +++ b/net/ipv4/tcp_timer.c
80088 @@ -22,6 +22,10 @@
80089 #include <linux/gfp.h>
80090 #include <net/tcp.h>
80091
80092 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80093 +extern int grsec_lastack_retries;
80094 +#endif
80095 +
80096 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80097 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80098 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80099 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
80100 }
80101 }
80102
80103 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80104 + if ((sk->sk_state == TCP_LAST_ACK) &&
80105 + (grsec_lastack_retries > 0) &&
80106 + (grsec_lastack_retries < retry_until))
80107 + retry_until = grsec_lastack_retries;
80108 +#endif
80109 +
80110 if (retransmits_timed_out(sk, retry_until,
80111 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
80112 /* Has it gone just too far? */
80113 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80114 index 79c8dbe..aceb1b6 100644
80115 --- a/net/ipv4/udp.c
80116 +++ b/net/ipv4/udp.c
80117 @@ -87,6 +87,7 @@
80118 #include <linux/types.h>
80119 #include <linux/fcntl.h>
80120 #include <linux/module.h>
80121 +#include <linux/security.h>
80122 #include <linux/socket.h>
80123 #include <linux/sockios.h>
80124 #include <linux/igmp.h>
80125 @@ -111,6 +112,10 @@
80126 #include <trace/events/skb.h>
80127 #include "udp_impl.h"
80128
80129 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80130 +extern int grsec_enable_blackhole;
80131 +#endif
80132 +
80133 struct udp_table udp_table __read_mostly;
80134 EXPORT_SYMBOL(udp_table);
80135
80136 @@ -569,6 +574,9 @@ found:
80137 return s;
80138 }
80139
80140 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80141 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80142 +
80143 /*
80144 * This routine is called by the ICMP module when it gets some
80145 * sort of error condition. If err < 0 then the socket should
80146 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80147 dport = usin->sin_port;
80148 if (dport == 0)
80149 return -EINVAL;
80150 +
80151 + err = gr_search_udp_sendmsg(sk, usin);
80152 + if (err)
80153 + return err;
80154 } else {
80155 if (sk->sk_state != TCP_ESTABLISHED)
80156 return -EDESTADDRREQ;
80157 +
80158 + err = gr_search_udp_sendmsg(sk, NULL);
80159 + if (err)
80160 + return err;
80161 +
80162 daddr = inet->inet_daddr;
80163 dport = inet->inet_dport;
80164 /* Open fast path for connected socket.
80165 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
80166 udp_lib_checksum_complete(skb)) {
80167 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80168 IS_UDPLITE(sk));
80169 - atomic_inc(&sk->sk_drops);
80170 + atomic_inc_unchecked(&sk->sk_drops);
80171 __skb_unlink(skb, rcvq);
80172 __skb_queue_tail(&list_kill, skb);
80173 }
80174 @@ -1194,6 +1211,10 @@ try_again:
80175 if (!skb)
80176 goto out;
80177
80178 + err = gr_search_udp_recvmsg(sk, skb);
80179 + if (err)
80180 + goto out_free;
80181 +
80182 ulen = skb->len - sizeof(struct udphdr);
80183 copied = len;
80184 if (copied > ulen)
80185 @@ -1227,7 +1248,7 @@ try_again:
80186 if (unlikely(err)) {
80187 trace_kfree_skb(skb, udp_recvmsg);
80188 if (!peeked) {
80189 - atomic_inc(&sk->sk_drops);
80190 + atomic_inc_unchecked(&sk->sk_drops);
80191 UDP_INC_STATS_USER(sock_net(sk),
80192 UDP_MIB_INERRORS, is_udplite);
80193 }
80194 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80195
80196 drop:
80197 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80198 - atomic_inc(&sk->sk_drops);
80199 + atomic_inc_unchecked(&sk->sk_drops);
80200 kfree_skb(skb);
80201 return -1;
80202 }
80203 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80204 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80205
80206 if (!skb1) {
80207 - atomic_inc(&sk->sk_drops);
80208 + atomic_inc_unchecked(&sk->sk_drops);
80209 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80210 IS_UDPLITE(sk));
80211 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80212 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80213 goto csum_error;
80214
80215 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80216 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80217 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80218 +#endif
80219 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80220
80221 /*
80222 @@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80223 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80224 0, sock_i_ino(sp),
80225 atomic_read(&sp->sk_refcnt), sp,
80226 - atomic_read(&sp->sk_drops), len);
80227 + atomic_read_unchecked(&sp->sk_drops), len);
80228 }
80229
80230 int udp4_seq_show(struct seq_file *seq, void *v)
80231 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80232 index 0424e4e..308dd43 100644
80233 --- a/net/ipv6/addrconf.c
80234 +++ b/net/ipv6/addrconf.c
80235 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80236 p.iph.ihl = 5;
80237 p.iph.protocol = IPPROTO_IPV6;
80238 p.iph.ttl = 64;
80239 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80240 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80241
80242 if (ops->ndo_do_ioctl) {
80243 mm_segment_t oldfs = get_fs();
80244 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
80245 index d5cb3c4..b3e38d0 100644
80246 --- a/net/ipv6/ip6_gre.c
80247 +++ b/net/ipv6/ip6_gre.c
80248 @@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
80249 }
80250
80251
80252 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
80253 +static struct inet6_protocol ip6gre_protocol = {
80254 .handler = ip6gre_rcv,
80255 .err_handler = ip6gre_err,
80256 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
80257 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80258 index e02faed..9780f28 100644
80259 --- a/net/ipv6/ipv6_sockglue.c
80260 +++ b/net/ipv6/ipv6_sockglue.c
80261 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80262 if (sk->sk_type != SOCK_STREAM)
80263 return -ENOPROTOOPT;
80264
80265 - msg.msg_control = optval;
80266 + msg.msg_control = (void __force_kernel *)optval;
80267 msg.msg_controllen = len;
80268 msg.msg_flags = flags;
80269
80270 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80271 index d7cb045..8c0ded6 100644
80272 --- a/net/ipv6/netfilter/ip6_tables.c
80273 +++ b/net/ipv6/netfilter/ip6_tables.c
80274 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
80275 #endif
80276
80277 static int get_info(struct net *net, void __user *user,
80278 - const int *len, int compat)
80279 + int len, int compat)
80280 {
80281 char name[XT_TABLE_MAXNAMELEN];
80282 struct xt_table *t;
80283 int ret;
80284
80285 - if (*len != sizeof(struct ip6t_getinfo)) {
80286 - duprintf("length %u != %zu\n", *len,
80287 + if (len != sizeof(struct ip6t_getinfo)) {
80288 + duprintf("length %u != %zu\n", len,
80289 sizeof(struct ip6t_getinfo));
80290 return -EINVAL;
80291 }
80292 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
80293 info.size = private->size;
80294 strcpy(info.name, name);
80295
80296 - if (copy_to_user(user, &info, *len) != 0)
80297 + if (copy_to_user(user, &info, len) != 0)
80298 ret = -EFAULT;
80299 else
80300 ret = 0;
80301 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80302
80303 switch (cmd) {
80304 case IP6T_SO_GET_INFO:
80305 - ret = get_info(sock_net(sk), user, len, 1);
80306 + ret = get_info(sock_net(sk), user, *len, 1);
80307 break;
80308 case IP6T_SO_GET_ENTRIES:
80309 ret = compat_get_entries(sock_net(sk), user, len);
80310 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80311
80312 switch (cmd) {
80313 case IP6T_SO_GET_INFO:
80314 - ret = get_info(sock_net(sk), user, len, 0);
80315 + ret = get_info(sock_net(sk), user, *len, 0);
80316 break;
80317
80318 case IP6T_SO_GET_ENTRIES:
80319 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80320 index d8e95c7..81422bc 100644
80321 --- a/net/ipv6/raw.c
80322 +++ b/net/ipv6/raw.c
80323 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
80324 {
80325 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
80326 skb_checksum_complete(skb)) {
80327 - atomic_inc(&sk->sk_drops);
80328 + atomic_inc_unchecked(&sk->sk_drops);
80329 kfree_skb(skb);
80330 return NET_RX_DROP;
80331 }
80332 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80333 struct raw6_sock *rp = raw6_sk(sk);
80334
80335 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80336 - atomic_inc(&sk->sk_drops);
80337 + atomic_inc_unchecked(&sk->sk_drops);
80338 kfree_skb(skb);
80339 return NET_RX_DROP;
80340 }
80341 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80342
80343 if (inet->hdrincl) {
80344 if (skb_checksum_complete(skb)) {
80345 - atomic_inc(&sk->sk_drops);
80346 + atomic_inc_unchecked(&sk->sk_drops);
80347 kfree_skb(skb);
80348 return NET_RX_DROP;
80349 }
80350 @@ -604,7 +604,7 @@ out:
80351 return err;
80352 }
80353
80354 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80355 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80356 struct flowi6 *fl6, struct dst_entry **dstp,
80357 unsigned int flags)
80358 {
80359 @@ -916,12 +916,15 @@ do_confirm:
80360 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80361 char __user *optval, int optlen)
80362 {
80363 + struct icmp6_filter filter;
80364 +
80365 switch (optname) {
80366 case ICMPV6_FILTER:
80367 if (optlen > sizeof(struct icmp6_filter))
80368 optlen = sizeof(struct icmp6_filter);
80369 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80370 + if (copy_from_user(&filter, optval, optlen))
80371 return -EFAULT;
80372 + raw6_sk(sk)->filter = filter;
80373 return 0;
80374 default:
80375 return -ENOPROTOOPT;
80376 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80377 char __user *optval, int __user *optlen)
80378 {
80379 int len;
80380 + struct icmp6_filter filter;
80381
80382 switch (optname) {
80383 case ICMPV6_FILTER:
80384 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80385 len = sizeof(struct icmp6_filter);
80386 if (put_user(len, optlen))
80387 return -EFAULT;
80388 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80389 + filter = raw6_sk(sk)->filter;
80390 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
80391 return -EFAULT;
80392 return 0;
80393 default:
80394 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80395 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80396 0,
80397 sock_i_ino(sp),
80398 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80399 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80400 }
80401
80402 static int raw6_seq_show(struct seq_file *seq, void *v)
80403 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80404 index 73f2a6b..f8049a1 100644
80405 --- a/net/ipv6/tcp_ipv6.c
80406 +++ b/net/ipv6/tcp_ipv6.c
80407 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80408 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80409 }
80410
80411 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80412 +extern int grsec_enable_blackhole;
80413 +#endif
80414 +
80415 static void tcp_v6_hash(struct sock *sk)
80416 {
80417 if (sk->sk_state != TCP_CLOSE) {
80418 @@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80419 return 0;
80420
80421 reset:
80422 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80423 + if (!grsec_enable_blackhole)
80424 +#endif
80425 tcp_v6_send_reset(sk, skb);
80426 discard:
80427 if (opt_skb)
80428 @@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80429 TCP_SKB_CB(skb)->sacked = 0;
80430
80431 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80432 - if (!sk)
80433 + if (!sk) {
80434 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80435 + ret = 1;
80436 +#endif
80437 goto no_tcp_socket;
80438 + }
80439
80440 process:
80441 - if (sk->sk_state == TCP_TIME_WAIT)
80442 + if (sk->sk_state == TCP_TIME_WAIT) {
80443 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80444 + ret = 2;
80445 +#endif
80446 goto do_time_wait;
80447 + }
80448
80449 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80450 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80451 @@ -1660,6 +1675,10 @@ no_tcp_socket:
80452 bad_packet:
80453 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80454 } else {
80455 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80456 + if (!grsec_enable_blackhole || (ret == 1 &&
80457 + (skb->dev->flags & IFF_LOOPBACK)))
80458 +#endif
80459 tcp_v6_send_reset(NULL, skb);
80460 }
80461
80462 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80463 index fc99972..69397e8 100644
80464 --- a/net/ipv6/udp.c
80465 +++ b/net/ipv6/udp.c
80466 @@ -51,6 +51,10 @@
80467 #include <trace/events/skb.h>
80468 #include "udp_impl.h"
80469
80470 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80471 +extern int grsec_enable_blackhole;
80472 +#endif
80473 +
80474 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80475 {
80476 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80477 @@ -395,7 +399,7 @@ try_again:
80478 if (unlikely(err)) {
80479 trace_kfree_skb(skb, udpv6_recvmsg);
80480 if (!peeked) {
80481 - atomic_inc(&sk->sk_drops);
80482 + atomic_inc_unchecked(&sk->sk_drops);
80483 if (is_udp4)
80484 UDP_INC_STATS_USER(sock_net(sk),
80485 UDP_MIB_INERRORS,
80486 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80487 return rc;
80488 drop:
80489 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80490 - atomic_inc(&sk->sk_drops);
80491 + atomic_inc_unchecked(&sk->sk_drops);
80492 kfree_skb(skb);
80493 return -1;
80494 }
80495 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80496 if (likely(skb1 == NULL))
80497 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80498 if (!skb1) {
80499 - atomic_inc(&sk->sk_drops);
80500 + atomic_inc_unchecked(&sk->sk_drops);
80501 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80502 IS_UDPLITE(sk));
80503 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80504 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80505 goto discard;
80506
80507 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80508 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80509 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80510 +#endif
80511 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80512
80513 kfree_skb(skb);
80514 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80515 0,
80516 sock_i_ino(sp),
80517 atomic_read(&sp->sk_refcnt), sp,
80518 - atomic_read(&sp->sk_drops));
80519 + atomic_read_unchecked(&sp->sk_drops));
80520 }
80521
80522 int udp6_seq_show(struct seq_file *seq, void *v)
80523 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80524 index 496ce2c..f79fac8 100644
80525 --- a/net/irda/ircomm/ircomm_tty.c
80526 +++ b/net/irda/ircomm/ircomm_tty.c
80527 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80528 add_wait_queue(&port->open_wait, &wait);
80529
80530 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80531 - __FILE__, __LINE__, tty->driver->name, port->count);
80532 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80533
80534 spin_lock_irqsave(&port->lock, flags);
80535 if (!tty_hung_up_p(filp)) {
80536 extra_count = 1;
80537 - port->count--;
80538 + atomic_dec(&port->count);
80539 }
80540 spin_unlock_irqrestore(&port->lock, flags);
80541 port->blocked_open++;
80542 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80543 }
80544
80545 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80546 - __FILE__, __LINE__, tty->driver->name, port->count);
80547 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80548
80549 schedule();
80550 }
80551 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80552 if (extra_count) {
80553 /* ++ is not atomic, so this should be protected - Jean II */
80554 spin_lock_irqsave(&port->lock, flags);
80555 - port->count++;
80556 + atomic_inc(&port->count);
80557 spin_unlock_irqrestore(&port->lock, flags);
80558 }
80559 port->blocked_open--;
80560
80561 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80562 - __FILE__, __LINE__, tty->driver->name, port->count);
80563 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80564
80565 if (!retval)
80566 port->flags |= ASYNC_NORMAL_ACTIVE;
80567 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80568
80569 /* ++ is not atomic, so this should be protected - Jean II */
80570 spin_lock_irqsave(&self->port.lock, flags);
80571 - self->port.count++;
80572 + atomic_inc(&self->port.count);
80573 spin_unlock_irqrestore(&self->port.lock, flags);
80574 tty_port_tty_set(&self->port, tty);
80575
80576 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80577 - self->line, self->port.count);
80578 + self->line, atomic_read(&self->port.count));
80579
80580 /* Not really used by us, but lets do it anyway */
80581 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80582 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80583 tty_kref_put(port->tty);
80584 }
80585 port->tty = NULL;
80586 - port->count = 0;
80587 + atomic_set(&port->count, 0);
80588 spin_unlock_irqrestore(&port->lock, flags);
80589
80590 wake_up_interruptible(&port->open_wait);
80591 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80592 seq_putc(m, '\n');
80593
80594 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80595 - seq_printf(m, "Open count: %d\n", self->port.count);
80596 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80597 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80598 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80599
80600 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80601 index cd6f7a9..e63fe89 100644
80602 --- a/net/iucv/af_iucv.c
80603 +++ b/net/iucv/af_iucv.c
80604 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80605
80606 write_lock_bh(&iucv_sk_list.lock);
80607
80608 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80609 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80610 while (__iucv_get_sock_by_name(name)) {
80611 sprintf(name, "%08x",
80612 - atomic_inc_return(&iucv_sk_list.autobind_name));
80613 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80614 }
80615
80616 write_unlock_bh(&iucv_sk_list.lock);
80617 diff --git a/net/key/af_key.c b/net/key/af_key.c
80618 index 08897a3..0b812ab 100644
80619 --- a/net/key/af_key.c
80620 +++ b/net/key/af_key.c
80621 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80622 static u32 get_acqseq(void)
80623 {
80624 u32 res;
80625 - static atomic_t acqseq;
80626 + static atomic_unchecked_t acqseq;
80627
80628 do {
80629 - res = atomic_inc_return(&acqseq);
80630 + res = atomic_inc_return_unchecked(&acqseq);
80631 } while (!res);
80632 return res;
80633 }
80634 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80635 index 494da7f..6ce2ffd 100644
80636 --- a/net/mac80211/cfg.c
80637 +++ b/net/mac80211/cfg.c
80638 @@ -2604,7 +2604,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80639 else
80640 local->probe_req_reg--;
80641
80642 - if (!local->open_count)
80643 + if (!local_read(&local->open_count))
80644 break;
80645
80646 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80647 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80648 index 493e2e8..be76574 100644
80649 --- a/net/mac80211/ieee80211_i.h
80650 +++ b/net/mac80211/ieee80211_i.h
80651 @@ -28,6 +28,7 @@
80652 #include <net/ieee80211_radiotap.h>
80653 #include <net/cfg80211.h>
80654 #include <net/mac80211.h>
80655 +#include <asm/local.h>
80656 #include "key.h"
80657 #include "sta_info.h"
80658 #include "debug.h"
80659 @@ -852,7 +853,7 @@ struct ieee80211_local {
80660 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80661 spinlock_t queue_stop_reason_lock;
80662
80663 - int open_count;
80664 + local_t open_count;
80665 int monitors, cooked_mntrs;
80666 /* number of interfaces with corresponding FIF_ flags */
80667 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80668 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80669 index 0f5af91..4dba9e7 100644
80670 --- a/net/mac80211/iface.c
80671 +++ b/net/mac80211/iface.c
80672 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80673 break;
80674 }
80675
80676 - if (local->open_count == 0) {
80677 + if (local_read(&local->open_count) == 0) {
80678 res = drv_start(local);
80679 if (res)
80680 goto err_del_bss;
80681 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80682 break;
80683 }
80684
80685 - if (local->monitors == 0 && local->open_count == 0) {
80686 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80687 res = ieee80211_add_virtual_monitor(local);
80688 if (res)
80689 goto err_stop;
80690 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80691 mutex_unlock(&local->mtx);
80692
80693 if (coming_up)
80694 - local->open_count++;
80695 + local_inc(&local->open_count);
80696
80697 if (hw_reconf_flags)
80698 ieee80211_hw_config(local, hw_reconf_flags);
80699 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80700 err_del_interface:
80701 drv_remove_interface(local, sdata);
80702 err_stop:
80703 - if (!local->open_count)
80704 + if (!local_read(&local->open_count))
80705 drv_stop(local);
80706 err_del_bss:
80707 sdata->bss = NULL;
80708 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80709 }
80710
80711 if (going_down)
80712 - local->open_count--;
80713 + local_dec(&local->open_count);
80714
80715 switch (sdata->vif.type) {
80716 case NL80211_IFTYPE_AP_VLAN:
80717 @@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80718
80719 ieee80211_recalc_ps(local, -1);
80720
80721 - if (local->open_count == 0) {
80722 + if (local_read(&local->open_count) == 0) {
80723 if (local->ops->napi_poll)
80724 napi_disable(&local->napi);
80725 ieee80211_clear_tx_pending(local);
80726 @@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80727 }
80728 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80729
80730 - if (local->monitors == local->open_count && local->monitors > 0)
80731 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80732 ieee80211_add_virtual_monitor(local);
80733 }
80734
80735 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80736 index f57f597..e0a7c03 100644
80737 --- a/net/mac80211/main.c
80738 +++ b/net/mac80211/main.c
80739 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80740 local->hw.conf.power_level = power;
80741 }
80742
80743 - if (changed && local->open_count) {
80744 + if (changed && local_read(&local->open_count)) {
80745 ret = drv_config(local, changed);
80746 /*
80747 * Goal:
80748 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80749 index 5c572e7..ecf75ce 100644
80750 --- a/net/mac80211/pm.c
80751 +++ b/net/mac80211/pm.c
80752 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80753 struct ieee80211_sub_if_data *sdata;
80754 struct sta_info *sta;
80755
80756 - if (!local->open_count)
80757 + if (!local_read(&local->open_count))
80758 goto suspend;
80759
80760 ieee80211_scan_cancel(local);
80761 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80762 cancel_work_sync(&local->dynamic_ps_enable_work);
80763 del_timer_sync(&local->dynamic_ps_timer);
80764
80765 - local->wowlan = wowlan && local->open_count;
80766 + local->wowlan = wowlan && local_read(&local->open_count);
80767 if (local->wowlan) {
80768 int err = drv_suspend(local, wowlan);
80769 if (err < 0) {
80770 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80771 drv_remove_interface(local, sdata);
80772
80773 /* stop hardware - this must stop RX */
80774 - if (local->open_count)
80775 + if (local_read(&local->open_count))
80776 ieee80211_stop_device(local);
80777
80778 suspend:
80779 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80780 index 3313c11..bec9f17 100644
80781 --- a/net/mac80211/rate.c
80782 +++ b/net/mac80211/rate.c
80783 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80784
80785 ASSERT_RTNL();
80786
80787 - if (local->open_count)
80788 + if (local_read(&local->open_count))
80789 return -EBUSY;
80790
80791 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80792 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80793 index c97a065..ff61928 100644
80794 --- a/net/mac80211/rc80211_pid_debugfs.c
80795 +++ b/net/mac80211/rc80211_pid_debugfs.c
80796 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80797
80798 spin_unlock_irqrestore(&events->lock, status);
80799
80800 - if (copy_to_user(buf, pb, p))
80801 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80802 return -EFAULT;
80803
80804 return p;
80805 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80806 index 0151ae3..26709d3 100644
80807 --- a/net/mac80211/util.c
80808 +++ b/net/mac80211/util.c
80809 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80810 }
80811 #endif
80812 /* everything else happens only if HW was up & running */
80813 - if (!local->open_count)
80814 + if (!local_read(&local->open_count))
80815 goto wake_up;
80816
80817 /*
80818 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80819 index 49e96df..63a51c3 100644
80820 --- a/net/netfilter/Kconfig
80821 +++ b/net/netfilter/Kconfig
80822 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
80823
80824 To compile it as a module, choose M here. If unsure, say N.
80825
80826 +config NETFILTER_XT_MATCH_GRADM
80827 + tristate '"gradm" match support'
80828 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80829 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80830 + ---help---
80831 + The gradm match allows to match on grsecurity RBAC being enabled.
80832 + It is useful when iptables rules are applied early on bootup to
80833 + prevent connections to the machine (except from a trusted host)
80834 + while the RBAC system is disabled.
80835 +
80836 config NETFILTER_XT_MATCH_HASHLIMIT
80837 tristate '"hashlimit" match support'
80838 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80839 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80840 index 3259697..54d5393 100644
80841 --- a/net/netfilter/Makefile
80842 +++ b/net/netfilter/Makefile
80843 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80844 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80845 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80846 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80847 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80848 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80849 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80850 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80851 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80852 index 1548df9..98ad9b4 100644
80853 --- a/net/netfilter/ipvs/ip_vs_conn.c
80854 +++ b/net/netfilter/ipvs/ip_vs_conn.c
80855 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80856 /* Increase the refcnt counter of the dest */
80857 atomic_inc(&dest->refcnt);
80858
80859 - conn_flags = atomic_read(&dest->conn_flags);
80860 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
80861 if (cp->protocol != IPPROTO_UDP)
80862 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80863 flags = cp->flags;
80864 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80865 atomic_set(&cp->refcnt, 1);
80866
80867 atomic_set(&cp->n_control, 0);
80868 - atomic_set(&cp->in_pkts, 0);
80869 + atomic_set_unchecked(&cp->in_pkts, 0);
80870
80871 atomic_inc(&ipvs->conn_count);
80872 if (flags & IP_VS_CONN_F_NO_CPORT)
80873 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80874
80875 /* Don't drop the entry if its number of incoming packets is not
80876 located in [0, 8] */
80877 - i = atomic_read(&cp->in_pkts);
80878 + i = atomic_read_unchecked(&cp->in_pkts);
80879 if (i > 8 || i < 0) return 0;
80880
80881 if (!todrop_rate[i]) return 0;
80882 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80883 index 58918e2..4d177a9 100644
80884 --- a/net/netfilter/ipvs/ip_vs_core.c
80885 +++ b/net/netfilter/ipvs/ip_vs_core.c
80886 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80887 ret = cp->packet_xmit(skb, cp, pd->pp);
80888 /* do not touch skb anymore */
80889
80890 - atomic_inc(&cp->in_pkts);
80891 + atomic_inc_unchecked(&cp->in_pkts);
80892 ip_vs_conn_put(cp);
80893 return ret;
80894 }
80895 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
80896 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
80897 pkts = sysctl_sync_threshold(ipvs);
80898 else
80899 - pkts = atomic_add_return(1, &cp->in_pkts);
80900 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80901
80902 if (ipvs->sync_state & IP_VS_STATE_MASTER)
80903 ip_vs_sync_conn(net, cp, pkts);
80904 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
80905 index c4ee437..a774a74 100644
80906 --- a/net/netfilter/ipvs/ip_vs_ctl.c
80907 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
80908 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
80909 ip_vs_rs_hash(ipvs, dest);
80910 write_unlock_bh(&ipvs->rs_lock);
80911 }
80912 - atomic_set(&dest->conn_flags, conn_flags);
80913 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
80914
80915 /* bind the service */
80916 if (!dest->svc) {
80917 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80918 " %-7s %-6d %-10d %-10d\n",
80919 &dest->addr.in6,
80920 ntohs(dest->port),
80921 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80922 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80923 atomic_read(&dest->weight),
80924 atomic_read(&dest->activeconns),
80925 atomic_read(&dest->inactconns));
80926 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80927 "%-7s %-6d %-10d %-10d\n",
80928 ntohl(dest->addr.ip),
80929 ntohs(dest->port),
80930 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80931 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80932 atomic_read(&dest->weight),
80933 atomic_read(&dest->activeconns),
80934 atomic_read(&dest->inactconns));
80935 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
80936
80937 entry.addr = dest->addr.ip;
80938 entry.port = dest->port;
80939 - entry.conn_flags = atomic_read(&dest->conn_flags);
80940 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
80941 entry.weight = atomic_read(&dest->weight);
80942 entry.u_threshold = dest->u_threshold;
80943 entry.l_threshold = dest->l_threshold;
80944 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
80945 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
80946 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
80947 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
80948 - (atomic_read(&dest->conn_flags) &
80949 + (atomic_read_unchecked(&dest->conn_flags) &
80950 IP_VS_CONN_F_FWD_MASK)) ||
80951 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
80952 atomic_read(&dest->weight)) ||
80953 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
80954 index effa10c..9058928 100644
80955 --- a/net/netfilter/ipvs/ip_vs_sync.c
80956 +++ b/net/netfilter/ipvs/ip_vs_sync.c
80957 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
80958 cp = cp->control;
80959 if (cp) {
80960 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80961 - pkts = atomic_add_return(1, &cp->in_pkts);
80962 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80963 else
80964 pkts = sysctl_sync_threshold(ipvs);
80965 ip_vs_sync_conn(net, cp->control, pkts);
80966 @@ -758,7 +758,7 @@ control:
80967 if (!cp)
80968 return;
80969 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80970 - pkts = atomic_add_return(1, &cp->in_pkts);
80971 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80972 else
80973 pkts = sysctl_sync_threshold(ipvs);
80974 goto sloop;
80975 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
80976
80977 if (opt)
80978 memcpy(&cp->in_seq, opt, sizeof(*opt));
80979 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80980 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80981 cp->state = state;
80982 cp->old_state = cp->state;
80983 /*
80984 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
80985 index cc4c809..50f8fe5 100644
80986 --- a/net/netfilter/ipvs/ip_vs_xmit.c
80987 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
80988 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
80989 else
80990 rc = NF_ACCEPT;
80991 /* do not touch skb anymore */
80992 - atomic_inc(&cp->in_pkts);
80993 + atomic_inc_unchecked(&cp->in_pkts);
80994 goto out;
80995 }
80996
80997 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
80998 else
80999 rc = NF_ACCEPT;
81000 /* do not touch skb anymore */
81001 - atomic_inc(&cp->in_pkts);
81002 + atomic_inc_unchecked(&cp->in_pkts);
81003 goto out;
81004 }
81005
81006 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
81007 index ec02168..f0caab6 100644
81008 --- a/net/netfilter/nf_conntrack_core.c
81009 +++ b/net/netfilter/nf_conntrack_core.c
81010 @@ -1533,6 +1533,10 @@ err_extend:
81011 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
81012 #define DYING_NULLS_VAL ((1<<30)+1)
81013
81014 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81015 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
81016 +#endif
81017 +
81018 static int nf_conntrack_init_net(struct net *net)
81019 {
81020 int ret;
81021 @@ -1546,7 +1550,11 @@ static int nf_conntrack_init_net(struct net *net)
81022 goto err_stat;
81023 }
81024
81025 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81026 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
81027 +#else
81028 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
81029 +#endif
81030 if (!net->ct.slabname) {
81031 ret = -ENOMEM;
81032 goto err_slabname;
81033 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81034 index 92fd8ec..3f6ea4b 100644
81035 --- a/net/netfilter/nfnetlink_log.c
81036 +++ b/net/netfilter/nfnetlink_log.c
81037 @@ -72,7 +72,7 @@ struct nfulnl_instance {
81038 };
81039
81040 static DEFINE_SPINLOCK(instances_lock);
81041 -static atomic_t global_seq;
81042 +static atomic_unchecked_t global_seq;
81043
81044 #define INSTANCE_BUCKETS 16
81045 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81046 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81047 /* global sequence number */
81048 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
81049 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
81050 - htonl(atomic_inc_return(&global_seq))))
81051 + htonl(atomic_inc_return_unchecked(&global_seq))))
81052 goto nla_put_failure;
81053
81054 if (data_len) {
81055 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81056 new file mode 100644
81057 index 0000000..c566332
81058 --- /dev/null
81059 +++ b/net/netfilter/xt_gradm.c
81060 @@ -0,0 +1,51 @@
81061 +/*
81062 + * gradm match for netfilter
81063 + * Copyright © Zbigniew Krzystolik, 2010
81064 + *
81065 + * This program is free software; you can redistribute it and/or modify
81066 + * it under the terms of the GNU General Public License; either version
81067 + * 2 or 3 as published by the Free Software Foundation.
81068 + */
81069 +#include <linux/module.h>
81070 +#include <linux/moduleparam.h>
81071 +#include <linux/skbuff.h>
81072 +#include <linux/netfilter/x_tables.h>
81073 +#include <linux/grsecurity.h>
81074 +#include <linux/netfilter/xt_gradm.h>
81075 +
81076 +static bool
81077 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
81078 +{
81079 + const struct xt_gradm_mtinfo *info = par->matchinfo;
81080 + bool retval = false;
81081 + if (gr_acl_is_enabled())
81082 + retval = true;
81083 + return retval ^ info->invflags;
81084 +}
81085 +
81086 +static struct xt_match gradm_mt_reg __read_mostly = {
81087 + .name = "gradm",
81088 + .revision = 0,
81089 + .family = NFPROTO_UNSPEC,
81090 + .match = gradm_mt,
81091 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
81092 + .me = THIS_MODULE,
81093 +};
81094 +
81095 +static int __init gradm_mt_init(void)
81096 +{
81097 + return xt_register_match(&gradm_mt_reg);
81098 +}
81099 +
81100 +static void __exit gradm_mt_exit(void)
81101 +{
81102 + xt_unregister_match(&gradm_mt_reg);
81103 +}
81104 +
81105 +module_init(gradm_mt_init);
81106 +module_exit(gradm_mt_exit);
81107 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
81108 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
81109 +MODULE_LICENSE("GPL");
81110 +MODULE_ALIAS("ipt_gradm");
81111 +MODULE_ALIAS("ip6t_gradm");
81112 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
81113 index 4fe4fb4..87a89e5 100644
81114 --- a/net/netfilter/xt_statistic.c
81115 +++ b/net/netfilter/xt_statistic.c
81116 @@ -19,7 +19,7 @@
81117 #include <linux/module.h>
81118
81119 struct xt_statistic_priv {
81120 - atomic_t count;
81121 + atomic_unchecked_t count;
81122 } ____cacheline_aligned_in_smp;
81123
81124 MODULE_LICENSE("GPL");
81125 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
81126 break;
81127 case XT_STATISTIC_MODE_NTH:
81128 do {
81129 - oval = atomic_read(&info->master->count);
81130 + oval = atomic_read_unchecked(&info->master->count);
81131 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
81132 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
81133 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
81134 if (nval == 0)
81135 ret = !ret;
81136 break;
81137 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
81138 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
81139 if (info->master == NULL)
81140 return -ENOMEM;
81141 - atomic_set(&info->master->count, info->u.nth.count);
81142 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
81143
81144 return 0;
81145 }
81146 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
81147 index 4da797f..eb1df70 100644
81148 --- a/net/netlink/af_netlink.c
81149 +++ b/net/netlink/af_netlink.c
81150 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
81151 sk->sk_error_report(sk);
81152 }
81153 }
81154 - atomic_inc(&sk->sk_drops);
81155 + atomic_inc_unchecked(&sk->sk_drops);
81156 }
81157
81158 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
81159 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
81160 sk_wmem_alloc_get(s),
81161 nlk->cb,
81162 atomic_read(&s->sk_refcnt),
81163 - atomic_read(&s->sk_drops),
81164 + atomic_read_unchecked(&s->sk_drops),
81165 sock_i_ino(s)
81166 );
81167
81168 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
81169 index 7261eb8..44e8ac6 100644
81170 --- a/net/netrom/af_netrom.c
81171 +++ b/net/netrom/af_netrom.c
81172 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81173 struct sock *sk = sock->sk;
81174 struct nr_sock *nr = nr_sk(sk);
81175
81176 + memset(sax, 0, sizeof(*sax));
81177 lock_sock(sk);
81178 if (peer != 0) {
81179 if (sk->sk_state != TCP_ESTABLISHED) {
81180 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81181 *uaddr_len = sizeof(struct full_sockaddr_ax25);
81182 } else {
81183 sax->fsa_ax25.sax25_family = AF_NETROM;
81184 - sax->fsa_ax25.sax25_ndigis = 0;
81185 sax->fsa_ax25.sax25_call = nr->source_addr;
81186 *uaddr_len = sizeof(struct sockaddr_ax25);
81187 }
81188 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
81189 index 94060ed..9c066f3 100644
81190 --- a/net/packet/af_packet.c
81191 +++ b/net/packet/af_packet.c
81192 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81193
81194 spin_lock(&sk->sk_receive_queue.lock);
81195 po->stats.tp_packets++;
81196 - skb->dropcount = atomic_read(&sk->sk_drops);
81197 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
81198 __skb_queue_tail(&sk->sk_receive_queue, skb);
81199 spin_unlock(&sk->sk_receive_queue.lock);
81200 sk->sk_data_ready(sk, skb->len);
81201 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81202 drop_n_acct:
81203 spin_lock(&sk->sk_receive_queue.lock);
81204 po->stats.tp_drops++;
81205 - atomic_inc(&sk->sk_drops);
81206 + atomic_inc_unchecked(&sk->sk_drops);
81207 spin_unlock(&sk->sk_receive_queue.lock);
81208
81209 drop_n_restore:
81210 @@ -2537,6 +2537,7 @@ out:
81211
81212 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81213 {
81214 + struct sock_extended_err ee;
81215 struct sock_exterr_skb *serr;
81216 struct sk_buff *skb, *skb2;
81217 int copied, err;
81218 @@ -2558,8 +2559,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81219 sock_recv_timestamp(msg, sk, skb);
81220
81221 serr = SKB_EXT_ERR(skb);
81222 + ee = serr->ee;
81223 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
81224 - sizeof(serr->ee), &serr->ee);
81225 + sizeof ee, &ee);
81226
81227 msg->msg_flags |= MSG_ERRQUEUE;
81228 err = copied;
81229 @@ -3171,7 +3173,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81230 case PACKET_HDRLEN:
81231 if (len > sizeof(int))
81232 len = sizeof(int);
81233 - if (copy_from_user(&val, optval, len))
81234 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
81235 return -EFAULT;
81236 switch (val) {
81237 case TPACKET_V1:
81238 @@ -3210,7 +3212,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81239 len = lv;
81240 if (put_user(len, optlen))
81241 return -EFAULT;
81242 - if (copy_to_user(optval, data, len))
81243 + if (len > sizeof(st) || copy_to_user(optval, data, len))
81244 return -EFAULT;
81245 return 0;
81246 }
81247 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
81248 index 5a940db..f0b9c12 100644
81249 --- a/net/phonet/af_phonet.c
81250 +++ b/net/phonet/af_phonet.c
81251 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
81252 {
81253 struct phonet_protocol *pp;
81254
81255 - if (protocol >= PHONET_NPROTO)
81256 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81257 return NULL;
81258
81259 rcu_read_lock();
81260 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
81261 {
81262 int err = 0;
81263
81264 - if (protocol >= PHONET_NPROTO)
81265 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81266 return -EINVAL;
81267
81268 err = proto_register(pp->prot, 1);
81269 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
81270 index 576f22c..bc7a71b 100644
81271 --- a/net/phonet/pep.c
81272 +++ b/net/phonet/pep.c
81273 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81274
81275 case PNS_PEP_CTRL_REQ:
81276 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
81277 - atomic_inc(&sk->sk_drops);
81278 + atomic_inc_unchecked(&sk->sk_drops);
81279 break;
81280 }
81281 __skb_pull(skb, 4);
81282 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81283 }
81284
81285 if (pn->rx_credits == 0) {
81286 - atomic_inc(&sk->sk_drops);
81287 + atomic_inc_unchecked(&sk->sk_drops);
81288 err = -ENOBUFS;
81289 break;
81290 }
81291 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
81292 }
81293
81294 if (pn->rx_credits == 0) {
81295 - atomic_inc(&sk->sk_drops);
81296 + atomic_inc_unchecked(&sk->sk_drops);
81297 err = NET_RX_DROP;
81298 break;
81299 }
81300 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
81301 index b7e9827..c264c85 100644
81302 --- a/net/phonet/socket.c
81303 +++ b/net/phonet/socket.c
81304 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
81305 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
81306 sock_i_ino(sk),
81307 atomic_read(&sk->sk_refcnt), sk,
81308 - atomic_read(&sk->sk_drops), &len);
81309 + atomic_read_unchecked(&sk->sk_drops), &len);
81310 }
81311 seq_printf(seq, "%*s\n", 127 - len, "");
81312 return 0;
81313 diff --git a/net/rds/cong.c b/net/rds/cong.c
81314 index e5b65ac..f3b6fb7 100644
81315 --- a/net/rds/cong.c
81316 +++ b/net/rds/cong.c
81317 @@ -78,7 +78,7 @@
81318 * finds that the saved generation number is smaller than the global generation
81319 * number, it wakes up the process.
81320 */
81321 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
81322 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
81323
81324 /*
81325 * Congestion monitoring
81326 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
81327 rdsdebug("waking map %p for %pI4\n",
81328 map, &map->m_addr);
81329 rds_stats_inc(s_cong_update_received);
81330 - atomic_inc(&rds_cong_generation);
81331 + atomic_inc_unchecked(&rds_cong_generation);
81332 if (waitqueue_active(&map->m_waitq))
81333 wake_up(&map->m_waitq);
81334 if (waitqueue_active(&rds_poll_waitq))
81335 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
81336
81337 int rds_cong_updated_since(unsigned long *recent)
81338 {
81339 - unsigned long gen = atomic_read(&rds_cong_generation);
81340 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
81341
81342 if (likely(*recent == gen))
81343 return 0;
81344 diff --git a/net/rds/ib.h b/net/rds/ib.h
81345 index 8d2b3d5..227ec5b 100644
81346 --- a/net/rds/ib.h
81347 +++ b/net/rds/ib.h
81348 @@ -128,7 +128,7 @@ struct rds_ib_connection {
81349 /* sending acks */
81350 unsigned long i_ack_flags;
81351 #ifdef KERNEL_HAS_ATOMIC64
81352 - atomic64_t i_ack_next; /* next ACK to send */
81353 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81354 #else
81355 spinlock_t i_ack_lock; /* protect i_ack_next */
81356 u64 i_ack_next; /* next ACK to send */
81357 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
81358 index a1e1162..265e129 100644
81359 --- a/net/rds/ib_cm.c
81360 +++ b/net/rds/ib_cm.c
81361 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
81362 /* Clear the ACK state */
81363 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81364 #ifdef KERNEL_HAS_ATOMIC64
81365 - atomic64_set(&ic->i_ack_next, 0);
81366 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81367 #else
81368 ic->i_ack_next = 0;
81369 #endif
81370 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
81371 index 8d19491..05a3e65 100644
81372 --- a/net/rds/ib_recv.c
81373 +++ b/net/rds/ib_recv.c
81374 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81375 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
81376 int ack_required)
81377 {
81378 - atomic64_set(&ic->i_ack_next, seq);
81379 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81380 if (ack_required) {
81381 smp_mb__before_clear_bit();
81382 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81383 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81384 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81385 smp_mb__after_clear_bit();
81386
81387 - return atomic64_read(&ic->i_ack_next);
81388 + return atomic64_read_unchecked(&ic->i_ack_next);
81389 }
81390 #endif
81391
81392 diff --git a/net/rds/iw.h b/net/rds/iw.h
81393 index 04ce3b1..48119a6 100644
81394 --- a/net/rds/iw.h
81395 +++ b/net/rds/iw.h
81396 @@ -134,7 +134,7 @@ struct rds_iw_connection {
81397 /* sending acks */
81398 unsigned long i_ack_flags;
81399 #ifdef KERNEL_HAS_ATOMIC64
81400 - atomic64_t i_ack_next; /* next ACK to send */
81401 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81402 #else
81403 spinlock_t i_ack_lock; /* protect i_ack_next */
81404 u64 i_ack_next; /* next ACK to send */
81405 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
81406 index a91e1db..cf3053f 100644
81407 --- a/net/rds/iw_cm.c
81408 +++ b/net/rds/iw_cm.c
81409 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
81410 /* Clear the ACK state */
81411 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81412 #ifdef KERNEL_HAS_ATOMIC64
81413 - atomic64_set(&ic->i_ack_next, 0);
81414 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81415 #else
81416 ic->i_ack_next = 0;
81417 #endif
81418 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
81419 index 4503335..db566b4 100644
81420 --- a/net/rds/iw_recv.c
81421 +++ b/net/rds/iw_recv.c
81422 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81423 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
81424 int ack_required)
81425 {
81426 - atomic64_set(&ic->i_ack_next, seq);
81427 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81428 if (ack_required) {
81429 smp_mb__before_clear_bit();
81430 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81431 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81432 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81433 smp_mb__after_clear_bit();
81434
81435 - return atomic64_read(&ic->i_ack_next);
81436 + return atomic64_read_unchecked(&ic->i_ack_next);
81437 }
81438 #endif
81439
81440 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
81441 index edac9ef..16bcb98 100644
81442 --- a/net/rds/tcp.c
81443 +++ b/net/rds/tcp.c
81444 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
81445 int val = 1;
81446
81447 set_fs(KERNEL_DS);
81448 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
81449 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
81450 sizeof(val));
81451 set_fs(oldfs);
81452 }
81453 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
81454 index 81cf5a4..b5826ff 100644
81455 --- a/net/rds/tcp_send.c
81456 +++ b/net/rds/tcp_send.c
81457 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
81458
81459 oldfs = get_fs();
81460 set_fs(KERNEL_DS);
81461 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
81462 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
81463 sizeof(val));
81464 set_fs(oldfs);
81465 }
81466 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
81467 index 05996d0..5a1dfe0 100644
81468 --- a/net/rxrpc/af_rxrpc.c
81469 +++ b/net/rxrpc/af_rxrpc.c
81470 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
81471 __be32 rxrpc_epoch;
81472
81473 /* current debugging ID */
81474 -atomic_t rxrpc_debug_id;
81475 +atomic_unchecked_t rxrpc_debug_id;
81476
81477 /* count of skbs currently in use */
81478 atomic_t rxrpc_n_skbs;
81479 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
81480 index e4d9cbc..b229649 100644
81481 --- a/net/rxrpc/ar-ack.c
81482 +++ b/net/rxrpc/ar-ack.c
81483 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81484
81485 _enter("{%d,%d,%d,%d},",
81486 call->acks_hard, call->acks_unacked,
81487 - atomic_read(&call->sequence),
81488 + atomic_read_unchecked(&call->sequence),
81489 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
81490
81491 stop = 0;
81492 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81493
81494 /* each Tx packet has a new serial number */
81495 sp->hdr.serial =
81496 - htonl(atomic_inc_return(&call->conn->serial));
81497 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
81498
81499 hdr = (struct rxrpc_header *) txb->head;
81500 hdr->serial = sp->hdr.serial;
81501 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
81502 */
81503 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
81504 {
81505 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
81506 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
81507 }
81508
81509 /*
81510 @@ -629,7 +629,7 @@ process_further:
81511
81512 latest = ntohl(sp->hdr.serial);
81513 hard = ntohl(ack.firstPacket);
81514 - tx = atomic_read(&call->sequence);
81515 + tx = atomic_read_unchecked(&call->sequence);
81516
81517 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81518 latest,
81519 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
81520 goto maybe_reschedule;
81521
81522 send_ACK_with_skew:
81523 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
81524 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
81525 ntohl(ack.serial));
81526 send_ACK:
81527 mtu = call->conn->trans->peer->if_mtu;
81528 @@ -1173,7 +1173,7 @@ send_ACK:
81529 ackinfo.rxMTU = htonl(5692);
81530 ackinfo.jumbo_max = htonl(4);
81531
81532 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81533 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81534 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81535 ntohl(hdr.serial),
81536 ntohs(ack.maxSkew),
81537 @@ -1191,7 +1191,7 @@ send_ACK:
81538 send_message:
81539 _debug("send message");
81540
81541 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81542 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81543 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
81544 send_message_2:
81545
81546 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
81547 index a3bbb36..3341fb9 100644
81548 --- a/net/rxrpc/ar-call.c
81549 +++ b/net/rxrpc/ar-call.c
81550 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
81551 spin_lock_init(&call->lock);
81552 rwlock_init(&call->state_lock);
81553 atomic_set(&call->usage, 1);
81554 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
81555 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81556 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
81557
81558 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
81559 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
81560 index 4106ca9..a338d7a 100644
81561 --- a/net/rxrpc/ar-connection.c
81562 +++ b/net/rxrpc/ar-connection.c
81563 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
81564 rwlock_init(&conn->lock);
81565 spin_lock_init(&conn->state_lock);
81566 atomic_set(&conn->usage, 1);
81567 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
81568 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81569 conn->avail_calls = RXRPC_MAXCALLS;
81570 conn->size_align = 4;
81571 conn->header_size = sizeof(struct rxrpc_header);
81572 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
81573 index e7ed43a..6afa140 100644
81574 --- a/net/rxrpc/ar-connevent.c
81575 +++ b/net/rxrpc/ar-connevent.c
81576 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
81577
81578 len = iov[0].iov_len + iov[1].iov_len;
81579
81580 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81581 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81582 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
81583
81584 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81585 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
81586 index 529572f..c758ca7 100644
81587 --- a/net/rxrpc/ar-input.c
81588 +++ b/net/rxrpc/ar-input.c
81589 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
81590 /* track the latest serial number on this connection for ACK packet
81591 * information */
81592 serial = ntohl(sp->hdr.serial);
81593 - hi_serial = atomic_read(&call->conn->hi_serial);
81594 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
81595 while (serial > hi_serial)
81596 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
81597 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
81598 serial);
81599
81600 /* request ACK generation for any ACK or DATA packet that requests
81601 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
81602 index a693aca..81e7293 100644
81603 --- a/net/rxrpc/ar-internal.h
81604 +++ b/net/rxrpc/ar-internal.h
81605 @@ -272,8 +272,8 @@ struct rxrpc_connection {
81606 int error; /* error code for local abort */
81607 int debug_id; /* debug ID for printks */
81608 unsigned int call_counter; /* call ID counter */
81609 - atomic_t serial; /* packet serial number counter */
81610 - atomic_t hi_serial; /* highest serial number received */
81611 + atomic_unchecked_t serial; /* packet serial number counter */
81612 + atomic_unchecked_t hi_serial; /* highest serial number received */
81613 u8 avail_calls; /* number of calls available */
81614 u8 size_align; /* data size alignment (for security) */
81615 u8 header_size; /* rxrpc + security header size */
81616 @@ -346,7 +346,7 @@ struct rxrpc_call {
81617 spinlock_t lock;
81618 rwlock_t state_lock; /* lock for state transition */
81619 atomic_t usage;
81620 - atomic_t sequence; /* Tx data packet sequence counter */
81621 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
81622 u32 abort_code; /* local/remote abort code */
81623 enum { /* current state of call */
81624 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
81625 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
81626 */
81627 extern atomic_t rxrpc_n_skbs;
81628 extern __be32 rxrpc_epoch;
81629 -extern atomic_t rxrpc_debug_id;
81630 +extern atomic_unchecked_t rxrpc_debug_id;
81631 extern struct workqueue_struct *rxrpc_workqueue;
81632
81633 /*
81634 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
81635 index 87f7135..74d3703 100644
81636 --- a/net/rxrpc/ar-local.c
81637 +++ b/net/rxrpc/ar-local.c
81638 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
81639 spin_lock_init(&local->lock);
81640 rwlock_init(&local->services_lock);
81641 atomic_set(&local->usage, 1);
81642 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
81643 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81644 memcpy(&local->srx, srx, sizeof(*srx));
81645 }
81646
81647 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
81648 index e1ac183..b43e10e 100644
81649 --- a/net/rxrpc/ar-output.c
81650 +++ b/net/rxrpc/ar-output.c
81651 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
81652 sp->hdr.cid = call->cid;
81653 sp->hdr.callNumber = call->call_id;
81654 sp->hdr.seq =
81655 - htonl(atomic_inc_return(&call->sequence));
81656 + htonl(atomic_inc_return_unchecked(&call->sequence));
81657 sp->hdr.serial =
81658 - htonl(atomic_inc_return(&conn->serial));
81659 + htonl(atomic_inc_return_unchecked(&conn->serial));
81660 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
81661 sp->hdr.userStatus = 0;
81662 sp->hdr.securityIndex = conn->security_ix;
81663 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
81664 index bebaa43..2644591 100644
81665 --- a/net/rxrpc/ar-peer.c
81666 +++ b/net/rxrpc/ar-peer.c
81667 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
81668 INIT_LIST_HEAD(&peer->error_targets);
81669 spin_lock_init(&peer->lock);
81670 atomic_set(&peer->usage, 1);
81671 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
81672 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81673 memcpy(&peer->srx, srx, sizeof(*srx));
81674
81675 rxrpc_assess_MTU_size(peer);
81676 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
81677 index 38047f7..9f48511 100644
81678 --- a/net/rxrpc/ar-proc.c
81679 +++ b/net/rxrpc/ar-proc.c
81680 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
81681 atomic_read(&conn->usage),
81682 rxrpc_conn_states[conn->state],
81683 key_serial(conn->key),
81684 - atomic_read(&conn->serial),
81685 - atomic_read(&conn->hi_serial));
81686 + atomic_read_unchecked(&conn->serial),
81687 + atomic_read_unchecked(&conn->hi_serial));
81688
81689 return 0;
81690 }
81691 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
81692 index 92df566..87ec1bf 100644
81693 --- a/net/rxrpc/ar-transport.c
81694 +++ b/net/rxrpc/ar-transport.c
81695 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
81696 spin_lock_init(&trans->client_lock);
81697 rwlock_init(&trans->conn_lock);
81698 atomic_set(&trans->usage, 1);
81699 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
81700 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81701
81702 if (peer->srx.transport.family == AF_INET) {
81703 switch (peer->srx.transport_type) {
81704 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
81705 index f226709..0e735a8 100644
81706 --- a/net/rxrpc/rxkad.c
81707 +++ b/net/rxrpc/rxkad.c
81708 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
81709
81710 len = iov[0].iov_len + iov[1].iov_len;
81711
81712 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81713 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81714 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
81715
81716 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81717 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
81718
81719 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
81720
81721 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
81722 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81723 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
81724
81725 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
81726 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
81727 index ea14cb4..834e8e4 100644
81728 --- a/net/sctp/ipv6.c
81729 +++ b/net/sctp/ipv6.c
81730 @@ -1037,7 +1037,7 @@ void sctp_v6_pf_init(void)
81731
81732 void sctp_v6_pf_exit(void)
81733 {
81734 - list_del(&sctp_af_inet6.list);
81735 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
81736 }
81737
81738 /* Initialize IPv6 support and register with socket layer. */
81739 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
81740 index 9966e7b..540c575 100644
81741 --- a/net/sctp/proc.c
81742 +++ b/net/sctp/proc.c
81743 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
81744 seq_printf(seq,
81745 "%8pK %8pK %-3d %-3d %-2d %-4d "
81746 "%4d %8d %8d %7d %5lu %-5d %5d ",
81747 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
81748 + assoc, sk,
81749 + sctp_sk(sk)->type, sk->sk_state,
81750 assoc->state, hash,
81751 assoc->assoc_id,
81752 assoc->sndbuf_used,
81753 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
81754 index 2d51842..150ba5c 100644
81755 --- a/net/sctp/protocol.c
81756 +++ b/net/sctp/protocol.c
81757 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
81758 return 0;
81759 }
81760
81761 - INIT_LIST_HEAD(&af->list);
81762 - list_add_tail(&af->list, &sctp_address_families);
81763 + pax_open_kernel();
81764 + INIT_LIST_HEAD((struct list_head *)&af->list);
81765 + pax_close_kernel();
81766 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
81767 return 1;
81768 }
81769
81770 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
81771
81772 static void sctp_v4_pf_exit(void)
81773 {
81774 - list_del(&sctp_af_inet.list);
81775 + pax_list_del((struct list_head *)&sctp_af_inet.list);
81776 }
81777
81778 static int sctp_v4_protosw_init(void)
81779 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
81780 index 406d957..543c737 100644
81781 --- a/net/sctp/socket.c
81782 +++ b/net/sctp/socket.c
81783 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
81784 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
81785 if (space_left < addrlen)
81786 return -ENOMEM;
81787 + if (addrlen > sizeof(temp) || addrlen < 0)
81788 + return -EFAULT;
81789 if (copy_to_user(to, &temp, addrlen))
81790 return -EFAULT;
81791 to += addrlen;
81792 diff --git a/net/socket.c b/net/socket.c
81793 index d92c490..b4bc863 100644
81794 --- a/net/socket.c
81795 +++ b/net/socket.c
81796 @@ -89,6 +89,7 @@
81797 #include <linux/magic.h>
81798 #include <linux/slab.h>
81799 #include <linux/xattr.h>
81800 +#include <linux/in.h>
81801
81802 #include <asm/uaccess.h>
81803 #include <asm/unistd.h>
81804 @@ -106,6 +107,8 @@
81805 #include <linux/sockios.h>
81806 #include <linux/atalk.h>
81807
81808 +#include <linux/grsock.h>
81809 +
81810 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
81811 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
81812 unsigned long nr_segs, loff_t pos);
81813 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
81814 &sockfs_dentry_operations, SOCKFS_MAGIC);
81815 }
81816
81817 -static struct vfsmount *sock_mnt __read_mostly;
81818 +struct vfsmount *sock_mnt __read_mostly;
81819
81820 static struct file_system_type sock_fs_type = {
81821 .name = "sockfs",
81822 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
81823 return -EAFNOSUPPORT;
81824 if (type < 0 || type >= SOCK_MAX)
81825 return -EINVAL;
81826 + if (protocol < 0)
81827 + return -EINVAL;
81828
81829 /* Compatibility.
81830
81831 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
81832 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
81833 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
81834
81835 + if(!gr_search_socket(family, type, protocol)) {
81836 + retval = -EACCES;
81837 + goto out;
81838 + }
81839 +
81840 + if (gr_handle_sock_all(family, type, protocol)) {
81841 + retval = -EACCES;
81842 + goto out;
81843 + }
81844 +
81845 retval = sock_create(family, type, protocol, &sock);
81846 if (retval < 0)
81847 goto out;
81848 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81849 if (sock) {
81850 err = move_addr_to_kernel(umyaddr, addrlen, &address);
81851 if (err >= 0) {
81852 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
81853 + err = -EACCES;
81854 + goto error;
81855 + }
81856 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
81857 + if (err)
81858 + goto error;
81859 +
81860 err = security_socket_bind(sock,
81861 (struct sockaddr *)&address,
81862 addrlen);
81863 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81864 (struct sockaddr *)
81865 &address, addrlen);
81866 }
81867 +error:
81868 fput_light(sock->file, fput_needed);
81869 }
81870 return err;
81871 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
81872 if ((unsigned int)backlog > somaxconn)
81873 backlog = somaxconn;
81874
81875 + if (gr_handle_sock_server_other(sock->sk)) {
81876 + err = -EPERM;
81877 + goto error;
81878 + }
81879 +
81880 + err = gr_search_listen(sock);
81881 + if (err)
81882 + goto error;
81883 +
81884 err = security_socket_listen(sock, backlog);
81885 if (!err)
81886 err = sock->ops->listen(sock, backlog);
81887
81888 +error:
81889 fput_light(sock->file, fput_needed);
81890 }
81891 return err;
81892 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81893 newsock->type = sock->type;
81894 newsock->ops = sock->ops;
81895
81896 + if (gr_handle_sock_server_other(sock->sk)) {
81897 + err = -EPERM;
81898 + sock_release(newsock);
81899 + goto out_put;
81900 + }
81901 +
81902 + err = gr_search_accept(sock);
81903 + if (err) {
81904 + sock_release(newsock);
81905 + goto out_put;
81906 + }
81907 +
81908 /*
81909 * We don't need try_module_get here, as the listening socket (sock)
81910 * has the protocol module (sock->ops->owner) held.
81911 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81912 fd_install(newfd, newfile);
81913 err = newfd;
81914
81915 + gr_attach_curr_ip(newsock->sk);
81916 +
81917 out_put:
81918 fput_light(sock->file, fput_needed);
81919 out:
81920 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81921 int, addrlen)
81922 {
81923 struct socket *sock;
81924 + struct sockaddr *sck;
81925 struct sockaddr_storage address;
81926 int err, fput_needed;
81927
81928 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81929 if (err < 0)
81930 goto out_put;
81931
81932 + sck = (struct sockaddr *)&address;
81933 +
81934 + if (gr_handle_sock_client(sck)) {
81935 + err = -EACCES;
81936 + goto out_put;
81937 + }
81938 +
81939 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
81940 + if (err)
81941 + goto out_put;
81942 +
81943 err =
81944 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
81945 if (err)
81946 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
81947 * checking falls down on this.
81948 */
81949 if (copy_from_user(ctl_buf,
81950 - (void __user __force *)msg_sys->msg_control,
81951 + (void __force_user *)msg_sys->msg_control,
81952 ctl_len))
81953 goto out_freectl;
81954 msg_sys->msg_control = ctl_buf;
81955 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
81956 * kernel msghdr to use the kernel address space)
81957 */
81958
81959 - uaddr = (__force void __user *)msg_sys->msg_name;
81960 + uaddr = (void __force_user *)msg_sys->msg_name;
81961 uaddr_len = COMPAT_NAMELEN(msg);
81962 if (MSG_CMSG_COMPAT & flags) {
81963 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
81964 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81965 }
81966
81967 ifr = compat_alloc_user_space(buf_size);
81968 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
81969 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
81970
81971 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
81972 return -EFAULT;
81973 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81974 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
81975
81976 if (copy_in_user(rxnfc, compat_rxnfc,
81977 - (void *)(&rxnfc->fs.m_ext + 1) -
81978 - (void *)rxnfc) ||
81979 + (void __user *)(&rxnfc->fs.m_ext + 1) -
81980 + (void __user *)rxnfc) ||
81981 copy_in_user(&rxnfc->fs.ring_cookie,
81982 &compat_rxnfc->fs.ring_cookie,
81983 - (void *)(&rxnfc->fs.location + 1) -
81984 - (void *)&rxnfc->fs.ring_cookie) ||
81985 + (void __user *)(&rxnfc->fs.location + 1) -
81986 + (void __user *)&rxnfc->fs.ring_cookie) ||
81987 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
81988 sizeof(rxnfc->rule_cnt)))
81989 return -EFAULT;
81990 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81991
81992 if (convert_out) {
81993 if (copy_in_user(compat_rxnfc, rxnfc,
81994 - (const void *)(&rxnfc->fs.m_ext + 1) -
81995 - (const void *)rxnfc) ||
81996 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
81997 + (const void __user *)rxnfc) ||
81998 copy_in_user(&compat_rxnfc->fs.ring_cookie,
81999 &rxnfc->fs.ring_cookie,
82000 - (const void *)(&rxnfc->fs.location + 1) -
82001 - (const void *)&rxnfc->fs.ring_cookie) ||
82002 + (const void __user *)(&rxnfc->fs.location + 1) -
82003 + (const void __user *)&rxnfc->fs.ring_cookie) ||
82004 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
82005 sizeof(rxnfc->rule_cnt)))
82006 return -EFAULT;
82007 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
82008 old_fs = get_fs();
82009 set_fs(KERNEL_DS);
82010 err = dev_ioctl(net, cmd,
82011 - (struct ifreq __user __force *) &kifr);
82012 + (struct ifreq __force_user *) &kifr);
82013 set_fs(old_fs);
82014
82015 return err;
82016 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
82017
82018 old_fs = get_fs();
82019 set_fs(KERNEL_DS);
82020 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
82021 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
82022 set_fs(old_fs);
82023
82024 if (cmd == SIOCGIFMAP && !err) {
82025 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
82026 ret |= __get_user(rtdev, &(ur4->rt_dev));
82027 if (rtdev) {
82028 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
82029 - r4.rt_dev = (char __user __force *)devname;
82030 + r4.rt_dev = (char __force_user *)devname;
82031 devname[15] = 0;
82032 } else
82033 r4.rt_dev = NULL;
82034 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
82035 int __user *uoptlen;
82036 int err;
82037
82038 - uoptval = (char __user __force *) optval;
82039 - uoptlen = (int __user __force *) optlen;
82040 + uoptval = (char __force_user *) optval;
82041 + uoptlen = (int __force_user *) optlen;
82042
82043 set_fs(KERNEL_DS);
82044 if (level == SOL_SOCKET)
82045 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
82046 char __user *uoptval;
82047 int err;
82048
82049 - uoptval = (char __user __force *) optval;
82050 + uoptval = (char __force_user *) optval;
82051
82052 set_fs(KERNEL_DS);
82053 if (level == SOL_SOCKET)
82054 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
82055 index 7865b44..174662e 100644
82056 --- a/net/sunrpc/sched.c
82057 +++ b/net/sunrpc/sched.c
82058 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
82059 #ifdef RPC_DEBUG
82060 static void rpc_task_set_debuginfo(struct rpc_task *task)
82061 {
82062 - static atomic_t rpc_pid;
82063 + static atomic_unchecked_t rpc_pid;
82064
82065 - task->tk_pid = atomic_inc_return(&rpc_pid);
82066 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
82067 }
82068 #else
82069 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
82070 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
82071 index 8343737..677025e 100644
82072 --- a/net/sunrpc/xprtrdma/svc_rdma.c
82073 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
82074 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
82075 static unsigned int min_max_inline = 4096;
82076 static unsigned int max_max_inline = 65536;
82077
82078 -atomic_t rdma_stat_recv;
82079 -atomic_t rdma_stat_read;
82080 -atomic_t rdma_stat_write;
82081 -atomic_t rdma_stat_sq_starve;
82082 -atomic_t rdma_stat_rq_starve;
82083 -atomic_t rdma_stat_rq_poll;
82084 -atomic_t rdma_stat_rq_prod;
82085 -atomic_t rdma_stat_sq_poll;
82086 -atomic_t rdma_stat_sq_prod;
82087 +atomic_unchecked_t rdma_stat_recv;
82088 +atomic_unchecked_t rdma_stat_read;
82089 +atomic_unchecked_t rdma_stat_write;
82090 +atomic_unchecked_t rdma_stat_sq_starve;
82091 +atomic_unchecked_t rdma_stat_rq_starve;
82092 +atomic_unchecked_t rdma_stat_rq_poll;
82093 +atomic_unchecked_t rdma_stat_rq_prod;
82094 +atomic_unchecked_t rdma_stat_sq_poll;
82095 +atomic_unchecked_t rdma_stat_sq_prod;
82096
82097 /* Temporary NFS request map and context caches */
82098 struct kmem_cache *svc_rdma_map_cachep;
82099 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
82100 len -= *ppos;
82101 if (len > *lenp)
82102 len = *lenp;
82103 - if (len && copy_to_user(buffer, str_buf, len))
82104 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
82105 return -EFAULT;
82106 *lenp = len;
82107 *ppos += len;
82108 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
82109 {
82110 .procname = "rdma_stat_read",
82111 .data = &rdma_stat_read,
82112 - .maxlen = sizeof(atomic_t),
82113 + .maxlen = sizeof(atomic_unchecked_t),
82114 .mode = 0644,
82115 .proc_handler = read_reset_stat,
82116 },
82117 {
82118 .procname = "rdma_stat_recv",
82119 .data = &rdma_stat_recv,
82120 - .maxlen = sizeof(atomic_t),
82121 + .maxlen = sizeof(atomic_unchecked_t),
82122 .mode = 0644,
82123 .proc_handler = read_reset_stat,
82124 },
82125 {
82126 .procname = "rdma_stat_write",
82127 .data = &rdma_stat_write,
82128 - .maxlen = sizeof(atomic_t),
82129 + .maxlen = sizeof(atomic_unchecked_t),
82130 .mode = 0644,
82131 .proc_handler = read_reset_stat,
82132 },
82133 {
82134 .procname = "rdma_stat_sq_starve",
82135 .data = &rdma_stat_sq_starve,
82136 - .maxlen = sizeof(atomic_t),
82137 + .maxlen = sizeof(atomic_unchecked_t),
82138 .mode = 0644,
82139 .proc_handler = read_reset_stat,
82140 },
82141 {
82142 .procname = "rdma_stat_rq_starve",
82143 .data = &rdma_stat_rq_starve,
82144 - .maxlen = sizeof(atomic_t),
82145 + .maxlen = sizeof(atomic_unchecked_t),
82146 .mode = 0644,
82147 .proc_handler = read_reset_stat,
82148 },
82149 {
82150 .procname = "rdma_stat_rq_poll",
82151 .data = &rdma_stat_rq_poll,
82152 - .maxlen = sizeof(atomic_t),
82153 + .maxlen = sizeof(atomic_unchecked_t),
82154 .mode = 0644,
82155 .proc_handler = read_reset_stat,
82156 },
82157 {
82158 .procname = "rdma_stat_rq_prod",
82159 .data = &rdma_stat_rq_prod,
82160 - .maxlen = sizeof(atomic_t),
82161 + .maxlen = sizeof(atomic_unchecked_t),
82162 .mode = 0644,
82163 .proc_handler = read_reset_stat,
82164 },
82165 {
82166 .procname = "rdma_stat_sq_poll",
82167 .data = &rdma_stat_sq_poll,
82168 - .maxlen = sizeof(atomic_t),
82169 + .maxlen = sizeof(atomic_unchecked_t),
82170 .mode = 0644,
82171 .proc_handler = read_reset_stat,
82172 },
82173 {
82174 .procname = "rdma_stat_sq_prod",
82175 .data = &rdma_stat_sq_prod,
82176 - .maxlen = sizeof(atomic_t),
82177 + .maxlen = sizeof(atomic_unchecked_t),
82178 .mode = 0644,
82179 .proc_handler = read_reset_stat,
82180 },
82181 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82182 index 41cb63b..c4a1489 100644
82183 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82184 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82185 @@ -501,7 +501,7 @@ next_sge:
82186 svc_rdma_put_context(ctxt, 0);
82187 goto out;
82188 }
82189 - atomic_inc(&rdma_stat_read);
82190 + atomic_inc_unchecked(&rdma_stat_read);
82191
82192 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
82193 chl_map->ch[ch_no].count -= read_wr.num_sge;
82194 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82195 dto_q);
82196 list_del_init(&ctxt->dto_q);
82197 } else {
82198 - atomic_inc(&rdma_stat_rq_starve);
82199 + atomic_inc_unchecked(&rdma_stat_rq_starve);
82200 clear_bit(XPT_DATA, &xprt->xpt_flags);
82201 ctxt = NULL;
82202 }
82203 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82204 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
82205 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
82206 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
82207 - atomic_inc(&rdma_stat_recv);
82208 + atomic_inc_unchecked(&rdma_stat_recv);
82209
82210 /* Build up the XDR from the receive buffers. */
82211 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
82212 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82213 index 42eb7ba..c887c45 100644
82214 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82215 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82216 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
82217 write_wr.wr.rdma.remote_addr = to;
82218
82219 /* Post It */
82220 - atomic_inc(&rdma_stat_write);
82221 + atomic_inc_unchecked(&rdma_stat_write);
82222 if (svc_rdma_send(xprt, &write_wr))
82223 goto err;
82224 return 0;
82225 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82226 index 62e4f9b..dd3f2d7 100644
82227 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
82228 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82229 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82230 return;
82231
82232 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
82233 - atomic_inc(&rdma_stat_rq_poll);
82234 + atomic_inc_unchecked(&rdma_stat_rq_poll);
82235
82236 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
82237 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
82238 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82239 }
82240
82241 if (ctxt)
82242 - atomic_inc(&rdma_stat_rq_prod);
82243 + atomic_inc_unchecked(&rdma_stat_rq_prod);
82244
82245 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
82246 /*
82247 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82248 return;
82249
82250 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
82251 - atomic_inc(&rdma_stat_sq_poll);
82252 + atomic_inc_unchecked(&rdma_stat_sq_poll);
82253 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
82254 if (wc.status != IB_WC_SUCCESS)
82255 /* Close the transport */
82256 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82257 }
82258
82259 if (ctxt)
82260 - atomic_inc(&rdma_stat_sq_prod);
82261 + atomic_inc_unchecked(&rdma_stat_sq_prod);
82262 }
82263
82264 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
82265 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
82266 spin_lock_bh(&xprt->sc_lock);
82267 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
82268 spin_unlock_bh(&xprt->sc_lock);
82269 - atomic_inc(&rdma_stat_sq_starve);
82270 + atomic_inc_unchecked(&rdma_stat_sq_starve);
82271
82272 /* See if we can opportunistically reap SQ WR to make room */
82273 sq_cq_reap(xprt);
82274 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
82275 index e3a6e37..be2ea77 100644
82276 --- a/net/sysctl_net.c
82277 +++ b/net/sysctl_net.c
82278 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
82279 struct ctl_table *table)
82280 {
82281 /* Allow network administrator to have same access as root. */
82282 - if (capable(CAP_NET_ADMIN)) {
82283 + if (capable_nolog(CAP_NET_ADMIN)) {
82284 int mode = (table->mode >> 6) & 7;
82285 return (mode << 6) | (mode << 3) | mode;
82286 }
82287 diff --git a/net/tipc/link.c b/net/tipc/link.c
82288 index a79c755..eca357d 100644
82289 --- a/net/tipc/link.c
82290 +++ b/net/tipc/link.c
82291 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
82292 struct tipc_msg fragm_hdr;
82293 struct sk_buff *buf, *buf_chain, *prev;
82294 u32 fragm_crs, fragm_rest, hsz, sect_rest;
82295 - const unchar *sect_crs;
82296 + const unchar __user *sect_crs;
82297 int curr_sect;
82298 u32 fragm_no;
82299
82300 @@ -1210,7 +1210,7 @@ again:
82301
82302 if (!sect_rest) {
82303 sect_rest = msg_sect[++curr_sect].iov_len;
82304 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
82305 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
82306 }
82307
82308 if (sect_rest < fragm_rest)
82309 @@ -1229,7 +1229,7 @@ error:
82310 }
82311 } else
82312 skb_copy_to_linear_data_offset(buf, fragm_crs,
82313 - sect_crs, sz);
82314 + (const void __force_kernel *)sect_crs, sz);
82315 sect_crs += sz;
82316 sect_rest -= sz;
82317 fragm_crs += sz;
82318 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
82319 index f2db8a8..9245aa4 100644
82320 --- a/net/tipc/msg.c
82321 +++ b/net/tipc/msg.c
82322 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
82323 msg_sect[cnt].iov_len);
82324 else
82325 skb_copy_to_linear_data_offset(*buf, pos,
82326 - msg_sect[cnt].iov_base,
82327 + (const void __force_kernel *)msg_sect[cnt].iov_base,
82328 msg_sect[cnt].iov_len);
82329 pos += msg_sect[cnt].iov_len;
82330 }
82331 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
82332 index 0f7d0d0..00f89bf 100644
82333 --- a/net/tipc/subscr.c
82334 +++ b/net/tipc/subscr.c
82335 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
82336 {
82337 struct iovec msg_sect;
82338
82339 - msg_sect.iov_base = (void *)&sub->evt;
82340 + msg_sect.iov_base = (void __force_user *)&sub->evt;
82341 msg_sect.iov_len = sizeof(struct tipc_event);
82342
82343 sub->evt.event = htohl(event, sub->swap);
82344 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
82345 index 5b5c876..3127bf7 100644
82346 --- a/net/unix/af_unix.c
82347 +++ b/net/unix/af_unix.c
82348 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
82349 err = -ECONNREFUSED;
82350 if (!S_ISSOCK(inode->i_mode))
82351 goto put_fail;
82352 +
82353 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
82354 + err = -EACCES;
82355 + goto put_fail;
82356 + }
82357 +
82358 u = unix_find_socket_byinode(inode);
82359 if (!u)
82360 goto put_fail;
82361 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
82362 if (u) {
82363 struct dentry *dentry;
82364 dentry = unix_sk(u)->path.dentry;
82365 +
82366 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
82367 + err = -EPERM;
82368 + sock_put(u);
82369 + goto fail;
82370 + }
82371 +
82372 if (dentry)
82373 touch_atime(&unix_sk(u)->path);
82374 } else
82375 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
82376 */
82377 err = security_path_mknod(&path, dentry, mode, 0);
82378 if (!err) {
82379 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
82380 + err = -EACCES;
82381 + goto out;
82382 + }
82383 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
82384 if (!err) {
82385 res->mnt = mntget(path.mnt);
82386 res->dentry = dget(dentry);
82387 + gr_handle_create(dentry, path.mnt);
82388 }
82389 }
82390 +out:
82391 done_path_create(&path, dentry);
82392 return err;
82393 }
82394 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
82395 index c8717c1..08539f5 100644
82396 --- a/net/wireless/wext-core.c
82397 +++ b/net/wireless/wext-core.c
82398 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82399 */
82400
82401 /* Support for very large requests */
82402 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
82403 - (user_length > descr->max_tokens)) {
82404 + if (user_length > descr->max_tokens) {
82405 /* Allow userspace to GET more than max so
82406 * we can support any size GET requests.
82407 * There is still a limit : -ENOMEM.
82408 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82409 }
82410 }
82411
82412 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
82413 - /*
82414 - * If this is a GET, but not NOMAX, it means that the extra
82415 - * data is not bounded by userspace, but by max_tokens. Thus
82416 - * set the length to max_tokens. This matches the extra data
82417 - * allocation.
82418 - * The driver should fill it with the number of tokens it
82419 - * provided, and it may check iwp->length rather than having
82420 - * knowledge of max_tokens. If the driver doesn't change the
82421 - * iwp->length, this ioctl just copies back max_token tokens
82422 - * filled with zeroes. Hopefully the driver isn't claiming
82423 - * them to be valid data.
82424 - */
82425 - iwp->length = descr->max_tokens;
82426 - }
82427 -
82428 err = handler(dev, info, (union iwreq_data *) iwp, extra);
82429
82430 iwp->length += essid_compat;
82431 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
82432 index 41eabc4..8d4e6d6 100644
82433 --- a/net/xfrm/xfrm_policy.c
82434 +++ b/net/xfrm/xfrm_policy.c
82435 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
82436 {
82437 policy->walk.dead = 1;
82438
82439 - atomic_inc(&policy->genid);
82440 + atomic_inc_unchecked(&policy->genid);
82441
82442 if (del_timer(&policy->timer))
82443 xfrm_pol_put(policy);
82444 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
82445 hlist_add_head(&policy->bydst, chain);
82446 xfrm_pol_hold(policy);
82447 net->xfrm.policy_count[dir]++;
82448 - atomic_inc(&flow_cache_genid);
82449 + atomic_inc_unchecked(&flow_cache_genid);
82450 rt_genid_bump(net);
82451 if (delpol)
82452 __xfrm_policy_unlink(delpol, dir);
82453 @@ -1550,7 +1550,7 @@ free_dst:
82454 goto out;
82455 }
82456
82457 -static int inline
82458 +static inline int
82459 xfrm_dst_alloc_copy(void **target, const void *src, int size)
82460 {
82461 if (!*target) {
82462 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
82463 return 0;
82464 }
82465
82466 -static int inline
82467 +static inline int
82468 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82469 {
82470 #ifdef CONFIG_XFRM_SUB_POLICY
82471 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82472 #endif
82473 }
82474
82475 -static int inline
82476 +static inline int
82477 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
82478 {
82479 #ifdef CONFIG_XFRM_SUB_POLICY
82480 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
82481
82482 xdst->num_pols = num_pols;
82483 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
82484 - xdst->policy_genid = atomic_read(&pols[0]->genid);
82485 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
82486
82487 return xdst;
82488 }
82489 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
82490 if (xdst->xfrm_genid != dst->xfrm->genid)
82491 return 0;
82492 if (xdst->num_pols > 0 &&
82493 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
82494 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
82495 return 0;
82496
82497 mtu = dst_mtu(dst->child);
82498 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
82499 sizeof(pol->xfrm_vec[i].saddr));
82500 pol->xfrm_vec[i].encap_family = mp->new_family;
82501 /* flush bundles */
82502 - atomic_inc(&pol->genid);
82503 + atomic_inc_unchecked(&pol->genid);
82504 }
82505 }
82506
82507 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
82508 index 3459692..eefb515 100644
82509 --- a/net/xfrm/xfrm_state.c
82510 +++ b/net/xfrm/xfrm_state.c
82511 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
82512 if (!try_module_get(afinfo->owner))
82513 goto out;
82514
82515 - mode->afinfo = afinfo;
82516 + pax_open_kernel();
82517 + *(void **)&mode->afinfo = afinfo;
82518 + pax_close_kernel();
82519 modemap[mode->encap] = mode;
82520 err = 0;
82521
82522 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
82523 index 0e801c3..5c8ad3b 100644
82524 --- a/scripts/Makefile.build
82525 +++ b/scripts/Makefile.build
82526 @@ -111,7 +111,7 @@ endif
82527 endif
82528
82529 # Do not include host rules unless needed
82530 -ifneq ($(hostprogs-y)$(hostprogs-m),)
82531 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
82532 include scripts/Makefile.host
82533 endif
82534
82535 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
82536 index 686cb0d..9d653bf 100644
82537 --- a/scripts/Makefile.clean
82538 +++ b/scripts/Makefile.clean
82539 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
82540 __clean-files := $(extra-y) $(always) \
82541 $(targets) $(clean-files) \
82542 $(host-progs) \
82543 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
82544 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
82545 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
82546
82547 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
82548
82549 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
82550 index 1ac414f..38575f7 100644
82551 --- a/scripts/Makefile.host
82552 +++ b/scripts/Makefile.host
82553 @@ -31,6 +31,8 @@
82554 # Note: Shared libraries consisting of C++ files are not supported
82555
82556 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
82557 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
82558 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
82559
82560 # C code
82561 # Executables compiled from a single .c file
82562 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
82563 # Shared libaries (only .c supported)
82564 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
82565 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
82566 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
82567 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
82568 # Remove .so files from "xxx-objs"
82569 host-cobjs := $(filter-out %.so,$(host-cobjs))
82570 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
82571
82572 -#Object (.o) files used by the shared libaries
82573 +# Object (.o) files used by the shared libaries
82574 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
82575 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
82576
82577 # output directory for programs/.o files
82578 # hostprogs-y := tools/build may have been specified. Retrieve directory
82579 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
82580 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
82581 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
82582 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
82583 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
82584 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
82585 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
82586 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
82587
82588 obj-dirs += $(host-objdirs)
82589 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
82590 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
82591 $(call if_changed_dep,host-cshobjs)
82592
82593 +# Compile .c file, create position independent .o file
82594 +# host-cxxshobjs -> .o
82595 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
82596 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
82597 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
82598 + $(call if_changed_dep,host-cxxshobjs)
82599 +
82600 # Link a shared library, based on position independent .o files
82601 # *.o -> .so shared library (host-cshlib)
82602 quiet_cmd_host-cshlib = HOSTLLD -shared $@
82603 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
82604 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
82605 $(call if_changed,host-cshlib)
82606
82607 +# Link a shared library, based on position independent .o files
82608 +# *.o -> .so shared library (host-cxxshlib)
82609 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
82610 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
82611 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
82612 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
82613 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
82614 + $(call if_changed,host-cxxshlib)
82615 +
82616 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
82617 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
82618 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
82619
82620 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
82621 index cb1f50c..cef2a7c 100644
82622 --- a/scripts/basic/fixdep.c
82623 +++ b/scripts/basic/fixdep.c
82624 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
82625 /*
82626 * Lookup a value in the configuration string.
82627 */
82628 -static int is_defined_config(const char *name, int len, unsigned int hash)
82629 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
82630 {
82631 struct item *aux;
82632
82633 @@ -211,10 +211,10 @@ static void clear_config(void)
82634 /*
82635 * Record the use of a CONFIG_* word.
82636 */
82637 -static void use_config(const char *m, int slen)
82638 +static void use_config(const char *m, unsigned int slen)
82639 {
82640 unsigned int hash = strhash(m, slen);
82641 - int c, i;
82642 + unsigned int c, i;
82643
82644 if (is_defined_config(m, slen, hash))
82645 return;
82646 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
82647
82648 static void parse_config_file(const char *map, size_t len)
82649 {
82650 - const int *end = (const int *) (map + len);
82651 + const unsigned int *end = (const unsigned int *) (map + len);
82652 /* start at +1, so that p can never be < map */
82653 - const int *m = (const int *) map + 1;
82654 + const unsigned int *m = (const unsigned int *) map + 1;
82655 const char *p, *q;
82656
82657 for (; m < end; m++) {
82658 @@ -406,7 +406,7 @@ static void print_deps(void)
82659 static void traps(void)
82660 {
82661 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
82662 - int *p = (int *)test;
82663 + unsigned int *p = (unsigned int *)test;
82664
82665 if (*p != INT_CONF) {
82666 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
82667 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
82668 new file mode 100644
82669 index 0000000..008ac1a
82670 --- /dev/null
82671 +++ b/scripts/gcc-plugin.sh
82672 @@ -0,0 +1,17 @@
82673 +#!/bin/bash
82674 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
82675 +#include "gcc-plugin.h"
82676 +#include "tree.h"
82677 +#include "tm.h"
82678 +#include "rtl.h"
82679 +#ifdef ENABLE_BUILD_WITH_CXX
82680 +#warning $2
82681 +#else
82682 +#warning $1
82683 +#endif
82684 +EOF`
82685 +if [ $? -eq 0 ]
82686 +then
82687 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
82688 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
82689 +fi
82690 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
82691 index b3d907e..a4782ab 100644
82692 --- a/scripts/link-vmlinux.sh
82693 +++ b/scripts/link-vmlinux.sh
82694 @@ -152,7 +152,7 @@ else
82695 fi;
82696
82697 # final build of init/
82698 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
82699 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
82700
82701 kallsymso=""
82702 kallsyms_vmlinux=""
82703 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
82704 index df4fc23..0ea719d 100644
82705 --- a/scripts/mod/file2alias.c
82706 +++ b/scripts/mod/file2alias.c
82707 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
82708 unsigned long size, unsigned long id_size,
82709 void *symval)
82710 {
82711 - int i;
82712 + unsigned int i;
82713
82714 if (size % id_size || size < id_size) {
82715 if (cross_build != 0)
82716 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
82717 /* USB is special because the bcdDevice can be matched against a numeric range */
82718 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
82719 static void do_usb_entry(struct usb_device_id *id,
82720 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
82721 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
82722 unsigned char range_lo, unsigned char range_hi,
82723 unsigned char max, struct module *mod)
82724 {
82725 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
82726 {
82727 unsigned int devlo, devhi;
82728 unsigned char chi, clo, max;
82729 - int ndigits;
82730 + unsigned int ndigits;
82731
82732 id->match_flags = TO_NATIVE(id->match_flags);
82733 id->idVendor = TO_NATIVE(id->idVendor);
82734 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
82735 for (i = 0; i < count; i++) {
82736 const char *id = (char *)devs[i].id;
82737 char acpi_id[sizeof(devs[0].id)];
82738 - int j;
82739 + unsigned int j;
82740
82741 buf_printf(&mod->dev_table_buf,
82742 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82743 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82744
82745 for (j = 0; j < PNP_MAX_DEVICES; j++) {
82746 const char *id = (char *)card->devs[j].id;
82747 - int i2, j2;
82748 + unsigned int i2, j2;
82749 int dup = 0;
82750
82751 if (!id[0])
82752 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82753 /* add an individual alias for every device entry */
82754 if (!dup) {
82755 char acpi_id[sizeof(card->devs[0].id)];
82756 - int k;
82757 + unsigned int k;
82758
82759 buf_printf(&mod->dev_table_buf,
82760 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82761 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
82762 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
82763 char *alias)
82764 {
82765 - int i, j;
82766 + unsigned int i, j;
82767
82768 sprintf(alias, "dmi*");
82769
82770 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
82771 index 0d93856..e828363 100644
82772 --- a/scripts/mod/modpost.c
82773 +++ b/scripts/mod/modpost.c
82774 @@ -933,6 +933,7 @@ enum mismatch {
82775 ANY_INIT_TO_ANY_EXIT,
82776 ANY_EXIT_TO_ANY_INIT,
82777 EXPORT_TO_INIT_EXIT,
82778 + DATA_TO_TEXT
82779 };
82780
82781 struct sectioncheck {
82782 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
82783 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
82784 .mismatch = EXPORT_TO_INIT_EXIT,
82785 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
82786 +},
82787 +/* Do not reference code from writable data */
82788 +{
82789 + .fromsec = { DATA_SECTIONS, NULL },
82790 + .tosec = { TEXT_SECTIONS, NULL },
82791 + .mismatch = DATA_TO_TEXT
82792 }
82793 };
82794
82795 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
82796 continue;
82797 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
82798 continue;
82799 - if (sym->st_value == addr)
82800 - return sym;
82801 /* Find a symbol nearby - addr are maybe negative */
82802 d = sym->st_value - addr;
82803 + if (d == 0)
82804 + return sym;
82805 if (d < 0)
82806 d = addr - sym->st_value;
82807 if (d < distance) {
82808 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
82809 tosym, prl_to, prl_to, tosym);
82810 free(prl_to);
82811 break;
82812 + case DATA_TO_TEXT:
82813 +#if 0
82814 + fprintf(stderr,
82815 + "The %s %s:%s references\n"
82816 + "the %s %s:%s%s\n",
82817 + from, fromsec, fromsym, to, tosec, tosym, to_p);
82818 +#endif
82819 + break;
82820 }
82821 fprintf(stderr, "\n");
82822 }
82823 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
82824 static void check_sec_ref(struct module *mod, const char *modname,
82825 struct elf_info *elf)
82826 {
82827 - int i;
82828 + unsigned int i;
82829 Elf_Shdr *sechdrs = elf->sechdrs;
82830
82831 /* Walk through all sections */
82832 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
82833 va_end(ap);
82834 }
82835
82836 -void buf_write(struct buffer *buf, const char *s, int len)
82837 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
82838 {
82839 if (buf->size - buf->pos < len) {
82840 buf->size += len + SZ;
82841 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
82842 if (fstat(fileno(file), &st) < 0)
82843 goto close_write;
82844
82845 - if (st.st_size != b->pos)
82846 + if (st.st_size != (off_t)b->pos)
82847 goto close_write;
82848
82849 tmp = NOFAIL(malloc(b->pos));
82850 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
82851 index 51207e4..f7d603d 100644
82852 --- a/scripts/mod/modpost.h
82853 +++ b/scripts/mod/modpost.h
82854 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
82855
82856 struct buffer {
82857 char *p;
82858 - int pos;
82859 - int size;
82860 + unsigned int pos;
82861 + unsigned int size;
82862 };
82863
82864 void __attribute__((format(printf, 2, 3)))
82865 buf_printf(struct buffer *buf, const char *fmt, ...);
82866
82867 void
82868 -buf_write(struct buffer *buf, const char *s, int len);
82869 +buf_write(struct buffer *buf, const char *s, unsigned int len);
82870
82871 struct module {
82872 struct module *next;
82873 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
82874 index 9dfcd6d..099068e 100644
82875 --- a/scripts/mod/sumversion.c
82876 +++ b/scripts/mod/sumversion.c
82877 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
82878 goto out;
82879 }
82880
82881 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
82882 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
82883 warn("writing sum in %s failed: %s\n",
82884 filename, strerror(errno));
82885 goto out;
82886 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
82887 index 5c11312..72742b5 100644
82888 --- a/scripts/pnmtologo.c
82889 +++ b/scripts/pnmtologo.c
82890 @@ -237,14 +237,14 @@ static void write_header(void)
82891 fprintf(out, " * Linux logo %s\n", logoname);
82892 fputs(" */\n\n", out);
82893 fputs("#include <linux/linux_logo.h>\n\n", out);
82894 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
82895 + fprintf(out, "static unsigned char %s_data[] = {\n",
82896 logoname);
82897 }
82898
82899 static void write_footer(void)
82900 {
82901 fputs("\n};\n\n", out);
82902 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
82903 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
82904 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
82905 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
82906 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
82907 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
82908 fputs("\n};\n\n", out);
82909
82910 /* write logo clut */
82911 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
82912 + fprintf(out, "static unsigned char %s_clut[] = {\n",
82913 logoname);
82914 write_hex_cnt = 0;
82915 for (i = 0; i < logo_clutsize; i++) {
82916 diff --git a/security/Kconfig b/security/Kconfig
82917 index e9c6ac7..01c698c 100644
82918 --- a/security/Kconfig
82919 +++ b/security/Kconfig
82920 @@ -4,6 +4,902 @@
82921
82922 menu "Security options"
82923
82924 +menu "Grsecurity"
82925 +
82926 + config ARCH_TRACK_EXEC_LIMIT
82927 + bool
82928 +
82929 + config PAX_KERNEXEC_PLUGIN
82930 + bool
82931 +
82932 + config PAX_PER_CPU_PGD
82933 + bool
82934 +
82935 + config TASK_SIZE_MAX_SHIFT
82936 + int
82937 + depends on X86_64
82938 + default 47 if !PAX_PER_CPU_PGD
82939 + default 42 if PAX_PER_CPU_PGD
82940 +
82941 + config PAX_ENABLE_PAE
82942 + bool
82943 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
82944 +
82945 + config PAX_USERCOPY_SLABS
82946 + bool
82947 +
82948 +config GRKERNSEC
82949 + bool "Grsecurity"
82950 + select CRYPTO
82951 + select CRYPTO_SHA256
82952 + select PROC_FS
82953 + select STOP_MACHINE
82954 + help
82955 + If you say Y here, you will be able to configure many features
82956 + that will enhance the security of your system. It is highly
82957 + recommended that you say Y here and read through the help
82958 + for each option so that you fully understand the features and
82959 + can evaluate their usefulness for your machine.
82960 +
82961 +choice
82962 + prompt "Configuration Method"
82963 + depends on GRKERNSEC
82964 + default GRKERNSEC_CONFIG_CUSTOM
82965 + help
82966 +
82967 +config GRKERNSEC_CONFIG_AUTO
82968 + bool "Automatic"
82969 + help
82970 + If you choose this configuration method, you'll be able to answer a small
82971 + number of simple questions about how you plan to use this kernel.
82972 + The settings of grsecurity and PaX will be automatically configured for
82973 + the highest commonly-used settings within the provided constraints.
82974 +
82975 + If you require additional configuration, custom changes can still be made
82976 + from the "custom configuration" menu.
82977 +
82978 +config GRKERNSEC_CONFIG_CUSTOM
82979 + bool "Custom"
82980 + help
82981 + If you choose this configuration method, you'll be able to configure all
82982 + grsecurity and PaX settings manually. Via this method, no options are
82983 + automatically enabled.
82984 +
82985 +endchoice
82986 +
82987 +choice
82988 + prompt "Usage Type"
82989 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82990 + default GRKERNSEC_CONFIG_SERVER
82991 + help
82992 +
82993 +config GRKERNSEC_CONFIG_SERVER
82994 + bool "Server"
82995 + help
82996 + Choose this option if you plan to use this kernel on a server.
82997 +
82998 +config GRKERNSEC_CONFIG_DESKTOP
82999 + bool "Desktop"
83000 + help
83001 + Choose this option if you plan to use this kernel on a desktop.
83002 +
83003 +endchoice
83004 +
83005 +choice
83006 + prompt "Virtualization Type"
83007 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
83008 + default GRKERNSEC_CONFIG_VIRT_NONE
83009 + help
83010 +
83011 +config GRKERNSEC_CONFIG_VIRT_NONE
83012 + bool "None"
83013 + help
83014 + Choose this option if this kernel will be run on bare metal.
83015 +
83016 +config GRKERNSEC_CONFIG_VIRT_GUEST
83017 + bool "Guest"
83018 + help
83019 + Choose this option if this kernel will be run as a VM guest.
83020 +
83021 +config GRKERNSEC_CONFIG_VIRT_HOST
83022 + bool "Host"
83023 + help
83024 + Choose this option if this kernel will be run as a VM host.
83025 +
83026 +endchoice
83027 +
83028 +choice
83029 + prompt "Virtualization Hardware"
83030 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
83031 + help
83032 +
83033 +config GRKERNSEC_CONFIG_VIRT_EPT
83034 + bool "EPT/RVI Processor Support"
83035 + depends on X86
83036 + help
83037 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
83038 + hardware virtualization. This allows for additional kernel hardening protections
83039 + to operate without additional performance impact.
83040 +
83041 + To see if your Intel processor supports EPT, see:
83042 + http://ark.intel.com/Products/VirtualizationTechnology
83043 + (Most Core i3/5/7 support EPT)
83044 +
83045 + To see if your AMD processor supports RVI, see:
83046 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
83047 +
83048 +config GRKERNSEC_CONFIG_VIRT_SOFT
83049 + bool "First-gen/No Hardware Virtualization"
83050 + help
83051 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
83052 + support hardware virtualization or doesn't support the EPT/RVI extensions.
83053 +
83054 +endchoice
83055 +
83056 +choice
83057 + prompt "Virtualization Software"
83058 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
83059 + help
83060 +
83061 +config GRKERNSEC_CONFIG_VIRT_XEN
83062 + bool "Xen"
83063 + help
83064 + Choose this option if this kernel is running as a Xen guest or host.
83065 +
83066 +config GRKERNSEC_CONFIG_VIRT_VMWARE
83067 + bool "VMWare"
83068 + help
83069 + Choose this option if this kernel is running as a VMWare guest or host.
83070 +
83071 +config GRKERNSEC_CONFIG_VIRT_KVM
83072 + bool "KVM"
83073 + help
83074 + Choose this option if this kernel is running as a KVM guest or host.
83075 +
83076 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
83077 + bool "VirtualBox"
83078 + help
83079 + Choose this option if this kernel is running as a VirtualBox guest or host.
83080 +
83081 +endchoice
83082 +
83083 +choice
83084 + prompt "Required Priorities"
83085 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83086 + default GRKERNSEC_CONFIG_PRIORITY_PERF
83087 + help
83088 +
83089 +config GRKERNSEC_CONFIG_PRIORITY_PERF
83090 + bool "Performance"
83091 + help
83092 + Choose this option if performance is of highest priority for this deployment
83093 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
83094 + and freed memory sanitizing will be disabled.
83095 +
83096 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
83097 + bool "Security"
83098 + help
83099 + Choose this option if security is of highest priority for this deployment of
83100 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
83101 + be enabled for this kernel. In a worst-case scenario, these features can
83102 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
83103 +
83104 +endchoice
83105 +
83106 +menu "Default Special Groups"
83107 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83108 +
83109 +config GRKERNSEC_PROC_GID
83110 + int "GID exempted from /proc restrictions"
83111 + default 1001
83112 + help
83113 + Setting this GID determines which group will be exempted from
83114 + grsecurity's /proc restrictions, allowing users of the specified
83115 + group to view network statistics and the existence of other users'
83116 + processes on the system. This GID may also be chosen at boot time
83117 + via "grsec_proc_gid=" on the kernel commandline.
83118 +
83119 +config GRKERNSEC_TPE_UNTRUSTED_GID
83120 + int "GID for TPE-untrusted users"
83121 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
83122 + default 1005
83123 + help
83124 + Setting this GID determines which group untrusted users should
83125 + be added to. These users will be placed under grsecurity's Trusted Path
83126 + Execution mechanism, preventing them from executing their own binaries.
83127 + The users will only be able to execute binaries in directories owned and
83128 + writable only by the root user. If the sysctl option is enabled, a sysctl
83129 + option with name "tpe_gid" is created.
83130 +
83131 +config GRKERNSEC_TPE_TRUSTED_GID
83132 + int "GID for TPE-trusted users"
83133 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
83134 + default 1005
83135 + help
83136 + Setting this GID determines what group TPE restrictions will be
83137 + *disabled* for. If the sysctl option is enabled, a sysctl option
83138 + with name "tpe_gid" is created.
83139 +
83140 +config GRKERNSEC_SYMLINKOWN_GID
83141 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
83142 + depends on GRKERNSEC_CONFIG_SERVER
83143 + default 1006
83144 + help
83145 + Setting this GID determines what group kernel-enforced
83146 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
83147 + is enabled, a sysctl option with name "symlinkown_gid" is created.
83148 +
83149 +
83150 +endmenu
83151 +
83152 +menu "Customize Configuration"
83153 +depends on GRKERNSEC
83154 +
83155 +menu "PaX"
83156 +
83157 +config PAX
83158 + bool "Enable various PaX features"
83159 + default y if GRKERNSEC_CONFIG_AUTO
83160 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
83161 + help
83162 + This allows you to enable various PaX features. PaX adds
83163 + intrusion prevention mechanisms to the kernel that reduce
83164 + the risks posed by exploitable memory corruption bugs.
83165 +
83166 +menu "PaX Control"
83167 + depends on PAX
83168 +
83169 +config PAX_SOFTMODE
83170 + bool 'Support soft mode'
83171 + help
83172 + Enabling this option will allow you to run PaX in soft mode, that
83173 + is, PaX features will not be enforced by default, only on executables
83174 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
83175 + support as they are the only way to mark executables for soft mode use.
83176 +
83177 + Soft mode can be activated by using the "pax_softmode=1" kernel command
83178 + line option on boot. Furthermore you can control various PaX features
83179 + at runtime via the entries in /proc/sys/kernel/pax.
83180 +
83181 +config PAX_EI_PAX
83182 + bool 'Use legacy ELF header marking'
83183 + default y if GRKERNSEC_CONFIG_AUTO
83184 + help
83185 + Enabling this option will allow you to control PaX features on
83186 + a per executable basis via the 'chpax' utility available at
83187 + http://pax.grsecurity.net/. The control flags will be read from
83188 + an otherwise reserved part of the ELF header. This marking has
83189 + numerous drawbacks (no support for soft-mode, toolchain does not
83190 + know about the non-standard use of the ELF header) therefore it
83191 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
83192 + support.
83193 +
83194 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
83195 + support as well, they will override the legacy EI_PAX marks.
83196 +
83197 + If you enable none of the marking options then all applications
83198 + will run with PaX enabled on them by default.
83199 +
83200 +config PAX_PT_PAX_FLAGS
83201 + bool 'Use ELF program header marking'
83202 + default y if GRKERNSEC_CONFIG_AUTO
83203 + help
83204 + Enabling this option will allow you to control PaX features on
83205 + a per executable basis via the 'paxctl' utility available at
83206 + http://pax.grsecurity.net/. The control flags will be read from
83207 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
83208 + has the benefits of supporting both soft mode and being fully
83209 + integrated into the toolchain (the binutils patch is available
83210 + from http://pax.grsecurity.net).
83211 +
83212 + Note that if you enable the legacy EI_PAX marking support as well,
83213 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
83214 +
83215 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83216 + must make sure that the marks are the same if a binary has both marks.
83217 +
83218 + If you enable none of the marking options then all applications
83219 + will run with PaX enabled on them by default.
83220 +
83221 +config PAX_XATTR_PAX_FLAGS
83222 + bool 'Use filesystem extended attributes marking'
83223 + default y if GRKERNSEC_CONFIG_AUTO
83224 + select CIFS_XATTR if CIFS
83225 + select EXT2_FS_XATTR if EXT2_FS
83226 + select EXT3_FS_XATTR if EXT3_FS
83227 + select EXT4_FS_XATTR if EXT4_FS
83228 + select JFFS2_FS_XATTR if JFFS2_FS
83229 + select REISERFS_FS_XATTR if REISERFS_FS
83230 + select SQUASHFS_XATTR if SQUASHFS
83231 + select TMPFS_XATTR if TMPFS
83232 + select UBIFS_FS_XATTR if UBIFS_FS
83233 + help
83234 + Enabling this option will allow you to control PaX features on
83235 + a per executable basis via the 'setfattr' utility. The control
83236 + flags will be read from the user.pax.flags extended attribute of
83237 + the file. This marking has the benefit of supporting binary-only
83238 + applications that self-check themselves (e.g., skype) and would
83239 + not tolerate chpax/paxctl changes. The main drawback is that
83240 + extended attributes are not supported by some filesystems (e.g.,
83241 + isofs, udf, vfat) so copying files through such filesystems will
83242 + lose the extended attributes and these PaX markings.
83243 +
83244 + Note that if you enable the legacy EI_PAX marking support as well,
83245 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
83246 +
83247 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83248 + must make sure that the marks are the same if a binary has both marks.
83249 +
83250 + If you enable none of the marking options then all applications
83251 + will run with PaX enabled on them by default.
83252 +
83253 +choice
83254 + prompt 'MAC system integration'
83255 + default PAX_HAVE_ACL_FLAGS
83256 + help
83257 + Mandatory Access Control systems have the option of controlling
83258 + PaX flags on a per executable basis, choose the method supported
83259 + by your particular system.
83260 +
83261 + - "none": if your MAC system does not interact with PaX,
83262 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
83263 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
83264 +
83265 + NOTE: this option is for developers/integrators only.
83266 +
83267 + config PAX_NO_ACL_FLAGS
83268 + bool 'none'
83269 +
83270 + config PAX_HAVE_ACL_FLAGS
83271 + bool 'direct'
83272 +
83273 + config PAX_HOOK_ACL_FLAGS
83274 + bool 'hook'
83275 +endchoice
83276 +
83277 +endmenu
83278 +
83279 +menu "Non-executable pages"
83280 + depends on PAX
83281 +
83282 +config PAX_NOEXEC
83283 + bool "Enforce non-executable pages"
83284 + default y if GRKERNSEC_CONFIG_AUTO
83285 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
83286 + help
83287 + By design some architectures do not allow for protecting memory
83288 + pages against execution or even if they do, Linux does not make
83289 + use of this feature. In practice this means that if a page is
83290 + readable (such as the stack or heap) it is also executable.
83291 +
83292 + There is a well known exploit technique that makes use of this
83293 + fact and a common programming mistake where an attacker can
83294 + introduce code of his choice somewhere in the attacked program's
83295 + memory (typically the stack or the heap) and then execute it.
83296 +
83297 + If the attacked program was running with different (typically
83298 + higher) privileges than that of the attacker, then he can elevate
83299 + his own privilege level (e.g. get a root shell, write to files for
83300 + which he does not have write access to, etc).
83301 +
83302 + Enabling this option will let you choose from various features
83303 + that prevent the injection and execution of 'foreign' code in
83304 + a program.
83305 +
83306 + This will also break programs that rely on the old behaviour and
83307 + expect that dynamically allocated memory via the malloc() family
83308 + of functions is executable (which it is not). Notable examples
83309 + are the XFree86 4.x server, the java runtime and wine.
83310 +
83311 +config PAX_PAGEEXEC
83312 + bool "Paging based non-executable pages"
83313 + default y if GRKERNSEC_CONFIG_AUTO
83314 + 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)
83315 + select S390_SWITCH_AMODE if S390
83316 + select S390_EXEC_PROTECT if S390
83317 + select ARCH_TRACK_EXEC_LIMIT if X86_32
83318 + help
83319 + This implementation is based on the paging feature of the CPU.
83320 + On i386 without hardware non-executable bit support there is a
83321 + variable but usually low performance impact, however on Intel's
83322 + P4 core based CPUs it is very high so you should not enable this
83323 + for kernels meant to be used on such CPUs.
83324 +
83325 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
83326 + with hardware non-executable bit support there is no performance
83327 + impact, on ppc the impact is negligible.
83328 +
83329 + Note that several architectures require various emulations due to
83330 + badly designed userland ABIs, this will cause a performance impact
83331 + but will disappear as soon as userland is fixed. For example, ppc
83332 + userland MUST have been built with secure-plt by a recent toolchain.
83333 +
83334 +config PAX_SEGMEXEC
83335 + bool "Segmentation based non-executable pages"
83336 + default y if GRKERNSEC_CONFIG_AUTO
83337 + depends on PAX_NOEXEC && X86_32
83338 + help
83339 + This implementation is based on the segmentation feature of the
83340 + CPU and has a very small performance impact, however applications
83341 + will be limited to a 1.5 GB address space instead of the normal
83342 + 3 GB.
83343 +
83344 +config PAX_EMUTRAMP
83345 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
83346 + default y if PARISC
83347 + help
83348 + There are some programs and libraries that for one reason or
83349 + another attempt to execute special small code snippets from
83350 + non-executable memory pages. Most notable examples are the
83351 + signal handler return code generated by the kernel itself and
83352 + the GCC trampolines.
83353 +
83354 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
83355 + such programs will no longer work under your kernel.
83356 +
83357 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
83358 + utilities to enable trampoline emulation for the affected programs
83359 + yet still have the protection provided by the non-executable pages.
83360 +
83361 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
83362 + your system will not even boot.
83363 +
83364 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
83365 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
83366 + for the affected files.
83367 +
83368 + NOTE: enabling this feature *may* open up a loophole in the
83369 + protection provided by non-executable pages that an attacker
83370 + could abuse. Therefore the best solution is to not have any
83371 + files on your system that would require this option. This can
83372 + be achieved by not using libc5 (which relies on the kernel
83373 + signal handler return code) and not using or rewriting programs
83374 + that make use of the nested function implementation of GCC.
83375 + Skilled users can just fix GCC itself so that it implements
83376 + nested function calls in a way that does not interfere with PaX.
83377 +
83378 +config PAX_EMUSIGRT
83379 + bool "Automatically emulate sigreturn trampolines"
83380 + depends on PAX_EMUTRAMP && PARISC
83381 + default y
83382 + help
83383 + Enabling this option will have the kernel automatically detect
83384 + and emulate signal return trampolines executing on the stack
83385 + that would otherwise lead to task termination.
83386 +
83387 + This solution is intended as a temporary one for users with
83388 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
83389 + Modula-3 runtime, etc) or executables linked to such, basically
83390 + everything that does not specify its own SA_RESTORER function in
83391 + normal executable memory like glibc 2.1+ does.
83392 +
83393 + On parisc you MUST enable this option, otherwise your system will
83394 + not even boot.
83395 +
83396 + NOTE: this feature cannot be disabled on a per executable basis
83397 + and since it *does* open up a loophole in the protection provided
83398 + by non-executable pages, the best solution is to not have any
83399 + files on your system that would require this option.
83400 +
83401 +config PAX_MPROTECT
83402 + bool "Restrict mprotect()"
83403 + default y if GRKERNSEC_CONFIG_AUTO
83404 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
83405 + help
83406 + Enabling this option will prevent programs from
83407 + - changing the executable status of memory pages that were
83408 + not originally created as executable,
83409 + - making read-only executable pages writable again,
83410 + - creating executable pages from anonymous memory,
83411 + - making read-only-after-relocations (RELRO) data pages writable again.
83412 +
83413 + You should say Y here to complete the protection provided by
83414 + the enforcement of non-executable pages.
83415 +
83416 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83417 + this feature on a per file basis.
83418 +
83419 +config PAX_MPROTECT_COMPAT
83420 + bool "Use legacy/compat protection demoting (read help)"
83421 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83422 + depends on PAX_MPROTECT
83423 + help
83424 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
83425 + by sending the proper error code to the application. For some broken
83426 + userland, this can cause problems with Python or other applications. The
83427 + current implementation however allows for applications like clamav to
83428 + detect if JIT compilation/execution is allowed and to fall back gracefully
83429 + to an interpreter-based mode if it does not. While we encourage everyone
83430 + to use the current implementation as-is and push upstream to fix broken
83431 + userland (note that the RWX logging option can assist with this), in some
83432 + environments this may not be possible. Having to disable MPROTECT
83433 + completely on certain binaries reduces the security benefit of PaX,
83434 + so this option is provided for those environments to revert to the old
83435 + behavior.
83436 +
83437 +config PAX_ELFRELOCS
83438 + bool "Allow ELF text relocations (read help)"
83439 + depends on PAX_MPROTECT
83440 + default n
83441 + help
83442 + Non-executable pages and mprotect() restrictions are effective
83443 + in preventing the introduction of new executable code into an
83444 + attacked task's address space. There remain only two venues
83445 + for this kind of attack: if the attacker can execute already
83446 + existing code in the attacked task then he can either have it
83447 + create and mmap() a file containing his code or have it mmap()
83448 + an already existing ELF library that does not have position
83449 + independent code in it and use mprotect() on it to make it
83450 + writable and copy his code there. While protecting against
83451 + the former approach is beyond PaX, the latter can be prevented
83452 + by having only PIC ELF libraries on one's system (which do not
83453 + need to relocate their code). If you are sure this is your case,
83454 + as is the case with all modern Linux distributions, then leave
83455 + this option disabled. You should say 'n' here.
83456 +
83457 +config PAX_ETEXECRELOCS
83458 + bool "Allow ELF ET_EXEC text relocations"
83459 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
83460 + select PAX_ELFRELOCS
83461 + default y
83462 + help
83463 + On some architectures there are incorrectly created applications
83464 + that require text relocations and would not work without enabling
83465 + this option. If you are an alpha, ia64 or parisc user, you should
83466 + enable this option and disable it once you have made sure that
83467 + none of your applications need it.
83468 +
83469 +config PAX_EMUPLT
83470 + bool "Automatically emulate ELF PLT"
83471 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
83472 + default y
83473 + help
83474 + Enabling this option will have the kernel automatically detect
83475 + and emulate the Procedure Linkage Table entries in ELF files.
83476 + On some architectures such entries are in writable memory, and
83477 + become non-executable leading to task termination. Therefore
83478 + it is mandatory that you enable this option on alpha, parisc,
83479 + sparc and sparc64, otherwise your system would not even boot.
83480 +
83481 + NOTE: this feature *does* open up a loophole in the protection
83482 + provided by the non-executable pages, therefore the proper
83483 + solution is to modify the toolchain to produce a PLT that does
83484 + not need to be writable.
83485 +
83486 +config PAX_DLRESOLVE
83487 + bool 'Emulate old glibc resolver stub'
83488 + depends on PAX_EMUPLT && SPARC
83489 + default n
83490 + help
83491 + This option is needed if userland has an old glibc (before 2.4)
83492 + that puts a 'save' instruction into the runtime generated resolver
83493 + stub that needs special emulation.
83494 +
83495 +config PAX_KERNEXEC
83496 + bool "Enforce non-executable kernel pages"
83497 + 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))
83498 + depends on (X86 || ARM_LPAE) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
83499 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
83500 + select PAX_KERNEXEC_PLUGIN if X86_64
83501 + help
83502 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
83503 + that is, enabling this option will make it harder to inject
83504 + and execute 'foreign' code in kernel memory itself.
83505 +
83506 +choice
83507 + prompt "Return Address Instrumentation Method"
83508 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
83509 + depends on PAX_KERNEXEC_PLUGIN
83510 + help
83511 + Select the method used to instrument function pointer dereferences.
83512 + Note that binary modules cannot be instrumented by this approach.
83513 +
83514 + Note that the implementation requires a gcc with plugin support,
83515 + i.e., gcc 4.5 or newer. You may need to install the supporting
83516 + headers explicitly in addition to the normal gcc package.
83517 +
83518 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
83519 + bool "bts"
83520 + help
83521 + This method is compatible with binary only modules but has
83522 + a higher runtime overhead.
83523 +
83524 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
83525 + bool "or"
83526 + depends on !PARAVIRT
83527 + help
83528 + This method is incompatible with binary only modules but has
83529 + a lower runtime overhead.
83530 +endchoice
83531 +
83532 +config PAX_KERNEXEC_PLUGIN_METHOD
83533 + string
83534 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
83535 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
83536 + default ""
83537 +
83538 +config PAX_KERNEXEC_MODULE_TEXT
83539 + int "Minimum amount of memory reserved for module code"
83540 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
83541 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83542 + depends on PAX_KERNEXEC && X86_32 && MODULES
83543 + help
83544 + Due to implementation details the kernel must reserve a fixed
83545 + amount of memory for module code at compile time that cannot be
83546 + changed at runtime. Here you can specify the minimum amount
83547 + in MB that will be reserved. Due to the same implementation
83548 + details this size will always be rounded up to the next 2/4 MB
83549 + boundary (depends on PAE) so the actually available memory for
83550 + module code will usually be more than this minimum.
83551 +
83552 + The default 4 MB should be enough for most users but if you have
83553 + an excessive number of modules (e.g., most distribution configs
83554 + compile many drivers as modules) or use huge modules such as
83555 + nvidia's kernel driver, you will need to adjust this amount.
83556 + A good rule of thumb is to look at your currently loaded kernel
83557 + modules and add up their sizes.
83558 +
83559 +endmenu
83560 +
83561 +menu "Address Space Layout Randomization"
83562 + depends on PAX
83563 +
83564 +config PAX_ASLR
83565 + bool "Address Space Layout Randomization"
83566 + default y if GRKERNSEC_CONFIG_AUTO
83567 + help
83568 + Many if not most exploit techniques rely on the knowledge of
83569 + certain addresses in the attacked program. The following options
83570 + will allow the kernel to apply a certain amount of randomization
83571 + to specific parts of the program thereby forcing an attacker to
83572 + guess them in most cases. Any failed guess will most likely crash
83573 + the attacked program which allows the kernel to detect such attempts
83574 + and react on them. PaX itself provides no reaction mechanisms,
83575 + instead it is strongly encouraged that you make use of Nergal's
83576 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
83577 + (http://www.grsecurity.net/) built-in crash detection features or
83578 + develop one yourself.
83579 +
83580 + By saying Y here you can choose to randomize the following areas:
83581 + - top of the task's kernel stack
83582 + - top of the task's userland stack
83583 + - base address for mmap() requests that do not specify one
83584 + (this includes all libraries)
83585 + - base address of the main executable
83586 +
83587 + It is strongly recommended to say Y here as address space layout
83588 + randomization has negligible impact on performance yet it provides
83589 + a very effective protection.
83590 +
83591 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83592 + this feature on a per file basis.
83593 +
83594 +config PAX_RANDKSTACK
83595 + bool "Randomize kernel stack base"
83596 + default y if GRKERNSEC_CONFIG_AUTO
83597 + depends on X86_TSC && X86
83598 + help
83599 + By saying Y here the kernel will randomize every task's kernel
83600 + stack on every system call. This will not only force an attacker
83601 + to guess it but also prevent him from making use of possible
83602 + leaked information about it.
83603 +
83604 + Since the kernel stack is a rather scarce resource, randomization
83605 + may cause unexpected stack overflows, therefore you should very
83606 + carefully test your system. Note that once enabled in the kernel
83607 + configuration, this feature cannot be disabled on a per file basis.
83608 +
83609 +config PAX_RANDUSTACK
83610 + bool "Randomize user stack base"
83611 + default y if GRKERNSEC_CONFIG_AUTO
83612 + depends on PAX_ASLR
83613 + help
83614 + By saying Y here the kernel will randomize every task's userland
83615 + stack. The randomization is done in two steps where the second
83616 + one may apply a big amount of shift to the top of the stack and
83617 + cause problems for programs that want to use lots of memory (more
83618 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
83619 + For this reason the second step can be controlled by 'chpax' or
83620 + 'paxctl' on a per file basis.
83621 +
83622 +config PAX_RANDMMAP
83623 + bool "Randomize mmap() base"
83624 + default y if GRKERNSEC_CONFIG_AUTO
83625 + depends on PAX_ASLR
83626 + help
83627 + By saying Y here the kernel will use a randomized base address for
83628 + mmap() requests that do not specify one themselves. As a result
83629 + all dynamically loaded libraries will appear at random addresses
83630 + and therefore be harder to exploit by a technique where an attacker
83631 + attempts to execute library code for his purposes (e.g. spawn a
83632 + shell from an exploited program that is running at an elevated
83633 + privilege level).
83634 +
83635 + Furthermore, if a program is relinked as a dynamic ELF file, its
83636 + base address will be randomized as well, completing the full
83637 + randomization of the address space layout. Attacking such programs
83638 + becomes a guess game. You can find an example of doing this at
83639 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
83640 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
83641 +
83642 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
83643 + feature on a per file basis.
83644 +
83645 +endmenu
83646 +
83647 +menu "Miscellaneous hardening features"
83648 +
83649 +config PAX_MEMORY_SANITIZE
83650 + bool "Sanitize all freed memory"
83651 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83652 + depends on !HIBERNATION
83653 + help
83654 + By saying Y here the kernel will erase memory pages as soon as they
83655 + are freed. This in turn reduces the lifetime of data stored in the
83656 + pages, making it less likely that sensitive information such as
83657 + passwords, cryptographic secrets, etc stay in memory for too long.
83658 +
83659 + This is especially useful for programs whose runtime is short, long
83660 + lived processes and the kernel itself benefit from this as long as
83661 + they operate on whole memory pages and ensure timely freeing of pages
83662 + that may hold sensitive information.
83663 +
83664 + The tradeoff is performance impact, on a single CPU system kernel
83665 + compilation sees a 3% slowdown, other systems and workloads may vary
83666 + and you are advised to test this feature on your expected workload
83667 + before deploying it.
83668 +
83669 + Note that this feature does not protect data stored in live pages,
83670 + e.g., process memory swapped to disk may stay there for a long time.
83671 +
83672 +config PAX_MEMORY_STACKLEAK
83673 + bool "Sanitize kernel stack"
83674 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83675 + depends on X86
83676 + help
83677 + By saying Y here the kernel will erase the kernel stack before it
83678 + returns from a system call. This in turn reduces the information
83679 + that a kernel stack leak bug can reveal.
83680 +
83681 + Note that such a bug can still leak information that was put on
83682 + the stack by the current system call (the one eventually triggering
83683 + the bug) but traces of earlier system calls on the kernel stack
83684 + cannot leak anymore.
83685 +
83686 + The tradeoff is performance impact: on a single CPU system kernel
83687 + compilation sees a 1% slowdown, other systems and workloads may vary
83688 + and you are advised to test this feature on your expected workload
83689 + before deploying it.
83690 +
83691 + Note that the full feature requires a gcc with plugin support,
83692 + i.e., gcc 4.5 or newer. You may need to install the supporting
83693 + headers explicitly in addition to the normal gcc package. Using
83694 + older gcc versions means that functions with large enough stack
83695 + frames may leave uninitialized memory behind that may be exposed
83696 + to a later syscall leaking the stack.
83697 +
83698 +config PAX_MEMORY_UDEREF
83699 + bool "Prevent invalid userland pointer dereference"
83700 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
83701 + depends on X86 && !UML_X86 && !XEN
83702 + select PAX_PER_CPU_PGD if X86_64
83703 + help
83704 + By saying Y here the kernel will be prevented from dereferencing
83705 + userland pointers in contexts where the kernel expects only kernel
83706 + pointers. This is both a useful runtime debugging feature and a
83707 + security measure that prevents exploiting a class of kernel bugs.
83708 +
83709 + The tradeoff is that some virtualization solutions may experience
83710 + a huge slowdown and therefore you should not enable this feature
83711 + for kernels meant to run in such environments. Whether a given VM
83712 + solution is affected or not is best determined by simply trying it
83713 + out, the performance impact will be obvious right on boot as this
83714 + mechanism engages from very early on. A good rule of thumb is that
83715 + VMs running on CPUs without hardware virtualization support (i.e.,
83716 + the majority of IA-32 CPUs) will likely experience the slowdown.
83717 +
83718 +config PAX_REFCOUNT
83719 + bool "Prevent various kernel object reference counter overflows"
83720 + default y if GRKERNSEC_CONFIG_AUTO
83721 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
83722 + help
83723 + By saying Y here the kernel will detect and prevent overflowing
83724 + various (but not all) kinds of object reference counters. Such
83725 + overflows can normally occur due to bugs only and are often, if
83726 + not always, exploitable.
83727 +
83728 + The tradeoff is that data structures protected by an overflowed
83729 + refcount will never be freed and therefore will leak memory. Note
83730 + that this leak also happens even without this protection but in
83731 + that case the overflow can eventually trigger the freeing of the
83732 + data structure while it is still being used elsewhere, resulting
83733 + in the exploitable situation that this feature prevents.
83734 +
83735 + Since this has a negligible performance impact, you should enable
83736 + this feature.
83737 +
83738 +config PAX_USERCOPY
83739 + bool "Harden heap object copies between kernel and userland"
83740 + default y if GRKERNSEC_CONFIG_AUTO
83741 + depends on ARM || IA64 || PPC || SPARC || X86
83742 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
83743 + select PAX_USERCOPY_SLABS
83744 + help
83745 + By saying Y here the kernel will enforce the size of heap objects
83746 + when they are copied in either direction between the kernel and
83747 + userland, even if only a part of the heap object is copied.
83748 +
83749 + Specifically, this checking prevents information leaking from the
83750 + kernel heap during kernel to userland copies (if the kernel heap
83751 + object is otherwise fully initialized) and prevents kernel heap
83752 + overflows during userland to kernel copies.
83753 +
83754 + Note that the current implementation provides the strictest bounds
83755 + checks for the SLUB allocator.
83756 +
83757 + Enabling this option also enables per-slab cache protection against
83758 + data in a given cache being copied into/out of via userland
83759 + accessors. Though the whitelist of regions will be reduced over
83760 + time, it notably protects important data structures like task structs.
83761 +
83762 + If frame pointers are enabled on x86, this option will also restrict
83763 + copies into and out of the kernel stack to local variables within a
83764 + single frame.
83765 +
83766 + Since this has a negligible performance impact, you should enable
83767 + this feature.
83768 +
83769 +
83770 +config PAX_USERCOPY_DEBUG
83771 + bool
83772 + depends on X86 && PAX_USERCOPY
83773 + default n
83774 +
83775 +config PAX_SIZE_OVERFLOW
83776 + bool "Prevent various integer overflows in function size parameters"
83777 + default y if GRKERNSEC_CONFIG_AUTO
83778 + depends on X86
83779 + help
83780 + By saying Y here the kernel recomputes expressions of function
83781 + arguments marked by a size_overflow attribute with double integer
83782 + precision (DImode/TImode for 32/64 bit integer types).
83783 +
83784 + The recomputed argument is checked against TYPE_MAX and an event
83785 + is logged on overflow and the triggering process is killed.
83786 +
83787 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
83788 +
83789 + Note that the implementation requires a gcc with plugin support,
83790 + i.e., gcc 4.5 or newer. You may need to install the supporting
83791 + headers explicitly in addition to the normal gcc package.
83792 +
83793 +config PAX_LATENT_ENTROPY
83794 + bool "Generate some entropy during boot"
83795 + default y if GRKERNSEC_CONFIG_AUTO
83796 + help
83797 + By saying Y here the kernel will instrument early boot code to
83798 + extract some entropy from both original and artificially created
83799 + program state. This will help especially embedded systems where
83800 + there is little 'natural' source of entropy normally. The cost
83801 + is some slowdown of the boot process.
83802 +
83803 + Note that the implementation requires a gcc with plugin support,
83804 + i.e., gcc 4.5 or newer. You may need to install the supporting
83805 + headers explicitly in addition to the normal gcc package.
83806 +
83807 + Note that entropy extracted this way is not cryptographically
83808 + secure!
83809 +
83810 +endmenu
83811 +
83812 +endmenu
83813 +
83814 +source grsecurity/Kconfig
83815 +
83816 +endmenu
83817 +
83818 +endmenu
83819 +
83820 source security/keys/Kconfig
83821
83822 config SECURITY_DMESG_RESTRICT
83823 @@ -103,7 +999,7 @@ config INTEL_TXT
83824 config LSM_MMAP_MIN_ADDR
83825 int "Low address space for LSM to protect from user allocation"
83826 depends on SECURITY && SECURITY_SELINUX
83827 - default 32768 if ARM
83828 + default 32768 if ALPHA || ARM || PARISC || SPARC32
83829 default 65536
83830 help
83831 This is the portion of low virtual memory which should be protected
83832 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
83833 index 8c2a7f6..b133ac9 100644
83834 --- a/security/apparmor/lsm.c
83835 +++ b/security/apparmor/lsm.c
83836 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
83837 return error;
83838 }
83839
83840 -static struct security_operations apparmor_ops = {
83841 +static struct security_operations apparmor_ops __read_only = {
83842 .name = "apparmor",
83843
83844 .ptrace_access_check = apparmor_ptrace_access_check,
83845 diff --git a/security/commoncap.c b/security/commoncap.c
83846 index 6dbae46..d5611fd 100644
83847 --- a/security/commoncap.c
83848 +++ b/security/commoncap.c
83849 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
83850 return 0;
83851 }
83852
83853 +/* returns:
83854 + 1 for suid privilege
83855 + 2 for sgid privilege
83856 + 3 for fscap privilege
83857 +*/
83858 +int is_privileged_binary(const struct dentry *dentry)
83859 +{
83860 + struct cpu_vfs_cap_data capdata;
83861 + struct inode *inode = dentry->d_inode;
83862 +
83863 + if (!inode || S_ISDIR(inode->i_mode))
83864 + return 0;
83865 +
83866 + if (inode->i_mode & S_ISUID)
83867 + return 1;
83868 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
83869 + return 2;
83870 +
83871 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
83872 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
83873 + return 3;
83874 + }
83875 +
83876 + return 0;
83877 +}
83878 +
83879 /*
83880 * Attempt to get the on-exec apply capability sets for an executable file from
83881 * its xattrs and, if present, apply them to the proposed credentials being
83882 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
83883 const struct cred *cred = current_cred();
83884 kuid_t root_uid = make_kuid(cred->user_ns, 0);
83885
83886 + if (gr_acl_enable_at_secure())
83887 + return 1;
83888 +
83889 if (!uid_eq(cred->uid, root_uid)) {
83890 if (bprm->cap_effective)
83891 return 1;
83892 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
83893 index 6ee8826..6350060 100644
83894 --- a/security/integrity/ima/ima.h
83895 +++ b/security/integrity/ima/ima.h
83896 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83897 extern spinlock_t ima_queue_lock;
83898
83899 struct ima_h_table {
83900 - atomic_long_t len; /* number of stored measurements in the list */
83901 - atomic_long_t violations;
83902 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
83903 + atomic_long_unchecked_t violations;
83904 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
83905 };
83906 extern struct ima_h_table ima_htable;
83907 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
83908 index b356884..fd9676e 100644
83909 --- a/security/integrity/ima/ima_api.c
83910 +++ b/security/integrity/ima/ima_api.c
83911 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83912 int result;
83913
83914 /* can overflow, only indicator */
83915 - atomic_long_inc(&ima_htable.violations);
83916 + atomic_long_inc_unchecked(&ima_htable.violations);
83917
83918 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
83919 if (!entry) {
83920 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
83921 index 38477c9..87a60c7 100644
83922 --- a/security/integrity/ima/ima_fs.c
83923 +++ b/security/integrity/ima/ima_fs.c
83924 @@ -28,12 +28,12 @@
83925 static int valid_policy = 1;
83926 #define TMPBUFLEN 12
83927 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
83928 - loff_t *ppos, atomic_long_t *val)
83929 + loff_t *ppos, atomic_long_unchecked_t *val)
83930 {
83931 char tmpbuf[TMPBUFLEN];
83932 ssize_t len;
83933
83934 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
83935 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
83936 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
83937 }
83938
83939 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
83940 index 55a6271..ad829c3 100644
83941 --- a/security/integrity/ima/ima_queue.c
83942 +++ b/security/integrity/ima/ima_queue.c
83943 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
83944 INIT_LIST_HEAD(&qe->later);
83945 list_add_tail_rcu(&qe->later, &ima_measurements);
83946
83947 - atomic_long_inc(&ima_htable.len);
83948 + atomic_long_inc_unchecked(&ima_htable.len);
83949 key = ima_hash_key(entry->digest);
83950 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
83951 return 0;
83952 diff --git a/security/keys/compat.c b/security/keys/compat.c
83953 index 1c26176..64a1ba2 100644
83954 --- a/security/keys/compat.c
83955 +++ b/security/keys/compat.c
83956 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
83957 if (ret == 0)
83958 goto no_payload_free;
83959
83960 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
83961 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
83962
83963 if (iov != iovstack)
83964 kfree(iov);
83965 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
83966 index 5d34b4e..2456674 100644
83967 --- a/security/keys/keyctl.c
83968 +++ b/security/keys/keyctl.c
83969 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
83970 /*
83971 * Copy the iovec data from userspace
83972 */
83973 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83974 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
83975 unsigned ioc)
83976 {
83977 for (; ioc > 0; ioc--) {
83978 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83979 * If successful, 0 will be returned.
83980 */
83981 long keyctl_instantiate_key_common(key_serial_t id,
83982 - const struct iovec *payload_iov,
83983 + const struct iovec __user *payload_iov,
83984 unsigned ioc,
83985 size_t plen,
83986 key_serial_t ringid)
83987 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
83988 [0].iov_len = plen
83989 };
83990
83991 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
83992 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
83993 }
83994
83995 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
83996 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
83997 if (ret == 0)
83998 goto no_payload_free;
83999
84000 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
84001 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
84002
84003 if (iov != iovstack)
84004 kfree(iov);
84005 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
84006 index 6e42df1..aba52bd 100644
84007 --- a/security/keys/keyring.c
84008 +++ b/security/keys/keyring.c
84009 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
84010 ret = -EFAULT;
84011
84012 for (loop = 0; loop < klist->nkeys; loop++) {
84013 + key_serial_t serial;
84014 key = rcu_deref_link_locked(klist, loop,
84015 keyring);
84016 + serial = key->serial;
84017
84018 tmp = sizeof(key_serial_t);
84019 if (tmp > buflen)
84020 tmp = buflen;
84021
84022 - if (copy_to_user(buffer,
84023 - &key->serial,
84024 - tmp) != 0)
84025 + if (copy_to_user(buffer, &serial, tmp))
84026 goto error;
84027
84028 buflen -= tmp;
84029 diff --git a/security/min_addr.c b/security/min_addr.c
84030 index f728728..6457a0c 100644
84031 --- a/security/min_addr.c
84032 +++ b/security/min_addr.c
84033 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
84034 */
84035 static void update_mmap_min_addr(void)
84036 {
84037 +#ifndef SPARC
84038 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
84039 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
84040 mmap_min_addr = dac_mmap_min_addr;
84041 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
84042 #else
84043 mmap_min_addr = dac_mmap_min_addr;
84044 #endif
84045 +#endif
84046 }
84047
84048 /*
84049 diff --git a/security/security.c b/security/security.c
84050 index 8dcd4ae..1124de7 100644
84051 --- a/security/security.c
84052 +++ b/security/security.c
84053 @@ -20,6 +20,7 @@
84054 #include <linux/ima.h>
84055 #include <linux/evm.h>
84056 #include <linux/fsnotify.h>
84057 +#include <linux/mm.h>
84058 #include <linux/mman.h>
84059 #include <linux/mount.h>
84060 #include <linux/personality.h>
84061 @@ -32,8 +33,8 @@
84062 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
84063 CONFIG_DEFAULT_SECURITY;
84064
84065 -static struct security_operations *security_ops;
84066 -static struct security_operations default_security_ops = {
84067 +static struct security_operations *security_ops __read_only;
84068 +static struct security_operations default_security_ops __read_only = {
84069 .name = "default",
84070 };
84071
84072 @@ -74,7 +75,9 @@ int __init security_init(void)
84073
84074 void reset_security_ops(void)
84075 {
84076 + pax_open_kernel();
84077 security_ops = &default_security_ops;
84078 + pax_close_kernel();
84079 }
84080
84081 /* Save user chosen LSM */
84082 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
84083 index 61a5336..27215d8 100644
84084 --- a/security/selinux/hooks.c
84085 +++ b/security/selinux/hooks.c
84086 @@ -95,8 +95,6 @@
84087
84088 #define NUM_SEL_MNT_OPTS 5
84089
84090 -extern struct security_operations *security_ops;
84091 -
84092 /* SECMARK reference count */
84093 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
84094
84095 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
84096
84097 #endif
84098
84099 -static struct security_operations selinux_ops = {
84100 +static struct security_operations selinux_ops __read_only = {
84101 .name = "selinux",
84102
84103 .ptrace_access_check = selinux_ptrace_access_check,
84104 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
84105 index 65f67cb..3f141ef 100644
84106 --- a/security/selinux/include/xfrm.h
84107 +++ b/security/selinux/include/xfrm.h
84108 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
84109
84110 static inline void selinux_xfrm_notify_policyload(void)
84111 {
84112 - atomic_inc(&flow_cache_genid);
84113 + atomic_inc_unchecked(&flow_cache_genid);
84114 rt_genid_bump(&init_net);
84115 }
84116 #else
84117 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
84118 index 38be92c..21f49ee 100644
84119 --- a/security/smack/smack_lsm.c
84120 +++ b/security/smack/smack_lsm.c
84121 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
84122 return 0;
84123 }
84124
84125 -struct security_operations smack_ops = {
84126 +struct security_operations smack_ops __read_only = {
84127 .name = "smack",
84128
84129 .ptrace_access_check = smack_ptrace_access_check,
84130 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
84131 index a2ee362..5754f34 100644
84132 --- a/security/tomoyo/tomoyo.c
84133 +++ b/security/tomoyo/tomoyo.c
84134 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
84135 * tomoyo_security_ops is a "struct security_operations" which is used for
84136 * registering TOMOYO.
84137 */
84138 -static struct security_operations tomoyo_security_ops = {
84139 +static struct security_operations tomoyo_security_ops __read_only = {
84140 .name = "tomoyo",
84141 .cred_alloc_blank = tomoyo_cred_alloc_blank,
84142 .cred_prepare = tomoyo_cred_prepare,
84143 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
84144 index 20ef514..4182bed 100644
84145 --- a/security/yama/Kconfig
84146 +++ b/security/yama/Kconfig
84147 @@ -1,6 +1,6 @@
84148 config SECURITY_YAMA
84149 bool "Yama support"
84150 - depends on SECURITY
84151 + depends on SECURITY && !GRKERNSEC
84152 select SECURITYFS
84153 select SECURITY_PATH
84154 default n
84155 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
84156 index 4cedc69..e59d8a3 100644
84157 --- a/sound/aoa/codecs/onyx.c
84158 +++ b/sound/aoa/codecs/onyx.c
84159 @@ -54,7 +54,7 @@ struct onyx {
84160 spdif_locked:1,
84161 analog_locked:1,
84162 original_mute:2;
84163 - int open_count;
84164 + local_t open_count;
84165 struct codec_info *codec_info;
84166
84167 /* mutex serializes concurrent access to the device
84168 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
84169 struct onyx *onyx = cii->codec_data;
84170
84171 mutex_lock(&onyx->mutex);
84172 - onyx->open_count++;
84173 + local_inc(&onyx->open_count);
84174 mutex_unlock(&onyx->mutex);
84175
84176 return 0;
84177 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
84178 struct onyx *onyx = cii->codec_data;
84179
84180 mutex_lock(&onyx->mutex);
84181 - onyx->open_count--;
84182 - if (!onyx->open_count)
84183 + if (local_dec_and_test(&onyx->open_count))
84184 onyx->spdif_locked = onyx->analog_locked = 0;
84185 mutex_unlock(&onyx->mutex);
84186
84187 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
84188 index ffd2025..df062c9 100644
84189 --- a/sound/aoa/codecs/onyx.h
84190 +++ b/sound/aoa/codecs/onyx.h
84191 @@ -11,6 +11,7 @@
84192 #include <linux/i2c.h>
84193 #include <asm/pmac_low_i2c.h>
84194 #include <asm/prom.h>
84195 +#include <asm/local.h>
84196
84197 /* PCM3052 register definitions */
84198
84199 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
84200 index 4c1cc51..16040040 100644
84201 --- a/sound/core/oss/pcm_oss.c
84202 +++ b/sound/core/oss/pcm_oss.c
84203 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
84204 if (in_kernel) {
84205 mm_segment_t fs;
84206 fs = snd_enter_user();
84207 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84208 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84209 snd_leave_user(fs);
84210 } else {
84211 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84212 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84213 }
84214 if (ret != -EPIPE && ret != -ESTRPIPE)
84215 break;
84216 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
84217 if (in_kernel) {
84218 mm_segment_t fs;
84219 fs = snd_enter_user();
84220 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84221 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84222 snd_leave_user(fs);
84223 } else {
84224 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84225 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84226 }
84227 if (ret == -EPIPE) {
84228 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
84229 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
84230 struct snd_pcm_plugin_channel *channels;
84231 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
84232 if (!in_kernel) {
84233 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
84234 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
84235 return -EFAULT;
84236 buf = runtime->oss.buffer;
84237 }
84238 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
84239 }
84240 } else {
84241 tmp = snd_pcm_oss_write2(substream,
84242 - (const char __force *)buf,
84243 + (const char __force_kernel *)buf,
84244 runtime->oss.period_bytes, 0);
84245 if (tmp <= 0)
84246 goto err;
84247 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
84248 struct snd_pcm_runtime *runtime = substream->runtime;
84249 snd_pcm_sframes_t frames, frames1;
84250 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
84251 - char __user *final_dst = (char __force __user *)buf;
84252 + char __user *final_dst = (char __force_user *)buf;
84253 if (runtime->oss.plugin_first) {
84254 struct snd_pcm_plugin_channel *channels;
84255 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
84256 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
84257 xfer += tmp;
84258 runtime->oss.buffer_used -= tmp;
84259 } else {
84260 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
84261 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
84262 runtime->oss.period_bytes, 0);
84263 if (tmp <= 0)
84264 goto err;
84265 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
84266 size1);
84267 size1 /= runtime->channels; /* frames */
84268 fs = snd_enter_user();
84269 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
84270 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
84271 snd_leave_user(fs);
84272 }
84273 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
84274 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
84275 index 91cdf943..4085161 100644
84276 --- a/sound/core/pcm_compat.c
84277 +++ b/sound/core/pcm_compat.c
84278 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
84279 int err;
84280
84281 fs = snd_enter_user();
84282 - err = snd_pcm_delay(substream, &delay);
84283 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
84284 snd_leave_user(fs);
84285 if (err < 0)
84286 return err;
84287 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
84288 index f9ddecf..e27404d 100644
84289 --- a/sound/core/pcm_native.c
84290 +++ b/sound/core/pcm_native.c
84291 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
84292 switch (substream->stream) {
84293 case SNDRV_PCM_STREAM_PLAYBACK:
84294 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
84295 - (void __user *)arg);
84296 + (void __force_user *)arg);
84297 break;
84298 case SNDRV_PCM_STREAM_CAPTURE:
84299 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
84300 - (void __user *)arg);
84301 + (void __force_user *)arg);
84302 break;
84303 default:
84304 result = -EINVAL;
84305 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
84306 index 60e8fc1..786abcb 100644
84307 --- a/sound/core/seq/seq_device.c
84308 +++ b/sound/core/seq/seq_device.c
84309 @@ -64,7 +64,7 @@ struct ops_list {
84310 int argsize; /* argument size */
84311
84312 /* operators */
84313 - struct snd_seq_dev_ops ops;
84314 + struct snd_seq_dev_ops *ops;
84315
84316 /* registred devices */
84317 struct list_head dev_list; /* list of devices */
84318 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
84319
84320 mutex_lock(&ops->reg_mutex);
84321 /* copy driver operators */
84322 - ops->ops = *entry;
84323 + ops->ops = entry;
84324 ops->driver |= DRIVER_LOADED;
84325 ops->argsize = argsize;
84326
84327 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
84328 dev->name, ops->id, ops->argsize, dev->argsize);
84329 return -EINVAL;
84330 }
84331 - if (ops->ops.init_device(dev) >= 0) {
84332 + if (ops->ops->init_device(dev) >= 0) {
84333 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
84334 ops->num_init_devices++;
84335 } else {
84336 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
84337 dev->name, ops->id, ops->argsize, dev->argsize);
84338 return -EINVAL;
84339 }
84340 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
84341 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
84342 dev->status = SNDRV_SEQ_DEVICE_FREE;
84343 dev->driver_data = NULL;
84344 ops->num_init_devices--;
84345 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
84346 index 2d5514b..3afae9c 100644
84347 --- a/sound/drivers/mts64.c
84348 +++ b/sound/drivers/mts64.c
84349 @@ -29,6 +29,7 @@
84350 #include <sound/initval.h>
84351 #include <sound/rawmidi.h>
84352 #include <sound/control.h>
84353 +#include <asm/local.h>
84354
84355 #define CARD_NAME "Miditerminal 4140"
84356 #define DRIVER_NAME "MTS64"
84357 @@ -67,7 +68,7 @@ struct mts64 {
84358 struct pardevice *pardev;
84359 int pardev_claimed;
84360
84361 - int open_count;
84362 + local_t open_count;
84363 int current_midi_output_port;
84364 int current_midi_input_port;
84365 u8 mode[MTS64_NUM_INPUT_PORTS];
84366 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84367 {
84368 struct mts64 *mts = substream->rmidi->private_data;
84369
84370 - if (mts->open_count == 0) {
84371 + if (local_read(&mts->open_count) == 0) {
84372 /* We don't need a spinlock here, because this is just called
84373 if the device has not been opened before.
84374 So there aren't any IRQs from the device */
84375 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84376
84377 msleep(50);
84378 }
84379 - ++(mts->open_count);
84380 + local_inc(&mts->open_count);
84381
84382 return 0;
84383 }
84384 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84385 struct mts64 *mts = substream->rmidi->private_data;
84386 unsigned long flags;
84387
84388 - --(mts->open_count);
84389 - if (mts->open_count == 0) {
84390 + if (local_dec_return(&mts->open_count) == 0) {
84391 /* We need the spinlock_irqsave here because we can still
84392 have IRQs at this point */
84393 spin_lock_irqsave(&mts->lock, flags);
84394 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84395
84396 msleep(500);
84397
84398 - } else if (mts->open_count < 0)
84399 - mts->open_count = 0;
84400 + } else if (local_read(&mts->open_count) < 0)
84401 + local_set(&mts->open_count, 0);
84402
84403 return 0;
84404 }
84405 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
84406 index b953fb4..1999c01 100644
84407 --- a/sound/drivers/opl4/opl4_lib.c
84408 +++ b/sound/drivers/opl4/opl4_lib.c
84409 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
84410 MODULE_DESCRIPTION("OPL4 driver");
84411 MODULE_LICENSE("GPL");
84412
84413 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
84414 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
84415 {
84416 int timeout = 10;
84417 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
84418 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
84419 index 8364855..59f2e2b 100644
84420 --- a/sound/drivers/portman2x4.c
84421 +++ b/sound/drivers/portman2x4.c
84422 @@ -48,6 +48,7 @@
84423 #include <sound/initval.h>
84424 #include <sound/rawmidi.h>
84425 #include <sound/control.h>
84426 +#include <asm/local.h>
84427
84428 #define CARD_NAME "Portman 2x4"
84429 #define DRIVER_NAME "portman"
84430 @@ -85,7 +86,7 @@ struct portman {
84431 struct pardevice *pardev;
84432 int pardev_claimed;
84433
84434 - int open_count;
84435 + local_t open_count;
84436 int mode[PORTMAN_NUM_INPUT_PORTS];
84437 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
84438 };
84439 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
84440 index ea995af..f1bfa37 100644
84441 --- a/sound/firewire/amdtp.c
84442 +++ b/sound/firewire/amdtp.c
84443 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
84444 ptr = s->pcm_buffer_pointer + data_blocks;
84445 if (ptr >= pcm->runtime->buffer_size)
84446 ptr -= pcm->runtime->buffer_size;
84447 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
84448 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
84449
84450 s->pcm_period_pointer += data_blocks;
84451 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
84452 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
84453 */
84454 void amdtp_out_stream_update(struct amdtp_out_stream *s)
84455 {
84456 - ACCESS_ONCE(s->source_node_id_field) =
84457 + ACCESS_ONCE_RW(s->source_node_id_field) =
84458 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
84459 }
84460 EXPORT_SYMBOL(amdtp_out_stream_update);
84461 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
84462 index b680c5e..061b7a0 100644
84463 --- a/sound/firewire/amdtp.h
84464 +++ b/sound/firewire/amdtp.h
84465 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
84466 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
84467 struct snd_pcm_substream *pcm)
84468 {
84469 - ACCESS_ONCE(s->pcm) = pcm;
84470 + ACCESS_ONCE_RW(s->pcm) = pcm;
84471 }
84472
84473 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
84474 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
84475 index d428ffe..751ef78 100644
84476 --- a/sound/firewire/isight.c
84477 +++ b/sound/firewire/isight.c
84478 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
84479 ptr += count;
84480 if (ptr >= runtime->buffer_size)
84481 ptr -= runtime->buffer_size;
84482 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
84483 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
84484
84485 isight->period_counter += count;
84486 if (isight->period_counter >= runtime->period_size) {
84487 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
84488 if (err < 0)
84489 return err;
84490
84491 - ACCESS_ONCE(isight->pcm_active) = true;
84492 + ACCESS_ONCE_RW(isight->pcm_active) = true;
84493
84494 return 0;
84495 }
84496 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
84497 {
84498 struct isight *isight = substream->private_data;
84499
84500 - ACCESS_ONCE(isight->pcm_active) = false;
84501 + ACCESS_ONCE_RW(isight->pcm_active) = false;
84502
84503 mutex_lock(&isight->mutex);
84504 isight_stop_streaming(isight);
84505 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
84506
84507 switch (cmd) {
84508 case SNDRV_PCM_TRIGGER_START:
84509 - ACCESS_ONCE(isight->pcm_running) = true;
84510 + ACCESS_ONCE_RW(isight->pcm_running) = true;
84511 break;
84512 case SNDRV_PCM_TRIGGER_STOP:
84513 - ACCESS_ONCE(isight->pcm_running) = false;
84514 + ACCESS_ONCE_RW(isight->pcm_running) = false;
84515 break;
84516 default:
84517 return -EINVAL;
84518 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
84519 index b2b3c01..e1c1e1f 100644
84520 --- a/sound/oss/sb_audio.c
84521 +++ b/sound/oss/sb_audio.c
84522 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
84523 buf16 = (signed short *)(localbuf + localoffs);
84524 while (c)
84525 {
84526 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84527 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84528 if (copy_from_user(lbuf8,
84529 userbuf+useroffs + p,
84530 locallen))
84531 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
84532 index 7d8803a..559f8d0 100644
84533 --- a/sound/oss/swarm_cs4297a.c
84534 +++ b/sound/oss/swarm_cs4297a.c
84535 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
84536 {
84537 struct cs4297a_state *s;
84538 u32 pwr, id;
84539 - mm_segment_t fs;
84540 int rval;
84541 #ifndef CONFIG_BCM_CS4297A_CSWARM
84542 u64 cfg;
84543 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
84544 if (!rval) {
84545 char *sb1250_duart_present;
84546
84547 +#if 0
84548 + mm_segment_t fs;
84549 fs = get_fs();
84550 set_fs(KERNEL_DS);
84551 -#if 0
84552 val = SOUND_MASK_LINE;
84553 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
84554 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
84555 val = initvol[i].vol;
84556 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
84557 }
84558 + set_fs(fs);
84559 // cs4297a_write_ac97(s, 0x18, 0x0808);
84560 #else
84561 // cs4297a_write_ac97(s, 0x5e, 0x180);
84562 cs4297a_write_ac97(s, 0x02, 0x0808);
84563 cs4297a_write_ac97(s, 0x18, 0x0808);
84564 #endif
84565 - set_fs(fs);
84566
84567 list_add(&s->list, &cs4297a_devs);
84568
84569 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
84570 index 4631a23..001ae57 100644
84571 --- a/sound/pci/ymfpci/ymfpci.h
84572 +++ b/sound/pci/ymfpci/ymfpci.h
84573 @@ -358,7 +358,7 @@ struct snd_ymfpci {
84574 spinlock_t reg_lock;
84575 spinlock_t voice_lock;
84576 wait_queue_head_t interrupt_sleep;
84577 - atomic_t interrupt_sleep_count;
84578 + atomic_unchecked_t interrupt_sleep_count;
84579 struct snd_info_entry *proc_entry;
84580 const struct firmware *dsp_microcode;
84581 const struct firmware *controller_microcode;
84582 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
84583 index 3a6f03f..bc5c86c 100644
84584 --- a/sound/pci/ymfpci/ymfpci_main.c
84585 +++ b/sound/pci/ymfpci/ymfpci_main.c
84586 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
84587 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
84588 break;
84589 }
84590 - if (atomic_read(&chip->interrupt_sleep_count)) {
84591 - atomic_set(&chip->interrupt_sleep_count, 0);
84592 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84593 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84594 wake_up(&chip->interrupt_sleep);
84595 }
84596 __end:
84597 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
84598 continue;
84599 init_waitqueue_entry(&wait, current);
84600 add_wait_queue(&chip->interrupt_sleep, &wait);
84601 - atomic_inc(&chip->interrupt_sleep_count);
84602 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
84603 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
84604 remove_wait_queue(&chip->interrupt_sleep, &wait);
84605 }
84606 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
84607 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
84608 spin_unlock(&chip->reg_lock);
84609
84610 - if (atomic_read(&chip->interrupt_sleep_count)) {
84611 - atomic_set(&chip->interrupt_sleep_count, 0);
84612 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84613 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84614 wake_up(&chip->interrupt_sleep);
84615 }
84616 }
84617 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
84618 spin_lock_init(&chip->reg_lock);
84619 spin_lock_init(&chip->voice_lock);
84620 init_waitqueue_head(&chip->interrupt_sleep);
84621 - atomic_set(&chip->interrupt_sleep_count, 0);
84622 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84623 chip->card = card;
84624 chip->pci = pci;
84625 chip->irq = -1;
84626 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
84627 new file mode 100644
84628 index 0000000..50f2f2f
84629 --- /dev/null
84630 +++ b/tools/gcc/.gitignore
84631 @@ -0,0 +1 @@
84632 +size_overflow_hash.h
84633 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
84634 new file mode 100644
84635 index 0000000..1d09b7e
84636 --- /dev/null
84637 +++ b/tools/gcc/Makefile
84638 @@ -0,0 +1,43 @@
84639 +#CC := gcc
84640 +#PLUGIN_SOURCE_FILES := pax_plugin.c
84641 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
84642 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
84643 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
84644 +
84645 +ifeq ($(PLUGINCC),$(HOSTCC))
84646 +HOSTLIBS := hostlibs
84647 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
84648 +else
84649 +HOSTLIBS := hostcxxlibs
84650 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
84651 +endif
84652 +
84653 +$(HOSTLIBS)-y := constify_plugin.so
84654 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
84655 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
84656 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
84657 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
84658 +$(HOSTLIBS)-y += colorize_plugin.so
84659 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
84660 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
84661 +
84662 +always := $($(HOSTLIBS)-y)
84663 +
84664 +constify_plugin-objs := constify_plugin.o
84665 +stackleak_plugin-objs := stackleak_plugin.o
84666 +kallocstat_plugin-objs := kallocstat_plugin.o
84667 +kernexec_plugin-objs := kernexec_plugin.o
84668 +checker_plugin-objs := checker_plugin.o
84669 +colorize_plugin-objs := colorize_plugin.o
84670 +size_overflow_plugin-objs := size_overflow_plugin.o
84671 +latent_entropy_plugin-objs := latent_entropy_plugin.o
84672 +
84673 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
84674 +
84675 +quiet_cmd_build_size_overflow_hash = GENHASH $@
84676 + cmd_build_size_overflow_hash = \
84677 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
84678 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
84679 + $(call if_changed,build_size_overflow_hash)
84680 +
84681 +targets += size_overflow_hash.h
84682 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
84683 new file mode 100644
84684 index 0000000..d41b5af
84685 --- /dev/null
84686 +++ b/tools/gcc/checker_plugin.c
84687 @@ -0,0 +1,171 @@
84688 +/*
84689 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84690 + * Licensed under the GPL v2
84691 + *
84692 + * Note: the choice of the license means that the compilation process is
84693 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84694 + * but for the kernel it doesn't matter since it doesn't link against
84695 + * any of the gcc libraries
84696 + *
84697 + * gcc plugin to implement various sparse (source code checker) features
84698 + *
84699 + * TODO:
84700 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
84701 + *
84702 + * BUGS:
84703 + * - none known
84704 + */
84705 +#include "gcc-plugin.h"
84706 +#include "config.h"
84707 +#include "system.h"
84708 +#include "coretypes.h"
84709 +#include "tree.h"
84710 +#include "tree-pass.h"
84711 +#include "flags.h"
84712 +#include "intl.h"
84713 +#include "toplev.h"
84714 +#include "plugin.h"
84715 +//#include "expr.h" where are you...
84716 +#include "diagnostic.h"
84717 +#include "plugin-version.h"
84718 +#include "tm.h"
84719 +#include "function.h"
84720 +#include "basic-block.h"
84721 +#include "gimple.h"
84722 +#include "rtl.h"
84723 +#include "emit-rtl.h"
84724 +#include "tree-flow.h"
84725 +#include "target.h"
84726 +
84727 +extern void c_register_addr_space (const char *str, addr_space_t as);
84728 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
84729 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
84730 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
84731 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
84732 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
84733 +
84734 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84735 +extern rtx emit_move_insn(rtx x, rtx y);
84736 +
84737 +int plugin_is_GPL_compatible;
84738 +
84739 +static struct plugin_info checker_plugin_info = {
84740 + .version = "201111150100",
84741 +};
84742 +
84743 +#define ADDR_SPACE_KERNEL 0
84744 +#define ADDR_SPACE_FORCE_KERNEL 1
84745 +#define ADDR_SPACE_USER 2
84746 +#define ADDR_SPACE_FORCE_USER 3
84747 +#define ADDR_SPACE_IOMEM 0
84748 +#define ADDR_SPACE_FORCE_IOMEM 0
84749 +#define ADDR_SPACE_PERCPU 0
84750 +#define ADDR_SPACE_FORCE_PERCPU 0
84751 +#define ADDR_SPACE_RCU 0
84752 +#define ADDR_SPACE_FORCE_RCU 0
84753 +
84754 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
84755 +{
84756 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
84757 +}
84758 +
84759 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
84760 +{
84761 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
84762 +}
84763 +
84764 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
84765 +{
84766 + return default_addr_space_valid_pointer_mode(mode, as);
84767 +}
84768 +
84769 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
84770 +{
84771 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
84772 +}
84773 +
84774 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
84775 +{
84776 + return default_addr_space_legitimize_address(x, oldx, mode, as);
84777 +}
84778 +
84779 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
84780 +{
84781 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
84782 + return true;
84783 +
84784 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
84785 + return true;
84786 +
84787 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
84788 + return true;
84789 +
84790 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
84791 + return true;
84792 +
84793 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
84794 + return true;
84795 +
84796 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
84797 + return true;
84798 +
84799 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
84800 + return true;
84801 +
84802 + return subset == superset;
84803 +}
84804 +
84805 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
84806 +{
84807 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
84808 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
84809 +
84810 + return op;
84811 +}
84812 +
84813 +static void register_checker_address_spaces(void *event_data, void *data)
84814 +{
84815 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
84816 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
84817 + c_register_addr_space("__user", ADDR_SPACE_USER);
84818 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
84819 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
84820 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
84821 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
84822 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
84823 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
84824 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
84825 +
84826 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
84827 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
84828 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
84829 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
84830 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
84831 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
84832 + targetm.addr_space.convert = checker_addr_space_convert;
84833 +}
84834 +
84835 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84836 +{
84837 + const char * const plugin_name = plugin_info->base_name;
84838 + const int argc = plugin_info->argc;
84839 + const struct plugin_argument * const argv = plugin_info->argv;
84840 + int i;
84841 +
84842 + if (!plugin_default_version_check(version, &gcc_version)) {
84843 + error(G_("incompatible gcc/plugin versions"));
84844 + return 1;
84845 + }
84846 +
84847 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
84848 +
84849 + for (i = 0; i < argc; ++i)
84850 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84851 +
84852 + if (TARGET_64BIT == 0)
84853 + return 0;
84854 +
84855 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
84856 +
84857 + return 0;
84858 +}
84859 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
84860 new file mode 100644
84861 index 0000000..846aeb0
84862 --- /dev/null
84863 +++ b/tools/gcc/colorize_plugin.c
84864 @@ -0,0 +1,148 @@
84865 +/*
84866 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
84867 + * Licensed under the GPL v2
84868 + *
84869 + * Note: the choice of the license means that the compilation process is
84870 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84871 + * but for the kernel it doesn't matter since it doesn't link against
84872 + * any of the gcc libraries
84873 + *
84874 + * gcc plugin to colorize diagnostic output
84875 + *
84876 + */
84877 +
84878 +#include "gcc-plugin.h"
84879 +#include "config.h"
84880 +#include "system.h"
84881 +#include "coretypes.h"
84882 +#include "tree.h"
84883 +#include "tree-pass.h"
84884 +#include "flags.h"
84885 +#include "intl.h"
84886 +#include "toplev.h"
84887 +#include "plugin.h"
84888 +#include "diagnostic.h"
84889 +#include "plugin-version.h"
84890 +#include "tm.h"
84891 +
84892 +int plugin_is_GPL_compatible;
84893 +
84894 +static struct plugin_info colorize_plugin_info = {
84895 + .version = "201203092200",
84896 + .help = NULL,
84897 +};
84898 +
84899 +#define GREEN "\033[32m\033[2m"
84900 +#define LIGHTGREEN "\033[32m\033[1m"
84901 +#define YELLOW "\033[33m\033[2m"
84902 +#define LIGHTYELLOW "\033[33m\033[1m"
84903 +#define RED "\033[31m\033[2m"
84904 +#define LIGHTRED "\033[31m\033[1m"
84905 +#define BLUE "\033[34m\033[2m"
84906 +#define LIGHTBLUE "\033[34m\033[1m"
84907 +#define BRIGHT "\033[m\033[1m"
84908 +#define NORMAL "\033[m"
84909 +
84910 +static diagnostic_starter_fn old_starter;
84911 +static diagnostic_finalizer_fn old_finalizer;
84912 +
84913 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84914 +{
84915 + const char *color;
84916 + char *newprefix;
84917 +
84918 + switch (diagnostic->kind) {
84919 + case DK_NOTE:
84920 + color = LIGHTBLUE;
84921 + break;
84922 +
84923 + case DK_PEDWARN:
84924 + case DK_WARNING:
84925 + color = LIGHTYELLOW;
84926 + break;
84927 +
84928 + case DK_ERROR:
84929 + case DK_FATAL:
84930 + case DK_ICE:
84931 + case DK_PERMERROR:
84932 + case DK_SORRY:
84933 + color = LIGHTRED;
84934 + break;
84935 +
84936 + default:
84937 + color = NORMAL;
84938 + }
84939 +
84940 + old_starter(context, diagnostic);
84941 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
84942 + return;
84943 + pp_destroy_prefix(context->printer);
84944 + pp_set_prefix(context->printer, newprefix);
84945 +}
84946 +
84947 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84948 +{
84949 + old_finalizer(context, diagnostic);
84950 +}
84951 +
84952 +static void colorize_arm(void)
84953 +{
84954 + old_starter = diagnostic_starter(global_dc);
84955 + old_finalizer = diagnostic_finalizer(global_dc);
84956 +
84957 + diagnostic_starter(global_dc) = start_colorize;
84958 + diagnostic_finalizer(global_dc) = finalize_colorize;
84959 +}
84960 +
84961 +static unsigned int execute_colorize_rearm(void)
84962 +{
84963 + if (diagnostic_starter(global_dc) == start_colorize)
84964 + return 0;
84965 +
84966 + colorize_arm();
84967 + return 0;
84968 +}
84969 +
84970 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
84971 + .pass = {
84972 + .type = SIMPLE_IPA_PASS,
84973 + .name = "colorize_rearm",
84974 + .gate = NULL,
84975 + .execute = execute_colorize_rearm,
84976 + .sub = NULL,
84977 + .next = NULL,
84978 + .static_pass_number = 0,
84979 + .tv_id = TV_NONE,
84980 + .properties_required = 0,
84981 + .properties_provided = 0,
84982 + .properties_destroyed = 0,
84983 + .todo_flags_start = 0,
84984 + .todo_flags_finish = 0
84985 + }
84986 +};
84987 +
84988 +static void colorize_start_unit(void *gcc_data, void *user_data)
84989 +{
84990 + colorize_arm();
84991 +}
84992 +
84993 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84994 +{
84995 + const char * const plugin_name = plugin_info->base_name;
84996 + struct register_pass_info colorize_rearm_pass_info = {
84997 + .pass = &pass_ipa_colorize_rearm.pass,
84998 + .reference_pass_name = "*free_lang_data",
84999 + .ref_pass_instance_number = 1,
85000 + .pos_op = PASS_POS_INSERT_AFTER
85001 + };
85002 +
85003 + if (!plugin_default_version_check(version, &gcc_version)) {
85004 + error(G_("incompatible gcc/plugin versions"));
85005 + return 1;
85006 + }
85007 +
85008 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
85009 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
85010 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
85011 + return 0;
85012 +}
85013 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
85014 new file mode 100644
85015 index 0000000..1742271
85016 --- /dev/null
85017 +++ b/tools/gcc/constify_plugin.c
85018 @@ -0,0 +1,349 @@
85019 +/*
85020 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
85021 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
85022 + * Licensed under the GPL v2, or (at your option) v3
85023 + *
85024 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
85025 + *
85026 + * Homepage:
85027 + * http://www.grsecurity.net/~ephox/const_plugin/
85028 + *
85029 + * Usage:
85030 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
85031 + * $ gcc -fplugin=constify_plugin.so test.c -O2
85032 + */
85033 +
85034 +#include "gcc-plugin.h"
85035 +#include "config.h"
85036 +#include "system.h"
85037 +#include "coretypes.h"
85038 +#include "tree.h"
85039 +#include "tree-pass.h"
85040 +#include "flags.h"
85041 +#include "intl.h"
85042 +#include "toplev.h"
85043 +#include "plugin.h"
85044 +#include "diagnostic.h"
85045 +#include "plugin-version.h"
85046 +#include "tm.h"
85047 +#include "function.h"
85048 +#include "basic-block.h"
85049 +#include "gimple.h"
85050 +#include "rtl.h"
85051 +#include "emit-rtl.h"
85052 +#include "tree-flow.h"
85053 +
85054 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
85055 +
85056 +int plugin_is_GPL_compatible;
85057 +
85058 +static struct plugin_info const_plugin_info = {
85059 + .version = "201301150230",
85060 + .help = "no-constify\tturn off constification\n",
85061 +};
85062 +
85063 +static tree get_field_type(tree field)
85064 +{
85065 + return strip_array_types(TREE_TYPE(field));
85066 +}
85067 +
85068 +static bool walk_struct(tree node);
85069 +static void deconstify_tree(tree node);
85070 +
85071 +static void deconstify_type(tree type)
85072 +{
85073 + tree field;
85074 +
85075 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
85076 + tree fieldtype = get_field_type(field);
85077 +
85078 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
85079 + continue;
85080 + if (!TYPE_READONLY(fieldtype))
85081 + continue;
85082 + if (!walk_struct(fieldtype))
85083 + continue;
85084 +
85085 + deconstify_tree(field);
85086 + TREE_READONLY(field) = 0;
85087 + }
85088 + TYPE_READONLY(type) = 0;
85089 + C_TYPE_FIELDS_READONLY(type) = 0;
85090 +}
85091 +
85092 +static void deconstify_tree(tree node)
85093 +{
85094 + tree old_type, new_type, field;
85095 +
85096 +// TREE_READONLY(node) = 0;
85097 + old_type = TREE_TYPE(node);
85098 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
85099 + node = old_type;
85100 + old_type = TREE_TYPE(old_type);
85101 + }
85102 +
85103 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
85104 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
85105 +
85106 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
85107 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
85108 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
85109 + DECL_FIELD_CONTEXT(field) = new_type;
85110 +
85111 + deconstify_type(new_type);
85112 +
85113 + TREE_TYPE(node) = new_type;
85114 +}
85115 +
85116 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85117 +{
85118 + tree type;
85119 +
85120 + *no_add_attrs = true;
85121 + if (TREE_CODE(*node) == FUNCTION_DECL) {
85122 + error("%qE attribute does not apply to functions", name);
85123 + return NULL_TREE;
85124 + }
85125 +
85126 + if (TREE_CODE(*node) == VAR_DECL) {
85127 + error("%qE attribute does not apply to variables", name);
85128 + return NULL_TREE;
85129 + }
85130 +
85131 + if (TYPE_P(*node)) {
85132 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
85133 + *no_add_attrs = false;
85134 + else
85135 + error("%qE attribute applies to struct and union types only", name);
85136 + return NULL_TREE;
85137 + }
85138 +
85139 + type = TREE_TYPE(*node);
85140 +
85141 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
85142 + error("%qE attribute applies to struct and union types only", name);
85143 + return NULL_TREE;
85144 + }
85145 +
85146 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
85147 + error("%qE attribute is already applied to the type", name);
85148 + return NULL_TREE;
85149 + }
85150 +
85151 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
85152 + error("%qE attribute used on type that is not constified", name);
85153 + return NULL_TREE;
85154 + }
85155 +
85156 + if (TREE_CODE(*node) == TYPE_DECL) {
85157 + deconstify_tree(*node);
85158 + return NULL_TREE;
85159 + }
85160 +
85161 + return NULL_TREE;
85162 +}
85163 +
85164 +static void constify_type(tree type)
85165 +{
85166 + TYPE_READONLY(type) = 1;
85167 + C_TYPE_FIELDS_READONLY(type) = 1;
85168 +}
85169 +
85170 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85171 +{
85172 + *no_add_attrs = true;
85173 + if (!TYPE_P(*node)) {
85174 + error("%qE attribute applies to types only", name);
85175 + return NULL_TREE;
85176 + }
85177 +
85178 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
85179 + error("%qE attribute applies to struct and union types only", name);
85180 + return NULL_TREE;
85181 + }
85182 +
85183 + *no_add_attrs = false;
85184 + constify_type(*node);
85185 + return NULL_TREE;
85186 +}
85187 +
85188 +static struct attribute_spec no_const_attr = {
85189 + .name = "no_const",
85190 + .min_length = 0,
85191 + .max_length = 0,
85192 + .decl_required = false,
85193 + .type_required = false,
85194 + .function_type_required = false,
85195 + .handler = handle_no_const_attribute,
85196 +#if BUILDING_GCC_VERSION >= 4007
85197 + .affects_type_identity = true
85198 +#endif
85199 +};
85200 +
85201 +static struct attribute_spec do_const_attr = {
85202 + .name = "do_const",
85203 + .min_length = 0,
85204 + .max_length = 0,
85205 + .decl_required = false,
85206 + .type_required = false,
85207 + .function_type_required = false,
85208 + .handler = handle_do_const_attribute,
85209 +#if BUILDING_GCC_VERSION >= 4007
85210 + .affects_type_identity = true
85211 +#endif
85212 +};
85213 +
85214 +static void register_attributes(void *event_data, void *data)
85215 +{
85216 + register_attribute(&no_const_attr);
85217 + register_attribute(&do_const_attr);
85218 +}
85219 +
85220 +static bool is_fptr(tree field)
85221 +{
85222 + tree ptr = get_field_type(field);
85223 +
85224 + if (TREE_CODE(ptr) != POINTER_TYPE)
85225 + return false;
85226 +
85227 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
85228 +}
85229 +
85230 +static bool walk_struct(tree node)
85231 +{
85232 + tree field;
85233 +
85234 + if (TYPE_FIELDS(node) == NULL_TREE)
85235 + return false;
85236 +
85237 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
85238 + return true;
85239 +
85240 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
85241 + gcc_assert(!TYPE_READONLY(node));
85242 + deconstify_type(node);
85243 + return false;
85244 + }
85245 +
85246 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
85247 + tree type = get_field_type(field);
85248 + enum tree_code code = TREE_CODE(type);
85249 +
85250 + if (node == type)
85251 + return false;
85252 + if (code == RECORD_TYPE || code == UNION_TYPE) {
85253 + if (!(walk_struct(type)))
85254 + return false;
85255 + } else if (!is_fptr(field) && !TREE_READONLY(field))
85256 + return false;
85257 + }
85258 + return true;
85259 +}
85260 +
85261 +static void finish_type(void *event_data, void *data)
85262 +{
85263 + tree type = (tree)event_data;
85264 +
85265 + if (type == NULL_TREE || type == error_mark_node)
85266 + return;
85267 +
85268 + if (TYPE_READONLY(type))
85269 + return;
85270 +
85271 + if (walk_struct(type))
85272 + constify_type(type);
85273 + else
85274 + deconstify_type(type);
85275 +}
85276 +
85277 +static unsigned int check_local_variables(void)
85278 +{
85279 + unsigned int ret = 0;
85280 + tree var;
85281 + referenced_var_iterator rvi;
85282 +
85283 +#if BUILDING_GCC_VERSION == 4005
85284 + FOR_EACH_REFERENCED_VAR(var, rvi) {
85285 +#else
85286 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
85287 +#endif
85288 + tree type = TREE_TYPE(var);
85289 +
85290 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
85291 + continue;
85292 +
85293 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
85294 + continue;
85295 +
85296 + if (!TYPE_READONLY(type))
85297 + continue;
85298 +
85299 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
85300 +// continue;
85301 +
85302 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
85303 +// continue;
85304 +
85305 + if (walk_struct(type)) {
85306 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
85307 + ret = 1;
85308 + }
85309 + }
85310 + return ret;
85311 +}
85312 +
85313 +struct gimple_opt_pass pass_local_variable = {
85314 + {
85315 + .type = GIMPLE_PASS,
85316 + .name = "check_local_variables",
85317 + .gate = NULL,
85318 + .execute = check_local_variables,
85319 + .sub = NULL,
85320 + .next = NULL,
85321 + .static_pass_number = 0,
85322 + .tv_id = TV_NONE,
85323 + .properties_required = 0,
85324 + .properties_provided = 0,
85325 + .properties_destroyed = 0,
85326 + .todo_flags_start = 0,
85327 + .todo_flags_finish = 0
85328 + }
85329 +};
85330 +
85331 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85332 +{
85333 + const char * const plugin_name = plugin_info->base_name;
85334 + const int argc = plugin_info->argc;
85335 + const struct plugin_argument * const argv = plugin_info->argv;
85336 + int i;
85337 + bool constify = true;
85338 +
85339 + struct register_pass_info local_variable_pass_info = {
85340 + .pass = &pass_local_variable.pass,
85341 + .reference_pass_name = "ssa",
85342 + .ref_pass_instance_number = 1,
85343 + .pos_op = PASS_POS_INSERT_BEFORE
85344 + };
85345 +
85346 + if (!plugin_default_version_check(version, &gcc_version)) {
85347 + error(G_("incompatible gcc/plugin versions"));
85348 + return 1;
85349 + }
85350 +
85351 + for (i = 0; i < argc; ++i) {
85352 + if (!(strcmp(argv[i].key, "no-constify"))) {
85353 + constify = false;
85354 + continue;
85355 + }
85356 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85357 + }
85358 +
85359 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
85360 + if (constify) {
85361 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
85362 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
85363 + }
85364 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85365 +
85366 + return 0;
85367 +}
85368 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
85369 new file mode 100644
85370 index 0000000..e518932
85371 --- /dev/null
85372 +++ b/tools/gcc/generate_size_overflow_hash.sh
85373 @@ -0,0 +1,94 @@
85374 +#!/bin/bash
85375 +
85376 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
85377 +
85378 +header1="size_overflow_hash.h"
85379 +database="size_overflow_hash.data"
85380 +n=65536
85381 +
85382 +usage() {
85383 +cat <<EOF
85384 +usage: $0 options
85385 +OPTIONS:
85386 + -h|--help help
85387 + -o header file
85388 + -d database file
85389 + -n hash array size
85390 +EOF
85391 + return 0
85392 +}
85393 +
85394 +while true
85395 +do
85396 + case "$1" in
85397 + -h|--help) usage && exit 0;;
85398 + -n) n=$2; shift 2;;
85399 + -o) header1="$2"; shift 2;;
85400 + -d) database="$2"; shift 2;;
85401 + --) shift 1; break ;;
85402 + *) break ;;
85403 + esac
85404 +done
85405 +
85406 +create_defines() {
85407 + for i in `seq 0 31`
85408 + do
85409 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
85410 + done
85411 + echo >> "$header1"
85412 +}
85413 +
85414 +create_structs() {
85415 + rm -f "$header1"
85416 +
85417 + create_defines
85418 +
85419 + cat "$database" | while read data
85420 + do
85421 + data_array=($data)
85422 + struct_hash_name="${data_array[0]}"
85423 + funcn="${data_array[1]}"
85424 + params="${data_array[2]}"
85425 + next="${data_array[4]}"
85426 +
85427 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
85428 +
85429 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
85430 + echo -en "\t.param\t= " >> "$header1"
85431 + line=
85432 + for param_num in ${params//-/ };
85433 + do
85434 + line="${line}PARAM"$param_num"|"
85435 + done
85436 +
85437 + echo -e "${line%?},\n};\n" >> "$header1"
85438 + done
85439 +}
85440 +
85441 +create_headers() {
85442 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
85443 +}
85444 +
85445 +create_array_elements() {
85446 + index=0
85447 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
85448 + do
85449 + data_array=($data)
85450 + i="${data_array[3]}"
85451 + hash="${data_array[0]}"
85452 + while [[ $index -lt $i ]]
85453 + do
85454 + echo -e "\t["$index"]\t= NULL," >> "$header1"
85455 + index=$(($index + 1))
85456 + done
85457 + index=$(($index + 1))
85458 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
85459 + done
85460 + echo '};' >> $header1
85461 +}
85462 +
85463 +create_structs
85464 +create_headers
85465 +create_array_elements
85466 +
85467 +exit 0
85468 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
85469 new file mode 100644
85470 index 0000000..a86e422
85471 --- /dev/null
85472 +++ b/tools/gcc/kallocstat_plugin.c
85473 @@ -0,0 +1,167 @@
85474 +/*
85475 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85476 + * Licensed under the GPL v2
85477 + *
85478 + * Note: the choice of the license means that the compilation process is
85479 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85480 + * but for the kernel it doesn't matter since it doesn't link against
85481 + * any of the gcc libraries
85482 + *
85483 + * gcc plugin to find the distribution of k*alloc sizes
85484 + *
85485 + * TODO:
85486 + *
85487 + * BUGS:
85488 + * - none known
85489 + */
85490 +#include "gcc-plugin.h"
85491 +#include "config.h"
85492 +#include "system.h"
85493 +#include "coretypes.h"
85494 +#include "tree.h"
85495 +#include "tree-pass.h"
85496 +#include "flags.h"
85497 +#include "intl.h"
85498 +#include "toplev.h"
85499 +#include "plugin.h"
85500 +//#include "expr.h" where are you...
85501 +#include "diagnostic.h"
85502 +#include "plugin-version.h"
85503 +#include "tm.h"
85504 +#include "function.h"
85505 +#include "basic-block.h"
85506 +#include "gimple.h"
85507 +#include "rtl.h"
85508 +#include "emit-rtl.h"
85509 +
85510 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85511 +
85512 +int plugin_is_GPL_compatible;
85513 +
85514 +static const char * const kalloc_functions[] = {
85515 + "__kmalloc",
85516 + "kmalloc",
85517 + "kmalloc_large",
85518 + "kmalloc_node",
85519 + "kmalloc_order",
85520 + "kmalloc_order_trace",
85521 + "kmalloc_slab",
85522 + "kzalloc",
85523 + "kzalloc_node",
85524 +};
85525 +
85526 +static struct plugin_info kallocstat_plugin_info = {
85527 + .version = "201111150100",
85528 +};
85529 +
85530 +static unsigned int execute_kallocstat(void);
85531 +
85532 +static struct gimple_opt_pass kallocstat_pass = {
85533 + .pass = {
85534 + .type = GIMPLE_PASS,
85535 + .name = "kallocstat",
85536 + .gate = NULL,
85537 + .execute = execute_kallocstat,
85538 + .sub = NULL,
85539 + .next = NULL,
85540 + .static_pass_number = 0,
85541 + .tv_id = TV_NONE,
85542 + .properties_required = 0,
85543 + .properties_provided = 0,
85544 + .properties_destroyed = 0,
85545 + .todo_flags_start = 0,
85546 + .todo_flags_finish = 0
85547 + }
85548 +};
85549 +
85550 +static bool is_kalloc(const char *fnname)
85551 +{
85552 + size_t i;
85553 +
85554 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
85555 + if (!strcmp(fnname, kalloc_functions[i]))
85556 + return true;
85557 + return false;
85558 +}
85559 +
85560 +static unsigned int execute_kallocstat(void)
85561 +{
85562 + basic_block bb;
85563 +
85564 + // 1. loop through BBs and GIMPLE statements
85565 + FOR_EACH_BB(bb) {
85566 + gimple_stmt_iterator gsi;
85567 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85568 + // gimple match:
85569 + tree fndecl, size;
85570 + gimple call_stmt;
85571 + const char *fnname;
85572 +
85573 + // is it a call
85574 + call_stmt = gsi_stmt(gsi);
85575 + if (!is_gimple_call(call_stmt))
85576 + continue;
85577 + fndecl = gimple_call_fndecl(call_stmt);
85578 + if (fndecl == NULL_TREE)
85579 + continue;
85580 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
85581 + continue;
85582 +
85583 + // is it a call to k*alloc
85584 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
85585 + if (!is_kalloc(fnname))
85586 + continue;
85587 +
85588 + // is the size arg the result of a simple const assignment
85589 + size = gimple_call_arg(call_stmt, 0);
85590 + while (true) {
85591 + gimple def_stmt;
85592 + expanded_location xloc;
85593 + size_t size_val;
85594 +
85595 + if (TREE_CODE(size) != SSA_NAME)
85596 + break;
85597 + def_stmt = SSA_NAME_DEF_STMT(size);
85598 + if (!def_stmt || !is_gimple_assign(def_stmt))
85599 + break;
85600 + if (gimple_num_ops(def_stmt) != 2)
85601 + break;
85602 + size = gimple_assign_rhs1(def_stmt);
85603 + if (!TREE_CONSTANT(size))
85604 + continue;
85605 + xloc = expand_location(gimple_location(def_stmt));
85606 + if (!xloc.file)
85607 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85608 + size_val = TREE_INT_CST_LOW(size);
85609 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
85610 + break;
85611 + }
85612 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85613 +//debug_tree(gimple_call_fn(call_stmt));
85614 +//print_node(stderr, "pax", fndecl, 4);
85615 + }
85616 + }
85617 +
85618 + return 0;
85619 +}
85620 +
85621 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85622 +{
85623 + const char * const plugin_name = plugin_info->base_name;
85624 + struct register_pass_info kallocstat_pass_info = {
85625 + .pass = &kallocstat_pass.pass,
85626 + .reference_pass_name = "ssa",
85627 + .ref_pass_instance_number = 1,
85628 + .pos_op = PASS_POS_INSERT_AFTER
85629 + };
85630 +
85631 + if (!plugin_default_version_check(version, &gcc_version)) {
85632 + error(G_("incompatible gcc/plugin versions"));
85633 + return 1;
85634 + }
85635 +
85636 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
85637 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
85638 +
85639 + return 0;
85640 +}
85641 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
85642 new file mode 100644
85643 index 0000000..8856202
85644 --- /dev/null
85645 +++ b/tools/gcc/kernexec_plugin.c
85646 @@ -0,0 +1,432 @@
85647 +/*
85648 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85649 + * Licensed under the GPL v2
85650 + *
85651 + * Note: the choice of the license means that the compilation process is
85652 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85653 + * but for the kernel it doesn't matter since it doesn't link against
85654 + * any of the gcc libraries
85655 + *
85656 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
85657 + *
85658 + * TODO:
85659 + *
85660 + * BUGS:
85661 + * - none known
85662 + */
85663 +#include "gcc-plugin.h"
85664 +#include "config.h"
85665 +#include "system.h"
85666 +#include "coretypes.h"
85667 +#include "tree.h"
85668 +#include "tree-pass.h"
85669 +#include "flags.h"
85670 +#include "intl.h"
85671 +#include "toplev.h"
85672 +#include "plugin.h"
85673 +//#include "expr.h" where are you...
85674 +#include "diagnostic.h"
85675 +#include "plugin-version.h"
85676 +#include "tm.h"
85677 +#include "function.h"
85678 +#include "basic-block.h"
85679 +#include "gimple.h"
85680 +#include "rtl.h"
85681 +#include "emit-rtl.h"
85682 +#include "tree-flow.h"
85683 +
85684 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85685 +extern rtx emit_move_insn(rtx x, rtx y);
85686 +
85687 +#if BUILDING_GCC_VERSION <= 4006
85688 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
85689 +#endif
85690 +
85691 +int plugin_is_GPL_compatible;
85692 +
85693 +static struct plugin_info kernexec_plugin_info = {
85694 + .version = "201111291120",
85695 + .help = "method=[bts|or]\tinstrumentation method\n"
85696 +};
85697 +
85698 +static unsigned int execute_kernexec_reload(void);
85699 +static unsigned int execute_kernexec_fptr(void);
85700 +static unsigned int execute_kernexec_retaddr(void);
85701 +static bool kernexec_cmodel_check(void);
85702 +
85703 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
85704 +static void (*kernexec_instrument_retaddr)(rtx);
85705 +
85706 +static struct gimple_opt_pass kernexec_reload_pass = {
85707 + .pass = {
85708 + .type = GIMPLE_PASS,
85709 + .name = "kernexec_reload",
85710 + .gate = kernexec_cmodel_check,
85711 + .execute = execute_kernexec_reload,
85712 + .sub = NULL,
85713 + .next = NULL,
85714 + .static_pass_number = 0,
85715 + .tv_id = TV_NONE,
85716 + .properties_required = 0,
85717 + .properties_provided = 0,
85718 + .properties_destroyed = 0,
85719 + .todo_flags_start = 0,
85720 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85721 + }
85722 +};
85723 +
85724 +static struct gimple_opt_pass kernexec_fptr_pass = {
85725 + .pass = {
85726 + .type = GIMPLE_PASS,
85727 + .name = "kernexec_fptr",
85728 + .gate = kernexec_cmodel_check,
85729 + .execute = execute_kernexec_fptr,
85730 + .sub = NULL,
85731 + .next = NULL,
85732 + .static_pass_number = 0,
85733 + .tv_id = TV_NONE,
85734 + .properties_required = 0,
85735 + .properties_provided = 0,
85736 + .properties_destroyed = 0,
85737 + .todo_flags_start = 0,
85738 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85739 + }
85740 +};
85741 +
85742 +static struct rtl_opt_pass kernexec_retaddr_pass = {
85743 + .pass = {
85744 + .type = RTL_PASS,
85745 + .name = "kernexec_retaddr",
85746 + .gate = kernexec_cmodel_check,
85747 + .execute = execute_kernexec_retaddr,
85748 + .sub = NULL,
85749 + .next = NULL,
85750 + .static_pass_number = 0,
85751 + .tv_id = TV_NONE,
85752 + .properties_required = 0,
85753 + .properties_provided = 0,
85754 + .properties_destroyed = 0,
85755 + .todo_flags_start = 0,
85756 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
85757 + }
85758 +};
85759 +
85760 +static bool kernexec_cmodel_check(void)
85761 +{
85762 + tree section;
85763 +
85764 + if (ix86_cmodel != CM_KERNEL)
85765 + return false;
85766 +
85767 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
85768 + if (!section || !TREE_VALUE(section))
85769 + return true;
85770 +
85771 + section = TREE_VALUE(TREE_VALUE(section));
85772 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
85773 + return true;
85774 +
85775 + return false;
85776 +}
85777 +
85778 +/*
85779 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
85780 + */
85781 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
85782 +{
85783 + gimple asm_movabs_stmt;
85784 +
85785 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
85786 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
85787 + gimple_asm_set_volatile(asm_movabs_stmt, true);
85788 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
85789 + update_stmt(asm_movabs_stmt);
85790 +}
85791 +
85792 +/*
85793 + * find all asm() stmts that clobber r10 and add a reload of r10
85794 + */
85795 +static unsigned int execute_kernexec_reload(void)
85796 +{
85797 + basic_block bb;
85798 +
85799 + // 1. loop through BBs and GIMPLE statements
85800 + FOR_EACH_BB(bb) {
85801 + gimple_stmt_iterator gsi;
85802 +
85803 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85804 + // gimple match: __asm__ ("" : : : "r10");
85805 + gimple asm_stmt;
85806 + size_t nclobbers;
85807 +
85808 + // is it an asm ...
85809 + asm_stmt = gsi_stmt(gsi);
85810 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
85811 + continue;
85812 +
85813 + // ... clobbering r10
85814 + nclobbers = gimple_asm_nclobbers(asm_stmt);
85815 + while (nclobbers--) {
85816 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
85817 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
85818 + continue;
85819 + kernexec_reload_fptr_mask(&gsi);
85820 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
85821 + break;
85822 + }
85823 + }
85824 + }
85825 +
85826 + return 0;
85827 +}
85828 +
85829 +/*
85830 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
85831 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
85832 + */
85833 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
85834 +{
85835 + gimple assign_intptr, assign_new_fptr, call_stmt;
85836 + tree intptr, old_fptr, new_fptr, kernexec_mask;
85837 +
85838 + call_stmt = gsi_stmt(*gsi);
85839 + old_fptr = gimple_call_fn(call_stmt);
85840 +
85841 + // create temporary unsigned long variable used for bitops and cast fptr to it
85842 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
85843 + add_referenced_var(intptr);
85844 + mark_sym_for_renaming(intptr);
85845 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
85846 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85847 + update_stmt(assign_intptr);
85848 +
85849 + // apply logical or to temporary unsigned long and bitmask
85850 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
85851 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
85852 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
85853 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85854 + update_stmt(assign_intptr);
85855 +
85856 + // cast temporary unsigned long back to a temporary fptr variable
85857 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
85858 + add_referenced_var(new_fptr);
85859 + mark_sym_for_renaming(new_fptr);
85860 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
85861 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
85862 + update_stmt(assign_new_fptr);
85863 +
85864 + // replace call stmt fn with the new fptr
85865 + gimple_call_set_fn(call_stmt, new_fptr);
85866 + update_stmt(call_stmt);
85867 +}
85868 +
85869 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
85870 +{
85871 + gimple asm_or_stmt, call_stmt;
85872 + tree old_fptr, new_fptr, input, output;
85873 + VEC(tree, gc) *inputs = NULL;
85874 + VEC(tree, gc) *outputs = NULL;
85875 +
85876 + call_stmt = gsi_stmt(*gsi);
85877 + old_fptr = gimple_call_fn(call_stmt);
85878 +
85879 + // create temporary fptr variable
85880 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
85881 + add_referenced_var(new_fptr);
85882 + mark_sym_for_renaming(new_fptr);
85883 +
85884 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
85885 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
85886 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
85887 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
85888 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
85889 + VEC_safe_push(tree, gc, inputs, input);
85890 + VEC_safe_push(tree, gc, outputs, output);
85891 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
85892 + gimple_asm_set_volatile(asm_or_stmt, true);
85893 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
85894 + update_stmt(asm_or_stmt);
85895 +
85896 + // replace call stmt fn with the new fptr
85897 + gimple_call_set_fn(call_stmt, new_fptr);
85898 + update_stmt(call_stmt);
85899 +}
85900 +
85901 +/*
85902 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
85903 + */
85904 +static unsigned int execute_kernexec_fptr(void)
85905 +{
85906 + basic_block bb;
85907 +
85908 + // 1. loop through BBs and GIMPLE statements
85909 + FOR_EACH_BB(bb) {
85910 + gimple_stmt_iterator gsi;
85911 +
85912 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85913 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
85914 + tree fn;
85915 + gimple call_stmt;
85916 +
85917 + // is it a call ...
85918 + call_stmt = gsi_stmt(gsi);
85919 + if (!is_gimple_call(call_stmt))
85920 + continue;
85921 + fn = gimple_call_fn(call_stmt);
85922 + if (TREE_CODE(fn) == ADDR_EXPR)
85923 + continue;
85924 + if (TREE_CODE(fn) != SSA_NAME)
85925 + gcc_unreachable();
85926 +
85927 + // ... through a function pointer
85928 + fn = SSA_NAME_VAR(fn);
85929 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
85930 + continue;
85931 + fn = TREE_TYPE(fn);
85932 + if (TREE_CODE(fn) != POINTER_TYPE)
85933 + continue;
85934 + fn = TREE_TYPE(fn);
85935 + if (TREE_CODE(fn) != FUNCTION_TYPE)
85936 + continue;
85937 +
85938 + kernexec_instrument_fptr(&gsi);
85939 +
85940 +//debug_tree(gimple_call_fn(call_stmt));
85941 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85942 + }
85943 + }
85944 +
85945 + return 0;
85946 +}
85947 +
85948 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
85949 +static void kernexec_instrument_retaddr_bts(rtx insn)
85950 +{
85951 + rtx btsq;
85952 + rtvec argvec, constraintvec, labelvec;
85953 + int line;
85954 +
85955 + // create asm volatile("btsq $63,(%%rsp)":::)
85956 + argvec = rtvec_alloc(0);
85957 + constraintvec = rtvec_alloc(0);
85958 + labelvec = rtvec_alloc(0);
85959 + line = expand_location(RTL_LOCATION(insn)).line;
85960 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85961 + MEM_VOLATILE_P(btsq) = 1;
85962 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
85963 + emit_insn_before(btsq, insn);
85964 +}
85965 +
85966 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
85967 +static void kernexec_instrument_retaddr_or(rtx insn)
85968 +{
85969 + rtx orq;
85970 + rtvec argvec, constraintvec, labelvec;
85971 + int line;
85972 +
85973 + // create asm volatile("orq %%r10,(%%rsp)":::)
85974 + argvec = rtvec_alloc(0);
85975 + constraintvec = rtvec_alloc(0);
85976 + labelvec = rtvec_alloc(0);
85977 + line = expand_location(RTL_LOCATION(insn)).line;
85978 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85979 + MEM_VOLATILE_P(orq) = 1;
85980 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
85981 + emit_insn_before(orq, insn);
85982 +}
85983 +
85984 +/*
85985 + * find all asm level function returns and forcibly set the highest bit of the return address
85986 + */
85987 +static unsigned int execute_kernexec_retaddr(void)
85988 +{
85989 + rtx insn;
85990 +
85991 + // 1. find function returns
85992 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85993 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
85994 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
85995 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
85996 + rtx body;
85997 +
85998 + // is it a retn
85999 + if (!JUMP_P(insn))
86000 + continue;
86001 + body = PATTERN(insn);
86002 + if (GET_CODE(body) == PARALLEL)
86003 + body = XVECEXP(body, 0, 0);
86004 + if (!ANY_RETURN_P(body))
86005 + continue;
86006 + kernexec_instrument_retaddr(insn);
86007 + }
86008 +
86009 +// print_simple_rtl(stderr, get_insns());
86010 +// print_rtl(stderr, get_insns());
86011 +
86012 + return 0;
86013 +}
86014 +
86015 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86016 +{
86017 + const char * const plugin_name = plugin_info->base_name;
86018 + const int argc = plugin_info->argc;
86019 + const struct plugin_argument * const argv = plugin_info->argv;
86020 + int i;
86021 + struct register_pass_info kernexec_reload_pass_info = {
86022 + .pass = &kernexec_reload_pass.pass,
86023 + .reference_pass_name = "ssa",
86024 + .ref_pass_instance_number = 1,
86025 + .pos_op = PASS_POS_INSERT_AFTER
86026 + };
86027 + struct register_pass_info kernexec_fptr_pass_info = {
86028 + .pass = &kernexec_fptr_pass.pass,
86029 + .reference_pass_name = "ssa",
86030 + .ref_pass_instance_number = 1,
86031 + .pos_op = PASS_POS_INSERT_AFTER
86032 + };
86033 + struct register_pass_info kernexec_retaddr_pass_info = {
86034 + .pass = &kernexec_retaddr_pass.pass,
86035 + .reference_pass_name = "pro_and_epilogue",
86036 + .ref_pass_instance_number = 1,
86037 + .pos_op = PASS_POS_INSERT_AFTER
86038 + };
86039 +
86040 + if (!plugin_default_version_check(version, &gcc_version)) {
86041 + error(G_("incompatible gcc/plugin versions"));
86042 + return 1;
86043 + }
86044 +
86045 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
86046 +
86047 + if (TARGET_64BIT == 0)
86048 + return 0;
86049 +
86050 + for (i = 0; i < argc; ++i) {
86051 + if (!strcmp(argv[i].key, "method")) {
86052 + if (!argv[i].value) {
86053 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86054 + continue;
86055 + }
86056 + if (!strcmp(argv[i].value, "bts")) {
86057 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
86058 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
86059 + } else if (!strcmp(argv[i].value, "or")) {
86060 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
86061 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
86062 + fix_register("r10", 1, 1);
86063 + } else
86064 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86065 + continue;
86066 + }
86067 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86068 + }
86069 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
86070 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
86071 +
86072 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
86073 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
86074 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
86075 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
86076 +
86077 + return 0;
86078 +}
86079 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
86080 new file mode 100644
86081 index 0000000..b8008f7
86082 --- /dev/null
86083 +++ b/tools/gcc/latent_entropy_plugin.c
86084 @@ -0,0 +1,295 @@
86085 +/*
86086 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
86087 + * Licensed under the GPL v2
86088 + *
86089 + * Note: the choice of the license means that the compilation process is
86090 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86091 + * but for the kernel it doesn't matter since it doesn't link against
86092 + * any of the gcc libraries
86093 + *
86094 + * gcc plugin to help generate a little bit of entropy from program state,
86095 + * used during boot in the kernel
86096 + *
86097 + * TODO:
86098 + * - add ipa pass to identify not explicitly marked candidate functions
86099 + * - mix in more program state (function arguments/return values, loop variables, etc)
86100 + * - more instrumentation control via attribute parameters
86101 + *
86102 + * BUGS:
86103 + * - LTO needs -flto-partition=none for now
86104 + */
86105 +#include "gcc-plugin.h"
86106 +#include "config.h"
86107 +#include "system.h"
86108 +#include "coretypes.h"
86109 +#include "tree.h"
86110 +#include "tree-pass.h"
86111 +#include "flags.h"
86112 +#include "intl.h"
86113 +#include "toplev.h"
86114 +#include "plugin.h"
86115 +//#include "expr.h" where are you...
86116 +#include "diagnostic.h"
86117 +#include "plugin-version.h"
86118 +#include "tm.h"
86119 +#include "function.h"
86120 +#include "basic-block.h"
86121 +#include "gimple.h"
86122 +#include "rtl.h"
86123 +#include "emit-rtl.h"
86124 +#include "tree-flow.h"
86125 +
86126 +int plugin_is_GPL_compatible;
86127 +
86128 +static tree latent_entropy_decl;
86129 +
86130 +static struct plugin_info latent_entropy_plugin_info = {
86131 + .version = "201207271820",
86132 + .help = NULL
86133 +};
86134 +
86135 +static unsigned int execute_latent_entropy(void);
86136 +static bool gate_latent_entropy(void);
86137 +
86138 +static struct gimple_opt_pass latent_entropy_pass = {
86139 + .pass = {
86140 + .type = GIMPLE_PASS,
86141 + .name = "latent_entropy",
86142 + .gate = gate_latent_entropy,
86143 + .execute = execute_latent_entropy,
86144 + .sub = NULL,
86145 + .next = NULL,
86146 + .static_pass_number = 0,
86147 + .tv_id = TV_NONE,
86148 + .properties_required = PROP_gimple_leh | PROP_cfg,
86149 + .properties_provided = 0,
86150 + .properties_destroyed = 0,
86151 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86152 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86153 + }
86154 +};
86155 +
86156 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86157 +{
86158 + if (TREE_CODE(*node) != FUNCTION_DECL) {
86159 + *no_add_attrs = true;
86160 + error("%qE attribute only applies to functions", name);
86161 + }
86162 + return NULL_TREE;
86163 +}
86164 +
86165 +static struct attribute_spec latent_entropy_attr = {
86166 + .name = "latent_entropy",
86167 + .min_length = 0,
86168 + .max_length = 0,
86169 + .decl_required = true,
86170 + .type_required = false,
86171 + .function_type_required = false,
86172 + .handler = handle_latent_entropy_attribute,
86173 +#if BUILDING_GCC_VERSION >= 4007
86174 + .affects_type_identity = false
86175 +#endif
86176 +};
86177 +
86178 +static void register_attributes(void *event_data, void *data)
86179 +{
86180 + register_attribute(&latent_entropy_attr);
86181 +}
86182 +
86183 +static bool gate_latent_entropy(void)
86184 +{
86185 + tree latent_entropy_attr;
86186 +
86187 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
86188 + return latent_entropy_attr != NULL_TREE;
86189 +}
86190 +
86191 +static unsigned HOST_WIDE_INT seed;
86192 +static unsigned HOST_WIDE_INT get_random_const(void)
86193 +{
86194 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
86195 + return seed;
86196 +}
86197 +
86198 +static enum tree_code get_op(tree *rhs)
86199 +{
86200 + static enum tree_code op;
86201 + unsigned HOST_WIDE_INT random_const;
86202 +
86203 + random_const = get_random_const();
86204 +
86205 + switch (op) {
86206 + case BIT_XOR_EXPR:
86207 + op = PLUS_EXPR;
86208 + break;
86209 +
86210 + case PLUS_EXPR:
86211 + if (rhs) {
86212 + op = LROTATE_EXPR;
86213 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
86214 + break;
86215 + }
86216 +
86217 + case LROTATE_EXPR:
86218 + default:
86219 + op = BIT_XOR_EXPR;
86220 + break;
86221 + }
86222 + if (rhs)
86223 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
86224 + return op;
86225 +}
86226 +
86227 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
86228 +{
86229 + gimple_stmt_iterator gsi;
86230 + gimple assign;
86231 + tree addxorrol, rhs;
86232 + enum tree_code op;
86233 +
86234 + op = get_op(&rhs);
86235 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
86236 + assign = gimple_build_assign(local_entropy, addxorrol);
86237 + find_referenced_vars_in(assign);
86238 +//debug_bb(bb);
86239 + gsi = gsi_after_labels(bb);
86240 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
86241 + update_stmt(assign);
86242 +}
86243 +
86244 +static void perturb_latent_entropy(basic_block bb, tree rhs)
86245 +{
86246 + gimple_stmt_iterator gsi;
86247 + gimple assign;
86248 + tree addxorrol, temp;
86249 +
86250 + // 1. create temporary copy of latent_entropy
86251 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
86252 + add_referenced_var(temp);
86253 + mark_sym_for_renaming(temp);
86254 +
86255 + // 2. read...
86256 + assign = gimple_build_assign(temp, latent_entropy_decl);
86257 + find_referenced_vars_in(assign);
86258 + gsi = gsi_after_labels(bb);
86259 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86260 + update_stmt(assign);
86261 +
86262 + // 3. ...modify...
86263 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
86264 + assign = gimple_build_assign(temp, addxorrol);
86265 + find_referenced_vars_in(assign);
86266 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86267 + update_stmt(assign);
86268 +
86269 + // 4. ...write latent_entropy
86270 + assign = gimple_build_assign(latent_entropy_decl, temp);
86271 + find_referenced_vars_in(assign);
86272 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86273 + update_stmt(assign);
86274 +}
86275 +
86276 +static unsigned int execute_latent_entropy(void)
86277 +{
86278 + basic_block bb;
86279 + gimple assign;
86280 + gimple_stmt_iterator gsi;
86281 + tree local_entropy;
86282 +
86283 + if (!latent_entropy_decl) {
86284 + struct varpool_node *node;
86285 +
86286 + for (node = varpool_nodes; node; node = node->next) {
86287 + tree var = node->decl;
86288 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
86289 + continue;
86290 + latent_entropy_decl = var;
86291 +// debug_tree(var);
86292 + break;
86293 + }
86294 + if (!latent_entropy_decl) {
86295 +// debug_tree(current_function_decl);
86296 + return 0;
86297 + }
86298 + }
86299 +
86300 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
86301 +
86302 + // 1. create local entropy variable
86303 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
86304 + add_referenced_var(local_entropy);
86305 + mark_sym_for_renaming(local_entropy);
86306 +
86307 + // 2. initialize local entropy variable
86308 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86309 + if (dom_info_available_p(CDI_DOMINATORS))
86310 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
86311 + gsi = gsi_start_bb(bb);
86312 +
86313 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
86314 +// gimple_set_location(assign, loc);
86315 + find_referenced_vars_in(assign);
86316 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86317 + update_stmt(assign);
86318 + bb = bb->next_bb;
86319 +
86320 + // 3. instrument each BB with an operation on the local entropy variable
86321 + while (bb != EXIT_BLOCK_PTR) {
86322 + perturb_local_entropy(bb, local_entropy);
86323 + bb = bb->next_bb;
86324 + };
86325 +
86326 + // 4. mix local entropy into the global entropy variable
86327 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
86328 + return 0;
86329 +}
86330 +
86331 +static void start_unit_callback(void *gcc_data, void *user_data)
86332 +{
86333 +#if BUILDING_GCC_VERSION >= 4007
86334 + seed = get_random_seed(false);
86335 +#else
86336 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
86337 + seed *= seed;
86338 +#endif
86339 +
86340 + if (in_lto_p)
86341 + return;
86342 +
86343 + // extern u64 latent_entropy
86344 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
86345 +
86346 + TREE_STATIC(latent_entropy_decl) = 1;
86347 + TREE_PUBLIC(latent_entropy_decl) = 1;
86348 + TREE_USED(latent_entropy_decl) = 1;
86349 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
86350 + DECL_EXTERNAL(latent_entropy_decl) = 1;
86351 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
86352 + DECL_INITIAL(latent_entropy_decl) = NULL;
86353 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
86354 +// varpool_finalize_decl(latent_entropy_decl);
86355 +// varpool_mark_needed_node(latent_entropy_decl);
86356 +}
86357 +
86358 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86359 +{
86360 + const char * const plugin_name = plugin_info->base_name;
86361 + struct register_pass_info latent_entropy_pass_info = {
86362 + .pass = &latent_entropy_pass.pass,
86363 + .reference_pass_name = "optimized",
86364 + .ref_pass_instance_number = 1,
86365 + .pos_op = PASS_POS_INSERT_BEFORE
86366 + };
86367 +
86368 + if (!plugin_default_version_check(version, &gcc_version)) {
86369 + error(G_("incompatible gcc/plugin versions"));
86370 + return 1;
86371 + }
86372 +
86373 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
86374 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86375 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
86376 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86377 +
86378 + return 0;
86379 +}
86380 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
86381 new file mode 100644
86382 index 0000000..5921fd7
86383 --- /dev/null
86384 +++ b/tools/gcc/size_overflow_hash.data
86385 @@ -0,0 +1,3713 @@
86386 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
86387 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
86388 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
86389 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
86390 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
86391 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
86392 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
86393 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
86394 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
86395 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
86396 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
86397 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
86398 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
86399 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
86400 +create_log_8225 create_log 2 8225 NULL
86401 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
86402 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
86403 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
86404 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
86405 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
86406 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
86407 +padzero_55 padzero 1 55 &sel_read_policyvers_55
86408 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
86409 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
86410 +read_file_blob_57406 read_file_blob 3 57406 NULL
86411 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
86412 +enclosure_register_57412 enclosure_register 3 57412 NULL
86413 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
86414 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
86415 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
86416 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
86417 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
86418 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
86419 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
86420 +init_cdev_8274 init_cdev 1 8274 NULL
86421 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
86422 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
86423 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
86424 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
86425 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
86426 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
86427 +load_msg_95 load_msg 2 95 NULL
86428 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
86429 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
86430 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
86431 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
86432 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
86433 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
86434 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
86435 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
86436 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
86437 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
86438 +send_midi_async_57463 send_midi_async 3 57463 NULL
86439 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
86440 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
86441 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
86442 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
86443 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
86444 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
86445 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
86446 +init_q_132 init_q 4 132 NULL
86447 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
86448 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
86449 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
86450 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
86451 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
86452 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
86453 +uio_read_49300 uio_read 3 49300 NULL
86454 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
86455 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
86456 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
86457 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
86458 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
86459 +play_iframe_8219 play_iframe 3 8219 NULL
86460 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
86461 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
86462 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
86463 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
86464 +init_tag_map_57515 init_tag_map 3 57515 NULL
86465 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
86466 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
86467 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
86468 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
86469 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
86470 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
86471 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
86472 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
86473 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
86474 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
86475 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
86476 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
86477 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
86478 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
86479 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
86480 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
86481 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
86482 +cache_read_24790 cache_read 3 24790 NULL
86483 +px_raw_event_49371 px_raw_event 4 49371 NULL
86484 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
86485 +compat_filldir_32999 compat_filldir 3 32999 NULL
86486 +hci_si_event_1404 hci_si_event 3 1404 NULL
86487 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
86488 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
86489 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
86490 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
86491 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
86492 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
86493 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
86494 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
86495 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
86496 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
86497 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
86498 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
86499 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
86500 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
86501 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
86502 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
86503 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
86504 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
86505 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
86506 +mem_read_57631 mem_read 3 57631 NULL
86507 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
86508 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
86509 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
86510 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
86511 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
86512 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
86513 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
86514 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
86515 +queues_read_24877 queues_read 3 24877 NULL
86516 +__fprog_create_41263 __fprog_create 2 41263 NULL
86517 +syslog_print_307 syslog_print 2 307 NULL
86518 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
86519 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
86520 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
86521 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
86522 +r3964_write_57662 r3964_write 4 57662 NULL
86523 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
86524 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
86525 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
86526 +alloc_context_41283 alloc_context 1 41283 NULL
86527 +__lgwrite_57669 __lgwrite 4 57669 NULL
86528 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
86529 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
86530 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
86531 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
86532 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
86533 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
86534 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
86535 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
86536 +write_node_33121 write_node 4 33121 NULL
86537 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
86538 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
86539 +profile_remove_8556 profile_remove 3 8556 NULL
86540 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
86541 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
86542 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
86543 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
86544 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
86545 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
86546 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
86547 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
86548 +tower_write_8580 tower_write 3 8580 NULL
86549 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
86550 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
86551 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
86552 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
86553 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
86554 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
86555 +smk_write_access_49561 smk_write_access 3 49561 NULL
86556 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
86557 +kmp_init_41373 kmp_init 2 41373 NULL
86558 +context_alloc_24645 context_alloc 3 24645 NULL
86559 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
86560 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
86561 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
86562 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
86563 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
86564 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
86565 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
86566 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
86567 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
86568 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
86569 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
86570 +pp_read_33210 pp_read 3 33210 NULL
86571 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
86572 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
86573 +ivtv_read_57796 ivtv_read 3 57796 NULL
86574 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
86575 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
86576 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
86577 +heap_init_49617 heap_init 2 49617 NULL
86578 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
86579 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
86580 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
86581 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
86582 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
86583 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
86584 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
86585 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
86586 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
86587 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
86588 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
86589 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
86590 +st_write_16874 st_write 3 16874 NULL
86591 +copy_to_user_57835 copy_to_user 3 57835 NULL
86592 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
86593 +pidlist_resize_496 pidlist_resize 2 496 NULL
86594 +flash_read_57843 flash_read 3 57843 NULL
86595 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
86596 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
86597 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
86598 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
86599 +arcfb_write_8702 arcfb_write 3 8702 NULL
86600 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
86601 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
86602 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
86603 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
86604 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
86605 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
86606 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
86607 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
86608 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
86609 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
86610 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
86611 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
86612 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
86613 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
86614 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
86615 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
86616 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
86617 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
86618 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
86619 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
86620 +devres_alloc_551 devres_alloc 2 551 NULL
86621 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
86622 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
86623 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
86624 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
86625 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
86626 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
86627 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
86628 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
86629 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
86630 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
86631 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
86632 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
86633 +sys_prctl_8766 sys_prctl 4 8766 NULL
86634 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
86635 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
86636 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
86637 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
86638 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
86639 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
86640 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
86641 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
86642 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
86643 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
86644 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
86645 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
86646 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
86647 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
86648 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
86649 +gserial_setup_41558 gserial_setup 2 41558 NULL
86650 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
86651 +rx_57944 rx 4 57944 NULL
86652 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
86653 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
86654 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
86655 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
86656 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
86657 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
86658 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
86659 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
86660 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
86661 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
86662 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
86663 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
86664 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
86665 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
86666 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
86667 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
86668 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
86669 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
86670 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
86671 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
86672 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
86673 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
86674 +a2mp_send_41615 a2mp_send 4 41615 NULL
86675 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
86676 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
86677 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
86678 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
86679 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
86680 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
86681 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
86682 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
86683 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
86684 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
86685 +add_uuid_49831 add_uuid 4 49831 NULL
86686 +send_pages_8872 send_pages 3 8872 NULL
86687 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
86688 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
86689 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
86690 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
86691 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
86692 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
86693 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
86694 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
86695 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
86696 +vfs_writev_25278 vfs_writev 3 25278 NULL
86697 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
86698 +alloc_async_14208 alloc_async 1 14208 NULL
86699 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
86700 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
86701 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
86702 +create_entry_33479 create_entry 2 33479 NULL
86703 +mce_async_out_58056 mce_async_out 3 58056 NULL
86704 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
86705 +sys_preadv_17100 sys_preadv 3 17100 NULL
86706 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
86707 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
86708 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
86709 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
86710 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
86711 +res_counter_read_33499 res_counter_read 4 33499 NULL
86712 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
86713 +cm4040_write_58079 cm4040_write 3 58079 NULL
86714 +fb_read_33506 fb_read 3 33506 NULL
86715 +help_25316 help 5 25316 NULL nohasharray
86716 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
86717 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
86718 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
86719 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
86720 +ddp_set_map_751 ddp_set_map 4 751 NULL
86721 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
86722 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
86723 +dvb_video_write_754 dvb_video_write 3 754 NULL
86724 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
86725 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
86726 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
86727 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
86728 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
86729 +udi_log_event_58105 udi_log_event 3 58105 NULL
86730 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
86731 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
86732 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
86733 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
86734 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
86735 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
86736 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
86737 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
86738 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
86739 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
86740 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
86741 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
86742 +sep_read_17161 sep_read 3 17161 NULL
86743 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
86744 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
86745 +dup_array_33551 dup_array 3 33551 NULL
86746 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
86747 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
86748 +fillonedir_41746 fillonedir 3 41746 NULL
86749 +init_bch_64130 init_bch 1-2 64130 NULL
86750 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
86751 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
86752 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
86753 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
86754 +savemem_58129 savemem 3 58129 NULL
86755 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
86756 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
86757 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
86758 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
86759 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
86760 +if_writecmd_815 if_writecmd 2 815 NULL
86761 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
86762 +read_fifo_826 read_fifo 3 826 NULL
86763 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
86764 +scsi_execute_33596 scsi_execute 5 33596 NULL
86765 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
86766 +ms_rw_17220 ms_rw 3-4 17220 NULL
86767 +read_tree_block_841 read_tree_block 3 841 NULL
86768 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
86769 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
86770 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
86771 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
86772 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
86773 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
86774 +um_idi_read_850 um_idi_read 3 850 NULL
86775 +__module_alloc_50004 __module_alloc 1 50004 NULL
86776 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
86777 +ts_read_44687 ts_read 3 44687 NULL
86778 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
86779 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
86780 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
86781 +provide_user_output_41105 provide_user_output 3 41105 NULL
86782 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
86783 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
86784 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
86785 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
86786 +alloc_ep_17269 alloc_ep 1 17269 NULL
86787 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
86788 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
86789 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
86790 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
86791 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
86792 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
86793 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
86794 +create_queues_9088 create_queues 2-3 9088 NULL
86795 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
86796 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
86797 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
86798 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
86799 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
86800 +read_file_debug_58256 read_file_debug 3 58256 NULL
86801 +skb_pad_17302 skb_pad 2 17302 NULL
86802 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
86803 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
86804 +profile_load_58267 profile_load 3 58267 NULL
86805 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
86806 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
86807 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
86808 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
86809 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
86810 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
86811 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
86812 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
86813 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
86814 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
86815 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
86816 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
86817 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
86818 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
86819 +get_packet_41914 get_packet 3 41914 NULL
86820 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
86821 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
86822 +read_file_slot_50111 read_file_slot 3 50111 NULL
86823 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
86824 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
86825 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
86826 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
86827 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
86828 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
86829 +copy_items_50140 copy_items 6 50140 NULL
86830 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
86831 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
86832 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
86833 +map_addr_56144 map_addr 7 56144 NULL
86834 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
86835 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
86836 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
86837 +portnames_read_41958 portnames_read 3 41958 NULL
86838 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
86839 +hashtab_create_33769 hashtab_create 3 33769 NULL
86840 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
86841 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
86842 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
86843 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
86844 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
86845 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
86846 +odev_update_50169 odev_update 2 50169 NULL
86847 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
86848 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
86849 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
86850 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
86851 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
86852 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
86853 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
86854 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
86855 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
86856 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
86857 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
86858 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
86859 +lguest_map_42008 lguest_map 1-2 42008 NULL
86860 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
86861 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
86862 +pool_allocate_42012 pool_allocate 3 42012 NULL
86863 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
86864 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
86865 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
86866 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
86867 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
86868 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
86869 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
86870 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
86871 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
86872 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
86873 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
86874 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
86875 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
86876 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
86877 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
86878 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
86879 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
86880 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
86881 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
86882 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
86883 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
86884 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
86885 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
86886 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
86887 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
86888 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
86889 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
86890 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
86891 +config_proc_write_33878 config_proc_write 3 33878 NULL
86892 +capabilities_read_58457 capabilities_read 3 58457 NULL
86893 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
86894 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
86895 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
86896 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
86897 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
86898 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
86899 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
86900 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
86901 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
86902 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
86903 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
86904 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
86905 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
86906 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
86907 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
86908 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
86909 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
86910 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
86911 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
86912 +vme_user_write_15587 vme_user_write 3 15587 NULL
86913 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
86914 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
86915 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
86916 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
86917 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
86918 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
86919 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
86920 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
86921 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
86922 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
86923 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
86924 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
86925 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
86926 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
86927 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
86928 +read_9397 read 3 9397 NULL
86929 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
86930 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
86931 +printer_write_60276 printer_write 3 60276 NULL
86932 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
86933 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
86934 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
86935 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
86936 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
86937 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
86938 +osst_execute_17607 osst_execute 7-6 17607 NULL
86939 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
86940 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
86941 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
86942 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
86943 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
86944 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
86945 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
86946 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
86947 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
86948 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
86949 +xip_file_read_58592 xip_file_read 3 58592 NULL
86950 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
86951 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
86952 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
86953 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
86954 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
86955 +ppp_write_34034 ppp_write 3 34034 NULL
86956 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
86957 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
86958 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
86959 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
86960 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
86961 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
86962 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
86963 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
86964 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
86965 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
86966 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
86967 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
86968 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
86969 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
86970 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
86971 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
86972 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
86973 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
86974 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
86975 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
86976 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
86977 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
86978 +lp_write_9511 lp_write 3 9511 NULL
86979 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
86980 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
86981 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
86982 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
86983 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
86984 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
86985 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
86986 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
86987 +read_file_dma_9530 read_file_dma 3 9530 NULL
86988 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
86989 +rcname_read_25919 rcname_read 3 25919 NULL
86990 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
86991 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
86992 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
86993 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
86994 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
86995 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
86996 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
86997 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
86998 +key_flags_read_25931 key_flags_read 3 25931 NULL
86999 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
87000 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
87001 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
87002 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
87003 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
87004 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
87005 +fw_node_create_9559 fw_node_create 2 9559 NULL
87006 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
87007 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
87008 +kobj_map_9566 kobj_map 2-3 9566 NULL
87009 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
87010 +acpi_map_58725 acpi_map 1-2 58725 NULL
87011 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
87012 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
87013 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
87014 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
87015 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
87016 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
87017 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
87018 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
87019 +file_read_actor_1401 file_read_actor 4 1401 NULL
87020 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
87021 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
87022 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
87023 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
87024 +do_sync_9604 do_sync 1 9604 NULL
87025 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
87026 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
87027 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
87028 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
87029 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
87030 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
87031 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
87032 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
87033 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
87034 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
87035 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
87036 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
87037 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
87038 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
87039 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
87040 +sge_rx_50594 sge_rx 3 50594 NULL
87041 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
87042 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
87043 +skb_padto_50759 skb_padto 2 50759 NULL
87044 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
87045 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
87046 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
87047 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
87048 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
87049 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
87050 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
87051 +ep_read_58813 ep_read 3 58813 NULL
87052 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
87053 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
87054 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
87055 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
87056 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
87057 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
87058 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
87059 +dns_query_9676 dns_query 3 9676 NULL
87060 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
87061 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
87062 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
87063 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
87064 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
87065 +command_write_58841 command_write 3 58841 NULL
87066 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
87067 +dev_config_8506 dev_config 3 8506 NULL
87068 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
87069 +sys_readv_50664 sys_readv 3 50664 NULL
87070 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
87071 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
87072 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
87073 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
87074 +recover_head_17904 recover_head 3 17904 NULL
87075 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
87076 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
87077 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
87078 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
87079 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
87080 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
87081 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
87082 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
87083 +skb_cow_26138 skb_cow 2 26138 NULL
87084 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
87085 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
87086 +do_sigpending_9766 do_sigpending 2 9766 NULL
87087 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
87088 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
87089 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
87090 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
87091 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
87092 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
87093 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
87094 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
87095 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
87096 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
87097 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
87098 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
87099 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
87100 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
87101 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
87102 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
87103 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
87104 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
87105 +get_registers_26187 get_registers 3 26187 NULL
87106 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
87107 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
87108 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
87109 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
87110 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
87111 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
87112 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
87113 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
87114 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
87115 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
87116 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
87117 +mce_write_26201 mce_write 3 26201 NULL
87118 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
87119 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
87120 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
87121 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
87122 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
87123 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
87124 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
87125 +tpm_write_50798 tpm_write 3 50798 NULL
87126 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
87127 +tun_do_read_50800 tun_do_read 4 50800 NULL
87128 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
87129 +write_flush_50803 write_flush 3 50803 NULL
87130 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
87131 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
87132 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
87133 +dvb_play_50814 dvb_play 3 50814 NULL
87134 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
87135 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
87136 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
87137 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
87138 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
87139 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
87140 +dma_attach_50831 dma_attach 6-7 50831 NULL
87141 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
87142 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
87143 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
87144 +packet_came_18072 packet_came 3 18072 NULL
87145 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
87146 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
87147 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
87148 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
87149 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
87150 +get_vm_area_18080 get_vm_area 1 18080 NULL
87151 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
87152 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
87153 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
87154 +self_check_write_50856 self_check_write 5 50856 NULL
87155 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
87156 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
87157 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
87158 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
87159 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
87160 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
87161 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
87162 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
87163 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
87164 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
87165 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
87166 +vb2_read_42703 vb2_read 3 42703 NULL
87167 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
87168 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
87169 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
87170 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
87171 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
87172 +read_file_misc_9948 read_file_misc 3 9948 NULL
87173 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
87174 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
87175 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
87176 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
87177 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
87178 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
87179 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
87180 +cosa_write_1774 cosa_write 3 1774 NULL
87181 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
87182 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
87183 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
87184 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
87185 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
87186 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
87187 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
87188 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
87189 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
87190 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
87191 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
87192 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
87193 +mld_newpack_50950 mld_newpack 2 50950 NULL
87194 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
87195 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
87196 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
87197 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
87198 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
87199 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
87200 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
87201 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
87202 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
87203 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
87204 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
87205 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
87206 +handle_request_10024 handle_request 9 10024 NULL
87207 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
87208 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
87209 +timeout_write_50991 timeout_write 3 50991 NULL
87210 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
87211 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
87212 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
87213 +proc_write_51003 proc_write 3 51003 NULL
87214 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
87215 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
87216 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
87217 +set_arg_42824 set_arg 3 42824 NULL
87218 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
87219 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
87220 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
87221 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
87222 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
87223 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
87224 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
87225 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
87226 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
87227 +dt3155_read_59226 dt3155_read 3 59226 NULL
87228 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
87229 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
87230 +dump_midi_51040 dump_midi 3 51040 NULL
87231 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
87232 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
87233 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
87234 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
87235 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
87236 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
87237 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
87238 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
87239 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
87240 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
87241 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
87242 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
87243 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
87244 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
87245 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
87246 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
87247 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
87248 +read_vmcore_26501 read_vmcore 3 26501 NULL
87249 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
87250 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
87251 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
87252 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
87253 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
87254 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
87255 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
87256 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
87257 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
87258 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
87259 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
87260 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
87261 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
87262 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
87263 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
87264 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
87265 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
87266 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
87267 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
87268 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
87269 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
87270 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
87271 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
87272 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
87273 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
87274 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
87275 +fd_copyout_59323 fd_copyout 3 59323 NULL
87276 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
87277 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
87278 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
87279 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
87280 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
87281 +solos_param_store_34755 solos_param_store 4 34755 NULL
87282 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
87283 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
87284 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
87285 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
87286 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
87287 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
87288 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
87289 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
87290 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
87291 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
87292 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
87293 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
87294 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
87295 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
87296 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
87297 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
87298 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
87299 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
87300 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
87301 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
87302 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
87303 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
87304 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
87305 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
87306 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
87307 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
87308 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
87309 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
87310 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
87311 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
87312 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
87313 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
87314 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
87315 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
87316 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
87317 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
87318 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
87319 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
87320 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
87321 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
87322 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
87323 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
87324 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
87325 +tipc_send_51238 tipc_send 4 51238 NULL
87326 +drm_property_create_51239 drm_property_create 4 51239 NULL
87327 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
87328 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
87329 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
87330 +audit_expand_2098 audit_expand 2 2098 NULL
87331 +st_read_51251 st_read 3 51251 NULL
87332 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
87333 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
87334 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
87335 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
87336 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
87337 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
87338 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
87339 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
87340 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
87341 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
87342 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
87343 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
87344 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
87345 +c4_add_card_54968 c4_add_card 3 54968 NULL
87346 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
87347 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
87348 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
87349 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
87350 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
87351 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
87352 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
87353 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
87354 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
87355 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
87356 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
87357 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
87358 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
87359 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
87360 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
87361 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
87362 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
87363 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
87364 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
87365 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
87366 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
87367 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
87368 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
87369 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
87370 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
87371 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
87372 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
87373 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
87374 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
87375 +debug_output_18575 debug_output 3 18575 NULL
87376 +Realloc_34961 Realloc 2 34961 NULL
87377 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
87378 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
87379 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
87380 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
87381 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
87382 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
87383 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
87384 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
87385 +vhci_write_2224 vhci_write 3 2224 NULL
87386 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
87387 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
87388 +rb_alloc_3102 rb_alloc 1 3102 NULL
87389 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
87390 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
87391 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
87392 +write_pbl_59583 write_pbl 4 59583 NULL
87393 +from_buffer_18625 from_buffer 3 18625 NULL
87394 +uio_write_43202 uio_write 3 43202 NULL
87395 +memdup_user_59590 memdup_user 2 59590 NULL
87396 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
87397 +iso_callback_43208 iso_callback 3 43208 NULL
87398 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
87399 +smk_write_load_26829 smk_write_load 3 26829 NULL
87400 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
87401 +do_update_counters_2259 do_update_counters 4 2259 NULL
87402 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
87403 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
87404 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
87405 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
87406 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
87407 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
87408 +mtrr_write_59622 mtrr_write 3 59622 NULL
87409 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
87410 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
87411 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
87412 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
87413 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
87414 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
87415 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
87416 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
87417 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
87418 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
87419 +fixup_leb_43256 fixup_leb 3 43256 NULL
87420 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
87421 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
87422 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
87423 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
87424 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
87425 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
87426 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
87427 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
87428 +evtchn_write_43278 evtchn_write 3 43278 NULL
87429 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
87430 +store_ifalias_35088 store_ifalias 4 35088 NULL
87431 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
87432 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
87433 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
87434 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
87435 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
87436 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
87437 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
87438 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
87439 +capi_write_35104 capi_write 3 35104 NULL nohasharray
87440 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
87441 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
87442 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
87443 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
87444 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
87445 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
87446 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
87447 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
87448 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
87449 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
87450 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
87451 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
87452 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
87453 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
87454 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
87455 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
87456 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
87457 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
87458 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
87459 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
87460 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
87461 +do_trimming_26952 do_trimming 3 26952 NULL
87462 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
87463 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
87464 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
87465 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
87466 +alloc_buf_34532 alloc_buf 1 34532 NULL
87467 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
87468 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
87469 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
87470 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
87471 +otp_read_10594 otp_read 2-4-5 10594 NULL
87472 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
87473 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
87474 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
87475 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
87476 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
87477 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
87478 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
87479 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
87480 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
87481 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
87482 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
87483 +venus_remove_59781 venus_remove 4 59781 NULL
87484 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
87485 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
87486 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
87487 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
87488 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
87489 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
87490 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
87491 +xenfb_write_43412 xenfb_write 3 43412 NULL
87492 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
87493 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
87494 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
87495 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
87496 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
87497 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
87498 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
87499 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
87500 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
87501 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
87502 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
87503 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
87504 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
87505 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
87506 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
87507 +cmd_complete_51629 cmd_complete 6 51629 NULL
87508 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
87509 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
87510 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
87511 +set_fd_set_35249 set_fd_set 1 35249 NULL
87512 +wiphy_new_2482 wiphy_new 2 2482 NULL
87513 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
87514 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
87515 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
87516 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
87517 +tcp_push_10680 tcp_push 3 10680 NULL
87518 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
87519 +c101_run_37279 c101_run 2 37279 NULL
87520 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
87521 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
87522 +tun_put_user_59849 tun_put_user 4 59849 NULL
87523 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
87524 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
87525 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
87526 +dm_write_2513 dm_write 3 2513 NULL
87527 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
87528 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
87529 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
87530 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
87531 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
87532 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
87533 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
87534 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
87535 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
87536 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
87537 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
87538 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
87539 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
87540 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
87541 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
87542 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
87543 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
87544 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
87545 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
87546 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
87547 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
87548 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
87549 +sel_write_access_51704 sel_write_access 3 51704 NULL
87550 +sys_syslog_10746 sys_syslog 3 10746 NULL
87551 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
87552 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
87553 +do_readlink_43518 do_readlink 2 43518 NULL
87554 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
87555 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
87556 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
87557 +read_file_reset_52310 read_file_reset 3 52310 NULL
87558 +pms_capture_27142 pms_capture 4 27142 NULL
87559 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
87560 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
87561 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
87562 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
87563 +msg_set_51725 msg_set 3 51725 NULL
87564 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
87565 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
87566 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
87567 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
87568 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
87569 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
87570 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
87571 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
87572 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
87573 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
87574 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
87575 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
87576 +sys_bind_10799 sys_bind 3 10799 NULL
87577 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
87578 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
87579 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
87580 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
87581 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
87582 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
87583 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
87584 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
87585 +send_command_10832 send_command 4 10832 NULL
87586 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
87587 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
87588 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
87589 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
87590 +proc_read_43614 proc_read 3 43614 NULL
87591 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
87592 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
87593 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
87594 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
87595 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
87596 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
87597 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
87598 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
87599 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
87600 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
87601 +vmalloc_15464 vmalloc 1 15464 NULL
87602 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
87603 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
87604 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
87605 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
87606 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
87607 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
87608 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
87609 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
87610 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
87611 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
87612 +adu_write_30487 adu_write 3 30487 NULL
87613 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
87614 +get_scq_10897 get_scq 2 10897 NULL
87615 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
87616 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
87617 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
87618 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
87619 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
87620 +load_module_60056 load_module 2 60056 NULL nohasharray
87621 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
87622 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
87623 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
87624 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
87625 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
87626 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
87627 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
87628 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
87629 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
87630 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
87631 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
87632 +user_read_51881 user_read 3 51881 NULL
87633 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
87634 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
87635 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
87636 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
87637 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
87638 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
87639 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
87640 +async_setkey_35521 async_setkey 3 35521 NULL
87641 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
87642 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
87643 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
87644 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
87645 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
87646 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
87647 +add_tty_40055 add_tty 1 40055 NULL nohasharray
87648 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
87649 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
87650 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
87651 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
87652 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
87653 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
87654 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
87655 +alloc_context_3194 alloc_context 1 3194 NULL
87656 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
87657 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
87658 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
87659 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
87660 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
87661 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
87662 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
87663 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
87664 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
87665 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
87666 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
87667 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
87668 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
87669 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
87670 +init_state_60165 init_state 2 60165 NULL
87671 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
87672 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
87673 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
87674 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
87675 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
87676 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
87677 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
87678 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
87679 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
87680 +calc_hmac_32010 calc_hmac 3 32010 NULL
87681 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
87682 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
87683 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
87684 +kernel_readv_35617 kernel_readv 3 35617 NULL
87685 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
87686 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
87687 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
87688 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
87689 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
87690 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
87691 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
87692 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
87693 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
87694 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
87695 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
87696 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
87697 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
87698 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
87699 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
87700 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
87701 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
87702 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
87703 +store_debug_level_35652 store_debug_level 3 35652 NULL
87704 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
87705 +read_flush_43851 read_flush 3 43851 NULL
87706 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
87707 +cmm_write_2896 cmm_write 3 2896 NULL
87708 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
87709 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
87710 +tunables_write_59563 tunables_write 3 59563 NULL
87711 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
87712 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
87713 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
87714 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
87715 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
87716 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
87717 +dm_table_create_35687 dm_table_create 3 35687 NULL
87718 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
87719 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
87720 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
87721 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
87722 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
87723 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
87724 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
87725 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
87726 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
87727 +debug_read_19322 debug_read 3 19322 NULL
87728 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
87729 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
87730 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
87731 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
87732 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
87733 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
87734 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
87735 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
87736 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
87737 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
87738 +doc_probe_23285 doc_probe 1 23285 NULL
87739 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
87740 +SendString_43928 SendString 3 43928 NULL
87741 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
87742 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
87743 +retry_count_read_52129 retry_count_read 3 52129 NULL
87744 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
87745 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
87746 +read_zero_19366 read_zero 3 19366 NULL
87747 +bch_alloc_4593 bch_alloc 1 4593 NULL
87748 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
87749 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
87750 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
87751 +raid5_resize_63306 raid5_resize 2 63306 NULL
87752 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
87753 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
87754 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
87755 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
87756 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
87757 +depth_write_3021 depth_write 3 3021 NULL
87758 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
87759 +read_file_stations_35795 read_file_stations 3 35795 NULL
87760 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
87761 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
87762 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
87763 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
87764 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
87765 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
87766 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
87767 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
87768 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
87769 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
87770 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
87771 +driver_names_read_60399 driver_names_read 3 60399 NULL
87772 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
87773 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
87774 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
87775 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
87776 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
87777 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
87778 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
87779 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
87780 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
87781 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
87782 +rx_data_60442 rx_data 4 60442 NULL
87783 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
87784 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
87785 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
87786 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
87787 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
87788 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
87789 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
87790 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
87791 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
87792 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
87793 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
87794 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
87795 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
87796 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
87797 +construct_key_11329 construct_key 3 11329 NULL
87798 +evm_write_key_27715 evm_write_key 3 27715 NULL
87799 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
87800 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
87801 +filldir_55137 filldir 3 55137 NULL
87802 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
87803 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
87804 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
87805 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
87806 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
87807 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
87808 +sel_write_create_11353 sel_write_create 3 11353 NULL
87809 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
87810 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
87811 +hwflags_read_52318 hwflags_read 3 52318 NULL
87812 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
87813 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
87814 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
87815 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
87816 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
87817 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
87818 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
87819 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
87820 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
87821 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
87822 +nfsd_read_19568 nfsd_read 5 19568 NULL
87823 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
87824 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
87825 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
87826 +kcalloc_27770 kcalloc 1-2 27770 NULL
87827 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
87828 +bm_status_read_19583 bm_status_read 3 19583 NULL
87829 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
87830 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
87831 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
87832 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
87833 +acl_alloc_35979 acl_alloc 1 35979 NULL
87834 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
87835 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
87836 +str_to_user_11411 str_to_user 2 11411 NULL
87837 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
87838 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
87839 +trace_options_read_11419 trace_options_read 3 11419 NULL
87840 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
87841 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
87842 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
87843 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
87844 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
87845 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
87846 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
87847 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
87848 +console_store_36007 console_store 4 36007 NULL
87849 +bttv_read_11432 bttv_read 3 11432 NULL
87850 +key_key_read_3241 key_key_read 3 3241 NULL
87851 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
87852 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
87853 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
87854 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
87855 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
87856 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
87857 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
87858 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
87859 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
87860 +um_idi_write_18293 um_idi_write 3 18293 NULL
87861 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
87862 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
87863 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
87864 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
87865 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
87866 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
87867 +sys_init_module_36047 sys_init_module 2 36047 NULL
87868 +read_profile_27859 read_profile 3 27859 NULL
87869 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
87870 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
87871 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
87872 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
87873 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
87874 +refill_pool_19477 refill_pool 2 19477 NULL
87875 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
87876 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
87877 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
87878 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
87879 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
87880 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
87881 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
87882 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
87883 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
87884 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
87885 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
87886 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
87887 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
87888 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
87889 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
87890 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
87891 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
87892 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
87893 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
87894 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
87895 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
87896 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
87897 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
87898 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
87899 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
87900 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
87901 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
87902 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
87903 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
87904 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
87905 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
87906 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
87907 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
87908 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
87909 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
87910 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
87911 +init_data_container_60709 init_data_container 1 60709 NULL
87912 +p9_client_read_19750 p9_client_read 5 19750 NULL
87913 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
87914 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
87915 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
87916 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
87917 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
87918 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
87919 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
87920 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
87921 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
87922 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
87923 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
87924 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
87925 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
87926 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
87927 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
87928 +send_stream_3397 send_stream 4 3397 NULL
87929 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
87930 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
87931 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
87932 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
87933 +msix_map_region_3411 msix_map_region 3 3411 NULL
87934 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
87935 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
87936 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
87937 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
87938 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
87939 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
87940 +opticon_write_60775 opticon_write 4 60775 NULL
87941 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
87942 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
87943 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
87944 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
87945 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
87946 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
87947 +vip_read_19832 vip_read 3 19832 NULL
87948 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
87949 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
87950 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
87951 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
87952 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
87953 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
87954 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
87955 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
87956 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
87957 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
87958 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
87959 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
87960 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
87961 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
87962 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
87963 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
87964 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
87965 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
87966 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
87967 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
87968 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
87969 +split_11691 split 2 11691 NULL
87970 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
87971 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
87972 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
87973 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
87974 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
87975 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
87976 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
87977 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
87978 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
87979 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
87980 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
87981 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
87982 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
87983 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
87984 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
87985 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
87986 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
87987 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
87988 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
87989 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
87990 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
87991 +spidev_write_44510 spidev_write 3 44510 NULL
87992 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
87993 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
87994 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
87995 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
87996 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
87997 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
87998 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
87999 +kone_receive_4690 kone_receive 4 4690 NULL
88000 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
88001 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
88002 +evtchn_read_3569 evtchn_read 3 3569 NULL
88003 +video_read_28148 video_read 3 28148 NULL
88004 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
88005 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
88006 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
88007 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
88008 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
88009 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
88010 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
88011 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
88012 +vc_resize_3585 vc_resize 2-3 3585 NULL
88013 +gluebi_write_27905 gluebi_write 3 27905 NULL
88014 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
88015 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
88016 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
88017 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
88018 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
88019 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
88020 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
88021 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
88022 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
88023 +pti_char_write_60960 pti_char_write 3 60960 NULL
88024 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
88025 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
88026 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
88027 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
88028 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
88029 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
88030 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
88031 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
88032 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
88033 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
88034 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
88035 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
88036 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
88037 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
88038 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
88039 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
88040 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
88041 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
88042 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
88043 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
88044 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
88045 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
88046 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
88047 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
88048 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
88049 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
88050 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
88051 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
88052 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
88053 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
88054 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
88055 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
88056 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
88057 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
88058 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
88059 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
88060 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
88061 +symtab_init_61050 symtab_init 2 61050 NULL
88062 +team_options_register_20091 team_options_register 3 20091 NULL
88063 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
88064 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
88065 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
88066 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
88067 +mpi_resize_44674 mpi_resize 2 44674 NULL
88068 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
88069 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
88070 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
88071 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
88072 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
88073 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
88074 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
88075 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
88076 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
88077 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
88078 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
88079 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
88080 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
88081 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
88082 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
88083 +pms_read_53873 pms_read 3 53873 NULL
88084 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
88085 +get_derived_key_61100 get_derived_key 4 61100 NULL
88086 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
88087 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
88088 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
88089 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
88090 +dm_read_15674 dm_read 3 15674 NULL
88091 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
88092 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
88093 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
88094 +kone_send_63435 kone_send 4 63435 NULL
88095 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
88096 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
88097 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
88098 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
88099 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
88100 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
88101 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
88102 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
88103 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
88104 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
88105 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
88106 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
88107 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
88108 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
88109 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
88110 +send_packet_52960 send_packet 4 52960 NULL
88111 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
88112 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
88113 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
88114 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
88115 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
88116 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
88117 +put_cmsg_36589 put_cmsg 4 36589 NULL
88118 +__vmalloc_61168 __vmalloc 1 61168 NULL
88119 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
88120 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
88121 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
88122 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
88123 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
88124 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
88125 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
88126 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
88127 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
88128 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
88129 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
88130 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
88131 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
88132 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
88133 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
88134 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
88135 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
88136 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
88137 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
88138 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
88139 +get_fd_set_3866 get_fd_set 1 3866 NULL
88140 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
88141 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
88142 +unlink_queued_645 unlink_queued 3-4 645 NULL
88143 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
88144 +sisusb_write_44834 sisusb_write 3 44834 NULL
88145 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
88146 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
88147 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
88148 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
88149 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
88150 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
88151 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
88152 +nvram_write_3894 nvram_write 3 3894 NULL
88153 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
88154 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
88155 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
88156 +vcs_write_3910 vcs_write 3 3910 NULL
88157 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
88158 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
88159 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
88160 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
88161 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
88162 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
88163 +do_tty_write_44896 do_tty_write 5 44896 NULL
88164 +set_powered_12129 set_powered 4 12129 NULL
88165 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
88166 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
88167 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
88168 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
88169 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
88170 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
88171 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
88172 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
88173 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
88174 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
88175 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
88176 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
88177 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
88178 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
88179 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
88180 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
88181 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
88182 +gather_array_56641 gather_array 3 56641 NULL
88183 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
88184 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
88185 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
88186 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
88187 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
88188 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
88189 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
88190 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
88191 +do_add_counters_3992 do_add_counters 3 3992 NULL
88192 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
88193 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
88194 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
88195 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
88196 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
88197 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
88198 +mei_write_4005 mei_write 3 4005 NULL
88199 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
88200 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
88201 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
88202 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
88203 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
88204 +receive_copy_12216 receive_copy 3 12216 NULL
88205 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
88206 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
88207 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
88208 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
88209 +change_xattr_61390 change_xattr 5 61390 NULL
88210 +find_skb_20431 find_skb 2 20431 NULL
88211 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
88212 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
88213 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
88214 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
88215 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
88216 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
88217 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
88218 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
88219 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
88220 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
88221 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
88222 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
88223 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
88224 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
88225 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
88226 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
88227 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
88228 +read_buf_20469 read_buf 2 20469 NULL
88229 +cm_write_36858 cm_write 3 36858 NULL
88230 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
88231 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
88232 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
88233 +sel_write_user_45060 sel_write_user 3 45060 NULL
88234 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
88235 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
88236 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
88237 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
88238 +fast_user_write_20494 fast_user_write 5 20494 NULL
88239 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
88240 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
88241 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
88242 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
88243 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
88244 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
88245 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
88246 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
88247 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
88248 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
88249 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
88250 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
88251 +osst_read_40237 osst_read 3 40237 NULL
88252 +tm6000_read_4151 tm6000_read 3 4151 NULL
88253 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
88254 +usbdev_read_45114 usbdev_read 3 45114 NULL
88255 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
88256 +spi_execute_28736 spi_execute 5 28736 NULL
88257 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
88258 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
88259 +get_alua_req_4166 get_alua_req 3 4166 NULL
88260 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
88261 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
88262 +venus_create_20555 venus_create 4 20555 NULL
88263 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
88264 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
88265 +receive_packet_12367 receive_packet 2 12367 NULL
88266 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
88267 +mem_write_22232 mem_write 3 22232 NULL
88268 +read_file_bool_4180 read_file_bool 3 4180 NULL
88269 +send_to_tty_45141 send_to_tty 3 45141 NULL
88270 +fops_read_40672 fops_read 3 40672 NULL
88271 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
88272 +write_leb_36957 write_leb 5 36957 NULL
88273 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
88274 +device_write_45156 device_write 3 45156 NULL
88275 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
88276 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
88277 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
88278 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
88279 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
88280 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
88281 +isp1760_register_628 isp1760_register 1-2 628 NULL
88282 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
88283 +lirc_write_20604 lirc_write 3 20604 NULL
88284 +sel_write_member_28800 sel_write_member 3 28800 NULL
88285 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
88286 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
88287 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
88288 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
88289 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
88290 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
88291 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
88292 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
88293 +setxattr_37006 setxattr 4 37006 NULL
88294 +add_child_45201 add_child 4 45201 NULL
88295 +seq_open_private_61589 seq_open_private 3 61589 NULL
88296 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
88297 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
88298 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
88299 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
88300 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
88301 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
88302 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
88303 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
88304 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
88305 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
88306 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
88307 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
88308 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
88309 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
88310 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
88311 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
88312 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
88313 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
88314 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
88315 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
88316 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
88317 +resize_stripes_61650 resize_stripes 2 61650 NULL
88318 +n2_run_53459 n2_run 3 53459 NULL
88319 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
88320 +parse_command_37079 parse_command 2 37079 NULL
88321 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
88322 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
88323 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
88324 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
88325 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
88326 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
88327 +insert_one_name_61668 insert_one_name 7 61668 NULL
88328 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
88329 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
88330 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
88331 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
88332 +lock_loop_61681 lock_loop 1 61681 NULL
88333 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
88334 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
88335 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
88336 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
88337 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
88338 +push_rx_28939 push_rx 3 28939 NULL
88339 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
88340 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
88341 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
88342 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
88343 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
88344 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
88345 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
88346 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
88347 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
88348 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
88349 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
88350 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
88351 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
88352 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
88353 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
88354 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
88355 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
88356 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
88357 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
88358 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
88359 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
88360 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
88361 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
88362 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
88363 +bin_uuid_28999 bin_uuid 3 28999 NULL
88364 +sys_sendto_20809 sys_sendto 6 20809 NULL
88365 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
88366 +set_registers_53582 set_registers 3 53582 NULL
88367 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
88368 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
88369 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
88370 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
88371 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
88372 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
88373 +keymap_store_45406 keymap_store 4 45406 NULL
88374 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
88375 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
88376 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
88377 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
88378 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
88379 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
88380 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
88381 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
88382 +__do_replace_37227 __do_replace 5 37227 NULL
88383 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
88384 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
88385 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
88386 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
88387 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
88388 +tso_fragment_29050 tso_fragment 3 29050 NULL
88389 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
88390 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
88391 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
88392 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
88393 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
88394 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
88395 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
88396 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
88397 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
88398 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
88399 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
88400 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
88401 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
88402 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
88403 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
88404 +set_link_security_4502 set_link_security 4 4502 NULL
88405 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
88406 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
88407 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
88408 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
88409 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
88410 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
88411 +mmio_read_40348 mmio_read 4 40348 NULL
88412 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
88413 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
88414 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
88415 +ivtv_write_12721 ivtv_write 3 12721 NULL
88416 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
88417 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
88418 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
88419 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
88420 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
88421 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
88422 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
88423 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
88424 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
88425 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
88426 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
88427 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
88428 +send_msg_37323 send_msg 4 37323 NULL
88429 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
88430 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
88431 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
88432 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
88433 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
88434 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
88435 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
88436 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
88437 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
88438 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
88439 +reshape_ring_29147 reshape_ring 2 29147 NULL
88440 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
88441 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
88442 +copy_macs_45534 copy_macs 4 45534 NULL
88443 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
88444 +listxattr_12769 listxattr 3 12769 NULL
88445 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
88446 +wdm_write_53735 wdm_write 3 53735 NULL
88447 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
88448 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
88449 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
88450 +mempool_create_29437 mempool_create 1 29437 NULL
88451 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
88452 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
88453 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
88454 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
88455 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
88456 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
88457 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
88458 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
88459 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
88460 +mgmt_event_12810 mgmt_event 4 12810 NULL
88461 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
88462 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
88463 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
88464 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
88465 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
88466 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
88467 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
88468 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
88469 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
88470 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
88471 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
88472 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
88473 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
88474 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
88475 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
88476 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
88477 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
88478 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
88479 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
88480 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
88481 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
88482 +recover_peb_29238 recover_peb 6-7 29238 NULL
88483 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
88484 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
88485 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
88486 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
88487 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
88488 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
88489 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
88490 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
88491 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
88492 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
88493 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
88494 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
88495 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
88496 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
88497 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
88498 +do_pselect_62061 do_pselect 1 62061 NULL
88499 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
88500 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
88501 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
88502 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
88503 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
88504 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
88505 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
88506 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
88507 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
88508 +sg_read_25799 sg_read 3 25799 NULL
88509 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
88510 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
88511 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
88512 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
88513 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
88514 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
88515 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
88516 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
88517 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
88518 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
88519 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
88520 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
88521 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
88522 +new_skb_21148 new_skb 1 21148 NULL
88523 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
88524 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
88525 +bm_status_write_12964 bm_status_write 3 12964 NULL
88526 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
88527 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
88528 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
88529 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
88530 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
88531 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
88532 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
88533 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
88534 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
88535 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
88536 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
88537 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
88538 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
88539 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
88540 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
88541 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
88542 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
88543 +video_usercopy_62151 video_usercopy 2 62151 NULL
88544 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
88545 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
88546 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
88547 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
88548 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
88549 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
88550 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
88551 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
88552 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
88553 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
88554 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
88555 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
88556 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
88557 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
88558 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
88559 +input_ff_create_21240 input_ff_create 2 21240 NULL
88560 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
88561 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
88562 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
88563 +amthi_read_45831 amthi_read 4 45831 NULL
88564 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
88565 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
88566 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
88567 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
88568 +sys_ipc_4889 sys_ipc 3 4889 NULL
88569 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
88570 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
88571 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
88572 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
88573 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
88574 +do_register_entry_29478 do_register_entry 4 29478 NULL
88575 +isdn_write_45863 isdn_write 3 45863 NULL
88576 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
88577 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
88578 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
88579 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
88580 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
88581 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
88582 +_malloc_54077 _malloc 1 54077 NULL
88583 +add_res_range_21310 add_res_range 4 21310 NULL
88584 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
88585 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
88586 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
88587 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
88588 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
88589 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
88590 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
88591 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
88592 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
88593 +create_xattr_54106 create_xattr 5 54106 NULL
88594 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
88595 +ep_write_59008 ep_write 3 59008 NULL
88596 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
88597 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
88598 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
88599 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
88600 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
88601 +alloc_mr_45935 alloc_mr 1 45935 NULL
88602 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
88603 +isku_receive_54130 isku_receive 4 54130 NULL
88604 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
88605 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
88606 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
88607 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
88608 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
88609 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
88610 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
88611 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
88612 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
88613 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
88614 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
88615 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
88616 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
88617 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
88618 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
88619 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
88620 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
88621 +comedi_read_13199 comedi_read 3 13199 NULL
88622 +flash_write_62354 flash_write 3 62354 NULL
88623 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
88624 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
88625 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
88626 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
88627 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
88628 +proc_file_read_53905 proc_file_read 3 53905 NULL
88629 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
88630 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
88631 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
88632 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
88633 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
88634 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
88635 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
88636 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
88637 +cru_detect_11272 cru_detect 1 11272 NULL
88638 +altera_irscan_62396 altera_irscan 2 62396 NULL
88639 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
88640 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
88641 +fw_download_code_13249 fw_download_code 3 13249 NULL
88642 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
88643 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
88644 +set_ssp_62411 set_ssp 4 62411 NULL
88645 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
88646 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
88647 +get_free_entries_46030 get_free_entries 1 46030 NULL
88648 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
88649 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
88650 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
88651 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
88652 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
88653 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
88654 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
88655 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
88656 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
88657 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
88658 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
88659 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
88660 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
88661 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
88662 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
88663 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
88664 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
88665 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
88666 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
88667 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
88668 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
88669 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
88670 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
88671 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
88672 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
88673 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
88674 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
88675 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
88676 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
88677 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
88678 +probes_write_29711 probes_write 3 29711 NULL
88679 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
88680 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
88681 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
88682 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
88683 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
88684 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
88685 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
88686 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
88687 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
88688 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
88689 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
88690 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
88691 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
88692 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
88693 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
88694 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
88695 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
88696 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
88697 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
88698 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
88699 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
88700 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
88701 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
88702 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
88703 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
88704 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
88705 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
88706 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
88707 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
88708 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
88709 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
88710 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
88711 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
88712 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
88713 +isdn_read_50021 isdn_read 3 50021 NULL
88714 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
88715 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
88716 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
88717 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
88718 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
88719 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
88720 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
88721 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
88722 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
88723 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
88724 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
88725 +get_subdir_62581 get_subdir 3 62581 NULL
88726 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
88727 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
88728 +vfs_readv_38011 vfs_readv 3 38011 NULL
88729 +keyring_read_13438 keyring_read 3 13438 NULL
88730 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
88731 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
88732 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
88733 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
88734 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
88735 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
88736 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
88737 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
88738 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
88739 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
88740 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
88741 +ftrace_write_29551 ftrace_write 3 29551 NULL
88742 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
88743 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
88744 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
88745 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
88746 +dev_write_7708 dev_write 3 7708 NULL
88747 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
88748 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
88749 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
88750 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
88751 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
88752 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
88753 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
88754 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
88755 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
88756 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
88757 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
88758 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
88759 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
88760 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
88761 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
88762 +bm_init_13529 bm_init 2 13529 NULL
88763 +check586_29914 check586 2 29914 NULL
88764 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
88765 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
88766 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
88767 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
88768 +pg_read_17276 pg_read 3 17276 NULL
88769 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
88770 +ep0_read_38095 ep0_read 3 38095 NULL
88771 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
88772 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
88773 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
88774 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
88775 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
88776 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
88777 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
88778 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
88779 +l2down_create_21755 l2down_create 4 21755 NULL
88780 +alloc_tio_13564 alloc_tio 3 13564 NULL
88781 +viacam_read_54526 viacam_read 3 54526 NULL
88782 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
88783 +tunables_read_36385 tunables_read 3 36385 NULL
88784 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
88785 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
88786 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
88787 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
88788 +setsockopt_54539 setsockopt 5 54539 NULL
88789 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
88790 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
88791 +tty_register_device_4544 tty_register_device 2 4544 NULL
88792 +cache_write_13589 cache_write 3 13589 NULL
88793 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
88794 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
88795 +key_replays_read_62746 key_replays_read 3 62746 NULL
88796 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
88797 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
88798 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
88799 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
88800 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
88801 +cdev_add_38176 cdev_add 2-3 38176 NULL
88802 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
88803 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
88804 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
88805 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
88806 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
88807 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
88808 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
88809 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
88810 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
88811 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
88812 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
88813 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
88814 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
88815 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
88816 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
88817 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
88818 +packet_snd_13634 packet_snd 3 13634 NULL
88819 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
88820 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
88821 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
88822 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
88823 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
88824 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
88825 +drp_wmove_30043 drp_wmove 4 30043 NULL
88826 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
88827 +cache_downcall_13666 cache_downcall 3 13666 NULL
88828 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
88829 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
88830 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
88831 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
88832 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
88833 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
88834 +tty_write_5494 tty_write 3 5494 NULL
88835 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
88836 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
88837 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
88838 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
88839 +teiup_create_43201 teiup_create 3 43201 NULL
88840 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
88841 +filldir64_46469 filldir64 3 46469 NULL
88842 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
88843 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
88844 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
88845 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
88846 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
88847 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
88848 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
88849 +spidev_message_5518 spidev_message 3 5518 NULL
88850 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
88851 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
88852 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
88853 +evm_read_key_54674 evm_read_key 3 54674 NULL
88854 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
88855 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
88856 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
88857 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
88858 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
88859 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
88860 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
88861 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
88862 +u32_array_read_2219 u32_array_read 3 2219 NULL
88863 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
88864 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
88865 +sys_add_key_61288 sys_add_key 4 61288 NULL
88866 +kmsg_read_46514 kmsg_read 3 46514 NULL
88867 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
88868 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
88869 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
88870 +recv_stream_30138 recv_stream 4 30138 NULL
88871 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
88872 +getdqbuf_62908 getdqbuf 1 62908 NULL
88873 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
88874 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
88875 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
88876 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
88877 +fir16_create_5574 fir16_create 3 5574 NULL
88878 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
88879 +pt_write_40159 pt_write 3 40159 NULL
88880 +bioset_create_5580 bioset_create 1 5580 NULL
88881 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
88882 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
88883 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
88884 +kzalloc_54740 kzalloc 1 54740 NULL
88885 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
88886 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
88887 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
88888 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
88889 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
88890 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
88891 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
88892 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
88893 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
88894 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
88895 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
88896 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
88897 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
88898 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
88899 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
88900 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
88901 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
88902 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
88903 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
88904 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
88905 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
88906 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
88907 +ti_recv_22027 ti_recv 4 22027 NULL
88908 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
88909 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
88910 +nfsd_write_54809 nfsd_write 6 54809 NULL
88911 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
88912 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
88913 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
88914 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
88915 +get_skb_63008 get_skb 2 63008 NULL
88916 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
88917 +netlink_send_38434 netlink_send 5 38434 NULL
88918 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
88919 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
88920 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
88921 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
88922 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
88923 +write_rio_54837 write_rio 3 54837 NULL
88924 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
88925 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
88926 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
88927 +get_arg_5694 get_arg 3 5694 NULL
88928 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
88929 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
88930 +compat_readv_30273 compat_readv 3 30273 NULL
88931 +printer_read_54851 printer_read 3 54851 NULL
88932 +mem_rw_22085 mem_rw 3 22085 NULL
88933 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
88934 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
88935 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
88936 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
88937 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
88938 +unlink1_63059 unlink1 3 63059 NULL
88939 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
88940 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
88941 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
88942 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
88943 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
88944 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
88945 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
88946 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
88947 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
88948 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
88949 +dev_names_read_38509 dev_names_read 3 38509 NULL
88950 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
88951 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
88952 +get_packet_5747 get_packet 3 5747 NULL
88953 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
88954 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
88955 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
88956 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
88957 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
88958 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
88959 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
88960 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
88961 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
88962 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
88963 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
88964 +resource_from_user_30341 resource_from_user 3 30341 NULL
88965 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
88966 +sound_write_5102 sound_write 3 5102 NULL
88967 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
88968 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
88969 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
88970 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
88971 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
88972 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
88973 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
88974 +com90xx_found_13974 com90xx_found 3 13974 NULL
88975 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
88976 +qcam_read_13977 qcam_read 3 13977 NULL
88977 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
88978 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
88979 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
88980 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
88981 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
88982 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
88983 +generic_readlink_32654 generic_readlink 3 32654 NULL
88984 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
88985 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
88986 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
88987 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
88988 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
88989 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
88990 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
88991 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
88992 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
88993 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
88994 +concat_writev_21451 concat_writev 3 21451 NULL
88995 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
88996 +_queue_data_54983 _queue_data 4 54983 NULL
88997 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
88998 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
88999 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
89000 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
89001 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
89002 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
89003 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
89004 +setup_req_5848 setup_req 3 5848 NULL
89005 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
89006 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
89007 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
89008 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
89009 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
89010 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
89011 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
89012 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
89013 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
89014 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
89015 +cma_create_area_38642 cma_create_area 2 38642 NULL
89016 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
89017 +sriov_enable_59689 sriov_enable 2 59689 NULL
89018 +enable_write_30456 enable_write 3 30456 NULL
89019 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
89020 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
89021 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
89022 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
89023 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
89024 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
89025 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
89026 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
89027 +port_show_regs_5904 port_show_regs 3 5904 NULL
89028 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
89029 +ptp_read_63251 ptp_read 4 63251 NULL
89030 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
89031 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
89032 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
89033 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
89034 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
89035 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
89036 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
89037 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
89038 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
89039 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
89040 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
89041 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
89042 +read_dma_55086 read_dma 3 55086 NULL
89043 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
89044 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
89045 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
89046 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
89047 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
89048 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
89049 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
89050 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
89051 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
89052 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
89053 +em_canid_change_14150 em_canid_change 3 14150 NULL
89054 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
89055 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
89056 +fb_write_46924 fb_write 3 46924 NULL
89057 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
89058 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
89059 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
89060 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
89061 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
89062 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
89063 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
89064 +udf_readpages_38761 udf_readpages 4 38761 NULL
89065 +reada_add_block_54247 reada_add_block 2 54247 NULL
89066 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
89067 +proc_info_read_63344 proc_info_read 3 63344 NULL
89068 +pep_indicate_38611 pep_indicate 5 38611 NULL
89069 +set_le_30581 set_le 4 30581 NULL
89070 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
89071 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
89072 +alloc_private_22399 alloc_private 2 22399 NULL
89073 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
89074 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
89075 +zoran_write_22404 zoran_write 3 22404 NULL
89076 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
89077 +idmouse_read_63374 idmouse_read 3 63374 NULL
89078 +queue_reply_22416 queue_reply 3 22416 NULL
89079 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
89080 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
89081 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
89082 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
89083 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
89084 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
89085 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
89086 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
89087 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
89088 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
89089 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
89090 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
89091 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
89092 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
89093 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
89094 +sys_select_38827 sys_select 1 38827 NULL
89095 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
89096 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
89097 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
89098 +direct_entry_38836 direct_entry 3 38836 NULL
89099 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
89100 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
89101 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
89102 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
89103 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
89104 +write_head_30481 write_head 4 30481 NULL
89105 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
89106 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
89107 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
89108 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
89109 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
89110 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
89111 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
89112 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
89113 +agp_remap_30665 agp_remap 2 30665 NULL
89114 +interfaces_38859 interfaces 2 38859 NULL
89115 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
89116 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
89117 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
89118 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
89119 +qc_capture_19298 qc_capture 3 19298 NULL
89120 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
89121 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
89122 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
89123 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
89124 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
89125 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
89126 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
89127 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
89128 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
89129 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
89130 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
89131 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
89132 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
89133 +read_kcore_63488 read_kcore 3 63488 NULL
89134 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
89135 +__skb_cow_39254 __skb_cow 2 39254 NULL
89136 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
89137 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
89138 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
89139 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
89140 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
89141 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
89142 +mousedev_read_47123 mousedev_read 3 47123 NULL
89143 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
89144 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
89145 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
89146 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
89147 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
89148 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
89149 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
89150 +vme_user_read_55338 vme_user_read 3 55338 NULL
89151 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
89152 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
89153 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
89154 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
89155 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
89156 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
89157 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
89158 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
89159 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
89160 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
89161 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
89162 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
89163 +snapshot_read_22601 snapshot_read 3 22601 NULL
89164 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
89165 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
89166 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
89167 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
89168 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
89169 +__send_to_port_55383 __send_to_port 3 55383 NULL
89170 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
89171 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
89172 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
89173 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
89174 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
89175 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
89176 +get_nodes_39012 get_nodes 3 39012 NULL
89177 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
89178 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
89179 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
89180 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
89181 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
89182 +create_subvol_30836 create_subvol 4 30836 NULL
89183 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
89184 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
89185 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
89186 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
89187 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
89188 +read_oldmem_55658 read_oldmem 3 55658 NULL
89189 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
89190 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
89191 +options_write_47243 options_write 3 47243 NULL
89192 +module_alloc_63630 module_alloc 1 63630 NULL
89193 +alloc_skb_55439 alloc_skb 1 55439 NULL
89194 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
89195 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
89196 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
89197 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
89198 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
89199 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
89200 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
89201 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
89202 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
89203 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
89204 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
89205 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
89206 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
89207 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
89208 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
89209 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
89210 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
89211 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
89212 +vbi_read_63673 vbi_read 3 63673 NULL
89213 +tun_get_user_39099 tun_get_user 4 39099 NULL
89214 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
89215 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
89216 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
89217 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
89218 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
89219 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
89220 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
89221 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
89222 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
89223 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
89224 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
89225 +ax25_output_22736 ax25_output 2 22736 NULL
89226 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
89227 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
89228 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
89229 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
89230 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
89231 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
89232 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
89233 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
89234 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
89235 +hid_input_report_32458 hid_input_report 4 32458 NULL
89236 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
89237 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
89238 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
89239 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
89240 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
89241 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
89242 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
89243 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
89244 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
89245 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
89246 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
89247 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
89248 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
89249 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
89250 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
89251 +get_info_55681 get_info 3 55681 NULL
89252 +setkey_14987 setkey 3 14987 NULL
89253 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
89254 +init_list_set_39188 init_list_set 2-3 39188 NULL
89255 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
89256 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
89257 +l2up_create_6430 l2up_create 3 6430 NULL
89258 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
89259 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
89260 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
89261 +add_partition_55588 add_partition 2 55588 NULL
89262 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
89263 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
89264 +depth_read_31112 depth_read 3 31112 NULL
89265 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
89266 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
89267 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
89268 +profile_replace_14652 profile_replace 3 14652 NULL
89269 +vzalloc_47421 vzalloc 1 47421 NULL
89270 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
89271 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
89272 +sys_writev_28384 sys_writev 3 28384 NULL
89273 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
89274 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
89275 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
89276 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
89277 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
89278 +create_attr_set_22861 create_attr_set 1 22861 NULL
89279 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
89280 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
89281 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
89282 +sel_write_load_63830 sel_write_load 3 63830 NULL
89283 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
89284 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
89285 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
89286 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
89287 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
89288 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
89289 +probe_bios_17467 probe_bios 1 17467 NULL
89290 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
89291 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
89292 +mei_read_6507 mei_read 3 6507 NULL
89293 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
89294 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
89295 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
89296 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
89297 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
89298 +SetArea_50835 SetArea 4 50835 NULL
89299 +tpm_read_50344 tpm_read 3 50344 NULL
89300 +newpart_47485 newpart 6 47485 NULL
89301 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
89302 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
89303 +core_sys_select_47494 core_sys_select 1 47494 NULL
89304 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
89305 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
89306 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
89307 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
89308 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
89309 +unlink_simple_47506 unlink_simple 3 47506 NULL
89310 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
89311 +wdm_read_6549 wdm_read 3 6549 NULL
89312 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
89313 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
89314 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
89315 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
89316 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
89317 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
89318 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
89319 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
89320 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
89321 +filter_read_61692 filter_read 3 61692 NULL
89322 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
89323 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
89324 +debugfs_read_62535 debugfs_read 3 62535 NULL
89325 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
89326 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
89327 +divas_write_63901 divas_write 3 63901 NULL
89328 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
89329 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
89330 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
89331 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
89332 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
89333 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
89334 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
89335 +ipw_write_59807 ipw_write 3 59807 NULL
89336 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
89337 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
89338 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
89339 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
89340 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
89341 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
89342 +cycx_setup_47562 cycx_setup 4 47562 NULL
89343 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
89344 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
89345 +set_local_name_55757 set_local_name 4 55757 NULL
89346 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
89347 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
89348 +read_ldt_47570 read_ldt 2 47570 NULL
89349 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
89350 +pci_iomap_47575 pci_iomap 3 47575 NULL
89351 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
89352 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
89353 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
89354 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
89355 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
89356 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
89357 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
89358 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
89359 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
89360 +conf_read_55786 conf_read 3 55786 NULL
89361 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
89362 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
89363 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
89364 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
89365 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
89366 +user_power_read_39414 user_power_read 3 39414 NULL
89367 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
89368 +uea_request_47613 uea_request 4 47613 NULL
89369 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
89370 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
89371 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
89372 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
89373 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
89374 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
89375 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
89376 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
89377 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
89378 +kmemdup_64015 kmemdup 2 64015 NULL
89379 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
89380 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
89381 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
89382 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
89383 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
89384 +oz_events_read_47535 oz_events_read 3 47535 NULL
89385 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
89386 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
89387 +sys_semop_39457 sys_semop 3 39457 NULL
89388 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
89389 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
89390 +update_pmkid_2481 update_pmkid 4 2481 NULL
89391 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
89392 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
89393 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
89394 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
89395 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
89396 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
89397 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
89398 +mpeg_read_6708 mpeg_read 3 6708 NULL
89399 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
89400 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
89401 +sky2_receive_13407 sky2_receive 2 13407 NULL
89402 +krealloc_14908 krealloc 2 14908 NULL
89403 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
89404 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
89405 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
89406 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
89407 +video_proc_write_6724 video_proc_write 3 6724 NULL
89408 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
89409 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
89410 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
89411 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
89412 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
89413 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
89414 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
89415 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
89416 +command_file_write_31318 command_file_write 3 31318 NULL
89417 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
89418 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
89419 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
89420 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
89421 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
89422 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
89423 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
89424 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
89425 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
89426 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
89427 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
89428 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
89429 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
89430 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
89431 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
89432 +int_proc_write_39542 int_proc_write 3 39542 NULL
89433 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
89434 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
89435 +read_file_ani_23161 read_file_ani 3 23161 NULL
89436 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
89437 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
89438 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
89439 +pp_write_39554 pp_write 3 39554 NULL
89440 +ioremap_23172 ioremap 1-2 23172 NULL
89441 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
89442 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
89443 +usblp_write_23178 usblp_write 3 23178 NULL
89444 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
89445 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
89446 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
89447 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
89448 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
89449 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
89450 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
89451 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
89452 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
89453 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
89454 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
89455 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
89456 +__team_options_register_63941 __team_options_register 3 63941 NULL
89457 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
89458 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
89459 +rvmalloc_46873 rvmalloc 1 46873 NULL
89460 +vmap_15025 vmap 2 15025 NULL
89461 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
89462 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
89463 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
89464 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
89465 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
89466 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
89467 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
89468 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
89469 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
89470 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
89471 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
89472 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
89473 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
89474 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
89475 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
89476 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
89477 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
89478 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
89479 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
89480 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
89481 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
89482 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
89483 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
89484 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
89485 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
89486 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
89487 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
89488 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
89489 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
89490 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
89491 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
89492 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
89493 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
89494 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
89495 +alg_setkey_31485 alg_setkey 3 31485 NULL
89496 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
89497 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
89498 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
89499 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
89500 +vhci_read_47878 vhci_read 3 47878 NULL
89501 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
89502 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
89503 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
89504 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
89505 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
89506 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
89507 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
89508 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
89509 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
89510 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
89511 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
89512 +timeout_read_47915 timeout_read 3 47915 NULL
89513 +hidraw_write_31536 hidraw_write 3 31536 NULL
89514 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
89515 +page_readlink_23346 page_readlink 3 23346 NULL
89516 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
89517 +comedi_write_47926 comedi_write 3 47926 NULL
89518 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
89519 +dsp_write_46218 dsp_write 2 46218 NULL
89520 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
89521 +usbvision_read_31555 usbvision_read 3 31555 NULL
89522 +pd_video_read_24510 pd_video_read 3 24510 NULL
89523 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
89524 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
89525 +request_key_async_6990 request_key_async 4 6990 NULL
89526 +ts_write_64336 ts_write 3 64336 NULL
89527 +handle_response_55951 handle_response 5 55951 NULL
89528 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
89529 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
89530 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
89531 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
89532 +osst_write_31581 osst_write 3 31581 NULL
89533 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
89534 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
89535 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
89536 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
89537 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
89538 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
89539 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
89540 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
89541 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
89542 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
89543 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
89544 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
89545 +ilo_write_64378 ilo_write 3 64378 NULL
89546 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
89547 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
89548 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
89549 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
89550 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
89551 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
89552 +copy_from_user_17559 copy_from_user 3 17559 NULL
89553 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
89554 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
89555 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
89556 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
89557 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
89558 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
89559 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
89560 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
89561 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
89562 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
89563 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
89564 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
89565 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
89566 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
89567 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
89568 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
89569 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
89570 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
89571 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
89572 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
89573 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
89574 +__lgread_31668 __lgread 4 31668 NULL
89575 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
89576 +fd_copyin_56247 fd_copyin 3 56247 NULL
89577 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
89578 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
89579 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
89580 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
89581 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
89582 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
89583 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
89584 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
89585 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
89586 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
89587 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
89588 +event_filter_read_23494 event_filter_read 3 23494 NULL
89589 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
89590 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
89591 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
89592 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
89593 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
89594 +pkt_add_39897 pkt_add 3 39897 NULL
89595 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
89596 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
89597 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
89598 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
89599 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
89600 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
89601 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
89602 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
89603 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
89604 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
89605 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
89606 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
89607 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
89608 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
89609 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
89610 +remove_uuid_64505 remove_uuid 4 64505 NULL
89611 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
89612 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
89613 +create_table_16213 create_table 2 16213 NULL
89614 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
89615 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
89616 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
89617 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
89618 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
89619 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
89620 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
89621 +set_discoverable_48141 set_discoverable 4 48141 NULL
89622 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
89623 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
89624 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
89625 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
89626 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
89627 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
89628 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
89629 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
89630 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
89631 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
89632 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
89633 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
89634 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
89635 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
89636 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
89637 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
89638 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
89639 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
89640 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
89641 +dev_read_56369 dev_read 3 56369 NULL
89642 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
89643 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
89644 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
89645 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
89646 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
89647 +init_ipath_48187 init_ipath 1 48187 NULL
89648 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
89649 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
89650 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
89651 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
89652 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
89653 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
89654 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
89655 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
89656 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
89657 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
89658 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
89659 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
89660 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
89661 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
89662 +use_pool_64607 use_pool 2 64607 NULL
89663 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
89664 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
89665 +store_msg_56417 store_msg 3 56417 NULL
89666 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
89667 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
89668 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
89669 +read_file_recv_48232 read_file_recv 3 48232 NULL
89670 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
89671 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
89672 +fanotify_write_64623 fanotify_write 3 64623 NULL
89673 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
89674 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
89675 +fl_create_56435 fl_create 5 56435 NULL
89676 +gnttab_map_56439 gnttab_map 2 56439 NULL
89677 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
89678 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
89679 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
89680 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
89681 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
89682 +set_connectable_56458 set_connectable 4 56458 NULL
89683 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
89684 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
89685 +add_port_54941 add_port 2 54941 NULL
89686 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
89687 +cx18_read_23699 cx18_read 3 23699 NULL
89688 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
89689 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
89690 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
89691 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
89692 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
89693 +send_set_info_48288 send_set_info 7 48288 NULL
89694 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
89695 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
89696 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
89697 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
89698 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
89699 +new_dir_31919 new_dir 3 31919 NULL
89700 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
89701 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
89702 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
89703 +mgmt_control_7349 mgmt_control 3 7349 NULL
89704 +hash_setkey_48310 hash_setkey 3 48310 NULL
89705 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
89706 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
89707 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
89708 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
89709 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
89710 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
89711 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
89712 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
89713 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
89714 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
89715 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
89716 +vb2_write_31948 vb2_write 3 31948 NULL
89717 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
89718 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
89719 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
89720 +ip_options_get_56538 ip_options_get 4 56538 NULL
89721 +write_62671 write 3 62671 NULL
89722 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
89723 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
89724 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
89725 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
89726 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
89727 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
89728 +skb_add_data_48363 skb_add_data 3 48363 NULL
89729 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
89730 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
89731 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
89732 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
89733 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
89734 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
89735 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
89736 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
89737 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
89738 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
89739 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
89740 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
89741 +system_enable_read_25815 system_enable_read 3 25815 NULL
89742 +allocate_probes_40204 allocate_probes 1 40204 NULL
89743 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
89744 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
89745 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
89746 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
89747 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
89748 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
89749 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
89750 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
89751 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
89752 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
89753 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
89754 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
89755 +fs_path_add_15648 fs_path_add 3 15648 NULL
89756 +event_filter_write_56609 event_filter_write 3 56609 NULL
89757 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
89758 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
89759 +xsd_read_15653 xsd_read 3 15653 NULL
89760 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
89761 +p54_init_common_23850 p54_init_common 1 23850 NULL
89762 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
89763 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
89764 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
89765 +garp_request_join_7471 garp_request_join 4 7471 NULL
89766 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
89767 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
89768 +unifi_read_14899 unifi_read 3 14899 NULL
89769 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
89770 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
89771 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
89772 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
89773 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
89774 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
89775 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
89776 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
89777 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
89778 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
89779 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
89780 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
89781 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
89782 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
89783 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
89784 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
89785 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
89786 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
89787 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
89788 +bio_alloc_32095 bio_alloc 2 32095 NULL
89789 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
89790 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
89791 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
89792 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
89793 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
89794 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
89795 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
89796 +send_control_msg_48498 send_control_msg 6 48498 NULL
89797 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
89798 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
89799 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
89800 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
89801 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
89802 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
89803 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
89804 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
89805 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
89806 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
89807 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
89808 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
89809 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
89810 +alloc_tx_32143 alloc_tx 2 32143 NULL
89811 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
89812 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
89813 +hsc_write_55875 hsc_write 3 55875 NULL
89814 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
89815 +do_test_15766 do_test 1 15766 NULL
89816 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
89817 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
89818 +named_distribute_48544 named_distribute 4 48544 NULL
89819 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
89820 +venus_link_32165 venus_link 5 32165 NULL
89821 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
89822 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
89823 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
89824 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
89825 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
89826 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
89827 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
89828 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
89829 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
89830 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
89831 +groups_alloc_7614 groups_alloc 1 7614 NULL
89832 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
89833 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
89834 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
89835 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
89836 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
89837 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
89838 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
89839 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
89840 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
89841 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
89842 +snapshot_write_28351 snapshot_write 3 28351 NULL
89843 +event_enable_read_7074 event_enable_read 3 7074 NULL
89844 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
89845 +do_syslog_56807 do_syslog 3 56807 NULL
89846 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
89847 +pskb_pull_65005 pskb_pull 2 65005 NULL
89848 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
89849 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
89850 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
89851 +unifi_write_65012 unifi_write 3 65012 NULL
89852 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
89853 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
89854 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
89855 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
89856 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
89857 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
89858 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
89859 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
89860 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
89861 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
89862 +if_write_51756 if_write 3 51756 NULL
89863 +insert_dent_65034 insert_dent 7 65034 NULL
89864 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
89865 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
89866 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
89867 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
89868 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
89869 +lc_create_48662 lc_create 3 48662 NULL
89870 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
89871 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
89872 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
89873 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
89874 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
89875 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
89876 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
89877 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
89878 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
89879 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
89880 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
89881 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
89882 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
89883 +altera_drscan_48698 altera_drscan 2 48698 NULL
89884 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
89885 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
89886 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
89887 +power_read_15939 power_read 3 15939 NULL
89888 +recv_msg_48709 recv_msg 4 48709 NULL
89889 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
89890 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
89891 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
89892 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
89893 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
89894 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
89895 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
89896 +revalidate_19043 revalidate 2 19043 NULL
89897 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
89898 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
89899 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
89900 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
89901 +check_header_56930 check_header 2 56930 NULL
89902 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
89903 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
89904 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
89905 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
89906 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
89907 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
89908 +frame_alloc_15981 frame_alloc 4 15981 NULL
89909 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
89910 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
89911 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
89912 +adu_read_24177 adu_read 3 24177 NULL
89913 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
89914 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
89915 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
89916 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
89917 +vfd_write_14717 vfd_write 3 14717 NULL
89918 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
89919 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
89920 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
89921 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
89922 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
89923 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
89924 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
89925 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
89926 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
89927 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
89928 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
89929 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
89930 +register_device_60015 register_device 2-3 60015 NULL
89931 +got_frame_16028 got_frame 2 16028 NULL
89932 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
89933 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
89934 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
89935 +scsi_register_49094 scsi_register 2 49094 NULL
89936 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
89937 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
89938 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
89939 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
89940 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
89941 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
89942 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
89943 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
89944 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
89945 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
89946 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
89947 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
89948 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
89949 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
89950 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
89951 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
89952 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
89953 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
89954 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
89955 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
89956 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
89957 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
89958 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
89959 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
89960 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
89961 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
89962 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
89963 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
89964 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
89965 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
89966 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
89967 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
89968 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
89969 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
89970 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
89971 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
89972 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
89973 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
89974 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
89975 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
89976 +fsm_init_16134 fsm_init 2 16134 NULL
89977 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
89978 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
89979 +disconnect_32521 disconnect 4 32521 NULL
89980 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
89981 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
89982 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
89983 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
89984 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
89985 +ilo_read_32531 ilo_read 3 32531 NULL
89986 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
89987 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
89988 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
89989 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
89990 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
89991 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
89992 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
89993 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
89994 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
89995 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
89996 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
89997 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
89998 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
89999 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
90000 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
90001 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
90002 +card_send_command_40757 card_send_command 3 40757 NULL
90003 +sys_mbind_7990 sys_mbind 5 7990 NULL
90004 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
90005 +pg_write_40766 pg_write 3 40766 NULL
90006 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
90007 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
90008 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
90009 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
90010 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
90011 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
90012 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
90013 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
90014 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
90015 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
90016 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
90017 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
90018 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
90019 +vcs_read_8017 vcs_read 3 8017 NULL
90020 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
90021 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
90022 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
90023 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
90024 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
90025 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
90026 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
90027 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
90028 +copy_and_check_19089 copy_and_check 3 19089 NULL
90029 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
90030 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
90031 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
90032 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
90033 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
90034 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
90035 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
90036 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
90037 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
90038 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
90039 +smk_user_access_24440 smk_user_access 3 24440 NULL
90040 +xd_rw_49020 xd_rw 3-4 49020 NULL
90041 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
90042 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
90043 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
90044 +kvmalloc_32646 kvmalloc 1 32646 NULL
90045 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
90046 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
90047 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
90048 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
90049 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
90050 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
90051 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
90052 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
90053 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
90054 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
90055 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
90056 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
90057 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
90058 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
90059 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
90060 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
90061 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
90062 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
90063 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
90064 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
90065 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
90066 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
90067 +venus_lookup_8121 venus_lookup 4 8121 NULL
90068 +compat_writev_60063 compat_writev 3 60063 NULL
90069 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
90070 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
90071 +read_file_queue_40895 read_file_queue 3 40895 NULL
90072 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
90073 +waiters_read_40902 waiters_read 3 40902 NULL
90074 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
90075 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
90076 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
90077 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
90078 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
90079 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
90080 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
90081 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
90082 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
90083 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
90084 +alloc_dr_65495 alloc_dr 2 65495 NULL
90085 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
90086 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
90087 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
90088 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
90089 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
90090 +rbd_add_16366 rbd_add 3 16366 NULL
90091 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
90092 +pt_read_49136 pt_read 3 49136 NULL
90093 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
90094 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
90095 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
90096 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
90097 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
90098 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
90099 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
90100 new file mode 100644
90101 index 0000000..792ee60
90102 --- /dev/null
90103 +++ b/tools/gcc/size_overflow_plugin.c
90104 @@ -0,0 +1,1930 @@
90105 +/*
90106 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
90107 + * Licensed under the GPL v2, or (at your option) v3
90108 + *
90109 + * Homepage:
90110 + * http://www.grsecurity.net/~ephox/overflow_plugin/
90111 + *
90112 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
90113 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
90114 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
90115 + *
90116 + * Usage:
90117 + * $ 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
90118 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
90119 + */
90120 +
90121 +#include "gcc-plugin.h"
90122 +#include "config.h"
90123 +#include "system.h"
90124 +#include "coretypes.h"
90125 +#include "tree.h"
90126 +#include "tree-pass.h"
90127 +#include "intl.h"
90128 +#include "plugin-version.h"
90129 +#include "tm.h"
90130 +#include "toplev.h"
90131 +#include "function.h"
90132 +#include "tree-flow.h"
90133 +#include "plugin.h"
90134 +#include "gimple.h"
90135 +#include "c-common.h"
90136 +#include "diagnostic.h"
90137 +#include "cfgloop.h"
90138 +
90139 +#if BUILDING_GCC_VERSION >= 4007
90140 +#include "c-tree.h"
90141 +#else
90142 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
90143 +#endif
90144 +
90145 +struct size_overflow_hash {
90146 + const struct size_overflow_hash * const next;
90147 + const char * const name;
90148 + const unsigned int param;
90149 +};
90150 +
90151 +#include "size_overflow_hash.h"
90152 +
90153 +enum marked {
90154 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
90155 +};
90156 +
90157 +static unsigned int call_count = 0;
90158 +
90159 +#define __unused __attribute__((__unused__))
90160 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
90161 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
90162 +#define BEFORE_STMT true
90163 +#define AFTER_STMT false
90164 +#define CREATE_NEW_VAR NULL_TREE
90165 +#define CODES_LIMIT 32
90166 +#define MAX_PARAM 32
90167 +#define MY_STMT GF_PLF_1
90168 +#define NO_CAST_CHECK GF_PLF_2
90169 +
90170 +#if BUILDING_GCC_VERSION == 4005
90171 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
90172 +#endif
90173 +
90174 +int plugin_is_GPL_compatible;
90175 +void debug_gimple_stmt(gimple gs);
90176 +
90177 +static tree expand(struct pointer_set_t *visited, tree lhs);
90178 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
90179 +static tree report_size_overflow_decl;
90180 +static const_tree const_char_ptr_type_node;
90181 +static unsigned int handle_function(void);
90182 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
90183 +static tree get_size_overflow_type(gimple stmt, const_tree node);
90184 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
90185 +
90186 +static struct plugin_info size_overflow_plugin_info = {
90187 + .version = "20130109beta",
90188 + .help = "no-size-overflow\tturn off size overflow checking\n",
90189 +};
90190 +
90191 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90192 +{
90193 + unsigned int arg_count;
90194 + enum tree_code code = TREE_CODE(*node);
90195 +
90196 + switch (code) {
90197 + case FUNCTION_DECL:
90198 + arg_count = type_num_arguments(TREE_TYPE(*node));
90199 + break;
90200 + case FUNCTION_TYPE:
90201 + case METHOD_TYPE:
90202 + arg_count = type_num_arguments(*node);
90203 + break;
90204 + default:
90205 + *no_add_attrs = true;
90206 + error("%s: %qE attribute only applies to functions", __func__, name);
90207 + return NULL_TREE;
90208 + }
90209 +
90210 + for (; args; args = TREE_CHAIN(args)) {
90211 + tree position = TREE_VALUE(args);
90212 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
90213 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90214 + *no_add_attrs = true;
90215 + }
90216 + }
90217 + return NULL_TREE;
90218 +}
90219 +
90220 +static const char* get_asm_name(tree node)
90221 +{
90222 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
90223 +}
90224 +
90225 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90226 +{
90227 + unsigned int arg_count, arg_num;
90228 + enum tree_code code = TREE_CODE(*node);
90229 +
90230 + switch (code) {
90231 + case FUNCTION_DECL:
90232 + arg_count = type_num_arguments(TREE_TYPE(*node));
90233 + break;
90234 + case FUNCTION_TYPE:
90235 + case METHOD_TYPE:
90236 + arg_count = type_num_arguments(*node);
90237 + break;
90238 + case FIELD_DECL:
90239 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
90240 + if (arg_num != 0) {
90241 + *no_add_attrs = true;
90242 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
90243 + }
90244 + return NULL_TREE;
90245 + default:
90246 + *no_add_attrs = true;
90247 + error("%qE attribute only applies to functions", name);
90248 + return NULL_TREE;
90249 + }
90250 +
90251 + for (; args; args = TREE_CHAIN(args)) {
90252 + tree position = TREE_VALUE(args);
90253 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
90254 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90255 + *no_add_attrs = true;
90256 + }
90257 + }
90258 + return NULL_TREE;
90259 +}
90260 +
90261 +static struct attribute_spec size_overflow_attr = {
90262 + .name = "size_overflow",
90263 + .min_length = 1,
90264 + .max_length = -1,
90265 + .decl_required = true,
90266 + .type_required = false,
90267 + .function_type_required = false,
90268 + .handler = handle_size_overflow_attribute,
90269 +#if BUILDING_GCC_VERSION >= 4007
90270 + .affects_type_identity = false
90271 +#endif
90272 +};
90273 +
90274 +static struct attribute_spec intentional_overflow_attr = {
90275 + .name = "intentional_overflow",
90276 + .min_length = 1,
90277 + .max_length = -1,
90278 + .decl_required = true,
90279 + .type_required = false,
90280 + .function_type_required = false,
90281 + .handler = handle_intentional_overflow_attribute,
90282 +#if BUILDING_GCC_VERSION >= 4007
90283 + .affects_type_identity = false
90284 +#endif
90285 +};
90286 +
90287 +static void register_attributes(void __unused *event_data, void __unused *data)
90288 +{
90289 + register_attribute(&size_overflow_attr);
90290 + register_attribute(&intentional_overflow_attr);
90291 +}
90292 +
90293 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
90294 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
90295 +{
90296 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
90297 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
90298 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
90299 +
90300 + unsigned int m = 0x57559429;
90301 + unsigned int n = 0x5052acdb;
90302 + const unsigned int *key4 = (const unsigned int *)key;
90303 + unsigned int h = len;
90304 + unsigned int k = len + seed + n;
90305 + unsigned long long p;
90306 +
90307 + while (len >= 8) {
90308 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
90309 + len -= 8;
90310 + }
90311 + if (len >= 4) {
90312 + cwmixb(key4[0]) key4 += 1;
90313 + len -= 4;
90314 + }
90315 + if (len)
90316 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
90317 + cwmixb(h ^ (k + n));
90318 + return k ^ h;
90319 +
90320 +#undef cwfold
90321 +#undef cwmixa
90322 +#undef cwmixb
90323 +}
90324 +
90325 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
90326 +{
90327 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
90328 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
90329 + return fn ^ codes;
90330 +}
90331 +
90332 +static inline tree get_original_function_decl(tree fndecl)
90333 +{
90334 + if (DECL_ABSTRACT_ORIGIN(fndecl))
90335 + return DECL_ABSTRACT_ORIGIN(fndecl);
90336 + return fndecl;
90337 +}
90338 +
90339 +static inline gimple get_def_stmt(const_tree node)
90340 +{
90341 + gcc_assert(node != NULL_TREE);
90342 + gcc_assert(TREE_CODE(node) == SSA_NAME);
90343 + return SSA_NAME_DEF_STMT(node);
90344 +}
90345 +
90346 +static unsigned char get_tree_code(const_tree type)
90347 +{
90348 + switch (TREE_CODE(type)) {
90349 + case ARRAY_TYPE:
90350 + return 0;
90351 + case BOOLEAN_TYPE:
90352 + return 1;
90353 + case ENUMERAL_TYPE:
90354 + return 2;
90355 + case FUNCTION_TYPE:
90356 + return 3;
90357 + case INTEGER_TYPE:
90358 + return 4;
90359 + case POINTER_TYPE:
90360 + return 5;
90361 + case RECORD_TYPE:
90362 + return 6;
90363 + case UNION_TYPE:
90364 + return 7;
90365 + case VOID_TYPE:
90366 + return 8;
90367 + case REAL_TYPE:
90368 + return 9;
90369 + case VECTOR_TYPE:
90370 + return 10;
90371 + case REFERENCE_TYPE:
90372 + return 11;
90373 + case OFFSET_TYPE:
90374 + return 12;
90375 + case COMPLEX_TYPE:
90376 + return 13;
90377 + default:
90378 + debug_tree((tree)type);
90379 + gcc_unreachable();
90380 + }
90381 +}
90382 +
90383 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
90384 +{
90385 + gcc_assert(type != NULL_TREE);
90386 +
90387 + while (type && len < CODES_LIMIT) {
90388 + tree_codes[len] = get_tree_code(type);
90389 + len++;
90390 + type = TREE_TYPE(type);
90391 + }
90392 + return len;
90393 +}
90394 +
90395 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
90396 +{
90397 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
90398 + enum tree_code code = TREE_CODE(type);
90399 + size_t len = 0;
90400 +
90401 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
90402 +
90403 + arg = TYPE_ARG_TYPES(type);
90404 + // skip builtins __builtin_constant_p
90405 + if (!arg && DECL_BUILT_IN(fndecl))
90406 + return 0;
90407 +
90408 + if (TREE_CODE_CLASS(code) == tcc_type)
90409 + result = type;
90410 + else
90411 + result = DECL_RESULT(fndecl);
90412 +
90413 + gcc_assert(result != NULL_TREE);
90414 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
90415 +
90416 + if (arg == NULL_TREE) {
90417 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
90418 + arg_field = DECL_ARGUMENT_FLD(fndecl);
90419 + if (arg_field == NULL_TREE)
90420 + return 0;
90421 + arg = TREE_TYPE(arg_field);
90422 + len = add_type_codes(arg, tree_codes, len);
90423 + gcc_assert(len != 0);
90424 + return len;
90425 + }
90426 +
90427 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
90428 + while (arg && len < CODES_LIMIT) {
90429 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
90430 + arg = TREE_CHAIN(arg);
90431 + }
90432 +
90433 + gcc_assert(len != 0);
90434 + return len;
90435 +}
90436 +
90437 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
90438 +{
90439 + unsigned int hash;
90440 + const struct size_overflow_hash *entry;
90441 + unsigned char tree_codes[CODES_LIMIT];
90442 + size_t len;
90443 + const char *func_name = get_asm_name(fndecl);
90444 +
90445 + len = get_function_decl(fndecl, tree_codes);
90446 + if (len == 0)
90447 + return NULL;
90448 +
90449 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
90450 +
90451 + entry = size_overflow_hash[hash];
90452 + while (entry) {
90453 + if (!strcmp(entry->name, func_name))
90454 + return entry;
90455 + entry = entry->next;
90456 + }
90457 +
90458 + return NULL;
90459 +}
90460 +
90461 +static void check_arg_type(const_tree arg)
90462 +{
90463 + const_tree type = TREE_TYPE(arg);
90464 + enum tree_code code = TREE_CODE(type);
90465 +
90466 + if (code == BOOLEAN_TYPE)
90467 + return;
90468 +
90469 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
90470 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
90471 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
90472 +}
90473 +
90474 +static unsigned int find_arg_number(const_tree arg, tree func)
90475 +{
90476 + tree var;
90477 + unsigned int argnum = 1;
90478 +
90479 + if (TREE_CODE(arg) == SSA_NAME)
90480 + arg = SSA_NAME_VAR(arg);
90481 +
90482 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
90483 + if (strcmp(NAME(arg), NAME(var))) {
90484 + argnum++;
90485 + continue;
90486 + }
90487 + check_arg_type(var);
90488 + return argnum;
90489 + }
90490 + gcc_unreachable();
90491 +}
90492 +
90493 +static tree create_new_var(tree type)
90494 +{
90495 + tree new_var = create_tmp_var(type, "cicus");
90496 +
90497 + add_referenced_var(new_var);
90498 + mark_sym_for_renaming(new_var);
90499 + return new_var;
90500 +}
90501 +
90502 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
90503 +{
90504 + gimple assign;
90505 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90506 + tree type = TREE_TYPE(rhs1);
90507 + tree lhs = create_new_var(type);
90508 +
90509 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
90510 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
90511 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90512 +
90513 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
90514 + update_stmt(assign);
90515 + gimple_set_plf(assign, MY_STMT, true);
90516 + return assign;
90517 +}
90518 +
90519 +static bool is_bool(const_tree node)
90520 +{
90521 + const_tree type;
90522 +
90523 + if (node == NULL_TREE)
90524 + return false;
90525 +
90526 + type = TREE_TYPE(node);
90527 + if (!INTEGRAL_TYPE_P(type))
90528 + return false;
90529 + if (TREE_CODE(type) == BOOLEAN_TYPE)
90530 + return true;
90531 + if (TYPE_PRECISION(type) == 1)
90532 + return true;
90533 + return false;
90534 +}
90535 +
90536 +static tree cast_a_tree(tree type, tree var)
90537 +{
90538 + gcc_assert(type != NULL_TREE);
90539 + gcc_assert(var != NULL_TREE);
90540 + gcc_assert(fold_convertible_p(type, var));
90541 +
90542 + return fold_convert(type, var);
90543 +}
90544 +
90545 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
90546 +{
90547 + gimple assign;
90548 +
90549 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
90550 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
90551 + gcc_unreachable();
90552 +
90553 + if (lhs == CREATE_NEW_VAR)
90554 + lhs = create_new_var(dst_type);
90555 +
90556 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
90557 +
90558 + if (!gsi_end_p(*gsi)) {
90559 + location_t loc = gimple_location(gsi_stmt(*gsi));
90560 + gimple_set_location(assign, loc);
90561 + }
90562 +
90563 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90564 +
90565 + if (before)
90566 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
90567 + else
90568 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
90569 + update_stmt(assign);
90570 + gimple_set_plf(assign, MY_STMT, true);
90571 +
90572 + return assign;
90573 +}
90574 +
90575 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
90576 +{
90577 + gimple assign;
90578 + gimple_stmt_iterator gsi;
90579 +
90580 + if (rhs == NULL_TREE)
90581 + return NULL_TREE;
90582 +
90583 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
90584 + return rhs;
90585 +
90586 + gsi = gsi_for_stmt(stmt);
90587 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
90588 + gimple_set_plf(assign, MY_STMT, true);
90589 + return gimple_get_lhs(assign);
90590 +}
90591 +
90592 +static tree cast_to_TI_type(gimple stmt, tree node)
90593 +{
90594 + gimple_stmt_iterator gsi;
90595 + gimple cast_stmt;
90596 + tree type = TREE_TYPE(node);
90597 +
90598 + if (types_compatible_p(type, intTI_type_node))
90599 + return node;
90600 +
90601 + gsi = gsi_for_stmt(stmt);
90602 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90603 + gimple_set_plf(cast_stmt, MY_STMT, true);
90604 + return gimple_get_lhs(cast_stmt);
90605 +}
90606 +
90607 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
90608 +{
90609 + tree lhs;
90610 + gimple_stmt_iterator gsi;
90611 +
90612 + if (rhs1 == NULL_TREE) {
90613 + debug_gimple_stmt(oldstmt);
90614 + error("%s: rhs1 is NULL_TREE", __func__);
90615 + gcc_unreachable();
90616 + }
90617 +
90618 + switch (gimple_code(oldstmt)) {
90619 + case GIMPLE_ASM:
90620 + lhs = rhs1;
90621 + break;
90622 + case GIMPLE_CALL:
90623 + lhs = gimple_call_lhs(oldstmt);
90624 + break;
90625 + case GIMPLE_ASSIGN:
90626 + lhs = gimple_get_lhs(oldstmt);
90627 + break;
90628 + default:
90629 + debug_gimple_stmt(oldstmt);
90630 + gcc_unreachable();
90631 + }
90632 +
90633 + gsi = gsi_for_stmt(oldstmt);
90634 + pointer_set_insert(visited, oldstmt);
90635 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
90636 + basic_block next_bb, cur_bb;
90637 + const_edge e;
90638 +
90639 + gcc_assert(before == false);
90640 + gcc_assert(stmt_can_throw_internal(oldstmt));
90641 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
90642 + gcc_assert(!gsi_end_p(gsi));
90643 +
90644 + cur_bb = gimple_bb(oldstmt);
90645 + next_bb = cur_bb->next_bb;
90646 + e = find_edge(cur_bb, next_bb);
90647 + gcc_assert(e != NULL);
90648 + gcc_assert(e->flags & EDGE_FALLTHRU);
90649 +
90650 + gsi = gsi_after_labels(next_bb);
90651 + gcc_assert(!gsi_end_p(gsi));
90652 +
90653 + before = true;
90654 + oldstmt = gsi_stmt(gsi);
90655 + }
90656 +
90657 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
90658 +}
90659 +
90660 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
90661 +{
90662 + gimple stmt;
90663 + gimple_stmt_iterator gsi;
90664 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
90665 +
90666 + if (gimple_plf(oldstmt, MY_STMT))
90667 + return lhs;
90668 +
90669 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
90670 + rhs1 = gimple_assign_rhs1(oldstmt);
90671 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
90672 + }
90673 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
90674 + rhs2 = gimple_assign_rhs2(oldstmt);
90675 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
90676 + }
90677 +
90678 + stmt = gimple_copy(oldstmt);
90679 + gimple_set_location(stmt, gimple_location(oldstmt));
90680 + gimple_set_plf(stmt, MY_STMT, true);
90681 +
90682 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
90683 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
90684 +
90685 + size_overflow_type = get_size_overflow_type(oldstmt, node);
90686 +
90687 + if (is_bool(lhs))
90688 + new_var = SSA_NAME_VAR(lhs);
90689 + else
90690 + new_var = create_new_var(size_overflow_type);
90691 + new_var = make_ssa_name(new_var, stmt);
90692 + gimple_set_lhs(stmt, new_var);
90693 +
90694 + if (rhs1 != NULL_TREE)
90695 + gimple_assign_set_rhs1(stmt, rhs1);
90696 +
90697 + if (rhs2 != NULL_TREE)
90698 + gimple_assign_set_rhs2(stmt, rhs2);
90699 +#if BUILDING_GCC_VERSION >= 4007
90700 + if (rhs3 != NULL_TREE)
90701 + gimple_assign_set_rhs3(stmt, rhs3);
90702 +#endif
90703 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
90704 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
90705 +
90706 + gsi = gsi_for_stmt(oldstmt);
90707 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
90708 + update_stmt(stmt);
90709 + pointer_set_insert(visited, oldstmt);
90710 + return gimple_get_lhs(stmt);
90711 +}
90712 +
90713 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
90714 +{
90715 + basic_block bb;
90716 + gimple phi;
90717 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
90718 +
90719 + bb = gsi_bb(gsi);
90720 +
90721 + phi = create_phi_node(result, bb);
90722 + gsi = gsi_last(phi_nodes(bb));
90723 + gsi_remove(&gsi, false);
90724 +
90725 + gsi = gsi_for_stmt(oldstmt);
90726 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
90727 + gimple_set_bb(phi, bb);
90728 + gimple_set_plf(phi, MY_STMT, true);
90729 + return phi;
90730 +}
90731 +
90732 +static basic_block create_a_first_bb(void)
90733 +{
90734 + basic_block first_bb;
90735 +
90736 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90737 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
90738 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
90739 + return first_bb;
90740 +}
90741 +
90742 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
90743 +{
90744 + basic_block bb;
90745 + const_gimple newstmt;
90746 + gimple_stmt_iterator gsi;
90747 + bool before = BEFORE_STMT;
90748 +
90749 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
90750 + gsi = gsi_for_stmt(get_def_stmt(arg));
90751 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
90752 + return gimple_get_lhs(newstmt);
90753 + }
90754 +
90755 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
90756 + gsi = gsi_after_labels(bb);
90757 + if (bb->index == 0) {
90758 + bb = create_a_first_bb();
90759 + gsi = gsi_start_bb(bb);
90760 + }
90761 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
90762 + return gimple_get_lhs(newstmt);
90763 +}
90764 +
90765 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
90766 +{
90767 + gimple newstmt;
90768 + gimple_stmt_iterator gsi;
90769 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
90770 + gimple def_newstmt = get_def_stmt(new_rhs);
90771 +
90772 + gsi_insert = gsi_insert_after;
90773 + gsi = gsi_for_stmt(def_newstmt);
90774 +
90775 + switch (gimple_code(get_def_stmt(arg))) {
90776 + case GIMPLE_PHI:
90777 + newstmt = gimple_build_assign(new_var, new_rhs);
90778 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
90779 + gsi_insert = gsi_insert_before;
90780 + break;
90781 + case GIMPLE_ASM:
90782 + case GIMPLE_CALL:
90783 + newstmt = gimple_build_assign(new_var, new_rhs);
90784 + break;
90785 + case GIMPLE_ASSIGN:
90786 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
90787 + break;
90788 + default:
90789 + /* unknown gimple_code (handle_build_new_phi_arg) */
90790 + gcc_unreachable();
90791 + }
90792 +
90793 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
90794 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
90795 + gimple_set_plf(newstmt, MY_STMT, true);
90796 + update_stmt(newstmt);
90797 + return newstmt;
90798 +}
90799 +
90800 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
90801 +{
90802 + const_gimple newstmt;
90803 + gimple def_stmt;
90804 + tree new_rhs;
90805 +
90806 + new_rhs = expand(visited, arg);
90807 + if (new_rhs == NULL_TREE)
90808 + return NULL_TREE;
90809 +
90810 + def_stmt = get_def_stmt(new_rhs);
90811 + if (gimple_code(def_stmt) == GIMPLE_NOP)
90812 + return NULL_TREE;
90813 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
90814 +
90815 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
90816 + return gimple_get_lhs(newstmt);
90817 +}
90818 +
90819 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
90820 +{
90821 + gimple phi, oldstmt = get_def_stmt(orig_result);
90822 + tree new_result, size_overflow_type;
90823 + unsigned int i;
90824 + unsigned int n = gimple_phi_num_args(oldstmt);
90825 +
90826 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
90827 +
90828 + new_result = create_new_var(size_overflow_type);
90829 +
90830 + pointer_set_insert(visited, oldstmt);
90831 + phi = overflow_create_phi_node(oldstmt, new_result);
90832 + for (i = 0; i < n; i++) {
90833 + tree arg, lhs;
90834 +
90835 + arg = gimple_phi_arg_def(oldstmt, i);
90836 + if (is_gimple_constant(arg))
90837 + arg = cast_a_tree(size_overflow_type, arg);
90838 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
90839 + if (lhs == NULL_TREE)
90840 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
90841 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
90842 + }
90843 +
90844 + update_stmt(phi);
90845 + return gimple_phi_result(phi);
90846 +}
90847 +
90848 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
90849 +{
90850 + const_gimple assign;
90851 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90852 + tree origtype = TREE_TYPE(orig_rhs);
90853 +
90854 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
90855 +
90856 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90857 + return gimple_get_lhs(assign);
90858 +}
90859 +
90860 +static void change_rhs1(gimple stmt, tree new_rhs1)
90861 +{
90862 + tree assign_rhs;
90863 + const_tree rhs = gimple_assign_rhs1(stmt);
90864 +
90865 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
90866 + gimple_assign_set_rhs1(stmt, assign_rhs);
90867 + update_stmt(stmt);
90868 +}
90869 +
90870 +static bool check_mode_type(const_gimple stmt)
90871 +{
90872 + const_tree lhs = gimple_get_lhs(stmt);
90873 + const_tree lhs_type = TREE_TYPE(lhs);
90874 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
90875 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
90876 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
90877 +
90878 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
90879 + return false;
90880 +
90881 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
90882 + return false;
90883 +
90884 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
90885 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
90886 + return false;
90887 +
90888 + return true;
90889 +}
90890 +
90891 +static bool check_undefined_integer_operation(const_gimple stmt)
90892 +{
90893 + const_gimple def_stmt;
90894 + const_tree lhs = gimple_get_lhs(stmt);
90895 + const_tree rhs1 = gimple_assign_rhs1(stmt);
90896 + const_tree rhs1_type = TREE_TYPE(rhs1);
90897 + const_tree lhs_type = TREE_TYPE(lhs);
90898 +
90899 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90900 + return false;
90901 +
90902 + def_stmt = get_def_stmt(rhs1);
90903 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
90904 + return false;
90905 +
90906 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
90907 + return false;
90908 + return true;
90909 +}
90910 +
90911 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
90912 +{
90913 + const_tree rhs1, lhs, rhs1_type, lhs_type;
90914 + enum machine_mode lhs_mode, rhs_mode;
90915 + gimple def_stmt = get_def_stmt(no_const_rhs);
90916 +
90917 + if (!gimple_assign_cast_p(def_stmt))
90918 + return false;
90919 +
90920 + rhs1 = gimple_assign_rhs1(def_stmt);
90921 + lhs = gimple_get_lhs(def_stmt);
90922 + rhs1_type = TREE_TYPE(rhs1);
90923 + lhs_type = TREE_TYPE(lhs);
90924 + rhs_mode = TYPE_MODE(rhs1_type);
90925 + lhs_mode = TYPE_MODE(lhs_type);
90926 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
90927 + return false;
90928 +
90929 + return true;
90930 +}
90931 +
90932 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
90933 +{
90934 + tree rhs1 = gimple_assign_rhs1(stmt);
90935 + tree lhs = gimple_get_lhs(stmt);
90936 + const_tree rhs1_type = TREE_TYPE(rhs1);
90937 + const_tree lhs_type = TREE_TYPE(lhs);
90938 +
90939 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90940 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90941 +
90942 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
90943 +}
90944 +
90945 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
90946 +{
90947 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
90948 + tree new_rhs1 = NULL_TREE;
90949 + tree rhs1 = gimple_assign_rhs1(stmt);
90950 + const_tree rhs1_type = TREE_TYPE(rhs1);
90951 + const_tree lhs_type = TREE_TYPE(lhs);
90952 +
90953 + if (gimple_plf(stmt, MY_STMT))
90954 + return lhs;
90955 +
90956 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
90957 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90958 +
90959 + new_rhs1 = expand(visited, rhs1);
90960 +
90961 + if (new_rhs1 == NULL_TREE)
90962 + return create_cast_assign(visited, stmt);
90963 +
90964 + if (gimple_plf(stmt, NO_CAST_CHECK))
90965 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90966 +
90967 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
90968 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90969 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90970 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90971 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90972 + }
90973 +
90974 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
90975 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90976 +
90977 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
90978 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90979 +
90980 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90981 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90982 +
90983 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90984 +
90985 + change_rhs1(stmt, new_rhs1);
90986 +
90987 + if (!check_mode_type(stmt))
90988 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90989 +
90990 + size_overflow_type = get_size_overflow_type(stmt, lhs);
90991 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90992 +
90993 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
90994 +
90995 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90996 +}
90997 +
90998 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
90999 +{
91000 + tree rhs1, lhs = gimple_get_lhs(stmt);
91001 + gimple def_stmt = get_def_stmt(lhs);
91002 +
91003 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
91004 + rhs1 = gimple_assign_rhs1(def_stmt);
91005 +
91006 + if (is_gimple_constant(rhs1))
91007 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91008 +
91009 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
91010 + switch (TREE_CODE(rhs1)) {
91011 + case SSA_NAME:
91012 + return handle_unary_rhs(visited, def_stmt);
91013 + case ARRAY_REF:
91014 + case BIT_FIELD_REF:
91015 + case ADDR_EXPR:
91016 + case COMPONENT_REF:
91017 + case INDIRECT_REF:
91018 +#if BUILDING_GCC_VERSION >= 4006
91019 + case MEM_REF:
91020 +#endif
91021 + case TARGET_MEM_REF:
91022 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91023 + case PARM_DECL:
91024 + case VAR_DECL:
91025 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91026 +
91027 + default:
91028 + debug_gimple_stmt(def_stmt);
91029 + debug_tree(rhs1);
91030 + gcc_unreachable();
91031 + }
91032 +}
91033 +
91034 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
91035 +{
91036 + gimple cond_stmt;
91037 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
91038 +
91039 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
91040 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
91041 + update_stmt(cond_stmt);
91042 +}
91043 +
91044 +static tree create_string_param(tree string)
91045 +{
91046 + tree i_type, a_type;
91047 + const int length = TREE_STRING_LENGTH(string);
91048 +
91049 + gcc_assert(length > 0);
91050 +
91051 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
91052 + a_type = build_array_type(char_type_node, i_type);
91053 +
91054 + TREE_TYPE(string) = a_type;
91055 + TREE_CONSTANT(string) = 1;
91056 + TREE_READONLY(string) = 1;
91057 +
91058 + return build1(ADDR_EXPR, ptr_type_node, string);
91059 +}
91060 +
91061 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
91062 +{
91063 + gimple func_stmt;
91064 + const_gimple def_stmt;
91065 + const_tree loc_line;
91066 + tree loc_file, ssa_name, current_func;
91067 + expanded_location xloc;
91068 + char *ssa_name_buf;
91069 + int len;
91070 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
91071 +
91072 + def_stmt = get_def_stmt(arg);
91073 + xloc = expand_location(gimple_location(def_stmt));
91074 +
91075 + if (!gimple_has_location(def_stmt)) {
91076 + xloc = expand_location(gimple_location(stmt));
91077 + if (!gimple_has_location(stmt))
91078 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
91079 + }
91080 +
91081 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
91082 +
91083 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
91084 + loc_file = create_string_param(loc_file);
91085 +
91086 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
91087 + current_func = create_string_param(current_func);
91088 +
91089 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
91090 + call_count++;
91091 + 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);
91092 + gcc_assert(len > 0);
91093 + ssa_name = build_string(len + 1, ssa_name_buf);
91094 + free(ssa_name_buf);
91095 + ssa_name = create_string_param(ssa_name);
91096 +
91097 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
91098 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
91099 +
91100 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
91101 +}
91102 +
91103 +static void __unused print_the_code_insertions(const_gimple stmt)
91104 +{
91105 + location_t loc = gimple_location(stmt);
91106 +
91107 + inform(loc, "Integer size_overflow check applied here.");
91108 +}
91109 +
91110 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
91111 +{
91112 + basic_block cond_bb, join_bb, bb_true;
91113 + edge e;
91114 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91115 +
91116 + cond_bb = gimple_bb(stmt);
91117 + if (before)
91118 + gsi_prev(&gsi);
91119 + if (gsi_end_p(gsi))
91120 + e = split_block_after_labels(cond_bb);
91121 + else
91122 + e = split_block(cond_bb, gsi_stmt(gsi));
91123 + cond_bb = e->src;
91124 + join_bb = e->dest;
91125 + e->flags = EDGE_FALSE_VALUE;
91126 + e->probability = REG_BR_PROB_BASE;
91127 +
91128 + bb_true = create_empty_bb(cond_bb);
91129 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
91130 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
91131 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
91132 +
91133 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
91134 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
91135 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
91136 +
91137 + if (current_loops != NULL) {
91138 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
91139 + add_bb_to_loop(bb_true, cond_bb->loop_father);
91140 + }
91141 +
91142 + insert_cond(cond_bb, arg, cond_code, type_value);
91143 + insert_cond_result(bb_true, stmt, arg, min);
91144 +
91145 +// print_the_code_insertions(stmt);
91146 +}
91147 +
91148 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
91149 +{
91150 + const_tree rhs_type = TREE_TYPE(rhs);
91151 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
91152 +
91153 + gcc_assert(rhs_type != NULL_TREE);
91154 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
91155 + return;
91156 +
91157 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
91158 +
91159 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
91160 + // typemax (-1) < typemin (0)
91161 + if (TREE_OVERFLOW(type_max))
91162 + return;
91163 +
91164 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
91165 +
91166 + cast_rhs_type = TREE_TYPE(cast_rhs);
91167 + type_max_type = TREE_TYPE(type_max);
91168 + type_min_type = TREE_TYPE(type_min);
91169 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
91170 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
91171 +
91172 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
91173 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
91174 +}
91175 +
91176 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
91177 +{
91178 + gimple change_rhs_def_stmt;
91179 + tree lhs = gimple_get_lhs(def_stmt);
91180 + tree lhs_type = TREE_TYPE(lhs);
91181 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
91182 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
91183 +
91184 + if (change_rhs == NULL_TREE)
91185 + return get_size_overflow_type(def_stmt, lhs);
91186 +
91187 + change_rhs_def_stmt = get_def_stmt(change_rhs);
91188 +
91189 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
91190 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91191 +
91192 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
91193 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91194 +
91195 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
91196 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91197 +
91198 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
91199 + debug_gimple_stmt(def_stmt);
91200 + gcc_unreachable();
91201 + }
91202 +
91203 + return get_size_overflow_type(def_stmt, lhs);
91204 +}
91205 +
91206 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
91207 +{
91208 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
91209 + return false;
91210 + if (!is_gimple_constant(rhs))
91211 + return false;
91212 + return true;
91213 +}
91214 +
91215 +static bool is_subtraction_special(const_gimple stmt)
91216 +{
91217 + gimple rhs1_def_stmt, rhs2_def_stmt;
91218 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
91219 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
91220 + const_tree rhs1 = gimple_assign_rhs1(stmt);
91221 + const_tree rhs2 = gimple_assign_rhs2(stmt);
91222 +
91223 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
91224 + return false;
91225 +
91226 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
91227 +
91228 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
91229 + return false;
91230 +
91231 + rhs1_def_stmt = get_def_stmt(rhs1);
91232 + rhs2_def_stmt = get_def_stmt(rhs2);
91233 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
91234 + return false;
91235 +
91236 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91237 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
91238 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
91239 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
91240 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
91241 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
91242 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
91243 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
91244 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
91245 + return false;
91246 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
91247 + return false;
91248 +
91249 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
91250 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
91251 + return true;
91252 +}
91253 +
91254 +static tree get_def_stmt_rhs(const_tree var)
91255 +{
91256 + tree rhs1, def_stmt_rhs1;
91257 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
91258 +
91259 + def_stmt = get_def_stmt(var);
91260 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
91261 +
91262 + rhs1 = gimple_assign_rhs1(def_stmt);
91263 + rhs1_def_stmt = get_def_stmt(rhs1);
91264 + if (!gimple_assign_cast_p(rhs1_def_stmt))
91265 + return rhs1;
91266 +
91267 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91268 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
91269 +
91270 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
91271 + case GIMPLE_CALL:
91272 + case GIMPLE_NOP:
91273 + case GIMPLE_ASM:
91274 + return def_stmt_rhs1;
91275 + case GIMPLE_ASSIGN:
91276 + return rhs1;
91277 + default:
91278 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
91279 + gcc_unreachable();
91280 + }
91281 +}
91282 +
91283 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
91284 +{
91285 + tree new_rhs1, new_rhs2;
91286 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
91287 + gimple assign, stmt = get_def_stmt(lhs);
91288 + tree rhs1 = gimple_assign_rhs1(stmt);
91289 + tree rhs2 = gimple_assign_rhs2(stmt);
91290 +
91291 + if (!is_subtraction_special(stmt))
91292 + return NULL_TREE;
91293 +
91294 + new_rhs1 = expand(visited, rhs1);
91295 + new_rhs2 = expand(visited, rhs2);
91296 +
91297 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
91298 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
91299 +
91300 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
91301 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
91302 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
91303 + }
91304 +
91305 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
91306 + new_lhs = gimple_get_lhs(assign);
91307 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
91308 +
91309 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91310 +}
91311 +
91312 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
91313 +{
91314 + const_gimple def_stmt;
91315 +
91316 + if (TREE_CODE(rhs) != SSA_NAME)
91317 + return false;
91318 +
91319 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
91320 + return false;
91321 +
91322 + def_stmt = get_def_stmt(rhs);
91323 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
91324 + return false;
91325 +
91326 + return true;
91327 +}
91328 +
91329 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
91330 +{
91331 + tree new_rhs, size_overflow_type, orig_rhs;
91332 + void (*gimple_assign_set_rhs)(gimple, tree);
91333 + tree rhs1 = gimple_assign_rhs1(stmt);
91334 + tree rhs2 = gimple_assign_rhs2(stmt);
91335 + tree lhs = gimple_get_lhs(stmt);
91336 +
91337 + if (change_rhs == NULL_TREE)
91338 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91339 +
91340 + if (new_rhs2 == NULL_TREE) {
91341 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
91342 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
91343 + orig_rhs = rhs1;
91344 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
91345 + } else {
91346 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
91347 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
91348 + orig_rhs = rhs2;
91349 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
91350 + }
91351 +
91352 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
91353 +
91354 + if (check_overflow)
91355 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
91356 +
91357 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
91358 + gimple_assign_set_rhs(stmt, new_rhs);
91359 + update_stmt(stmt);
91360 +
91361 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91362 +}
91363 +
91364 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
91365 +{
91366 + tree rhs1, rhs2, new_lhs;
91367 + gimple def_stmt = get_def_stmt(lhs);
91368 + tree new_rhs1 = NULL_TREE;
91369 + tree new_rhs2 = NULL_TREE;
91370 +
91371 + rhs1 = gimple_assign_rhs1(def_stmt);
91372 + rhs2 = gimple_assign_rhs2(def_stmt);
91373 +
91374 + /* no DImode/TImode division in the 32/64 bit kernel */
91375 + switch (gimple_assign_rhs_code(def_stmt)) {
91376 + case RDIV_EXPR:
91377 + case TRUNC_DIV_EXPR:
91378 + case CEIL_DIV_EXPR:
91379 + case FLOOR_DIV_EXPR:
91380 + case ROUND_DIV_EXPR:
91381 + case TRUNC_MOD_EXPR:
91382 + case CEIL_MOD_EXPR:
91383 + case FLOOR_MOD_EXPR:
91384 + case ROUND_MOD_EXPR:
91385 + case EXACT_DIV_EXPR:
91386 + case POINTER_PLUS_EXPR:
91387 + case BIT_AND_EXPR:
91388 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91389 + default:
91390 + break;
91391 + }
91392 +
91393 + new_lhs = handle_integer_truncation(visited, lhs);
91394 + if (new_lhs != NULL_TREE)
91395 + return new_lhs;
91396 +
91397 + if (TREE_CODE(rhs1) == SSA_NAME)
91398 + new_rhs1 = expand(visited, rhs1);
91399 + if (TREE_CODE(rhs2) == SSA_NAME)
91400 + new_rhs2 = expand(visited, rhs2);
91401 +
91402 + if (is_a_neg_overflow(def_stmt, rhs2))
91403 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91404 + if (is_a_neg_overflow(def_stmt, rhs1))
91405 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91406 +
91407 + if (is_a_constant_overflow(def_stmt, rhs2))
91408 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91409 + if (is_a_constant_overflow(def_stmt, rhs1))
91410 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91411 +
91412 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91413 +}
91414 +
91415 +#if BUILDING_GCC_VERSION >= 4007
91416 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
91417 +{
91418 + if (is_gimple_constant(rhs))
91419 + return cast_a_tree(size_overflow_type, rhs);
91420 + if (TREE_CODE(rhs) != SSA_NAME)
91421 + return NULL_TREE;
91422 + return expand(visited, rhs);
91423 +}
91424 +
91425 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
91426 +{
91427 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
91428 + gimple def_stmt = get_def_stmt(lhs);
91429 +
91430 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
91431 +
91432 + rhs1 = gimple_assign_rhs1(def_stmt);
91433 + rhs2 = gimple_assign_rhs2(def_stmt);
91434 + rhs3 = gimple_assign_rhs3(def_stmt);
91435 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
91436 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
91437 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
91438 +
91439 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
91440 +}
91441 +#endif
91442 +
91443 +static tree get_size_overflow_type(gimple stmt, const_tree node)
91444 +{
91445 + const_tree type;
91446 + tree new_type;
91447 +
91448 + gcc_assert(node != NULL_TREE);
91449 +
91450 + type = TREE_TYPE(node);
91451 +
91452 + if (gimple_plf(stmt, MY_STMT))
91453 + return TREE_TYPE(node);
91454 +
91455 + switch (TYPE_MODE(type)) {
91456 + case QImode:
91457 + new_type = intHI_type_node;
91458 + break;
91459 + case HImode:
91460 + new_type = intSI_type_node;
91461 + break;
91462 + case SImode:
91463 + new_type = intDI_type_node;
91464 + break;
91465 + case DImode:
91466 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
91467 + new_type = intDI_type_node;
91468 + else
91469 + new_type = intTI_type_node;
91470 + break;
91471 + default:
91472 + debug_tree((tree)node);
91473 + error("%s: unsupported gcc configuration.", __func__);
91474 + gcc_unreachable();
91475 + }
91476 +
91477 + if (TYPE_QUALS(type) != 0)
91478 + return build_qualified_type(new_type, TYPE_QUALS(type));
91479 + return new_type;
91480 +}
91481 +
91482 +static tree expand_visited(gimple def_stmt)
91483 +{
91484 + const_gimple next_stmt;
91485 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
91486 +
91487 + gsi_next(&gsi);
91488 + next_stmt = gsi_stmt(gsi);
91489 +
91490 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
91491 +
91492 + switch (gimple_code(next_stmt)) {
91493 + case GIMPLE_ASSIGN:
91494 + return gimple_get_lhs(next_stmt);
91495 + case GIMPLE_PHI:
91496 + return gimple_phi_result(next_stmt);
91497 + case GIMPLE_CALL:
91498 + return gimple_call_lhs(next_stmt);
91499 + default:
91500 + return NULL_TREE;
91501 + }
91502 +}
91503 +
91504 +static tree expand(struct pointer_set_t *visited, tree lhs)
91505 +{
91506 + gimple def_stmt;
91507 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
91508 +
91509 + if (is_gimple_constant(lhs))
91510 + return NULL_TREE;
91511 +
91512 + if (TREE_CODE(lhs) == ADDR_EXPR)
91513 + return NULL_TREE;
91514 +
91515 + if (code == REAL_TYPE)
91516 + return NULL_TREE;
91517 +
91518 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
91519 +
91520 + def_stmt = get_def_stmt(lhs);
91521 +
91522 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
91523 + return NULL_TREE;
91524 +
91525 + if (gimple_plf(def_stmt, MY_STMT))
91526 + return lhs;
91527 +
91528 + if (pointer_set_contains(visited, def_stmt))
91529 + return expand_visited(def_stmt);
91530 +
91531 + switch (gimple_code(def_stmt)) {
91532 + case GIMPLE_PHI:
91533 + return build_new_phi(visited, lhs);
91534 + case GIMPLE_CALL:
91535 + case GIMPLE_ASM:
91536 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91537 + case GIMPLE_ASSIGN:
91538 + switch (gimple_num_ops(def_stmt)) {
91539 + case 2:
91540 + return handle_unary_ops(visited, def_stmt);
91541 + case 3:
91542 + return handle_binary_ops(visited, lhs);
91543 +#if BUILDING_GCC_VERSION >= 4007
91544 + case 4:
91545 + return handle_ternary_ops(visited, lhs);
91546 +#endif
91547 + }
91548 + default:
91549 + debug_gimple_stmt(def_stmt);
91550 + error("%s: unknown gimple code", __func__);
91551 + gcc_unreachable();
91552 + }
91553 +}
91554 +
91555 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
91556 +{
91557 + const_gimple assign;
91558 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91559 + tree origtype = TREE_TYPE(origarg);
91560 +
91561 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
91562 +
91563 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91564 +
91565 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
91566 + update_stmt(stmt);
91567 +}
91568 +
91569 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
91570 +{
91571 + const char *origid;
91572 + tree arg;
91573 + const_tree origarg;
91574 +
91575 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
91576 + return true;
91577 +
91578 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
91579 + while (origarg && *argnum) {
91580 + (*argnum)--;
91581 + origarg = TREE_CHAIN(origarg);
91582 + }
91583 +
91584 + gcc_assert(*argnum == 0);
91585 +
91586 + gcc_assert(origarg != NULL_TREE);
91587 + origid = NAME(origarg);
91588 + *argnum = 0;
91589 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
91590 + if (!strcmp(origid, NAME(arg)))
91591 + return true;
91592 + (*argnum)++;
91593 + }
91594 + return false;
91595 +}
91596 +
91597 +static bool skip_types(const_tree var)
91598 +{
91599 + const_tree type;
91600 +
91601 + switch (TREE_CODE(var)) {
91602 + case ADDR_EXPR:
91603 +#if BUILDING_GCC_VERSION >= 4006
91604 + case MEM_REF:
91605 +#endif
91606 + case ARRAY_REF:
91607 + case BIT_FIELD_REF:
91608 + case INDIRECT_REF:
91609 + case TARGET_MEM_REF:
91610 + case VAR_DECL:
91611 + return true;
91612 + default:
91613 + break;
91614 + }
91615 +
91616 + type = TREE_TYPE(TREE_TYPE(var));
91617 + if (!type)
91618 + return false;
91619 + switch (TREE_CODE(type)) {
91620 + case RECORD_TYPE:
91621 + return true;
91622 + default:
91623 + break;
91624 + }
91625 +
91626 + return false;
91627 +}
91628 +
91629 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
91630 +{
91631 + gimple phi = get_def_stmt(result);
91632 + unsigned int i, n = gimple_phi_num_args(phi);
91633 +
91634 + if (!phi)
91635 + return false;
91636 +
91637 + pointer_set_insert(visited, phi);
91638 + for (i = 0; i < n; i++) {
91639 + const_tree arg = gimple_phi_arg_def(phi, i);
91640 + if (pre_expand(visited, arg))
91641 + return true;
91642 + }
91643 + return false;
91644 +}
91645 +
91646 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
91647 +{
91648 + gimple def_stmt = get_def_stmt(lhs);
91649 + const_tree rhs;
91650 +
91651 + if (!def_stmt)
91652 + return false;
91653 +
91654 + rhs = gimple_assign_rhs1(def_stmt);
91655 + if (pre_expand(visited, rhs))
91656 + return true;
91657 + return false;
91658 +}
91659 +
91660 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
91661 +{
91662 + bool rhs1_found, rhs2_found;
91663 + gimple def_stmt = get_def_stmt(lhs);
91664 + const_tree rhs1, rhs2;
91665 +
91666 + if (!def_stmt)
91667 + return false;
91668 +
91669 + rhs1 = gimple_assign_rhs1(def_stmt);
91670 + rhs2 = gimple_assign_rhs2(def_stmt);
91671 + rhs1_found = pre_expand(visited, rhs1);
91672 + rhs2_found = pre_expand(visited, rhs2);
91673 +
91674 + return rhs1_found || rhs2_found;
91675 +}
91676 +
91677 +static const_tree search_field_decl(const_tree comp_ref)
91678 +{
91679 + const_tree field = NULL_TREE;
91680 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
91681 +
91682 + for (i = 0; i < len; i++) {
91683 + field = TREE_OPERAND(comp_ref, i);
91684 + if (TREE_CODE(field) == FIELD_DECL)
91685 + break;
91686 + }
91687 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
91688 + return field;
91689 +}
91690 +
91691 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
91692 +{
91693 + const_tree attr, p;
91694 +
91695 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
91696 + if (!attr || !TREE_VALUE(attr))
91697 + return MARKED_NO;
91698 +
91699 + p = TREE_VALUE(attr);
91700 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
91701 + return MARKED_NOT_INTENTIONAL;
91702 +
91703 + do {
91704 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
91705 + return MARKED_YES;
91706 + p = TREE_CHAIN(p);
91707 + } while (p);
91708 +
91709 + return MARKED_NO;
91710 +}
91711 +
91712 +static void print_missing_msg(tree func, unsigned int argnum)
91713 +{
91714 + unsigned int new_hash;
91715 + size_t len;
91716 + unsigned char tree_codes[CODES_LIMIT];
91717 + location_t loc = DECL_SOURCE_LOCATION(func);
91718 + const char *curfunc = get_asm_name(func);
91719 +
91720 + len = get_function_decl(func, tree_codes);
91721 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
91722 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
91723 +}
91724 +
91725 +static unsigned int search_missing_attribute(const_tree arg)
91726 +{
91727 + const_tree type = TREE_TYPE(arg);
91728 + tree func = get_original_function_decl(current_function_decl);
91729 + unsigned int argnum;
91730 + const struct size_overflow_hash *hash;
91731 +
91732 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
91733 +
91734 + if (TREE_CODE(type) == POINTER_TYPE)
91735 + return 0;
91736 +
91737 + argnum = find_arg_number(arg, func);
91738 + if (argnum == 0)
91739 + return 0;
91740 +
91741 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
91742 + return argnum;
91743 +
91744 + hash = get_function_hash(func);
91745 + if (!hash || !(hash->param & (1U << argnum))) {
91746 + print_missing_msg(func, argnum);
91747 + return 0;
91748 + }
91749 + return argnum;
91750 +}
91751 +
91752 +static bool is_already_marked(const_tree lhs)
91753 +{
91754 + unsigned int argnum;
91755 + const_tree fndecl;
91756 +
91757 + argnum = search_missing_attribute(lhs);
91758 + fndecl = get_original_function_decl(current_function_decl);
91759 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
91760 + return true;
91761 + return false;
91762 +}
91763 +
91764 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
91765 +{
91766 + const_gimple def_stmt;
91767 +
91768 + if (is_gimple_constant(lhs))
91769 + return false;
91770 +
91771 + if (skip_types(lhs))
91772 + return false;
91773 +
91774 + // skip char type (FIXME: only kernel)
91775 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
91776 + return false;
91777 +
91778 + if (TREE_CODE(lhs) == PARM_DECL)
91779 + return is_already_marked(lhs);
91780 +
91781 + if (TREE_CODE(lhs) == COMPONENT_REF) {
91782 + const_tree field, attr;
91783 +
91784 + field = search_field_decl(lhs);
91785 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
91786 + if (!attr || !TREE_VALUE(attr))
91787 + return false;
91788 + return true;
91789 + }
91790 +
91791 + def_stmt = get_def_stmt(lhs);
91792 +
91793 + if (!def_stmt)
91794 + return false;
91795 +
91796 + if (pointer_set_contains(visited, def_stmt))
91797 + return false;
91798 +
91799 + switch (gimple_code(def_stmt)) {
91800 + case GIMPLE_NOP:
91801 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
91802 + return is_already_marked(lhs);
91803 + return false;
91804 + case GIMPLE_PHI:
91805 + return walk_phi(visited, lhs);
91806 + case GIMPLE_CALL:
91807 + case GIMPLE_ASM:
91808 + return false;
91809 + case GIMPLE_ASSIGN:
91810 + switch (gimple_num_ops(def_stmt)) {
91811 + case 2:
91812 + return walk_unary_ops(visited, lhs);
91813 + case 3:
91814 + return walk_binary_ops(visited, lhs);
91815 + }
91816 + default:
91817 + debug_gimple_stmt((gimple)def_stmt);
91818 + error("%s: unknown gimple code", __func__);
91819 + gcc_unreachable();
91820 + }
91821 +}
91822 +
91823 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
91824 +{
91825 + struct pointer_set_t *visited;
91826 + bool is_found;
91827 + enum marked is_marked;
91828 + location_t loc;
91829 +
91830 + visited = pointer_set_create();
91831 + is_found = pre_expand(visited, arg);
91832 + pointer_set_destroy(visited);
91833 +
91834 + is_marked = mark_status(fndecl, argnum + 1);
91835 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
91836 + return true;
91837 +
91838 + if (is_found) {
91839 + loc = DECL_SOURCE_LOCATION(fndecl);
91840 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
91841 + return true;
91842 + }
91843 + return false;
91844 +}
91845 +
91846 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
91847 +{
91848 + struct pointer_set_t *visited;
91849 + tree arg, newarg;
91850 + bool match;
91851 +
91852 + match = get_function_arg(&argnum, fndecl);
91853 + if (!match)
91854 + return;
91855 + gcc_assert(gimple_call_num_args(stmt) > argnum);
91856 + arg = gimple_call_arg(stmt, argnum);
91857 + if (arg == NULL_TREE)
91858 + return;
91859 +
91860 + if (is_gimple_constant(arg))
91861 + return;
91862 +
91863 + if (search_attributes(fndecl, arg, argnum))
91864 + return;
91865 +
91866 + if (TREE_CODE(arg) != SSA_NAME)
91867 + return;
91868 +
91869 + check_arg_type(arg);
91870 +
91871 + visited = pointer_set_create();
91872 + newarg = expand(visited, arg);
91873 + pointer_set_destroy(visited);
91874 +
91875 + if (newarg == NULL_TREE)
91876 + return;
91877 +
91878 + change_function_arg(stmt, arg, argnum, newarg);
91879 +
91880 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
91881 +}
91882 +
91883 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
91884 +{
91885 + tree p = TREE_VALUE(attr);
91886 + do {
91887 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
91888 + p = TREE_CHAIN(p);
91889 + } while (p);
91890 +}
91891 +
91892 +static void handle_function_by_hash(gimple stmt, tree fndecl)
91893 +{
91894 + tree orig_fndecl;
91895 + unsigned int num;
91896 + const struct size_overflow_hash *hash;
91897 +
91898 + orig_fndecl = get_original_function_decl(fndecl);
91899 + if (C_DECL_IMPLICIT(orig_fndecl))
91900 + return;
91901 + hash = get_function_hash(orig_fndecl);
91902 + if (!hash)
91903 + return;
91904 +
91905 + for (num = 1; num <= MAX_PARAM; num++)
91906 + if (hash->param & (1U << num))
91907 + handle_function_arg(stmt, fndecl, num - 1);
91908 +}
91909 +
91910 +static void set_plf_false(void)
91911 +{
91912 + basic_block bb;
91913 +
91914 + FOR_ALL_BB(bb) {
91915 + gimple_stmt_iterator si;
91916 +
91917 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
91918 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91919 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
91920 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91921 + }
91922 +}
91923 +
91924 +static unsigned int handle_function(void)
91925 +{
91926 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
91927 +
91928 + set_plf_false();
91929 +
91930 + do {
91931 + gimple_stmt_iterator gsi;
91932 + next = bb->next_bb;
91933 +
91934 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
91935 + tree fndecl, attr;
91936 + gimple stmt = gsi_stmt(gsi);
91937 +
91938 + if (!(is_gimple_call(stmt)))
91939 + continue;
91940 + fndecl = gimple_call_fndecl(stmt);
91941 + if (fndecl == NULL_TREE)
91942 + continue;
91943 + if (gimple_call_num_args(stmt) == 0)
91944 + continue;
91945 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
91946 + if (!attr || !TREE_VALUE(attr))
91947 + handle_function_by_hash(stmt, fndecl);
91948 + else
91949 + handle_function_by_attribute(stmt, attr, fndecl);
91950 + gsi = gsi_for_stmt(stmt);
91951 + next = gimple_bb(stmt)->next_bb;
91952 + }
91953 + bb = next;
91954 + } while (bb);
91955 + return 0;
91956 +}
91957 +
91958 +static struct gimple_opt_pass size_overflow_pass = {
91959 + .pass = {
91960 + .type = GIMPLE_PASS,
91961 + .name = "size_overflow",
91962 + .gate = NULL,
91963 + .execute = handle_function,
91964 + .sub = NULL,
91965 + .next = NULL,
91966 + .static_pass_number = 0,
91967 + .tv_id = TV_NONE,
91968 + .properties_required = PROP_cfg | PROP_referenced_vars,
91969 + .properties_provided = 0,
91970 + .properties_destroyed = 0,
91971 + .todo_flags_start = 0,
91972 + .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
91973 + }
91974 +};
91975 +
91976 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
91977 +{
91978 + tree fntype;
91979 +
91980 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
91981 +
91982 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
91983 + fntype = build_function_type_list(void_type_node,
91984 + const_char_ptr_type_node,
91985 + unsigned_type_node,
91986 + const_char_ptr_type_node,
91987 + const_char_ptr_type_node,
91988 + NULL_TREE);
91989 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
91990 +
91991 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
91992 + TREE_PUBLIC(report_size_overflow_decl) = 1;
91993 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
91994 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
91995 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
91996 +}
91997 +
91998 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91999 +{
92000 + int i;
92001 + const char * const plugin_name = plugin_info->base_name;
92002 + const int argc = plugin_info->argc;
92003 + const struct plugin_argument * const argv = plugin_info->argv;
92004 + bool enable = true;
92005 +
92006 + struct register_pass_info size_overflow_pass_info = {
92007 + .pass = &size_overflow_pass.pass,
92008 + .reference_pass_name = "ssa",
92009 + .ref_pass_instance_number = 1,
92010 + .pos_op = PASS_POS_INSERT_AFTER
92011 + };
92012 +
92013 + if (!plugin_default_version_check(version, &gcc_version)) {
92014 + error(G_("incompatible gcc/plugin versions"));
92015 + return 1;
92016 + }
92017 +
92018 + for (i = 0; i < argc; ++i) {
92019 + if (!strcmp(argv[i].key, "no-size-overflow")) {
92020 + enable = false;
92021 + continue;
92022 + }
92023 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92024 + }
92025 +
92026 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
92027 + if (enable) {
92028 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
92029 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
92030 + }
92031 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
92032 +
92033 + return 0;
92034 +}
92035 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
92036 new file mode 100644
92037 index 0000000..38d2014
92038 --- /dev/null
92039 +++ b/tools/gcc/stackleak_plugin.c
92040 @@ -0,0 +1,313 @@
92041 +/*
92042 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
92043 + * Licensed under the GPL v2
92044 + *
92045 + * Note: the choice of the license means that the compilation process is
92046 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92047 + * but for the kernel it doesn't matter since it doesn't link against
92048 + * any of the gcc libraries
92049 + *
92050 + * gcc plugin to help implement various PaX features
92051 + *
92052 + * - track lowest stack pointer
92053 + *
92054 + * TODO:
92055 + * - initialize all local variables
92056 + *
92057 + * BUGS:
92058 + * - none known
92059 + */
92060 +#include "gcc-plugin.h"
92061 +#include "config.h"
92062 +#include "system.h"
92063 +#include "coretypes.h"
92064 +#include "tree.h"
92065 +#include "tree-pass.h"
92066 +#include "flags.h"
92067 +#include "intl.h"
92068 +#include "toplev.h"
92069 +#include "plugin.h"
92070 +//#include "expr.h" where are you...
92071 +#include "diagnostic.h"
92072 +#include "plugin-version.h"
92073 +#include "tm.h"
92074 +#include "function.h"
92075 +#include "basic-block.h"
92076 +#include "gimple.h"
92077 +#include "rtl.h"
92078 +#include "emit-rtl.h"
92079 +
92080 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92081 +
92082 +int plugin_is_GPL_compatible;
92083 +
92084 +static int track_frame_size = -1;
92085 +static const char track_function[] = "pax_track_stack";
92086 +static const char check_function[] = "pax_check_alloca";
92087 +static bool init_locals;
92088 +
92089 +static struct plugin_info stackleak_plugin_info = {
92090 + .version = "201203140940",
92091 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
92092 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
92093 +};
92094 +
92095 +static bool gate_stackleak_track_stack(void);
92096 +static unsigned int execute_stackleak_tree_instrument(void);
92097 +static unsigned int execute_stackleak_final(void);
92098 +
92099 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
92100 + .pass = {
92101 + .type = GIMPLE_PASS,
92102 + .name = "stackleak_tree_instrument",
92103 + .gate = gate_stackleak_track_stack,
92104 + .execute = execute_stackleak_tree_instrument,
92105 + .sub = NULL,
92106 + .next = NULL,
92107 + .static_pass_number = 0,
92108 + .tv_id = TV_NONE,
92109 + .properties_required = PROP_gimple_leh | PROP_cfg,
92110 + .properties_provided = 0,
92111 + .properties_destroyed = 0,
92112 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
92113 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
92114 + }
92115 +};
92116 +
92117 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
92118 + .pass = {
92119 + .type = RTL_PASS,
92120 + .name = "stackleak_final",
92121 + .gate = gate_stackleak_track_stack,
92122 + .execute = execute_stackleak_final,
92123 + .sub = NULL,
92124 + .next = NULL,
92125 + .static_pass_number = 0,
92126 + .tv_id = TV_NONE,
92127 + .properties_required = 0,
92128 + .properties_provided = 0,
92129 + .properties_destroyed = 0,
92130 + .todo_flags_start = 0,
92131 + .todo_flags_finish = TODO_dump_func
92132 + }
92133 +};
92134 +
92135 +static bool gate_stackleak_track_stack(void)
92136 +{
92137 + return track_frame_size >= 0;
92138 +}
92139 +
92140 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
92141 +{
92142 + gimple check_alloca;
92143 + tree fntype, fndecl, alloca_size;
92144 +
92145 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
92146 + fndecl = build_fn_decl(check_function, fntype);
92147 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92148 +
92149 + // insert call to void pax_check_alloca(unsigned long size)
92150 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
92151 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
92152 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
92153 +}
92154 +
92155 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
92156 +{
92157 + gimple track_stack;
92158 + tree fntype, fndecl;
92159 +
92160 + fntype = build_function_type_list(void_type_node, NULL_TREE);
92161 + fndecl = build_fn_decl(track_function, fntype);
92162 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92163 +
92164 + // insert call to void pax_track_stack(void)
92165 + track_stack = gimple_build_call(fndecl, 0);
92166 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
92167 +}
92168 +
92169 +#if BUILDING_GCC_VERSION == 4005
92170 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
92171 +{
92172 + tree fndecl;
92173 +
92174 + if (!is_gimple_call(stmt))
92175 + return false;
92176 + fndecl = gimple_call_fndecl(stmt);
92177 + if (!fndecl)
92178 + return false;
92179 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
92180 + return false;
92181 +// print_node(stderr, "pax", fndecl, 4);
92182 + return DECL_FUNCTION_CODE(fndecl) == code;
92183 +}
92184 +#endif
92185 +
92186 +static bool is_alloca(gimple stmt)
92187 +{
92188 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
92189 + return true;
92190 +
92191 +#if BUILDING_GCC_VERSION >= 4007
92192 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
92193 + return true;
92194 +#endif
92195 +
92196 + return false;
92197 +}
92198 +
92199 +static unsigned int execute_stackleak_tree_instrument(void)
92200 +{
92201 + basic_block bb, entry_bb;
92202 + bool prologue_instrumented = false, is_leaf = true;
92203 +
92204 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
92205 +
92206 + // 1. loop through BBs and GIMPLE statements
92207 + FOR_EACH_BB(bb) {
92208 + gimple_stmt_iterator gsi;
92209 +
92210 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92211 + gimple stmt;
92212 +
92213 + stmt = gsi_stmt(gsi);
92214 +
92215 + if (is_gimple_call(stmt))
92216 + is_leaf = false;
92217 +
92218 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
92219 + if (!is_alloca(stmt))
92220 + continue;
92221 +
92222 + // 2. insert stack overflow check before each __builtin_alloca call
92223 + stackleak_check_alloca(&gsi);
92224 +
92225 + // 3. insert track call after each __builtin_alloca call
92226 + stackleak_add_instrumentation(&gsi);
92227 + if (bb == entry_bb)
92228 + prologue_instrumented = true;
92229 + }
92230 + }
92231 +
92232 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
92233 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
92234 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
92235 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
92236 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
92237 + return 0;
92238 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
92239 + return 0;
92240 +
92241 + // 4. insert track call at the beginning
92242 + if (!prologue_instrumented) {
92243 + gimple_stmt_iterator gsi;
92244 +
92245 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
92246 + if (dom_info_available_p(CDI_DOMINATORS))
92247 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
92248 + gsi = gsi_start_bb(bb);
92249 + stackleak_add_instrumentation(&gsi);
92250 + }
92251 +
92252 + return 0;
92253 +}
92254 +
92255 +static unsigned int execute_stackleak_final(void)
92256 +{
92257 + rtx insn;
92258 +
92259 + if (cfun->calls_alloca)
92260 + return 0;
92261 +
92262 + // keep calls only if function frame is big enough
92263 + if (get_frame_size() >= track_frame_size)
92264 + return 0;
92265 +
92266 + // 1. find pax_track_stack calls
92267 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
92268 + // 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))
92269 + rtx body;
92270 +
92271 + if (!CALL_P(insn))
92272 + continue;
92273 + body = PATTERN(insn);
92274 + if (GET_CODE(body) != CALL)
92275 + continue;
92276 + body = XEXP(body, 0);
92277 + if (GET_CODE(body) != MEM)
92278 + continue;
92279 + body = XEXP(body, 0);
92280 + if (GET_CODE(body) != SYMBOL_REF)
92281 + continue;
92282 + if (strcmp(XSTR(body, 0), track_function))
92283 + continue;
92284 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92285 + // 2. delete call
92286 + insn = delete_insn_and_edges(insn);
92287 +#if BUILDING_GCC_VERSION >= 4007
92288 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
92289 + insn = delete_insn_and_edges(insn);
92290 +#endif
92291 + }
92292 +
92293 +// print_simple_rtl(stderr, get_insns());
92294 +// print_rtl(stderr, get_insns());
92295 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92296 +
92297 + return 0;
92298 +}
92299 +
92300 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92301 +{
92302 + const char * const plugin_name = plugin_info->base_name;
92303 + const int argc = plugin_info->argc;
92304 + const struct plugin_argument * const argv = plugin_info->argv;
92305 + int i;
92306 + struct register_pass_info stackleak_tree_instrument_pass_info = {
92307 + .pass = &stackleak_tree_instrument_pass.pass,
92308 +// .reference_pass_name = "tree_profile",
92309 + .reference_pass_name = "optimized",
92310 + .ref_pass_instance_number = 1,
92311 + .pos_op = PASS_POS_INSERT_BEFORE
92312 + };
92313 + struct register_pass_info stackleak_final_pass_info = {
92314 + .pass = &stackleak_final_rtl_opt_pass.pass,
92315 + .reference_pass_name = "final",
92316 + .ref_pass_instance_number = 1,
92317 + .pos_op = PASS_POS_INSERT_BEFORE
92318 + };
92319 +
92320 + if (!plugin_default_version_check(version, &gcc_version)) {
92321 + error(G_("incompatible gcc/plugin versions"));
92322 + return 1;
92323 + }
92324 +
92325 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
92326 +
92327 + for (i = 0; i < argc; ++i) {
92328 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
92329 + if (!argv[i].value) {
92330 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92331 + continue;
92332 + }
92333 + track_frame_size = atoi(argv[i].value);
92334 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
92335 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92336 + continue;
92337 + }
92338 + if (!strcmp(argv[i].key, "initialize-locals")) {
92339 + if (argv[i].value) {
92340 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92341 + continue;
92342 + }
92343 + init_locals = true;
92344 + continue;
92345 + }
92346 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92347 + }
92348 +
92349 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
92350 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
92351 +
92352 + return 0;
92353 +}
92354 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
92355 index 6789d78..4afd019e 100644
92356 --- a/tools/perf/util/include/asm/alternative-asm.h
92357 +++ b/tools/perf/util/include/asm/alternative-asm.h
92358 @@ -5,4 +5,7 @@
92359
92360 #define altinstruction_entry #
92361
92362 + .macro pax_force_retaddr rip=0, reload=0
92363 + .endm
92364 +
92365 #endif
92366 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
92367 index 6e8fa7e..37f02a5 100644
92368 --- a/virt/kvm/kvm_main.c
92369 +++ b/virt/kvm/kvm_main.c
92370 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
92371
92372 static cpumask_var_t cpus_hardware_enabled;
92373 static int kvm_usage_count = 0;
92374 -static atomic_t hardware_enable_failed;
92375 +static atomic_unchecked_t hardware_enable_failed;
92376
92377 struct kmem_cache *kvm_vcpu_cache;
92378 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
92379
92380 -static __read_mostly struct preempt_ops kvm_preempt_ops;
92381 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
92382 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
92383 +static struct preempt_ops kvm_preempt_ops = {
92384 + .sched_in = kvm_sched_in,
92385 + .sched_out = kvm_sched_out,
92386 +};
92387
92388 struct dentry *kvm_debugfs_dir;
92389
92390 @@ -726,7 +731,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
92391 /* We can read the guest memory with __xxx_user() later on. */
92392 if (user_alloc &&
92393 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
92394 - !access_ok(VERIFY_WRITE,
92395 + !__access_ok(VERIFY_WRITE,
92396 (void __user *)(unsigned long)mem->userspace_addr,
92397 mem->memory_size)))
92398 goto out;
92399 @@ -2450,7 +2455,7 @@ static void hardware_enable_nolock(void *junk)
92400
92401 if (r) {
92402 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
92403 - atomic_inc(&hardware_enable_failed);
92404 + atomic_inc_unchecked(&hardware_enable_failed);
92405 printk(KERN_INFO "kvm: enabling virtualization on "
92406 "CPU%d failed\n", cpu);
92407 }
92408 @@ -2504,10 +2509,10 @@ static int hardware_enable_all(void)
92409
92410 kvm_usage_count++;
92411 if (kvm_usage_count == 1) {
92412 - atomic_set(&hardware_enable_failed, 0);
92413 + atomic_set_unchecked(&hardware_enable_failed, 0);
92414 on_each_cpu(hardware_enable_nolock, NULL, 1);
92415
92416 - if (atomic_read(&hardware_enable_failed)) {
92417 + if (atomic_read_unchecked(&hardware_enable_failed)) {
92418 hardware_disable_all_nolock();
92419 r = -EBUSY;
92420 }
92421 @@ -2865,7 +2870,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
92422 kvm_arch_vcpu_put(vcpu);
92423 }
92424
92425 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92426 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92427 struct module *module)
92428 {
92429 int r;
92430 @@ -2901,7 +2906,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92431 if (!vcpu_align)
92432 vcpu_align = __alignof__(struct kvm_vcpu);
92433 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
92434 - 0, NULL);
92435 + SLAB_USERCOPY, NULL);
92436 if (!kvm_vcpu_cache) {
92437 r = -ENOMEM;
92438 goto out_free_3;
92439 @@ -2911,9 +2916,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92440 if (r)
92441 goto out_free;
92442
92443 - kvm_chardev_ops.owner = module;
92444 - kvm_vm_fops.owner = module;
92445 - kvm_vcpu_fops.owner = module;
92446 + pax_open_kernel();
92447 + *(void **)&kvm_chardev_ops.owner = module;
92448 + *(void **)&kvm_vm_fops.owner = module;
92449 + *(void **)&kvm_vcpu_fops.owner = module;
92450 + pax_close_kernel();
92451
92452 r = misc_register(&kvm_dev);
92453 if (r) {
92454 @@ -2923,9 +2930,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92455
92456 register_syscore_ops(&kvm_syscore_ops);
92457
92458 - kvm_preempt_ops.sched_in = kvm_sched_in;
92459 - kvm_preempt_ops.sched_out = kvm_sched_out;
92460 -
92461 r = kvm_init_debug();
92462 if (r) {
92463 printk(KERN_ERR "kvm: create debugfs files failed\n");