]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.3-201301181518.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.3-201301181518.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 51a9bda..3097345 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..65de923 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1304,7 +1304,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589 - if (!vma || addr + len <= vma->vm_start)
590 + if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594 @@ -1340,6 +1340,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598 +#ifdef CONFIG_PAX_RANDMMAP
599 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600 +#endif
601 +
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605 @@ -1347,8 +1351,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610 - len, limit);
611 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612 +
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617 index 0c4132d..88f0d53 100644
618 --- a/arch/alpha/mm/fault.c
619 +++ b/arch/alpha/mm/fault.c
620 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624 +#ifdef CONFIG_PAX_PAGEEXEC
625 +/*
626 + * PaX: decide what to do with offenders (regs->pc = fault address)
627 + *
628 + * returns 1 when task should be killed
629 + * 2 when patched PLT trampoline was detected
630 + * 3 when unpatched PLT trampoline was detected
631 + */
632 +static int pax_handle_fetch_fault(struct pt_regs *regs)
633 +{
634 +
635 +#ifdef CONFIG_PAX_EMUPLT
636 + int err;
637 +
638 + do { /* PaX: patched PLT emulation #1 */
639 + unsigned int ldah, ldq, jmp;
640 +
641 + err = get_user(ldah, (unsigned int *)regs->pc);
642 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644 +
645 + if (err)
646 + break;
647 +
648 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650 + jmp == 0x6BFB0000U)
651 + {
652 + unsigned long r27, addr;
653 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655 +
656 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657 + err = get_user(r27, (unsigned long *)addr);
658 + if (err)
659 + break;
660 +
661 + regs->r27 = r27;
662 + regs->pc = r27;
663 + return 2;
664 + }
665 + } while (0);
666 +
667 + do { /* PaX: patched PLT emulation #2 */
668 + unsigned int ldah, lda, br;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
672 + err |= get_user(br, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
679 + (br & 0xFFE00000U) == 0xC3E00000U)
680 + {
681 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684 +
685 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: unpatched PLT emulation */
692 + unsigned int br;
693 +
694 + err = get_user(br, (unsigned int *)regs->pc);
695 +
696 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697 + unsigned int br2, ldq, nop, jmp;
698 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699 +
700 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701 + err = get_user(br2, (unsigned int *)addr);
702 + err |= get_user(ldq, (unsigned int *)(addr+4));
703 + err |= get_user(nop, (unsigned int *)(addr+8));
704 + err |= get_user(jmp, (unsigned int *)(addr+12));
705 + err |= get_user(resolver, (unsigned long *)(addr+16));
706 +
707 + if (err)
708 + break;
709 +
710 + if (br2 == 0xC3600000U &&
711 + ldq == 0xA77B000CU &&
712 + nop == 0x47FF041FU &&
713 + jmp == 0x6B7B0000U)
714 + {
715 + regs->r28 = regs->pc+4;
716 + regs->r27 = addr+16;
717 + regs->pc = resolver;
718 + return 3;
719 + }
720 + }
721 + } while (0);
722 +#endif
723 +
724 + return 1;
725 +}
726 +
727 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728 +{
729 + unsigned long i;
730 +
731 + printk(KERN_ERR "PAX: bytes at PC: ");
732 + for (i = 0; i < 5; i++) {
733 + unsigned int c;
734 + if (get_user(c, (unsigned int *)pc+i))
735 + printk(KERN_CONT "???????? ");
736 + else
737 + printk(KERN_CONT "%08x ", c);
738 + }
739 + printk("\n");
740 +}
741 +#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745 @@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749 - if (!(vma->vm_flags & VM_EXEC))
750 + if (!(vma->vm_flags & VM_EXEC)) {
751 +
752 +#ifdef CONFIG_PAX_PAGEEXEC
753 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754 + goto bad_area;
755 +
756 + up_read(&mm->mmap_sem);
757 + switch (pax_handle_fetch_fault(regs)) {
758 +
759 +#ifdef CONFIG_PAX_EMUPLT
760 + case 2:
761 + case 3:
762 + return;
763 +#endif
764 +
765 + }
766 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767 + do_group_exit(SIGKILL);
768 +#else
769 goto bad_area;
770 +#endif
771 +
772 + }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777 index c79f61f..9ac0642 100644
778 --- a/arch/arm/include/asm/atomic.h
779 +++ b/arch/arm/include/asm/atomic.h
780 @@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784 +#ifdef CONFIG_GENERIC_ATOMIC64
785 +#include <asm-generic/atomic64.h>
786 +#endif
787 +
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792 +#define _ASM_EXTABLE(from, to) \
793 +" .pushsection __ex_table,\"a\"\n"\
794 +" .align 3\n" \
795 +" .long " #from ", " #to"\n" \
796 +" .popsection"
797 +
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805 +{
806 + return v->counter;
807 +}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810 +{
811 + v->counter = i;
812 +}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820 +"1: ldrex %1, [%3]\n"
821 +" adds %0, %1, %4\n"
822 +
823 +#ifdef CONFIG_PAX_REFCOUNT
824 +" bvc 3f\n"
825 +"2: bkpt 0xf103\n"
826 +"3:\n"
827 +#endif
828 +
829 +" strex %1, %0, [%3]\n"
830 +" teq %1, #0\n"
831 +" bne 1b"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +"\n4:\n"
835 + _ASM_EXTABLE(2b, 4b)
836 +#endif
837 +
838 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839 + : "r" (&v->counter), "Ir" (i)
840 + : "cc");
841 +}
842 +
843 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856 +"1: ldrex %1, [%3]\n"
857 +" adds %0, %1, %4\n"
858 +
859 +#ifdef CONFIG_PAX_REFCOUNT
860 +" bvc 3f\n"
861 +" mov %0, %1\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +
879 + smp_mb();
880 +
881 + return result;
882 +}
883 +
884 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885 +{
886 + unsigned long tmp;
887 + int result;
888 +
889 + smp_mb();
890 +
891 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899 +"1: ldrex %1, [%3]\n"
900 +" subs %0, %1, %4\n"
901 +
902 +#ifdef CONFIG_PAX_REFCOUNT
903 +" bvc 3f\n"
904 +"2: bkpt 0xf103\n"
905 +"3:\n"
906 +#endif
907 +
908 +" strex %1, %0, [%3]\n"
909 +" teq %1, #0\n"
910 +" bne 1b"
911 +
912 +#ifdef CONFIG_PAX_REFCOUNT
913 +"\n4:\n"
914 + _ASM_EXTABLE(2b, 4b)
915 +#endif
916 +
917 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918 + : "r" (&v->counter), "Ir" (i)
919 + : "cc");
920 +}
921 +
922 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923 +{
924 + unsigned long tmp;
925 + int result;
926 +
927 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935 -"1: ldrex %0, [%3]\n"
936 -" sub %0, %0, %4\n"
937 +"1: ldrex %1, [%3]\n"
938 +" subs %0, %1, %4\n"
939 +
940 +#ifdef CONFIG_PAX_REFCOUNT
941 +" bvc 3f\n"
942 +" mov %0, %1\n"
943 +"2: bkpt 0xf103\n"
944 +"3:\n"
945 +#endif
946 +
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950 +
951 +#ifdef CONFIG_PAX_REFCOUNT
952 +"\n4:\n"
953 + _ASM_EXTABLE(2b, 4b)
954 +#endif
955 +
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964 +{
965 + unsigned long oldval, res;
966 +
967 + smp_mb();
968 +
969 + do {
970 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971 + "ldrex %1, [%3]\n"
972 + "mov %0, #0\n"
973 + "teq %1, %4\n"
974 + "strexeq %0, %5, [%3]\n"
975 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
977 + : "cc");
978 + } while (res);
979 +
980 + smp_mb();
981 +
982 + return oldval;
983 +}
984 +
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992 +
993 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994 +{
995 + return atomic_add_return(i, v);
996 +}
997 +
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000 +{
1001 + (void) atomic_add_return(i, v);
1002 +}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011 +{
1012 + (void) atomic_sub_return(i, v);
1013 +}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022 +{
1023 + return atomic_cmpxchg(v, old, new);
1024 +}
1025 +
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034 +{
1035 + return xchg(&v->counter, new);
1036 +}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045 +{
1046 + atomic_add_unchecked(1, v);
1047 +}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050 +{
1051 + atomic_sub_unchecked(1, v);
1052 +}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056 +{
1057 + return atomic_add_return_unchecked(1, v) == 0;
1058 +}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062 +{
1063 + return atomic_add_return_unchecked(1, v);
1064 +}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068 @@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072 +#ifdef CONFIG_PAX_REFCOUNT
1073 +typedef struct {
1074 + u64 __aligned(8) counter;
1075 +} atomic64_unchecked_t;
1076 +#else
1077 +typedef atomic64_t atomic64_unchecked_t;
1078 +#endif
1079 +
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088 +{
1089 + u64 result;
1090 +
1091 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092 +" ldrexd %0, %H0, [%1]"
1093 + : "=&r" (result)
1094 + : "r" (&v->counter), "Qo" (v->counter)
1095 + );
1096 +
1097 + return result;
1098 +}
1099 +
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108 +{
1109 + u64 tmp;
1110 +
1111 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112 +"1: ldrexd %0, %H0, [%2]\n"
1113 +" strexd %0, %3, %H3, [%2]\n"
1114 +" teq %0, #0\n"
1115 +" bne 1b"
1116 + : "=&r" (tmp), "=Qo" (v->counter)
1117 + : "r" (&v->counter), "r" (i)
1118 + : "cc");
1119 +}
1120 +
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128 +" adcs %H0, %H0, %H4\n"
1129 +
1130 +#ifdef CONFIG_PAX_REFCOUNT
1131 +" bvc 3f\n"
1132 +"2: bkpt 0xf103\n"
1133 +"3:\n"
1134 +#endif
1135 +
1136 +" strexd %1, %0, %H0, [%3]\n"
1137 +" teq %1, #0\n"
1138 +" bne 1b"
1139 +
1140 +#ifdef CONFIG_PAX_REFCOUNT
1141 +"\n4:\n"
1142 + _ASM_EXTABLE(2b, 4b)
1143 +#endif
1144 +
1145 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146 + : "r" (&v->counter), "r" (i)
1147 + : "cc");
1148 +}
1149 +
1150 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151 +{
1152 + u64 result;
1153 + unsigned long tmp;
1154 +
1155 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156 +"1: ldrexd %0, %H0, [%3]\n"
1157 +" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165 - u64 result;
1166 - unsigned long tmp;
1167 + u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" adds %0, %1, %4\n"
1174 +" adcs %H0, %H1, %H4\n"
1175 +
1176 +#ifdef CONFIG_PAX_REFCOUNT
1177 +" bvc 3f\n"
1178 +" mov %0, %1\n"
1179 +" mov %H0, %H1\n"
1180 +"2: bkpt 0xf103\n"
1181 +"3:\n"
1182 +#endif
1183 +
1184 +" strexd %1, %0, %H0, [%3]\n"
1185 +" teq %1, #0\n"
1186 +" bne 1b"
1187 +
1188 +#ifdef CONFIG_PAX_REFCOUNT
1189 +"\n4:\n"
1190 + _ASM_EXTABLE(2b, 4b)
1191 +#endif
1192 +
1193 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 + : "r" (&v->counter), "r" (i)
1195 + : "cc");
1196 +
1197 + smp_mb();
1198 +
1199 + return result;
1200 +}
1201 +
1202 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203 +{
1204 + u64 result;
1205 + unsigned long tmp;
1206 +
1207 + smp_mb();
1208 +
1209 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217 +" sbcs %H0, %H0, %H4\n"
1218 +
1219 +#ifdef CONFIG_PAX_REFCOUNT
1220 +" bvc 3f\n"
1221 +"2: bkpt 0xf103\n"
1222 +"3:\n"
1223 +#endif
1224 +
1225 +" strexd %1, %0, %H0, [%3]\n"
1226 +" teq %1, #0\n"
1227 +" bne 1b"
1228 +
1229 +#ifdef CONFIG_PAX_REFCOUNT
1230 +"\n4:\n"
1231 + _ASM_EXTABLE(2b, 4b)
1232 +#endif
1233 +
1234 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235 + : "r" (&v->counter), "r" (i)
1236 + : "cc");
1237 +}
1238 +
1239 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245 +"1: ldrexd %0, %H0, [%3]\n"
1246 +" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254 - u64 result;
1255 - unsigned long tmp;
1256 + u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261 -"1: ldrexd %0, %H0, [%3]\n"
1262 -" subs %0, %0, %4\n"
1263 -" sbc %H0, %H0, %H4\n"
1264 +"1: ldrexd %1, %H1, [%3]\n"
1265 +" subs %0, %1, %4\n"
1266 +" sbcs %H0, %H1, %H4\n"
1267 +
1268 +#ifdef CONFIG_PAX_REFCOUNT
1269 +" bvc 3f\n"
1270 +" mov %0, %1\n"
1271 +" mov %H0, %H1\n"
1272 +"2: bkpt 0xf103\n"
1273 +"3:\n"
1274 +#endif
1275 +
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279 +
1280 +#ifdef CONFIG_PAX_REFCOUNT
1281 +"\n4:\n"
1282 + _ASM_EXTABLE(2b, 4b)
1283 +#endif
1284 +
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293 +{
1294 + u64 oldval;
1295 + unsigned long res;
1296 +
1297 + smp_mb();
1298 +
1299 + do {
1300 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301 + "ldrexd %1, %H1, [%3]\n"
1302 + "mov %0, #0\n"
1303 + "teq %1, %4\n"
1304 + "teqeq %H1, %H4\n"
1305 + "strexdeq %0, %5, %H5, [%3]"
1306 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307 + : "r" (&ptr->counter), "r" (old), "r" (new)
1308 + : "cc");
1309 + } while (res);
1310 +
1311 + smp_mb();
1312 +
1313 + return oldval;
1314 +}
1315 +
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323 - u64 result;
1324 - unsigned long tmp;
1325 + u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330 -"1: ldrexd %0, %H0, [%3]\n"
1331 -" subs %0, %0, #1\n"
1332 -" sbc %H0, %H0, #0\n"
1333 +"1: ldrexd %1, %H1, [%3]\n"
1334 +" subs %0, %1, #1\n"
1335 +" sbcs %H0, %H1, #0\n"
1336 +
1337 +#ifdef CONFIG_PAX_REFCOUNT
1338 +" bvc 3f\n"
1339 +" mov %0, %1\n"
1340 +" mov %H0, %H1\n"
1341 +"2: bkpt 0xf103\n"
1342 +"3:\n"
1343 +#endif
1344 +
1345 " teq %H0, #0\n"
1346 -" bmi 2f\n"
1347 +" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351 -"2:"
1352 +"4:\n"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 + _ASM_EXTABLE(2b, 4b)
1356 +#endif
1357 +
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365 -" beq 2f\n"
1366 +" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368 -" adc %H0, %H0, %H6\n"
1369 +" adcs %H0, %H0, %H6\n"
1370 +
1371 +#ifdef CONFIG_PAX_REFCOUNT
1372 +" bvc 3f\n"
1373 +"2: bkpt 0xf103\n"
1374 +"3:\n"
1375 +#endif
1376 +
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380 -"2:"
1381 +"4:\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 + _ASM_EXTABLE(2b, 4b)
1385 +#endif
1386 +
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405 index 75fe66b..ba3dee4 100644
1406 --- a/arch/arm/include/asm/cache.h
1407 +++ b/arch/arm/include/asm/cache.h
1408 @@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412 +#include <linux/const.h>
1413 +
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420 @@ -24,5 +26,6 @@
1421 #endif
1422
1423 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1424 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1425
1426 #endif
1427 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1428 index e1489c5..d418304 100644
1429 --- a/arch/arm/include/asm/cacheflush.h
1430 +++ b/arch/arm/include/asm/cacheflush.h
1431 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1432 void (*dma_unmap_area)(const void *, size_t, int);
1433
1434 void (*dma_flush_range)(const void *, const void *);
1435 -};
1436 +} __no_const;
1437
1438 /*
1439 * Select the calling method
1440 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1441 index 7eb18c1..e38b6d2 100644
1442 --- a/arch/arm/include/asm/cmpxchg.h
1443 +++ b/arch/arm/include/asm/cmpxchg.h
1444 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1445
1446 #define xchg(ptr,x) \
1447 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1448 +#define xchg_unchecked(ptr,x) \
1449 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1450
1451 #include <asm-generic/cmpxchg-local.h>
1452
1453 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1454 index ab98fdd..6b19938 100644
1455 --- a/arch/arm/include/asm/delay.h
1456 +++ b/arch/arm/include/asm/delay.h
1457 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1458 void (*delay)(unsigned long);
1459 void (*const_udelay)(unsigned long);
1460 void (*udelay)(unsigned long);
1461 -} arm_delay_ops;
1462 +} *arm_delay_ops;
1463
1464 -#define __delay(n) arm_delay_ops.delay(n)
1465 +#define __delay(n) arm_delay_ops->delay(n)
1466
1467 /*
1468 * This function intentionally does not exist; if you see references to
1469 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1470 * first constant multiplications gets optimized away if the delay is
1471 * a constant)
1472 */
1473 -#define __udelay(n) arm_delay_ops.udelay(n)
1474 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1475 +#define __udelay(n) arm_delay_ops->udelay(n)
1476 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1477
1478 #define udelay(n) \
1479 (__builtin_constant_p(n) ? \
1480 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1481 index 38050b1..9d90e8b 100644
1482 --- a/arch/arm/include/asm/elf.h
1483 +++ b/arch/arm/include/asm/elf.h
1484 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1485 the loader. We need to make sure that it is out of the way of the program
1486 that it will "exec", and that there is sufficient room for the brk. */
1487
1488 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1489 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1490 +
1491 +#ifdef CONFIG_PAX_ASLR
1492 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1493 +
1494 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1495 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1496 +#endif
1497
1498 /* When the program starts, a1 contains a pointer to a function to be
1499 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1500 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1501 extern void elf_set_personality(const struct elf32_hdr *);
1502 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1503
1504 -struct mm_struct;
1505 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1506 -#define arch_randomize_brk arch_randomize_brk
1507 -
1508 #endif
1509 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1510 index 83eb2f7..ed77159 100644
1511 --- a/arch/arm/include/asm/kmap_types.h
1512 +++ b/arch/arm/include/asm/kmap_types.h
1513 @@ -4,6 +4,6 @@
1514 /*
1515 * This is the "bare minimum". AIO seems to require this.
1516 */
1517 -#define KM_TYPE_NR 16
1518 +#define KM_TYPE_NR 17
1519
1520 #endif
1521 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1522 index 195ac2f..2272f0d 100644
1523 --- a/arch/arm/include/asm/mach/map.h
1524 +++ b/arch/arm/include/asm/mach/map.h
1525 @@ -34,6 +34,9 @@ struct map_desc {
1526 #define MT_MEMORY_ITCM 13
1527 #define MT_MEMORY_SO 14
1528 #define MT_MEMORY_DMA_READY 15
1529 +#define MT_MEMORY_R 16
1530 +#define MT_MEMORY_RW 17
1531 +#define MT_MEMORY_RX 18
1532
1533 #ifdef CONFIG_MMU
1534 extern void iotable_init(struct map_desc *, int);
1535 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1536 index 53426c6..c7baff3 100644
1537 --- a/arch/arm/include/asm/outercache.h
1538 +++ b/arch/arm/include/asm/outercache.h
1539 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1540 #endif
1541 void (*set_debug)(unsigned long);
1542 void (*resume)(void);
1543 -};
1544 +} __no_const;
1545
1546 #ifdef CONFIG_OUTER_CACHE
1547
1548 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1549 index 812a494..71fc0b6 100644
1550 --- a/arch/arm/include/asm/page.h
1551 +++ b/arch/arm/include/asm/page.h
1552 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1553 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1554 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1555 unsigned long vaddr, struct vm_area_struct *vma);
1556 -};
1557 +} __no_const;
1558
1559 #ifdef MULTI_USER
1560 extern struct cpu_user_fns cpu_user;
1561 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1562 index 943504f..1ad2de8 100644
1563 --- a/arch/arm/include/asm/pgalloc.h
1564 +++ b/arch/arm/include/asm/pgalloc.h
1565 @@ -22,7 +22,7 @@
1566
1567 #ifdef CONFIG_MMU
1568
1569 -#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
1570 +#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_PXNTABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
1571 #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
1572
1573 #ifdef CONFIG_ARM_LPAE
1574 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1575 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1576 }
1577
1578 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1579 +{
1580 + pud_populate(mm, pud, pmd);
1581 +}
1582 +
1583 #else /* !CONFIG_ARM_LPAE */
1584
1585 /*
1586 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1587 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1588 #define pmd_free(mm, pmd) do { } while (0)
1589 #define pud_populate(mm,pmd,pte) BUG()
1590 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1591
1592 #endif /* CONFIG_ARM_LPAE */
1593
1594 @@ -126,6 +132,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1595 __free_page(pte);
1596 }
1597
1598 +static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1599 +{
1600 + pmdval_t pmdval = pmd_val(*pmdp) | prot;
1601 + pmdp[0] = __pmd(pmdval);
1602 +#ifndef CONFIG_ARM_LPAE
1603 + pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1604 +#endif
1605 + flush_pmd_entry(pmdp);
1606 +}
1607 +
1608 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1609 pmdval_t prot)
1610 {
1611 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1612 index 5cfba15..d437dc2 100644
1613 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1614 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1615 @@ -20,12 +20,15 @@
1616 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1617 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1618 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1619 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1620 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1621 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1622 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1623 +
1624 /*
1625 * - section
1626 */
1627 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1628 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1629 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1630 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1631 @@ -37,6 +40,7 @@
1632 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1633 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1634 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1635 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1636
1637 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1638 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1639 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1640 index d795282..d82ff13 100644
1641 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1642 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1643 @@ -32,6 +32,7 @@
1644 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1645 #define PMD_BIT4 (_AT(pmdval_t, 0))
1646 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1647 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1648
1649 /*
1650 * - section
1651 @@ -41,9 +42,11 @@
1652 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1653 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1654 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1655 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1656 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1657 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1658 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1659 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1660 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1661
1662 /*
1663 @@ -66,6 +69,7 @@
1664 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1665 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1666 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1667 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1668 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1669
1670 /*
1671 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1672 index b249035..4ab204b 100644
1673 --- a/arch/arm/include/asm/pgtable-3level.h
1674 +++ b/arch/arm/include/asm/pgtable-3level.h
1675 @@ -73,6 +73,7 @@
1676 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1677 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1678 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1679 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1680 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1681 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1682 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1683 @@ -80,6 +81,7 @@
1684 /*
1685 * To be used in assembly code with the upper page attributes.
1686 */
1687 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1688 #define L_PTE_XN_HIGH (1 << (54 - 32))
1689 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1690
1691 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1692 index 08c1231..6a2d6b0 100644
1693 --- a/arch/arm/include/asm/pgtable.h
1694 +++ b/arch/arm/include/asm/pgtable.h
1695 @@ -30,6 +30,9 @@
1696 #include <asm/pgtable-2level.h>
1697 #endif
1698
1699 +#define ktla_ktva(addr) (addr)
1700 +#define ktva_ktla(addr) (addr)
1701 +
1702 /*
1703 * Just any arbitrary offset to the start of the vmalloc VM area: the
1704 * current 8MB value just means that there will be a 8MB "hole" after the
1705 @@ -53,6 +56,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1706 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1707 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1708
1709 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1710 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1711 +
1712 +#ifdef CONFIG_PAX_KERNEXEC
1713 +static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1714 +static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1715 +#else
1716 +static inline unsigned long pax_open_kernel(void) { return 0; }
1717 +static inline unsigned long pax_close_kernel(void) { return 0; }
1718 +#endif
1719 +
1720 /*
1721 * This is the lowest virtual address we can permit any user space
1722 * mapping to be mapped at. This is particularly important for
1723 @@ -73,23 +87,23 @@ extern pgprot_t pgprot_kernel;
1724
1725 #define _MOD_PROT(p, b) __pgprot(pgprot_val(p) | (b))
1726
1727 -#define PAGE_NONE _MOD_PROT(pgprot_user, L_PTE_XN | L_PTE_RDONLY)
1728 -#define PAGE_SHARED _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_XN)
1729 -#define PAGE_SHARED_EXEC _MOD_PROT(pgprot_user, L_PTE_USER)
1730 -#define PAGE_COPY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1731 -#define PAGE_COPY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY)
1732 -#define PAGE_READONLY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1733 -#define PAGE_READONLY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY)
1734 +#define PAGE_NONE _MOD_PROT(pgprot_user, L_PTE_XN | L_PTE_PXN | L_PTE_RDONLY)
1735 +#define PAGE_SHARED _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_XN | L_PTE_PXN)
1736 +#define PAGE_SHARED_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_PXN)
1737 +#define PAGE_COPY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1738 +#define PAGE_COPY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1739 +#define PAGE_READONLY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1740 +#define PAGE_READONLY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1741 #define PAGE_KERNEL _MOD_PROT(pgprot_kernel, L_PTE_XN)
1742 #define PAGE_KERNEL_EXEC pgprot_kernel
1743
1744 -#define __PAGE_NONE __pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN)
1745 -#define __PAGE_SHARED __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN)
1746 -#define __PAGE_SHARED_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER)
1747 -#define __PAGE_COPY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1748 -#define __PAGE_COPY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY)
1749 -#define __PAGE_READONLY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1750 -#define __PAGE_READONLY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY)
1751 +#define __PAGE_NONE __pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1752 +#define __PAGE_SHARED __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN | L_PTE_PXN)
1753 +#define __PAGE_SHARED_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_PXN)
1754 +#define __PAGE_COPY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1755 +#define __PAGE_COPY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1756 +#define __PAGE_READONLY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1757 +#define __PAGE_READONLY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1758
1759 #define __pgprot_modify(prot,mask,bits) \
1760 __pgprot((pgprot_val(prot) & ~(mask)) | (bits))
1761 @@ -242,7 +256,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1762
1763 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1764 {
1765 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1766 + const pteval_t mask = L_PTE_XN | L_PTE_PXN | L_PTE_RDONLY | L_PTE_USER;
1767 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1768 return pte;
1769 }
1770 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1771 index f3628fb..a0672dd 100644
1772 --- a/arch/arm/include/asm/proc-fns.h
1773 +++ b/arch/arm/include/asm/proc-fns.h
1774 @@ -75,7 +75,7 @@ extern struct processor {
1775 unsigned int suspend_size;
1776 void (*do_suspend)(void *);
1777 void (*do_resume)(void *);
1778 -} processor;
1779 +} __do_const processor;
1780
1781 #ifndef MULTI_CPU
1782 extern void cpu_proc_init(void);
1783 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1784 index 2e3be16..4dc90fc 100644
1785 --- a/arch/arm/include/asm/smp.h
1786 +++ b/arch/arm/include/asm/smp.h
1787 @@ -106,7 +106,7 @@ struct smp_operations {
1788 int (*cpu_disable)(unsigned int cpu);
1789 #endif
1790 #endif
1791 -};
1792 +} __no_const;
1793
1794 /*
1795 * set platform specific SMP operations
1796 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1797 index 8477b4c..801a6a9 100644
1798 --- a/arch/arm/include/asm/thread_info.h
1799 +++ b/arch/arm/include/asm/thread_info.h
1800 @@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1801 #define TIF_SYSCALL_TRACE 8
1802 #define TIF_SYSCALL_AUDIT 9
1803 #define TIF_SYSCALL_TRACEPOINT 10
1804 +
1805 +/* within 8 bits of TIF_SYSCALL_TRACE
1806 + to meet flexible second operand requirements
1807 +*/
1808 +#define TIF_GRSEC_SETXID 11
1809 +
1810 #define TIF_USING_IWMMXT 17
1811 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1812 #define TIF_RESTORE_SIGMASK 20
1813 @@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1814 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1815 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1816 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1817 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1818
1819 /* Checks for any syscall work in entry-common.S */
1820 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1821 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1822 + _TIF_GRSEC_SETXID)
1823
1824 /*
1825 * Change these and you break ASM code in entry-common.S
1826 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1827 index 7e1f760..1af891c 100644
1828 --- a/arch/arm/include/asm/uaccess.h
1829 +++ b/arch/arm/include/asm/uaccess.h
1830 @@ -22,6 +22,8 @@
1831 #define VERIFY_READ 0
1832 #define VERIFY_WRITE 1
1833
1834 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1835 +
1836 /*
1837 * The exception table consists of pairs of addresses: the first is the
1838 * address of an instruction that is allowed to fault, and the second is
1839 @@ -418,8 +420,23 @@ do { \
1840
1841
1842 #ifdef CONFIG_MMU
1843 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1844 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1845 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1846 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1847 +
1848 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1849 +{
1850 + if (!__builtin_constant_p(n))
1851 + check_object_size(to, n, false);
1852 + return ___copy_from_user(to, from, n);
1853 +}
1854 +
1855 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1856 +{
1857 + if (!__builtin_constant_p(n))
1858 + check_object_size(from, n, true);
1859 + return ___copy_to_user(to, from, n);
1860 +}
1861 +
1862 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1863 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1864 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1865 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1866
1867 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1868 {
1869 + if ((long)n < 0)
1870 + return n;
1871 +
1872 if (access_ok(VERIFY_READ, from, n))
1873 n = __copy_from_user(to, from, n);
1874 else /* security hole - plug it */
1875 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1876
1877 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1878 {
1879 + if ((long)n < 0)
1880 + return n;
1881 +
1882 if (access_ok(VERIFY_WRITE, to, n))
1883 n = __copy_to_user(to, from, n);
1884 return n;
1885 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1886 index 60d3b73..9168db0 100644
1887 --- a/arch/arm/kernel/armksyms.c
1888 +++ b/arch/arm/kernel/armksyms.c
1889 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1890 #ifdef CONFIG_MMU
1891 EXPORT_SYMBOL(copy_page);
1892
1893 -EXPORT_SYMBOL(__copy_from_user);
1894 -EXPORT_SYMBOL(__copy_to_user);
1895 +EXPORT_SYMBOL(___copy_from_user);
1896 +EXPORT_SYMBOL(___copy_to_user);
1897 EXPORT_SYMBOL(__clear_user);
1898
1899 EXPORT_SYMBOL(__get_user_1);
1900 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1901 index 4eee351..e247728 100644
1902 --- a/arch/arm/kernel/head.S
1903 +++ b/arch/arm/kernel/head.S
1904 @@ -52,7 +52,9 @@
1905 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1906
1907 .macro pgtbl, rd, phys
1908 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1909 + mov \rd, #TEXT_OFFSET
1910 + sub \rd, #PG_DIR_SIZE
1911 + add \rd, \rd, \phys
1912 .endm
1913
1914 /*
1915 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1916 index 1e9be5d..b9a75e1 100644
1917 --- a/arch/arm/kernel/module.c
1918 +++ b/arch/arm/kernel/module.c
1919 @@ -37,12 +37,35 @@
1920 #endif
1921
1922 #ifdef CONFIG_MMU
1923 -void *module_alloc(unsigned long size)
1924 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1925 {
1926 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1927 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1928 + GFP_KERNEL, prot, -1,
1929 __builtin_return_address(0));
1930 }
1931 +
1932 +void *module_alloc(unsigned long size)
1933 +{
1934 +
1935 +#ifdef CONFIG_PAX_KERNEXEC
1936 + return __module_alloc(size, PAGE_KERNEL);
1937 +#else
1938 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1939 +#endif
1940 +
1941 +}
1942 +
1943 +#ifdef CONFIG_PAX_KERNEXEC
1944 +void module_free_exec(struct module *mod, void *module_region)
1945 +{
1946 + module_free(mod, module_region);
1947 +}
1948 +
1949 +void *module_alloc_exec(unsigned long size)
1950 +{
1951 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1952 +}
1953 +#endif
1954 #endif
1955
1956 int
1957 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1958 index 90084a6..bf4bcfb 100644
1959 --- a/arch/arm/kernel/process.c
1960 +++ b/arch/arm/kernel/process.c
1961 @@ -28,7 +28,6 @@
1962 #include <linux/tick.h>
1963 #include <linux/utsname.h>
1964 #include <linux/uaccess.h>
1965 -#include <linux/random.h>
1966 #include <linux/hw_breakpoint.h>
1967 #include <linux/cpuidle.h>
1968 #include <linux/leds.h>
1969 @@ -256,9 +255,10 @@ void machine_power_off(void)
1970 machine_shutdown();
1971 if (pm_power_off)
1972 pm_power_off();
1973 + BUG();
1974 }
1975
1976 -void machine_restart(char *cmd)
1977 +__noreturn void machine_restart(char *cmd)
1978 {
1979 machine_shutdown();
1980
1981 @@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
1982 return 0;
1983 }
1984
1985 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1986 -{
1987 - unsigned long range_end = mm->brk + 0x02000000;
1988 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1989 -}
1990 -
1991 #ifdef CONFIG_MMU
1992 /*
1993 * The vectors page is always readable from user space for the
1994 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1995 index 739db3a..7f4a272 100644
1996 --- a/arch/arm/kernel/ptrace.c
1997 +++ b/arch/arm/kernel/ptrace.c
1998 @@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
1999 PTRACE_SYSCALL_EXIT,
2000 };
2001
2002 +#ifdef CONFIG_GRKERNSEC_SETXID
2003 +extern void gr_delayed_cred_worker(void);
2004 +#endif
2005 +
2006 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2007 enum ptrace_syscall_dir dir)
2008 {
2009 @@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2010
2011 current_thread_info()->syscall = scno;
2012
2013 +#ifdef CONFIG_GRKERNSEC_SETXID
2014 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2015 + gr_delayed_cred_worker();
2016 +#endif
2017 +
2018 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2019 return scno;
2020
2021 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2022 index da1d1aa..0a606e7 100644
2023 --- a/arch/arm/kernel/setup.c
2024 +++ b/arch/arm/kernel/setup.c
2025 @@ -99,19 +99,19 @@ EXPORT_SYMBOL(elf_hwcap);
2026
2027
2028 #ifdef MULTI_CPU
2029 -struct processor processor __read_mostly;
2030 +struct processor processor;
2031 #endif
2032 #ifdef MULTI_TLB
2033 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2034 +struct cpu_tlb_fns cpu_tlb __read_only;
2035 #endif
2036 #ifdef MULTI_USER
2037 -struct cpu_user_fns cpu_user __read_mostly;
2038 +struct cpu_user_fns cpu_user __read_only;
2039 #endif
2040 #ifdef MULTI_CACHE
2041 -struct cpu_cache_fns cpu_cache __read_mostly;
2042 +struct cpu_cache_fns cpu_cache __read_only;
2043 #endif
2044 #ifdef CONFIG_OUTER_CACHE
2045 -struct outer_cache_fns outer_cache __read_mostly;
2046 +struct outer_cache_fns outer_cache __read_only;
2047 EXPORT_SYMBOL(outer_cache);
2048 #endif
2049
2050 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2051 index fbc8b26..000ded0 100644
2052 --- a/arch/arm/kernel/smp.c
2053 +++ b/arch/arm/kernel/smp.c
2054 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2055
2056 static DECLARE_COMPLETION(cpu_running);
2057
2058 -static struct smp_operations smp_ops;
2059 +static struct smp_operations smp_ops __read_only;
2060
2061 void __init smp_set_ops(struct smp_operations *ops)
2062 {
2063 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2064 index b0179b8..b54c6c1 100644
2065 --- a/arch/arm/kernel/traps.c
2066 +++ b/arch/arm/kernel/traps.c
2067 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2068 static int die_owner = -1;
2069 static unsigned int die_nest_count;
2070
2071 +extern void gr_handle_kernel_exploit(void);
2072 +
2073 static unsigned long oops_begin(void)
2074 {
2075 int cpu;
2076 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2077 panic("Fatal exception in interrupt");
2078 if (panic_on_oops)
2079 panic("Fatal exception");
2080 +
2081 + gr_handle_kernel_exploit();
2082 +
2083 if (signr)
2084 do_exit(signr);
2085 }
2086 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2087 index 36ff15b..75d9e9d 100644
2088 --- a/arch/arm/kernel/vmlinux.lds.S
2089 +++ b/arch/arm/kernel/vmlinux.lds.S
2090 @@ -8,7 +8,11 @@
2091 #include <asm/thread_info.h>
2092 #include <asm/memory.h>
2093 #include <asm/page.h>
2094 -
2095 +
2096 +#ifdef CONFIG_PAX_KERNEXEC
2097 +#include <asm/pgtable.h>
2098 +#endif
2099 +
2100 #define PROC_INFO \
2101 . = ALIGN(4); \
2102 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2103 @@ -90,6 +94,11 @@ SECTIONS
2104 _text = .;
2105 HEAD_TEXT
2106 }
2107 +
2108 +#ifdef CONFIG_PAX_KERNEXEC
2109 + . = ALIGN(1<<SECTION_SHIFT);
2110 +#endif
2111 +
2112 .text : { /* Real text segment */
2113 _stext = .; /* Text and read-only data */
2114 __exception_text_start = .;
2115 @@ -133,6 +142,10 @@ SECTIONS
2116
2117 _etext = .; /* End of text and rodata section */
2118
2119 +#ifdef CONFIG_PAX_KERNEXEC
2120 + . = ALIGN(1<<SECTION_SHIFT);
2121 +#endif
2122 +
2123 #ifndef CONFIG_XIP_KERNEL
2124 . = ALIGN(PAGE_SIZE);
2125 __init_begin = .;
2126 @@ -192,6 +205,11 @@ SECTIONS
2127 . = PAGE_OFFSET + TEXT_OFFSET;
2128 #else
2129 __init_end = .;
2130 +
2131 +#ifdef CONFIG_PAX_KERNEXEC
2132 + . = ALIGN(1<<SECTION_SHIFT);
2133 +#endif
2134 +
2135 . = ALIGN(THREAD_SIZE);
2136 __data_loc = .;
2137 #endif
2138 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2139 index 66a477a..bee61d3 100644
2140 --- a/arch/arm/lib/copy_from_user.S
2141 +++ b/arch/arm/lib/copy_from_user.S
2142 @@ -16,7 +16,7 @@
2143 /*
2144 * Prototype:
2145 *
2146 - * size_t __copy_from_user(void *to, const void *from, size_t n)
2147 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
2148 *
2149 * Purpose:
2150 *
2151 @@ -84,11 +84,11 @@
2152
2153 .text
2154
2155 -ENTRY(__copy_from_user)
2156 +ENTRY(___copy_from_user)
2157
2158 #include "copy_template.S"
2159
2160 -ENDPROC(__copy_from_user)
2161 +ENDPROC(___copy_from_user)
2162
2163 .pushsection .fixup,"ax"
2164 .align 0
2165 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2166 index 6ee2f67..d1cce76 100644
2167 --- a/arch/arm/lib/copy_page.S
2168 +++ b/arch/arm/lib/copy_page.S
2169 @@ -10,6 +10,7 @@
2170 * ASM optimised string functions
2171 */
2172 #include <linux/linkage.h>
2173 +#include <linux/const.h>
2174 #include <asm/assembler.h>
2175 #include <asm/asm-offsets.h>
2176 #include <asm/cache.h>
2177 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2178 index d066df6..df28194 100644
2179 --- a/arch/arm/lib/copy_to_user.S
2180 +++ b/arch/arm/lib/copy_to_user.S
2181 @@ -16,7 +16,7 @@
2182 /*
2183 * Prototype:
2184 *
2185 - * size_t __copy_to_user(void *to, const void *from, size_t n)
2186 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
2187 *
2188 * Purpose:
2189 *
2190 @@ -88,11 +88,11 @@
2191 .text
2192
2193 ENTRY(__copy_to_user_std)
2194 -WEAK(__copy_to_user)
2195 +WEAK(___copy_to_user)
2196
2197 #include "copy_template.S"
2198
2199 -ENDPROC(__copy_to_user)
2200 +ENDPROC(___copy_to_user)
2201 ENDPROC(__copy_to_user_std)
2202
2203 .pushsection .fixup,"ax"
2204 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2205 index 0dc5385..45833ef 100644
2206 --- a/arch/arm/lib/delay.c
2207 +++ b/arch/arm/lib/delay.c
2208 @@ -28,12 +28,14 @@
2209 /*
2210 * Default to the loop-based delay implementation.
2211 */
2212 -struct arm_delay_ops arm_delay_ops = {
2213 +static struct arm_delay_ops arm_loop_delay_ops = {
2214 .delay = __loop_delay,
2215 .const_udelay = __loop_const_udelay,
2216 .udelay = __loop_udelay,
2217 };
2218
2219 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2220 +
2221 static const struct delay_timer *delay_timer;
2222 static bool delay_calibrated;
2223
2224 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2225 __timer_const_udelay(usecs * UDELAY_MULT);
2226 }
2227
2228 +static struct arm_delay_ops arm_timer_delay_ops = {
2229 + .delay = __timer_delay,
2230 + .const_udelay = __timer_const_udelay,
2231 + .udelay = __timer_udelay,
2232 +};
2233 +
2234 void __init register_current_timer_delay(const struct delay_timer *timer)
2235 {
2236 if (!delay_calibrated) {
2237 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2238 delay_timer = timer;
2239 lpj_fine = timer->freq / HZ;
2240 loops_per_jiffy = lpj_fine;
2241 - arm_delay_ops.delay = __timer_delay;
2242 - arm_delay_ops.const_udelay = __timer_const_udelay;
2243 - arm_delay_ops.udelay = __timer_udelay;
2244 + arm_delay_ops = &arm_timer_delay_ops;
2245 delay_calibrated = true;
2246 } else {
2247 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2248 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2249 index 025f742..8432b08 100644
2250 --- a/arch/arm/lib/uaccess_with_memcpy.c
2251 +++ b/arch/arm/lib/uaccess_with_memcpy.c
2252 @@ -104,7 +104,7 @@ out:
2253 }
2254
2255 unsigned long
2256 -__copy_to_user(void __user *to, const void *from, unsigned long n)
2257 +___copy_to_user(void __user *to, const void *from, unsigned long n)
2258 {
2259 /*
2260 * This test is stubbed out of the main function above to keep
2261 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2262 index 2c6c218..2b87c2d 100644
2263 --- a/arch/arm/mach-kirkwood/common.c
2264 +++ b/arch/arm/mach-kirkwood/common.c
2265 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2266 clk_gate_ops.disable(hw);
2267 }
2268
2269 -static struct clk_ops clk_gate_fn_ops;
2270 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2271 +{
2272 + return clk_gate_ops.is_enabled(hw);
2273 +}
2274 +
2275 +static struct clk_ops clk_gate_fn_ops = {
2276 + .enable = clk_gate_fn_enable,
2277 + .disable = clk_gate_fn_disable,
2278 + .is_enabled = clk_gate_fn_is_enabled,
2279 +};
2280
2281 static struct clk __init *clk_register_gate_fn(struct device *dev,
2282 const char *name,
2283 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2284 gate_fn->fn_en = fn_en;
2285 gate_fn->fn_dis = fn_dis;
2286
2287 - /* ops is the gate ops, but with our enable/disable functions */
2288 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2289 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2290 - clk_gate_fn_ops = clk_gate_ops;
2291 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
2292 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
2293 - }
2294 -
2295 clk = clk_register(dev, &gate_fn->gate.hw);
2296
2297 if (IS_ERR(clk))
2298 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2299 index d95f727..12f10dd 100644
2300 --- a/arch/arm/mach-omap2/board-n8x0.c
2301 +++ b/arch/arm/mach-omap2/board-n8x0.c
2302 @@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2303 }
2304 #endif
2305
2306 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2307 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2308 .late_init = n8x0_menelaus_late_init,
2309 };
2310
2311 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2312 index 87cc6d0..fd4f248 100644
2313 --- a/arch/arm/mach-omap2/omap_hwmod.c
2314 +++ b/arch/arm/mach-omap2/omap_hwmod.c
2315 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2316 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2317 struct omap_hwmod_rst_info *ohri);
2318 int (*init_clkdm)(struct omap_hwmod *oh);
2319 -};
2320 +} __no_const;
2321
2322 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2323 -static struct omap_hwmod_soc_ops soc_ops;
2324 +static struct omap_hwmod_soc_ops soc_ops __read_only;
2325
2326 /* omap_hwmod_list contains all registered struct omap_hwmods */
2327 static LIST_HEAD(omap_hwmod_list);
2328 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2329 index 5dbf13f..9be36fd 100644
2330 --- a/arch/arm/mm/fault.c
2331 +++ b/arch/arm/mm/fault.c
2332 @@ -25,6 +25,7 @@
2333 #include <asm/system_misc.h>
2334 #include <asm/system_info.h>
2335 #include <asm/tlbflush.h>
2336 +#include <asm/sections.h>
2337
2338 #include "fault.h"
2339
2340 @@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2341 if (fixup_exception(regs))
2342 return;
2343
2344 +#ifdef CONFIG_PAX_KERNEXEC
2345 + if (fsr & FSR_WRITE) {
2346 + if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2347 + if (current->signal->curr_ip)
2348 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2349 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2350 + else
2351 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2352 + current->comm, task_pid_nr(current), current_uid(), current_euid());
2353 + }
2354 + }
2355 +#endif
2356 +
2357 /*
2358 * No handler, we'll have to terminate things with extreme prejudice.
2359 */
2360 @@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2361 }
2362 #endif
2363
2364 +#ifdef CONFIG_PAX_PAGEEXEC
2365 + if (fsr & FSR_LNX_PF) {
2366 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2367 + do_group_exit(SIGKILL);
2368 + }
2369 +#endif
2370 +
2371 tsk->thread.address = addr;
2372 tsk->thread.error_code = fsr;
2373 tsk->thread.trap_no = 14;
2374 @@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2375 }
2376 #endif /* CONFIG_MMU */
2377
2378 +#ifdef CONFIG_PAX_PAGEEXEC
2379 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2380 +{
2381 + long i;
2382 +
2383 + printk(KERN_ERR "PAX: bytes at PC: ");
2384 + for (i = 0; i < 20; i++) {
2385 + unsigned char c;
2386 + if (get_user(c, (__force unsigned char __user *)pc+i))
2387 + printk(KERN_CONT "?? ");
2388 + else
2389 + printk(KERN_CONT "%02x ", c);
2390 + }
2391 + printk("\n");
2392 +
2393 + printk(KERN_ERR "PAX: bytes at SP-4: ");
2394 + for (i = -1; i < 20; i++) {
2395 + unsigned long c;
2396 + if (get_user(c, (__force unsigned long __user *)sp+i))
2397 + printk(KERN_CONT "???????? ");
2398 + else
2399 + printk(KERN_CONT "%08lx ", c);
2400 + }
2401 + printk("\n");
2402 +}
2403 +#endif
2404 +
2405 /*
2406 * First Level Translation Fault Handler
2407 *
2408 @@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2409 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2410 struct siginfo info;
2411
2412 +#ifdef CONFIG_PAX_KERNEXEC
2413 + if (!user_mode(regs) && is_xn_fault(ifsr)) {
2414 + if (current->signal->curr_ip)
2415 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2416 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2417 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2418 + else
2419 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2420 + current->comm, task_pid_nr(current), current_uid(), current_euid(),
2421 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2422 + goto die;
2423 + }
2424 +#endif
2425 +
2426 +#ifdef CONFIG_PAX_REFCOUNT
2427 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2428 + unsigned int bkpt;
2429 +
2430 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2431 + current->thread.error_code = ifsr;
2432 + current->thread.trap_no = 0;
2433 + pax_report_refcount_overflow(regs);
2434 + fixup_exception(regs);
2435 + return;
2436 + }
2437 + }
2438 +#endif
2439 +
2440 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2441 return;
2442
2443 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2444 inf->name, ifsr, addr);
2445
2446 +die:
2447 info.si_signo = inf->sig;
2448 info.si_errno = 0;
2449 info.si_code = inf->code;
2450 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2451 index cf08bdf..f1a0383 100644
2452 --- a/arch/arm/mm/fault.h
2453 +++ b/arch/arm/mm/fault.h
2454 @@ -3,6 +3,7 @@
2455
2456 /*
2457 * Fault status register encodings. We steal bit 31 for our own purposes.
2458 + * Set when the FSR value is from an instruction fault.
2459 */
2460 #define FSR_LNX_PF (1 << 31)
2461 #define FSR_WRITE (1 << 11)
2462 @@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2463 }
2464 #endif
2465
2466 +/* valid for LPAE and !LPAE */
2467 +static inline int is_xn_fault(unsigned int fsr)
2468 +{
2469 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
2470 +}
2471 +
2472 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2473 unsigned long search_exception_table(unsigned long addr);
2474
2475 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2476 index ad722f1..46b670e 100644
2477 --- a/arch/arm/mm/init.c
2478 +++ b/arch/arm/mm/init.c
2479 @@ -734,9 +734,43 @@ void __init mem_init(void)
2480
2481 void free_initmem(void)
2482 {
2483 +
2484 +#ifdef CONFIG_PAX_KERNEXEC
2485 + unsigned long addr;
2486 + pgd_t *pgd;
2487 + pud_t *pud;
2488 + pmd_t *pmd;
2489 +#endif
2490 +
2491 #ifdef CONFIG_HAVE_TCM
2492 extern char __tcm_start, __tcm_end;
2493 +#endif
2494
2495 +#ifdef CONFIG_PAX_KERNEXEC
2496 + /* make pages tables, etc before .text NX */
2497 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2498 + pgd = pgd_offset_k(addr);
2499 + pud = pud_offset(pgd, addr);
2500 + pmd = pmd_offset(pud, addr);
2501 + __pmd_update(pmd, PMD_SECT_XN);
2502 + }
2503 + /* make init NX */
2504 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2505 + pgd = pgd_offset_k(addr);
2506 + pud = pud_offset(pgd, addr);
2507 + pmd = pmd_offset(pud, addr);
2508 + __pmd_update(pmd, PMD_SECT_XN);
2509 + }
2510 + /* make kernel code/rodata read-only */
2511 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2512 + pgd = pgd_offset_k(addr);
2513 + pud = pud_offset(pgd, addr);
2514 + pmd = pmd_offset(pud, addr);
2515 + __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2516 + }
2517 +#endif
2518 +
2519 +#ifdef CONFIG_HAVE_TCM
2520 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2521 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2522 __phys_to_pfn(__pa(&__tcm_end)),
2523 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2524 index ce8cb19..3e96d5f 100644
2525 --- a/arch/arm/mm/mmap.c
2526 +++ b/arch/arm/mm/mmap.c
2527 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2528 if (len > TASK_SIZE)
2529 return -ENOMEM;
2530
2531 +#ifdef CONFIG_PAX_RANDMMAP
2532 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2533 +#endif
2534 +
2535 if (addr) {
2536 if (do_align)
2537 addr = COLOUR_ALIGN(addr, pgoff);
2538 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2539 addr = PAGE_ALIGN(addr);
2540
2541 vma = find_vma(mm, addr);
2542 - if (TASK_SIZE - len >= addr &&
2543 - (!vma || addr + len <= vma->vm_start))
2544 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2545 return addr;
2546 }
2547 if (len > mm->cached_hole_size) {
2548 - start_addr = addr = mm->free_area_cache;
2549 + start_addr = addr = mm->free_area_cache;
2550 } else {
2551 - start_addr = addr = mm->mmap_base;
2552 - mm->cached_hole_size = 0;
2553 + start_addr = addr = mm->mmap_base;
2554 + mm->cached_hole_size = 0;
2555 }
2556
2557 full_search:
2558 @@ -124,14 +127,14 @@ full_search:
2559 * Start a new search - just in case we missed
2560 * some holes.
2561 */
2562 - if (start_addr != TASK_UNMAPPED_BASE) {
2563 - start_addr = addr = TASK_UNMAPPED_BASE;
2564 + if (start_addr != mm->mmap_base) {
2565 + start_addr = addr = mm->mmap_base;
2566 mm->cached_hole_size = 0;
2567 goto full_search;
2568 }
2569 return -ENOMEM;
2570 }
2571 - if (!vma || addr + len <= vma->vm_start) {
2572 + if (check_heap_stack_gap(vma, addr, len)) {
2573 /*
2574 * Remember the place where we stopped the search:
2575 */
2576 @@ -175,6 +178,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2577 return addr;
2578 }
2579
2580 +#ifdef CONFIG_PAX_RANDMMAP
2581 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2582 +#endif
2583 +
2584 /* requesting a specific address */
2585 if (addr) {
2586 if (do_align)
2587 @@ -182,8 +189,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2588 else
2589 addr = PAGE_ALIGN(addr);
2590 vma = find_vma(mm, addr);
2591 - if (TASK_SIZE - len >= addr &&
2592 - (!vma || addr + len <= vma->vm_start))
2593 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2594 return addr;
2595 }
2596
2597 @@ -203,7 +209,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2598 /* make sure it can fit in the remaining address space */
2599 if (addr > len) {
2600 vma = find_vma(mm, addr-len);
2601 - if (!vma || addr <= vma->vm_start)
2602 + if (check_heap_stack_gap(vma, addr - len, len))
2603 /* remember the address as a hint for next time */
2604 return (mm->free_area_cache = addr-len);
2605 }
2606 @@ -212,17 +218,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2607 goto bottomup;
2608
2609 addr = mm->mmap_base - len;
2610 - if (do_align)
2611 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2612
2613 do {
2614 + if (do_align)
2615 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2616 /*
2617 * Lookup failure means no vma is above this address,
2618 * else if new region fits below vma->vm_start,
2619 * return with success:
2620 */
2621 vma = find_vma(mm, addr);
2622 - if (!vma || addr+len <= vma->vm_start)
2623 + if (check_heap_stack_gap(vma, addr, len))
2624 /* remember the address as a hint for next time */
2625 return (mm->free_area_cache = addr);
2626
2627 @@ -231,10 +237,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2628 mm->cached_hole_size = vma->vm_start - addr;
2629
2630 /* try just below the current vma->vm_start */
2631 - addr = vma->vm_start - len;
2632 - if (do_align)
2633 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2634 - } while (len < vma->vm_start);
2635 + addr = skip_heap_stack_gap(vma, len);
2636 + } while (!IS_ERR_VALUE(addr));
2637
2638 bottomup:
2639 /*
2640 @@ -266,10 +270,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2641
2642 if (mmap_is_legacy()) {
2643 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2644 +
2645 +#ifdef CONFIG_PAX_RANDMMAP
2646 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2647 + mm->mmap_base += mm->delta_mmap;
2648 +#endif
2649 +
2650 mm->get_unmapped_area = arch_get_unmapped_area;
2651 mm->unmap_area = arch_unmap_area;
2652 } else {
2653 mm->mmap_base = mmap_base(random_factor);
2654 +
2655 +#ifdef CONFIG_PAX_RANDMMAP
2656 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2657 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2658 +#endif
2659 +
2660 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2661 mm->unmap_area = arch_unmap_area_topdown;
2662 }
2663 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2664 index 99b47b9..ede7824 100644
2665 --- a/arch/arm/mm/mmu.c
2666 +++ b/arch/arm/mm/mmu.c
2667 @@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2668 [MT_UNCACHED] = {
2669 .prot_pte = PROT_PTE_DEVICE,
2670 .prot_l1 = PMD_TYPE_TABLE,
2671 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2672 + .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2673 .domain = DOMAIN_IO,
2674 },
2675 [MT_CACHECLEAN] = {
2676 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2677 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2678 .domain = DOMAIN_KERNEL,
2679 },
2680 #ifndef CONFIG_ARM_LPAE
2681 [MT_MINICLEAN] = {
2682 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2683 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2684 .domain = DOMAIN_KERNEL,
2685 },
2686 #endif
2687 @@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2688 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2689 .domain = DOMAIN_KERNEL,
2690 },
2691 + [MT_MEMORY_R] = {
2692 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2693 + .prot_l1 = PMD_TYPE_TABLE,
2694 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2695 + .domain = DOMAIN_KERNEL,
2696 + },
2697 + [MT_MEMORY_RW] = {
2698 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2699 + .prot_l1 = PMD_TYPE_TABLE,
2700 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2701 + .domain = DOMAIN_KERNEL,
2702 + },
2703 + [MT_MEMORY_RX] = {
2704 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2705 + .prot_l1 = PMD_TYPE_TABLE,
2706 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2707 + .domain = DOMAIN_KERNEL,
2708 + },
2709 [MT_ROM] = {
2710 - .prot_sect = PMD_TYPE_SECT,
2711 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2712 .domain = DOMAIN_KERNEL,
2713 },
2714 [MT_MEMORY_NONCACHED] = {
2715 @@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2716 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2717 L_PTE_XN,
2718 .prot_l1 = PMD_TYPE_TABLE,
2719 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2720 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2721 .domain = DOMAIN_KERNEL,
2722 },
2723 [MT_MEMORY_ITCM] = {
2724 @@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2725 * from SVC mode and no access from userspace.
2726 */
2727 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2728 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2729 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2730 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2731 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2732 #endif
2733 @@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2734 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2735 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2736 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2737 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2738 + mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2739 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2740 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2741 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2742 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2743 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2744 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2745 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2746 @@ -503,6 +529,12 @@ static void __init build_mem_type_table(void)
2747 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2748 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2749 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2750 + mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2751 + mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2752 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2753 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2754 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2755 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2756 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2757 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2758 mem_types[MT_ROM].prot_sect |= cp->pmd;
2759 @@ -1198,8 +1230,37 @@ static void __init map_lowmem(void)
2760 map.pfn = __phys_to_pfn(start);
2761 map.virtual = __phys_to_virt(start);
2762 map.length = end - start;
2763 - map.type = MT_MEMORY;
2764
2765 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2766 + struct map_desc kernel;
2767 + struct map_desc initmap;
2768 +
2769 + /* when freeing initmem we will make this RW */
2770 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2771 + initmap.virtual = (unsigned long)__init_begin;
2772 + initmap.length = _sdata - __init_begin;
2773 + initmap.type = MT_MEMORY;
2774 + create_mapping(&initmap);
2775 +
2776 + /* when freeing initmem we will make this RX */
2777 + kernel.pfn = __phys_to_pfn(__pa(_stext));
2778 + kernel.virtual = (unsigned long)_stext;
2779 + kernel.length = __init_begin - _stext;
2780 + kernel.type = MT_MEMORY;
2781 + create_mapping(&kernel);
2782 +
2783 + if (map.virtual < (unsigned long)_stext) {
2784 + map.length = (unsigned long)_stext - map.virtual;
2785 + map.type = MT_MEMORY;
2786 + create_mapping(&map);
2787 + }
2788 +
2789 + map.pfn = __phys_to_pfn(__pa(_sdata));
2790 + map.virtual = (unsigned long)_sdata;
2791 + map.length = end - __pa(_sdata);
2792 + }
2793 +
2794 + map.type = MT_MEMORY_RW;
2795 create_mapping(&map);
2796 }
2797 }
2798 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2799 index ec63e4a..62aa5f1d 100644
2800 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2801 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2802 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2803 value in bridge_virt_base */
2804 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2805 const int win);
2806 -};
2807 +} __no_const;
2808
2809 /*
2810 * Information needed to setup one address mapping.
2811 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2812 index f5144cd..71f6d1f 100644
2813 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2814 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2815 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2816 int (*started)(unsigned ch);
2817 int (*flush)(unsigned ch);
2818 int (*stop)(unsigned ch);
2819 -};
2820 +} __no_const;
2821
2822 extern void *samsung_dmadev_get_ops(void);
2823 extern void *s3c_dma_get_ops(void);
2824 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2825 index c3a58a1..78fbf54 100644
2826 --- a/arch/avr32/include/asm/cache.h
2827 +++ b/arch/avr32/include/asm/cache.h
2828 @@ -1,8 +1,10 @@
2829 #ifndef __ASM_AVR32_CACHE_H
2830 #define __ASM_AVR32_CACHE_H
2831
2832 +#include <linux/const.h>
2833 +
2834 #define L1_CACHE_SHIFT 5
2835 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2836 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2837
2838 /*
2839 * Memory returned by kmalloc() may be used for DMA, so we must make
2840 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2841 index e2c3287..6c4f98c 100644
2842 --- a/arch/avr32/include/asm/elf.h
2843 +++ b/arch/avr32/include/asm/elf.h
2844 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2845 the loader. We need to make sure that it is out of the way of the program
2846 that it will "exec", and that there is sufficient room for the brk. */
2847
2848 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2849 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2850
2851 +#ifdef CONFIG_PAX_ASLR
2852 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2853 +
2854 +#define PAX_DELTA_MMAP_LEN 15
2855 +#define PAX_DELTA_STACK_LEN 15
2856 +#endif
2857
2858 /* This yields a mask that user programs can use to figure out what
2859 instruction set this CPU supports. This could be done in user space,
2860 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2861 index 479330b..53717a8 100644
2862 --- a/arch/avr32/include/asm/kmap_types.h
2863 +++ b/arch/avr32/include/asm/kmap_types.h
2864 @@ -2,9 +2,9 @@
2865 #define __ASM_AVR32_KMAP_TYPES_H
2866
2867 #ifdef CONFIG_DEBUG_HIGHMEM
2868 -# define KM_TYPE_NR 29
2869 +# define KM_TYPE_NR 30
2870 #else
2871 -# define KM_TYPE_NR 14
2872 +# define KM_TYPE_NR 15
2873 #endif
2874
2875 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2876 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2877 index b2f2d2d..d1c85cb 100644
2878 --- a/arch/avr32/mm/fault.c
2879 +++ b/arch/avr32/mm/fault.c
2880 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2881
2882 int exception_trace = 1;
2883
2884 +#ifdef CONFIG_PAX_PAGEEXEC
2885 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2886 +{
2887 + unsigned long i;
2888 +
2889 + printk(KERN_ERR "PAX: bytes at PC: ");
2890 + for (i = 0; i < 20; i++) {
2891 + unsigned char c;
2892 + if (get_user(c, (unsigned char *)pc+i))
2893 + printk(KERN_CONT "???????? ");
2894 + else
2895 + printk(KERN_CONT "%02x ", c);
2896 + }
2897 + printk("\n");
2898 +}
2899 +#endif
2900 +
2901 /*
2902 * This routine handles page faults. It determines the address and the
2903 * problem, and then passes it off to one of the appropriate routines.
2904 @@ -174,6 +191,16 @@ bad_area:
2905 up_read(&mm->mmap_sem);
2906
2907 if (user_mode(regs)) {
2908 +
2909 +#ifdef CONFIG_PAX_PAGEEXEC
2910 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2911 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2912 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2913 + do_group_exit(SIGKILL);
2914 + }
2915 + }
2916 +#endif
2917 +
2918 if (exception_trace && printk_ratelimit())
2919 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2920 "sp %08lx ecr %lu\n",
2921 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2922 index 568885a..f8008df 100644
2923 --- a/arch/blackfin/include/asm/cache.h
2924 +++ b/arch/blackfin/include/asm/cache.h
2925 @@ -7,6 +7,7 @@
2926 #ifndef __ARCH_BLACKFIN_CACHE_H
2927 #define __ARCH_BLACKFIN_CACHE_H
2928
2929 +#include <linux/const.h>
2930 #include <linux/linkage.h> /* for asmlinkage */
2931
2932 /*
2933 @@ -14,7 +15,7 @@
2934 * Blackfin loads 32 bytes for cache
2935 */
2936 #define L1_CACHE_SHIFT 5
2937 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2938 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2939 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2940
2941 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2942 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2943 index aea2718..3639a60 100644
2944 --- a/arch/cris/include/arch-v10/arch/cache.h
2945 +++ b/arch/cris/include/arch-v10/arch/cache.h
2946 @@ -1,8 +1,9 @@
2947 #ifndef _ASM_ARCH_CACHE_H
2948 #define _ASM_ARCH_CACHE_H
2949
2950 +#include <linux/const.h>
2951 /* Etrax 100LX have 32-byte cache-lines. */
2952 -#define L1_CACHE_BYTES 32
2953 #define L1_CACHE_SHIFT 5
2954 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2955
2956 #endif /* _ASM_ARCH_CACHE_H */
2957 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2958 index 7caf25d..ee65ac5 100644
2959 --- a/arch/cris/include/arch-v32/arch/cache.h
2960 +++ b/arch/cris/include/arch-v32/arch/cache.h
2961 @@ -1,11 +1,12 @@
2962 #ifndef _ASM_CRIS_ARCH_CACHE_H
2963 #define _ASM_CRIS_ARCH_CACHE_H
2964
2965 +#include <linux/const.h>
2966 #include <arch/hwregs/dma.h>
2967
2968 /* A cache-line is 32 bytes. */
2969 -#define L1_CACHE_BYTES 32
2970 #define L1_CACHE_SHIFT 5
2971 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2972
2973 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2974
2975 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2976 index b86329d..6709906 100644
2977 --- a/arch/frv/include/asm/atomic.h
2978 +++ b/arch/frv/include/asm/atomic.h
2979 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2980 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2981 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2982
2983 +#define atomic64_read_unchecked(v) atomic64_read(v)
2984 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2985 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2986 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2987 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2988 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2989 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2990 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2991 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2992 +
2993 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2994 {
2995 int c, old;
2996 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2997 index 2797163..c2a401d 100644
2998 --- a/arch/frv/include/asm/cache.h
2999 +++ b/arch/frv/include/asm/cache.h
3000 @@ -12,10 +12,11 @@
3001 #ifndef __ASM_CACHE_H
3002 #define __ASM_CACHE_H
3003
3004 +#include <linux/const.h>
3005
3006 /* bytes per L1 cache line */
3007 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3008 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3009 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3010
3011 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3012 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3013 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3014 index 43901f2..0d8b865 100644
3015 --- a/arch/frv/include/asm/kmap_types.h
3016 +++ b/arch/frv/include/asm/kmap_types.h
3017 @@ -2,6 +2,6 @@
3018 #ifndef _ASM_KMAP_TYPES_H
3019 #define _ASM_KMAP_TYPES_H
3020
3021 -#define KM_TYPE_NR 17
3022 +#define KM_TYPE_NR 18
3023
3024 #endif
3025 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3026 index 385fd30..6c3d97e 100644
3027 --- a/arch/frv/mm/elf-fdpic.c
3028 +++ b/arch/frv/mm/elf-fdpic.c
3029 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3030 if (addr) {
3031 addr = PAGE_ALIGN(addr);
3032 vma = find_vma(current->mm, addr);
3033 - if (TASK_SIZE - len >= addr &&
3034 - (!vma || addr + len <= vma->vm_start))
3035 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3036 goto success;
3037 }
3038
3039 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3040 for (; vma; vma = vma->vm_next) {
3041 if (addr > limit)
3042 break;
3043 - if (addr + len <= vma->vm_start)
3044 + if (check_heap_stack_gap(vma, addr, len))
3045 goto success;
3046 addr = vma->vm_end;
3047 }
3048 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3049 for (; vma; vma = vma->vm_next) {
3050 if (addr > limit)
3051 break;
3052 - if (addr + len <= vma->vm_start)
3053 + if (check_heap_stack_gap(vma, addr, len))
3054 goto success;
3055 addr = vma->vm_end;
3056 }
3057 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3058 index f4ca594..adc72fd6 100644
3059 --- a/arch/hexagon/include/asm/cache.h
3060 +++ b/arch/hexagon/include/asm/cache.h
3061 @@ -21,9 +21,11 @@
3062 #ifndef __ASM_CACHE_H
3063 #define __ASM_CACHE_H
3064
3065 +#include <linux/const.h>
3066 +
3067 /* Bytes per L1 cache line */
3068 -#define L1_CACHE_SHIFT (5)
3069 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3070 +#define L1_CACHE_SHIFT 5
3071 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3072
3073 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3074 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3075 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3076 index 6e6fe18..a6ae668 100644
3077 --- a/arch/ia64/include/asm/atomic.h
3078 +++ b/arch/ia64/include/asm/atomic.h
3079 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3080 #define atomic64_inc(v) atomic64_add(1, (v))
3081 #define atomic64_dec(v) atomic64_sub(1, (v))
3082
3083 +#define atomic64_read_unchecked(v) atomic64_read(v)
3084 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3085 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3086 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3087 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3088 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3089 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3090 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3091 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3092 +
3093 /* Atomic operations are already serializing */
3094 #define smp_mb__before_atomic_dec() barrier()
3095 #define smp_mb__after_atomic_dec() barrier()
3096 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3097 index 988254a..e1ee885 100644
3098 --- a/arch/ia64/include/asm/cache.h
3099 +++ b/arch/ia64/include/asm/cache.h
3100 @@ -1,6 +1,7 @@
3101 #ifndef _ASM_IA64_CACHE_H
3102 #define _ASM_IA64_CACHE_H
3103
3104 +#include <linux/const.h>
3105
3106 /*
3107 * Copyright (C) 1998-2000 Hewlett-Packard Co
3108 @@ -9,7 +10,7 @@
3109
3110 /* Bytes per L1 (data) cache line. */
3111 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3112 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3113 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3114
3115 #ifdef CONFIG_SMP
3116 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3117 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3118 index b5298eb..67c6e62 100644
3119 --- a/arch/ia64/include/asm/elf.h
3120 +++ b/arch/ia64/include/asm/elf.h
3121 @@ -42,6 +42,13 @@
3122 */
3123 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3124
3125 +#ifdef CONFIG_PAX_ASLR
3126 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3127 +
3128 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3129 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3130 +#endif
3131 +
3132 #define PT_IA_64_UNWIND 0x70000001
3133
3134 /* IA-64 relocations: */
3135 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3136 index 96a8d92..617a1cf 100644
3137 --- a/arch/ia64/include/asm/pgalloc.h
3138 +++ b/arch/ia64/include/asm/pgalloc.h
3139 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3140 pgd_val(*pgd_entry) = __pa(pud);
3141 }
3142
3143 +static inline void
3144 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3145 +{
3146 + pgd_populate(mm, pgd_entry, pud);
3147 +}
3148 +
3149 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3150 {
3151 return quicklist_alloc(0, GFP_KERNEL, NULL);
3152 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3153 pud_val(*pud_entry) = __pa(pmd);
3154 }
3155
3156 +static inline void
3157 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3158 +{
3159 + pud_populate(mm, pud_entry, pmd);
3160 +}
3161 +
3162 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3163 {
3164 return quicklist_alloc(0, GFP_KERNEL, NULL);
3165 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3166 index 815810c..d60bd4c 100644
3167 --- a/arch/ia64/include/asm/pgtable.h
3168 +++ b/arch/ia64/include/asm/pgtable.h
3169 @@ -12,7 +12,7 @@
3170 * David Mosberger-Tang <davidm@hpl.hp.com>
3171 */
3172
3173 -
3174 +#include <linux/const.h>
3175 #include <asm/mman.h>
3176 #include <asm/page.h>
3177 #include <asm/processor.h>
3178 @@ -142,6 +142,17 @@
3179 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3180 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3181 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3182 +
3183 +#ifdef CONFIG_PAX_PAGEEXEC
3184 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3185 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3186 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3187 +#else
3188 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3189 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3190 +# define PAGE_COPY_NOEXEC PAGE_COPY
3191 +#endif
3192 +
3193 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3194 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3195 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3196 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3197 index 54ff557..70c88b7 100644
3198 --- a/arch/ia64/include/asm/spinlock.h
3199 +++ b/arch/ia64/include/asm/spinlock.h
3200 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3201 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3202
3203 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3204 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3205 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3206 }
3207
3208 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3209 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3210 index 449c8c0..50cdf87 100644
3211 --- a/arch/ia64/include/asm/uaccess.h
3212 +++ b/arch/ia64/include/asm/uaccess.h
3213 @@ -42,6 +42,8 @@
3214 #include <asm/pgtable.h>
3215 #include <asm/io.h>
3216
3217 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3218 +
3219 /*
3220 * For historical reasons, the following macros are grossly misnamed:
3221 */
3222 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3223 static inline unsigned long
3224 __copy_to_user (void __user *to, const void *from, unsigned long count)
3225 {
3226 + if (count > INT_MAX)
3227 + return count;
3228 +
3229 + if (!__builtin_constant_p(count))
3230 + check_object_size(from, count, true);
3231 +
3232 return __copy_user(to, (__force void __user *) from, count);
3233 }
3234
3235 static inline unsigned long
3236 __copy_from_user (void *to, const void __user *from, unsigned long count)
3237 {
3238 + if (count > INT_MAX)
3239 + return count;
3240 +
3241 + if (!__builtin_constant_p(count))
3242 + check_object_size(to, count, false);
3243 +
3244 return __copy_user((__force void __user *) to, from, count);
3245 }
3246
3247 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3248 ({ \
3249 void __user *__cu_to = (to); \
3250 const void *__cu_from = (from); \
3251 - long __cu_len = (n); \
3252 + unsigned long __cu_len = (n); \
3253 \
3254 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
3255 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3256 + if (!__builtin_constant_p(n)) \
3257 + check_object_size(__cu_from, __cu_len, true); \
3258 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3259 + } \
3260 __cu_len; \
3261 })
3262
3263 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3264 ({ \
3265 void *__cu_to = (to); \
3266 const void __user *__cu_from = (from); \
3267 - long __cu_len = (n); \
3268 + unsigned long __cu_len = (n); \
3269 \
3270 __chk_user_ptr(__cu_from); \
3271 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
3272 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3273 + if (!__builtin_constant_p(n)) \
3274 + check_object_size(__cu_to, __cu_len, false); \
3275 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3276 + } \
3277 __cu_len; \
3278 })
3279
3280 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3281 index 24603be..948052d 100644
3282 --- a/arch/ia64/kernel/module.c
3283 +++ b/arch/ia64/kernel/module.c
3284 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3285 void
3286 module_free (struct module *mod, void *module_region)
3287 {
3288 - if (mod && mod->arch.init_unw_table &&
3289 - module_region == mod->module_init) {
3290 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3291 unw_remove_unwind_table(mod->arch.init_unw_table);
3292 mod->arch.init_unw_table = NULL;
3293 }
3294 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3295 }
3296
3297 static inline int
3298 +in_init_rx (const struct module *mod, uint64_t addr)
3299 +{
3300 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3301 +}
3302 +
3303 +static inline int
3304 +in_init_rw (const struct module *mod, uint64_t addr)
3305 +{
3306 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3307 +}
3308 +
3309 +static inline int
3310 in_init (const struct module *mod, uint64_t addr)
3311 {
3312 - return addr - (uint64_t) mod->module_init < mod->init_size;
3313 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3314 +}
3315 +
3316 +static inline int
3317 +in_core_rx (const struct module *mod, uint64_t addr)
3318 +{
3319 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3320 +}
3321 +
3322 +static inline int
3323 +in_core_rw (const struct module *mod, uint64_t addr)
3324 +{
3325 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3326 }
3327
3328 static inline int
3329 in_core (const struct module *mod, uint64_t addr)
3330 {
3331 - return addr - (uint64_t) mod->module_core < mod->core_size;
3332 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3333 }
3334
3335 static inline int
3336 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3337 break;
3338
3339 case RV_BDREL:
3340 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3341 + if (in_init_rx(mod, val))
3342 + val -= (uint64_t) mod->module_init_rx;
3343 + else if (in_init_rw(mod, val))
3344 + val -= (uint64_t) mod->module_init_rw;
3345 + else if (in_core_rx(mod, val))
3346 + val -= (uint64_t) mod->module_core_rx;
3347 + else if (in_core_rw(mod, val))
3348 + val -= (uint64_t) mod->module_core_rw;
3349 break;
3350
3351 case RV_LTV:
3352 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3353 * addresses have been selected...
3354 */
3355 uint64_t gp;
3356 - if (mod->core_size > MAX_LTOFF)
3357 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3358 /*
3359 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3360 * at the end of the module.
3361 */
3362 - gp = mod->core_size - MAX_LTOFF / 2;
3363 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3364 else
3365 - gp = mod->core_size / 2;
3366 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3367 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3368 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3369 mod->arch.gp = gp;
3370 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3371 }
3372 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3373 index d9439ef..b9a4303 100644
3374 --- a/arch/ia64/kernel/sys_ia64.c
3375 +++ b/arch/ia64/kernel/sys_ia64.c
3376 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3377 if (REGION_NUMBER(addr) == RGN_HPAGE)
3378 addr = 0;
3379 #endif
3380 +
3381 +#ifdef CONFIG_PAX_RANDMMAP
3382 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3383 + addr = mm->free_area_cache;
3384 + else
3385 +#endif
3386 +
3387 if (!addr)
3388 addr = mm->free_area_cache;
3389
3390 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3391 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3392 /* At this point: (!vma || addr < vma->vm_end). */
3393 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3394 - if (start_addr != TASK_UNMAPPED_BASE) {
3395 + if (start_addr != mm->mmap_base) {
3396 /* Start a new search --- just in case we missed some holes. */
3397 - addr = TASK_UNMAPPED_BASE;
3398 + addr = mm->mmap_base;
3399 goto full_search;
3400 }
3401 return -ENOMEM;
3402 }
3403 - if (!vma || addr + len <= vma->vm_start) {
3404 + if (check_heap_stack_gap(vma, addr, len)) {
3405 /* Remember the address where we stopped this search: */
3406 mm->free_area_cache = addr + len;
3407 return addr;
3408 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3409 index 0ccb28f..8992469 100644
3410 --- a/arch/ia64/kernel/vmlinux.lds.S
3411 +++ b/arch/ia64/kernel/vmlinux.lds.S
3412 @@ -198,7 +198,7 @@ SECTIONS {
3413 /* Per-cpu data: */
3414 . = ALIGN(PERCPU_PAGE_SIZE);
3415 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3416 - __phys_per_cpu_start = __per_cpu_load;
3417 + __phys_per_cpu_start = per_cpu_load;
3418 /*
3419 * ensure percpu data fits
3420 * into percpu page size
3421 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3422 index 6cf0341..d352594 100644
3423 --- a/arch/ia64/mm/fault.c
3424 +++ b/arch/ia64/mm/fault.c
3425 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3426 return pte_present(pte);
3427 }
3428
3429 +#ifdef CONFIG_PAX_PAGEEXEC
3430 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3431 +{
3432 + unsigned long i;
3433 +
3434 + printk(KERN_ERR "PAX: bytes at PC: ");
3435 + for (i = 0; i < 8; i++) {
3436 + unsigned int c;
3437 + if (get_user(c, (unsigned int *)pc+i))
3438 + printk(KERN_CONT "???????? ");
3439 + else
3440 + printk(KERN_CONT "%08x ", c);
3441 + }
3442 + printk("\n");
3443 +}
3444 +#endif
3445 +
3446 # define VM_READ_BIT 0
3447 # define VM_WRITE_BIT 1
3448 # define VM_EXEC_BIT 2
3449 @@ -149,8 +166,21 @@ retry:
3450 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3451 goto bad_area;
3452
3453 - if ((vma->vm_flags & mask) != mask)
3454 + if ((vma->vm_flags & mask) != mask) {
3455 +
3456 +#ifdef CONFIG_PAX_PAGEEXEC
3457 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3458 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3459 + goto bad_area;
3460 +
3461 + up_read(&mm->mmap_sem);
3462 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3463 + do_group_exit(SIGKILL);
3464 + }
3465 +#endif
3466 +
3467 goto bad_area;
3468 + }
3469
3470 /*
3471 * If for any reason at all we couldn't handle the fault, make
3472 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3473 index 5ca674b..e0e1b70 100644
3474 --- a/arch/ia64/mm/hugetlbpage.c
3475 +++ b/arch/ia64/mm/hugetlbpage.c
3476 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3477 /* At this point: (!vmm || addr < vmm->vm_end). */
3478 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3479 return -ENOMEM;
3480 - if (!vmm || (addr + len) <= vmm->vm_start)
3481 + if (check_heap_stack_gap(vmm, addr, len))
3482 return addr;
3483 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3484 }
3485 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3486 index 082e383..fb7be80 100644
3487 --- a/arch/ia64/mm/init.c
3488 +++ b/arch/ia64/mm/init.c
3489 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3490 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3491 vma->vm_end = vma->vm_start + PAGE_SIZE;
3492 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3493 +
3494 +#ifdef CONFIG_PAX_PAGEEXEC
3495 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3496 + vma->vm_flags &= ~VM_EXEC;
3497 +
3498 +#ifdef CONFIG_PAX_MPROTECT
3499 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
3500 + vma->vm_flags &= ~VM_MAYEXEC;
3501 +#endif
3502 +
3503 + }
3504 +#endif
3505 +
3506 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3507 down_write(&current->mm->mmap_sem);
3508 if (insert_vm_struct(current->mm, vma)) {
3509 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3510 index 40b3ee9..8c2c112 100644
3511 --- a/arch/m32r/include/asm/cache.h
3512 +++ b/arch/m32r/include/asm/cache.h
3513 @@ -1,8 +1,10 @@
3514 #ifndef _ASM_M32R_CACHE_H
3515 #define _ASM_M32R_CACHE_H
3516
3517 +#include <linux/const.h>
3518 +
3519 /* L1 cache line size */
3520 #define L1_CACHE_SHIFT 4
3521 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3522 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3523
3524 #endif /* _ASM_M32R_CACHE_H */
3525 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3526 index 82abd15..d95ae5d 100644
3527 --- a/arch/m32r/lib/usercopy.c
3528 +++ b/arch/m32r/lib/usercopy.c
3529 @@ -14,6 +14,9 @@
3530 unsigned long
3531 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3532 {
3533 + if ((long)n < 0)
3534 + return n;
3535 +
3536 prefetch(from);
3537 if (access_ok(VERIFY_WRITE, to, n))
3538 __copy_user(to,from,n);
3539 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3540 unsigned long
3541 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3542 {
3543 + if ((long)n < 0)
3544 + return n;
3545 +
3546 prefetchw(to);
3547 if (access_ok(VERIFY_READ, from, n))
3548 __copy_user_zeroing(to,from,n);
3549 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3550 index 0395c51..5f26031 100644
3551 --- a/arch/m68k/include/asm/cache.h
3552 +++ b/arch/m68k/include/asm/cache.h
3553 @@ -4,9 +4,11 @@
3554 #ifndef __ARCH_M68K_CACHE_H
3555 #define __ARCH_M68K_CACHE_H
3556
3557 +#include <linux/const.h>
3558 +
3559 /* bytes per L1 cache line */
3560 #define L1_CACHE_SHIFT 4
3561 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3562 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3563
3564 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3565
3566 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3567 index 4efe96a..60e8699 100644
3568 --- a/arch/microblaze/include/asm/cache.h
3569 +++ b/arch/microblaze/include/asm/cache.h
3570 @@ -13,11 +13,12 @@
3571 #ifndef _ASM_MICROBLAZE_CACHE_H
3572 #define _ASM_MICROBLAZE_CACHE_H
3573
3574 +#include <linux/const.h>
3575 #include <asm/registers.h>
3576
3577 #define L1_CACHE_SHIFT 5
3578 /* word-granular cache in microblaze */
3579 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3580 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3581
3582 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3583
3584 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3585 index 01cc6ba..bcb7a5d 100644
3586 --- a/arch/mips/include/asm/atomic.h
3587 +++ b/arch/mips/include/asm/atomic.h
3588 @@ -21,6 +21,10 @@
3589 #include <asm/cmpxchg.h>
3590 #include <asm/war.h>
3591
3592 +#ifdef CONFIG_GENERIC_ATOMIC64
3593 +#include <asm-generic/atomic64.h>
3594 +#endif
3595 +
3596 #define ATOMIC_INIT(i) { (i) }
3597
3598 /*
3599 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3600 */
3601 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3602
3603 +#define atomic64_read_unchecked(v) atomic64_read(v)
3604 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3605 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3606 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3607 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3608 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3609 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3610 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3611 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3612 +
3613 #endif /* CONFIG_64BIT */
3614
3615 /*
3616 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3617 index b4db69f..8f3b093 100644
3618 --- a/arch/mips/include/asm/cache.h
3619 +++ b/arch/mips/include/asm/cache.h
3620 @@ -9,10 +9,11 @@
3621 #ifndef _ASM_CACHE_H
3622 #define _ASM_CACHE_H
3623
3624 +#include <linux/const.h>
3625 #include <kmalloc.h>
3626
3627 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3628 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3629 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3630
3631 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3632 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3633 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3634 index 455c0ac..ad65fbe 100644
3635 --- a/arch/mips/include/asm/elf.h
3636 +++ b/arch/mips/include/asm/elf.h
3637 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
3638 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3639 #endif
3640
3641 +#ifdef CONFIG_PAX_ASLR
3642 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3643 +
3644 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3645 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3646 +#endif
3647 +
3648 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3649 struct linux_binprm;
3650 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3651 int uses_interp);
3652
3653 -struct mm_struct;
3654 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3655 -#define arch_randomize_brk arch_randomize_brk
3656 -
3657 #endif /* _ASM_ELF_H */
3658 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3659 index c1f6afa..38cc6e9 100644
3660 --- a/arch/mips/include/asm/exec.h
3661 +++ b/arch/mips/include/asm/exec.h
3662 @@ -12,6 +12,6 @@
3663 #ifndef _ASM_EXEC_H
3664 #define _ASM_EXEC_H
3665
3666 -extern unsigned long arch_align_stack(unsigned long sp);
3667 +#define arch_align_stack(x) ((x) & ~0xfUL)
3668
3669 #endif /* _ASM_EXEC_H */
3670 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3671 index da9bd7d..91aa7ab 100644
3672 --- a/arch/mips/include/asm/page.h
3673 +++ b/arch/mips/include/asm/page.h
3674 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3675 #ifdef CONFIG_CPU_MIPS32
3676 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3677 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3678 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3679 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3680 #else
3681 typedef struct { unsigned long long pte; } pte_t;
3682 #define pte_val(x) ((x).pte)
3683 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3684 index 881d18b..cea38bc 100644
3685 --- a/arch/mips/include/asm/pgalloc.h
3686 +++ b/arch/mips/include/asm/pgalloc.h
3687 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3688 {
3689 set_pud(pud, __pud((unsigned long)pmd));
3690 }
3691 +
3692 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3693 +{
3694 + pud_populate(mm, pud, pmd);
3695 +}
3696 #endif
3697
3698 /*
3699 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3700 index 18806a5..141ffcf 100644
3701 --- a/arch/mips/include/asm/thread_info.h
3702 +++ b/arch/mips/include/asm/thread_info.h
3703 @@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3704 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3705 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3706 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3707 +/* li takes a 32bit immediate */
3708 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3709 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3710
3711 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3712 @@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3713 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3714 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3715 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3716 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3717 +
3718 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3719
3720 /* work to do in syscall_trace_leave() */
3721 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3722 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3723
3724 /* work to do on interrupt/exception return */
3725 #define _TIF_WORK_MASK \
3726 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3727 /* work to do on any return to u-space */
3728 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3729 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3730
3731 #endif /* __KERNEL__ */
3732
3733 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3734 index 9fdd8bc..4bd7f1a 100644
3735 --- a/arch/mips/kernel/binfmt_elfn32.c
3736 +++ b/arch/mips/kernel/binfmt_elfn32.c
3737 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3738 #undef ELF_ET_DYN_BASE
3739 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3740
3741 +#ifdef CONFIG_PAX_ASLR
3742 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3743 +
3744 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3745 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3746 +#endif
3747 +
3748 #include <asm/processor.h>
3749 #include <linux/module.h>
3750 #include <linux/elfcore.h>
3751 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3752 index ff44823..97f8906 100644
3753 --- a/arch/mips/kernel/binfmt_elfo32.c
3754 +++ b/arch/mips/kernel/binfmt_elfo32.c
3755 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3756 #undef ELF_ET_DYN_BASE
3757 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3758
3759 +#ifdef CONFIG_PAX_ASLR
3760 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3761 +
3762 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3763 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3764 +#endif
3765 +
3766 #include <asm/processor.h>
3767
3768 /*
3769 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3770 index 69b17a9..9db82f9 100644
3771 --- a/arch/mips/kernel/process.c
3772 +++ b/arch/mips/kernel/process.c
3773 @@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3774 out:
3775 return pc;
3776 }
3777 -
3778 -/*
3779 - * Don't forget that the stack pointer must be aligned on a 8 bytes
3780 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3781 - */
3782 -unsigned long arch_align_stack(unsigned long sp)
3783 -{
3784 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3785 - sp -= get_random_int() & ~PAGE_MASK;
3786 -
3787 - return sp & ALMASK;
3788 -}
3789 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3790 index 4812c6d..2069554 100644
3791 --- a/arch/mips/kernel/ptrace.c
3792 +++ b/arch/mips/kernel/ptrace.c
3793 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3794 return arch;
3795 }
3796
3797 +#ifdef CONFIG_GRKERNSEC_SETXID
3798 +extern void gr_delayed_cred_worker(void);
3799 +#endif
3800 +
3801 /*
3802 * Notification of system call entry/exit
3803 * - triggered by current->work.syscall_trace
3804 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3805 /* do the secure computing check first */
3806 secure_computing_strict(regs->regs[2]);
3807
3808 +#ifdef CONFIG_GRKERNSEC_SETXID
3809 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3810 + gr_delayed_cred_worker();
3811 +#endif
3812 +
3813 if (!(current->ptrace & PT_PTRACED))
3814 goto out;
3815
3816 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3817 index 374f66e..1c882a0 100644
3818 --- a/arch/mips/kernel/scall32-o32.S
3819 +++ b/arch/mips/kernel/scall32-o32.S
3820 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3821
3822 stack_done:
3823 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3824 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3825 + li t1, _TIF_SYSCALL_WORK
3826 and t0, t1
3827 bnez t0, syscall_trace_entry # -> yes
3828
3829 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3830 index 169de6a..f594a89 100644
3831 --- a/arch/mips/kernel/scall64-64.S
3832 +++ b/arch/mips/kernel/scall64-64.S
3833 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3834
3835 sd a3, PT_R26(sp) # save a3 for syscall restarting
3836
3837 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3838 + li t1, _TIF_SYSCALL_WORK
3839 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3840 and t0, t1, t0
3841 bnez t0, syscall_trace_entry
3842 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3843 index 86ec03f..1235baf 100644
3844 --- a/arch/mips/kernel/scall64-n32.S
3845 +++ b/arch/mips/kernel/scall64-n32.S
3846 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3847
3848 sd a3, PT_R26(sp) # save a3 for syscall restarting
3849
3850 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3851 + li t1, _TIF_SYSCALL_WORK
3852 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3853 and t0, t1, t0
3854 bnez t0, n32_syscall_trace_entry
3855 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3856 index 53c2d72..3734584 100644
3857 --- a/arch/mips/kernel/scall64-o32.S
3858 +++ b/arch/mips/kernel/scall64-o32.S
3859 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3860 PTR 4b, bad_stack
3861 .previous
3862
3863 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3864 + li t1, _TIF_SYSCALL_WORK
3865 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3866 and t0, t1, t0
3867 bnez t0, trace_a_syscall
3868 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3869 index ddcec1e..c7f983e 100644
3870 --- a/arch/mips/mm/fault.c
3871 +++ b/arch/mips/mm/fault.c
3872 @@ -27,6 +27,23 @@
3873 #include <asm/highmem.h> /* For VMALLOC_END */
3874 #include <linux/kdebug.h>
3875
3876 +#ifdef CONFIG_PAX_PAGEEXEC
3877 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3878 +{
3879 + unsigned long i;
3880 +
3881 + printk(KERN_ERR "PAX: bytes at PC: ");
3882 + for (i = 0; i < 5; i++) {
3883 + unsigned int c;
3884 + if (get_user(c, (unsigned int *)pc+i))
3885 + printk(KERN_CONT "???????? ");
3886 + else
3887 + printk(KERN_CONT "%08x ", c);
3888 + }
3889 + printk("\n");
3890 +}
3891 +#endif
3892 +
3893 /*
3894 * This routine handles page faults. It determines the address,
3895 * and the problem, and then passes it off to one of the appropriate
3896 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3897 index 302d779..7d35bf8 100644
3898 --- a/arch/mips/mm/mmap.c
3899 +++ b/arch/mips/mm/mmap.c
3900 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3901 do_color_align = 1;
3902
3903 /* requesting a specific address */
3904 +
3905 +#ifdef CONFIG_PAX_RANDMMAP
3906 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3907 +#endif
3908 +
3909 if (addr) {
3910 if (do_color_align)
3911 addr = COLOUR_ALIGN(addr, pgoff);
3912 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3913 addr = PAGE_ALIGN(addr);
3914
3915 vma = find_vma(mm, addr);
3916 - if (TASK_SIZE - len >= addr &&
3917 - (!vma || addr + len <= vma->vm_start))
3918 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3919 return addr;
3920 }
3921
3922 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3923 /* At this point: (!vma || addr < vma->vm_end). */
3924 if (TASK_SIZE - len < addr)
3925 return -ENOMEM;
3926 - if (!vma || addr + len <= vma->vm_start)
3927 + if (check_heap_stack_gap(vmm, addr, len))
3928 return addr;
3929 addr = vma->vm_end;
3930 if (do_color_align)
3931 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3932 /* make sure it can fit in the remaining address space */
3933 if (likely(addr > len)) {
3934 vma = find_vma(mm, addr - len);
3935 - if (!vma || addr <= vma->vm_start) {
3936 + if (check_heap_stack_gap(vmm, addr - len, len))
3937 /* cache the address as a hint for next time */
3938 return mm->free_area_cache = addr - len;
3939 }
3940 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3941 * return with success:
3942 */
3943 vma = find_vma(mm, addr);
3944 - if (likely(!vma || addr + len <= vma->vm_start)) {
3945 + if (check_heap_stack_gap(vmm, addr, len)) {
3946 /* cache the address as a hint for next time */
3947 return mm->free_area_cache = addr;
3948 }
3949 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3950 mm->unmap_area = arch_unmap_area_topdown;
3951 }
3952 }
3953 -
3954 -static inline unsigned long brk_rnd(void)
3955 -{
3956 - unsigned long rnd = get_random_int();
3957 -
3958 - rnd = rnd << PAGE_SHIFT;
3959 - /* 8MB for 32bit, 256MB for 64bit */
3960 - if (TASK_IS_32BIT_ADDR)
3961 - rnd = rnd & 0x7ffffful;
3962 - else
3963 - rnd = rnd & 0xffffffful;
3964 -
3965 - return rnd;
3966 -}
3967 -
3968 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3969 -{
3970 - unsigned long base = mm->brk;
3971 - unsigned long ret;
3972 -
3973 - ret = PAGE_ALIGN(base + brk_rnd());
3974 -
3975 - if (ret < mm->brk)
3976 - return mm->brk;
3977 -
3978 - return ret;
3979 -}
3980 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3981 index 967d144..db12197 100644
3982 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3983 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3984 @@ -11,12 +11,14 @@
3985 #ifndef _ASM_PROC_CACHE_H
3986 #define _ASM_PROC_CACHE_H
3987
3988 +#include <linux/const.h>
3989 +
3990 /* L1 cache */
3991
3992 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3993 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3994 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3995 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3996 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3997 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3998
3999 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4000 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4001 index bcb5df2..84fabd2 100644
4002 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4003 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4004 @@ -16,13 +16,15 @@
4005 #ifndef _ASM_PROC_CACHE_H
4006 #define _ASM_PROC_CACHE_H
4007
4008 +#include <linux/const.h>
4009 +
4010 /*
4011 * L1 cache
4012 */
4013 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4014 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4015 -#define L1_CACHE_BYTES 32 /* bytes per entry */
4016 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4017 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4018 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4019
4020 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4021 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4022 index 4ce7a01..449202a 100644
4023 --- a/arch/openrisc/include/asm/cache.h
4024 +++ b/arch/openrisc/include/asm/cache.h
4025 @@ -19,11 +19,13 @@
4026 #ifndef __ASM_OPENRISC_CACHE_H
4027 #define __ASM_OPENRISC_CACHE_H
4028
4029 +#include <linux/const.h>
4030 +
4031 /* FIXME: How can we replace these with values from the CPU...
4032 * they shouldn't be hard-coded!
4033 */
4034
4035 -#define L1_CACHE_BYTES 16
4036 #define L1_CACHE_SHIFT 4
4037 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4038
4039 #endif /* __ASM_OPENRISC_CACHE_H */
4040 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4041 index af9cf30..2aae9b2 100644
4042 --- a/arch/parisc/include/asm/atomic.h
4043 +++ b/arch/parisc/include/asm/atomic.h
4044 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4045
4046 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4047
4048 +#define atomic64_read_unchecked(v) atomic64_read(v)
4049 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4050 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4051 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4052 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4053 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4054 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4055 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4056 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4057 +
4058 #endif /* !CONFIG_64BIT */
4059
4060
4061 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4062 index 47f11c7..3420df2 100644
4063 --- a/arch/parisc/include/asm/cache.h
4064 +++ b/arch/parisc/include/asm/cache.h
4065 @@ -5,6 +5,7 @@
4066 #ifndef __ARCH_PARISC_CACHE_H
4067 #define __ARCH_PARISC_CACHE_H
4068
4069 +#include <linux/const.h>
4070
4071 /*
4072 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4073 @@ -15,13 +16,13 @@
4074 * just ruin performance.
4075 */
4076 #ifdef CONFIG_PA20
4077 -#define L1_CACHE_BYTES 64
4078 #define L1_CACHE_SHIFT 6
4079 #else
4080 -#define L1_CACHE_BYTES 32
4081 #define L1_CACHE_SHIFT 5
4082 #endif
4083
4084 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4085 +
4086 #ifndef __ASSEMBLY__
4087
4088 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4089 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4090 index 19f6cb1..6c78cf2 100644
4091 --- a/arch/parisc/include/asm/elf.h
4092 +++ b/arch/parisc/include/asm/elf.h
4093 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4094
4095 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4096
4097 +#ifdef CONFIG_PAX_ASLR
4098 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4099 +
4100 +#define PAX_DELTA_MMAP_LEN 16
4101 +#define PAX_DELTA_STACK_LEN 16
4102 +#endif
4103 +
4104 /* This yields a mask that user programs can use to figure out what
4105 instruction set this CPU supports. This could be done in user space,
4106 but it's not easy, and we've already done it here. */
4107 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4108 index fc987a1..6e068ef 100644
4109 --- a/arch/parisc/include/asm/pgalloc.h
4110 +++ b/arch/parisc/include/asm/pgalloc.h
4111 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4112 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4113 }
4114
4115 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4116 +{
4117 + pgd_populate(mm, pgd, pmd);
4118 +}
4119 +
4120 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4121 {
4122 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4123 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4124 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4125 #define pmd_free(mm, x) do { } while (0)
4126 #define pgd_populate(mm, pmd, pte) BUG()
4127 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
4128
4129 #endif
4130
4131 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4132 index ee99f23..802b0a1 100644
4133 --- a/arch/parisc/include/asm/pgtable.h
4134 +++ b/arch/parisc/include/asm/pgtable.h
4135 @@ -212,6 +212,17 @@ struct vm_area_struct;
4136 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4137 #define PAGE_COPY PAGE_EXECREAD
4138 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4139 +
4140 +#ifdef CONFIG_PAX_PAGEEXEC
4141 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4142 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4143 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4144 +#else
4145 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4146 +# define PAGE_COPY_NOEXEC PAGE_COPY
4147 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4148 +#endif
4149 +
4150 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4151 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4152 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4153 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4154 index 4ba2c93..f5e3974 100644
4155 --- a/arch/parisc/include/asm/uaccess.h
4156 +++ b/arch/parisc/include/asm/uaccess.h
4157 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4158 const void __user *from,
4159 unsigned long n)
4160 {
4161 - int sz = __compiletime_object_size(to);
4162 + size_t sz = __compiletime_object_size(to);
4163 int ret = -EFAULT;
4164
4165 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4166 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4167 ret = __copy_from_user(to, from, n);
4168 else
4169 copy_from_user_overflow();
4170 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4171 index 5e34ccf..672bc9c 100644
4172 --- a/arch/parisc/kernel/module.c
4173 +++ b/arch/parisc/kernel/module.c
4174 @@ -98,16 +98,38 @@
4175
4176 /* three functions to determine where in the module core
4177 * or init pieces the location is */
4178 +static inline int in_init_rx(struct module *me, void *loc)
4179 +{
4180 + return (loc >= me->module_init_rx &&
4181 + loc < (me->module_init_rx + me->init_size_rx));
4182 +}
4183 +
4184 +static inline int in_init_rw(struct module *me, void *loc)
4185 +{
4186 + return (loc >= me->module_init_rw &&
4187 + loc < (me->module_init_rw + me->init_size_rw));
4188 +}
4189 +
4190 static inline int in_init(struct module *me, void *loc)
4191 {
4192 - return (loc >= me->module_init &&
4193 - loc <= (me->module_init + me->init_size));
4194 + return in_init_rx(me, loc) || in_init_rw(me, loc);
4195 +}
4196 +
4197 +static inline int in_core_rx(struct module *me, void *loc)
4198 +{
4199 + return (loc >= me->module_core_rx &&
4200 + loc < (me->module_core_rx + me->core_size_rx));
4201 +}
4202 +
4203 +static inline int in_core_rw(struct module *me, void *loc)
4204 +{
4205 + return (loc >= me->module_core_rw &&
4206 + loc < (me->module_core_rw + me->core_size_rw));
4207 }
4208
4209 static inline int in_core(struct module *me, void *loc)
4210 {
4211 - return (loc >= me->module_core &&
4212 - loc <= (me->module_core + me->core_size));
4213 + return in_core_rx(me, loc) || in_core_rw(me, loc);
4214 }
4215
4216 static inline int in_local(struct module *me, void *loc)
4217 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4218 }
4219
4220 /* align things a bit */
4221 - me->core_size = ALIGN(me->core_size, 16);
4222 - me->arch.got_offset = me->core_size;
4223 - me->core_size += gots * sizeof(struct got_entry);
4224 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4225 + me->arch.got_offset = me->core_size_rw;
4226 + me->core_size_rw += gots * sizeof(struct got_entry);
4227
4228 - me->core_size = ALIGN(me->core_size, 16);
4229 - me->arch.fdesc_offset = me->core_size;
4230 - me->core_size += fdescs * sizeof(Elf_Fdesc);
4231 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4232 + me->arch.fdesc_offset = me->core_size_rw;
4233 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4234
4235 me->arch.got_max = gots;
4236 me->arch.fdesc_max = fdescs;
4237 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4238
4239 BUG_ON(value == 0);
4240
4241 - got = me->module_core + me->arch.got_offset;
4242 + got = me->module_core_rw + me->arch.got_offset;
4243 for (i = 0; got[i].addr; i++)
4244 if (got[i].addr == value)
4245 goto out;
4246 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4247 #ifdef CONFIG_64BIT
4248 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4249 {
4250 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4251 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4252
4253 if (!value) {
4254 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4255 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4256
4257 /* Create new one */
4258 fdesc->addr = value;
4259 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4260 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4261 return (Elf_Addr)fdesc;
4262 }
4263 #endif /* CONFIG_64BIT */
4264 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4265
4266 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4267 end = table + sechdrs[me->arch.unwind_section].sh_size;
4268 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4269 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4270
4271 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4272 me->arch.unwind_section, table, end, gp);
4273 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4274 index f76c108..8117482 100644
4275 --- a/arch/parisc/kernel/sys_parisc.c
4276 +++ b/arch/parisc/kernel/sys_parisc.c
4277 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4278 /* At this point: (!vma || addr < vma->vm_end). */
4279 if (TASK_SIZE - len < addr)
4280 return -ENOMEM;
4281 - if (!vma || addr + len <= vma->vm_start)
4282 + if (check_heap_stack_gap(vma, addr, len))
4283 return addr;
4284 addr = vma->vm_end;
4285 }
4286 @@ -81,7 +81,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4287 /* At this point: (!vma || addr < vma->vm_end). */
4288 if (TASK_SIZE - len < addr)
4289 return -ENOMEM;
4290 - if (!vma || addr + len <= vma->vm_start)
4291 + if (check_heap_stack_gap(vma, addr, len))
4292 return addr;
4293 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4294 if (addr < vma->vm_end) /* handle wraparound */
4295 @@ -100,7 +100,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4296 if (flags & MAP_FIXED)
4297 return addr;
4298 if (!addr)
4299 - addr = TASK_UNMAPPED_BASE;
4300 + addr = current->mm->mmap_base;
4301
4302 if (filp) {
4303 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4304 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4305 index 45ba99f..8e22c33 100644
4306 --- a/arch/parisc/kernel/traps.c
4307 +++ b/arch/parisc/kernel/traps.c
4308 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4309
4310 down_read(&current->mm->mmap_sem);
4311 vma = find_vma(current->mm,regs->iaoq[0]);
4312 - if (vma && (regs->iaoq[0] >= vma->vm_start)
4313 - && (vma->vm_flags & VM_EXEC)) {
4314 -
4315 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4316 fault_address = regs->iaoq[0];
4317 fault_space = regs->iasq[0];
4318
4319 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4320 index 18162ce..94de376 100644
4321 --- a/arch/parisc/mm/fault.c
4322 +++ b/arch/parisc/mm/fault.c
4323 @@ -15,6 +15,7 @@
4324 #include <linux/sched.h>
4325 #include <linux/interrupt.h>
4326 #include <linux/module.h>
4327 +#include <linux/unistd.h>
4328
4329 #include <asm/uaccess.h>
4330 #include <asm/traps.h>
4331 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4332 static unsigned long
4333 parisc_acctyp(unsigned long code, unsigned int inst)
4334 {
4335 - if (code == 6 || code == 16)
4336 + if (code == 6 || code == 7 || code == 16)
4337 return VM_EXEC;
4338
4339 switch (inst & 0xf0000000) {
4340 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4341 }
4342 #endif
4343
4344 +#ifdef CONFIG_PAX_PAGEEXEC
4345 +/*
4346 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4347 + *
4348 + * returns 1 when task should be killed
4349 + * 2 when rt_sigreturn trampoline was detected
4350 + * 3 when unpatched PLT trampoline was detected
4351 + */
4352 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4353 +{
4354 +
4355 +#ifdef CONFIG_PAX_EMUPLT
4356 + int err;
4357 +
4358 + do { /* PaX: unpatched PLT emulation */
4359 + unsigned int bl, depwi;
4360 +
4361 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4362 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4363 +
4364 + if (err)
4365 + break;
4366 +
4367 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4368 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4369 +
4370 + err = get_user(ldw, (unsigned int *)addr);
4371 + err |= get_user(bv, (unsigned int *)(addr+4));
4372 + err |= get_user(ldw2, (unsigned int *)(addr+8));
4373 +
4374 + if (err)
4375 + break;
4376 +
4377 + if (ldw == 0x0E801096U &&
4378 + bv == 0xEAC0C000U &&
4379 + ldw2 == 0x0E881095U)
4380 + {
4381 + unsigned int resolver, map;
4382 +
4383 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4384 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4385 + if (err)
4386 + break;
4387 +
4388 + regs->gr[20] = instruction_pointer(regs)+8;
4389 + regs->gr[21] = map;
4390 + regs->gr[22] = resolver;
4391 + regs->iaoq[0] = resolver | 3UL;
4392 + regs->iaoq[1] = regs->iaoq[0] + 4;
4393 + return 3;
4394 + }
4395 + }
4396 + } while (0);
4397 +#endif
4398 +
4399 +#ifdef CONFIG_PAX_EMUTRAMP
4400 +
4401 +#ifndef CONFIG_PAX_EMUSIGRT
4402 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4403 + return 1;
4404 +#endif
4405 +
4406 + do { /* PaX: rt_sigreturn emulation */
4407 + unsigned int ldi1, ldi2, bel, nop;
4408 +
4409 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4410 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4411 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4412 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4413 +
4414 + if (err)
4415 + break;
4416 +
4417 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4418 + ldi2 == 0x3414015AU &&
4419 + bel == 0xE4008200U &&
4420 + nop == 0x08000240U)
4421 + {
4422 + regs->gr[25] = (ldi1 & 2) >> 1;
4423 + regs->gr[20] = __NR_rt_sigreturn;
4424 + regs->gr[31] = regs->iaoq[1] + 16;
4425 + regs->sr[0] = regs->iasq[1];
4426 + regs->iaoq[0] = 0x100UL;
4427 + regs->iaoq[1] = regs->iaoq[0] + 4;
4428 + regs->iasq[0] = regs->sr[2];
4429 + regs->iasq[1] = regs->sr[2];
4430 + return 2;
4431 + }
4432 + } while (0);
4433 +#endif
4434 +
4435 + return 1;
4436 +}
4437 +
4438 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4439 +{
4440 + unsigned long i;
4441 +
4442 + printk(KERN_ERR "PAX: bytes at PC: ");
4443 + for (i = 0; i < 5; i++) {
4444 + unsigned int c;
4445 + if (get_user(c, (unsigned int *)pc+i))
4446 + printk(KERN_CONT "???????? ");
4447 + else
4448 + printk(KERN_CONT "%08x ", c);
4449 + }
4450 + printk("\n");
4451 +}
4452 +#endif
4453 +
4454 int fixup_exception(struct pt_regs *regs)
4455 {
4456 const struct exception_table_entry *fix;
4457 @@ -192,8 +303,33 @@ good_area:
4458
4459 acc_type = parisc_acctyp(code,regs->iir);
4460
4461 - if ((vma->vm_flags & acc_type) != acc_type)
4462 + if ((vma->vm_flags & acc_type) != acc_type) {
4463 +
4464 +#ifdef CONFIG_PAX_PAGEEXEC
4465 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4466 + (address & ~3UL) == instruction_pointer(regs))
4467 + {
4468 + up_read(&mm->mmap_sem);
4469 + switch (pax_handle_fetch_fault(regs)) {
4470 +
4471 +#ifdef CONFIG_PAX_EMUPLT
4472 + case 3:
4473 + return;
4474 +#endif
4475 +
4476 +#ifdef CONFIG_PAX_EMUTRAMP
4477 + case 2:
4478 + return;
4479 +#endif
4480 +
4481 + }
4482 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4483 + do_group_exit(SIGKILL);
4484 + }
4485 +#endif
4486 +
4487 goto bad_area;
4488 + }
4489
4490 /*
4491 * If for any reason at all we couldn't handle the fault, make
4492 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4493 index e3b1d41..8e81edf 100644
4494 --- a/arch/powerpc/include/asm/atomic.h
4495 +++ b/arch/powerpc/include/asm/atomic.h
4496 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4497 return t1;
4498 }
4499
4500 +#define atomic64_read_unchecked(v) atomic64_read(v)
4501 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4502 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4503 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4504 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4505 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4506 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4507 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4508 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4509 +
4510 #endif /* __powerpc64__ */
4511
4512 #endif /* __KERNEL__ */
4513 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4514 index 9e495c9..b6878e5 100644
4515 --- a/arch/powerpc/include/asm/cache.h
4516 +++ b/arch/powerpc/include/asm/cache.h
4517 @@ -3,6 +3,7 @@
4518
4519 #ifdef __KERNEL__
4520
4521 +#include <linux/const.h>
4522
4523 /* bytes per L1 cache line */
4524 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4525 @@ -22,7 +23,7 @@
4526 #define L1_CACHE_SHIFT 7
4527 #endif
4528
4529 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4530 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4531
4532 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4533
4534 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4535 index 6abf0a1..459d0f1 100644
4536 --- a/arch/powerpc/include/asm/elf.h
4537 +++ b/arch/powerpc/include/asm/elf.h
4538 @@ -28,8 +28,19 @@
4539 the loader. We need to make sure that it is out of the way of the program
4540 that it will "exec", and that there is sufficient room for the brk. */
4541
4542 -extern unsigned long randomize_et_dyn(unsigned long base);
4543 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4544 +#define ELF_ET_DYN_BASE (0x20000000)
4545 +
4546 +#ifdef CONFIG_PAX_ASLR
4547 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4548 +
4549 +#ifdef __powerpc64__
4550 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4551 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4552 +#else
4553 +#define PAX_DELTA_MMAP_LEN 15
4554 +#define PAX_DELTA_STACK_LEN 15
4555 +#endif
4556 +#endif
4557
4558 /*
4559 * Our registers are always unsigned longs, whether we're a 32 bit
4560 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4561 (0x7ff >> (PAGE_SHIFT - 12)) : \
4562 (0x3ffff >> (PAGE_SHIFT - 12)))
4563
4564 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4565 -#define arch_randomize_brk arch_randomize_brk
4566 -
4567 -
4568 #ifdef CONFIG_SPU_BASE
4569 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4570 #define NT_SPU 1
4571 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4572 index 8196e9c..d83a9f3 100644
4573 --- a/arch/powerpc/include/asm/exec.h
4574 +++ b/arch/powerpc/include/asm/exec.h
4575 @@ -4,6 +4,6 @@
4576 #ifndef _ASM_POWERPC_EXEC_H
4577 #define _ASM_POWERPC_EXEC_H
4578
4579 -extern unsigned long arch_align_stack(unsigned long sp);
4580 +#define arch_align_stack(x) ((x) & ~0xfUL)
4581
4582 #endif /* _ASM_POWERPC_EXEC_H */
4583 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4584 index 5acabbd..7ea14fa 100644
4585 --- a/arch/powerpc/include/asm/kmap_types.h
4586 +++ b/arch/powerpc/include/asm/kmap_types.h
4587 @@ -10,7 +10,7 @@
4588 * 2 of the License, or (at your option) any later version.
4589 */
4590
4591 -#define KM_TYPE_NR 16
4592 +#define KM_TYPE_NR 17
4593
4594 #endif /* __KERNEL__ */
4595 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4596 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4597 index 8565c25..2865190 100644
4598 --- a/arch/powerpc/include/asm/mman.h
4599 +++ b/arch/powerpc/include/asm/mman.h
4600 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4601 }
4602 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4603
4604 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4605 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4606 {
4607 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4608 }
4609 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4610 index f072e97..b436dee 100644
4611 --- a/arch/powerpc/include/asm/page.h
4612 +++ b/arch/powerpc/include/asm/page.h
4613 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4614 * and needs to be executable. This means the whole heap ends
4615 * up being executable.
4616 */
4617 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4618 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4619 +#define VM_DATA_DEFAULT_FLAGS32 \
4620 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4621 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4622
4623 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4624 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4625 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4626 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4627 #endif
4628
4629 +#define ktla_ktva(addr) (addr)
4630 +#define ktva_ktla(addr) (addr)
4631 +
4632 /*
4633 * Use the top bit of the higher-level page table entries to indicate whether
4634 * the entries we point to contain hugepages. This works because we know that
4635 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4636 index cd915d6..c10cee8 100644
4637 --- a/arch/powerpc/include/asm/page_64.h
4638 +++ b/arch/powerpc/include/asm/page_64.h
4639 @@ -154,15 +154,18 @@ do { \
4640 * stack by default, so in the absence of a PT_GNU_STACK program header
4641 * we turn execute permission off.
4642 */
4643 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4644 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4645 +#define VM_STACK_DEFAULT_FLAGS32 \
4646 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4647 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4648
4649 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4650 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4651
4652 +#ifndef CONFIG_PAX_PAGEEXEC
4653 #define VM_STACK_DEFAULT_FLAGS \
4654 (is_32bit_task() ? \
4655 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4656 +#endif
4657
4658 #include <asm-generic/getorder.h>
4659
4660 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4661 index 292725c..f87ae14 100644
4662 --- a/arch/powerpc/include/asm/pgalloc-64.h
4663 +++ b/arch/powerpc/include/asm/pgalloc-64.h
4664 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4665 #ifndef CONFIG_PPC_64K_PAGES
4666
4667 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4668 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4669
4670 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4671 {
4672 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4673 pud_set(pud, (unsigned long)pmd);
4674 }
4675
4676 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4677 +{
4678 + pud_populate(mm, pud, pmd);
4679 +}
4680 +
4681 #define pmd_populate(mm, pmd, pte_page) \
4682 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4683 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4684 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4685 #else /* CONFIG_PPC_64K_PAGES */
4686
4687 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4688 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4689
4690 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4691 pte_t *pte)
4692 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4693 index a9cbd3b..3b67efa 100644
4694 --- a/arch/powerpc/include/asm/pgtable.h
4695 +++ b/arch/powerpc/include/asm/pgtable.h
4696 @@ -2,6 +2,7 @@
4697 #define _ASM_POWERPC_PGTABLE_H
4698 #ifdef __KERNEL__
4699
4700 +#include <linux/const.h>
4701 #ifndef __ASSEMBLY__
4702 #include <asm/processor.h> /* For TASK_SIZE */
4703 #include <asm/mmu.h>
4704 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4705 index 4aad413..85d86bf 100644
4706 --- a/arch/powerpc/include/asm/pte-hash32.h
4707 +++ b/arch/powerpc/include/asm/pte-hash32.h
4708 @@ -21,6 +21,7 @@
4709 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4710 #define _PAGE_USER 0x004 /* usermode access allowed */
4711 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4712 +#define _PAGE_EXEC _PAGE_GUARDED
4713 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4714 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4715 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4716 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4717 index d24c141..b60696e 100644
4718 --- a/arch/powerpc/include/asm/reg.h
4719 +++ b/arch/powerpc/include/asm/reg.h
4720 @@ -215,6 +215,7 @@
4721 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4722 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4723 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4724 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4725 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4726 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4727 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4728 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4729 index 406b7b9..af63426 100644
4730 --- a/arch/powerpc/include/asm/thread_info.h
4731 +++ b/arch/powerpc/include/asm/thread_info.h
4732 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
4733 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
4734 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
4735 #define TIF_SINGLESTEP 8 /* singlestepping active */
4736 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
4737 #define TIF_SECCOMP 10 /* secure computing */
4738 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
4739 #define TIF_NOERROR 12 /* Force successful syscall return */
4740 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
4741 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
4742 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
4743 for stack store? */
4744 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
4745 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
4746 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
4747
4748 /* as above, but as bit values */
4749 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
4750 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
4751 #define _TIF_UPROBE (1<<TIF_UPROBE)
4752 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
4753 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
4754 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
4755 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
4756 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
4757 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
4758 + _TIF_GRSEC_SETXID)
4759
4760 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
4761 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
4762 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
4763 index 4db4959..335e00c 100644
4764 --- a/arch/powerpc/include/asm/uaccess.h
4765 +++ b/arch/powerpc/include/asm/uaccess.h
4766 @@ -13,6 +13,8 @@
4767 #define VERIFY_READ 0
4768 #define VERIFY_WRITE 1
4769
4770 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4771 +
4772 /*
4773 * The fs value determines whether argument validity checking should be
4774 * performed or not. If get_fs() == USER_DS, checking is performed, with
4775 @@ -318,52 +320,6 @@ do { \
4776 extern unsigned long __copy_tofrom_user(void __user *to,
4777 const void __user *from, unsigned long size);
4778
4779 -#ifndef __powerpc64__
4780 -
4781 -static inline unsigned long copy_from_user(void *to,
4782 - const void __user *from, unsigned long n)
4783 -{
4784 - unsigned long over;
4785 -
4786 - if (access_ok(VERIFY_READ, from, n))
4787 - return __copy_tofrom_user((__force void __user *)to, from, n);
4788 - if ((unsigned long)from < TASK_SIZE) {
4789 - over = (unsigned long)from + n - TASK_SIZE;
4790 - return __copy_tofrom_user((__force void __user *)to, from,
4791 - n - over) + over;
4792 - }
4793 - return n;
4794 -}
4795 -
4796 -static inline unsigned long copy_to_user(void __user *to,
4797 - const void *from, unsigned long n)
4798 -{
4799 - unsigned long over;
4800 -
4801 - if (access_ok(VERIFY_WRITE, to, n))
4802 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4803 - if ((unsigned long)to < TASK_SIZE) {
4804 - over = (unsigned long)to + n - TASK_SIZE;
4805 - return __copy_tofrom_user(to, (__force void __user *)from,
4806 - n - over) + over;
4807 - }
4808 - return n;
4809 -}
4810 -
4811 -#else /* __powerpc64__ */
4812 -
4813 -#define __copy_in_user(to, from, size) \
4814 - __copy_tofrom_user((to), (from), (size))
4815 -
4816 -extern unsigned long copy_from_user(void *to, const void __user *from,
4817 - unsigned long n);
4818 -extern unsigned long copy_to_user(void __user *to, const void *from,
4819 - unsigned long n);
4820 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4821 - unsigned long n);
4822 -
4823 -#endif /* __powerpc64__ */
4824 -
4825 static inline unsigned long __copy_from_user_inatomic(void *to,
4826 const void __user *from, unsigned long n)
4827 {
4828 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4829 if (ret == 0)
4830 return 0;
4831 }
4832 +
4833 + if (!__builtin_constant_p(n))
4834 + check_object_size(to, n, false);
4835 +
4836 return __copy_tofrom_user((__force void __user *)to, from, n);
4837 }
4838
4839 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4840 if (ret == 0)
4841 return 0;
4842 }
4843 +
4844 + if (!__builtin_constant_p(n))
4845 + check_object_size(from, n, true);
4846 +
4847 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4848 }
4849
4850 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4851 return __copy_to_user_inatomic(to, from, size);
4852 }
4853
4854 +#ifndef __powerpc64__
4855 +
4856 +static inline unsigned long __must_check copy_from_user(void *to,
4857 + const void __user *from, unsigned long n)
4858 +{
4859 + unsigned long over;
4860 +
4861 + if ((long)n < 0)
4862 + return n;
4863 +
4864 + if (access_ok(VERIFY_READ, from, n)) {
4865 + if (!__builtin_constant_p(n))
4866 + check_object_size(to, n, false);
4867 + return __copy_tofrom_user((__force void __user *)to, from, n);
4868 + }
4869 + if ((unsigned long)from < TASK_SIZE) {
4870 + over = (unsigned long)from + n - TASK_SIZE;
4871 + if (!__builtin_constant_p(n - over))
4872 + check_object_size(to, n - over, false);
4873 + return __copy_tofrom_user((__force void __user *)to, from,
4874 + n - over) + over;
4875 + }
4876 + return n;
4877 +}
4878 +
4879 +static inline unsigned long __must_check copy_to_user(void __user *to,
4880 + const void *from, unsigned long n)
4881 +{
4882 + unsigned long over;
4883 +
4884 + if ((long)n < 0)
4885 + return n;
4886 +
4887 + if (access_ok(VERIFY_WRITE, to, n)) {
4888 + if (!__builtin_constant_p(n))
4889 + check_object_size(from, n, true);
4890 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4891 + }
4892 + if ((unsigned long)to < TASK_SIZE) {
4893 + over = (unsigned long)to + n - TASK_SIZE;
4894 + if (!__builtin_constant_p(n))
4895 + check_object_size(from, n - over, true);
4896 + return __copy_tofrom_user(to, (__force void __user *)from,
4897 + n - over) + over;
4898 + }
4899 + return n;
4900 +}
4901 +
4902 +#else /* __powerpc64__ */
4903 +
4904 +#define __copy_in_user(to, from, size) \
4905 + __copy_tofrom_user((to), (from), (size))
4906 +
4907 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4908 +{
4909 + if ((long)n < 0 || n > INT_MAX)
4910 + return n;
4911 +
4912 + if (!__builtin_constant_p(n))
4913 + check_object_size(to, n, false);
4914 +
4915 + if (likely(access_ok(VERIFY_READ, from, n)))
4916 + n = __copy_from_user(to, from, n);
4917 + else
4918 + memset(to, 0, n);
4919 + return n;
4920 +}
4921 +
4922 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4923 +{
4924 + if ((long)n < 0 || n > INT_MAX)
4925 + return n;
4926 +
4927 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4928 + if (!__builtin_constant_p(n))
4929 + check_object_size(from, n, true);
4930 + n = __copy_to_user(to, from, n);
4931 + }
4932 + return n;
4933 +}
4934 +
4935 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4936 + unsigned long n);
4937 +
4938 +#endif /* __powerpc64__ */
4939 +
4940 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4941
4942 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4943 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4944 index 4684e33..acc4d19e 100644
4945 --- a/arch/powerpc/kernel/exceptions-64e.S
4946 +++ b/arch/powerpc/kernel/exceptions-64e.S
4947 @@ -715,6 +715,7 @@ storage_fault_common:
4948 std r14,_DAR(r1)
4949 std r15,_DSISR(r1)
4950 addi r3,r1,STACK_FRAME_OVERHEAD
4951 + bl .save_nvgprs
4952 mr r4,r14
4953 mr r5,r15
4954 ld r14,PACA_EXGEN+EX_R14(r13)
4955 @@ -723,8 +724,7 @@ storage_fault_common:
4956 cmpdi r3,0
4957 bne- 1f
4958 b .ret_from_except_lite
4959 -1: bl .save_nvgprs
4960 - mr r5,r3
4961 +1: mr r5,r3
4962 addi r3,r1,STACK_FRAME_OVERHEAD
4963 ld r4,_DAR(r1)
4964 bl .bad_page_fault
4965 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4966 index 10b658a..e542888 100644
4967 --- a/arch/powerpc/kernel/exceptions-64s.S
4968 +++ b/arch/powerpc/kernel/exceptions-64s.S
4969 @@ -1013,10 +1013,10 @@ handle_page_fault:
4970 11: ld r4,_DAR(r1)
4971 ld r5,_DSISR(r1)
4972 addi r3,r1,STACK_FRAME_OVERHEAD
4973 + bl .save_nvgprs
4974 bl .do_page_fault
4975 cmpdi r3,0
4976 beq+ 12f
4977 - bl .save_nvgprs
4978 mr r5,r3
4979 addi r3,r1,STACK_FRAME_OVERHEAD
4980 lwz r4,_DAR(r1)
4981 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4982 index 2e3200c..72095ce 100644
4983 --- a/arch/powerpc/kernel/module_32.c
4984 +++ b/arch/powerpc/kernel/module_32.c
4985 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4986 me->arch.core_plt_section = i;
4987 }
4988 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4989 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4990 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4991 return -ENOEXEC;
4992 }
4993
4994 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4995
4996 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4997 /* Init, or core PLT? */
4998 - if (location >= mod->module_core
4999 - && location < mod->module_core + mod->core_size)
5000 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5001 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5002 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5003 - else
5004 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5005 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5006 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5007 + else {
5008 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5009 + return ~0UL;
5010 + }
5011
5012 /* Find this entry, or if that fails, the next avail. entry */
5013 while (entry->jump[0]) {
5014 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5015 index ba48233..16ac31d 100644
5016 --- a/arch/powerpc/kernel/process.c
5017 +++ b/arch/powerpc/kernel/process.c
5018 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5019 * Lookup NIP late so we have the best change of getting the
5020 * above info out without failing
5021 */
5022 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5023 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5024 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5025 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5026 #endif
5027 show_stack(current, (unsigned long *) regs->gpr[1]);
5028 if (!user_mode(regs))
5029 @@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5030 newsp = stack[0];
5031 ip = stack[STACK_FRAME_LR_SAVE];
5032 if (!firstframe || ip != lr) {
5033 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5034 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5035 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5036 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5037 - printk(" (%pS)",
5038 + printk(" (%pA)",
5039 (void *)current->ret_stack[curr_frame].ret);
5040 curr_frame--;
5041 }
5042 @@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5043 struct pt_regs *regs = (struct pt_regs *)
5044 (sp + STACK_FRAME_OVERHEAD);
5045 lr = regs->link;
5046 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
5047 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
5048 regs->trap, (void *)regs->nip, (void *)lr);
5049 firstframe = 1;
5050 }
5051 @@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5052 mtspr(SPRN_CTRLT, ctrl);
5053 }
5054 #endif /* CONFIG_PPC64 */
5055 -
5056 -unsigned long arch_align_stack(unsigned long sp)
5057 -{
5058 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5059 - sp -= get_random_int() & ~PAGE_MASK;
5060 - return sp & ~0xf;
5061 -}
5062 -
5063 -static inline unsigned long brk_rnd(void)
5064 -{
5065 - unsigned long rnd = 0;
5066 -
5067 - /* 8MB for 32bit, 1GB for 64bit */
5068 - if (is_32bit_task())
5069 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5070 - else
5071 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5072 -
5073 - return rnd << PAGE_SHIFT;
5074 -}
5075 -
5076 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5077 -{
5078 - unsigned long base = mm->brk;
5079 - unsigned long ret;
5080 -
5081 -#ifdef CONFIG_PPC_STD_MMU_64
5082 - /*
5083 - * If we are using 1TB segments and we are allowed to randomise
5084 - * the heap, we can put it above 1TB so it is backed by a 1TB
5085 - * segment. Otherwise the heap will be in the bottom 1TB
5086 - * which always uses 256MB segments and this may result in a
5087 - * performance penalty.
5088 - */
5089 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5090 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5091 -#endif
5092 -
5093 - ret = PAGE_ALIGN(base + brk_rnd());
5094 -
5095 - if (ret < mm->brk)
5096 - return mm->brk;
5097 -
5098 - return ret;
5099 -}
5100 -
5101 -unsigned long randomize_et_dyn(unsigned long base)
5102 -{
5103 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5104 -
5105 - if (ret < base)
5106 - return base;
5107 -
5108 - return ret;
5109 -}
5110 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5111 index 79d8e56..38ffcbb 100644
5112 --- a/arch/powerpc/kernel/ptrace.c
5113 +++ b/arch/powerpc/kernel/ptrace.c
5114 @@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5115 return ret;
5116 }
5117
5118 +#ifdef CONFIG_GRKERNSEC_SETXID
5119 +extern void gr_delayed_cred_worker(void);
5120 +#endif
5121 +
5122 /*
5123 * We must return the syscall number to actually look up in the table.
5124 * This can be -1L to skip running any syscall at all.
5125 @@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5126
5127 secure_computing_strict(regs->gpr[0]);
5128
5129 +#ifdef CONFIG_GRKERNSEC_SETXID
5130 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5131 + gr_delayed_cred_worker();
5132 +#endif
5133 +
5134 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5135 tracehook_report_syscall_entry(regs))
5136 /*
5137 @@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5138 {
5139 int step;
5140
5141 +#ifdef CONFIG_GRKERNSEC_SETXID
5142 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5143 + gr_delayed_cred_worker();
5144 +#endif
5145 +
5146 audit_syscall_exit(regs);
5147
5148 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5149 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5150 index 804e323..79181c1 100644
5151 --- a/arch/powerpc/kernel/signal_32.c
5152 +++ b/arch/powerpc/kernel/signal_32.c
5153 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5154 /* Save user registers on the stack */
5155 frame = &rt_sf->uc.uc_mcontext;
5156 addr = frame;
5157 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5158 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5159 if (save_user_regs(regs, frame, 0, 1))
5160 goto badframe;
5161 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5162 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5163 index d183f87..1867f1a 100644
5164 --- a/arch/powerpc/kernel/signal_64.c
5165 +++ b/arch/powerpc/kernel/signal_64.c
5166 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5167 current->thread.fpscr.val = 0;
5168
5169 /* Set up to return from userspace. */
5170 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5171 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5172 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5173 } else {
5174 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5175 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5176 index 3251840..3f7c77a 100644
5177 --- a/arch/powerpc/kernel/traps.c
5178 +++ b/arch/powerpc/kernel/traps.c
5179 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5180 return flags;
5181 }
5182
5183 +extern void gr_handle_kernel_exploit(void);
5184 +
5185 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5186 int signr)
5187 {
5188 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5189 panic("Fatal exception in interrupt");
5190 if (panic_on_oops)
5191 panic("Fatal exception");
5192 +
5193 + gr_handle_kernel_exploit();
5194 +
5195 do_exit(signr);
5196 }
5197
5198 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5199 index 1b2076f..835e4be 100644
5200 --- a/arch/powerpc/kernel/vdso.c
5201 +++ b/arch/powerpc/kernel/vdso.c
5202 @@ -34,6 +34,7 @@
5203 #include <asm/firmware.h>
5204 #include <asm/vdso.h>
5205 #include <asm/vdso_datapage.h>
5206 +#include <asm/mman.h>
5207
5208 #include "setup.h"
5209
5210 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5211 vdso_base = VDSO32_MBASE;
5212 #endif
5213
5214 - current->mm->context.vdso_base = 0;
5215 + current->mm->context.vdso_base = ~0UL;
5216
5217 /* vDSO has a problem and was disabled, just don't "enable" it for the
5218 * process
5219 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5220 vdso_base = get_unmapped_area(NULL, vdso_base,
5221 (vdso_pages << PAGE_SHIFT) +
5222 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5223 - 0, 0);
5224 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
5225 if (IS_ERR_VALUE(vdso_base)) {
5226 rc = vdso_base;
5227 goto fail_mmapsem;
5228 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5229 index 5eea6f3..5d10396 100644
5230 --- a/arch/powerpc/lib/usercopy_64.c
5231 +++ b/arch/powerpc/lib/usercopy_64.c
5232 @@ -9,22 +9,6 @@
5233 #include <linux/module.h>
5234 #include <asm/uaccess.h>
5235
5236 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5237 -{
5238 - if (likely(access_ok(VERIFY_READ, from, n)))
5239 - n = __copy_from_user(to, from, n);
5240 - else
5241 - memset(to, 0, n);
5242 - return n;
5243 -}
5244 -
5245 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5246 -{
5247 - if (likely(access_ok(VERIFY_WRITE, to, n)))
5248 - n = __copy_to_user(to, from, n);
5249 - return n;
5250 -}
5251 -
5252 unsigned long copy_in_user(void __user *to, const void __user *from,
5253 unsigned long n)
5254 {
5255 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5256 return n;
5257 }
5258
5259 -EXPORT_SYMBOL(copy_from_user);
5260 -EXPORT_SYMBOL(copy_to_user);
5261 EXPORT_SYMBOL(copy_in_user);
5262
5263 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5264 index 0a6b283..7674925 100644
5265 --- a/arch/powerpc/mm/fault.c
5266 +++ b/arch/powerpc/mm/fault.c
5267 @@ -32,6 +32,10 @@
5268 #include <linux/perf_event.h>
5269 #include <linux/magic.h>
5270 #include <linux/ratelimit.h>
5271 +#include <linux/slab.h>
5272 +#include <linux/pagemap.h>
5273 +#include <linux/compiler.h>
5274 +#include <linux/unistd.h>
5275
5276 #include <asm/firmware.h>
5277 #include <asm/page.h>
5278 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5279 }
5280 #endif
5281
5282 +#ifdef CONFIG_PAX_PAGEEXEC
5283 +/*
5284 + * PaX: decide what to do with offenders (regs->nip = fault address)
5285 + *
5286 + * returns 1 when task should be killed
5287 + */
5288 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5289 +{
5290 + return 1;
5291 +}
5292 +
5293 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5294 +{
5295 + unsigned long i;
5296 +
5297 + printk(KERN_ERR "PAX: bytes at PC: ");
5298 + for (i = 0; i < 5; i++) {
5299 + unsigned int c;
5300 + if (get_user(c, (unsigned int __user *)pc+i))
5301 + printk(KERN_CONT "???????? ");
5302 + else
5303 + printk(KERN_CONT "%08x ", c);
5304 + }
5305 + printk("\n");
5306 +}
5307 +#endif
5308 +
5309 /*
5310 * Check whether the instruction at regs->nip is a store using
5311 * an update addressing form which will update r1.
5312 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5313 * indicate errors in DSISR but can validly be set in SRR1.
5314 */
5315 if (trap == 0x400)
5316 - error_code &= 0x48200000;
5317 + error_code &= 0x58200000;
5318 else
5319 is_write = error_code & DSISR_ISSTORE;
5320 #else
5321 @@ -367,7 +398,7 @@ good_area:
5322 * "undefined". Of those that can be set, this is the only
5323 * one which seems bad.
5324 */
5325 - if (error_code & 0x10000000)
5326 + if (error_code & DSISR_GUARDED)
5327 /* Guarded storage error. */
5328 goto bad_area;
5329 #endif /* CONFIG_8xx */
5330 @@ -382,7 +413,7 @@ good_area:
5331 * processors use the same I/D cache coherency mechanism
5332 * as embedded.
5333 */
5334 - if (error_code & DSISR_PROTFAULT)
5335 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5336 goto bad_area;
5337 #endif /* CONFIG_PPC_STD_MMU */
5338
5339 @@ -465,6 +496,23 @@ bad_area:
5340 bad_area_nosemaphore:
5341 /* User mode accesses cause a SIGSEGV */
5342 if (user_mode(regs)) {
5343 +
5344 +#ifdef CONFIG_PAX_PAGEEXEC
5345 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5346 +#ifdef CONFIG_PPC_STD_MMU
5347 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5348 +#else
5349 + if (is_exec && regs->nip == address) {
5350 +#endif
5351 + switch (pax_handle_fetch_fault(regs)) {
5352 + }
5353 +
5354 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5355 + do_group_exit(SIGKILL);
5356 + }
5357 + }
5358 +#endif
5359 +
5360 _exception(SIGSEGV, regs, code, address);
5361 return 0;
5362 }
5363 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5364 index 67a42ed..1c7210c 100644
5365 --- a/arch/powerpc/mm/mmap_64.c
5366 +++ b/arch/powerpc/mm/mmap_64.c
5367 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5368 */
5369 if (mmap_is_legacy()) {
5370 mm->mmap_base = TASK_UNMAPPED_BASE;
5371 +
5372 +#ifdef CONFIG_PAX_RANDMMAP
5373 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5374 + mm->mmap_base += mm->delta_mmap;
5375 +#endif
5376 +
5377 mm->get_unmapped_area = arch_get_unmapped_area;
5378 mm->unmap_area = arch_unmap_area;
5379 } else {
5380 mm->mmap_base = mmap_base();
5381 +
5382 +#ifdef CONFIG_PAX_RANDMMAP
5383 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5384 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5385 +#endif
5386 +
5387 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5388 mm->unmap_area = arch_unmap_area_topdown;
5389 }
5390 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5391 index 5829d2a..b64ed2e 100644
5392 --- a/arch/powerpc/mm/slice.c
5393 +++ b/arch/powerpc/mm/slice.c
5394 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5395 if ((mm->task_size - len) < addr)
5396 return 0;
5397 vma = find_vma(mm, addr);
5398 - return (!vma || (addr + len) <= vma->vm_start);
5399 + return check_heap_stack_gap(vma, addr, len);
5400 }
5401
5402 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5403 @@ -272,7 +272,7 @@ full_search:
5404 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5405 continue;
5406 }
5407 - if (!vma || addr + len <= vma->vm_start) {
5408 + if (check_heap_stack_gap(vma, addr, len)) {
5409 /*
5410 * Remember the place where we stopped the search:
5411 */
5412 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5413 }
5414 }
5415
5416 - addr = mm->mmap_base;
5417 - while (addr > len) {
5418 + if (mm->mmap_base < len)
5419 + addr = -ENOMEM;
5420 + else
5421 + addr = mm->mmap_base - len;
5422 +
5423 + while (!IS_ERR_VALUE(addr)) {
5424 /* Go down by chunk size */
5425 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5426 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
5427
5428 /* Check for hit with different page size */
5429 mask = slice_range_to_mask(addr, len);
5430 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5431 * return with success:
5432 */
5433 vma = find_vma(mm, addr);
5434 - if (!vma || (addr + len) <= vma->vm_start) {
5435 + if (check_heap_stack_gap(vma, addr, len)) {
5436 /* remember the address as a hint for next time */
5437 if (use_cache)
5438 mm->free_area_cache = addr;
5439 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5440 mm->cached_hole_size = vma->vm_start - addr;
5441
5442 /* try just below the current vma->vm_start */
5443 - addr = vma->vm_start;
5444 + addr = skip_heap_stack_gap(vma, len);
5445 }
5446
5447 /*
5448 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5449 if (fixed && addr > (mm->task_size - len))
5450 return -EINVAL;
5451
5452 +#ifdef CONFIG_PAX_RANDMMAP
5453 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5454 + addr = 0;
5455 +#endif
5456 +
5457 /* If hint, make sure it matches our alignment restrictions */
5458 if (!fixed && addr) {
5459 addr = _ALIGN_UP(addr, 1ul << pshift);
5460 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5461 index c797832..ce575c8 100644
5462 --- a/arch/s390/include/asm/atomic.h
5463 +++ b/arch/s390/include/asm/atomic.h
5464 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5465 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5466 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5467
5468 +#define atomic64_read_unchecked(v) atomic64_read(v)
5469 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5470 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5471 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5472 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5473 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5474 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5475 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5476 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5477 +
5478 #define smp_mb__before_atomic_dec() smp_mb()
5479 #define smp_mb__after_atomic_dec() smp_mb()
5480 #define smp_mb__before_atomic_inc() smp_mb()
5481 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5482 index 4d7ccac..d03d0ad 100644
5483 --- a/arch/s390/include/asm/cache.h
5484 +++ b/arch/s390/include/asm/cache.h
5485 @@ -9,8 +9,10 @@
5486 #ifndef __ARCH_S390_CACHE_H
5487 #define __ARCH_S390_CACHE_H
5488
5489 -#define L1_CACHE_BYTES 256
5490 +#include <linux/const.h>
5491 +
5492 #define L1_CACHE_SHIFT 8
5493 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5494 #define NET_SKB_PAD 32
5495
5496 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5497 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5498 index 178ff96..8c93bd1 100644
5499 --- a/arch/s390/include/asm/elf.h
5500 +++ b/arch/s390/include/asm/elf.h
5501 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5502 the loader. We need to make sure that it is out of the way of the program
5503 that it will "exec", and that there is sufficient room for the brk. */
5504
5505 -extern unsigned long randomize_et_dyn(unsigned long base);
5506 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5507 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5508 +
5509 +#ifdef CONFIG_PAX_ASLR
5510 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5511 +
5512 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5513 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5514 +#endif
5515
5516 /* This yields a mask that user programs can use to figure out what
5517 instruction set this CPU supports. */
5518 @@ -210,9 +216,6 @@ struct linux_binprm;
5519 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5520 int arch_setup_additional_pages(struct linux_binprm *, int);
5521
5522 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5523 -#define arch_randomize_brk arch_randomize_brk
5524 -
5525 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5526
5527 #endif
5528 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5529 index c4a93d6..4d2a9b4 100644
5530 --- a/arch/s390/include/asm/exec.h
5531 +++ b/arch/s390/include/asm/exec.h
5532 @@ -7,6 +7,6 @@
5533 #ifndef __ASM_EXEC_H
5534 #define __ASM_EXEC_H
5535
5536 -extern unsigned long arch_align_stack(unsigned long sp);
5537 +#define arch_align_stack(x) ((x) & ~0xfUL)
5538
5539 #endif /* __ASM_EXEC_H */
5540 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5541 index 34268df..ea97318 100644
5542 --- a/arch/s390/include/asm/uaccess.h
5543 +++ b/arch/s390/include/asm/uaccess.h
5544 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
5545 copy_to_user(void __user *to, const void *from, unsigned long n)
5546 {
5547 might_fault();
5548 +
5549 + if ((long)n < 0)
5550 + return n;
5551 +
5552 if (access_ok(VERIFY_WRITE, to, n))
5553 n = __copy_to_user(to, from, n);
5554 return n;
5555 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5556 static inline unsigned long __must_check
5557 __copy_from_user(void *to, const void __user *from, unsigned long n)
5558 {
5559 + if ((long)n < 0)
5560 + return n;
5561 +
5562 if (__builtin_constant_p(n) && (n <= 256))
5563 return uaccess.copy_from_user_small(n, from, to);
5564 else
5565 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5566 static inline unsigned long __must_check
5567 copy_from_user(void *to, const void __user *from, unsigned long n)
5568 {
5569 - unsigned int sz = __compiletime_object_size(to);
5570 + size_t sz = __compiletime_object_size(to);
5571
5572 might_fault();
5573 - if (unlikely(sz != -1 && sz < n)) {
5574 +
5575 + if ((long)n < 0)
5576 + return n;
5577 +
5578 + if (unlikely(sz != (size_t)-1 && sz < n)) {
5579 copy_from_user_overflow();
5580 return n;
5581 }
5582 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5583 index 4610dea..cf0af21 100644
5584 --- a/arch/s390/kernel/module.c
5585 +++ b/arch/s390/kernel/module.c
5586 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5587
5588 /* Increase core size by size of got & plt and set start
5589 offsets for got and plt. */
5590 - me->core_size = ALIGN(me->core_size, 4);
5591 - me->arch.got_offset = me->core_size;
5592 - me->core_size += me->arch.got_size;
5593 - me->arch.plt_offset = me->core_size;
5594 - me->core_size += me->arch.plt_size;
5595 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
5596 + me->arch.got_offset = me->core_size_rw;
5597 + me->core_size_rw += me->arch.got_size;
5598 + me->arch.plt_offset = me->core_size_rx;
5599 + me->core_size_rx += me->arch.plt_size;
5600 return 0;
5601 }
5602
5603 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5604 if (info->got_initialized == 0) {
5605 Elf_Addr *gotent;
5606
5607 - gotent = me->module_core + me->arch.got_offset +
5608 + gotent = me->module_core_rw + me->arch.got_offset +
5609 info->got_offset;
5610 *gotent = val;
5611 info->got_initialized = 1;
5612 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5613 else if (r_type == R_390_GOTENT ||
5614 r_type == R_390_GOTPLTENT)
5615 *(unsigned int *) loc =
5616 - (val + (Elf_Addr) me->module_core - loc) >> 1;
5617 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5618 else if (r_type == R_390_GOT64 ||
5619 r_type == R_390_GOTPLT64)
5620 *(unsigned long *) loc = val;
5621 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5622 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5623 if (info->plt_initialized == 0) {
5624 unsigned int *ip;
5625 - ip = me->module_core + me->arch.plt_offset +
5626 + ip = me->module_core_rx + me->arch.plt_offset +
5627 info->plt_offset;
5628 #ifndef CONFIG_64BIT
5629 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5630 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5631 val - loc + 0xffffUL < 0x1ffffeUL) ||
5632 (r_type == R_390_PLT32DBL &&
5633 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5634 - val = (Elf_Addr) me->module_core +
5635 + val = (Elf_Addr) me->module_core_rx +
5636 me->arch.plt_offset +
5637 info->plt_offset;
5638 val += rela->r_addend - loc;
5639 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5640 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5641 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5642 val = val + rela->r_addend -
5643 - ((Elf_Addr) me->module_core + me->arch.got_offset);
5644 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5645 if (r_type == R_390_GOTOFF16)
5646 *(unsigned short *) loc = val;
5647 else if (r_type == R_390_GOTOFF32)
5648 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5649 break;
5650 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5651 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5652 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
5653 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5654 rela->r_addend - loc;
5655 if (r_type == R_390_GOTPC)
5656 *(unsigned int *) loc = val;
5657 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5658 index cd31ad4..201c5a3 100644
5659 --- a/arch/s390/kernel/process.c
5660 +++ b/arch/s390/kernel/process.c
5661 @@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5662 }
5663 return 0;
5664 }
5665 -
5666 -unsigned long arch_align_stack(unsigned long sp)
5667 -{
5668 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5669 - sp -= get_random_int() & ~PAGE_MASK;
5670 - return sp & ~0xf;
5671 -}
5672 -
5673 -static inline unsigned long brk_rnd(void)
5674 -{
5675 - /* 8MB for 32bit, 1GB for 64bit */
5676 - if (is_32bit_task())
5677 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5678 - else
5679 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5680 -}
5681 -
5682 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5683 -{
5684 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5685 -
5686 - if (ret < mm->brk)
5687 - return mm->brk;
5688 - return ret;
5689 -}
5690 -
5691 -unsigned long randomize_et_dyn(unsigned long base)
5692 -{
5693 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5694 -
5695 - if (!(current->flags & PF_RANDOMIZE))
5696 - return base;
5697 - if (ret < base)
5698 - return base;
5699 - return ret;
5700 -}
5701 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5702 index c59a5ef..3fae59c 100644
5703 --- a/arch/s390/mm/mmap.c
5704 +++ b/arch/s390/mm/mmap.c
5705 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5706 */
5707 if (mmap_is_legacy()) {
5708 mm->mmap_base = TASK_UNMAPPED_BASE;
5709 +
5710 +#ifdef CONFIG_PAX_RANDMMAP
5711 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5712 + mm->mmap_base += mm->delta_mmap;
5713 +#endif
5714 +
5715 mm->get_unmapped_area = arch_get_unmapped_area;
5716 mm->unmap_area = arch_unmap_area;
5717 } else {
5718 mm->mmap_base = mmap_base();
5719 +
5720 +#ifdef CONFIG_PAX_RANDMMAP
5721 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5722 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5723 +#endif
5724 +
5725 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5726 mm->unmap_area = arch_unmap_area_topdown;
5727 }
5728 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5729 */
5730 if (mmap_is_legacy()) {
5731 mm->mmap_base = TASK_UNMAPPED_BASE;
5732 +
5733 +#ifdef CONFIG_PAX_RANDMMAP
5734 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5735 + mm->mmap_base += mm->delta_mmap;
5736 +#endif
5737 +
5738 mm->get_unmapped_area = s390_get_unmapped_area;
5739 mm->unmap_area = arch_unmap_area;
5740 } else {
5741 mm->mmap_base = mmap_base();
5742 +
5743 +#ifdef CONFIG_PAX_RANDMMAP
5744 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5745 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5746 +#endif
5747 +
5748 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
5749 mm->unmap_area = arch_unmap_area_topdown;
5750 }
5751 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
5752 index ae3d59f..f65f075 100644
5753 --- a/arch/score/include/asm/cache.h
5754 +++ b/arch/score/include/asm/cache.h
5755 @@ -1,7 +1,9 @@
5756 #ifndef _ASM_SCORE_CACHE_H
5757 #define _ASM_SCORE_CACHE_H
5758
5759 +#include <linux/const.h>
5760 +
5761 #define L1_CACHE_SHIFT 4
5762 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5763 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5764
5765 #endif /* _ASM_SCORE_CACHE_H */
5766 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
5767 index f9f3cd5..58ff438 100644
5768 --- a/arch/score/include/asm/exec.h
5769 +++ b/arch/score/include/asm/exec.h
5770 @@ -1,6 +1,6 @@
5771 #ifndef _ASM_SCORE_EXEC_H
5772 #define _ASM_SCORE_EXEC_H
5773
5774 -extern unsigned long arch_align_stack(unsigned long sp);
5775 +#define arch_align_stack(x) (x)
5776
5777 #endif /* _ASM_SCORE_EXEC_H */
5778 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5779 index 637970c..0b6556b 100644
5780 --- a/arch/score/kernel/process.c
5781 +++ b/arch/score/kernel/process.c
5782 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
5783
5784 return task_pt_regs(task)->cp0_epc;
5785 }
5786 -
5787 -unsigned long arch_align_stack(unsigned long sp)
5788 -{
5789 - return sp;
5790 -}
5791 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5792 index ef9e555..331bd29 100644
5793 --- a/arch/sh/include/asm/cache.h
5794 +++ b/arch/sh/include/asm/cache.h
5795 @@ -9,10 +9,11 @@
5796 #define __ASM_SH_CACHE_H
5797 #ifdef __KERNEL__
5798
5799 +#include <linux/const.h>
5800 #include <linux/init.h>
5801 #include <cpu/cache.h>
5802
5803 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5804 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5805
5806 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5807
5808 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5809 index afeb710..d1d1289 100644
5810 --- a/arch/sh/mm/mmap.c
5811 +++ b/arch/sh/mm/mmap.c
5812 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5813 addr = PAGE_ALIGN(addr);
5814
5815 vma = find_vma(mm, addr);
5816 - if (TASK_SIZE - len >= addr &&
5817 - (!vma || addr + len <= vma->vm_start))
5818 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5819 return addr;
5820 }
5821
5822 @@ -106,7 +105,7 @@ full_search:
5823 }
5824 return -ENOMEM;
5825 }
5826 - if (likely(!vma || addr + len <= vma->vm_start)) {
5827 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5828 /*
5829 * Remember the place where we stopped the search:
5830 */
5831 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5832 addr = PAGE_ALIGN(addr);
5833
5834 vma = find_vma(mm, addr);
5835 - if (TASK_SIZE - len >= addr &&
5836 - (!vma || addr + len <= vma->vm_start))
5837 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5838 return addr;
5839 }
5840
5841 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5842 /* make sure it can fit in the remaining address space */
5843 if (likely(addr > len)) {
5844 vma = find_vma(mm, addr-len);
5845 - if (!vma || addr <= vma->vm_start) {
5846 + if (check_heap_stack_gap(vma, addr - len, len)) {
5847 /* remember the address as a hint for next time */
5848 return (mm->free_area_cache = addr-len);
5849 }
5850 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5851 if (unlikely(mm->mmap_base < len))
5852 goto bottomup;
5853
5854 - addr = mm->mmap_base-len;
5855 - if (do_colour_align)
5856 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5857 + addr = mm->mmap_base - len;
5858
5859 do {
5860 + if (do_colour_align)
5861 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5862 /*
5863 * Lookup failure means no vma is above this address,
5864 * else if new region fits below vma->vm_start,
5865 * return with success:
5866 */
5867 vma = find_vma(mm, addr);
5868 - if (likely(!vma || addr+len <= vma->vm_start)) {
5869 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5870 /* remember the address as a hint for next time */
5871 return (mm->free_area_cache = addr);
5872 }
5873 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5874 mm->cached_hole_size = vma->vm_start - addr;
5875
5876 /* try just below the current vma->vm_start */
5877 - addr = vma->vm_start-len;
5878 - if (do_colour_align)
5879 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5880 - } while (likely(len < vma->vm_start));
5881 + addr = skip_heap_stack_gap(vma, len);
5882 + } while (!IS_ERR_VALUE(addr));
5883
5884 bottomup:
5885 /*
5886 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5887 index be56a24..443328f 100644
5888 --- a/arch/sparc/include/asm/atomic_64.h
5889 +++ b/arch/sparc/include/asm/atomic_64.h
5890 @@ -14,18 +14,40 @@
5891 #define ATOMIC64_INIT(i) { (i) }
5892
5893 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5894 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5895 +{
5896 + return v->counter;
5897 +}
5898 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5899 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5900 +{
5901 + return v->counter;
5902 +}
5903
5904 #define atomic_set(v, i) (((v)->counter) = i)
5905 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5906 +{
5907 + v->counter = i;
5908 +}
5909 #define atomic64_set(v, i) (((v)->counter) = i)
5910 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5911 +{
5912 + v->counter = i;
5913 +}
5914
5915 extern void atomic_add(int, atomic_t *);
5916 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5917 extern void atomic64_add(long, atomic64_t *);
5918 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5919 extern void atomic_sub(int, atomic_t *);
5920 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5921 extern void atomic64_sub(long, atomic64_t *);
5922 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5923
5924 extern int atomic_add_ret(int, atomic_t *);
5925 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5926 extern long atomic64_add_ret(long, atomic64_t *);
5927 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5928 extern int atomic_sub_ret(int, atomic_t *);
5929 extern long atomic64_sub_ret(long, atomic64_t *);
5930
5931 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5932 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5933
5934 #define atomic_inc_return(v) atomic_add_ret(1, v)
5935 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5936 +{
5937 + return atomic_add_ret_unchecked(1, v);
5938 +}
5939 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5940 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5941 +{
5942 + return atomic64_add_ret_unchecked(1, v);
5943 +}
5944
5945 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5946 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5947
5948 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5949 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5950 +{
5951 + return atomic_add_ret_unchecked(i, v);
5952 +}
5953 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5954 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5955 +{
5956 + return atomic64_add_ret_unchecked(i, v);
5957 +}
5958
5959 /*
5960 * atomic_inc_and_test - increment and test
5961 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5962 * other cases.
5963 */
5964 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5965 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5966 +{
5967 + return atomic_inc_return_unchecked(v) == 0;
5968 +}
5969 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5970
5971 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5972 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5973 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5974
5975 #define atomic_inc(v) atomic_add(1, v)
5976 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5977 +{
5978 + atomic_add_unchecked(1, v);
5979 +}
5980 #define atomic64_inc(v) atomic64_add(1, v)
5981 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5982 +{
5983 + atomic64_add_unchecked(1, v);
5984 +}
5985
5986 #define atomic_dec(v) atomic_sub(1, v)
5987 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5988 +{
5989 + atomic_sub_unchecked(1, v);
5990 +}
5991 #define atomic64_dec(v) atomic64_sub(1, v)
5992 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5993 +{
5994 + atomic64_sub_unchecked(1, v);
5995 +}
5996
5997 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5998 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5999
6000 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6001 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6002 +{
6003 + return cmpxchg(&v->counter, old, new);
6004 +}
6005 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6006 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6007 +{
6008 + return xchg(&v->counter, new);
6009 +}
6010
6011 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6012 {
6013 - int c, old;
6014 + int c, old, new;
6015 c = atomic_read(v);
6016 for (;;) {
6017 - if (unlikely(c == (u)))
6018 + if (unlikely(c == u))
6019 break;
6020 - old = atomic_cmpxchg((v), c, c + (a));
6021 +
6022 + asm volatile("addcc %2, %0, %0\n"
6023 +
6024 +#ifdef CONFIG_PAX_REFCOUNT
6025 + "tvs %%icc, 6\n"
6026 +#endif
6027 +
6028 + : "=r" (new)
6029 + : "0" (c), "ir" (a)
6030 + : "cc");
6031 +
6032 + old = atomic_cmpxchg(v, c, new);
6033 if (likely(old == c))
6034 break;
6035 c = old;
6036 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6037 #define atomic64_cmpxchg(v, o, n) \
6038 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6039 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6040 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6041 +{
6042 + return xchg(&v->counter, new);
6043 +}
6044
6045 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6046 {
6047 - long c, old;
6048 + long c, old, new;
6049 c = atomic64_read(v);
6050 for (;;) {
6051 - if (unlikely(c == (u)))
6052 + if (unlikely(c == u))
6053 break;
6054 - old = atomic64_cmpxchg((v), c, c + (a));
6055 +
6056 + asm volatile("addcc %2, %0, %0\n"
6057 +
6058 +#ifdef CONFIG_PAX_REFCOUNT
6059 + "tvs %%xcc, 6\n"
6060 +#endif
6061 +
6062 + : "=r" (new)
6063 + : "0" (c), "ir" (a)
6064 + : "cc");
6065 +
6066 + old = atomic64_cmpxchg(v, c, new);
6067 if (likely(old == c))
6068 break;
6069 c = old;
6070 }
6071 - return c != (u);
6072 + return c != u;
6073 }
6074
6075 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6076 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6077 index 5bb6991..5c2132e 100644
6078 --- a/arch/sparc/include/asm/cache.h
6079 +++ b/arch/sparc/include/asm/cache.h
6080 @@ -7,10 +7,12 @@
6081 #ifndef _SPARC_CACHE_H
6082 #define _SPARC_CACHE_H
6083
6084 +#include <linux/const.h>
6085 +
6086 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6087
6088 #define L1_CACHE_SHIFT 5
6089 -#define L1_CACHE_BYTES 32
6090 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6091
6092 #ifdef CONFIG_SPARC32
6093 #define SMP_CACHE_BYTES_SHIFT 5
6094 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6095 index ac74a2c..a9e58af 100644
6096 --- a/arch/sparc/include/asm/elf_32.h
6097 +++ b/arch/sparc/include/asm/elf_32.h
6098 @@ -114,6 +114,13 @@ typedef struct {
6099
6100 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6101
6102 +#ifdef CONFIG_PAX_ASLR
6103 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
6104 +
6105 +#define PAX_DELTA_MMAP_LEN 16
6106 +#define PAX_DELTA_STACK_LEN 16
6107 +#endif
6108 +
6109 /* This yields a mask that user programs can use to figure out what
6110 instruction set this cpu supports. This can NOT be done in userspace
6111 on Sparc. */
6112 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6113 index 370ca1e..d4f4a98 100644
6114 --- a/arch/sparc/include/asm/elf_64.h
6115 +++ b/arch/sparc/include/asm/elf_64.h
6116 @@ -189,6 +189,13 @@ typedef struct {
6117 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6118 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6119
6120 +#ifdef CONFIG_PAX_ASLR
6121 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6122 +
6123 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6124 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6125 +#endif
6126 +
6127 extern unsigned long sparc64_elf_hwcap;
6128 #define ELF_HWCAP sparc64_elf_hwcap
6129
6130 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6131 index 9b1c36d..209298b 100644
6132 --- a/arch/sparc/include/asm/pgalloc_32.h
6133 +++ b/arch/sparc/include/asm/pgalloc_32.h
6134 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6135 }
6136
6137 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6138 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6139
6140 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6141 unsigned long address)
6142 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6143 index bcfe063..b333142 100644
6144 --- a/arch/sparc/include/asm/pgalloc_64.h
6145 +++ b/arch/sparc/include/asm/pgalloc_64.h
6146 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6147 }
6148
6149 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6150 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6151
6152 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6153 {
6154 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6155 index 6fc1348..390c50a 100644
6156 --- a/arch/sparc/include/asm/pgtable_32.h
6157 +++ b/arch/sparc/include/asm/pgtable_32.h
6158 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6159 #define PAGE_SHARED SRMMU_PAGE_SHARED
6160 #define PAGE_COPY SRMMU_PAGE_COPY
6161 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6162 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6163 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6164 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6165 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6166
6167 /* Top-level page directory - dummy used by init-mm.
6168 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6169
6170 /* xwr */
6171 #define __P000 PAGE_NONE
6172 -#define __P001 PAGE_READONLY
6173 -#define __P010 PAGE_COPY
6174 -#define __P011 PAGE_COPY
6175 +#define __P001 PAGE_READONLY_NOEXEC
6176 +#define __P010 PAGE_COPY_NOEXEC
6177 +#define __P011 PAGE_COPY_NOEXEC
6178 #define __P100 PAGE_READONLY
6179 #define __P101 PAGE_READONLY
6180 #define __P110 PAGE_COPY
6181 #define __P111 PAGE_COPY
6182
6183 #define __S000 PAGE_NONE
6184 -#define __S001 PAGE_READONLY
6185 -#define __S010 PAGE_SHARED
6186 -#define __S011 PAGE_SHARED
6187 +#define __S001 PAGE_READONLY_NOEXEC
6188 +#define __S010 PAGE_SHARED_NOEXEC
6189 +#define __S011 PAGE_SHARED_NOEXEC
6190 #define __S100 PAGE_READONLY
6191 #define __S101 PAGE_READONLY
6192 #define __S110 PAGE_SHARED
6193 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6194 index 79da178..c2eede8 100644
6195 --- a/arch/sparc/include/asm/pgtsrmmu.h
6196 +++ b/arch/sparc/include/asm/pgtsrmmu.h
6197 @@ -115,6 +115,11 @@
6198 SRMMU_EXEC | SRMMU_REF)
6199 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6200 SRMMU_EXEC | SRMMU_REF)
6201 +
6202 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6203 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6204 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6205 +
6206 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6207 SRMMU_DIRTY | SRMMU_REF)
6208
6209 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6210 index 9689176..63c18ea 100644
6211 --- a/arch/sparc/include/asm/spinlock_64.h
6212 +++ b/arch/sparc/include/asm/spinlock_64.h
6213 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6214
6215 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6216
6217 -static void inline arch_read_lock(arch_rwlock_t *lock)
6218 +static inline void arch_read_lock(arch_rwlock_t *lock)
6219 {
6220 unsigned long tmp1, tmp2;
6221
6222 __asm__ __volatile__ (
6223 "1: ldsw [%2], %0\n"
6224 " brlz,pn %0, 2f\n"
6225 -"4: add %0, 1, %1\n"
6226 +"4: addcc %0, 1, %1\n"
6227 +
6228 +#ifdef CONFIG_PAX_REFCOUNT
6229 +" tvs %%icc, 6\n"
6230 +#endif
6231 +
6232 " cas [%2], %0, %1\n"
6233 " cmp %0, %1\n"
6234 " bne,pn %%icc, 1b\n"
6235 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6236 " .previous"
6237 : "=&r" (tmp1), "=&r" (tmp2)
6238 : "r" (lock)
6239 - : "memory");
6240 + : "memory", "cc");
6241 }
6242
6243 -static int inline arch_read_trylock(arch_rwlock_t *lock)
6244 +static inline int arch_read_trylock(arch_rwlock_t *lock)
6245 {
6246 int tmp1, tmp2;
6247
6248 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6249 "1: ldsw [%2], %0\n"
6250 " brlz,a,pn %0, 2f\n"
6251 " mov 0, %0\n"
6252 -" add %0, 1, %1\n"
6253 +" addcc %0, 1, %1\n"
6254 +
6255 +#ifdef CONFIG_PAX_REFCOUNT
6256 +" tvs %%icc, 6\n"
6257 +#endif
6258 +
6259 " cas [%2], %0, %1\n"
6260 " cmp %0, %1\n"
6261 " bne,pn %%icc, 1b\n"
6262 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6263 return tmp1;
6264 }
6265
6266 -static void inline arch_read_unlock(arch_rwlock_t *lock)
6267 +static inline void arch_read_unlock(arch_rwlock_t *lock)
6268 {
6269 unsigned long tmp1, tmp2;
6270
6271 __asm__ __volatile__(
6272 "1: lduw [%2], %0\n"
6273 -" sub %0, 1, %1\n"
6274 +" subcc %0, 1, %1\n"
6275 +
6276 +#ifdef CONFIG_PAX_REFCOUNT
6277 +" tvs %%icc, 6\n"
6278 +#endif
6279 +
6280 " cas [%2], %0, %1\n"
6281 " cmp %0, %1\n"
6282 " bne,pn %%xcc, 1b\n"
6283 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6284 : "memory");
6285 }
6286
6287 -static void inline arch_write_lock(arch_rwlock_t *lock)
6288 +static inline void arch_write_lock(arch_rwlock_t *lock)
6289 {
6290 unsigned long mask, tmp1, tmp2;
6291
6292 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6293 : "memory");
6294 }
6295
6296 -static void inline arch_write_unlock(arch_rwlock_t *lock)
6297 +static inline void arch_write_unlock(arch_rwlock_t *lock)
6298 {
6299 __asm__ __volatile__(
6300 " stw %%g0, [%0]"
6301 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6302 : "memory");
6303 }
6304
6305 -static int inline arch_write_trylock(arch_rwlock_t *lock)
6306 +static inline int arch_write_trylock(arch_rwlock_t *lock)
6307 {
6308 unsigned long mask, tmp1, tmp2, result;
6309
6310 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6311 index 25849ae..924c54b 100644
6312 --- a/arch/sparc/include/asm/thread_info_32.h
6313 +++ b/arch/sparc/include/asm/thread_info_32.h
6314 @@ -49,6 +49,8 @@ struct thread_info {
6315 unsigned long w_saved;
6316
6317 struct restart_block restart_block;
6318 +
6319 + unsigned long lowest_stack;
6320 };
6321
6322 /*
6323 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6324 index a3fe4dc..cae132a 100644
6325 --- a/arch/sparc/include/asm/thread_info_64.h
6326 +++ b/arch/sparc/include/asm/thread_info_64.h
6327 @@ -63,6 +63,8 @@ struct thread_info {
6328 struct pt_regs *kern_una_regs;
6329 unsigned int kern_una_insn;
6330
6331 + unsigned long lowest_stack;
6332 +
6333 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6334 };
6335
6336 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6337 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6338 /* flag bit 6 is available */
6339 #define TIF_32BIT 7 /* 32-bit binary */
6340 -/* flag bit 8 is available */
6341 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6342 #define TIF_SECCOMP 9 /* secure computing */
6343 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6344 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6345 +
6346 /* NOTE: Thread flags >= 12 should be ones we have no interest
6347 * in using in assembly, else we can't use the mask as
6348 * an immediate value in instructions such as andcc.
6349 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6350 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6351 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6352 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6353 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6354
6355 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6356 _TIF_DO_NOTIFY_RESUME_MASK | \
6357 _TIF_NEED_RESCHED)
6358 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6359
6360 +#define _TIF_WORK_SYSCALL \
6361 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6362 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6363 +
6364 +
6365 /*
6366 * Thread-synchronous status.
6367 *
6368 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6369 index 0167d26..9acd8ed 100644
6370 --- a/arch/sparc/include/asm/uaccess.h
6371 +++ b/arch/sparc/include/asm/uaccess.h
6372 @@ -1,5 +1,13 @@
6373 #ifndef ___ASM_SPARC_UACCESS_H
6374 #define ___ASM_SPARC_UACCESS_H
6375 +
6376 +#ifdef __KERNEL__
6377 +#ifndef __ASSEMBLY__
6378 +#include <linux/types.h>
6379 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6380 +#endif
6381 +#endif
6382 +
6383 #if defined(__sparc__) && defined(__arch64__)
6384 #include <asm/uaccess_64.h>
6385 #else
6386 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6387 index 53a28dd..50c38c3 100644
6388 --- a/arch/sparc/include/asm/uaccess_32.h
6389 +++ b/arch/sparc/include/asm/uaccess_32.h
6390 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6391
6392 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6393 {
6394 - if (n && __access_ok((unsigned long) to, n))
6395 + if ((long)n < 0)
6396 + return n;
6397 +
6398 + if (n && __access_ok((unsigned long) to, n)) {
6399 + if (!__builtin_constant_p(n))
6400 + check_object_size(from, n, true);
6401 return __copy_user(to, (__force void __user *) from, n);
6402 - else
6403 + } else
6404 return n;
6405 }
6406
6407 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6408 {
6409 + if ((long)n < 0)
6410 + return n;
6411 +
6412 + if (!__builtin_constant_p(n))
6413 + check_object_size(from, n, true);
6414 +
6415 return __copy_user(to, (__force void __user *) from, n);
6416 }
6417
6418 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6419 {
6420 - if (n && __access_ok((unsigned long) from, n))
6421 + if ((long)n < 0)
6422 + return n;
6423 +
6424 + if (n && __access_ok((unsigned long) from, n)) {
6425 + if (!__builtin_constant_p(n))
6426 + check_object_size(to, n, false);
6427 return __copy_user((__force void __user *) to, from, n);
6428 - else
6429 + } else
6430 return n;
6431 }
6432
6433 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6434 {
6435 + if ((long)n < 0)
6436 + return n;
6437 +
6438 return __copy_user((__force void __user *) to, from, n);
6439 }
6440
6441 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6442 index 73083e1..2bc62a6 100644
6443 --- a/arch/sparc/include/asm/uaccess_64.h
6444 +++ b/arch/sparc/include/asm/uaccess_64.h
6445 @@ -10,6 +10,7 @@
6446 #include <linux/compiler.h>
6447 #include <linux/string.h>
6448 #include <linux/thread_info.h>
6449 +#include <linux/kernel.h>
6450 #include <asm/asi.h>
6451 #include <asm/spitfire.h>
6452 #include <asm-generic/uaccess-unaligned.h>
6453 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6454 static inline unsigned long __must_check
6455 copy_from_user(void *to, const void __user *from, unsigned long size)
6456 {
6457 - unsigned long ret = ___copy_from_user(to, from, size);
6458 + unsigned long ret;
6459
6460 + if ((long)size < 0 || size > INT_MAX)
6461 + return size;
6462 +
6463 + if (!__builtin_constant_p(size))
6464 + check_object_size(to, size, false);
6465 +
6466 + ret = ___copy_from_user(to, from, size);
6467 if (unlikely(ret))
6468 ret = copy_from_user_fixup(to, from, size);
6469
6470 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6471 static inline unsigned long __must_check
6472 copy_to_user(void __user *to, const void *from, unsigned long size)
6473 {
6474 - unsigned long ret = ___copy_to_user(to, from, size);
6475 + unsigned long ret;
6476
6477 + if ((long)size < 0 || size > INT_MAX)
6478 + return size;
6479 +
6480 + if (!__builtin_constant_p(size))
6481 + check_object_size(from, size, true);
6482 +
6483 + ret = ___copy_to_user(to, from, size);
6484 if (unlikely(ret))
6485 ret = copy_to_user_fixup(to, from, size);
6486 return ret;
6487 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6488 index 6cf591b..b49e65a 100644
6489 --- a/arch/sparc/kernel/Makefile
6490 +++ b/arch/sparc/kernel/Makefile
6491 @@ -3,7 +3,7 @@
6492 #
6493
6494 asflags-y := -ansi
6495 -ccflags-y := -Werror
6496 +#ccflags-y := -Werror
6497
6498 extra-y := head_$(BITS).o
6499
6500 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6501 index 487bffb..955a925 100644
6502 --- a/arch/sparc/kernel/process_32.c
6503 +++ b/arch/sparc/kernel/process_32.c
6504 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6505
6506 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6507 r->psr, r->pc, r->npc, r->y, print_tainted());
6508 - printk("PC: <%pS>\n", (void *) r->pc);
6509 + printk("PC: <%pA>\n", (void *) r->pc);
6510 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6511 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6512 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6513 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6514 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6515 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6516 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6517 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6518
6519 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6520 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6521 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6522 rw = (struct reg_window32 *) fp;
6523 pc = rw->ins[7];
6524 printk("[%08lx : ", pc);
6525 - printk("%pS ] ", (void *) pc);
6526 + printk("%pA ] ", (void *) pc);
6527 fp = rw->ins[6];
6528 } while (++count < 16);
6529 printk("\n");
6530 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6531 index c6e0c29..052832b 100644
6532 --- a/arch/sparc/kernel/process_64.c
6533 +++ b/arch/sparc/kernel/process_64.c
6534 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6535 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6536 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6537 if (regs->tstate & TSTATE_PRIV)
6538 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6539 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6540 }
6541
6542 void show_regs(struct pt_regs *regs)
6543 {
6544 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6545 regs->tpc, regs->tnpc, regs->y, print_tainted());
6546 - printk("TPC: <%pS>\n", (void *) regs->tpc);
6547 + printk("TPC: <%pA>\n", (void *) regs->tpc);
6548 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6549 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6550 regs->u_regs[3]);
6551 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6552 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6553 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6554 regs->u_regs[15]);
6555 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6556 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6557 show_regwindow(regs);
6558 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6559 }
6560 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6561 ((tp && tp->task) ? tp->task->pid : -1));
6562
6563 if (gp->tstate & TSTATE_PRIV) {
6564 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6565 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6566 (void *) gp->tpc,
6567 (void *) gp->o7,
6568 (void *) gp->i7,
6569 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6570 index 7ff45e4..a58f271 100644
6571 --- a/arch/sparc/kernel/ptrace_64.c
6572 +++ b/arch/sparc/kernel/ptrace_64.c
6573 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6574 return ret;
6575 }
6576
6577 +#ifdef CONFIG_GRKERNSEC_SETXID
6578 +extern void gr_delayed_cred_worker(void);
6579 +#endif
6580 +
6581 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6582 {
6583 int ret = 0;
6584 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6585 /* do the secure computing check first */
6586 secure_computing_strict(regs->u_regs[UREG_G1]);
6587
6588 +#ifdef CONFIG_GRKERNSEC_SETXID
6589 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6590 + gr_delayed_cred_worker();
6591 +#endif
6592 +
6593 if (test_thread_flag(TIF_SYSCALL_TRACE))
6594 ret = tracehook_report_syscall_entry(regs);
6595
6596 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6597
6598 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6599 {
6600 +#ifdef CONFIG_GRKERNSEC_SETXID
6601 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6602 + gr_delayed_cred_worker();
6603 +#endif
6604 +
6605 audit_syscall_exit(regs);
6606
6607 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6608 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6609 index 0c9b31b..7cb7aee 100644
6610 --- a/arch/sparc/kernel/sys_sparc_32.c
6611 +++ b/arch/sparc/kernel/sys_sparc_32.c
6612 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6613 if (len > TASK_SIZE - PAGE_SIZE)
6614 return -ENOMEM;
6615 if (!addr)
6616 - addr = TASK_UNMAPPED_BASE;
6617 + addr = current->mm->mmap_base;
6618
6619 if (flags & MAP_SHARED)
6620 addr = COLOUR_ALIGN(addr);
6621 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6622 /* At this point: (!vmm || addr < vmm->vm_end). */
6623 if (TASK_SIZE - PAGE_SIZE - len < addr)
6624 return -ENOMEM;
6625 - if (!vmm || addr + len <= vmm->vm_start)
6626 + if (check_heap_stack_gap(vmm, addr, len))
6627 return addr;
6628 addr = vmm->vm_end;
6629 if (flags & MAP_SHARED)
6630 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6631 index 878ef3d..8742f10 100644
6632 --- a/arch/sparc/kernel/sys_sparc_64.c
6633 +++ b/arch/sparc/kernel/sys_sparc_64.c
6634 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6635 /* We do not accept a shared mapping if it would violate
6636 * cache aliasing constraints.
6637 */
6638 - if ((flags & MAP_SHARED) &&
6639 + if ((filp || (flags & MAP_SHARED)) &&
6640 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6641 return -EINVAL;
6642 return addr;
6643 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6644 if (filp || (flags & MAP_SHARED))
6645 do_color_align = 1;
6646
6647 +#ifdef CONFIG_PAX_RANDMMAP
6648 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6649 +#endif
6650 +
6651 if (addr) {
6652 if (do_color_align)
6653 addr = COLOUR_ALIGN(addr, pgoff);
6654 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6655 addr = PAGE_ALIGN(addr);
6656
6657 vma = find_vma(mm, addr);
6658 - if (task_size - len >= addr &&
6659 - (!vma || addr + len <= vma->vm_start))
6660 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6661 return addr;
6662 }
6663
6664 if (len > mm->cached_hole_size) {
6665 - start_addr = addr = mm->free_area_cache;
6666 + start_addr = addr = mm->free_area_cache;
6667 } else {
6668 - start_addr = addr = TASK_UNMAPPED_BASE;
6669 + start_addr = addr = mm->mmap_base;
6670 mm->cached_hole_size = 0;
6671 }
6672
6673 @@ -157,14 +160,14 @@ full_search:
6674 vma = find_vma(mm, VA_EXCLUDE_END);
6675 }
6676 if (unlikely(task_size < addr)) {
6677 - if (start_addr != TASK_UNMAPPED_BASE) {
6678 - start_addr = addr = TASK_UNMAPPED_BASE;
6679 + if (start_addr != mm->mmap_base) {
6680 + start_addr = addr = mm->mmap_base;
6681 mm->cached_hole_size = 0;
6682 goto full_search;
6683 }
6684 return -ENOMEM;
6685 }
6686 - if (likely(!vma || addr + len <= vma->vm_start)) {
6687 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6688 /*
6689 * Remember the place where we stopped the search:
6690 */
6691 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6692 /* We do not accept a shared mapping if it would violate
6693 * cache aliasing constraints.
6694 */
6695 - if ((flags & MAP_SHARED) &&
6696 + if ((filp || (flags & MAP_SHARED)) &&
6697 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6698 return -EINVAL;
6699 return addr;
6700 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6701 addr = PAGE_ALIGN(addr);
6702
6703 vma = find_vma(mm, addr);
6704 - if (task_size - len >= addr &&
6705 - (!vma || addr + len <= vma->vm_start))
6706 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6707 return addr;
6708 }
6709
6710 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6711 /* make sure it can fit in the remaining address space */
6712 if (likely(addr > len)) {
6713 vma = find_vma(mm, addr-len);
6714 - if (!vma || addr <= vma->vm_start) {
6715 + if (check_heap_stack_gap(vma, addr - len, len)) {
6716 /* remember the address as a hint for next time */
6717 return (mm->free_area_cache = addr-len);
6718 }
6719 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6720 if (unlikely(mm->mmap_base < len))
6721 goto bottomup;
6722
6723 - addr = mm->mmap_base-len;
6724 - if (do_color_align)
6725 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6726 + addr = mm->mmap_base - len;
6727
6728 do {
6729 + if (do_color_align)
6730 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6731 /*
6732 * Lookup failure means no vma is above this address,
6733 * else if new region fits below vma->vm_start,
6734 * return with success:
6735 */
6736 vma = find_vma(mm, addr);
6737 - if (likely(!vma || addr+len <= vma->vm_start)) {
6738 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6739 /* remember the address as a hint for next time */
6740 return (mm->free_area_cache = addr);
6741 }
6742 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6743 mm->cached_hole_size = vma->vm_start - addr;
6744
6745 /* try just below the current vma->vm_start */
6746 - addr = vma->vm_start-len;
6747 - if (do_color_align)
6748 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6749 - } while (likely(len < vma->vm_start));
6750 + addr = skip_heap_stack_gap(vma, len);
6751 + } while (!IS_ERR_VALUE(addr));
6752
6753 bottomup:
6754 /*
6755 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6756 gap == RLIM_INFINITY ||
6757 sysctl_legacy_va_layout) {
6758 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6759 +
6760 +#ifdef CONFIG_PAX_RANDMMAP
6761 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6762 + mm->mmap_base += mm->delta_mmap;
6763 +#endif
6764 +
6765 mm->get_unmapped_area = arch_get_unmapped_area;
6766 mm->unmap_area = arch_unmap_area;
6767 } else {
6768 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6769 gap = (task_size / 6 * 5);
6770
6771 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6772 +
6773 +#ifdef CONFIG_PAX_RANDMMAP
6774 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6775 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6776 +#endif
6777 +
6778 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6779 mm->unmap_area = arch_unmap_area_topdown;
6780 }
6781 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6782 index bf23477..b7425a6 100644
6783 --- a/arch/sparc/kernel/syscalls.S
6784 +++ b/arch/sparc/kernel/syscalls.S
6785 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6786 #endif
6787 .align 32
6788 1: ldx [%g6 + TI_FLAGS], %l5
6789 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6790 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6791 be,pt %icc, rtrap
6792 nop
6793 call syscall_trace_leave
6794 @@ -189,7 +189,7 @@ linux_sparc_syscall32:
6795
6796 srl %i5, 0, %o5 ! IEU1
6797 srl %i2, 0, %o2 ! IEU0 Group
6798 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6799 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6800 bne,pn %icc, linux_syscall_trace32 ! CTI
6801 mov %i0, %l5 ! IEU1
6802 call %l7 ! CTI Group brk forced
6803 @@ -212,7 +212,7 @@ linux_sparc_syscall:
6804
6805 mov %i3, %o3 ! IEU1
6806 mov %i4, %o4 ! IEU0 Group
6807 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6808 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6809 bne,pn %icc, linux_syscall_trace ! CTI Group
6810 mov %i0, %l5 ! IEU0
6811 2: call %l7 ! CTI Group brk forced
6812 @@ -228,7 +228,7 @@ ret_sys_call:
6813
6814 cmp %o0, -ERESTART_RESTARTBLOCK
6815 bgeu,pn %xcc, 1f
6816 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6817 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6818 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6819
6820 2:
6821 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6822 index a5785ea..405c5f7 100644
6823 --- a/arch/sparc/kernel/traps_32.c
6824 +++ b/arch/sparc/kernel/traps_32.c
6825 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6826 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6827 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6828
6829 +extern void gr_handle_kernel_exploit(void);
6830 +
6831 void die_if_kernel(char *str, struct pt_regs *regs)
6832 {
6833 static int die_counter;
6834 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6835 count++ < 30 &&
6836 (((unsigned long) rw) >= PAGE_OFFSET) &&
6837 !(((unsigned long) rw) & 0x7)) {
6838 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6839 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6840 (void *) rw->ins[7]);
6841 rw = (struct reg_window32 *)rw->ins[6];
6842 }
6843 }
6844 printk("Instruction DUMP:");
6845 instruction_dump ((unsigned long *) regs->pc);
6846 - if(regs->psr & PSR_PS)
6847 + if(regs->psr & PSR_PS) {
6848 + gr_handle_kernel_exploit();
6849 do_exit(SIGKILL);
6850 + }
6851 do_exit(SIGSEGV);
6852 }
6853
6854 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6855 index b66a779..8e8d66c 100644
6856 --- a/arch/sparc/kernel/traps_64.c
6857 +++ b/arch/sparc/kernel/traps_64.c
6858 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6859 i + 1,
6860 p->trapstack[i].tstate, p->trapstack[i].tpc,
6861 p->trapstack[i].tnpc, p->trapstack[i].tt);
6862 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6863 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6864 }
6865 }
6866
6867 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6868
6869 lvl -= 0x100;
6870 if (regs->tstate & TSTATE_PRIV) {
6871 +
6872 +#ifdef CONFIG_PAX_REFCOUNT
6873 + if (lvl == 6)
6874 + pax_report_refcount_overflow(regs);
6875 +#endif
6876 +
6877 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6878 die_if_kernel(buffer, regs);
6879 }
6880 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6881 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6882 {
6883 char buffer[32];
6884 -
6885 +
6886 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6887 0, lvl, SIGTRAP) == NOTIFY_STOP)
6888 return;
6889
6890 +#ifdef CONFIG_PAX_REFCOUNT
6891 + if (lvl == 6)
6892 + pax_report_refcount_overflow(regs);
6893 +#endif
6894 +
6895 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6896
6897 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6898 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6899 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6900 printk("%s" "ERROR(%d): ",
6901 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6902 - printk("TPC<%pS>\n", (void *) regs->tpc);
6903 + printk("TPC<%pA>\n", (void *) regs->tpc);
6904 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6905 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6906 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6907 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6908 smp_processor_id(),
6909 (type & 0x1) ? 'I' : 'D',
6910 regs->tpc);
6911 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6912 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6913 panic("Irrecoverable Cheetah+ parity error.");
6914 }
6915
6916 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6917 smp_processor_id(),
6918 (type & 0x1) ? 'I' : 'D',
6919 regs->tpc);
6920 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6921 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6922 }
6923
6924 struct sun4v_error_entry {
6925 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6926
6927 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6928 regs->tpc, tl);
6929 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6930 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6931 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6932 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6933 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6934 (void *) regs->u_regs[UREG_I7]);
6935 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6936 "pte[%lx] error[%lx]\n",
6937 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6938
6939 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6940 regs->tpc, tl);
6941 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6942 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6943 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6944 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6945 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6946 (void *) regs->u_regs[UREG_I7]);
6947 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6948 "pte[%lx] error[%lx]\n",
6949 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6950 fp = (unsigned long)sf->fp + STACK_BIAS;
6951 }
6952
6953 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6954 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6955 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6956 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6957 int index = tsk->curr_ret_stack;
6958 if (tsk->ret_stack && index >= graph) {
6959 pc = tsk->ret_stack[index - graph].ret;
6960 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6961 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6962 graph++;
6963 }
6964 }
6965 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6966 return (struct reg_window *) (fp + STACK_BIAS);
6967 }
6968
6969 +extern void gr_handle_kernel_exploit(void);
6970 +
6971 void die_if_kernel(char *str, struct pt_regs *regs)
6972 {
6973 static int die_counter;
6974 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6975 while (rw &&
6976 count++ < 30 &&
6977 kstack_valid(tp, (unsigned long) rw)) {
6978 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6979 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6980 (void *) rw->ins[7]);
6981
6982 rw = kernel_stack_up(rw);
6983 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6984 }
6985 user_instruction_dump ((unsigned int __user *) regs->tpc);
6986 }
6987 - if (regs->tstate & TSTATE_PRIV)
6988 + if (regs->tstate & TSTATE_PRIV) {
6989 + gr_handle_kernel_exploit();
6990 do_exit(SIGKILL);
6991 + }
6992 do_exit(SIGSEGV);
6993 }
6994 EXPORT_SYMBOL(die_if_kernel);
6995 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6996 index 8201c25e..072a2a7 100644
6997 --- a/arch/sparc/kernel/unaligned_64.c
6998 +++ b/arch/sparc/kernel/unaligned_64.c
6999 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7000 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7001
7002 if (__ratelimit(&ratelimit)) {
7003 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
7004 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
7005 regs->tpc, (void *) regs->tpc);
7006 }
7007 }
7008 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7009 index 8410065f2..4fd4ca22 100644
7010 --- a/arch/sparc/lib/Makefile
7011 +++ b/arch/sparc/lib/Makefile
7012 @@ -2,7 +2,7 @@
7013 #
7014
7015 asflags-y := -ansi -DST_DIV0=0x02
7016 -ccflags-y := -Werror
7017 +#ccflags-y := -Werror
7018
7019 lib-$(CONFIG_SPARC32) += ashrdi3.o
7020 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7021 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7022 index 85c233d..68500e0 100644
7023 --- a/arch/sparc/lib/atomic_64.S
7024 +++ b/arch/sparc/lib/atomic_64.S
7025 @@ -17,7 +17,12 @@
7026 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7027 BACKOFF_SETUP(%o2)
7028 1: lduw [%o1], %g1
7029 - add %g1, %o0, %g7
7030 + addcc %g1, %o0, %g7
7031 +
7032 +#ifdef CONFIG_PAX_REFCOUNT
7033 + tvs %icc, 6
7034 +#endif
7035 +
7036 cas [%o1], %g1, %g7
7037 cmp %g1, %g7
7038 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7039 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7040 2: BACKOFF_SPIN(%o2, %o3, 1b)
7041 ENDPROC(atomic_add)
7042
7043 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7044 + BACKOFF_SETUP(%o2)
7045 +1: lduw [%o1], %g1
7046 + add %g1, %o0, %g7
7047 + cas [%o1], %g1, %g7
7048 + cmp %g1, %g7
7049 + bne,pn %icc, 2f
7050 + nop
7051 + retl
7052 + nop
7053 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7054 +ENDPROC(atomic_add_unchecked)
7055 +
7056 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7057 BACKOFF_SETUP(%o2)
7058 1: lduw [%o1], %g1
7059 - sub %g1, %o0, %g7
7060 + subcc %g1, %o0, %g7
7061 +
7062 +#ifdef CONFIG_PAX_REFCOUNT
7063 + tvs %icc, 6
7064 +#endif
7065 +
7066 cas [%o1], %g1, %g7
7067 cmp %g1, %g7
7068 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7069 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7070 2: BACKOFF_SPIN(%o2, %o3, 1b)
7071 ENDPROC(atomic_sub)
7072
7073 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7074 + BACKOFF_SETUP(%o2)
7075 +1: lduw [%o1], %g1
7076 + sub %g1, %o0, %g7
7077 + cas [%o1], %g1, %g7
7078 + cmp %g1, %g7
7079 + bne,pn %icc, 2f
7080 + nop
7081 + retl
7082 + nop
7083 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7084 +ENDPROC(atomic_sub_unchecked)
7085 +
7086 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7087 BACKOFF_SETUP(%o2)
7088 1: lduw [%o1], %g1
7089 - add %g1, %o0, %g7
7090 + addcc %g1, %o0, %g7
7091 +
7092 +#ifdef CONFIG_PAX_REFCOUNT
7093 + tvs %icc, 6
7094 +#endif
7095 +
7096 cas [%o1], %g1, %g7
7097 cmp %g1, %g7
7098 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7099 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7100 2: BACKOFF_SPIN(%o2, %o3, 1b)
7101 ENDPROC(atomic_add_ret)
7102
7103 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7104 + BACKOFF_SETUP(%o2)
7105 +1: lduw [%o1], %g1
7106 + addcc %g1, %o0, %g7
7107 + cas [%o1], %g1, %g7
7108 + cmp %g1, %g7
7109 + bne,pn %icc, 2f
7110 + add %g7, %o0, %g7
7111 + sra %g7, 0, %o0
7112 + retl
7113 + nop
7114 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7115 +ENDPROC(atomic_add_ret_unchecked)
7116 +
7117 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7118 BACKOFF_SETUP(%o2)
7119 1: lduw [%o1], %g1
7120 - sub %g1, %o0, %g7
7121 + subcc %g1, %o0, %g7
7122 +
7123 +#ifdef CONFIG_PAX_REFCOUNT
7124 + tvs %icc, 6
7125 +#endif
7126 +
7127 cas [%o1], %g1, %g7
7128 cmp %g1, %g7
7129 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7130 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7131 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7132 BACKOFF_SETUP(%o2)
7133 1: ldx [%o1], %g1
7134 - add %g1, %o0, %g7
7135 + addcc %g1, %o0, %g7
7136 +
7137 +#ifdef CONFIG_PAX_REFCOUNT
7138 + tvs %xcc, 6
7139 +#endif
7140 +
7141 casx [%o1], %g1, %g7
7142 cmp %g1, %g7
7143 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7144 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7145 2: BACKOFF_SPIN(%o2, %o3, 1b)
7146 ENDPROC(atomic64_add)
7147
7148 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7149 + BACKOFF_SETUP(%o2)
7150 +1: ldx [%o1], %g1
7151 + addcc %g1, %o0, %g7
7152 + casx [%o1], %g1, %g7
7153 + cmp %g1, %g7
7154 + bne,pn %xcc, 2f
7155 + nop
7156 + retl
7157 + nop
7158 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7159 +ENDPROC(atomic64_add_unchecked)
7160 +
7161 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7162 BACKOFF_SETUP(%o2)
7163 1: ldx [%o1], %g1
7164 - sub %g1, %o0, %g7
7165 + subcc %g1, %o0, %g7
7166 +
7167 +#ifdef CONFIG_PAX_REFCOUNT
7168 + tvs %xcc, 6
7169 +#endif
7170 +
7171 casx [%o1], %g1, %g7
7172 cmp %g1, %g7
7173 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7174 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7175 2: BACKOFF_SPIN(%o2, %o3, 1b)
7176 ENDPROC(atomic64_sub)
7177
7178 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7179 + BACKOFF_SETUP(%o2)
7180 +1: ldx [%o1], %g1
7181 + subcc %g1, %o0, %g7
7182 + casx [%o1], %g1, %g7
7183 + cmp %g1, %g7
7184 + bne,pn %xcc, 2f
7185 + nop
7186 + retl
7187 + nop
7188 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7189 +ENDPROC(atomic64_sub_unchecked)
7190 +
7191 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7192 BACKOFF_SETUP(%o2)
7193 1: ldx [%o1], %g1
7194 - add %g1, %o0, %g7
7195 + addcc %g1, %o0, %g7
7196 +
7197 +#ifdef CONFIG_PAX_REFCOUNT
7198 + tvs %xcc, 6
7199 +#endif
7200 +
7201 casx [%o1], %g1, %g7
7202 cmp %g1, %g7
7203 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7204 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7205 2: BACKOFF_SPIN(%o2, %o3, 1b)
7206 ENDPROC(atomic64_add_ret)
7207
7208 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7209 + BACKOFF_SETUP(%o2)
7210 +1: ldx [%o1], %g1
7211 + addcc %g1, %o0, %g7
7212 + casx [%o1], %g1, %g7
7213 + cmp %g1, %g7
7214 + bne,pn %xcc, 2f
7215 + add %g7, %o0, %g7
7216 + mov %g7, %o0
7217 + retl
7218 + nop
7219 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7220 +ENDPROC(atomic64_add_ret_unchecked)
7221 +
7222 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7223 BACKOFF_SETUP(%o2)
7224 1: ldx [%o1], %g1
7225 - sub %g1, %o0, %g7
7226 + subcc %g1, %o0, %g7
7227 +
7228 +#ifdef CONFIG_PAX_REFCOUNT
7229 + tvs %xcc, 6
7230 +#endif
7231 +
7232 casx [%o1], %g1, %g7
7233 cmp %g1, %g7
7234 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7235 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7236 index 0c4e35e..745d3e4 100644
7237 --- a/arch/sparc/lib/ksyms.c
7238 +++ b/arch/sparc/lib/ksyms.c
7239 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7240
7241 /* Atomic counter implementation. */
7242 EXPORT_SYMBOL(atomic_add);
7243 +EXPORT_SYMBOL(atomic_add_unchecked);
7244 EXPORT_SYMBOL(atomic_add_ret);
7245 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
7246 EXPORT_SYMBOL(atomic_sub);
7247 +EXPORT_SYMBOL(atomic_sub_unchecked);
7248 EXPORT_SYMBOL(atomic_sub_ret);
7249 EXPORT_SYMBOL(atomic64_add);
7250 +EXPORT_SYMBOL(atomic64_add_unchecked);
7251 EXPORT_SYMBOL(atomic64_add_ret);
7252 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7253 EXPORT_SYMBOL(atomic64_sub);
7254 +EXPORT_SYMBOL(atomic64_sub_unchecked);
7255 EXPORT_SYMBOL(atomic64_sub_ret);
7256 EXPORT_SYMBOL(atomic64_dec_if_positive);
7257
7258 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7259 index 30c3ecc..736f015 100644
7260 --- a/arch/sparc/mm/Makefile
7261 +++ b/arch/sparc/mm/Makefile
7262 @@ -2,7 +2,7 @@
7263 #
7264
7265 asflags-y := -ansi
7266 -ccflags-y := -Werror
7267 +#ccflags-y := -Werror
7268
7269 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7270 obj-y += fault_$(BITS).o
7271 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7272 index e98bfda..ea8d221 100644
7273 --- a/arch/sparc/mm/fault_32.c
7274 +++ b/arch/sparc/mm/fault_32.c
7275 @@ -21,6 +21,9 @@
7276 #include <linux/perf_event.h>
7277 #include <linux/interrupt.h>
7278 #include <linux/kdebug.h>
7279 +#include <linux/slab.h>
7280 +#include <linux/pagemap.h>
7281 +#include <linux/compiler.h>
7282
7283 #include <asm/page.h>
7284 #include <asm/pgtable.h>
7285 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7286 return safe_compute_effective_address(regs, insn);
7287 }
7288
7289 +#ifdef CONFIG_PAX_PAGEEXEC
7290 +#ifdef CONFIG_PAX_DLRESOLVE
7291 +static void pax_emuplt_close(struct vm_area_struct *vma)
7292 +{
7293 + vma->vm_mm->call_dl_resolve = 0UL;
7294 +}
7295 +
7296 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7297 +{
7298 + unsigned int *kaddr;
7299 +
7300 + vmf->page = alloc_page(GFP_HIGHUSER);
7301 + if (!vmf->page)
7302 + return VM_FAULT_OOM;
7303 +
7304 + kaddr = kmap(vmf->page);
7305 + memset(kaddr, 0, PAGE_SIZE);
7306 + kaddr[0] = 0x9DE3BFA8U; /* save */
7307 + flush_dcache_page(vmf->page);
7308 + kunmap(vmf->page);
7309 + return VM_FAULT_MAJOR;
7310 +}
7311 +
7312 +static const struct vm_operations_struct pax_vm_ops = {
7313 + .close = pax_emuplt_close,
7314 + .fault = pax_emuplt_fault
7315 +};
7316 +
7317 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7318 +{
7319 + int ret;
7320 +
7321 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7322 + vma->vm_mm = current->mm;
7323 + vma->vm_start = addr;
7324 + vma->vm_end = addr + PAGE_SIZE;
7325 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7326 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7327 + vma->vm_ops = &pax_vm_ops;
7328 +
7329 + ret = insert_vm_struct(current->mm, vma);
7330 + if (ret)
7331 + return ret;
7332 +
7333 + ++current->mm->total_vm;
7334 + return 0;
7335 +}
7336 +#endif
7337 +
7338 +/*
7339 + * PaX: decide what to do with offenders (regs->pc = fault address)
7340 + *
7341 + * returns 1 when task should be killed
7342 + * 2 when patched PLT trampoline was detected
7343 + * 3 when unpatched PLT trampoline was detected
7344 + */
7345 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7346 +{
7347 +
7348 +#ifdef CONFIG_PAX_EMUPLT
7349 + int err;
7350 +
7351 + do { /* PaX: patched PLT emulation #1 */
7352 + unsigned int sethi1, sethi2, jmpl;
7353 +
7354 + err = get_user(sethi1, (unsigned int *)regs->pc);
7355 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7356 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7357 +
7358 + if (err)
7359 + break;
7360 +
7361 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7362 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7363 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7364 + {
7365 + unsigned int addr;
7366 +
7367 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7368 + addr = regs->u_regs[UREG_G1];
7369 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7370 + regs->pc = addr;
7371 + regs->npc = addr+4;
7372 + return 2;
7373 + }
7374 + } while (0);
7375 +
7376 + do { /* PaX: patched PLT emulation #2 */
7377 + unsigned int ba;
7378 +
7379 + err = get_user(ba, (unsigned int *)regs->pc);
7380 +
7381 + if (err)
7382 + break;
7383 +
7384 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7385 + unsigned int addr;
7386 +
7387 + if ((ba & 0xFFC00000U) == 0x30800000U)
7388 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7389 + else
7390 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7391 + regs->pc = addr;
7392 + regs->npc = addr+4;
7393 + return 2;
7394 + }
7395 + } while (0);
7396 +
7397 + do { /* PaX: patched PLT emulation #3 */
7398 + unsigned int sethi, bajmpl, nop;
7399 +
7400 + err = get_user(sethi, (unsigned int *)regs->pc);
7401 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7402 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7403 +
7404 + if (err)
7405 + break;
7406 +
7407 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7408 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7409 + nop == 0x01000000U)
7410 + {
7411 + unsigned int addr;
7412 +
7413 + addr = (sethi & 0x003FFFFFU) << 10;
7414 + regs->u_regs[UREG_G1] = addr;
7415 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7416 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7417 + else
7418 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7419 + regs->pc = addr;
7420 + regs->npc = addr+4;
7421 + return 2;
7422 + }
7423 + } while (0);
7424 +
7425 + do { /* PaX: unpatched PLT emulation step 1 */
7426 + unsigned int sethi, ba, nop;
7427 +
7428 + err = get_user(sethi, (unsigned int *)regs->pc);
7429 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
7430 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7431 +
7432 + if (err)
7433 + break;
7434 +
7435 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7436 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7437 + nop == 0x01000000U)
7438 + {
7439 + unsigned int addr, save, call;
7440 +
7441 + if ((ba & 0xFFC00000U) == 0x30800000U)
7442 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7443 + else
7444 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7445 +
7446 + err = get_user(save, (unsigned int *)addr);
7447 + err |= get_user(call, (unsigned int *)(addr+4));
7448 + err |= get_user(nop, (unsigned int *)(addr+8));
7449 + if (err)
7450 + break;
7451 +
7452 +#ifdef CONFIG_PAX_DLRESOLVE
7453 + if (save == 0x9DE3BFA8U &&
7454 + (call & 0xC0000000U) == 0x40000000U &&
7455 + nop == 0x01000000U)
7456 + {
7457 + struct vm_area_struct *vma;
7458 + unsigned long call_dl_resolve;
7459 +
7460 + down_read(&current->mm->mmap_sem);
7461 + call_dl_resolve = current->mm->call_dl_resolve;
7462 + up_read(&current->mm->mmap_sem);
7463 + if (likely(call_dl_resolve))
7464 + goto emulate;
7465 +
7466 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7467 +
7468 + down_write(&current->mm->mmap_sem);
7469 + if (current->mm->call_dl_resolve) {
7470 + call_dl_resolve = current->mm->call_dl_resolve;
7471 + up_write(&current->mm->mmap_sem);
7472 + if (vma)
7473 + kmem_cache_free(vm_area_cachep, vma);
7474 + goto emulate;
7475 + }
7476 +
7477 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7478 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7479 + up_write(&current->mm->mmap_sem);
7480 + if (vma)
7481 + kmem_cache_free(vm_area_cachep, vma);
7482 + return 1;
7483 + }
7484 +
7485 + if (pax_insert_vma(vma, call_dl_resolve)) {
7486 + up_write(&current->mm->mmap_sem);
7487 + kmem_cache_free(vm_area_cachep, vma);
7488 + return 1;
7489 + }
7490 +
7491 + current->mm->call_dl_resolve = call_dl_resolve;
7492 + up_write(&current->mm->mmap_sem);
7493 +
7494 +emulate:
7495 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7496 + regs->pc = call_dl_resolve;
7497 + regs->npc = addr+4;
7498 + return 3;
7499 + }
7500 +#endif
7501 +
7502 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7503 + if ((save & 0xFFC00000U) == 0x05000000U &&
7504 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7505 + nop == 0x01000000U)
7506 + {
7507 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7508 + regs->u_regs[UREG_G2] = addr + 4;
7509 + addr = (save & 0x003FFFFFU) << 10;
7510 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7511 + regs->pc = addr;
7512 + regs->npc = addr+4;
7513 + return 3;
7514 + }
7515 + }
7516 + } while (0);
7517 +
7518 + do { /* PaX: unpatched PLT emulation step 2 */
7519 + unsigned int save, call, nop;
7520 +
7521 + err = get_user(save, (unsigned int *)(regs->pc-4));
7522 + err |= get_user(call, (unsigned int *)regs->pc);
7523 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
7524 + if (err)
7525 + break;
7526 +
7527 + if (save == 0x9DE3BFA8U &&
7528 + (call & 0xC0000000U) == 0x40000000U &&
7529 + nop == 0x01000000U)
7530 + {
7531 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7532 +
7533 + regs->u_regs[UREG_RETPC] = regs->pc;
7534 + regs->pc = dl_resolve;
7535 + regs->npc = dl_resolve+4;
7536 + return 3;
7537 + }
7538 + } while (0);
7539 +#endif
7540 +
7541 + return 1;
7542 +}
7543 +
7544 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7545 +{
7546 + unsigned long i;
7547 +
7548 + printk(KERN_ERR "PAX: bytes at PC: ");
7549 + for (i = 0; i < 8; i++) {
7550 + unsigned int c;
7551 + if (get_user(c, (unsigned int *)pc+i))
7552 + printk(KERN_CONT "???????? ");
7553 + else
7554 + printk(KERN_CONT "%08x ", c);
7555 + }
7556 + printk("\n");
7557 +}
7558 +#endif
7559 +
7560 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7561 int text_fault)
7562 {
7563 @@ -230,6 +504,24 @@ good_area:
7564 if (!(vma->vm_flags & VM_WRITE))
7565 goto bad_area;
7566 } else {
7567 +
7568 +#ifdef CONFIG_PAX_PAGEEXEC
7569 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7570 + up_read(&mm->mmap_sem);
7571 + switch (pax_handle_fetch_fault(regs)) {
7572 +
7573 +#ifdef CONFIG_PAX_EMUPLT
7574 + case 2:
7575 + case 3:
7576 + return;
7577 +#endif
7578 +
7579 + }
7580 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7581 + do_group_exit(SIGKILL);
7582 + }
7583 +#endif
7584 +
7585 /* Allow reads even for write-only mappings */
7586 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7587 goto bad_area;
7588 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7589 index 097aee7..5ca6697 100644
7590 --- a/arch/sparc/mm/fault_64.c
7591 +++ b/arch/sparc/mm/fault_64.c
7592 @@ -21,6 +21,9 @@
7593 #include <linux/kprobes.h>
7594 #include <linux/kdebug.h>
7595 #include <linux/percpu.h>
7596 +#include <linux/slab.h>
7597 +#include <linux/pagemap.h>
7598 +#include <linux/compiler.h>
7599
7600 #include <asm/page.h>
7601 #include <asm/pgtable.h>
7602 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7603 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7604 regs->tpc);
7605 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7606 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7607 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7608 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7609 dump_stack();
7610 unhandled_fault(regs->tpc, current, regs);
7611 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7612 show_regs(regs);
7613 }
7614
7615 +#ifdef CONFIG_PAX_PAGEEXEC
7616 +#ifdef CONFIG_PAX_DLRESOLVE
7617 +static void pax_emuplt_close(struct vm_area_struct *vma)
7618 +{
7619 + vma->vm_mm->call_dl_resolve = 0UL;
7620 +}
7621 +
7622 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7623 +{
7624 + unsigned int *kaddr;
7625 +
7626 + vmf->page = alloc_page(GFP_HIGHUSER);
7627 + if (!vmf->page)
7628 + return VM_FAULT_OOM;
7629 +
7630 + kaddr = kmap(vmf->page);
7631 + memset(kaddr, 0, PAGE_SIZE);
7632 + kaddr[0] = 0x9DE3BFA8U; /* save */
7633 + flush_dcache_page(vmf->page);
7634 + kunmap(vmf->page);
7635 + return VM_FAULT_MAJOR;
7636 +}
7637 +
7638 +static const struct vm_operations_struct pax_vm_ops = {
7639 + .close = pax_emuplt_close,
7640 + .fault = pax_emuplt_fault
7641 +};
7642 +
7643 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7644 +{
7645 + int ret;
7646 +
7647 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7648 + vma->vm_mm = current->mm;
7649 + vma->vm_start = addr;
7650 + vma->vm_end = addr + PAGE_SIZE;
7651 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7652 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7653 + vma->vm_ops = &pax_vm_ops;
7654 +
7655 + ret = insert_vm_struct(current->mm, vma);
7656 + if (ret)
7657 + return ret;
7658 +
7659 + ++current->mm->total_vm;
7660 + return 0;
7661 +}
7662 +#endif
7663 +
7664 +/*
7665 + * PaX: decide what to do with offenders (regs->tpc = fault address)
7666 + *
7667 + * returns 1 when task should be killed
7668 + * 2 when patched PLT trampoline was detected
7669 + * 3 when unpatched PLT trampoline was detected
7670 + */
7671 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7672 +{
7673 +
7674 +#ifdef CONFIG_PAX_EMUPLT
7675 + int err;
7676 +
7677 + do { /* PaX: patched PLT emulation #1 */
7678 + unsigned int sethi1, sethi2, jmpl;
7679 +
7680 + err = get_user(sethi1, (unsigned int *)regs->tpc);
7681 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
7682 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
7683 +
7684 + if (err)
7685 + break;
7686 +
7687 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7688 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7689 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7690 + {
7691 + unsigned long addr;
7692 +
7693 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7694 + addr = regs->u_regs[UREG_G1];
7695 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7696 +
7697 + if (test_thread_flag(TIF_32BIT))
7698 + addr &= 0xFFFFFFFFUL;
7699 +
7700 + regs->tpc = addr;
7701 + regs->tnpc = addr+4;
7702 + return 2;
7703 + }
7704 + } while (0);
7705 +
7706 + do { /* PaX: patched PLT emulation #2 */
7707 + unsigned int ba;
7708 +
7709 + err = get_user(ba, (unsigned int *)regs->tpc);
7710 +
7711 + if (err)
7712 + break;
7713 +
7714 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7715 + unsigned long addr;
7716 +
7717 + if ((ba & 0xFFC00000U) == 0x30800000U)
7718 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7719 + else
7720 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7721 +
7722 + if (test_thread_flag(TIF_32BIT))
7723 + addr &= 0xFFFFFFFFUL;
7724 +
7725 + regs->tpc = addr;
7726 + regs->tnpc = addr+4;
7727 + return 2;
7728 + }
7729 + } while (0);
7730 +
7731 + do { /* PaX: patched PLT emulation #3 */
7732 + unsigned int sethi, bajmpl, nop;
7733 +
7734 + err = get_user(sethi, (unsigned int *)regs->tpc);
7735 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
7736 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7737 +
7738 + if (err)
7739 + break;
7740 +
7741 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7742 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7743 + nop == 0x01000000U)
7744 + {
7745 + unsigned long addr;
7746 +
7747 + addr = (sethi & 0x003FFFFFU) << 10;
7748 + regs->u_regs[UREG_G1] = addr;
7749 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7750 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7751 + else
7752 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7753 +
7754 + if (test_thread_flag(TIF_32BIT))
7755 + addr &= 0xFFFFFFFFUL;
7756 +
7757 + regs->tpc = addr;
7758 + regs->tnpc = addr+4;
7759 + return 2;
7760 + }
7761 + } while (0);
7762 +
7763 + do { /* PaX: patched PLT emulation #4 */
7764 + unsigned int sethi, mov1, call, mov2;
7765 +
7766 + err = get_user(sethi, (unsigned int *)regs->tpc);
7767 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7768 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
7769 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7770 +
7771 + if (err)
7772 + break;
7773 +
7774 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7775 + mov1 == 0x8210000FU &&
7776 + (call & 0xC0000000U) == 0x40000000U &&
7777 + mov2 == 0x9E100001U)
7778 + {
7779 + unsigned long addr;
7780 +
7781 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7782 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7783 +
7784 + if (test_thread_flag(TIF_32BIT))
7785 + addr &= 0xFFFFFFFFUL;
7786 +
7787 + regs->tpc = addr;
7788 + regs->tnpc = addr+4;
7789 + return 2;
7790 + }
7791 + } while (0);
7792 +
7793 + do { /* PaX: patched PLT emulation #5 */
7794 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7795 +
7796 + err = get_user(sethi, (unsigned int *)regs->tpc);
7797 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7798 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7799 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7800 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7801 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7802 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7803 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7804 +
7805 + if (err)
7806 + break;
7807 +
7808 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7809 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7810 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7811 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7812 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7813 + sllx == 0x83287020U &&
7814 + jmpl == 0x81C04005U &&
7815 + nop == 0x01000000U)
7816 + {
7817 + unsigned long addr;
7818 +
7819 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7820 + regs->u_regs[UREG_G1] <<= 32;
7821 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7822 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7823 + regs->tpc = addr;
7824 + regs->tnpc = addr+4;
7825 + return 2;
7826 + }
7827 + } while (0);
7828 +
7829 + do { /* PaX: patched PLT emulation #6 */
7830 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7831 +
7832 + err = get_user(sethi, (unsigned int *)regs->tpc);
7833 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7834 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7835 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7836 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7837 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7838 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7839 +
7840 + if (err)
7841 + break;
7842 +
7843 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7844 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7845 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7846 + sllx == 0x83287020U &&
7847 + (or & 0xFFFFE000U) == 0x8A116000U &&
7848 + jmpl == 0x81C04005U &&
7849 + nop == 0x01000000U)
7850 + {
7851 + unsigned long addr;
7852 +
7853 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7854 + regs->u_regs[UREG_G1] <<= 32;
7855 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7856 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7857 + regs->tpc = addr;
7858 + regs->tnpc = addr+4;
7859 + return 2;
7860 + }
7861 + } while (0);
7862 +
7863 + do { /* PaX: unpatched PLT emulation step 1 */
7864 + unsigned int sethi, ba, nop;
7865 +
7866 + err = get_user(sethi, (unsigned int *)regs->tpc);
7867 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7868 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7869 +
7870 + if (err)
7871 + break;
7872 +
7873 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7874 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7875 + nop == 0x01000000U)
7876 + {
7877 + unsigned long addr;
7878 + unsigned int save, call;
7879 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7880 +
7881 + if ((ba & 0xFFC00000U) == 0x30800000U)
7882 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7883 + else
7884 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7885 +
7886 + if (test_thread_flag(TIF_32BIT))
7887 + addr &= 0xFFFFFFFFUL;
7888 +
7889 + err = get_user(save, (unsigned int *)addr);
7890 + err |= get_user(call, (unsigned int *)(addr+4));
7891 + err |= get_user(nop, (unsigned int *)(addr+8));
7892 + if (err)
7893 + break;
7894 +
7895 +#ifdef CONFIG_PAX_DLRESOLVE
7896 + if (save == 0x9DE3BFA8U &&
7897 + (call & 0xC0000000U) == 0x40000000U &&
7898 + nop == 0x01000000U)
7899 + {
7900 + struct vm_area_struct *vma;
7901 + unsigned long call_dl_resolve;
7902 +
7903 + down_read(&current->mm->mmap_sem);
7904 + call_dl_resolve = current->mm->call_dl_resolve;
7905 + up_read(&current->mm->mmap_sem);
7906 + if (likely(call_dl_resolve))
7907 + goto emulate;
7908 +
7909 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7910 +
7911 + down_write(&current->mm->mmap_sem);
7912 + if (current->mm->call_dl_resolve) {
7913 + call_dl_resolve = current->mm->call_dl_resolve;
7914 + up_write(&current->mm->mmap_sem);
7915 + if (vma)
7916 + kmem_cache_free(vm_area_cachep, vma);
7917 + goto emulate;
7918 + }
7919 +
7920 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7921 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7922 + up_write(&current->mm->mmap_sem);
7923 + if (vma)
7924 + kmem_cache_free(vm_area_cachep, vma);
7925 + return 1;
7926 + }
7927 +
7928 + if (pax_insert_vma(vma, call_dl_resolve)) {
7929 + up_write(&current->mm->mmap_sem);
7930 + kmem_cache_free(vm_area_cachep, vma);
7931 + return 1;
7932 + }
7933 +
7934 + current->mm->call_dl_resolve = call_dl_resolve;
7935 + up_write(&current->mm->mmap_sem);
7936 +
7937 +emulate:
7938 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7939 + regs->tpc = call_dl_resolve;
7940 + regs->tnpc = addr+4;
7941 + return 3;
7942 + }
7943 +#endif
7944 +
7945 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7946 + if ((save & 0xFFC00000U) == 0x05000000U &&
7947 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7948 + nop == 0x01000000U)
7949 + {
7950 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7951 + regs->u_regs[UREG_G2] = addr + 4;
7952 + addr = (save & 0x003FFFFFU) << 10;
7953 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7954 +
7955 + if (test_thread_flag(TIF_32BIT))
7956 + addr &= 0xFFFFFFFFUL;
7957 +
7958 + regs->tpc = addr;
7959 + regs->tnpc = addr+4;
7960 + return 3;
7961 + }
7962 +
7963 + /* PaX: 64-bit PLT stub */
7964 + err = get_user(sethi1, (unsigned int *)addr);
7965 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7966 + err |= get_user(or1, (unsigned int *)(addr+8));
7967 + err |= get_user(or2, (unsigned int *)(addr+12));
7968 + err |= get_user(sllx, (unsigned int *)(addr+16));
7969 + err |= get_user(add, (unsigned int *)(addr+20));
7970 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7971 + err |= get_user(nop, (unsigned int *)(addr+28));
7972 + if (err)
7973 + break;
7974 +
7975 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7976 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7977 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7978 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7979 + sllx == 0x89293020U &&
7980 + add == 0x8A010005U &&
7981 + jmpl == 0x89C14000U &&
7982 + nop == 0x01000000U)
7983 + {
7984 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7985 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7986 + regs->u_regs[UREG_G4] <<= 32;
7987 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7988 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7989 + regs->u_regs[UREG_G4] = addr + 24;
7990 + addr = regs->u_regs[UREG_G5];
7991 + regs->tpc = addr;
7992 + regs->tnpc = addr+4;
7993 + return 3;
7994 + }
7995 + }
7996 + } while (0);
7997 +
7998 +#ifdef CONFIG_PAX_DLRESOLVE
7999 + do { /* PaX: unpatched PLT emulation step 2 */
8000 + unsigned int save, call, nop;
8001 +
8002 + err = get_user(save, (unsigned int *)(regs->tpc-4));
8003 + err |= get_user(call, (unsigned int *)regs->tpc);
8004 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8005 + if (err)
8006 + break;
8007 +
8008 + if (save == 0x9DE3BFA8U &&
8009 + (call & 0xC0000000U) == 0x40000000U &&
8010 + nop == 0x01000000U)
8011 + {
8012 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8013 +
8014 + if (test_thread_flag(TIF_32BIT))
8015 + dl_resolve &= 0xFFFFFFFFUL;
8016 +
8017 + regs->u_regs[UREG_RETPC] = regs->tpc;
8018 + regs->tpc = dl_resolve;
8019 + regs->tnpc = dl_resolve+4;
8020 + return 3;
8021 + }
8022 + } while (0);
8023 +#endif
8024 +
8025 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8026 + unsigned int sethi, ba, nop;
8027 +
8028 + err = get_user(sethi, (unsigned int *)regs->tpc);
8029 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8030 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8031 +
8032 + if (err)
8033 + break;
8034 +
8035 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8036 + (ba & 0xFFF00000U) == 0x30600000U &&
8037 + nop == 0x01000000U)
8038 + {
8039 + unsigned long addr;
8040 +
8041 + addr = (sethi & 0x003FFFFFU) << 10;
8042 + regs->u_regs[UREG_G1] = addr;
8043 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8044 +
8045 + if (test_thread_flag(TIF_32BIT))
8046 + addr &= 0xFFFFFFFFUL;
8047 +
8048 + regs->tpc = addr;
8049 + regs->tnpc = addr+4;
8050 + return 2;
8051 + }
8052 + } while (0);
8053 +
8054 +#endif
8055 +
8056 + return 1;
8057 +}
8058 +
8059 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8060 +{
8061 + unsigned long i;
8062 +
8063 + printk(KERN_ERR "PAX: bytes at PC: ");
8064 + for (i = 0; i < 8; i++) {
8065 + unsigned int c;
8066 + if (get_user(c, (unsigned int *)pc+i))
8067 + printk(KERN_CONT "???????? ");
8068 + else
8069 + printk(KERN_CONT "%08x ", c);
8070 + }
8071 + printk("\n");
8072 +}
8073 +#endif
8074 +
8075 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8076 {
8077 struct mm_struct *mm = current->mm;
8078 @@ -341,6 +804,29 @@ retry:
8079 if (!vma)
8080 goto bad_area;
8081
8082 +#ifdef CONFIG_PAX_PAGEEXEC
8083 + /* PaX: detect ITLB misses on non-exec pages */
8084 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8085 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8086 + {
8087 + if (address != regs->tpc)
8088 + goto good_area;
8089 +
8090 + up_read(&mm->mmap_sem);
8091 + switch (pax_handle_fetch_fault(regs)) {
8092 +
8093 +#ifdef CONFIG_PAX_EMUPLT
8094 + case 2:
8095 + case 3:
8096 + return;
8097 +#endif
8098 +
8099 + }
8100 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8101 + do_group_exit(SIGKILL);
8102 + }
8103 +#endif
8104 +
8105 /* Pure DTLB misses do not tell us whether the fault causing
8106 * load/store/atomic was a write or not, it only says that there
8107 * was no match. So in such a case we (carefully) read the
8108 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8109 index f76f83d..0f28457 100644
8110 --- a/arch/sparc/mm/hugetlbpage.c
8111 +++ b/arch/sparc/mm/hugetlbpage.c
8112 @@ -67,7 +67,7 @@ full_search:
8113 }
8114 return -ENOMEM;
8115 }
8116 - if (likely(!vma || addr + len <= vma->vm_start)) {
8117 + if (likely(check_heap_stack_gap(vma, addr, len))) {
8118 /*
8119 * Remember the place where we stopped the search:
8120 */
8121 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8122 /* make sure it can fit in the remaining address space */
8123 if (likely(addr > len)) {
8124 vma = find_vma(mm, addr-len);
8125 - if (!vma || addr <= vma->vm_start) {
8126 + if (check_heap_stack_gap(vma, addr - len, len)) {
8127 /* remember the address as a hint for next time */
8128 return (mm->free_area_cache = addr-len);
8129 }
8130 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8131 if (unlikely(mm->mmap_base < len))
8132 goto bottomup;
8133
8134 - addr = (mm->mmap_base-len) & HPAGE_MASK;
8135 + addr = mm->mmap_base - len;
8136
8137 do {
8138 + addr &= HPAGE_MASK;
8139 /*
8140 * Lookup failure means no vma is above this address,
8141 * else if new region fits below vma->vm_start,
8142 * return with success:
8143 */
8144 vma = find_vma(mm, addr);
8145 - if (likely(!vma || addr+len <= vma->vm_start)) {
8146 + if (likely(check_heap_stack_gap(vma, addr, len))) {
8147 /* remember the address as a hint for next time */
8148 return (mm->free_area_cache = addr);
8149 }
8150 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8151 mm->cached_hole_size = vma->vm_start - addr;
8152
8153 /* try just below the current vma->vm_start */
8154 - addr = (vma->vm_start-len) & HPAGE_MASK;
8155 - } while (likely(len < vma->vm_start));
8156 + addr = skip_heap_stack_gap(vma, len);
8157 + } while (!IS_ERR_VALUE(addr));
8158
8159 bottomup:
8160 /*
8161 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8162 if (addr) {
8163 addr = ALIGN(addr, HPAGE_SIZE);
8164 vma = find_vma(mm, addr);
8165 - if (task_size - len >= addr &&
8166 - (!vma || addr + len <= vma->vm_start))
8167 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
8168 return addr;
8169 }
8170 if (mm->get_unmapped_area == arch_get_unmapped_area)
8171 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8172 index f4500c6..889656c 100644
8173 --- a/arch/tile/include/asm/atomic_64.h
8174 +++ b/arch/tile/include/asm/atomic_64.h
8175 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8176
8177 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8178
8179 +#define atomic64_read_unchecked(v) atomic64_read(v)
8180 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8181 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8182 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8183 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8184 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8185 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8186 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8187 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8188 +
8189 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8190 #define smp_mb__before_atomic_dec() smp_mb()
8191 #define smp_mb__after_atomic_dec() smp_mb()
8192 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8193 index a9a5299..0fce79e 100644
8194 --- a/arch/tile/include/asm/cache.h
8195 +++ b/arch/tile/include/asm/cache.h
8196 @@ -15,11 +15,12 @@
8197 #ifndef _ASM_TILE_CACHE_H
8198 #define _ASM_TILE_CACHE_H
8199
8200 +#include <linux/const.h>
8201 #include <arch/chip.h>
8202
8203 /* bytes per L1 data cache line */
8204 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8205 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8206 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8207
8208 /* bytes per L2 cache line */
8209 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8210 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8211 index 9ab078a..d6635c2 100644
8212 --- a/arch/tile/include/asm/uaccess.h
8213 +++ b/arch/tile/include/asm/uaccess.h
8214 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8215 const void __user *from,
8216 unsigned long n)
8217 {
8218 - int sz = __compiletime_object_size(to);
8219 + size_t sz = __compiletime_object_size(to);
8220
8221 - if (likely(sz == -1 || sz >= n))
8222 + if (likely(sz == (size_t)-1 || sz >= n))
8223 n = _copy_from_user(to, from, n);
8224 else
8225 copy_from_user_overflow();
8226 diff --git a/arch/um/Makefile b/arch/um/Makefile
8227 index 133f7de..1d6f2f1 100644
8228 --- a/arch/um/Makefile
8229 +++ b/arch/um/Makefile
8230 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8231 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8232 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8233
8234 +ifdef CONSTIFY_PLUGIN
8235 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8236 +endif
8237 +
8238 #This will adjust *FLAGS accordingly to the platform.
8239 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8240
8241 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8242 index 19e1bdd..3665b77 100644
8243 --- a/arch/um/include/asm/cache.h
8244 +++ b/arch/um/include/asm/cache.h
8245 @@ -1,6 +1,7 @@
8246 #ifndef __UM_CACHE_H
8247 #define __UM_CACHE_H
8248
8249 +#include <linux/const.h>
8250
8251 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8252 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8253 @@ -12,6 +13,6 @@
8254 # define L1_CACHE_SHIFT 5
8255 #endif
8256
8257 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8258 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8259
8260 #endif
8261 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8262 index 2e0a6b1..a64d0f5 100644
8263 --- a/arch/um/include/asm/kmap_types.h
8264 +++ b/arch/um/include/asm/kmap_types.h
8265 @@ -8,6 +8,6 @@
8266
8267 /* No more #include "asm/arch/kmap_types.h" ! */
8268
8269 -#define KM_TYPE_NR 14
8270 +#define KM_TYPE_NR 15
8271
8272 #endif
8273 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8274 index 5ff53d9..5850cdf 100644
8275 --- a/arch/um/include/asm/page.h
8276 +++ b/arch/um/include/asm/page.h
8277 @@ -14,6 +14,9 @@
8278 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8279 #define PAGE_MASK (~(PAGE_SIZE-1))
8280
8281 +#define ktla_ktva(addr) (addr)
8282 +#define ktva_ktla(addr) (addr)
8283 +
8284 #ifndef __ASSEMBLY__
8285
8286 struct page;
8287 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8288 index 0032f92..cd151e0 100644
8289 --- a/arch/um/include/asm/pgtable-3level.h
8290 +++ b/arch/um/include/asm/pgtable-3level.h
8291 @@ -58,6 +58,7 @@
8292 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8293 #define pud_populate(mm, pud, pmd) \
8294 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8295 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8296
8297 #ifdef CONFIG_64BIT
8298 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8299 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8300 index b6d699c..df7ac1d 100644
8301 --- a/arch/um/kernel/process.c
8302 +++ b/arch/um/kernel/process.c
8303 @@ -387,22 +387,6 @@ int singlestepping(void * t)
8304 return 2;
8305 }
8306
8307 -/*
8308 - * Only x86 and x86_64 have an arch_align_stack().
8309 - * All other arches have "#define arch_align_stack(x) (x)"
8310 - * in their asm/system.h
8311 - * As this is included in UML from asm-um/system-generic.h,
8312 - * we can use it to behave as the subarch does.
8313 - */
8314 -#ifndef arch_align_stack
8315 -unsigned long arch_align_stack(unsigned long sp)
8316 -{
8317 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8318 - sp -= get_random_int() % 8192;
8319 - return sp & ~0xf;
8320 -}
8321 -#endif
8322 -
8323 unsigned long get_wchan(struct task_struct *p)
8324 {
8325 unsigned long stack_page, sp, ip;
8326 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8327 index ad8f795..2c7eec6 100644
8328 --- a/arch/unicore32/include/asm/cache.h
8329 +++ b/arch/unicore32/include/asm/cache.h
8330 @@ -12,8 +12,10 @@
8331 #ifndef __UNICORE_CACHE_H__
8332 #define __UNICORE_CACHE_H__
8333
8334 -#define L1_CACHE_SHIFT (5)
8335 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8336 +#include <linux/const.h>
8337 +
8338 +#define L1_CACHE_SHIFT 5
8339 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8340
8341 /*
8342 * Memory returned by kmalloc() may be used for DMA, so we must make
8343 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8344 index 46c3bff..c2286e7 100644
8345 --- a/arch/x86/Kconfig
8346 +++ b/arch/x86/Kconfig
8347 @@ -241,7 +241,7 @@ config X86_HT
8348
8349 config X86_32_LAZY_GS
8350 def_bool y
8351 - depends on X86_32 && !CC_STACKPROTECTOR
8352 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8353
8354 config ARCH_HWEIGHT_CFLAGS
8355 string
8356 @@ -1056,7 +1056,7 @@ choice
8357
8358 config NOHIGHMEM
8359 bool "off"
8360 - depends on !X86_NUMAQ
8361 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8362 ---help---
8363 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8364 However, the address space of 32-bit x86 processors is only 4
8365 @@ -1093,7 +1093,7 @@ config NOHIGHMEM
8366
8367 config HIGHMEM4G
8368 bool "4GB"
8369 - depends on !X86_NUMAQ
8370 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8371 ---help---
8372 Select this if you have a 32-bit processor and between 1 and 4
8373 gigabytes of physical RAM.
8374 @@ -1147,7 +1147,7 @@ config PAGE_OFFSET
8375 hex
8376 default 0xB0000000 if VMSPLIT_3G_OPT
8377 default 0x80000000 if VMSPLIT_2G
8378 - default 0x78000000 if VMSPLIT_2G_OPT
8379 + default 0x70000000 if VMSPLIT_2G_OPT
8380 default 0x40000000 if VMSPLIT_1G
8381 default 0xC0000000
8382 depends on X86_32
8383 @@ -1548,6 +1548,7 @@ config SECCOMP
8384
8385 config CC_STACKPROTECTOR
8386 bool "Enable -fstack-protector buffer overflow detection"
8387 + depends on X86_64 || !PAX_MEMORY_UDEREF
8388 ---help---
8389 This option turns on the -fstack-protector GCC feature. This
8390 feature puts, at the beginning of functions, a canary value on
8391 @@ -1605,6 +1606,7 @@ config KEXEC_JUMP
8392 config PHYSICAL_START
8393 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8394 default "0x1000000"
8395 + range 0x400000 0x40000000
8396 ---help---
8397 This gives the physical address where the kernel is loaded.
8398
8399 @@ -1668,6 +1670,7 @@ config X86_NEED_RELOCS
8400 config PHYSICAL_ALIGN
8401 hex "Alignment value to which kernel should be aligned" if X86_32
8402 default "0x1000000"
8403 + range 0x400000 0x1000000 if PAX_KERNEXEC
8404 range 0x2000 0x1000000
8405 ---help---
8406 This value puts the alignment restrictions on physical address
8407 @@ -1699,9 +1702,10 @@ config HOTPLUG_CPU
8408 Say N if you want to disable CPU hotplug.
8409
8410 config COMPAT_VDSO
8411 - def_bool y
8412 + def_bool n
8413 prompt "Compat VDSO support"
8414 depends on X86_32 || IA32_EMULATION
8415 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
8416 ---help---
8417 Map the 32-bit VDSO to the predictable old-style address too.
8418
8419 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8420 index f3b86d0..17fd30f 100644
8421 --- a/arch/x86/Kconfig.cpu
8422 +++ b/arch/x86/Kconfig.cpu
8423 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8424
8425 config X86_F00F_BUG
8426 def_bool y
8427 - depends on M586MMX || M586TSC || M586 || M486 || M386
8428 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8429
8430 config X86_INVD_BUG
8431 def_bool y
8432 @@ -359,7 +359,7 @@ config X86_POPAD_OK
8433
8434 config X86_ALIGNMENT_16
8435 def_bool y
8436 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8437 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8438
8439 config X86_INTEL_USERCOPY
8440 def_bool y
8441 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
8442 # generates cmov.
8443 config X86_CMOV
8444 def_bool y
8445 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8446 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8447
8448 config X86_MINIMUM_CPU_FAMILY
8449 int
8450 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8451 index b322f12..652d0d9 100644
8452 --- a/arch/x86/Kconfig.debug
8453 +++ b/arch/x86/Kconfig.debug
8454 @@ -84,7 +84,7 @@ config X86_PTDUMP
8455 config DEBUG_RODATA
8456 bool "Write protect kernel read-only data structures"
8457 default y
8458 - depends on DEBUG_KERNEL
8459 + depends on DEBUG_KERNEL && BROKEN
8460 ---help---
8461 Mark the kernel read-only data as write-protected in the pagetables,
8462 in order to catch accidental (and incorrect) writes to such const
8463 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8464
8465 config DEBUG_SET_MODULE_RONX
8466 bool "Set loadable kernel module data as NX and text as RO"
8467 - depends on MODULES
8468 + depends on MODULES && BROKEN
8469 ---help---
8470 This option helps catch unintended modifications to loadable
8471 kernel module's text and read-only data. It also prevents execution
8472 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8473
8474 config DEBUG_STRICT_USER_COPY_CHECKS
8475 bool "Strict copy size checks"
8476 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8477 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8478 ---help---
8479 Enabling this option turns a certain set of sanity checks for user
8480 copy operations into compile time failures.
8481 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8482 index 05afcca..b6ecb51 100644
8483 --- a/arch/x86/Makefile
8484 +++ b/arch/x86/Makefile
8485 @@ -50,6 +50,7 @@ else
8486 UTS_MACHINE := x86_64
8487 CHECKFLAGS += -D__x86_64__ -m64
8488
8489 + biarch := $(call cc-option,-m64)
8490 KBUILD_AFLAGS += -m64
8491 KBUILD_CFLAGS += -m64
8492
8493 @@ -229,3 +230,12 @@ define archhelp
8494 echo ' FDARGS="..." arguments for the booted kernel'
8495 echo ' FDINITRD=file initrd for the booted kernel'
8496 endef
8497 +
8498 +define OLD_LD
8499 +
8500 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8501 +*** Please upgrade your binutils to 2.18 or newer
8502 +endef
8503 +
8504 +archprepare:
8505 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8506 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8507 index ccce0ed..fd9da25 100644
8508 --- a/arch/x86/boot/Makefile
8509 +++ b/arch/x86/boot/Makefile
8510 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8511 $(call cc-option, -fno-stack-protector) \
8512 $(call cc-option, -mpreferred-stack-boundary=2)
8513 KBUILD_CFLAGS += $(call cc-option, -m32)
8514 +ifdef CONSTIFY_PLUGIN
8515 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8516 +endif
8517 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8518 GCOV_PROFILE := n
8519
8520 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8521 index 878e4b9..20537ab 100644
8522 --- a/arch/x86/boot/bitops.h
8523 +++ b/arch/x86/boot/bitops.h
8524 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8525 u8 v;
8526 const u32 *p = (const u32 *)addr;
8527
8528 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8529 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8530 return v;
8531 }
8532
8533 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8534
8535 static inline void set_bit(int nr, void *addr)
8536 {
8537 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8538 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8539 }
8540
8541 #endif /* BOOT_BITOPS_H */
8542 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8543 index 18997e5..83d9c67 100644
8544 --- a/arch/x86/boot/boot.h
8545 +++ b/arch/x86/boot/boot.h
8546 @@ -85,7 +85,7 @@ static inline void io_delay(void)
8547 static inline u16 ds(void)
8548 {
8549 u16 seg;
8550 - asm("movw %%ds,%0" : "=rm" (seg));
8551 + asm volatile("movw %%ds,%0" : "=rm" (seg));
8552 return seg;
8553 }
8554
8555 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8556 static inline int memcmp(const void *s1, const void *s2, size_t len)
8557 {
8558 u8 diff;
8559 - asm("repe; cmpsb; setnz %0"
8560 + asm volatile("repe; cmpsb; setnz %0"
8561 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8562 return diff;
8563 }
8564 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8565 index 8a84501..b2d165f 100644
8566 --- a/arch/x86/boot/compressed/Makefile
8567 +++ b/arch/x86/boot/compressed/Makefile
8568 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8569 KBUILD_CFLAGS += $(cflags-y)
8570 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8571 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8572 +ifdef CONSTIFY_PLUGIN
8573 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8574 +endif
8575
8576 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8577 GCOV_PROFILE := n
8578 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8579 index e87b0ca..2bce457 100644
8580 --- a/arch/x86/boot/compressed/eboot.c
8581 +++ b/arch/x86/boot/compressed/eboot.c
8582 @@ -144,7 +144,6 @@ again:
8583 *addr = max_addr;
8584 }
8585
8586 -free_pool:
8587 efi_call_phys1(sys_table->boottime->free_pool, map);
8588
8589 fail:
8590 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8591 if (i == map_size / desc_size)
8592 status = EFI_NOT_FOUND;
8593
8594 -free_pool:
8595 efi_call_phys1(sys_table->boottime->free_pool, map);
8596 fail:
8597 return status;
8598 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8599 index aa4aaf1..6656f2f 100644
8600 --- a/arch/x86/boot/compressed/head_32.S
8601 +++ b/arch/x86/boot/compressed/head_32.S
8602 @@ -116,7 +116,7 @@ preferred_addr:
8603 notl %eax
8604 andl %eax, %ebx
8605 #else
8606 - movl $LOAD_PHYSICAL_ADDR, %ebx
8607 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8608 #endif
8609
8610 /* Target address to relocate to for decompression */
8611 @@ -202,7 +202,7 @@ relocated:
8612 * and where it was actually loaded.
8613 */
8614 movl %ebp, %ebx
8615 - subl $LOAD_PHYSICAL_ADDR, %ebx
8616 + subl $____LOAD_PHYSICAL_ADDR, %ebx
8617 jz 2f /* Nothing to be done if loaded at compiled addr. */
8618 /*
8619 * Process relocations.
8620 @@ -210,8 +210,7 @@ relocated:
8621
8622 1: subl $4, %edi
8623 movl (%edi), %ecx
8624 - testl %ecx, %ecx
8625 - jz 2f
8626 + jecxz 2f
8627 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8628 jmp 1b
8629 2:
8630 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8631 index 2c4b171..e1fa5b1 100644
8632 --- a/arch/x86/boot/compressed/head_64.S
8633 +++ b/arch/x86/boot/compressed/head_64.S
8634 @@ -91,7 +91,7 @@ ENTRY(startup_32)
8635 notl %eax
8636 andl %eax, %ebx
8637 #else
8638 - movl $LOAD_PHYSICAL_ADDR, %ebx
8639 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8640 #endif
8641
8642 /* Target address to relocate to for decompression */
8643 @@ -273,7 +273,7 @@ preferred_addr:
8644 notq %rax
8645 andq %rax, %rbp
8646 #else
8647 - movq $LOAD_PHYSICAL_ADDR, %rbp
8648 + movq $____LOAD_PHYSICAL_ADDR, %rbp
8649 #endif
8650
8651 /* Target address to relocate to for decompression */
8652 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
8653 index 88f7ff6..ed695dd 100644
8654 --- a/arch/x86/boot/compressed/misc.c
8655 +++ b/arch/x86/boot/compressed/misc.c
8656 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
8657 case PT_LOAD:
8658 #ifdef CONFIG_RELOCATABLE
8659 dest = output;
8660 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
8661 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
8662 #else
8663 dest = (void *)(phdr->p_paddr);
8664 #endif
8665 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
8666 error("Destination address too large");
8667 #endif
8668 #ifndef CONFIG_RELOCATABLE
8669 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
8670 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
8671 error("Wrong destination address");
8672 #endif
8673
8674 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
8675 index 4d3ff03..e4972ff 100644
8676 --- a/arch/x86/boot/cpucheck.c
8677 +++ b/arch/x86/boot/cpucheck.c
8678 @@ -74,7 +74,7 @@ static int has_fpu(void)
8679 u16 fcw = -1, fsw = -1;
8680 u32 cr0;
8681
8682 - asm("movl %%cr0,%0" : "=r" (cr0));
8683 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
8684 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
8685 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
8686 asm volatile("movl %0,%%cr0" : : "r" (cr0));
8687 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
8688 {
8689 u32 f0, f1;
8690
8691 - asm("pushfl ; "
8692 + asm volatile("pushfl ; "
8693 "pushfl ; "
8694 "popl %0 ; "
8695 "movl %0,%1 ; "
8696 @@ -115,7 +115,7 @@ static void get_flags(void)
8697 set_bit(X86_FEATURE_FPU, cpu.flags);
8698
8699 if (has_eflag(X86_EFLAGS_ID)) {
8700 - asm("cpuid"
8701 + asm volatile("cpuid"
8702 : "=a" (max_intel_level),
8703 "=b" (cpu_vendor[0]),
8704 "=d" (cpu_vendor[1]),
8705 @@ -124,7 +124,7 @@ static void get_flags(void)
8706
8707 if (max_intel_level >= 0x00000001 &&
8708 max_intel_level <= 0x0000ffff) {
8709 - asm("cpuid"
8710 + asm volatile("cpuid"
8711 : "=a" (tfms),
8712 "=c" (cpu.flags[4]),
8713 "=d" (cpu.flags[0])
8714 @@ -136,7 +136,7 @@ static void get_flags(void)
8715 cpu.model += ((tfms >> 16) & 0xf) << 4;
8716 }
8717
8718 - asm("cpuid"
8719 + asm volatile("cpuid"
8720 : "=a" (max_amd_level)
8721 : "a" (0x80000000)
8722 : "ebx", "ecx", "edx");
8723 @@ -144,7 +144,7 @@ static void get_flags(void)
8724 if (max_amd_level >= 0x80000001 &&
8725 max_amd_level <= 0x8000ffff) {
8726 u32 eax = 0x80000001;
8727 - asm("cpuid"
8728 + asm volatile("cpuid"
8729 : "+a" (eax),
8730 "=c" (cpu.flags[6]),
8731 "=d" (cpu.flags[1])
8732 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8733 u32 ecx = MSR_K7_HWCR;
8734 u32 eax, edx;
8735
8736 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8737 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8738 eax &= ~(1 << 15);
8739 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8740 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8741
8742 get_flags(); /* Make sure it really did something */
8743 err = check_flags();
8744 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8745 u32 ecx = MSR_VIA_FCR;
8746 u32 eax, edx;
8747
8748 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8749 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8750 eax |= (1<<1)|(1<<7);
8751 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8752 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8753
8754 set_bit(X86_FEATURE_CX8, cpu.flags);
8755 err = check_flags();
8756 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8757 u32 eax, edx;
8758 u32 level = 1;
8759
8760 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8761 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8762 - asm("cpuid"
8763 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8764 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8765 + asm volatile("cpuid"
8766 : "+a" (level), "=d" (cpu.flags[0])
8767 : : "ecx", "ebx");
8768 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8769 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8770
8771 err = check_flags();
8772 }
8773 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8774 index 8c132a6..13e5c96 100644
8775 --- a/arch/x86/boot/header.S
8776 +++ b/arch/x86/boot/header.S
8777 @@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8778 # single linked list of
8779 # struct setup_data
8780
8781 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8782 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8783
8784 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8785 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8786 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8787 +#else
8788 #define VO_INIT_SIZE (VO__end - VO__text)
8789 +#endif
8790 #if ZO_INIT_SIZE > VO_INIT_SIZE
8791 #define INIT_SIZE ZO_INIT_SIZE
8792 #else
8793 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8794 index db75d07..8e6d0af 100644
8795 --- a/arch/x86/boot/memory.c
8796 +++ b/arch/x86/boot/memory.c
8797 @@ -19,7 +19,7 @@
8798
8799 static int detect_memory_e820(void)
8800 {
8801 - int count = 0;
8802 + unsigned int count = 0;
8803 struct biosregs ireg, oreg;
8804 struct e820entry *desc = boot_params.e820_map;
8805 static struct e820entry buf; /* static so it is zeroed */
8806 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8807 index 11e8c6e..fdbb1ed 100644
8808 --- a/arch/x86/boot/video-vesa.c
8809 +++ b/arch/x86/boot/video-vesa.c
8810 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8811
8812 boot_params.screen_info.vesapm_seg = oreg.es;
8813 boot_params.screen_info.vesapm_off = oreg.di;
8814 + boot_params.screen_info.vesapm_size = oreg.cx;
8815 }
8816
8817 /*
8818 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8819 index 43eda28..5ab5fdb 100644
8820 --- a/arch/x86/boot/video.c
8821 +++ b/arch/x86/boot/video.c
8822 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8823 static unsigned int get_entry(void)
8824 {
8825 char entry_buf[4];
8826 - int i, len = 0;
8827 + unsigned int i, len = 0;
8828 int key;
8829 unsigned int v;
8830
8831 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8832 index 5b577d5..3c1fed4 100644
8833 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8834 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8835 @@ -8,6 +8,8 @@
8836 * including this sentence is retained in full.
8837 */
8838
8839 +#include <asm/alternative-asm.h>
8840 +
8841 .extern crypto_ft_tab
8842 .extern crypto_it_tab
8843 .extern crypto_fl_tab
8844 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8845 je B192; \
8846 leaq 32(r9),r9;
8847
8848 +#define ret pax_force_retaddr 0, 1; ret
8849 +
8850 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8851 movq r1,r2; \
8852 movq r3,r4; \
8853 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8854 index 3470624..201259d 100644
8855 --- a/arch/x86/crypto/aesni-intel_asm.S
8856 +++ b/arch/x86/crypto/aesni-intel_asm.S
8857 @@ -31,6 +31,7 @@
8858
8859 #include <linux/linkage.h>
8860 #include <asm/inst.h>
8861 +#include <asm/alternative-asm.h>
8862
8863 #ifdef __x86_64__
8864 .data
8865 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8866 pop %r14
8867 pop %r13
8868 pop %r12
8869 + pax_force_retaddr 0, 1
8870 ret
8871 +ENDPROC(aesni_gcm_dec)
8872
8873
8874 /*****************************************************************************
8875 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8876 pop %r14
8877 pop %r13
8878 pop %r12
8879 + pax_force_retaddr 0, 1
8880 ret
8881 +ENDPROC(aesni_gcm_enc)
8882
8883 #endif
8884
8885 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8886 pxor %xmm1, %xmm0
8887 movaps %xmm0, (TKEYP)
8888 add $0x10, TKEYP
8889 + pax_force_retaddr_bts
8890 ret
8891
8892 .align 4
8893 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8894 shufps $0b01001110, %xmm2, %xmm1
8895 movaps %xmm1, 0x10(TKEYP)
8896 add $0x20, TKEYP
8897 + pax_force_retaddr_bts
8898 ret
8899
8900 .align 4
8901 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8902
8903 movaps %xmm0, (TKEYP)
8904 add $0x10, TKEYP
8905 + pax_force_retaddr_bts
8906 ret
8907
8908 .align 4
8909 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8910 pxor %xmm1, %xmm2
8911 movaps %xmm2, (TKEYP)
8912 add $0x10, TKEYP
8913 + pax_force_retaddr_bts
8914 ret
8915
8916 /*
8917 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8918 #ifndef __x86_64__
8919 popl KEYP
8920 #endif
8921 + pax_force_retaddr 0, 1
8922 ret
8923 +ENDPROC(aesni_set_key)
8924
8925 /*
8926 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8927 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8928 popl KLEN
8929 popl KEYP
8930 #endif
8931 + pax_force_retaddr 0, 1
8932 ret
8933 +ENDPROC(aesni_enc)
8934
8935 /*
8936 * _aesni_enc1: internal ABI
8937 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8938 AESENC KEY STATE
8939 movaps 0x70(TKEYP), KEY
8940 AESENCLAST KEY STATE
8941 + pax_force_retaddr_bts
8942 ret
8943
8944 /*
8945 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8946 AESENCLAST KEY STATE2
8947 AESENCLAST KEY STATE3
8948 AESENCLAST KEY STATE4
8949 + pax_force_retaddr_bts
8950 ret
8951
8952 /*
8953 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8954 popl KLEN
8955 popl KEYP
8956 #endif
8957 + pax_force_retaddr 0, 1
8958 ret
8959 +ENDPROC(aesni_dec)
8960
8961 /*
8962 * _aesni_dec1: internal ABI
8963 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8964 AESDEC KEY STATE
8965 movaps 0x70(TKEYP), KEY
8966 AESDECLAST KEY STATE
8967 + pax_force_retaddr_bts
8968 ret
8969
8970 /*
8971 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8972 AESDECLAST KEY STATE2
8973 AESDECLAST KEY STATE3
8974 AESDECLAST KEY STATE4
8975 + pax_force_retaddr_bts
8976 ret
8977
8978 /*
8979 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8980 popl KEYP
8981 popl LEN
8982 #endif
8983 + pax_force_retaddr 0, 1
8984 ret
8985 +ENDPROC(aesni_ecb_enc)
8986
8987 /*
8988 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8989 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8990 popl KEYP
8991 popl LEN
8992 #endif
8993 + pax_force_retaddr 0, 1
8994 ret
8995 +ENDPROC(aesni_ecb_dec)
8996
8997 /*
8998 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8999 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9000 popl LEN
9001 popl IVP
9002 #endif
9003 + pax_force_retaddr 0, 1
9004 ret
9005 +ENDPROC(aesni_cbc_enc)
9006
9007 /*
9008 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9009 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9010 popl LEN
9011 popl IVP
9012 #endif
9013 + pax_force_retaddr 0, 1
9014 ret
9015 +ENDPROC(aesni_cbc_dec)
9016
9017 #ifdef __x86_64__
9018 .align 16
9019 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
9020 mov $1, TCTR_LOW
9021 MOVQ_R64_XMM TCTR_LOW INC
9022 MOVQ_R64_XMM CTR TCTR_LOW
9023 + pax_force_retaddr_bts
9024 ret
9025
9026 /*
9027 @@ -2554,6 +2582,7 @@ _aesni_inc:
9028 .Linc_low:
9029 movaps CTR, IV
9030 PSHUFB_XMM BSWAP_MASK IV
9031 + pax_force_retaddr_bts
9032 ret
9033
9034 /*
9035 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9036 .Lctr_enc_ret:
9037 movups IV, (IVP)
9038 .Lctr_enc_just_ret:
9039 + pax_force_retaddr 0, 1
9040 ret
9041 +ENDPROC(aesni_ctr_enc)
9042 #endif
9043 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9044 index 391d245..67f35c2 100644
9045 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9046 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9047 @@ -20,6 +20,8 @@
9048 *
9049 */
9050
9051 +#include <asm/alternative-asm.h>
9052 +
9053 .file "blowfish-x86_64-asm.S"
9054 .text
9055
9056 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
9057 jnz __enc_xor;
9058
9059 write_block();
9060 + pax_force_retaddr 0, 1
9061 ret;
9062 __enc_xor:
9063 xor_block();
9064 + pax_force_retaddr 0, 1
9065 ret;
9066
9067 .align 8
9068 @@ -188,6 +192,7 @@ blowfish_dec_blk:
9069
9070 movq %r11, %rbp;
9071
9072 + pax_force_retaddr 0, 1
9073 ret;
9074
9075 /**********************************************************************
9076 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9077
9078 popq %rbx;
9079 popq %rbp;
9080 + pax_force_retaddr 0, 1
9081 ret;
9082
9083 __enc_xor4:
9084 @@ -349,6 +355,7 @@ __enc_xor4:
9085
9086 popq %rbx;
9087 popq %rbp;
9088 + pax_force_retaddr 0, 1
9089 ret;
9090
9091 .align 8
9092 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9093 popq %rbx;
9094 popq %rbp;
9095
9096 + pax_force_retaddr 0, 1
9097 ret;
9098
9099 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9100 index 0b33743..7a56206 100644
9101 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9102 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9103 @@ -20,6 +20,8 @@
9104 *
9105 */
9106
9107 +#include <asm/alternative-asm.h>
9108 +
9109 .file "camellia-x86_64-asm_64.S"
9110 .text
9111
9112 @@ -229,12 +231,14 @@ __enc_done:
9113 enc_outunpack(mov, RT1);
9114
9115 movq RRBP, %rbp;
9116 + pax_force_retaddr 0, 1
9117 ret;
9118
9119 __enc_xor:
9120 enc_outunpack(xor, RT1);
9121
9122 movq RRBP, %rbp;
9123 + pax_force_retaddr 0, 1
9124 ret;
9125
9126 .global camellia_dec_blk;
9127 @@ -275,6 +279,7 @@ __dec_rounds16:
9128 dec_outunpack();
9129
9130 movq RRBP, %rbp;
9131 + pax_force_retaddr 0, 1
9132 ret;
9133
9134 /**********************************************************************
9135 @@ -468,6 +473,7 @@ __enc2_done:
9136
9137 movq RRBP, %rbp;
9138 popq %rbx;
9139 + pax_force_retaddr 0, 1
9140 ret;
9141
9142 __enc2_xor:
9143 @@ -475,6 +481,7 @@ __enc2_xor:
9144
9145 movq RRBP, %rbp;
9146 popq %rbx;
9147 + pax_force_retaddr 0, 1
9148 ret;
9149
9150 .global camellia_dec_blk_2way;
9151 @@ -517,4 +524,5 @@ __dec2_rounds16:
9152
9153 movq RRBP, %rbp;
9154 movq RXOR, %rbx;
9155 + pax_force_retaddr 0, 1
9156 ret;
9157 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9158 index a41a3aa..bdf5753 100644
9159 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9160 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9161 @@ -23,6 +23,8 @@
9162 *
9163 */
9164
9165 +#include <asm/alternative-asm.h>
9166 +
9167 .file "cast5-avx-x86_64-asm_64.S"
9168
9169 .extern cast5_s1
9170 @@ -293,6 +295,7 @@ __skip_enc:
9171 leaq 3*(2*4*4)(%r11), %rax;
9172 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9173
9174 + pax_force_retaddr 0, 1
9175 ret;
9176
9177 __enc_xor16:
9178 @@ -303,6 +306,7 @@ __enc_xor16:
9179 leaq 3*(2*4*4)(%r11), %rax;
9180 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9181
9182 + pax_force_retaddr 0, 1
9183 ret;
9184
9185 .align 16
9186 @@ -369,6 +373,7 @@ __dec_tail:
9187 leaq 3*(2*4*4)(%r11), %rax;
9188 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9189
9190 + pax_force_retaddr 0, 1
9191 ret;
9192
9193 __skip_dec:
9194 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9195 index 218d283..819e6da 100644
9196 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9197 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9198 @@ -23,6 +23,8 @@
9199 *
9200 */
9201
9202 +#include <asm/alternative-asm.h>
9203 +
9204 .file "cast6-avx-x86_64-asm_64.S"
9205
9206 .extern cast6_s1
9207 @@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9208 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9209 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9210
9211 + pax_force_retaddr 0, 1
9212 ret;
9213
9214 __enc_xor8:
9215 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9216 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9217
9218 + pax_force_retaddr 0, 1
9219 ret;
9220
9221 .align 16
9222 @@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9223 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9224 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9225
9226 + pax_force_retaddr 0, 1
9227 ret;
9228 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9229 index 6214a9b..1f4fc9a 100644
9230 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9231 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9232 @@ -1,3 +1,5 @@
9233 +#include <asm/alternative-asm.h>
9234 +
9235 # enter ECRYPT_encrypt_bytes
9236 .text
9237 .p2align 5
9238 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9239 add %r11,%rsp
9240 mov %rdi,%rax
9241 mov %rsi,%rdx
9242 + pax_force_retaddr 0, 1
9243 ret
9244 # bytesatleast65:
9245 ._bytesatleast65:
9246 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
9247 add %r11,%rsp
9248 mov %rdi,%rax
9249 mov %rsi,%rdx
9250 + pax_force_retaddr
9251 ret
9252 # enter ECRYPT_ivsetup
9253 .text
9254 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9255 add %r11,%rsp
9256 mov %rdi,%rax
9257 mov %rsi,%rdx
9258 + pax_force_retaddr
9259 ret
9260 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9261 index 504106b..4e50951 100644
9262 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9263 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9264 @@ -24,6 +24,8 @@
9265 *
9266 */
9267
9268 +#include <asm/alternative-asm.h>
9269 +
9270 .file "serpent-avx-x86_64-asm_64.S"
9271 .text
9272
9273 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9274 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9275 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9276
9277 + pax_force_retaddr
9278 ret;
9279
9280 __enc_xor8:
9281 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9282 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9283
9284 + pax_force_retaddr
9285 ret;
9286
9287 .align 8
9288 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9289 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9290 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9291
9292 + pax_force_retaddr
9293 ret;
9294 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9295 index 3ee1ff0..cbc568b 100644
9296 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9297 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9298 @@ -24,6 +24,8 @@
9299 *
9300 */
9301
9302 +#include <asm/alternative-asm.h>
9303 +
9304 .file "serpent-sse2-x86_64-asm_64.S"
9305 .text
9306
9307 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9308 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9309 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9310
9311 + pax_force_retaddr
9312 ret;
9313
9314 __enc_xor8:
9315 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9316 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9317
9318 + pax_force_retaddr
9319 ret;
9320
9321 .align 8
9322 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9323 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9324 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9325
9326 + pax_force_retaddr
9327 ret;
9328 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9329 index 49d6987..df66bd4 100644
9330 --- a/arch/x86/crypto/sha1_ssse3_asm.S
9331 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
9332 @@ -28,6 +28,8 @@
9333 * (at your option) any later version.
9334 */
9335
9336 +#include <asm/alternative-asm.h>
9337 +
9338 #define CTX %rdi // arg1
9339 #define BUF %rsi // arg2
9340 #define CNT %rdx // arg3
9341 @@ -104,6 +106,7 @@
9342 pop %r12
9343 pop %rbp
9344 pop %rbx
9345 + pax_force_retaddr 0, 1
9346 ret
9347
9348 .size \name, .-\name
9349 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9350 index 1585abb..4a9af16 100644
9351 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9352 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9353 @@ -23,6 +23,8 @@
9354 *
9355 */
9356
9357 +#include <asm/alternative-asm.h>
9358 +
9359 .file "twofish-avx-x86_64-asm_64.S"
9360 .text
9361
9362 @@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9363 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9364 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9365
9366 + pax_force_retaddr
9367 ret;
9368
9369 __enc_xor8:
9370 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9371 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9372
9373 + pax_force_retaddr
9374 ret;
9375
9376 .align 8
9377 @@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9378 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9379 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9380
9381 + pax_force_retaddr
9382 ret;
9383 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9384 index 5b012a2..36d5364 100644
9385 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9386 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9387 @@ -20,6 +20,8 @@
9388 *
9389 */
9390
9391 +#include <asm/alternative-asm.h>
9392 +
9393 .file "twofish-x86_64-asm-3way.S"
9394 .text
9395
9396 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9397 popq %r13;
9398 popq %r14;
9399 popq %r15;
9400 + pax_force_retaddr 0, 1
9401 ret;
9402
9403 __enc_xor3:
9404 @@ -271,6 +274,7 @@ __enc_xor3:
9405 popq %r13;
9406 popq %r14;
9407 popq %r15;
9408 + pax_force_retaddr 0, 1
9409 ret;
9410
9411 .global twofish_dec_blk_3way
9412 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9413 popq %r13;
9414 popq %r14;
9415 popq %r15;
9416 + pax_force_retaddr 0, 1
9417 ret;
9418
9419 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9420 index 7bcf3fc..f53832f 100644
9421 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9422 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9423 @@ -21,6 +21,7 @@
9424 .text
9425
9426 #include <asm/asm-offsets.h>
9427 +#include <asm/alternative-asm.h>
9428
9429 #define a_offset 0
9430 #define b_offset 4
9431 @@ -268,6 +269,7 @@ twofish_enc_blk:
9432
9433 popq R1
9434 movq $1,%rax
9435 + pax_force_retaddr 0, 1
9436 ret
9437
9438 twofish_dec_blk:
9439 @@ -319,4 +321,5 @@ twofish_dec_blk:
9440
9441 popq R1
9442 movq $1,%rax
9443 + pax_force_retaddr 0, 1
9444 ret
9445 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9446 index 07b3a68..bd2a388 100644
9447 --- a/arch/x86/ia32/ia32_aout.c
9448 +++ b/arch/x86/ia32/ia32_aout.c
9449 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9450 unsigned long dump_start, dump_size;
9451 struct user32 dump;
9452
9453 + memset(&dump, 0, sizeof(dump));
9454 +
9455 fs = get_fs();
9456 set_fs(KERNEL_DS);
9457 has_dumped = 1;
9458 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9459 index efc6a95..95abfe2 100644
9460 --- a/arch/x86/ia32/ia32_signal.c
9461 +++ b/arch/x86/ia32/ia32_signal.c
9462 @@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9463 }
9464 seg = get_fs();
9465 set_fs(KERNEL_DS);
9466 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9467 - (stack_t __force __user *) &uoss, regs->sp);
9468 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9469 + (stack_t __force_user *) &uoss, regs->sp);
9470 set_fs(seg);
9471 if (ret >= 0 && uoss_ptr) {
9472 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9473 @@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9474 sp -= frame_size;
9475 /* Align the stack pointer according to the i386 ABI,
9476 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9477 - sp = ((sp + 4) & -16ul) - 4;
9478 + sp = ((sp - 12) & -16ul) - 4;
9479 return (void __user *) sp;
9480 }
9481
9482 @@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9483 * These are actually not used anymore, but left because some
9484 * gdb versions depend on them as a marker.
9485 */
9486 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9487 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9488 } put_user_catch(err);
9489
9490 if (err)
9491 @@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9492 0xb8,
9493 __NR_ia32_rt_sigreturn,
9494 0x80cd,
9495 - 0,
9496 + 0
9497 };
9498
9499 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9500 @@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9501
9502 if (ka->sa.sa_flags & SA_RESTORER)
9503 restorer = ka->sa.sa_restorer;
9504 + else if (current->mm->context.vdso)
9505 + /* Return stub is in 32bit vsyscall page */
9506 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9507 else
9508 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9509 - rt_sigreturn);
9510 + restorer = &frame->retcode;
9511 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9512
9513 /*
9514 * Not actually used anymore, but left because some gdb
9515 * versions need it.
9516 */
9517 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9518 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9519 } put_user_catch(err);
9520
9521 err |= copy_siginfo_to_user32(&frame->info, info);
9522 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9523 index 076745f..ae8f6cb 100644
9524 --- a/arch/x86/ia32/ia32entry.S
9525 +++ b/arch/x86/ia32/ia32entry.S
9526 @@ -15,8 +15,10 @@
9527 #include <asm/irqflags.h>
9528 #include <asm/asm.h>
9529 #include <asm/smap.h>
9530 +#include <asm/pgtable.h>
9531 #include <linux/linkage.h>
9532 #include <linux/err.h>
9533 +#include <asm/alternative-asm.h>
9534
9535 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9536 #include <linux/elf-em.h>
9537 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9538 ENDPROC(native_irq_enable_sysexit)
9539 #endif
9540
9541 + .macro pax_enter_kernel_user
9542 + pax_set_fptr_mask
9543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9544 + call pax_enter_kernel_user
9545 +#endif
9546 + .endm
9547 +
9548 + .macro pax_exit_kernel_user
9549 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9550 + call pax_exit_kernel_user
9551 +#endif
9552 +#ifdef CONFIG_PAX_RANDKSTACK
9553 + pushq %rax
9554 + pushq %r11
9555 + call pax_randomize_kstack
9556 + popq %r11
9557 + popq %rax
9558 +#endif
9559 + .endm
9560 +
9561 +.macro pax_erase_kstack
9562 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9563 + call pax_erase_kstack
9564 +#endif
9565 +.endm
9566 +
9567 /*
9568 * 32bit SYSENTER instruction entry.
9569 *
9570 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9571 CFI_REGISTER rsp,rbp
9572 SWAPGS_UNSAFE_STACK
9573 movq PER_CPU_VAR(kernel_stack), %rsp
9574 - addq $(KERNEL_STACK_OFFSET),%rsp
9575 - /*
9576 - * No need to follow this irqs on/off section: the syscall
9577 - * disabled irqs, here we enable it straight after entry:
9578 - */
9579 - ENABLE_INTERRUPTS(CLBR_NONE)
9580 movl %ebp,%ebp /* zero extension */
9581 pushq_cfi $__USER32_DS
9582 /*CFI_REL_OFFSET ss,0*/
9583 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9584 CFI_REL_OFFSET rsp,0
9585 pushfq_cfi
9586 /*CFI_REL_OFFSET rflags,0*/
9587 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9588 - CFI_REGISTER rip,r10
9589 + orl $X86_EFLAGS_IF,(%rsp)
9590 + GET_THREAD_INFO(%r11)
9591 + movl TI_sysenter_return(%r11), %r11d
9592 + CFI_REGISTER rip,r11
9593 pushq_cfi $__USER32_CS
9594 /*CFI_REL_OFFSET cs,0*/
9595 movl %eax, %eax
9596 - pushq_cfi %r10
9597 + pushq_cfi %r11
9598 CFI_REL_OFFSET rip,0
9599 pushq_cfi %rax
9600 cld
9601 SAVE_ARGS 0,1,0
9602 + pax_enter_kernel_user
9603 +
9604 +#ifdef CONFIG_PAX_RANDKSTACK
9605 + pax_erase_kstack
9606 +#endif
9607 +
9608 + /*
9609 + * No need to follow this irqs on/off section: the syscall
9610 + * disabled irqs, here we enable it straight after entry:
9611 + */
9612 + ENABLE_INTERRUPTS(CLBR_NONE)
9613 /* no need to do an access_ok check here because rbp has been
9614 32bit zero extended */
9615 +
9616 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9617 + mov $PAX_USER_SHADOW_BASE,%r11
9618 + add %r11,%rbp
9619 +#endif
9620 +
9621 ASM_STAC
9622 1: movl (%rbp),%ebp
9623 _ASM_EXTABLE(1b,ia32_badarg)
9624 ASM_CLAC
9625 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9626 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9627 + GET_THREAD_INFO(%r11)
9628 + orl $TS_COMPAT,TI_status(%r11)
9629 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9630 CFI_REMEMBER_STATE
9631 jnz sysenter_tracesys
9632 cmpq $(IA32_NR_syscalls-1),%rax
9633 @@ -162,12 +204,15 @@ sysenter_do_call:
9634 sysenter_dispatch:
9635 call *ia32_sys_call_table(,%rax,8)
9636 movq %rax,RAX-ARGOFFSET(%rsp)
9637 + GET_THREAD_INFO(%r11)
9638 DISABLE_INTERRUPTS(CLBR_NONE)
9639 TRACE_IRQS_OFF
9640 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9641 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9642 jnz sysexit_audit
9643 sysexit_from_sys_call:
9644 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9645 + pax_exit_kernel_user
9646 + pax_erase_kstack
9647 + andl $~TS_COMPAT,TI_status(%r11)
9648 /* clear IF, that popfq doesn't enable interrupts early */
9649 andl $~0x200,EFLAGS-R11(%rsp)
9650 movl RIP-R11(%rsp),%edx /* User %eip */
9651 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
9652 movl %eax,%esi /* 2nd arg: syscall number */
9653 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
9654 call __audit_syscall_entry
9655 +
9656 + pax_erase_kstack
9657 +
9658 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
9659 cmpq $(IA32_NR_syscalls-1),%rax
9660 ja ia32_badsys
9661 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
9662 .endm
9663
9664 .macro auditsys_exit exit
9665 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9666 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9667 jnz ia32_ret_from_sys_call
9668 TRACE_IRQS_ON
9669 sti
9670 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
9671 1: setbe %al /* 1 if error, 0 if not */
9672 movzbl %al,%edi /* zero-extend that into %edi */
9673 call __audit_syscall_exit
9674 + GET_THREAD_INFO(%r11)
9675 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
9676 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
9677 cli
9678 TRACE_IRQS_OFF
9679 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9680 + testl %edi,TI_flags(%r11)
9681 jz \exit
9682 CLEAR_RREGS -ARGOFFSET
9683 jmp int_with_check
9684 @@ -237,7 +286,7 @@ sysexit_audit:
9685
9686 sysenter_tracesys:
9687 #ifdef CONFIG_AUDITSYSCALL
9688 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9689 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9690 jz sysenter_auditsys
9691 #endif
9692 SAVE_REST
9693 @@ -249,6 +298,9 @@ sysenter_tracesys:
9694 RESTORE_REST
9695 cmpq $(IA32_NR_syscalls-1),%rax
9696 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
9697 +
9698 + pax_erase_kstack
9699 +
9700 jmp sysenter_do_call
9701 CFI_ENDPROC
9702 ENDPROC(ia32_sysenter_target)
9703 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
9704 ENTRY(ia32_cstar_target)
9705 CFI_STARTPROC32 simple
9706 CFI_SIGNAL_FRAME
9707 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
9708 + CFI_DEF_CFA rsp,0
9709 CFI_REGISTER rip,rcx
9710 /*CFI_REGISTER rflags,r11*/
9711 SWAPGS_UNSAFE_STACK
9712 movl %esp,%r8d
9713 CFI_REGISTER rsp,r8
9714 movq PER_CPU_VAR(kernel_stack),%rsp
9715 + SAVE_ARGS 8*6,0,0
9716 + pax_enter_kernel_user
9717 +
9718 +#ifdef CONFIG_PAX_RANDKSTACK
9719 + pax_erase_kstack
9720 +#endif
9721 +
9722 /*
9723 * No need to follow this irqs on/off section: the syscall
9724 * disabled irqs and here we enable it straight after entry:
9725 */
9726 ENABLE_INTERRUPTS(CLBR_NONE)
9727 - SAVE_ARGS 8,0,0
9728 movl %eax,%eax /* zero extension */
9729 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
9730 movq %rcx,RIP-ARGOFFSET(%rsp)
9731 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
9732 /* no need to do an access_ok check here because r8 has been
9733 32bit zero extended */
9734 /* hardware stack frame is complete now */
9735 +
9736 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9737 + mov $PAX_USER_SHADOW_BASE,%r11
9738 + add %r11,%r8
9739 +#endif
9740 +
9741 ASM_STAC
9742 1: movl (%r8),%r9d
9743 _ASM_EXTABLE(1b,ia32_badarg)
9744 ASM_CLAC
9745 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9746 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9747 + GET_THREAD_INFO(%r11)
9748 + orl $TS_COMPAT,TI_status(%r11)
9749 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9750 CFI_REMEMBER_STATE
9751 jnz cstar_tracesys
9752 cmpq $IA32_NR_syscalls-1,%rax
9753 @@ -319,12 +384,15 @@ cstar_do_call:
9754 cstar_dispatch:
9755 call *ia32_sys_call_table(,%rax,8)
9756 movq %rax,RAX-ARGOFFSET(%rsp)
9757 + GET_THREAD_INFO(%r11)
9758 DISABLE_INTERRUPTS(CLBR_NONE)
9759 TRACE_IRQS_OFF
9760 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9761 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9762 jnz sysretl_audit
9763 sysretl_from_sys_call:
9764 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9765 + pax_exit_kernel_user
9766 + pax_erase_kstack
9767 + andl $~TS_COMPAT,TI_status(%r11)
9768 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
9769 movl RIP-ARGOFFSET(%rsp),%ecx
9770 CFI_REGISTER rip,rcx
9771 @@ -352,7 +420,7 @@ sysretl_audit:
9772
9773 cstar_tracesys:
9774 #ifdef CONFIG_AUDITSYSCALL
9775 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9776 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9777 jz cstar_auditsys
9778 #endif
9779 xchgl %r9d,%ebp
9780 @@ -366,6 +434,9 @@ cstar_tracesys:
9781 xchgl %ebp,%r9d
9782 cmpq $(IA32_NR_syscalls-1),%rax
9783 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
9784 +
9785 + pax_erase_kstack
9786 +
9787 jmp cstar_do_call
9788 END(ia32_cstar_target)
9789
9790 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
9791 CFI_REL_OFFSET rip,RIP-RIP
9792 PARAVIRT_ADJUST_EXCEPTION_FRAME
9793 SWAPGS
9794 - /*
9795 - * No need to follow this irqs on/off section: the syscall
9796 - * disabled irqs and here we enable it straight after entry:
9797 - */
9798 - ENABLE_INTERRUPTS(CLBR_NONE)
9799 movl %eax,%eax
9800 pushq_cfi %rax
9801 cld
9802 /* note the registers are not zero extended to the sf.
9803 this could be a problem. */
9804 SAVE_ARGS 0,1,0
9805 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9806 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9807 + pax_enter_kernel_user
9808 +
9809 +#ifdef CONFIG_PAX_RANDKSTACK
9810 + pax_erase_kstack
9811 +#endif
9812 +
9813 + /*
9814 + * No need to follow this irqs on/off section: the syscall
9815 + * disabled irqs and here we enable it straight after entry:
9816 + */
9817 + ENABLE_INTERRUPTS(CLBR_NONE)
9818 + GET_THREAD_INFO(%r11)
9819 + orl $TS_COMPAT,TI_status(%r11)
9820 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9821 jnz ia32_tracesys
9822 cmpq $(IA32_NR_syscalls-1),%rax
9823 ja ia32_badsys
9824 @@ -442,6 +520,9 @@ ia32_tracesys:
9825 RESTORE_REST
9826 cmpq $(IA32_NR_syscalls-1),%rax
9827 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
9828 +
9829 + pax_erase_kstack
9830 +
9831 jmp ia32_do_call
9832 END(ia32_syscall)
9833
9834 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9835 index 86d68d1..f9960fe 100644
9836 --- a/arch/x86/ia32/sys_ia32.c
9837 +++ b/arch/x86/ia32/sys_ia32.c
9838 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9839 */
9840 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9841 {
9842 - typeof(ubuf->st_uid) uid = 0;
9843 - typeof(ubuf->st_gid) gid = 0;
9844 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
9845 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
9846 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9847 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9848 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9849 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9850 mm_segment_t old_fs = get_fs();
9851
9852 set_fs(KERNEL_DS);
9853 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9854 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9855 set_fs(old_fs);
9856 if (put_compat_timespec(&t, interval))
9857 return -EFAULT;
9858 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9859 mm_segment_t old_fs = get_fs();
9860
9861 set_fs(KERNEL_DS);
9862 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9863 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9864 set_fs(old_fs);
9865 if (!ret) {
9866 switch (_NSIG_WORDS) {
9867 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9868 if (copy_siginfo_from_user32(&info, uinfo))
9869 return -EFAULT;
9870 set_fs(KERNEL_DS);
9871 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9872 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9873 set_fs(old_fs);
9874 return ret;
9875 }
9876 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9877 return -EFAULT;
9878
9879 set_fs(KERNEL_DS);
9880 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9881 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9882 count);
9883 set_fs(old_fs);
9884
9885 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9886 index 372231c..a5aa1a1 100644
9887 --- a/arch/x86/include/asm/alternative-asm.h
9888 +++ b/arch/x86/include/asm/alternative-asm.h
9889 @@ -18,6 +18,45 @@
9890 .endm
9891 #endif
9892
9893 +#ifdef KERNEXEC_PLUGIN
9894 + .macro pax_force_retaddr_bts rip=0
9895 + btsq $63,\rip(%rsp)
9896 + .endm
9897 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9898 + .macro pax_force_retaddr rip=0, reload=0
9899 + btsq $63,\rip(%rsp)
9900 + .endm
9901 + .macro pax_force_fptr ptr
9902 + btsq $63,\ptr
9903 + .endm
9904 + .macro pax_set_fptr_mask
9905 + .endm
9906 +#endif
9907 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9908 + .macro pax_force_retaddr rip=0, reload=0
9909 + .if \reload
9910 + pax_set_fptr_mask
9911 + .endif
9912 + orq %r10,\rip(%rsp)
9913 + .endm
9914 + .macro pax_force_fptr ptr
9915 + orq %r10,\ptr
9916 + .endm
9917 + .macro pax_set_fptr_mask
9918 + movabs $0x8000000000000000,%r10
9919 + .endm
9920 +#endif
9921 +#else
9922 + .macro pax_force_retaddr rip=0, reload=0
9923 + .endm
9924 + .macro pax_force_fptr ptr
9925 + .endm
9926 + .macro pax_force_retaddr_bts rip=0
9927 + .endm
9928 + .macro pax_set_fptr_mask
9929 + .endm
9930 +#endif
9931 +
9932 .macro altinstruction_entry orig alt feature orig_len alt_len
9933 .long \orig - .
9934 .long \alt - .
9935 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9936 index 58ed6d9..f1cbe58 100644
9937 --- a/arch/x86/include/asm/alternative.h
9938 +++ b/arch/x86/include/asm/alternative.h
9939 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9940 ".pushsection .discard,\"aw\",@progbits\n" \
9941 DISCARD_ENTRY(1) \
9942 ".popsection\n" \
9943 - ".pushsection .altinstr_replacement, \"ax\"\n" \
9944 + ".pushsection .altinstr_replacement, \"a\"\n" \
9945 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9946 ".popsection"
9947
9948 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9949 DISCARD_ENTRY(1) \
9950 DISCARD_ENTRY(2) \
9951 ".popsection\n" \
9952 - ".pushsection .altinstr_replacement, \"ax\"\n" \
9953 + ".pushsection .altinstr_replacement, \"a\"\n" \
9954 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9955 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9956 ".popsection"
9957 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9958 index 3388034..ba52312 100644
9959 --- a/arch/x86/include/asm/apic.h
9960 +++ b/arch/x86/include/asm/apic.h
9961 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9962
9963 #ifdef CONFIG_X86_LOCAL_APIC
9964
9965 -extern unsigned int apic_verbosity;
9966 +extern int apic_verbosity;
9967 extern int local_apic_timer_c2_ok;
9968
9969 extern int disable_apic;
9970 @@ -391,7 +391,7 @@ struct apic {
9971 */
9972 int (*x86_32_numa_cpu_node)(int cpu);
9973 #endif
9974 -};
9975 +} __do_const;
9976
9977 /*
9978 * Pointer to the local APIC driver in use on this system (there's
9979 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9980 index 20370c6..a2eb9b0 100644
9981 --- a/arch/x86/include/asm/apm.h
9982 +++ b/arch/x86/include/asm/apm.h
9983 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9984 __asm__ __volatile__(APM_DO_ZERO_SEGS
9985 "pushl %%edi\n\t"
9986 "pushl %%ebp\n\t"
9987 - "lcall *%%cs:apm_bios_entry\n\t"
9988 + "lcall *%%ss:apm_bios_entry\n\t"
9989 "setc %%al\n\t"
9990 "popl %%ebp\n\t"
9991 "popl %%edi\n\t"
9992 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9993 __asm__ __volatile__(APM_DO_ZERO_SEGS
9994 "pushl %%edi\n\t"
9995 "pushl %%ebp\n\t"
9996 - "lcall *%%cs:apm_bios_entry\n\t"
9997 + "lcall *%%ss:apm_bios_entry\n\t"
9998 "setc %%bl\n\t"
9999 "popl %%ebp\n\t"
10000 "popl %%edi\n\t"
10001 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10002 index b6c3b82..b4c077a 100644
10003 --- a/arch/x86/include/asm/atomic.h
10004 +++ b/arch/x86/include/asm/atomic.h
10005 @@ -22,7 +22,18 @@
10006 */
10007 static inline int atomic_read(const atomic_t *v)
10008 {
10009 - return (*(volatile int *)&(v)->counter);
10010 + return (*(volatile const int *)&(v)->counter);
10011 +}
10012 +
10013 +/**
10014 + * atomic_read_unchecked - read atomic variable
10015 + * @v: pointer of type atomic_unchecked_t
10016 + *
10017 + * Atomically reads the value of @v.
10018 + */
10019 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10020 +{
10021 + return (*(volatile const int *)&(v)->counter);
10022 }
10023
10024 /**
10025 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10026 }
10027
10028 /**
10029 + * atomic_set_unchecked - set atomic variable
10030 + * @v: pointer of type atomic_unchecked_t
10031 + * @i: required value
10032 + *
10033 + * Atomically sets the value of @v to @i.
10034 + */
10035 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10036 +{
10037 + v->counter = i;
10038 +}
10039 +
10040 +/**
10041 * atomic_add - add integer to atomic variable
10042 * @i: integer value to add
10043 * @v: pointer of type atomic_t
10044 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10045 */
10046 static inline void atomic_add(int i, atomic_t *v)
10047 {
10048 - asm volatile(LOCK_PREFIX "addl %1,%0"
10049 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10050 +
10051 +#ifdef CONFIG_PAX_REFCOUNT
10052 + "jno 0f\n"
10053 + LOCK_PREFIX "subl %1,%0\n"
10054 + "int $4\n0:\n"
10055 + _ASM_EXTABLE(0b, 0b)
10056 +#endif
10057 +
10058 + : "+m" (v->counter)
10059 + : "ir" (i));
10060 +}
10061 +
10062 +/**
10063 + * atomic_add_unchecked - add integer to atomic variable
10064 + * @i: integer value to add
10065 + * @v: pointer of type atomic_unchecked_t
10066 + *
10067 + * Atomically adds @i to @v.
10068 + */
10069 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10070 +{
10071 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10072 : "+m" (v->counter)
10073 : "ir" (i));
10074 }
10075 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10076 */
10077 static inline void atomic_sub(int i, atomic_t *v)
10078 {
10079 - asm volatile(LOCK_PREFIX "subl %1,%0"
10080 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10081 +
10082 +#ifdef CONFIG_PAX_REFCOUNT
10083 + "jno 0f\n"
10084 + LOCK_PREFIX "addl %1,%0\n"
10085 + "int $4\n0:\n"
10086 + _ASM_EXTABLE(0b, 0b)
10087 +#endif
10088 +
10089 + : "+m" (v->counter)
10090 + : "ir" (i));
10091 +}
10092 +
10093 +/**
10094 + * atomic_sub_unchecked - subtract integer from atomic variable
10095 + * @i: integer value to subtract
10096 + * @v: pointer of type atomic_unchecked_t
10097 + *
10098 + * Atomically subtracts @i from @v.
10099 + */
10100 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10101 +{
10102 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10103 : "+m" (v->counter)
10104 : "ir" (i));
10105 }
10106 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10107 {
10108 unsigned char c;
10109
10110 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10111 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
10112 +
10113 +#ifdef CONFIG_PAX_REFCOUNT
10114 + "jno 0f\n"
10115 + LOCK_PREFIX "addl %2,%0\n"
10116 + "int $4\n0:\n"
10117 + _ASM_EXTABLE(0b, 0b)
10118 +#endif
10119 +
10120 + "sete %1\n"
10121 : "+m" (v->counter), "=qm" (c)
10122 : "ir" (i) : "memory");
10123 return c;
10124 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10125 */
10126 static inline void atomic_inc(atomic_t *v)
10127 {
10128 - asm volatile(LOCK_PREFIX "incl %0"
10129 + asm volatile(LOCK_PREFIX "incl %0\n"
10130 +
10131 +#ifdef CONFIG_PAX_REFCOUNT
10132 + "jno 0f\n"
10133 + LOCK_PREFIX "decl %0\n"
10134 + "int $4\n0:\n"
10135 + _ASM_EXTABLE(0b, 0b)
10136 +#endif
10137 +
10138 + : "+m" (v->counter));
10139 +}
10140 +
10141 +/**
10142 + * atomic_inc_unchecked - increment atomic variable
10143 + * @v: pointer of type atomic_unchecked_t
10144 + *
10145 + * Atomically increments @v by 1.
10146 + */
10147 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10148 +{
10149 + asm volatile(LOCK_PREFIX "incl %0\n"
10150 : "+m" (v->counter));
10151 }
10152
10153 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10154 */
10155 static inline void atomic_dec(atomic_t *v)
10156 {
10157 - asm volatile(LOCK_PREFIX "decl %0"
10158 + asm volatile(LOCK_PREFIX "decl %0\n"
10159 +
10160 +#ifdef CONFIG_PAX_REFCOUNT
10161 + "jno 0f\n"
10162 + LOCK_PREFIX "incl %0\n"
10163 + "int $4\n0:\n"
10164 + _ASM_EXTABLE(0b, 0b)
10165 +#endif
10166 +
10167 + : "+m" (v->counter));
10168 +}
10169 +
10170 +/**
10171 + * atomic_dec_unchecked - decrement atomic variable
10172 + * @v: pointer of type atomic_unchecked_t
10173 + *
10174 + * Atomically decrements @v by 1.
10175 + */
10176 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10177 +{
10178 + asm volatile(LOCK_PREFIX "decl %0\n"
10179 : "+m" (v->counter));
10180 }
10181
10182 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10183 {
10184 unsigned char c;
10185
10186 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
10187 + asm volatile(LOCK_PREFIX "decl %0\n"
10188 +
10189 +#ifdef CONFIG_PAX_REFCOUNT
10190 + "jno 0f\n"
10191 + LOCK_PREFIX "incl %0\n"
10192 + "int $4\n0:\n"
10193 + _ASM_EXTABLE(0b, 0b)
10194 +#endif
10195 +
10196 + "sete %1\n"
10197 : "+m" (v->counter), "=qm" (c)
10198 : : "memory");
10199 return c != 0;
10200 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10201 {
10202 unsigned char c;
10203
10204 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
10205 + asm volatile(LOCK_PREFIX "incl %0\n"
10206 +
10207 +#ifdef CONFIG_PAX_REFCOUNT
10208 + "jno 0f\n"
10209 + LOCK_PREFIX "decl %0\n"
10210 + "int $4\n0:\n"
10211 + _ASM_EXTABLE(0b, 0b)
10212 +#endif
10213 +
10214 + "sete %1\n"
10215 + : "+m" (v->counter), "=qm" (c)
10216 + : : "memory");
10217 + return c != 0;
10218 +}
10219 +
10220 +/**
10221 + * atomic_inc_and_test_unchecked - increment and test
10222 + * @v: pointer of type atomic_unchecked_t
10223 + *
10224 + * Atomically increments @v by 1
10225 + * and returns true if the result is zero, or false for all
10226 + * other cases.
10227 + */
10228 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10229 +{
10230 + unsigned char c;
10231 +
10232 + asm volatile(LOCK_PREFIX "incl %0\n"
10233 + "sete %1\n"
10234 : "+m" (v->counter), "=qm" (c)
10235 : : "memory");
10236 return c != 0;
10237 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10238 {
10239 unsigned char c;
10240
10241 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10242 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
10243 +
10244 +#ifdef CONFIG_PAX_REFCOUNT
10245 + "jno 0f\n"
10246 + LOCK_PREFIX "subl %2,%0\n"
10247 + "int $4\n0:\n"
10248 + _ASM_EXTABLE(0b, 0b)
10249 +#endif
10250 +
10251 + "sets %1\n"
10252 : "+m" (v->counter), "=qm" (c)
10253 : "ir" (i) : "memory");
10254 return c;
10255 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10256 goto no_xadd;
10257 #endif
10258 /* Modern 486+ processor */
10259 - return i + xadd(&v->counter, i);
10260 + return i + xadd_check_overflow(&v->counter, i);
10261
10262 #ifdef CONFIG_M386
10263 no_xadd: /* Legacy 386 processor */
10264 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10265 }
10266
10267 /**
10268 + * atomic_add_return_unchecked - add integer and return
10269 + * @i: integer value to add
10270 + * @v: pointer of type atomic_unchecked_t
10271 + *
10272 + * Atomically adds @i to @v and returns @i + @v
10273 + */
10274 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10275 +{
10276 +#ifdef CONFIG_M386
10277 + int __i;
10278 + unsigned long flags;
10279 + if (unlikely(boot_cpu_data.x86 <= 3))
10280 + goto no_xadd;
10281 +#endif
10282 + /* Modern 486+ processor */
10283 + return i + xadd(&v->counter, i);
10284 +
10285 +#ifdef CONFIG_M386
10286 +no_xadd: /* Legacy 386 processor */
10287 + raw_local_irq_save(flags);
10288 + __i = atomic_read_unchecked(v);
10289 + atomic_set_unchecked(v, i + __i);
10290 + raw_local_irq_restore(flags);
10291 + return i + __i;
10292 +#endif
10293 +}
10294 +
10295 +/**
10296 * atomic_sub_return - subtract integer and return
10297 * @v: pointer of type atomic_t
10298 * @i: integer value to subtract
10299 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10300 }
10301
10302 #define atomic_inc_return(v) (atomic_add_return(1, v))
10303 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10304 +{
10305 + return atomic_add_return_unchecked(1, v);
10306 +}
10307 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10308
10309 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10310 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10311 return cmpxchg(&v->counter, old, new);
10312 }
10313
10314 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10315 +{
10316 + return cmpxchg(&v->counter, old, new);
10317 +}
10318 +
10319 static inline int atomic_xchg(atomic_t *v, int new)
10320 {
10321 return xchg(&v->counter, new);
10322 }
10323
10324 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10325 +{
10326 + return xchg(&v->counter, new);
10327 +}
10328 +
10329 /**
10330 * __atomic_add_unless - add unless the number is already a given value
10331 * @v: pointer of type atomic_t
10332 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10333 */
10334 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10335 {
10336 - int c, old;
10337 + int c, old, new;
10338 c = atomic_read(v);
10339 for (;;) {
10340 - if (unlikely(c == (u)))
10341 + if (unlikely(c == u))
10342 break;
10343 - old = atomic_cmpxchg((v), c, c + (a));
10344 +
10345 + asm volatile("addl %2,%0\n"
10346 +
10347 +#ifdef CONFIG_PAX_REFCOUNT
10348 + "jno 0f\n"
10349 + "subl %2,%0\n"
10350 + "int $4\n0:\n"
10351 + _ASM_EXTABLE(0b, 0b)
10352 +#endif
10353 +
10354 + : "=r" (new)
10355 + : "0" (c), "ir" (a));
10356 +
10357 + old = atomic_cmpxchg(v, c, new);
10358 if (likely(old == c))
10359 break;
10360 c = old;
10361 @@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10362 }
10363
10364 /**
10365 + * atomic_inc_not_zero_hint - increment if not null
10366 + * @v: pointer of type atomic_t
10367 + * @hint: probable value of the atomic before the increment
10368 + *
10369 + * This version of atomic_inc_not_zero() gives a hint of probable
10370 + * value of the atomic. This helps processor to not read the memory
10371 + * before doing the atomic read/modify/write cycle, lowering
10372 + * number of bus transactions on some arches.
10373 + *
10374 + * Returns: 0 if increment was not done, 1 otherwise.
10375 + */
10376 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10377 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10378 +{
10379 + int val, c = hint, new;
10380 +
10381 + /* sanity test, should be removed by compiler if hint is a constant */
10382 + if (!hint)
10383 + return __atomic_add_unless(v, 1, 0);
10384 +
10385 + do {
10386 + asm volatile("incl %0\n"
10387 +
10388 +#ifdef CONFIG_PAX_REFCOUNT
10389 + "jno 0f\n"
10390 + "decl %0\n"
10391 + "int $4\n0:\n"
10392 + _ASM_EXTABLE(0b, 0b)
10393 +#endif
10394 +
10395 + : "=r" (new)
10396 + : "0" (c));
10397 +
10398 + val = atomic_cmpxchg(v, c, new);
10399 + if (val == c)
10400 + return 1;
10401 + c = val;
10402 + } while (c);
10403 +
10404 + return 0;
10405 +}
10406 +
10407 +/**
10408 * atomic_inc_short - increment of a short integer
10409 * @v: pointer to type int
10410 *
10411 @@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10412 #endif
10413
10414 /* These are x86-specific, used by some header files */
10415 -#define atomic_clear_mask(mask, addr) \
10416 - asm volatile(LOCK_PREFIX "andl %0,%1" \
10417 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
10418 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10419 +{
10420 + asm volatile(LOCK_PREFIX "andl %1,%0"
10421 + : "+m" (v->counter)
10422 + : "r" (~(mask))
10423 + : "memory");
10424 +}
10425
10426 -#define atomic_set_mask(mask, addr) \
10427 - asm volatile(LOCK_PREFIX "orl %0,%1" \
10428 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10429 - : "memory")
10430 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10431 +{
10432 + asm volatile(LOCK_PREFIX "andl %1,%0"
10433 + : "+m" (v->counter)
10434 + : "r" (~(mask))
10435 + : "memory");
10436 +}
10437 +
10438 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10439 +{
10440 + asm volatile(LOCK_PREFIX "orl %1,%0"
10441 + : "+m" (v->counter)
10442 + : "r" (mask)
10443 + : "memory");
10444 +}
10445 +
10446 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10447 +{
10448 + asm volatile(LOCK_PREFIX "orl %1,%0"
10449 + : "+m" (v->counter)
10450 + : "r" (mask)
10451 + : "memory");
10452 +}
10453
10454 /* Atomic operations are already serializing on x86 */
10455 #define smp_mb__before_atomic_dec() barrier()
10456 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10457 index b154de7..aadebd8 100644
10458 --- a/arch/x86/include/asm/atomic64_32.h
10459 +++ b/arch/x86/include/asm/atomic64_32.h
10460 @@ -12,6 +12,14 @@ typedef struct {
10461 u64 __aligned(8) counter;
10462 } atomic64_t;
10463
10464 +#ifdef CONFIG_PAX_REFCOUNT
10465 +typedef struct {
10466 + u64 __aligned(8) counter;
10467 +} atomic64_unchecked_t;
10468 +#else
10469 +typedef atomic64_t atomic64_unchecked_t;
10470 +#endif
10471 +
10472 #define ATOMIC64_INIT(val) { (val) }
10473
10474 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10475 @@ -37,21 +45,31 @@ typedef struct {
10476 ATOMIC64_DECL_ONE(sym##_386)
10477
10478 ATOMIC64_DECL_ONE(add_386);
10479 +ATOMIC64_DECL_ONE(add_unchecked_386);
10480 ATOMIC64_DECL_ONE(sub_386);
10481 +ATOMIC64_DECL_ONE(sub_unchecked_386);
10482 ATOMIC64_DECL_ONE(inc_386);
10483 +ATOMIC64_DECL_ONE(inc_unchecked_386);
10484 ATOMIC64_DECL_ONE(dec_386);
10485 +ATOMIC64_DECL_ONE(dec_unchecked_386);
10486 #endif
10487
10488 #define alternative_atomic64(f, out, in...) \
10489 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10490
10491 ATOMIC64_DECL(read);
10492 +ATOMIC64_DECL(read_unchecked);
10493 ATOMIC64_DECL(set);
10494 +ATOMIC64_DECL(set_unchecked);
10495 ATOMIC64_DECL(xchg);
10496 ATOMIC64_DECL(add_return);
10497 +ATOMIC64_DECL(add_return_unchecked);
10498 ATOMIC64_DECL(sub_return);
10499 +ATOMIC64_DECL(sub_return_unchecked);
10500 ATOMIC64_DECL(inc_return);
10501 +ATOMIC64_DECL(inc_return_unchecked);
10502 ATOMIC64_DECL(dec_return);
10503 +ATOMIC64_DECL(dec_return_unchecked);
10504 ATOMIC64_DECL(dec_if_positive);
10505 ATOMIC64_DECL(inc_not_zero);
10506 ATOMIC64_DECL(add_unless);
10507 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10508 }
10509
10510 /**
10511 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10512 + * @p: pointer to type atomic64_unchecked_t
10513 + * @o: expected value
10514 + * @n: new value
10515 + *
10516 + * Atomically sets @v to @n if it was equal to @o and returns
10517 + * the old value.
10518 + */
10519 +
10520 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10521 +{
10522 + return cmpxchg64(&v->counter, o, n);
10523 +}
10524 +
10525 +/**
10526 * atomic64_xchg - xchg atomic64 variable
10527 * @v: pointer to type atomic64_t
10528 * @n: value to assign
10529 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10530 }
10531
10532 /**
10533 + * atomic64_set_unchecked - set atomic64 variable
10534 + * @v: pointer to type atomic64_unchecked_t
10535 + * @n: value to assign
10536 + *
10537 + * Atomically sets the value of @v to @n.
10538 + */
10539 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10540 +{
10541 + unsigned high = (unsigned)(i >> 32);
10542 + unsigned low = (unsigned)i;
10543 + alternative_atomic64(set, /* no output */,
10544 + "S" (v), "b" (low), "c" (high)
10545 + : "eax", "edx", "memory");
10546 +}
10547 +
10548 +/**
10549 * atomic64_read - read atomic64 variable
10550 * @v: pointer to type atomic64_t
10551 *
10552 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10553 }
10554
10555 /**
10556 + * atomic64_read_unchecked - read atomic64 variable
10557 + * @v: pointer to type atomic64_unchecked_t
10558 + *
10559 + * Atomically reads the value of @v and returns it.
10560 + */
10561 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10562 +{
10563 + long long r;
10564 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10565 + return r;
10566 + }
10567 +
10568 +/**
10569 * atomic64_add_return - add and return
10570 * @i: integer value to add
10571 * @v: pointer to type atomic64_t
10572 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10573 return i;
10574 }
10575
10576 +/**
10577 + * atomic64_add_return_unchecked - add and return
10578 + * @i: integer value to add
10579 + * @v: pointer to type atomic64_unchecked_t
10580 + *
10581 + * Atomically adds @i to @v and returns @i + *@v
10582 + */
10583 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10584 +{
10585 + alternative_atomic64(add_return_unchecked,
10586 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10587 + ASM_NO_INPUT_CLOBBER("memory"));
10588 + return i;
10589 +}
10590 +
10591 /*
10592 * Other variants with different arithmetic operators:
10593 */
10594 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10595 return a;
10596 }
10597
10598 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10599 +{
10600 + long long a;
10601 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
10602 + "S" (v) : "memory", "ecx");
10603 + return a;
10604 +}
10605 +
10606 static inline long long atomic64_dec_return(atomic64_t *v)
10607 {
10608 long long a;
10609 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10610 }
10611
10612 /**
10613 + * atomic64_add_unchecked - add integer to atomic64 variable
10614 + * @i: integer value to add
10615 + * @v: pointer to type atomic64_unchecked_t
10616 + *
10617 + * Atomically adds @i to @v.
10618 + */
10619 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10620 +{
10621 + __alternative_atomic64(add_unchecked, add_return_unchecked,
10622 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10623 + ASM_NO_INPUT_CLOBBER("memory"));
10624 + return i;
10625 +}
10626 +
10627 +/**
10628 * atomic64_sub - subtract the atomic64 variable
10629 * @i: integer value to subtract
10630 * @v: pointer to type atomic64_t
10631 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10632 index 0e1cbfc..5623683 100644
10633 --- a/arch/x86/include/asm/atomic64_64.h
10634 +++ b/arch/x86/include/asm/atomic64_64.h
10635 @@ -18,7 +18,19 @@
10636 */
10637 static inline long atomic64_read(const atomic64_t *v)
10638 {
10639 - return (*(volatile long *)&(v)->counter);
10640 + return (*(volatile const long *)&(v)->counter);
10641 +}
10642 +
10643 +/**
10644 + * atomic64_read_unchecked - read atomic64 variable
10645 + * @v: pointer of type atomic64_unchecked_t
10646 + *
10647 + * Atomically reads the value of @v.
10648 + * Doesn't imply a read memory barrier.
10649 + */
10650 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10651 +{
10652 + return (*(volatile const long *)&(v)->counter);
10653 }
10654
10655 /**
10656 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
10657 }
10658
10659 /**
10660 + * atomic64_set_unchecked - set atomic64 variable
10661 + * @v: pointer to type atomic64_unchecked_t
10662 + * @i: required value
10663 + *
10664 + * Atomically sets the value of @v to @i.
10665 + */
10666 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10667 +{
10668 + v->counter = i;
10669 +}
10670 +
10671 +/**
10672 * atomic64_add - add integer to atomic64 variable
10673 * @i: integer value to add
10674 * @v: pointer to type atomic64_t
10675 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
10676 */
10677 static inline void atomic64_add(long i, atomic64_t *v)
10678 {
10679 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
10680 +
10681 +#ifdef CONFIG_PAX_REFCOUNT
10682 + "jno 0f\n"
10683 + LOCK_PREFIX "subq %1,%0\n"
10684 + "int $4\n0:\n"
10685 + _ASM_EXTABLE(0b, 0b)
10686 +#endif
10687 +
10688 + : "=m" (v->counter)
10689 + : "er" (i), "m" (v->counter));
10690 +}
10691 +
10692 +/**
10693 + * atomic64_add_unchecked - add integer to atomic64 variable
10694 + * @i: integer value to add
10695 + * @v: pointer to type atomic64_unchecked_t
10696 + *
10697 + * Atomically adds @i to @v.
10698 + */
10699 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
10700 +{
10701 asm volatile(LOCK_PREFIX "addq %1,%0"
10702 : "=m" (v->counter)
10703 : "er" (i), "m" (v->counter));
10704 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
10705 */
10706 static inline void atomic64_sub(long i, atomic64_t *v)
10707 {
10708 - asm volatile(LOCK_PREFIX "subq %1,%0"
10709 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
10710 +
10711 +#ifdef CONFIG_PAX_REFCOUNT
10712 + "jno 0f\n"
10713 + LOCK_PREFIX "addq %1,%0\n"
10714 + "int $4\n0:\n"
10715 + _ASM_EXTABLE(0b, 0b)
10716 +#endif
10717 +
10718 + : "=m" (v->counter)
10719 + : "er" (i), "m" (v->counter));
10720 +}
10721 +
10722 +/**
10723 + * atomic64_sub_unchecked - subtract the atomic64 variable
10724 + * @i: integer value to subtract
10725 + * @v: pointer to type atomic64_unchecked_t
10726 + *
10727 + * Atomically subtracts @i from @v.
10728 + */
10729 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
10730 +{
10731 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
10732 : "=m" (v->counter)
10733 : "er" (i), "m" (v->counter));
10734 }
10735 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
10736 {
10737 unsigned char c;
10738
10739 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
10740 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
10741 +
10742 +#ifdef CONFIG_PAX_REFCOUNT
10743 + "jno 0f\n"
10744 + LOCK_PREFIX "addq %2,%0\n"
10745 + "int $4\n0:\n"
10746 + _ASM_EXTABLE(0b, 0b)
10747 +#endif
10748 +
10749 + "sete %1\n"
10750 : "=m" (v->counter), "=qm" (c)
10751 : "er" (i), "m" (v->counter) : "memory");
10752 return c;
10753 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
10754 */
10755 static inline void atomic64_inc(atomic64_t *v)
10756 {
10757 + asm volatile(LOCK_PREFIX "incq %0\n"
10758 +
10759 +#ifdef CONFIG_PAX_REFCOUNT
10760 + "jno 0f\n"
10761 + LOCK_PREFIX "decq %0\n"
10762 + "int $4\n0:\n"
10763 + _ASM_EXTABLE(0b, 0b)
10764 +#endif
10765 +
10766 + : "=m" (v->counter)
10767 + : "m" (v->counter));
10768 +}
10769 +
10770 +/**
10771 + * atomic64_inc_unchecked - increment atomic64 variable
10772 + * @v: pointer to type atomic64_unchecked_t
10773 + *
10774 + * Atomically increments @v by 1.
10775 + */
10776 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10777 +{
10778 asm volatile(LOCK_PREFIX "incq %0"
10779 : "=m" (v->counter)
10780 : "m" (v->counter));
10781 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
10782 */
10783 static inline void atomic64_dec(atomic64_t *v)
10784 {
10785 - asm volatile(LOCK_PREFIX "decq %0"
10786 + asm volatile(LOCK_PREFIX "decq %0\n"
10787 +
10788 +#ifdef CONFIG_PAX_REFCOUNT
10789 + "jno 0f\n"
10790 + LOCK_PREFIX "incq %0\n"
10791 + "int $4\n0:\n"
10792 + _ASM_EXTABLE(0b, 0b)
10793 +#endif
10794 +
10795 + : "=m" (v->counter)
10796 + : "m" (v->counter));
10797 +}
10798 +
10799 +/**
10800 + * atomic64_dec_unchecked - decrement atomic64 variable
10801 + * @v: pointer to type atomic64_t
10802 + *
10803 + * Atomically decrements @v by 1.
10804 + */
10805 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10806 +{
10807 + asm volatile(LOCK_PREFIX "decq %0\n"
10808 : "=m" (v->counter)
10809 : "m" (v->counter));
10810 }
10811 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
10812 {
10813 unsigned char c;
10814
10815 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
10816 + asm volatile(LOCK_PREFIX "decq %0\n"
10817 +
10818 +#ifdef CONFIG_PAX_REFCOUNT
10819 + "jno 0f\n"
10820 + LOCK_PREFIX "incq %0\n"
10821 + "int $4\n0:\n"
10822 + _ASM_EXTABLE(0b, 0b)
10823 +#endif
10824 +
10825 + "sete %1\n"
10826 : "=m" (v->counter), "=qm" (c)
10827 : "m" (v->counter) : "memory");
10828 return c != 0;
10829 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
10830 {
10831 unsigned char c;
10832
10833 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
10834 + asm volatile(LOCK_PREFIX "incq %0\n"
10835 +
10836 +#ifdef CONFIG_PAX_REFCOUNT
10837 + "jno 0f\n"
10838 + LOCK_PREFIX "decq %0\n"
10839 + "int $4\n0:\n"
10840 + _ASM_EXTABLE(0b, 0b)
10841 +#endif
10842 +
10843 + "sete %1\n"
10844 : "=m" (v->counter), "=qm" (c)
10845 : "m" (v->counter) : "memory");
10846 return c != 0;
10847 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10848 {
10849 unsigned char c;
10850
10851 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10852 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
10853 +
10854 +#ifdef CONFIG_PAX_REFCOUNT
10855 + "jno 0f\n"
10856 + LOCK_PREFIX "subq %2,%0\n"
10857 + "int $4\n0:\n"
10858 + _ASM_EXTABLE(0b, 0b)
10859 +#endif
10860 +
10861 + "sets %1\n"
10862 : "=m" (v->counter), "=qm" (c)
10863 : "er" (i), "m" (v->counter) : "memory");
10864 return c;
10865 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10866 */
10867 static inline long atomic64_add_return(long i, atomic64_t *v)
10868 {
10869 + return i + xadd_check_overflow(&v->counter, i);
10870 +}
10871 +
10872 +/**
10873 + * atomic64_add_return_unchecked - add and return
10874 + * @i: integer value to add
10875 + * @v: pointer to type atomic64_unchecked_t
10876 + *
10877 + * Atomically adds @i to @v and returns @i + @v
10878 + */
10879 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10880 +{
10881 return i + xadd(&v->counter, i);
10882 }
10883
10884 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10885 }
10886
10887 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10888 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10889 +{
10890 + return atomic64_add_return_unchecked(1, v);
10891 +}
10892 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10893
10894 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10895 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10896 return cmpxchg(&v->counter, old, new);
10897 }
10898
10899 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10900 +{
10901 + return cmpxchg(&v->counter, old, new);
10902 +}
10903 +
10904 static inline long atomic64_xchg(atomic64_t *v, long new)
10905 {
10906 return xchg(&v->counter, new);
10907 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10908 */
10909 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10910 {
10911 - long c, old;
10912 + long c, old, new;
10913 c = atomic64_read(v);
10914 for (;;) {
10915 - if (unlikely(c == (u)))
10916 + if (unlikely(c == u))
10917 break;
10918 - old = atomic64_cmpxchg((v), c, c + (a));
10919 +
10920 + asm volatile("add %2,%0\n"
10921 +
10922 +#ifdef CONFIG_PAX_REFCOUNT
10923 + "jno 0f\n"
10924 + "sub %2,%0\n"
10925 + "int $4\n0:\n"
10926 + _ASM_EXTABLE(0b, 0b)
10927 +#endif
10928 +
10929 + : "=r" (new)
10930 + : "0" (c), "ir" (a));
10931 +
10932 + old = atomic64_cmpxchg(v, c, new);
10933 if (likely(old == c))
10934 break;
10935 c = old;
10936 }
10937 - return c != (u);
10938 + return c != u;
10939 }
10940
10941 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10942 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10943 index 6dfd019..0c6699f 100644
10944 --- a/arch/x86/include/asm/bitops.h
10945 +++ b/arch/x86/include/asm/bitops.h
10946 @@ -40,7 +40,7 @@
10947 * a mask operation on a byte.
10948 */
10949 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10950 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10951 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10952 #define CONST_MASK(nr) (1 << ((nr) & 7))
10953
10954 /**
10955 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10956 index b13fe63..0dab13a 100644
10957 --- a/arch/x86/include/asm/boot.h
10958 +++ b/arch/x86/include/asm/boot.h
10959 @@ -11,10 +11,15 @@
10960 #include <asm/pgtable_types.h>
10961
10962 /* Physical address where kernel should be loaded. */
10963 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10964 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10965 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10966 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10967
10968 +#ifndef __ASSEMBLY__
10969 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10970 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10971 +#endif
10972 +
10973 /* Minimum kernel alignment, as a power of two */
10974 #ifdef CONFIG_X86_64
10975 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10976 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10977 index 48f99f1..d78ebf9 100644
10978 --- a/arch/x86/include/asm/cache.h
10979 +++ b/arch/x86/include/asm/cache.h
10980 @@ -5,12 +5,13 @@
10981
10982 /* L1 cache line size */
10983 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10984 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10985 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10986
10987 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10988 +#define __read_only __attribute__((__section__(".data..read_only")))
10989
10990 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10991 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10992 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10993
10994 #ifdef CONFIG_X86_VSMP
10995 #ifdef CONFIG_SMP
10996 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10997 index 9863ee3..4a1f8e1 100644
10998 --- a/arch/x86/include/asm/cacheflush.h
10999 +++ b/arch/x86/include/asm/cacheflush.h
11000 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11001 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11002
11003 if (pg_flags == _PGMT_DEFAULT)
11004 - return -1;
11005 + return ~0UL;
11006 else if (pg_flags == _PGMT_WC)
11007 return _PAGE_CACHE_WC;
11008 else if (pg_flags == _PGMT_UC_MINUS)
11009 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11010 index 46fc474..b02b0f9 100644
11011 --- a/arch/x86/include/asm/checksum_32.h
11012 +++ b/arch/x86/include/asm/checksum_32.h
11013 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11014 int len, __wsum sum,
11015 int *src_err_ptr, int *dst_err_ptr);
11016
11017 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11018 + int len, __wsum sum,
11019 + int *src_err_ptr, int *dst_err_ptr);
11020 +
11021 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11022 + int len, __wsum sum,
11023 + int *src_err_ptr, int *dst_err_ptr);
11024 +
11025 /*
11026 * Note: when you get a NULL pointer exception here this means someone
11027 * passed in an incorrect kernel address to one of these functions.
11028 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11029 int *err_ptr)
11030 {
11031 might_sleep();
11032 - return csum_partial_copy_generic((__force void *)src, dst,
11033 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
11034 len, sum, err_ptr, NULL);
11035 }
11036
11037 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11038 {
11039 might_sleep();
11040 if (access_ok(VERIFY_WRITE, dst, len))
11041 - return csum_partial_copy_generic(src, (__force void *)dst,
11042 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11043 len, sum, NULL, err_ptr);
11044
11045 if (len)
11046 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11047 index 8d871ea..c1a0dc9 100644
11048 --- a/arch/x86/include/asm/cmpxchg.h
11049 +++ b/arch/x86/include/asm/cmpxchg.h
11050 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11051 __compiletime_error("Bad argument size for cmpxchg");
11052 extern void __xadd_wrong_size(void)
11053 __compiletime_error("Bad argument size for xadd");
11054 +extern void __xadd_check_overflow_wrong_size(void)
11055 + __compiletime_error("Bad argument size for xadd_check_overflow");
11056 extern void __add_wrong_size(void)
11057 __compiletime_error("Bad argument size for add");
11058 +extern void __add_check_overflow_wrong_size(void)
11059 + __compiletime_error("Bad argument size for add_check_overflow");
11060
11061 /*
11062 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11063 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11064 __ret; \
11065 })
11066
11067 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11068 + ({ \
11069 + __typeof__ (*(ptr)) __ret = (arg); \
11070 + switch (sizeof(*(ptr))) { \
11071 + case __X86_CASE_L: \
11072 + asm volatile (lock #op "l %0, %1\n" \
11073 + "jno 0f\n" \
11074 + "mov %0,%1\n" \
11075 + "int $4\n0:\n" \
11076 + _ASM_EXTABLE(0b, 0b) \
11077 + : "+r" (__ret), "+m" (*(ptr)) \
11078 + : : "memory", "cc"); \
11079 + break; \
11080 + case __X86_CASE_Q: \
11081 + asm volatile (lock #op "q %q0, %1\n" \
11082 + "jno 0f\n" \
11083 + "mov %0,%1\n" \
11084 + "int $4\n0:\n" \
11085 + _ASM_EXTABLE(0b, 0b) \
11086 + : "+r" (__ret), "+m" (*(ptr)) \
11087 + : : "memory", "cc"); \
11088 + break; \
11089 + default: \
11090 + __ ## op ## _check_overflow_wrong_size(); \
11091 + } \
11092 + __ret; \
11093 + })
11094 +
11095 /*
11096 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11097 * Since this is generally used to protect other memory information, we
11098 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11099 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11100 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11101
11102 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11103 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11104 +
11105 #define __add(ptr, inc, lock) \
11106 ({ \
11107 __typeof__ (*(ptr)) __ret = (inc); \
11108 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11109 index 8c297aa..7a90f03 100644
11110 --- a/arch/x86/include/asm/cpufeature.h
11111 +++ b/arch/x86/include/asm/cpufeature.h
11112 @@ -205,7 +205,7 @@
11113 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11114 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11115 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11116 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11117 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11118 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11119 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11120 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11121 @@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11122 ".section .discard,\"aw\",@progbits\n"
11123 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11124 ".previous\n"
11125 - ".section .altinstr_replacement,\"ax\"\n"
11126 + ".section .altinstr_replacement,\"a\"\n"
11127 "3: movb $1,%0\n"
11128 "4:\n"
11129 ".previous\n"
11130 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11131 index 8bf1c06..f723dfd 100644
11132 --- a/arch/x86/include/asm/desc.h
11133 +++ b/arch/x86/include/asm/desc.h
11134 @@ -4,6 +4,7 @@
11135 #include <asm/desc_defs.h>
11136 #include <asm/ldt.h>
11137 #include <asm/mmu.h>
11138 +#include <asm/pgtable.h>
11139
11140 #include <linux/smp.h>
11141 #include <linux/percpu.h>
11142 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11143
11144 desc->type = (info->read_exec_only ^ 1) << 1;
11145 desc->type |= info->contents << 2;
11146 + desc->type |= info->seg_not_present ^ 1;
11147
11148 desc->s = 1;
11149 desc->dpl = 0x3;
11150 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11151 }
11152
11153 extern struct desc_ptr idt_descr;
11154 -extern gate_desc idt_table[];
11155 extern struct desc_ptr nmi_idt_descr;
11156 -extern gate_desc nmi_idt_table[];
11157 -
11158 -struct gdt_page {
11159 - struct desc_struct gdt[GDT_ENTRIES];
11160 -} __attribute__((aligned(PAGE_SIZE)));
11161 -
11162 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11163 +extern gate_desc idt_table[256];
11164 +extern gate_desc nmi_idt_table[256];
11165
11166 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11167 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11168 {
11169 - return per_cpu(gdt_page, cpu).gdt;
11170 + return cpu_gdt_table[cpu];
11171 }
11172
11173 #ifdef CONFIG_X86_64
11174 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11175 unsigned long base, unsigned dpl, unsigned flags,
11176 unsigned short seg)
11177 {
11178 - gate->a = (seg << 16) | (base & 0xffff);
11179 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11180 + gate->gate.offset_low = base;
11181 + gate->gate.seg = seg;
11182 + gate->gate.reserved = 0;
11183 + gate->gate.type = type;
11184 + gate->gate.s = 0;
11185 + gate->gate.dpl = dpl;
11186 + gate->gate.p = 1;
11187 + gate->gate.offset_high = base >> 16;
11188 }
11189
11190 #endif
11191 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11192
11193 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11194 {
11195 + pax_open_kernel();
11196 memcpy(&idt[entry], gate, sizeof(*gate));
11197 + pax_close_kernel();
11198 }
11199
11200 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11201 {
11202 + pax_open_kernel();
11203 memcpy(&ldt[entry], desc, 8);
11204 + pax_close_kernel();
11205 }
11206
11207 static inline void
11208 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11209 default: size = sizeof(*gdt); break;
11210 }
11211
11212 + pax_open_kernel();
11213 memcpy(&gdt[entry], desc, size);
11214 + pax_close_kernel();
11215 }
11216
11217 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11218 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11219
11220 static inline void native_load_tr_desc(void)
11221 {
11222 + pax_open_kernel();
11223 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11224 + pax_close_kernel();
11225 }
11226
11227 static inline void native_load_gdt(const struct desc_ptr *dtr)
11228 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11229 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11230 unsigned int i;
11231
11232 + pax_open_kernel();
11233 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11234 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11235 + pax_close_kernel();
11236 }
11237
11238 #define _LDT_empty(info) \
11239 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11240 }
11241
11242 #ifdef CONFIG_X86_64
11243 -static inline void set_nmi_gate(int gate, void *addr)
11244 +static inline void set_nmi_gate(int gate, const void *addr)
11245 {
11246 gate_desc s;
11247
11248 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11249 }
11250 #endif
11251
11252 -static inline void _set_gate(int gate, unsigned type, void *addr,
11253 +static inline void _set_gate(int gate, unsigned type, const void *addr,
11254 unsigned dpl, unsigned ist, unsigned seg)
11255 {
11256 gate_desc s;
11257 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11258 * Pentium F0 0F bugfix can have resulted in the mapped
11259 * IDT being write-protected.
11260 */
11261 -static inline void set_intr_gate(unsigned int n, void *addr)
11262 +static inline void set_intr_gate(unsigned int n, const void *addr)
11263 {
11264 BUG_ON((unsigned)n > 0xFF);
11265 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11266 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11267 /*
11268 * This routine sets up an interrupt gate at directory privilege level 3.
11269 */
11270 -static inline void set_system_intr_gate(unsigned int n, void *addr)
11271 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
11272 {
11273 BUG_ON((unsigned)n > 0xFF);
11274 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11275 }
11276
11277 -static inline void set_system_trap_gate(unsigned int n, void *addr)
11278 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
11279 {
11280 BUG_ON((unsigned)n > 0xFF);
11281 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11282 }
11283
11284 -static inline void set_trap_gate(unsigned int n, void *addr)
11285 +static inline void set_trap_gate(unsigned int n, const void *addr)
11286 {
11287 BUG_ON((unsigned)n > 0xFF);
11288 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11289 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11290 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11291 {
11292 BUG_ON((unsigned)n > 0xFF);
11293 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11294 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11295 }
11296
11297 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11298 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11299 {
11300 BUG_ON((unsigned)n > 0xFF);
11301 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11302 }
11303
11304 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11305 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11306 {
11307 BUG_ON((unsigned)n > 0xFF);
11308 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11309 }
11310
11311 +#ifdef CONFIG_X86_32
11312 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11313 +{
11314 + struct desc_struct d;
11315 +
11316 + if (likely(limit))
11317 + limit = (limit - 1UL) >> PAGE_SHIFT;
11318 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
11319 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11320 +}
11321 +#endif
11322 +
11323 #endif /* _ASM_X86_DESC_H */
11324 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11325 index 278441f..b95a174 100644
11326 --- a/arch/x86/include/asm/desc_defs.h
11327 +++ b/arch/x86/include/asm/desc_defs.h
11328 @@ -31,6 +31,12 @@ struct desc_struct {
11329 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11330 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11331 };
11332 + struct {
11333 + u16 offset_low;
11334 + u16 seg;
11335 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11336 + unsigned offset_high: 16;
11337 + } gate;
11338 };
11339 } __attribute__((packed));
11340
11341 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11342 index 3778256..c5d4fce 100644
11343 --- a/arch/x86/include/asm/e820.h
11344 +++ b/arch/x86/include/asm/e820.h
11345 @@ -69,7 +69,7 @@ struct e820map {
11346 #define ISA_START_ADDRESS 0xa0000
11347 #define ISA_END_ADDRESS 0x100000
11348
11349 -#define BIOS_BEGIN 0x000a0000
11350 +#define BIOS_BEGIN 0x000c0000
11351 #define BIOS_END 0x00100000
11352
11353 #define BIOS_ROM_BASE 0xffe00000
11354 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11355 index 5939f44..f8845f6 100644
11356 --- a/arch/x86/include/asm/elf.h
11357 +++ b/arch/x86/include/asm/elf.h
11358 @@ -243,7 +243,25 @@ extern int force_personality32;
11359 the loader. We need to make sure that it is out of the way of the program
11360 that it will "exec", and that there is sufficient room for the brk. */
11361
11362 +#ifdef CONFIG_PAX_SEGMEXEC
11363 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11364 +#else
11365 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11366 +#endif
11367 +
11368 +#ifdef CONFIG_PAX_ASLR
11369 +#ifdef CONFIG_X86_32
11370 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11371 +
11372 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11373 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11374 +#else
11375 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
11376 +
11377 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11378 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11379 +#endif
11380 +#endif
11381
11382 /* This yields a mask that user programs can use to figure out what
11383 instruction set this CPU supports. This could be done in user space,
11384 @@ -296,16 +314,12 @@ do { \
11385
11386 #define ARCH_DLINFO \
11387 do { \
11388 - if (vdso_enabled) \
11389 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11390 - (unsigned long)current->mm->context.vdso); \
11391 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11392 } while (0)
11393
11394 #define ARCH_DLINFO_X32 \
11395 do { \
11396 - if (vdso_enabled) \
11397 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11398 - (unsigned long)current->mm->context.vdso); \
11399 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11400 } while (0)
11401
11402 #define AT_SYSINFO 32
11403 @@ -320,7 +334,7 @@ else \
11404
11405 #endif /* !CONFIG_X86_32 */
11406
11407 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11408 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11409
11410 #define VDSO_ENTRY \
11411 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11412 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11413 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11414 #define compat_arch_setup_additional_pages syscall32_setup_pages
11415
11416 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11417 -#define arch_randomize_brk arch_randomize_brk
11418 -
11419 /*
11420 * True on X86_32 or when emulating IA32 on X86_64
11421 */
11422 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11423 index 75ce3f4..882e801 100644
11424 --- a/arch/x86/include/asm/emergency-restart.h
11425 +++ b/arch/x86/include/asm/emergency-restart.h
11426 @@ -13,6 +13,6 @@ enum reboot_type {
11427
11428 extern enum reboot_type reboot_type;
11429
11430 -extern void machine_emergency_restart(void);
11431 +extern void machine_emergency_restart(void) __noreturn;
11432
11433 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11434 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11435 index 41ab26e..a88c9e6 100644
11436 --- a/arch/x86/include/asm/fpu-internal.h
11437 +++ b/arch/x86/include/asm/fpu-internal.h
11438 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11439 ({ \
11440 int err; \
11441 asm volatile(ASM_STAC "\n" \
11442 - "1:" #insn "\n\t" \
11443 + "1:" \
11444 + __copyuser_seg \
11445 + #insn "\n\t" \
11446 "2: " ASM_CLAC "\n" \
11447 ".section .fixup,\"ax\"\n" \
11448 "3: movl $-1,%[err]\n" \
11449 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11450 "emms\n\t" /* clear stack tags */
11451 "fildl %P[addr]", /* set F?P to defined value */
11452 X86_FEATURE_FXSAVE_LEAK,
11453 - [addr] "m" (tsk->thread.fpu.has_fpu));
11454 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11455
11456 return fpu_restore_checking(&tsk->thread.fpu);
11457 }
11458 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11459 index f373046..02653e2 100644
11460 --- a/arch/x86/include/asm/futex.h
11461 +++ b/arch/x86/include/asm/futex.h
11462 @@ -12,6 +12,7 @@
11463 #include <asm/smap.h>
11464
11465 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11466 + typecheck(u32 __user *, uaddr); \
11467 asm volatile("\t" ASM_STAC "\n" \
11468 "1:\t" insn "\n" \
11469 "2:\t" ASM_CLAC "\n" \
11470 @@ -20,15 +21,16 @@
11471 "\tjmp\t2b\n" \
11472 "\t.previous\n" \
11473 _ASM_EXTABLE(1b, 3b) \
11474 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11475 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11476 : "i" (-EFAULT), "0" (oparg), "1" (0))
11477
11478 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11479 + typecheck(u32 __user *, uaddr); \
11480 asm volatile("\t" ASM_STAC "\n" \
11481 "1:\tmovl %2, %0\n" \
11482 "\tmovl\t%0, %3\n" \
11483 "\t" insn "\n" \
11484 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11485 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11486 "\tjnz\t1b\n" \
11487 "3:\t" ASM_CLAC "\n" \
11488 "\t.section .fixup,\"ax\"\n" \
11489 @@ -38,7 +40,7 @@
11490 _ASM_EXTABLE(1b, 4b) \
11491 _ASM_EXTABLE(2b, 4b) \
11492 : "=&a" (oldval), "=&r" (ret), \
11493 - "+m" (*uaddr), "=&r" (tem) \
11494 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11495 : "r" (oparg), "i" (-EFAULT), "1" (0))
11496
11497 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11498 @@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11499
11500 switch (op) {
11501 case FUTEX_OP_SET:
11502 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11503 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11504 break;
11505 case FUTEX_OP_ADD:
11506 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11507 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11508 uaddr, oparg);
11509 break;
11510 case FUTEX_OP_OR:
11511 @@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11512 return -EFAULT;
11513
11514 asm volatile("\t" ASM_STAC "\n"
11515 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11516 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11517 "2:\t" ASM_CLAC "\n"
11518 "\t.section .fixup, \"ax\"\n"
11519 "3:\tmov %3, %0\n"
11520 "\tjmp 2b\n"
11521 "\t.previous\n"
11522 _ASM_EXTABLE(1b, 3b)
11523 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11524 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11525 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11526 : "memory"
11527 );
11528 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11529 index eb92a6e..b98b2f4 100644
11530 --- a/arch/x86/include/asm/hw_irq.h
11531 +++ b/arch/x86/include/asm/hw_irq.h
11532 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11533 extern void enable_IO_APIC(void);
11534
11535 /* Statistics */
11536 -extern atomic_t irq_err_count;
11537 -extern atomic_t irq_mis_count;
11538 +extern atomic_unchecked_t irq_err_count;
11539 +extern atomic_unchecked_t irq_mis_count;
11540
11541 /* EISA */
11542 extern void eisa_set_level_irq(unsigned int irq);
11543 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11544 index d8e8eef..15b1179 100644
11545 --- a/arch/x86/include/asm/io.h
11546 +++ b/arch/x86/include/asm/io.h
11547 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11548 return ioremap_nocache(offset, size);
11549 }
11550
11551 -extern void iounmap(volatile void __iomem *addr);
11552 +extern void iounmap(const volatile void __iomem *addr);
11553
11554 extern void set_iounmap_nonlazy(void);
11555
11556 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11557
11558 #include <linux/vmalloc.h>
11559
11560 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11561 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11562 +{
11563 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11564 +}
11565 +
11566 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11567 +{
11568 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11569 +}
11570 +
11571 /*
11572 * Convert a virtual cached pointer to an uncached pointer
11573 */
11574 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11575 index bba3cf8..06bc8da 100644
11576 --- a/arch/x86/include/asm/irqflags.h
11577 +++ b/arch/x86/include/asm/irqflags.h
11578 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11579 sti; \
11580 sysexit
11581
11582 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
11583 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11584 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
11585 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11586 +
11587 #else
11588 #define INTERRUPT_RETURN iret
11589 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11590 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11591 index d3ddd17..c9fb0cc 100644
11592 --- a/arch/x86/include/asm/kprobes.h
11593 +++ b/arch/x86/include/asm/kprobes.h
11594 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11595 #define RELATIVEJUMP_SIZE 5
11596 #define RELATIVECALL_OPCODE 0xe8
11597 #define RELATIVE_ADDR_SIZE 4
11598 -#define MAX_STACK_SIZE 64
11599 -#define MIN_STACK_SIZE(ADDR) \
11600 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11601 - THREAD_SIZE - (unsigned long)(ADDR))) \
11602 - ? (MAX_STACK_SIZE) \
11603 - : (((unsigned long)current_thread_info()) + \
11604 - THREAD_SIZE - (unsigned long)(ADDR)))
11605 +#define MAX_STACK_SIZE 64UL
11606 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11607
11608 #define flush_insn_slot(p) do { } while (0)
11609
11610 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
11611 index b2e11f4..f293e2e 100644
11612 --- a/arch/x86/include/asm/kvm_host.h
11613 +++ b/arch/x86/include/asm/kvm_host.h
11614 @@ -707,7 +707,7 @@ struct kvm_x86_ops {
11615 int (*check_intercept)(struct kvm_vcpu *vcpu,
11616 struct x86_instruction_info *info,
11617 enum x86_intercept_stage stage);
11618 -};
11619 +} __do_const;
11620
11621 struct kvm_arch_async_pf {
11622 u32 token;
11623 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11624 index c8bed0d..85c03fd 100644
11625 --- a/arch/x86/include/asm/local.h
11626 +++ b/arch/x86/include/asm/local.h
11627 @@ -10,33 +10,97 @@ typedef struct {
11628 atomic_long_t a;
11629 } local_t;
11630
11631 +typedef struct {
11632 + atomic_long_unchecked_t a;
11633 +} local_unchecked_t;
11634 +
11635 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11636
11637 #define local_read(l) atomic_long_read(&(l)->a)
11638 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11639 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
11640 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
11641
11642 static inline void local_inc(local_t *l)
11643 {
11644 - asm volatile(_ASM_INC "%0"
11645 + asm volatile(_ASM_INC "%0\n"
11646 +
11647 +#ifdef CONFIG_PAX_REFCOUNT
11648 + "jno 0f\n"
11649 + _ASM_DEC "%0\n"
11650 + "int $4\n0:\n"
11651 + _ASM_EXTABLE(0b, 0b)
11652 +#endif
11653 +
11654 + : "+m" (l->a.counter));
11655 +}
11656 +
11657 +static inline void local_inc_unchecked(local_unchecked_t *l)
11658 +{
11659 + asm volatile(_ASM_INC "%0\n"
11660 : "+m" (l->a.counter));
11661 }
11662
11663 static inline void local_dec(local_t *l)
11664 {
11665 - asm volatile(_ASM_DEC "%0"
11666 + asm volatile(_ASM_DEC "%0\n"
11667 +
11668 +#ifdef CONFIG_PAX_REFCOUNT
11669 + "jno 0f\n"
11670 + _ASM_INC "%0\n"
11671 + "int $4\n0:\n"
11672 + _ASM_EXTABLE(0b, 0b)
11673 +#endif
11674 +
11675 + : "+m" (l->a.counter));
11676 +}
11677 +
11678 +static inline void local_dec_unchecked(local_unchecked_t *l)
11679 +{
11680 + asm volatile(_ASM_DEC "%0\n"
11681 : "+m" (l->a.counter));
11682 }
11683
11684 static inline void local_add(long i, local_t *l)
11685 {
11686 - asm volatile(_ASM_ADD "%1,%0"
11687 + asm volatile(_ASM_ADD "%1,%0\n"
11688 +
11689 +#ifdef CONFIG_PAX_REFCOUNT
11690 + "jno 0f\n"
11691 + _ASM_SUB "%1,%0\n"
11692 + "int $4\n0:\n"
11693 + _ASM_EXTABLE(0b, 0b)
11694 +#endif
11695 +
11696 + : "+m" (l->a.counter)
11697 + : "ir" (i));
11698 +}
11699 +
11700 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
11701 +{
11702 + asm volatile(_ASM_ADD "%1,%0\n"
11703 : "+m" (l->a.counter)
11704 : "ir" (i));
11705 }
11706
11707 static inline void local_sub(long i, local_t *l)
11708 {
11709 - asm volatile(_ASM_SUB "%1,%0"
11710 + asm volatile(_ASM_SUB "%1,%0\n"
11711 +
11712 +#ifdef CONFIG_PAX_REFCOUNT
11713 + "jno 0f\n"
11714 + _ASM_ADD "%1,%0\n"
11715 + "int $4\n0:\n"
11716 + _ASM_EXTABLE(0b, 0b)
11717 +#endif
11718 +
11719 + : "+m" (l->a.counter)
11720 + : "ir" (i));
11721 +}
11722 +
11723 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
11724 +{
11725 + asm volatile(_ASM_SUB "%1,%0\n"
11726 : "+m" (l->a.counter)
11727 : "ir" (i));
11728 }
11729 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
11730 {
11731 unsigned char c;
11732
11733 - asm volatile(_ASM_SUB "%2,%0; sete %1"
11734 + asm volatile(_ASM_SUB "%2,%0\n"
11735 +
11736 +#ifdef CONFIG_PAX_REFCOUNT
11737 + "jno 0f\n"
11738 + _ASM_ADD "%2,%0\n"
11739 + "int $4\n0:\n"
11740 + _ASM_EXTABLE(0b, 0b)
11741 +#endif
11742 +
11743 + "sete %1\n"
11744 : "+m" (l->a.counter), "=qm" (c)
11745 : "ir" (i) : "memory");
11746 return c;
11747 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
11748 {
11749 unsigned char c;
11750
11751 - asm volatile(_ASM_DEC "%0; sete %1"
11752 + asm volatile(_ASM_DEC "%0\n"
11753 +
11754 +#ifdef CONFIG_PAX_REFCOUNT
11755 + "jno 0f\n"
11756 + _ASM_INC "%0\n"
11757 + "int $4\n0:\n"
11758 + _ASM_EXTABLE(0b, 0b)
11759 +#endif
11760 +
11761 + "sete %1\n"
11762 : "+m" (l->a.counter), "=qm" (c)
11763 : : "memory");
11764 return c != 0;
11765 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
11766 {
11767 unsigned char c;
11768
11769 - asm volatile(_ASM_INC "%0; sete %1"
11770 + asm volatile(_ASM_INC "%0\n"
11771 +
11772 +#ifdef CONFIG_PAX_REFCOUNT
11773 + "jno 0f\n"
11774 + _ASM_DEC "%0\n"
11775 + "int $4\n0:\n"
11776 + _ASM_EXTABLE(0b, 0b)
11777 +#endif
11778 +
11779 + "sete %1\n"
11780 : "+m" (l->a.counter), "=qm" (c)
11781 : : "memory");
11782 return c != 0;
11783 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
11784 {
11785 unsigned char c;
11786
11787 - asm volatile(_ASM_ADD "%2,%0; sets %1"
11788 + asm volatile(_ASM_ADD "%2,%0\n"
11789 +
11790 +#ifdef CONFIG_PAX_REFCOUNT
11791 + "jno 0f\n"
11792 + _ASM_SUB "%2,%0\n"
11793 + "int $4\n0:\n"
11794 + _ASM_EXTABLE(0b, 0b)
11795 +#endif
11796 +
11797 + "sets %1\n"
11798 : "+m" (l->a.counter), "=qm" (c)
11799 : "ir" (i) : "memory");
11800 return c;
11801 @@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
11802 #endif
11803 /* Modern 486+ processor */
11804 __i = i;
11805 - asm volatile(_ASM_XADD "%0, %1;"
11806 + asm volatile(_ASM_XADD "%0, %1\n"
11807 +
11808 +#ifdef CONFIG_PAX_REFCOUNT
11809 + "jno 0f\n"
11810 + _ASM_MOV "%0,%1\n"
11811 + "int $4\n0:\n"
11812 + _ASM_EXTABLE(0b, 0b)
11813 +#endif
11814 +
11815 : "+r" (i), "+m" (l->a.counter)
11816 : : "memory");
11817 return i + __i;
11818 @@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
11819 #endif
11820 }
11821
11822 +/**
11823 + * local_add_return_unchecked - add and return
11824 + * @i: integer value to add
11825 + * @l: pointer to type local_unchecked_t
11826 + *
11827 + * Atomically adds @i to @l and returns @i + @l
11828 + */
11829 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
11830 +{
11831 + long __i;
11832 +#ifdef CONFIG_M386
11833 + unsigned long flags;
11834 + if (unlikely(boot_cpu_data.x86 <= 3))
11835 + goto no_xadd;
11836 +#endif
11837 + /* Modern 486+ processor */
11838 + __i = i;
11839 + asm volatile(_ASM_XADD "%0, %1\n"
11840 + : "+r" (i), "+m" (l->a.counter)
11841 + : : "memory");
11842 + return i + __i;
11843 +
11844 +#ifdef CONFIG_M386
11845 +no_xadd: /* Legacy 386 processor */
11846 + local_irq_save(flags);
11847 + __i = local_read_unchecked(l);
11848 + local_set_unchecked(l, i + __i);
11849 + local_irq_restore(flags);
11850 + return i + __i;
11851 +#endif
11852 +}
11853 +
11854 static inline long local_sub_return(long i, local_t *l)
11855 {
11856 return local_add_return(-i, l);
11857 @@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
11858
11859 #define local_cmpxchg(l, o, n) \
11860 (cmpxchg_local(&((l)->a.counter), (o), (n)))
11861 +#define local_cmpxchg_unchecked(l, o, n) \
11862 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
11863 /* Always has a lock prefix */
11864 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
11865
11866 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
11867 index 593e51d..fa69c9a 100644
11868 --- a/arch/x86/include/asm/mman.h
11869 +++ b/arch/x86/include/asm/mman.h
11870 @@ -5,4 +5,14 @@
11871
11872 #include <asm-generic/mman.h>
11873
11874 +#ifdef __KERNEL__
11875 +#ifndef __ASSEMBLY__
11876 +#ifdef CONFIG_X86_32
11877 +#define arch_mmap_check i386_mmap_check
11878 +int i386_mmap_check(unsigned long addr, unsigned long len,
11879 + unsigned long flags);
11880 +#endif
11881 +#endif
11882 +#endif
11883 +
11884 #endif /* _ASM_X86_MMAN_H */
11885 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
11886 index 5f55e69..e20bfb1 100644
11887 --- a/arch/x86/include/asm/mmu.h
11888 +++ b/arch/x86/include/asm/mmu.h
11889 @@ -9,7 +9,7 @@
11890 * we put the segment information here.
11891 */
11892 typedef struct {
11893 - void *ldt;
11894 + struct desc_struct *ldt;
11895 int size;
11896
11897 #ifdef CONFIG_X86_64
11898 @@ -18,7 +18,19 @@ typedef struct {
11899 #endif
11900
11901 struct mutex lock;
11902 - void *vdso;
11903 + unsigned long vdso;
11904 +
11905 +#ifdef CONFIG_X86_32
11906 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11907 + unsigned long user_cs_base;
11908 + unsigned long user_cs_limit;
11909 +
11910 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11911 + cpumask_t cpu_user_cs_mask;
11912 +#endif
11913 +
11914 +#endif
11915 +#endif
11916 } mm_context_t;
11917
11918 #ifdef CONFIG_SMP
11919 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11920 index cdbf367..adb37ac 100644
11921 --- a/arch/x86/include/asm/mmu_context.h
11922 +++ b/arch/x86/include/asm/mmu_context.h
11923 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11924
11925 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11926 {
11927 +
11928 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11929 + unsigned int i;
11930 + pgd_t *pgd;
11931 +
11932 + pax_open_kernel();
11933 + pgd = get_cpu_pgd(smp_processor_id());
11934 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11935 + set_pgd_batched(pgd+i, native_make_pgd(0));
11936 + pax_close_kernel();
11937 +#endif
11938 +
11939 #ifdef CONFIG_SMP
11940 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11941 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11942 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11943 struct task_struct *tsk)
11944 {
11945 unsigned cpu = smp_processor_id();
11946 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11947 + int tlbstate = TLBSTATE_OK;
11948 +#endif
11949
11950 if (likely(prev != next)) {
11951 #ifdef CONFIG_SMP
11952 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11953 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11954 +#endif
11955 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11956 this_cpu_write(cpu_tlbstate.active_mm, next);
11957 #endif
11958 cpumask_set_cpu(cpu, mm_cpumask(next));
11959
11960 /* Re-load page tables */
11961 +#ifdef CONFIG_PAX_PER_CPU_PGD
11962 + pax_open_kernel();
11963 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11964 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11965 + pax_close_kernel();
11966 + load_cr3(get_cpu_pgd(cpu));
11967 +#else
11968 load_cr3(next->pgd);
11969 +#endif
11970
11971 /* stop flush ipis for the previous mm */
11972 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11973 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11974 */
11975 if (unlikely(prev->context.ldt != next->context.ldt))
11976 load_LDT_nolock(&next->context);
11977 - }
11978 +
11979 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11980 + if (!(__supported_pte_mask & _PAGE_NX)) {
11981 + smp_mb__before_clear_bit();
11982 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11983 + smp_mb__after_clear_bit();
11984 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11985 + }
11986 +#endif
11987 +
11988 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11989 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11990 + prev->context.user_cs_limit != next->context.user_cs_limit))
11991 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11992 #ifdef CONFIG_SMP
11993 + else if (unlikely(tlbstate != TLBSTATE_OK))
11994 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11995 +#endif
11996 +#endif
11997 +
11998 + }
11999 else {
12000 +
12001 +#ifdef CONFIG_PAX_PER_CPU_PGD
12002 + pax_open_kernel();
12003 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12004 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12005 + pax_close_kernel();
12006 + load_cr3(get_cpu_pgd(cpu));
12007 +#endif
12008 +
12009 +#ifdef CONFIG_SMP
12010 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12011 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12012
12013 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12014 * tlb flush IPI delivery. We must reload CR3
12015 * to make sure to use no freed page tables.
12016 */
12017 +
12018 +#ifndef CONFIG_PAX_PER_CPU_PGD
12019 load_cr3(next->pgd);
12020 +#endif
12021 +
12022 load_LDT_nolock(&next->context);
12023 +
12024 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12025 + if (!(__supported_pte_mask & _PAGE_NX))
12026 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12027 +#endif
12028 +
12029 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12030 +#ifdef CONFIG_PAX_PAGEEXEC
12031 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12032 +#endif
12033 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12034 +#endif
12035 +
12036 }
12037 +#endif
12038 }
12039 -#endif
12040 }
12041
12042 #define activate_mm(prev, next) \
12043 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12044 index 9eae775..c914fea 100644
12045 --- a/arch/x86/include/asm/module.h
12046 +++ b/arch/x86/include/asm/module.h
12047 @@ -5,6 +5,7 @@
12048
12049 #ifdef CONFIG_X86_64
12050 /* X86_64 does not define MODULE_PROC_FAMILY */
12051 +#define MODULE_PROC_FAMILY ""
12052 #elif defined CONFIG_M386
12053 #define MODULE_PROC_FAMILY "386 "
12054 #elif defined CONFIG_M486
12055 @@ -59,8 +60,20 @@
12056 #error unknown processor family
12057 #endif
12058
12059 -#ifdef CONFIG_X86_32
12060 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12061 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12062 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12063 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12064 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12065 +#else
12066 +#define MODULE_PAX_KERNEXEC ""
12067 #endif
12068
12069 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12070 +#define MODULE_PAX_UDEREF "UDEREF "
12071 +#else
12072 +#define MODULE_PAX_UDEREF ""
12073 +#endif
12074 +
12075 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12076 +
12077 #endif /* _ASM_X86_MODULE_H */
12078 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12079 index 320f7bb..e89f8f8 100644
12080 --- a/arch/x86/include/asm/page_64_types.h
12081 +++ b/arch/x86/include/asm/page_64_types.h
12082 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12083
12084 /* duplicated to the one in bootmem.h */
12085 extern unsigned long max_pfn;
12086 -extern unsigned long phys_base;
12087 +extern const unsigned long phys_base;
12088
12089 extern unsigned long __phys_addr(unsigned long);
12090 #define __phys_reloc_hide(x) (x)
12091 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12092 index a0facf3..c017b15 100644
12093 --- a/arch/x86/include/asm/paravirt.h
12094 +++ b/arch/x86/include/asm/paravirt.h
12095 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12096 val);
12097 }
12098
12099 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12100 +{
12101 + pgdval_t val = native_pgd_val(pgd);
12102 +
12103 + if (sizeof(pgdval_t) > sizeof(long))
12104 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12105 + val, (u64)val >> 32);
12106 + else
12107 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12108 + val);
12109 +}
12110 +
12111 static inline void pgd_clear(pgd_t *pgdp)
12112 {
12113 set_pgd(pgdp, __pgd(0));
12114 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12115 pv_mmu_ops.set_fixmap(idx, phys, flags);
12116 }
12117
12118 +#ifdef CONFIG_PAX_KERNEXEC
12119 +static inline unsigned long pax_open_kernel(void)
12120 +{
12121 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12122 +}
12123 +
12124 +static inline unsigned long pax_close_kernel(void)
12125 +{
12126 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12127 +}
12128 +#else
12129 +static inline unsigned long pax_open_kernel(void) { return 0; }
12130 +static inline unsigned long pax_close_kernel(void) { return 0; }
12131 +#endif
12132 +
12133 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12134
12135 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12136 @@ -929,7 +956,7 @@ extern void default_banner(void);
12137
12138 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12139 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12140 -#define PARA_INDIRECT(addr) *%cs:addr
12141 +#define PARA_INDIRECT(addr) *%ss:addr
12142 #endif
12143
12144 #define INTERRUPT_RETURN \
12145 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
12146 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12147 CLBR_NONE, \
12148 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12149 +
12150 +#define GET_CR0_INTO_RDI \
12151 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12152 + mov %rax,%rdi
12153 +
12154 +#define SET_RDI_INTO_CR0 \
12155 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12156 +
12157 +#define GET_CR3_INTO_RDI \
12158 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12159 + mov %rax,%rdi
12160 +
12161 +#define SET_RDI_INTO_CR3 \
12162 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12163 +
12164 #endif /* CONFIG_X86_32 */
12165
12166 #endif /* __ASSEMBLY__ */
12167 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12168 index 142236e..57cf5ea 100644
12169 --- a/arch/x86/include/asm/paravirt_types.h
12170 +++ b/arch/x86/include/asm/paravirt_types.h
12171 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
12172 struct paravirt_callee_save make_pud;
12173
12174 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12175 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12176 #endif /* PAGETABLE_LEVELS == 4 */
12177 #endif /* PAGETABLE_LEVELS >= 3 */
12178
12179 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
12180 an mfn. We can tell which is which from the index. */
12181 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12182 phys_addr_t phys, pgprot_t flags);
12183 +
12184 +#ifdef CONFIG_PAX_KERNEXEC
12185 + unsigned long (*pax_open_kernel)(void);
12186 + unsigned long (*pax_close_kernel)(void);
12187 +#endif
12188 +
12189 };
12190
12191 struct arch_spinlock;
12192 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12193 index b4389a4..7024269 100644
12194 --- a/arch/x86/include/asm/pgalloc.h
12195 +++ b/arch/x86/include/asm/pgalloc.h
12196 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12197 pmd_t *pmd, pte_t *pte)
12198 {
12199 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12200 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12201 +}
12202 +
12203 +static inline void pmd_populate_user(struct mm_struct *mm,
12204 + pmd_t *pmd, pte_t *pte)
12205 +{
12206 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12207 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12208 }
12209
12210 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12211
12212 #ifdef CONFIG_X86_PAE
12213 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12214 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12215 +{
12216 + pud_populate(mm, pudp, pmd);
12217 +}
12218 #else /* !CONFIG_X86_PAE */
12219 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12220 {
12221 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12222 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12223 }
12224 +
12225 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12226 +{
12227 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12228 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12229 +}
12230 #endif /* CONFIG_X86_PAE */
12231
12232 #if PAGETABLE_LEVELS > 3
12233 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12234 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12235 }
12236
12237 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12238 +{
12239 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12240 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12241 +}
12242 +
12243 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12244 {
12245 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12246 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12247 index f2b489c..4f7e2e5 100644
12248 --- a/arch/x86/include/asm/pgtable-2level.h
12249 +++ b/arch/x86/include/asm/pgtable-2level.h
12250 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12251
12252 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12253 {
12254 + pax_open_kernel();
12255 *pmdp = pmd;
12256 + pax_close_kernel();
12257 }
12258
12259 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12260 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12261 index 4cc9f2b..5fd9226 100644
12262 --- a/arch/x86/include/asm/pgtable-3level.h
12263 +++ b/arch/x86/include/asm/pgtable-3level.h
12264 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12265
12266 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12267 {
12268 + pax_open_kernel();
12269 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12270 + pax_close_kernel();
12271 }
12272
12273 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12274 {
12275 + pax_open_kernel();
12276 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12277 + pax_close_kernel();
12278 }
12279
12280 /*
12281 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12282 index a1f780d..5f38ced4 100644
12283 --- a/arch/x86/include/asm/pgtable.h
12284 +++ b/arch/x86/include/asm/pgtable.h
12285 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12286
12287 #ifndef __PAGETABLE_PUD_FOLDED
12288 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12289 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12290 #define pgd_clear(pgd) native_pgd_clear(pgd)
12291 #endif
12292
12293 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12294
12295 #define arch_end_context_switch(prev) do {} while(0)
12296
12297 +#define pax_open_kernel() native_pax_open_kernel()
12298 +#define pax_close_kernel() native_pax_close_kernel()
12299 #endif /* CONFIG_PARAVIRT */
12300
12301 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
12302 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12303 +
12304 +#ifdef CONFIG_PAX_KERNEXEC
12305 +static inline unsigned long native_pax_open_kernel(void)
12306 +{
12307 + unsigned long cr0;
12308 +
12309 + preempt_disable();
12310 + barrier();
12311 + cr0 = read_cr0() ^ X86_CR0_WP;
12312 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
12313 + write_cr0(cr0);
12314 + return cr0 ^ X86_CR0_WP;
12315 +}
12316 +
12317 +static inline unsigned long native_pax_close_kernel(void)
12318 +{
12319 + unsigned long cr0;
12320 +
12321 + cr0 = read_cr0() ^ X86_CR0_WP;
12322 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
12323 + write_cr0(cr0);
12324 + barrier();
12325 + preempt_enable_no_resched();
12326 + return cr0 ^ X86_CR0_WP;
12327 +}
12328 +#else
12329 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
12330 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
12331 +#endif
12332 +
12333 /*
12334 * The following only work if pte_present() is true.
12335 * Undefined behaviour if not..
12336 */
12337 +static inline int pte_user(pte_t pte)
12338 +{
12339 + return pte_val(pte) & _PAGE_USER;
12340 +}
12341 +
12342 static inline int pte_dirty(pte_t pte)
12343 {
12344 return pte_flags(pte) & _PAGE_DIRTY;
12345 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12346 return pte_clear_flags(pte, _PAGE_RW);
12347 }
12348
12349 +static inline pte_t pte_mkread(pte_t pte)
12350 +{
12351 + return __pte(pte_val(pte) | _PAGE_USER);
12352 +}
12353 +
12354 static inline pte_t pte_mkexec(pte_t pte)
12355 {
12356 - return pte_clear_flags(pte, _PAGE_NX);
12357 +#ifdef CONFIG_X86_PAE
12358 + if (__supported_pte_mask & _PAGE_NX)
12359 + return pte_clear_flags(pte, _PAGE_NX);
12360 + else
12361 +#endif
12362 + return pte_set_flags(pte, _PAGE_USER);
12363 +}
12364 +
12365 +static inline pte_t pte_exprotect(pte_t pte)
12366 +{
12367 +#ifdef CONFIG_X86_PAE
12368 + if (__supported_pte_mask & _PAGE_NX)
12369 + return pte_set_flags(pte, _PAGE_NX);
12370 + else
12371 +#endif
12372 + return pte_clear_flags(pte, _PAGE_USER);
12373 }
12374
12375 static inline pte_t pte_mkdirty(pte_t pte)
12376 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12377 #endif
12378
12379 #ifndef __ASSEMBLY__
12380 +
12381 +#ifdef CONFIG_PAX_PER_CPU_PGD
12382 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12383 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12384 +{
12385 + return cpu_pgd[cpu];
12386 +}
12387 +#endif
12388 +
12389 #include <linux/mm_types.h>
12390
12391 static inline int pte_none(pte_t pte)
12392 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12393
12394 static inline int pgd_bad(pgd_t pgd)
12395 {
12396 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12397 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12398 }
12399
12400 static inline int pgd_none(pgd_t pgd)
12401 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
12402 * pgd_offset() returns a (pgd_t *)
12403 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12404 */
12405 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12406 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12407 +
12408 +#ifdef CONFIG_PAX_PER_CPU_PGD
12409 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12410 +#endif
12411 +
12412 /*
12413 * a shortcut which implies the use of the kernel's pgd, instead
12414 * of a process's
12415 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
12416 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12417 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12418
12419 +#ifdef CONFIG_X86_32
12420 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12421 +#else
12422 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12423 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12424 +
12425 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12426 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12427 +#else
12428 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12429 +#endif
12430 +
12431 +#endif
12432 +
12433 #ifndef __ASSEMBLY__
12434
12435 extern int direct_gbpages;
12436 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12437 * dst and src can be on the same page, but the range must not overlap,
12438 * and must not cross a page boundary.
12439 */
12440 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12441 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12442 {
12443 - memcpy(dst, src, count * sizeof(pgd_t));
12444 + pax_open_kernel();
12445 + while (count--)
12446 + *dst++ = *src++;
12447 + pax_close_kernel();
12448 }
12449
12450 +#ifdef CONFIG_PAX_PER_CPU_PGD
12451 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12452 +#endif
12453 +
12454 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12455 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12456 +#else
12457 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12458 +#endif
12459
12460 #include <asm-generic/pgtable.h>
12461 #endif /* __ASSEMBLY__ */
12462 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12463 index 8faa215..a8a17ea 100644
12464 --- a/arch/x86/include/asm/pgtable_32.h
12465 +++ b/arch/x86/include/asm/pgtable_32.h
12466 @@ -25,9 +25,6 @@
12467 struct mm_struct;
12468 struct vm_area_struct;
12469
12470 -extern pgd_t swapper_pg_dir[1024];
12471 -extern pgd_t initial_page_table[1024];
12472 -
12473 static inline void pgtable_cache_init(void) { }
12474 static inline void check_pgt_cache(void) { }
12475 void paging_init(void);
12476 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12477 # include <asm/pgtable-2level.h>
12478 #endif
12479
12480 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12481 +extern pgd_t initial_page_table[PTRS_PER_PGD];
12482 +#ifdef CONFIG_X86_PAE
12483 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12484 +#endif
12485 +
12486 #if defined(CONFIG_HIGHPTE)
12487 #define pte_offset_map(dir, address) \
12488 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12489 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12490 /* Clear a kernel PTE and flush it from the TLB */
12491 #define kpte_clear_flush(ptep, vaddr) \
12492 do { \
12493 + pax_open_kernel(); \
12494 pte_clear(&init_mm, (vaddr), (ptep)); \
12495 + pax_close_kernel(); \
12496 __flush_tlb_one((vaddr)); \
12497 } while (0)
12498
12499 @@ -75,6 +80,9 @@ do { \
12500
12501 #endif /* !__ASSEMBLY__ */
12502
12503 +#define HAVE_ARCH_UNMAPPED_AREA
12504 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12505 +
12506 /*
12507 * kern_addr_valid() is (1) for FLATMEM and (0) for
12508 * SPARSEMEM and DISCONTIGMEM
12509 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12510 index ed5903b..c7fe163 100644
12511 --- a/arch/x86/include/asm/pgtable_32_types.h
12512 +++ b/arch/x86/include/asm/pgtable_32_types.h
12513 @@ -8,7 +8,7 @@
12514 */
12515 #ifdef CONFIG_X86_PAE
12516 # include <asm/pgtable-3level_types.h>
12517 -# define PMD_SIZE (1UL << PMD_SHIFT)
12518 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12519 # define PMD_MASK (~(PMD_SIZE - 1))
12520 #else
12521 # include <asm/pgtable-2level_types.h>
12522 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12523 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12524 #endif
12525
12526 +#ifdef CONFIG_PAX_KERNEXEC
12527 +#ifndef __ASSEMBLY__
12528 +extern unsigned char MODULES_EXEC_VADDR[];
12529 +extern unsigned char MODULES_EXEC_END[];
12530 +#endif
12531 +#include <asm/boot.h>
12532 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12533 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12534 +#else
12535 +#define ktla_ktva(addr) (addr)
12536 +#define ktva_ktla(addr) (addr)
12537 +#endif
12538 +
12539 #define MODULES_VADDR VMALLOC_START
12540 #define MODULES_END VMALLOC_END
12541 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12542 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12543 index 47356f9..deb94a2 100644
12544 --- a/arch/x86/include/asm/pgtable_64.h
12545 +++ b/arch/x86/include/asm/pgtable_64.h
12546 @@ -16,10 +16,14 @@
12547
12548 extern pud_t level3_kernel_pgt[512];
12549 extern pud_t level3_ident_pgt[512];
12550 +extern pud_t level3_vmalloc_start_pgt[512];
12551 +extern pud_t level3_vmalloc_end_pgt[512];
12552 +extern pud_t level3_vmemmap_pgt[512];
12553 +extern pud_t level2_vmemmap_pgt[512];
12554 extern pmd_t level2_kernel_pgt[512];
12555 extern pmd_t level2_fixmap_pgt[512];
12556 -extern pmd_t level2_ident_pgt[512];
12557 -extern pgd_t init_level4_pgt[];
12558 +extern pmd_t level2_ident_pgt[512*2];
12559 +extern pgd_t init_level4_pgt[512];
12560
12561 #define swapper_pg_dir init_level4_pgt
12562
12563 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12564
12565 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12566 {
12567 + pax_open_kernel();
12568 *pmdp = pmd;
12569 + pax_close_kernel();
12570 }
12571
12572 static inline void native_pmd_clear(pmd_t *pmd)
12573 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12574
12575 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12576 {
12577 + pax_open_kernel();
12578 *pudp = pud;
12579 + pax_close_kernel();
12580 }
12581
12582 static inline void native_pud_clear(pud_t *pud)
12583 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12584
12585 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12586 {
12587 + pax_open_kernel();
12588 + *pgdp = pgd;
12589 + pax_close_kernel();
12590 +}
12591 +
12592 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12593 +{
12594 *pgdp = pgd;
12595 }
12596
12597 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12598 index 766ea16..5b96cb3 100644
12599 --- a/arch/x86/include/asm/pgtable_64_types.h
12600 +++ b/arch/x86/include/asm/pgtable_64_types.h
12601 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12602 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12603 #define MODULES_END _AC(0xffffffffff000000, UL)
12604 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12605 +#define MODULES_EXEC_VADDR MODULES_VADDR
12606 +#define MODULES_EXEC_END MODULES_END
12607 +
12608 +#define ktla_ktva(addr) (addr)
12609 +#define ktva_ktla(addr) (addr)
12610
12611 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12612 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12613 index ec8a1fc..7ccb593 100644
12614 --- a/arch/x86/include/asm/pgtable_types.h
12615 +++ b/arch/x86/include/asm/pgtable_types.h
12616 @@ -16,13 +16,12 @@
12617 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
12618 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
12619 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
12620 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
12621 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
12622 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
12623 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
12624 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
12625 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
12626 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
12627 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
12628 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
12629 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
12630 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
12631
12632 /* If _PAGE_BIT_PRESENT is clear, we use these: */
12633 @@ -40,7 +39,6 @@
12634 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
12635 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
12636 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
12637 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
12638 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
12639 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
12640 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
12641 @@ -57,8 +55,10 @@
12642
12643 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
12644 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
12645 -#else
12646 +#elif defined(CONFIG_KMEMCHECK)
12647 #define _PAGE_NX (_AT(pteval_t, 0))
12648 +#else
12649 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
12650 #endif
12651
12652 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
12653 @@ -96,6 +96,9 @@
12654 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
12655 _PAGE_ACCESSED)
12656
12657 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
12658 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
12659 +
12660 #define __PAGE_KERNEL_EXEC \
12661 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
12662 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
12663 @@ -106,7 +109,7 @@
12664 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
12665 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
12666 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
12667 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
12668 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
12669 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
12670 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
12671 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
12672 @@ -168,8 +171,8 @@
12673 * bits are combined, this will alow user to access the high address mapped
12674 * VDSO in the presence of CONFIG_COMPAT_VDSO
12675 */
12676 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
12677 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
12678 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12679 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12680 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
12681 #endif
12682
12683 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
12684 {
12685 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
12686 }
12687 +#endif
12688
12689 +#if PAGETABLE_LEVELS == 3
12690 +#include <asm-generic/pgtable-nopud.h>
12691 +#endif
12692 +
12693 +#if PAGETABLE_LEVELS == 2
12694 +#include <asm-generic/pgtable-nopmd.h>
12695 +#endif
12696 +
12697 +#ifndef __ASSEMBLY__
12698 #if PAGETABLE_LEVELS > 3
12699 typedef struct { pudval_t pud; } pud_t;
12700
12701 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
12702 return pud.pud;
12703 }
12704 #else
12705 -#include <asm-generic/pgtable-nopud.h>
12706 -
12707 static inline pudval_t native_pud_val(pud_t pud)
12708 {
12709 return native_pgd_val(pud.pgd);
12710 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
12711 return pmd.pmd;
12712 }
12713 #else
12714 -#include <asm-generic/pgtable-nopmd.h>
12715 -
12716 static inline pmdval_t native_pmd_val(pmd_t pmd)
12717 {
12718 return native_pgd_val(pmd.pud.pgd);
12719 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
12720
12721 extern pteval_t __supported_pte_mask;
12722 extern void set_nx(void);
12723 -extern int nx_enabled;
12724
12725 #define pgprot_writecombine pgprot_writecombine
12726 extern pgprot_t pgprot_writecombine(pgprot_t prot);
12727 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
12728 index ad1fc85..0b15fe1 100644
12729 --- a/arch/x86/include/asm/processor.h
12730 +++ b/arch/x86/include/asm/processor.h
12731 @@ -289,7 +289,7 @@ struct tss_struct {
12732
12733 } ____cacheline_aligned;
12734
12735 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
12736 +extern struct tss_struct init_tss[NR_CPUS];
12737
12738 /*
12739 * Save the original ist values for checking stack pointers during debugging
12740 @@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
12741 */
12742 #define TASK_SIZE PAGE_OFFSET
12743 #define TASK_SIZE_MAX TASK_SIZE
12744 +
12745 +#ifdef CONFIG_PAX_SEGMEXEC
12746 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
12747 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
12748 +#else
12749 #define STACK_TOP TASK_SIZE
12750 -#define STACK_TOP_MAX STACK_TOP
12751 +#endif
12752 +
12753 +#define STACK_TOP_MAX TASK_SIZE
12754
12755 #define INIT_THREAD { \
12756 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
12757 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12758 .vm86_info = NULL, \
12759 .sysenter_cs = __KERNEL_CS, \
12760 .io_bitmap_ptr = NULL, \
12761 @@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
12762 */
12763 #define INIT_TSS { \
12764 .x86_tss = { \
12765 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
12766 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12767 .ss0 = __KERNEL_DS, \
12768 .ss1 = __KERNEL_CS, \
12769 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
12770 @@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
12771 extern unsigned long thread_saved_pc(struct task_struct *tsk);
12772
12773 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
12774 -#define KSTK_TOP(info) \
12775 -({ \
12776 - unsigned long *__ptr = (unsigned long *)(info); \
12777 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
12778 -})
12779 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
12780
12781 /*
12782 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
12783 @@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12784 #define task_pt_regs(task) \
12785 ({ \
12786 struct pt_regs *__regs__; \
12787 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
12788 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
12789 __regs__ - 1; \
12790 })
12791
12792 @@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12793 /*
12794 * User space process size. 47bits minus one guard page.
12795 */
12796 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
12797 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
12798
12799 /* This decides where the kernel will search for a free chunk of vm
12800 * space during mmap's.
12801 */
12802 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
12803 - 0xc0000000 : 0xFFFFe000)
12804 + 0xc0000000 : 0xFFFFf000)
12805
12806 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
12807 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
12808 @@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12809 #define STACK_TOP_MAX TASK_SIZE_MAX
12810
12811 #define INIT_THREAD { \
12812 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12813 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12814 }
12815
12816 #define INIT_TSS { \
12817 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12818 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12819 }
12820
12821 /*
12822 @@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
12823 */
12824 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
12825
12826 +#ifdef CONFIG_PAX_SEGMEXEC
12827 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
12828 +#endif
12829 +
12830 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
12831
12832 /* Get/set a process' ability to use the timestamp counter instruction */
12833 @@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
12834 #define cpu_has_amd_erratum(x) (false)
12835 #endif /* CONFIG_CPU_SUP_AMD */
12836
12837 -extern unsigned long arch_align_stack(unsigned long sp);
12838 +#define arch_align_stack(x) ((x) & ~0xfUL)
12839 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12840
12841 void default_idle(void);
12842 bool set_pm_idle_to_default(void);
12843
12844 -void stop_this_cpu(void *dummy);
12845 +void stop_this_cpu(void *dummy) __noreturn;
12846
12847 #endif /* _ASM_X86_PROCESSOR_H */
12848 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12849 index 19f16eb..b50624b 100644
12850 --- a/arch/x86/include/asm/ptrace.h
12851 +++ b/arch/x86/include/asm/ptrace.h
12852 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12853 }
12854
12855 /*
12856 - * user_mode_vm(regs) determines whether a register set came from user mode.
12857 + * user_mode(regs) determines whether a register set came from user mode.
12858 * This is true if V8086 mode was enabled OR if the register set was from
12859 * protected mode with RPL-3 CS value. This tricky test checks that with
12860 * one comparison. Many places in the kernel can bypass this full check
12861 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12862 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12863 + * be used.
12864 */
12865 -static inline int user_mode(struct pt_regs *regs)
12866 +static inline int user_mode_novm(struct pt_regs *regs)
12867 {
12868 #ifdef CONFIG_X86_32
12869 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12870 #else
12871 - return !!(regs->cs & 3);
12872 + return !!(regs->cs & SEGMENT_RPL_MASK);
12873 #endif
12874 }
12875
12876 -static inline int user_mode_vm(struct pt_regs *regs)
12877 +static inline int user_mode(struct pt_regs *regs)
12878 {
12879 #ifdef CONFIG_X86_32
12880 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12881 USER_RPL;
12882 #else
12883 - return user_mode(regs);
12884 + return user_mode_novm(regs);
12885 #endif
12886 }
12887
12888 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12889 #ifdef CONFIG_X86_64
12890 static inline bool user_64bit_mode(struct pt_regs *regs)
12891 {
12892 + unsigned long cs = regs->cs & 0xffff;
12893 #ifndef CONFIG_PARAVIRT
12894 /*
12895 * On non-paravirt systems, this is the only long mode CPL 3
12896 * selector. We do not allow long mode selectors in the LDT.
12897 */
12898 - return regs->cs == __USER_CS;
12899 + return cs == __USER_CS;
12900 #else
12901 /* Headers are too twisted for this to go in paravirt.h. */
12902 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12903 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12904 #endif
12905 }
12906 #endif
12907 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12908 index fe1ec5b..dc5c3fe 100644
12909 --- a/arch/x86/include/asm/realmode.h
12910 +++ b/arch/x86/include/asm/realmode.h
12911 @@ -22,16 +22,14 @@ struct real_mode_header {
12912 #endif
12913 /* APM/BIOS reboot */
12914 u32 machine_real_restart_asm;
12915 -#ifdef CONFIG_X86_64
12916 u32 machine_real_restart_seg;
12917 -#endif
12918 };
12919
12920 /* This must match data at trampoline_32/64.S */
12921 struct trampoline_header {
12922 #ifdef CONFIG_X86_32
12923 u32 start;
12924 - u16 gdt_pad;
12925 + u16 boot_cs;
12926 u16 gdt_limit;
12927 u32 gdt_base;
12928 #else
12929 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12930 index a82c4f1..f9c9696 100644
12931 --- a/arch/x86/include/asm/reboot.h
12932 +++ b/arch/x86/include/asm/reboot.h
12933 @@ -6,12 +6,12 @@
12934 struct pt_regs;
12935
12936 struct machine_ops {
12937 - void (*restart)(char *cmd);
12938 - void (*halt)(void);
12939 - void (*power_off)(void);
12940 + void (* __noreturn restart)(char *cmd);
12941 + void (* __noreturn halt)(void);
12942 + void (* __noreturn power_off)(void);
12943 void (*shutdown)(void);
12944 void (*crash_shutdown)(struct pt_regs *);
12945 - void (*emergency_restart)(void);
12946 + void (* __noreturn emergency_restart)(void);
12947 };
12948
12949 extern struct machine_ops machine_ops;
12950 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12951 index 2dbe4a7..ce1db00 100644
12952 --- a/arch/x86/include/asm/rwsem.h
12953 +++ b/arch/x86/include/asm/rwsem.h
12954 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12955 {
12956 asm volatile("# beginning down_read\n\t"
12957 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12958 +
12959 +#ifdef CONFIG_PAX_REFCOUNT
12960 + "jno 0f\n"
12961 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12962 + "int $4\n0:\n"
12963 + _ASM_EXTABLE(0b, 0b)
12964 +#endif
12965 +
12966 /* adds 0x00000001 */
12967 " jns 1f\n"
12968 " call call_rwsem_down_read_failed\n"
12969 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12970 "1:\n\t"
12971 " mov %1,%2\n\t"
12972 " add %3,%2\n\t"
12973 +
12974 +#ifdef CONFIG_PAX_REFCOUNT
12975 + "jno 0f\n"
12976 + "sub %3,%2\n"
12977 + "int $4\n0:\n"
12978 + _ASM_EXTABLE(0b, 0b)
12979 +#endif
12980 +
12981 " jle 2f\n\t"
12982 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12983 " jnz 1b\n\t"
12984 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12985 long tmp;
12986 asm volatile("# beginning down_write\n\t"
12987 LOCK_PREFIX " xadd %1,(%2)\n\t"
12988 +
12989 +#ifdef CONFIG_PAX_REFCOUNT
12990 + "jno 0f\n"
12991 + "mov %1,(%2)\n"
12992 + "int $4\n0:\n"
12993 + _ASM_EXTABLE(0b, 0b)
12994 +#endif
12995 +
12996 /* adds 0xffff0001, returns the old value */
12997 " test %1,%1\n\t"
12998 /* was the count 0 before? */
12999 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13000 long tmp;
13001 asm volatile("# beginning __up_read\n\t"
13002 LOCK_PREFIX " xadd %1,(%2)\n\t"
13003 +
13004 +#ifdef CONFIG_PAX_REFCOUNT
13005 + "jno 0f\n"
13006 + "mov %1,(%2)\n"
13007 + "int $4\n0:\n"
13008 + _ASM_EXTABLE(0b, 0b)
13009 +#endif
13010 +
13011 /* subtracts 1, returns the old value */
13012 " jns 1f\n\t"
13013 " call call_rwsem_wake\n" /* expects old value in %edx */
13014 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13015 long tmp;
13016 asm volatile("# beginning __up_write\n\t"
13017 LOCK_PREFIX " xadd %1,(%2)\n\t"
13018 +
13019 +#ifdef CONFIG_PAX_REFCOUNT
13020 + "jno 0f\n"
13021 + "mov %1,(%2)\n"
13022 + "int $4\n0:\n"
13023 + _ASM_EXTABLE(0b, 0b)
13024 +#endif
13025 +
13026 /* subtracts 0xffff0001, returns the old value */
13027 " jns 1f\n\t"
13028 " call call_rwsem_wake\n" /* expects old value in %edx */
13029 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13030 {
13031 asm volatile("# beginning __downgrade_write\n\t"
13032 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13033 +
13034 +#ifdef CONFIG_PAX_REFCOUNT
13035 + "jno 0f\n"
13036 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13037 + "int $4\n0:\n"
13038 + _ASM_EXTABLE(0b, 0b)
13039 +#endif
13040 +
13041 /*
13042 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13043 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13044 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13045 */
13046 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13047 {
13048 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13049 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13050 +
13051 +#ifdef CONFIG_PAX_REFCOUNT
13052 + "jno 0f\n"
13053 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
13054 + "int $4\n0:\n"
13055 + _ASM_EXTABLE(0b, 0b)
13056 +#endif
13057 +
13058 : "+m" (sem->count)
13059 : "er" (delta));
13060 }
13061 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13062 */
13063 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13064 {
13065 - return delta + xadd(&sem->count, delta);
13066 + return delta + xadd_check_overflow(&sem->count, delta);
13067 }
13068
13069 #endif /* __KERNEL__ */
13070 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13071 index c48a950..c6d7468 100644
13072 --- a/arch/x86/include/asm/segment.h
13073 +++ b/arch/x86/include/asm/segment.h
13074 @@ -64,10 +64,15 @@
13075 * 26 - ESPFIX small SS
13076 * 27 - per-cpu [ offset to per-cpu data area ]
13077 * 28 - stack_canary-20 [ for stack protector ]
13078 - * 29 - unused
13079 - * 30 - unused
13080 + * 29 - PCI BIOS CS
13081 + * 30 - PCI BIOS DS
13082 * 31 - TSS for double fault handler
13083 */
13084 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13085 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13086 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13087 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13088 +
13089 #define GDT_ENTRY_TLS_MIN 6
13090 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13091
13092 @@ -79,6 +84,8 @@
13093
13094 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13095
13096 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13097 +
13098 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13099
13100 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13101 @@ -104,6 +111,12 @@
13102 #define __KERNEL_STACK_CANARY 0
13103 #endif
13104
13105 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13106 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13107 +
13108 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13109 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13110 +
13111 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13112
13113 /*
13114 @@ -141,7 +154,7 @@
13115 */
13116
13117 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13118 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13119 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13120
13121
13122 #else
13123 @@ -165,6 +178,8 @@
13124 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13125 #define __USER32_DS __USER_DS
13126
13127 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13128 +
13129 #define GDT_ENTRY_TSS 8 /* needs two entries */
13130 #define GDT_ENTRY_LDT 10 /* needs two entries */
13131 #define GDT_ENTRY_TLS_MIN 12
13132 @@ -185,6 +200,7 @@
13133 #endif
13134
13135 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13136 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13137 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13138 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13139 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13140 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13141 {
13142 unsigned long __limit;
13143 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13144 - return __limit + 1;
13145 + return __limit;
13146 }
13147
13148 #endif /* !__ASSEMBLY__ */
13149 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13150 index 4f19a15..e04d86f 100644
13151 --- a/arch/x86/include/asm/smp.h
13152 +++ b/arch/x86/include/asm/smp.h
13153 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13154 /* cpus sharing the last level cache: */
13155 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13156 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13157 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13158 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13159
13160 static inline struct cpumask *cpu_sibling_mask(int cpu)
13161 {
13162 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13163 extern int safe_smp_processor_id(void);
13164
13165 #elif defined(CONFIG_X86_64_SMP)
13166 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13167 -
13168 -#define stack_smp_processor_id() \
13169 -({ \
13170 - struct thread_info *ti; \
13171 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13172 - ti->cpu; \
13173 -})
13174 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13175 +#define stack_smp_processor_id() raw_smp_processor_id()
13176 #define safe_smp_processor_id() smp_processor_id()
13177
13178 #endif
13179 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13180 index 33692ea..350a534 100644
13181 --- a/arch/x86/include/asm/spinlock.h
13182 +++ b/arch/x86/include/asm/spinlock.h
13183 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13184 static inline void arch_read_lock(arch_rwlock_t *rw)
13185 {
13186 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13187 +
13188 +#ifdef CONFIG_PAX_REFCOUNT
13189 + "jno 0f\n"
13190 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13191 + "int $4\n0:\n"
13192 + _ASM_EXTABLE(0b, 0b)
13193 +#endif
13194 +
13195 "jns 1f\n"
13196 "call __read_lock_failed\n\t"
13197 "1:\n"
13198 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13199 static inline void arch_write_lock(arch_rwlock_t *rw)
13200 {
13201 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13202 +
13203 +#ifdef CONFIG_PAX_REFCOUNT
13204 + "jno 0f\n"
13205 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13206 + "int $4\n0:\n"
13207 + _ASM_EXTABLE(0b, 0b)
13208 +#endif
13209 +
13210 "jz 1f\n"
13211 "call __write_lock_failed\n\t"
13212 "1:\n"
13213 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13214
13215 static inline void arch_read_unlock(arch_rwlock_t *rw)
13216 {
13217 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13218 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13219 +
13220 +#ifdef CONFIG_PAX_REFCOUNT
13221 + "jno 0f\n"
13222 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13223 + "int $4\n0:\n"
13224 + _ASM_EXTABLE(0b, 0b)
13225 +#endif
13226 +
13227 :"+m" (rw->lock) : : "memory");
13228 }
13229
13230 static inline void arch_write_unlock(arch_rwlock_t *rw)
13231 {
13232 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13233 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13234 +
13235 +#ifdef CONFIG_PAX_REFCOUNT
13236 + "jno 0f\n"
13237 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13238 + "int $4\n0:\n"
13239 + _ASM_EXTABLE(0b, 0b)
13240 +#endif
13241 +
13242 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13243 }
13244
13245 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13246 index 6a99859..03cb807 100644
13247 --- a/arch/x86/include/asm/stackprotector.h
13248 +++ b/arch/x86/include/asm/stackprotector.h
13249 @@ -47,7 +47,7 @@
13250 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13251 */
13252 #define GDT_STACK_CANARY_INIT \
13253 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13254 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13255
13256 /*
13257 * Initialize the stackprotector canary value.
13258 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13259
13260 static inline void load_stack_canary_segment(void)
13261 {
13262 -#ifdef CONFIG_X86_32
13263 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13264 asm volatile ("mov %0, %%gs" : : "r" (0));
13265 #endif
13266 }
13267 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13268 index 70bbe39..4ae2bd4 100644
13269 --- a/arch/x86/include/asm/stacktrace.h
13270 +++ b/arch/x86/include/asm/stacktrace.h
13271 @@ -11,28 +11,20 @@
13272
13273 extern int kstack_depth_to_print;
13274
13275 -struct thread_info;
13276 +struct task_struct;
13277 struct stacktrace_ops;
13278
13279 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13280 - unsigned long *stack,
13281 - unsigned long bp,
13282 - const struct stacktrace_ops *ops,
13283 - void *data,
13284 - unsigned long *end,
13285 - int *graph);
13286 +typedef unsigned long walk_stack_t(struct task_struct *task,
13287 + void *stack_start,
13288 + unsigned long *stack,
13289 + unsigned long bp,
13290 + const struct stacktrace_ops *ops,
13291 + void *data,
13292 + unsigned long *end,
13293 + int *graph);
13294
13295 -extern unsigned long
13296 -print_context_stack(struct thread_info *tinfo,
13297 - unsigned long *stack, unsigned long bp,
13298 - const struct stacktrace_ops *ops, void *data,
13299 - unsigned long *end, int *graph);
13300 -
13301 -extern unsigned long
13302 -print_context_stack_bp(struct thread_info *tinfo,
13303 - unsigned long *stack, unsigned long bp,
13304 - const struct stacktrace_ops *ops, void *data,
13305 - unsigned long *end, int *graph);
13306 +extern walk_stack_t print_context_stack;
13307 +extern walk_stack_t print_context_stack_bp;
13308
13309 /* Generic stack tracer with callbacks */
13310
13311 @@ -40,7 +32,7 @@ struct stacktrace_ops {
13312 void (*address)(void *data, unsigned long address, int reliable);
13313 /* On negative return stop dumping */
13314 int (*stack)(void *data, char *name);
13315 - walk_stack_t walk_stack;
13316 + walk_stack_t *walk_stack;
13317 };
13318
13319 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13320 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13321 index 4ec45b3..a4f0a8a 100644
13322 --- a/arch/x86/include/asm/switch_to.h
13323 +++ b/arch/x86/include/asm/switch_to.h
13324 @@ -108,7 +108,7 @@ do { \
13325 "call __switch_to\n\t" \
13326 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13327 __switch_canary \
13328 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
13329 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13330 "movq %%rax,%%rdi\n\t" \
13331 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13332 "jnz ret_from_fork\n\t" \
13333 @@ -119,7 +119,7 @@ do { \
13334 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13335 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13336 [_tif_fork] "i" (_TIF_FORK), \
13337 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
13338 + [thread_info] "m" (current_tinfo), \
13339 [current_task] "m" (current_task) \
13340 __switch_canary_iparam \
13341 : "memory", "cc" __EXTRA_CLOBBER)
13342 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13343 index 2d946e6..e453ec4 100644
13344 --- a/arch/x86/include/asm/thread_info.h
13345 +++ b/arch/x86/include/asm/thread_info.h
13346 @@ -10,6 +10,7 @@
13347 #include <linux/compiler.h>
13348 #include <asm/page.h>
13349 #include <asm/types.h>
13350 +#include <asm/percpu.h>
13351
13352 /*
13353 * low level task data that entry.S needs immediate access to
13354 @@ -24,7 +25,6 @@ struct exec_domain;
13355 #include <linux/atomic.h>
13356
13357 struct thread_info {
13358 - struct task_struct *task; /* main task structure */
13359 struct exec_domain *exec_domain; /* execution domain */
13360 __u32 flags; /* low level flags */
13361 __u32 status; /* thread synchronous flags */
13362 @@ -34,19 +34,13 @@ struct thread_info {
13363 mm_segment_t addr_limit;
13364 struct restart_block restart_block;
13365 void __user *sysenter_return;
13366 -#ifdef CONFIG_X86_32
13367 - unsigned long previous_esp; /* ESP of the previous stack in
13368 - case of nested (IRQ) stacks
13369 - */
13370 - __u8 supervisor_stack[0];
13371 -#endif
13372 + unsigned long lowest_stack;
13373 unsigned int sig_on_uaccess_error:1;
13374 unsigned int uaccess_err:1; /* uaccess failed */
13375 };
13376
13377 -#define INIT_THREAD_INFO(tsk) \
13378 +#define INIT_THREAD_INFO \
13379 { \
13380 - .task = &tsk, \
13381 .exec_domain = &default_exec_domain, \
13382 .flags = 0, \
13383 .cpu = 0, \
13384 @@ -57,7 +51,7 @@ struct thread_info {
13385 }, \
13386 }
13387
13388 -#define init_thread_info (init_thread_union.thread_info)
13389 +#define init_thread_info (init_thread_union.stack)
13390 #define init_stack (init_thread_union.stack)
13391
13392 #else /* !__ASSEMBLY__ */
13393 @@ -98,6 +92,7 @@ struct thread_info {
13394 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13395 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13396 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13397 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13398
13399 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13400 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13401 @@ -122,17 +117,18 @@ struct thread_info {
13402 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13403 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13404 #define _TIF_X32 (1 << TIF_X32)
13405 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13406
13407 /* work to do in syscall_trace_enter() */
13408 #define _TIF_WORK_SYSCALL_ENTRY \
13409 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13410 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13411 - _TIF_NOHZ)
13412 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13413
13414 /* work to do in syscall_trace_leave() */
13415 #define _TIF_WORK_SYSCALL_EXIT \
13416 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13417 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13418 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13419
13420 /* work to do on interrupt/exception return */
13421 #define _TIF_WORK_MASK \
13422 @@ -143,7 +139,7 @@ struct thread_info {
13423 /* work to do on any return to user space */
13424 #define _TIF_ALLWORK_MASK \
13425 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13426 - _TIF_NOHZ)
13427 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13428
13429 /* Only used for 64 bit */
13430 #define _TIF_DO_NOTIFY_MASK \
13431 @@ -159,45 +155,40 @@ struct thread_info {
13432
13433 #define PREEMPT_ACTIVE 0x10000000
13434
13435 -#ifdef CONFIG_X86_32
13436 -
13437 -#define STACK_WARN (THREAD_SIZE/8)
13438 -/*
13439 - * macros/functions for gaining access to the thread information structure
13440 - *
13441 - * preempt_count needs to be 1 initially, until the scheduler is functional.
13442 - */
13443 -#ifndef __ASSEMBLY__
13444 -
13445 -
13446 -/* how to get the current stack pointer from C */
13447 -register unsigned long current_stack_pointer asm("esp") __used;
13448 -
13449 -/* how to get the thread information struct from C */
13450 -static inline struct thread_info *current_thread_info(void)
13451 -{
13452 - return (struct thread_info *)
13453 - (current_stack_pointer & ~(THREAD_SIZE - 1));
13454 -}
13455 -
13456 -#else /* !__ASSEMBLY__ */
13457 -
13458 +#ifdef __ASSEMBLY__
13459 /* how to get the thread information struct from ASM */
13460 #define GET_THREAD_INFO(reg) \
13461 - movl $-THREAD_SIZE, reg; \
13462 - andl %esp, reg
13463 + mov PER_CPU_VAR(current_tinfo), reg
13464
13465 /* use this one if reg already contains %esp */
13466 -#define GET_THREAD_INFO_WITH_ESP(reg) \
13467 - andl $-THREAD_SIZE, reg
13468 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13469 +#else
13470 +/* how to get the thread information struct from C */
13471 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13472 +
13473 +static __always_inline struct thread_info *current_thread_info(void)
13474 +{
13475 + return this_cpu_read_stable(current_tinfo);
13476 +}
13477 +#endif
13478 +
13479 +#ifdef CONFIG_X86_32
13480 +
13481 +#define STACK_WARN (THREAD_SIZE/8)
13482 +/*
13483 + * macros/functions for gaining access to the thread information structure
13484 + *
13485 + * preempt_count needs to be 1 initially, until the scheduler is functional.
13486 + */
13487 +#ifndef __ASSEMBLY__
13488 +
13489 +/* how to get the current stack pointer from C */
13490 +register unsigned long current_stack_pointer asm("esp") __used;
13491
13492 #endif
13493
13494 #else /* X86_32 */
13495
13496 -#include <asm/percpu.h>
13497 -#define KERNEL_STACK_OFFSET (5*8)
13498 -
13499 /*
13500 * macros/functions for gaining access to the thread information structure
13501 * preempt_count needs to be 1 initially, until the scheduler is functional.
13502 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13503 #ifndef __ASSEMBLY__
13504 DECLARE_PER_CPU(unsigned long, kernel_stack);
13505
13506 -static inline struct thread_info *current_thread_info(void)
13507 -{
13508 - struct thread_info *ti;
13509 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
13510 - KERNEL_STACK_OFFSET - THREAD_SIZE);
13511 - return ti;
13512 -}
13513 -
13514 -#else /* !__ASSEMBLY__ */
13515 -
13516 -/* how to get the thread information struct from ASM */
13517 -#define GET_THREAD_INFO(reg) \
13518 - movq PER_CPU_VAR(kernel_stack),reg ; \
13519 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13520 -
13521 -/*
13522 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13523 - * a certain register (to be used in assembler memory operands).
13524 - */
13525 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13526 -
13527 +/* how to get the current stack pointer from C */
13528 +register unsigned long current_stack_pointer asm("rsp") __used;
13529 #endif
13530
13531 #endif /* !X86_32 */
13532 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13533 extern void arch_task_cache_init(void);
13534 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13535 extern void arch_release_task_struct(struct task_struct *tsk);
13536 +
13537 +#define __HAVE_THREAD_FUNCTIONS
13538 +#define task_thread_info(task) (&(task)->tinfo)
13539 +#define task_stack_page(task) ((task)->stack)
13540 +#define setup_thread_stack(p, org) do {} while (0)
13541 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13542 +
13543 #endif
13544 #endif /* _ASM_X86_THREAD_INFO_H */
13545 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13546 index 7ccf8d1..7cdca12 100644
13547 --- a/arch/x86/include/asm/uaccess.h
13548 +++ b/arch/x86/include/asm/uaccess.h
13549 @@ -7,6 +7,7 @@
13550 #include <linux/compiler.h>
13551 #include <linux/thread_info.h>
13552 #include <linux/string.h>
13553 +#include <linux/sched.h>
13554 #include <asm/asm.h>
13555 #include <asm/page.h>
13556 #include <asm/smap.h>
13557 @@ -14,6 +15,8 @@
13558 #define VERIFY_READ 0
13559 #define VERIFY_WRITE 1
13560
13561 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
13562 +
13563 /*
13564 * The fs value determines whether argument validity checking should be
13565 * performed or not. If get_fs() == USER_DS, checking is performed, with
13566 @@ -29,7 +32,12 @@
13567
13568 #define get_ds() (KERNEL_DS)
13569 #define get_fs() (current_thread_info()->addr_limit)
13570 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13571 +void __set_fs(mm_segment_t x);
13572 +void set_fs(mm_segment_t x);
13573 +#else
13574 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13575 +#endif
13576
13577 #define segment_eq(a, b) ((a).seg == (b).seg)
13578
13579 @@ -77,8 +85,33 @@
13580 * checks that the pointer is in the user space range - after calling
13581 * this function, memory access functions may still return -EFAULT.
13582 */
13583 -#define access_ok(type, addr, size) \
13584 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13585 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13586 +#define access_ok(type, addr, size) \
13587 +({ \
13588 + long __size = size; \
13589 + unsigned long __addr = (unsigned long)addr; \
13590 + unsigned long __addr_ao = __addr & PAGE_MASK; \
13591 + unsigned long __end_ao = __addr + __size - 1; \
13592 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13593 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13594 + while(__addr_ao <= __end_ao) { \
13595 + char __c_ao; \
13596 + __addr_ao += PAGE_SIZE; \
13597 + if (__size > PAGE_SIZE) \
13598 + cond_resched(); \
13599 + if (__get_user(__c_ao, (char __user *)__addr)) \
13600 + break; \
13601 + if (type != VERIFY_WRITE) { \
13602 + __addr = __addr_ao; \
13603 + continue; \
13604 + } \
13605 + if (__put_user(__c_ao, (char __user *)__addr)) \
13606 + break; \
13607 + __addr = __addr_ao; \
13608 + } \
13609 + } \
13610 + __ret_ao; \
13611 +})
13612
13613 /*
13614 * The exception table consists of pairs of addresses relative to the
13615 @@ -189,13 +222,21 @@ extern int __get_user_bad(void);
13616 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
13617 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
13618
13619 -
13620 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13621 +#define __copyuser_seg "gs;"
13622 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
13623 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
13624 +#else
13625 +#define __copyuser_seg
13626 +#define __COPYUSER_SET_ES
13627 +#define __COPYUSER_RESTORE_ES
13628 +#endif
13629
13630 #ifdef CONFIG_X86_32
13631 #define __put_user_asm_u64(x, addr, err, errret) \
13632 asm volatile(ASM_STAC "\n" \
13633 - "1: movl %%eax,0(%2)\n" \
13634 - "2: movl %%edx,4(%2)\n" \
13635 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
13636 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
13637 "3: " ASM_CLAC "\n" \
13638 ".section .fixup,\"ax\"\n" \
13639 "4: movl %3,%0\n" \
13640 @@ -208,8 +249,8 @@ extern int __get_user_bad(void);
13641
13642 #define __put_user_asm_ex_u64(x, addr) \
13643 asm volatile(ASM_STAC "\n" \
13644 - "1: movl %%eax,0(%1)\n" \
13645 - "2: movl %%edx,4(%1)\n" \
13646 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
13647 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
13648 "3: " ASM_CLAC "\n" \
13649 _ASM_EXTABLE_EX(1b, 2b) \
13650 _ASM_EXTABLE_EX(2b, 3b) \
13651 @@ -261,7 +302,7 @@ extern void __put_user_8(void);
13652 __typeof__(*(ptr)) __pu_val; \
13653 __chk_user_ptr(ptr); \
13654 might_fault(); \
13655 - __pu_val = x; \
13656 + __pu_val = (x); \
13657 switch (sizeof(*(ptr))) { \
13658 case 1: \
13659 __put_user_x(1, __pu_val, ptr, __ret_pu); \
13660 @@ -383,7 +424,7 @@ do { \
13661
13662 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13663 asm volatile(ASM_STAC "\n" \
13664 - "1: mov"itype" %2,%"rtype"1\n" \
13665 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
13666 "2: " ASM_CLAC "\n" \
13667 ".section .fixup,\"ax\"\n" \
13668 "3: mov %3,%0\n" \
13669 @@ -391,7 +432,7 @@ do { \
13670 " jmp 2b\n" \
13671 ".previous\n" \
13672 _ASM_EXTABLE(1b, 3b) \
13673 - : "=r" (err), ltype(x) \
13674 + : "=r" (err), ltype (x) \
13675 : "m" (__m(addr)), "i" (errret), "0" (err))
13676
13677 #define __get_user_size_ex(x, ptr, size) \
13678 @@ -416,7 +457,7 @@ do { \
13679 } while (0)
13680
13681 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
13682 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
13683 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
13684 "2:\n" \
13685 _ASM_EXTABLE_EX(1b, 2b) \
13686 : ltype(x) : "m" (__m(addr)))
13687 @@ -433,13 +474,24 @@ do { \
13688 int __gu_err; \
13689 unsigned long __gu_val; \
13690 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
13691 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
13692 + (x) = (__typeof__(*(ptr)))__gu_val; \
13693 __gu_err; \
13694 })
13695
13696 /* FIXME: this hack is definitely wrong -AK */
13697 struct __large_struct { unsigned long buf[100]; };
13698 -#define __m(x) (*(struct __large_struct __user *)(x))
13699 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13700 +#define ____m(x) \
13701 +({ \
13702 + unsigned long ____x = (unsigned long)(x); \
13703 + if (____x < PAX_USER_SHADOW_BASE) \
13704 + ____x += PAX_USER_SHADOW_BASE; \
13705 + (void __user *)____x; \
13706 +})
13707 +#else
13708 +#define ____m(x) (x)
13709 +#endif
13710 +#define __m(x) (*(struct __large_struct __user *)____m(x))
13711
13712 /*
13713 * Tell gcc we read from memory instead of writing: this is because
13714 @@ -448,7 +500,7 @@ struct __large_struct { unsigned long buf[100]; };
13715 */
13716 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13717 asm volatile(ASM_STAC "\n" \
13718 - "1: mov"itype" %"rtype"1,%2\n" \
13719 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
13720 "2: " ASM_CLAC "\n" \
13721 ".section .fixup,\"ax\"\n" \
13722 "3: mov %3,%0\n" \
13723 @@ -456,10 +508,10 @@ struct __large_struct { unsigned long buf[100]; };
13724 ".previous\n" \
13725 _ASM_EXTABLE(1b, 3b) \
13726 : "=r"(err) \
13727 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
13728 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
13729
13730 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
13731 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
13732 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
13733 "2:\n" \
13734 _ASM_EXTABLE_EX(1b, 2b) \
13735 : : ltype(x), "m" (__m(addr)))
13736 @@ -498,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
13737 * On error, the variable @x is set to zero.
13738 */
13739
13740 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13741 +#define __get_user(x, ptr) get_user((x), (ptr))
13742 +#else
13743 #define __get_user(x, ptr) \
13744 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
13745 +#endif
13746
13747 /**
13748 * __put_user: - Write a simple value into user space, with less checking.
13749 @@ -521,8 +577,12 @@ struct __large_struct { unsigned long buf[100]; };
13750 * Returns zero on success, or -EFAULT on error.
13751 */
13752
13753 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13754 +#define __put_user(x, ptr) put_user((x), (ptr))
13755 +#else
13756 #define __put_user(x, ptr) \
13757 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
13758 +#endif
13759
13760 #define __get_user_unaligned __get_user
13761 #define __put_user_unaligned __put_user
13762 @@ -540,7 +600,7 @@ struct __large_struct { unsigned long buf[100]; };
13763 #define get_user_ex(x, ptr) do { \
13764 unsigned long __gue_val; \
13765 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
13766 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
13767 + (x) = (__typeof__(*(ptr)))__gue_val; \
13768 } while (0)
13769
13770 #ifdef CONFIG_X86_WP_WORKS_OK
13771 @@ -574,8 +634,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
13772 extern __must_check long strlen_user(const char __user *str);
13773 extern __must_check long strnlen_user(const char __user *str, long n);
13774
13775 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13776 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13777 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13778 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13779
13780 /*
13781 * movsl can be slow when source and dest are not both 8-byte aligned
13782 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
13783 index 7f760a9..00f93c0 100644
13784 --- a/arch/x86/include/asm/uaccess_32.h
13785 +++ b/arch/x86/include/asm/uaccess_32.h
13786 @@ -11,15 +11,15 @@
13787 #include <asm/page.h>
13788
13789 unsigned long __must_check __copy_to_user_ll
13790 - (void __user *to, const void *from, unsigned long n);
13791 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
13792 unsigned long __must_check __copy_from_user_ll
13793 - (void *to, const void __user *from, unsigned long n);
13794 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13795 unsigned long __must_check __copy_from_user_ll_nozero
13796 - (void *to, const void __user *from, unsigned long n);
13797 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13798 unsigned long __must_check __copy_from_user_ll_nocache
13799 - (void *to, const void __user *from, unsigned long n);
13800 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13801 unsigned long __must_check __copy_from_user_ll_nocache_nozero
13802 - (void *to, const void __user *from, unsigned long n);
13803 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13804
13805 /**
13806 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
13807 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
13808 static __always_inline unsigned long __must_check
13809 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13810 {
13811 + if ((long)n < 0)
13812 + return n;
13813 +
13814 if (__builtin_constant_p(n)) {
13815 unsigned long ret;
13816
13817 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13818 return ret;
13819 }
13820 }
13821 + if (!__builtin_constant_p(n))
13822 + check_object_size(from, n, true);
13823 return __copy_to_user_ll(to, from, n);
13824 }
13825
13826 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
13827 __copy_to_user(void __user *to, const void *from, unsigned long n)
13828 {
13829 might_fault();
13830 +
13831 return __copy_to_user_inatomic(to, from, n);
13832 }
13833
13834 static __always_inline unsigned long
13835 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13836 {
13837 + if ((long)n < 0)
13838 + return n;
13839 +
13840 /* Avoid zeroing the tail if the copy fails..
13841 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13842 * but as the zeroing behaviour is only significant when n is not
13843 @@ -137,6 +146,10 @@ static __always_inline unsigned long
13844 __copy_from_user(void *to, const void __user *from, unsigned long n)
13845 {
13846 might_fault();
13847 +
13848 + if ((long)n < 0)
13849 + return n;
13850 +
13851 if (__builtin_constant_p(n)) {
13852 unsigned long ret;
13853
13854 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13855 return ret;
13856 }
13857 }
13858 + if (!__builtin_constant_p(n))
13859 + check_object_size(to, n, false);
13860 return __copy_from_user_ll(to, from, n);
13861 }
13862
13863 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13864 const void __user *from, unsigned long n)
13865 {
13866 might_fault();
13867 +
13868 + if ((long)n < 0)
13869 + return n;
13870 +
13871 if (__builtin_constant_p(n)) {
13872 unsigned long ret;
13873
13874 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13875 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13876 unsigned long n)
13877 {
13878 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13879 + if ((long)n < 0)
13880 + return n;
13881 +
13882 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13883 }
13884
13885 -unsigned long __must_check copy_to_user(void __user *to,
13886 - const void *from, unsigned long n);
13887 -unsigned long __must_check _copy_from_user(void *to,
13888 - const void __user *from,
13889 - unsigned long n);
13890 -
13891 +extern void copy_to_user_overflow(void)
13892 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13893 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13894 +#else
13895 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13896 +#endif
13897 +;
13898
13899 extern void copy_from_user_overflow(void)
13900 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13901 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
13902 #endif
13903 ;
13904
13905 -static inline unsigned long __must_check copy_from_user(void *to,
13906 - const void __user *from,
13907 - unsigned long n)
13908 +/**
13909 + * copy_to_user: - Copy a block of data into user space.
13910 + * @to: Destination address, in user space.
13911 + * @from: Source address, in kernel space.
13912 + * @n: Number of bytes to copy.
13913 + *
13914 + * Context: User context only. This function may sleep.
13915 + *
13916 + * Copy data from kernel space to user space.
13917 + *
13918 + * Returns number of bytes that could not be copied.
13919 + * On success, this will be zero.
13920 + */
13921 +static inline unsigned long __must_check
13922 +copy_to_user(void __user *to, const void *from, unsigned long n)
13923 {
13924 - int sz = __compiletime_object_size(to);
13925 + size_t sz = __compiletime_object_size(from);
13926
13927 - if (likely(sz == -1 || sz >= n))
13928 - n = _copy_from_user(to, from, n);
13929 - else
13930 + if (unlikely(sz != (size_t)-1 && sz < n))
13931 + copy_to_user_overflow();
13932 + else if (access_ok(VERIFY_WRITE, to, n))
13933 + n = __copy_to_user(to, from, n);
13934 + return n;
13935 +}
13936 +
13937 +/**
13938 + * copy_from_user: - Copy a block of data from user space.
13939 + * @to: Destination address, in kernel space.
13940 + * @from: Source address, in user space.
13941 + * @n: Number of bytes to copy.
13942 + *
13943 + * Context: User context only. This function may sleep.
13944 + *
13945 + * Copy data from user space to kernel space.
13946 + *
13947 + * Returns number of bytes that could not be copied.
13948 + * On success, this will be zero.
13949 + *
13950 + * If some data could not be copied, this function will pad the copied
13951 + * data to the requested size using zero bytes.
13952 + */
13953 +static inline unsigned long __must_check
13954 +copy_from_user(void *to, const void __user *from, unsigned long n)
13955 +{
13956 + size_t sz = __compiletime_object_size(to);
13957 +
13958 + if (unlikely(sz != (size_t)-1 && sz < n))
13959 copy_from_user_overflow();
13960 -
13961 + else if (access_ok(VERIFY_READ, from, n))
13962 + n = __copy_from_user(to, from, n);
13963 + else if ((long)n > 0) {
13964 + if (!__builtin_constant_p(n))
13965 + check_object_size(to, n, false);
13966 + memset(to, 0, n);
13967 + }
13968 return n;
13969 }
13970
13971 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13972 index 142810c..4389299 100644
13973 --- a/arch/x86/include/asm/uaccess_64.h
13974 +++ b/arch/x86/include/asm/uaccess_64.h
13975 @@ -10,6 +10,9 @@
13976 #include <asm/alternative.h>
13977 #include <asm/cpufeature.h>
13978 #include <asm/page.h>
13979 +#include <asm/pgtable.h>
13980 +
13981 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13982
13983 /*
13984 * Copy To/From Userspace
13985 @@ -17,13 +20,13 @@
13986
13987 /* Handles exceptions in both to and from, but doesn't do access_ok */
13988 __must_check unsigned long
13989 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13990 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13991 __must_check unsigned long
13992 -copy_user_generic_string(void *to, const void *from, unsigned len);
13993 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13994 __must_check unsigned long
13995 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13996 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13997
13998 -static __always_inline __must_check unsigned long
13999 +static __always_inline __must_check __size_overflow(3) unsigned long
14000 copy_user_generic(void *to, const void *from, unsigned len)
14001 {
14002 unsigned ret;
14003 @@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
14004 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14005 "=d" (len)),
14006 "1" (to), "2" (from), "3" (len)
14007 - : "memory", "rcx", "r8", "r9", "r10", "r11");
14008 + : "memory", "rcx", "r8", "r9", "r11");
14009 return ret;
14010 }
14011
14012 +static __always_inline __must_check unsigned long
14013 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14014 +static __always_inline __must_check unsigned long
14015 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14016 __must_check unsigned long
14017 -_copy_to_user(void __user *to, const void *from, unsigned len);
14018 -__must_check unsigned long
14019 -_copy_from_user(void *to, const void __user *from, unsigned len);
14020 -__must_check unsigned long
14021 -copy_in_user(void __user *to, const void __user *from, unsigned len);
14022 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14023 +
14024 +extern void copy_to_user_overflow(void)
14025 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14026 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14027 +#else
14028 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14029 +#endif
14030 +;
14031 +
14032 +extern void copy_from_user_overflow(void)
14033 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14034 + __compiletime_error("copy_from_user() buffer size is not provably correct")
14035 +#else
14036 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
14037 +#endif
14038 +;
14039
14040 static inline unsigned long __must_check copy_from_user(void *to,
14041 const void __user *from,
14042 unsigned long n)
14043 {
14044 - int sz = __compiletime_object_size(to);
14045 -
14046 might_fault();
14047 - if (likely(sz == -1 || sz >= n))
14048 - n = _copy_from_user(to, from, n);
14049 -#ifdef CONFIG_DEBUG_VM
14050 - else
14051 - WARN(1, "Buffer overflow detected!\n");
14052 -#endif
14053 +
14054 + if (access_ok(VERIFY_READ, from, n))
14055 + n = __copy_from_user(to, from, n);
14056 + else if (n < INT_MAX) {
14057 + if (!__builtin_constant_p(n))
14058 + check_object_size(to, n, false);
14059 + memset(to, 0, n);
14060 + }
14061 return n;
14062 }
14063
14064 static __always_inline __must_check
14065 -int copy_to_user(void __user *dst, const void *src, unsigned size)
14066 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
14067 {
14068 might_fault();
14069
14070 - return _copy_to_user(dst, src, size);
14071 + if (access_ok(VERIFY_WRITE, dst, size))
14072 + size = __copy_to_user(dst, src, size);
14073 + return size;
14074 }
14075
14076 static __always_inline __must_check
14077 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
14078 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14079 {
14080 - int ret = 0;
14081 + size_t sz = __compiletime_object_size(dst);
14082 + unsigned ret = 0;
14083
14084 might_fault();
14085 - if (!__builtin_constant_p(size))
14086 - return copy_user_generic(dst, (__force void *)src, size);
14087 +
14088 + if (size > INT_MAX)
14089 + return size;
14090 +
14091 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14092 + if (!__access_ok(VERIFY_READ, src, size))
14093 + return size;
14094 +#endif
14095 +
14096 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14097 + copy_from_user_overflow();
14098 + return size;
14099 + }
14100 +
14101 + if (!__builtin_constant_p(size)) {
14102 + check_object_size(dst, size, false);
14103 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14104 + }
14105 switch (size) {
14106 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14107 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14108 ret, "b", "b", "=q", 1);
14109 return ret;
14110 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14111 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14112 ret, "w", "w", "=r", 2);
14113 return ret;
14114 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14115 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14116 ret, "l", "k", "=r", 4);
14117 return ret;
14118 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14119 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14120 ret, "q", "", "=r", 8);
14121 return ret;
14122 case 10:
14123 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14124 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14125 ret, "q", "", "=r", 10);
14126 if (unlikely(ret))
14127 return ret;
14128 __get_user_asm(*(u16 *)(8 + (char *)dst),
14129 - (u16 __user *)(8 + (char __user *)src),
14130 + (const u16 __user *)(8 + (const char __user *)src),
14131 ret, "w", "w", "=r", 2);
14132 return ret;
14133 case 16:
14134 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14135 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14136 ret, "q", "", "=r", 16);
14137 if (unlikely(ret))
14138 return ret;
14139 __get_user_asm(*(u64 *)(8 + (char *)dst),
14140 - (u64 __user *)(8 + (char __user *)src),
14141 + (const u64 __user *)(8 + (const char __user *)src),
14142 ret, "q", "", "=r", 8);
14143 return ret;
14144 default:
14145 - return copy_user_generic(dst, (__force void *)src, size);
14146 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14147 }
14148 }
14149
14150 static __always_inline __must_check
14151 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
14152 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14153 {
14154 - int ret = 0;
14155 + size_t sz = __compiletime_object_size(src);
14156 + unsigned ret = 0;
14157
14158 might_fault();
14159 - if (!__builtin_constant_p(size))
14160 - return copy_user_generic((__force void *)dst, src, size);
14161 +
14162 + if (size > INT_MAX)
14163 + return size;
14164 +
14165 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14166 + if (!__access_ok(VERIFY_WRITE, dst, size))
14167 + return size;
14168 +#endif
14169 +
14170 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14171 + copy_to_user_overflow();
14172 + return size;
14173 + }
14174 +
14175 + if (!__builtin_constant_p(size)) {
14176 + check_object_size(src, size, true);
14177 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14178 + }
14179 switch (size) {
14180 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14181 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14182 ret, "b", "b", "iq", 1);
14183 return ret;
14184 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14185 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14186 ret, "w", "w", "ir", 2);
14187 return ret;
14188 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14189 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14190 ret, "l", "k", "ir", 4);
14191 return ret;
14192 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14193 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14194 ret, "q", "", "er", 8);
14195 return ret;
14196 case 10:
14197 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14198 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14199 ret, "q", "", "er", 10);
14200 if (unlikely(ret))
14201 return ret;
14202 asm("":::"memory");
14203 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14204 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14205 ret, "w", "w", "ir", 2);
14206 return ret;
14207 case 16:
14208 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14209 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14210 ret, "q", "", "er", 16);
14211 if (unlikely(ret))
14212 return ret;
14213 asm("":::"memory");
14214 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14215 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14216 ret, "q", "", "er", 8);
14217 return ret;
14218 default:
14219 - return copy_user_generic((__force void *)dst, src, size);
14220 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14221 }
14222 }
14223
14224 static __always_inline __must_check
14225 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14226 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14227 {
14228 - int ret = 0;
14229 + unsigned ret = 0;
14230
14231 might_fault();
14232 +
14233 + if (size > INT_MAX)
14234 + return size;
14235 +
14236 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14237 + if (!__access_ok(VERIFY_READ, src, size))
14238 + return size;
14239 + if (!__access_ok(VERIFY_WRITE, dst, size))
14240 + return size;
14241 +#endif
14242 +
14243 if (!__builtin_constant_p(size))
14244 - return copy_user_generic((__force void *)dst,
14245 - (__force void *)src, size);
14246 + return copy_user_generic((__force_kernel void *)____m(dst),
14247 + (__force_kernel const void *)____m(src), size);
14248 switch (size) {
14249 case 1: {
14250 u8 tmp;
14251 - __get_user_asm(tmp, (u8 __user *)src,
14252 + __get_user_asm(tmp, (const u8 __user *)src,
14253 ret, "b", "b", "=q", 1);
14254 if (likely(!ret))
14255 __put_user_asm(tmp, (u8 __user *)dst,
14256 @@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14257 }
14258 case 2: {
14259 u16 tmp;
14260 - __get_user_asm(tmp, (u16 __user *)src,
14261 + __get_user_asm(tmp, (const u16 __user *)src,
14262 ret, "w", "w", "=r", 2);
14263 if (likely(!ret))
14264 __put_user_asm(tmp, (u16 __user *)dst,
14265 @@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14266
14267 case 4: {
14268 u32 tmp;
14269 - __get_user_asm(tmp, (u32 __user *)src,
14270 + __get_user_asm(tmp, (const u32 __user *)src,
14271 ret, "l", "k", "=r", 4);
14272 if (likely(!ret))
14273 __put_user_asm(tmp, (u32 __user *)dst,
14274 @@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14275 }
14276 case 8: {
14277 u64 tmp;
14278 - __get_user_asm(tmp, (u64 __user *)src,
14279 + __get_user_asm(tmp, (const u64 __user *)src,
14280 ret, "q", "", "=r", 8);
14281 if (likely(!ret))
14282 __put_user_asm(tmp, (u64 __user *)dst,
14283 @@ -212,41 +278,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14284 return ret;
14285 }
14286 default:
14287 - return copy_user_generic((__force void *)dst,
14288 - (__force void *)src, size);
14289 + return copy_user_generic((__force_kernel void *)____m(dst),
14290 + (__force_kernel const void *)____m(src), size);
14291 }
14292 }
14293
14294 static __must_check __always_inline int
14295 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14296 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14297 {
14298 - return copy_user_generic(dst, (__force const void *)src, size);
14299 + if (size > INT_MAX)
14300 + return size;
14301 +
14302 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14303 + if (!__access_ok(VERIFY_READ, src, size))
14304 + return size;
14305 +#endif
14306 +
14307 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14308 }
14309
14310 -static __must_check __always_inline int
14311 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14312 +static __must_check __always_inline unsigned long
14313 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14314 {
14315 - return copy_user_generic((__force void *)dst, src, size);
14316 + if (size > INT_MAX)
14317 + return size;
14318 +
14319 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14320 + if (!__access_ok(VERIFY_WRITE, dst, size))
14321 + return size;
14322 +#endif
14323 +
14324 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14325 }
14326
14327 -extern long __copy_user_nocache(void *dst, const void __user *src,
14328 - unsigned size, int zerorest);
14329 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14330 + unsigned long size, int zerorest) __size_overflow(3);
14331
14332 -static inline int
14333 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14334 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14335 {
14336 might_sleep();
14337 +
14338 + if (size > INT_MAX)
14339 + return size;
14340 +
14341 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14342 + if (!__access_ok(VERIFY_READ, src, size))
14343 + return size;
14344 +#endif
14345 +
14346 return __copy_user_nocache(dst, src, size, 1);
14347 }
14348
14349 -static inline int
14350 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14351 - unsigned size)
14352 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14353 + unsigned long size)
14354 {
14355 + if (size > INT_MAX)
14356 + return size;
14357 +
14358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14359 + if (!__access_ok(VERIFY_READ, src, size))
14360 + return size;
14361 +#endif
14362 +
14363 return __copy_user_nocache(dst, src, size, 0);
14364 }
14365
14366 -unsigned long
14367 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14368 +extern unsigned long
14369 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14370
14371 #endif /* _ASM_X86_UACCESS_64_H */
14372 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14373 index 5b238981..77fdd78 100644
14374 --- a/arch/x86/include/asm/word-at-a-time.h
14375 +++ b/arch/x86/include/asm/word-at-a-time.h
14376 @@ -11,7 +11,7 @@
14377 * and shift, for example.
14378 */
14379 struct word_at_a_time {
14380 - const unsigned long one_bits, high_bits;
14381 + unsigned long one_bits, high_bits;
14382 };
14383
14384 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14385 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14386 index 0415cda..b43d877 100644
14387 --- a/arch/x86/include/asm/xsave.h
14388 +++ b/arch/x86/include/asm/xsave.h
14389 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14390 return -EFAULT;
14391
14392 __asm__ __volatile__(ASM_STAC "\n"
14393 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14394 + "1:"
14395 + __copyuser_seg
14396 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14397 "2: " ASM_CLAC "\n"
14398 ".section .fixup,\"ax\"\n"
14399 "3: movl $-1,%[err]\n"
14400 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14401 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14402 {
14403 int err;
14404 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14405 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14406 u32 lmask = mask;
14407 u32 hmask = mask >> 32;
14408
14409 __asm__ __volatile__(ASM_STAC "\n"
14410 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14411 + "1:"
14412 + __copyuser_seg
14413 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14414 "2: " ASM_CLAC "\n"
14415 ".section .fixup,\"ax\"\n"
14416 "3: movl $-1,%[err]\n"
14417 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14418 index 91ce48f..a48ea05 100644
14419 --- a/arch/x86/kernel/Makefile
14420 +++ b/arch/x86/kernel/Makefile
14421 @@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14422 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14423 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14424 obj-y += probe_roms.o
14425 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14426 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14427 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14428 obj-y += syscall_$(BITS).o
14429 obj-$(CONFIG_X86_64) += vsyscall_64.o
14430 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
14431 index e651f7a..c995dc4 100644
14432 --- a/arch/x86/kernel/acpi/boot.c
14433 +++ b/arch/x86/kernel/acpi/boot.c
14434 @@ -1576,7 +1576,7 @@ int __init acpi_boot_init(void)
14435 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
14436
14437 if (!acpi_noirq)
14438 - x86_init.pci.init = pci_acpi_init;
14439 + *(void **)&x86_init.pci.init = pci_acpi_init;
14440
14441 return 0;
14442 }
14443 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14444 index 11676cf..a8cf3ec 100644
14445 --- a/arch/x86/kernel/acpi/sleep.c
14446 +++ b/arch/x86/kernel/acpi/sleep.c
14447 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14448 #else /* CONFIG_64BIT */
14449 #ifdef CONFIG_SMP
14450 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14451 +
14452 + pax_open_kernel();
14453 early_gdt_descr.address =
14454 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14455 + pax_close_kernel();
14456 +
14457 initial_gs = per_cpu_offset(smp_processor_id());
14458 #endif
14459 initial_code = (unsigned long)wakeup_long64;
14460 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14461 index 13ab720..95d5442 100644
14462 --- a/arch/x86/kernel/acpi/wakeup_32.S
14463 +++ b/arch/x86/kernel/acpi/wakeup_32.S
14464 @@ -30,13 +30,11 @@ wakeup_pmode_return:
14465 # and restore the stack ... but you need gdt for this to work
14466 movl saved_context_esp, %esp
14467
14468 - movl %cs:saved_magic, %eax
14469 - cmpl $0x12345678, %eax
14470 + cmpl $0x12345678, saved_magic
14471 jne bogus_magic
14472
14473 # jump to place where we left off
14474 - movl saved_eip, %eax
14475 - jmp *%eax
14476 + jmp *(saved_eip)
14477
14478 bogus_magic:
14479 jmp bogus_magic
14480 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14481 index ef5ccca..bd83949 100644
14482 --- a/arch/x86/kernel/alternative.c
14483 +++ b/arch/x86/kernel/alternative.c
14484 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14485 */
14486 for (a = start; a < end; a++) {
14487 instr = (u8 *)&a->instr_offset + a->instr_offset;
14488 +
14489 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14490 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14491 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14492 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14493 +#endif
14494 +
14495 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14496 BUG_ON(a->replacementlen > a->instrlen);
14497 BUG_ON(a->instrlen > sizeof(insnbuf));
14498 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14499 for (poff = start; poff < end; poff++) {
14500 u8 *ptr = (u8 *)poff + *poff;
14501
14502 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14503 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14504 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14505 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14506 +#endif
14507 +
14508 if (!*poff || ptr < text || ptr >= text_end)
14509 continue;
14510 /* turn DS segment override prefix into lock prefix */
14511 - if (*ptr == 0x3e)
14512 + if (*ktla_ktva(ptr) == 0x3e)
14513 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14514 }
14515 mutex_unlock(&text_mutex);
14516 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14517 for (poff = start; poff < end; poff++) {
14518 u8 *ptr = (u8 *)poff + *poff;
14519
14520 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14521 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14522 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14523 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14524 +#endif
14525 +
14526 if (!*poff || ptr < text || ptr >= text_end)
14527 continue;
14528 /* turn lock prefix into DS segment override prefix */
14529 - if (*ptr == 0xf0)
14530 + if (*ktla_ktva(ptr) == 0xf0)
14531 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14532 }
14533 mutex_unlock(&text_mutex);
14534 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14535
14536 BUG_ON(p->len > MAX_PATCH_LEN);
14537 /* prep the buffer with the original instructions */
14538 - memcpy(insnbuf, p->instr, p->len);
14539 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14540 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14541 (unsigned long)p->instr, p->len);
14542
14543 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14544 if (!uniproc_patched || num_possible_cpus() == 1)
14545 free_init_pages("SMP alternatives",
14546 (unsigned long)__smp_locks,
14547 - (unsigned long)__smp_locks_end);
14548 + PAGE_ALIGN((unsigned long)__smp_locks_end));
14549 #endif
14550
14551 apply_paravirt(__parainstructions, __parainstructions_end);
14552 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14553 * instructions. And on the local CPU you need to be protected again NMI or MCE
14554 * handlers seeing an inconsistent instruction while you patch.
14555 */
14556 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
14557 +void *__kprobes text_poke_early(void *addr, const void *opcode,
14558 size_t len)
14559 {
14560 unsigned long flags;
14561 local_irq_save(flags);
14562 - memcpy(addr, opcode, len);
14563 +
14564 + pax_open_kernel();
14565 + memcpy(ktla_ktva(addr), opcode, len);
14566 sync_core();
14567 + pax_close_kernel();
14568 +
14569 local_irq_restore(flags);
14570 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14571 that causes hangs on some VIA CPUs. */
14572 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14573 */
14574 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14575 {
14576 - unsigned long flags;
14577 - char *vaddr;
14578 + unsigned char *vaddr = ktla_ktva(addr);
14579 struct page *pages[2];
14580 - int i;
14581 + size_t i;
14582
14583 if (!core_kernel_text((unsigned long)addr)) {
14584 - pages[0] = vmalloc_to_page(addr);
14585 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14586 + pages[0] = vmalloc_to_page(vaddr);
14587 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14588 } else {
14589 - pages[0] = virt_to_page(addr);
14590 + pages[0] = virt_to_page(vaddr);
14591 WARN_ON(!PageReserved(pages[0]));
14592 - pages[1] = virt_to_page(addr + PAGE_SIZE);
14593 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14594 }
14595 BUG_ON(!pages[0]);
14596 - local_irq_save(flags);
14597 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14598 - if (pages[1])
14599 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14600 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14601 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14602 - clear_fixmap(FIX_TEXT_POKE0);
14603 - if (pages[1])
14604 - clear_fixmap(FIX_TEXT_POKE1);
14605 - local_flush_tlb();
14606 - sync_core();
14607 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
14608 - that causes hangs on some VIA CPUs. */
14609 + text_poke_early(addr, opcode, len);
14610 for (i = 0; i < len; i++)
14611 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14612 - local_irq_restore(flags);
14613 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14614 return addr;
14615 }
14616
14617 diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
14618 index e663112..21938a3 100644
14619 --- a/arch/x86/kernel/amd_gart_64.c
14620 +++ b/arch/x86/kernel/amd_gart_64.c
14621 @@ -851,7 +851,7 @@ int __init gart_iommu_init(void)
14622
14623 flush_gart();
14624 dma_ops = &gart_dma_ops;
14625 - x86_platform.iommu_shutdown = gart_iommu_shutdown;
14626 + *(void **)&x86_platform.iommu_shutdown = gart_iommu_shutdown;
14627 swiotlb = 0;
14628
14629 return 0;
14630 diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
14631 index d5fd66f..6119b16 100644
14632 --- a/arch/x86/kernel/aperture_64.c
14633 +++ b/arch/x86/kernel/aperture_64.c
14634 @@ -390,7 +390,7 @@ int __init gart_iommu_hole_init(void)
14635
14636 iommu_detected = 1;
14637 gart_iommu_aperture = 1;
14638 - x86_init.iommu.iommu_init = gart_iommu_init;
14639 + *(void **)&x86_init.iommu.iommu_init = gart_iommu_init;
14640
14641 ctl = read_pci_config(bus, slot, 3,
14642 AMD64_GARTAPERTURECTL);
14643 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14644 index b17416e..be6e5dc 100644
14645 --- a/arch/x86/kernel/apic/apic.c
14646 +++ b/arch/x86/kernel/apic/apic.c
14647 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14648 /*
14649 * Debug level, exported for io_apic.c
14650 */
14651 -unsigned int apic_verbosity;
14652 +int apic_verbosity;
14653
14654 int pic_mode;
14655
14656 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14657 apic_write(APIC_ESR, 0);
14658 v1 = apic_read(APIC_ESR);
14659 ack_APIC_irq();
14660 - atomic_inc(&irq_err_count);
14661 + atomic_inc_unchecked(&irq_err_count);
14662
14663 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14664 smp_processor_id(), v0 , v1);
14665 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
14666 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
14667 /* Should happen once for each apic */
14668 WARN_ON((*drv)->eoi_write == eoi_write);
14669 - (*drv)->eoi_write = eoi_write;
14670 + pax_open_kernel();
14671 + *(void **)&(*drv)->eoi_write = eoi_write;
14672 + pax_close_kernel();
14673 }
14674 }
14675
14676 diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
14677 index a65829a..6ddc249 100644
14678 --- a/arch/x86/kernel/apic/apic_numachip.c
14679 +++ b/arch/x86/kernel/apic/apic_numachip.c
14680 @@ -178,7 +178,7 @@ static int __init numachip_system_init(void)
14681 if (!numachip_system)
14682 return 0;
14683
14684 - x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
14685 + *(void **)&x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
14686
14687 map_csrs();
14688
14689 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
14690 index 1817fa9..7bff097 100644
14691 --- a/arch/x86/kernel/apic/io_apic.c
14692 +++ b/arch/x86/kernel/apic/io_apic.c
14693 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
14694 }
14695 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
14696
14697 -void lock_vector_lock(void)
14698 +void lock_vector_lock(void) __acquires(vector_lock)
14699 {
14700 /* Used to the online set of cpus does not change
14701 * during assign_irq_vector.
14702 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
14703 raw_spin_lock(&vector_lock);
14704 }
14705
14706 -void unlock_vector_lock(void)
14707 +void unlock_vector_lock(void) __releases(vector_lock)
14708 {
14709 raw_spin_unlock(&vector_lock);
14710 }
14711 @@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
14712 ack_APIC_irq();
14713 }
14714
14715 -atomic_t irq_mis_count;
14716 +atomic_unchecked_t irq_mis_count;
14717
14718 #ifdef CONFIG_GENERIC_PENDING_IRQ
14719 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14720 @@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
14721 * at the cpu.
14722 */
14723 if (!(v & (1 << (i & 0x1f)))) {
14724 - atomic_inc(&irq_mis_count);
14725 + atomic_inc_unchecked(&irq_mis_count);
14726
14727 eoi_ioapic_irq(irq, cfg);
14728 }
14729 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
14730 index d661ee9..512c0a1 100644
14731 --- a/arch/x86/kernel/apic/numaq_32.c
14732 +++ b/arch/x86/kernel/apic/numaq_32.c
14733 @@ -257,14 +257,14 @@ static __init void early_check_numaq(void)
14734 early_get_smp_config();
14735
14736 if (found_numaq) {
14737 - x86_init.mpparse.mpc_record = numaq_mpc_record;
14738 - x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
14739 - x86_init.mpparse.mpc_apic_id = mpc_apic_id;
14740 - x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
14741 - x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
14742 - x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
14743 - x86_init.timers.tsc_pre_init = numaq_tsc_init;
14744 - x86_init.pci.init = pci_numaq_init;
14745 + *(void **)&x86_init.mpparse.mpc_record = numaq_mpc_record;
14746 + *(void **)&x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
14747 + *(void **)&x86_init.mpparse.mpc_apic_id = mpc_apic_id;
14748 + *(void **)&x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
14749 + *(void **)&x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
14750 + *(void **)&x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
14751 + *(void **)&x86_init.timers.tsc_pre_init = numaq_tsc_init;
14752 + *(void **)&x86_init.pci.init = pci_numaq_init;
14753 }
14754 }
14755
14756 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
14757 index 8cfade9..8ea7b51 100644
14758 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
14759 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
14760 @@ -139,8 +139,8 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
14761 is_uv1 ? UV1_HUB_REVISION_BASE : UV2_HUB_REVISION_BASE;
14762 pnodeid = early_get_pnodeid();
14763 early_get_apic_pnode_shift();
14764 - x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
14765 - x86_platform.nmi_init = uv_nmi_init;
14766 + *(void **)&x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
14767 + *(void **)&x86_platform.nmi_init = uv_nmi_init;
14768 if (!strcmp(oem_table_id, "UVL"))
14769 uv_system_type = UV_LEGACY_APIC;
14770 else if (!strcmp(oem_table_id, "UVX"))
14771 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14772 index d65464e..1035d31 100644
14773 --- a/arch/x86/kernel/apm_32.c
14774 +++ b/arch/x86/kernel/apm_32.c
14775 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14776 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14777 * even though they are called in protected mode.
14778 */
14779 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14780 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14781 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14782
14783 static const char driver_version[] = "1.16ac"; /* no spaces */
14784 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14785 BUG_ON(cpu != 0);
14786 gdt = get_cpu_gdt_table(cpu);
14787 save_desc_40 = gdt[0x40 / 8];
14788 +
14789 + pax_open_kernel();
14790 gdt[0x40 / 8] = bad_bios_desc;
14791 + pax_close_kernel();
14792
14793 apm_irq_save(flags);
14794 APM_DO_SAVE_SEGS;
14795 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14796 &call->esi);
14797 APM_DO_RESTORE_SEGS;
14798 apm_irq_restore(flags);
14799 +
14800 + pax_open_kernel();
14801 gdt[0x40 / 8] = save_desc_40;
14802 + pax_close_kernel();
14803 +
14804 put_cpu();
14805
14806 return call->eax & 0xff;
14807 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14808 BUG_ON(cpu != 0);
14809 gdt = get_cpu_gdt_table(cpu);
14810 save_desc_40 = gdt[0x40 / 8];
14811 +
14812 + pax_open_kernel();
14813 gdt[0x40 / 8] = bad_bios_desc;
14814 + pax_close_kernel();
14815
14816 apm_irq_save(flags);
14817 APM_DO_SAVE_SEGS;
14818 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14819 &call->eax);
14820 APM_DO_RESTORE_SEGS;
14821 apm_irq_restore(flags);
14822 +
14823 + pax_open_kernel();
14824 gdt[0x40 / 8] = save_desc_40;
14825 + pax_close_kernel();
14826 +
14827 put_cpu();
14828 return error;
14829 }
14830 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14831 * code to that CPU.
14832 */
14833 gdt = get_cpu_gdt_table(0);
14834 +
14835 + pax_open_kernel();
14836 set_desc_base(&gdt[APM_CS >> 3],
14837 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14838 set_desc_base(&gdt[APM_CS_16 >> 3],
14839 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14840 set_desc_base(&gdt[APM_DS >> 3],
14841 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14842 + pax_close_kernel();
14843
14844 proc_create("apm", 0, NULL, &apm_file_ops);
14845
14846 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14847 index 2861082..6d4718e 100644
14848 --- a/arch/x86/kernel/asm-offsets.c
14849 +++ b/arch/x86/kernel/asm-offsets.c
14850 @@ -33,6 +33,8 @@ void common(void) {
14851 OFFSET(TI_status, thread_info, status);
14852 OFFSET(TI_addr_limit, thread_info, addr_limit);
14853 OFFSET(TI_preempt_count, thread_info, preempt_count);
14854 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14855 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14856
14857 BLANK();
14858 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14859 @@ -53,8 +55,26 @@ void common(void) {
14860 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14861 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14862 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14863 +
14864 +#ifdef CONFIG_PAX_KERNEXEC
14865 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14866 #endif
14867
14868 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14869 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14870 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14871 +#ifdef CONFIG_X86_64
14872 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14873 +#endif
14874 +#endif
14875 +
14876 +#endif
14877 +
14878 + BLANK();
14879 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14880 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14881 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14882 +
14883 #ifdef CONFIG_XEN
14884 BLANK();
14885 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14886 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14887 index 1b4754f..fbb4227 100644
14888 --- a/arch/x86/kernel/asm-offsets_64.c
14889 +++ b/arch/x86/kernel/asm-offsets_64.c
14890 @@ -76,6 +76,7 @@ int main(void)
14891 BLANK();
14892 #undef ENTRY
14893
14894 + DEFINE(TSS_size, sizeof(struct tss_struct));
14895 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14896 BLANK();
14897
14898 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14899 index a0e067d..9c7db16 100644
14900 --- a/arch/x86/kernel/cpu/Makefile
14901 +++ b/arch/x86/kernel/cpu/Makefile
14902 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14903 CFLAGS_REMOVE_perf_event.o = -pg
14904 endif
14905
14906 -# Make sure load_percpu_segment has no stackprotector
14907 -nostackp := $(call cc-option, -fno-stack-protector)
14908 -CFLAGS_common.o := $(nostackp)
14909 -
14910 obj-y := intel_cacheinfo.o scattered.o topology.o
14911 obj-y += proc.o capflags.o powerflags.o common.o
14912 obj-y += vmware.o hypervisor.o mshyperv.o
14913 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14914 index 1b7d165..b9e2627 100644
14915 --- a/arch/x86/kernel/cpu/amd.c
14916 +++ b/arch/x86/kernel/cpu/amd.c
14917 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14918 unsigned int size)
14919 {
14920 /* AMD errata T13 (order #21922) */
14921 - if ((c->x86 == 6)) {
14922 + if (c->x86 == 6) {
14923 /* Duron Rev A0 */
14924 if (c->x86_model == 3 && c->x86_mask == 0)
14925 size = 64;
14926 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14927 index 7505f7b..d59dac0 100644
14928 --- a/arch/x86/kernel/cpu/common.c
14929 +++ b/arch/x86/kernel/cpu/common.c
14930 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14931
14932 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14933
14934 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14935 -#ifdef CONFIG_X86_64
14936 - /*
14937 - * We need valid kernel segments for data and code in long mode too
14938 - * IRET will check the segment types kkeil 2000/10/28
14939 - * Also sysret mandates a special GDT layout
14940 - *
14941 - * TLS descriptors are currently at a different place compared to i386.
14942 - * Hopefully nobody expects them at a fixed place (Wine?)
14943 - */
14944 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14945 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14946 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14947 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14948 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14949 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14950 -#else
14951 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14952 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14953 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14954 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14955 - /*
14956 - * Segments used for calling PnP BIOS have byte granularity.
14957 - * They code segments and data segments have fixed 64k limits,
14958 - * the transfer segment sizes are set at run time.
14959 - */
14960 - /* 32-bit code */
14961 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14962 - /* 16-bit code */
14963 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14964 - /* 16-bit data */
14965 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14966 - /* 16-bit data */
14967 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14968 - /* 16-bit data */
14969 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14970 - /*
14971 - * The APM segments have byte granularity and their bases
14972 - * are set at run time. All have 64k limits.
14973 - */
14974 - /* 32-bit code */
14975 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14976 - /* 16-bit code */
14977 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14978 - /* data */
14979 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14980 -
14981 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14982 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14983 - GDT_STACK_CANARY_INIT
14984 -#endif
14985 -} };
14986 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14987 -
14988 static int __init x86_xsave_setup(char *s)
14989 {
14990 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14991 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
14992 {
14993 struct desc_ptr gdt_descr;
14994
14995 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14996 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14997 gdt_descr.size = GDT_SIZE - 1;
14998 load_gdt(&gdt_descr);
14999 /* Reload the per-cpu base */
15000 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15001 /* Filter out anything that depends on CPUID levels we don't have */
15002 filter_cpuid_features(c, true);
15003
15004 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15005 + setup_clear_cpu_cap(X86_FEATURE_SEP);
15006 +#endif
15007 +
15008 /* If the model name is still unset, do table lookup. */
15009 if (!c->x86_model_id[0]) {
15010 const char *p;
15011 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15012 }
15013 __setup("clearcpuid=", setup_disablecpuid);
15014
15015 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15016 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
15017 +
15018 #ifdef CONFIG_X86_64
15019 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15020 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15021 - (unsigned long) nmi_idt_table };
15022 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15023
15024 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15025 irq_stack_union) __aligned(PAGE_SIZE);
15026 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15027 EXPORT_PER_CPU_SYMBOL(current_task);
15028
15029 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15030 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15031 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15032 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15033
15034 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15035 @@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15036 {
15037 memset(regs, 0, sizeof(struct pt_regs));
15038 regs->fs = __KERNEL_PERCPU;
15039 - regs->gs = __KERNEL_STACK_CANARY;
15040 + savesegment(gs, regs->gs);
15041
15042 return regs;
15043 }
15044 @@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15045 int i;
15046
15047 cpu = stack_smp_processor_id();
15048 - t = &per_cpu(init_tss, cpu);
15049 + t = init_tss + cpu;
15050 oist = &per_cpu(orig_ist, cpu);
15051
15052 #ifdef CONFIG_NUMA
15053 @@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15054 switch_to_new_gdt(cpu);
15055 loadsegment(fs, 0);
15056
15057 - load_idt((const struct desc_ptr *)&idt_descr);
15058 + load_idt(&idt_descr);
15059
15060 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15061 syscall_init();
15062 @@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15063 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15064 barrier();
15065
15066 - x86_configure_nx();
15067 if (cpu != 0)
15068 enable_x2apic();
15069
15070 @@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15071 {
15072 int cpu = smp_processor_id();
15073 struct task_struct *curr = current;
15074 - struct tss_struct *t = &per_cpu(init_tss, cpu);
15075 + struct tss_struct *t = init_tss + cpu;
15076 struct thread_struct *thread = &curr->thread;
15077
15078 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15079 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15080 index 198e019..867575e 100644
15081 --- a/arch/x86/kernel/cpu/intel.c
15082 +++ b/arch/x86/kernel/cpu/intel.c
15083 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15084 * Update the IDT descriptor and reload the IDT so that
15085 * it uses the read-only mapped virtual address.
15086 */
15087 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15088 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15089 load_idt(&idt_descr);
15090 }
15091 #endif
15092 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15093 index 93c5451..3887433 100644
15094 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15095 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15096 @@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15097 };
15098
15099 #ifdef CONFIG_AMD_NB
15100 +static struct attribute *default_attrs_amd_nb[] = {
15101 + &type.attr,
15102 + &level.attr,
15103 + &coherency_line_size.attr,
15104 + &physical_line_partition.attr,
15105 + &ways_of_associativity.attr,
15106 + &number_of_sets.attr,
15107 + &size.attr,
15108 + &shared_cpu_map.attr,
15109 + &shared_cpu_list.attr,
15110 + NULL,
15111 + NULL,
15112 + NULL,
15113 + NULL
15114 +};
15115 +
15116 static struct attribute ** __cpuinit amd_l3_attrs(void)
15117 {
15118 static struct attribute **attrs;
15119 @@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15120
15121 n = ARRAY_SIZE(default_attrs);
15122
15123 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15124 - n += 2;
15125 -
15126 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15127 - n += 1;
15128 -
15129 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15130 - if (attrs == NULL)
15131 - return attrs = default_attrs;
15132 -
15133 - for (n = 0; default_attrs[n]; n++)
15134 - attrs[n] = default_attrs[n];
15135 + attrs = default_attrs_amd_nb;
15136
15137 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15138 attrs[n++] = &cache_disable_0.attr;
15139 @@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15140 .default_attrs = default_attrs,
15141 };
15142
15143 +#ifdef CONFIG_AMD_NB
15144 +static struct kobj_type ktype_cache_amd_nb = {
15145 + .sysfs_ops = &sysfs_ops,
15146 + .default_attrs = default_attrs_amd_nb,
15147 +};
15148 +#endif
15149 +
15150 static struct kobj_type ktype_percpu_entry = {
15151 .sysfs_ops = &sysfs_ops,
15152 };
15153 @@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15154 return retval;
15155 }
15156
15157 +#ifdef CONFIG_AMD_NB
15158 + amd_l3_attrs();
15159 +#endif
15160 +
15161 for (i = 0; i < num_cache_leaves; i++) {
15162 + struct kobj_type *ktype;
15163 +
15164 this_object = INDEX_KOBJECT_PTR(cpu, i);
15165 this_object->cpu = cpu;
15166 this_object->index = i;
15167
15168 this_leaf = CPUID4_INFO_IDX(cpu, i);
15169
15170 - ktype_cache.default_attrs = default_attrs;
15171 + ktype = &ktype_cache;
15172 #ifdef CONFIG_AMD_NB
15173 if (this_leaf->base.nb)
15174 - ktype_cache.default_attrs = amd_l3_attrs();
15175 + ktype = &ktype_cache_amd_nb;
15176 #endif
15177 retval = kobject_init_and_add(&(this_object->kobj),
15178 - &ktype_cache,
15179 + ktype,
15180 per_cpu(ici_cache_kobject, cpu),
15181 "index%1lu", i);
15182 if (unlikely(retval)) {
15183 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15184 index 46cbf86..55c7292 100644
15185 --- a/arch/x86/kernel/cpu/mcheck/mce.c
15186 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
15187 @@ -45,6 +45,7 @@
15188 #include <asm/processor.h>
15189 #include <asm/mce.h>
15190 #include <asm/msr.h>
15191 +#include <asm/local.h>
15192
15193 #include "mce-internal.h"
15194
15195 @@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15196 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15197 m->cs, m->ip);
15198
15199 - if (m->cs == __KERNEL_CS)
15200 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15201 print_symbol("{%s}", m->ip);
15202 pr_cont("\n");
15203 }
15204 @@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15205
15206 #define PANIC_TIMEOUT 5 /* 5 seconds */
15207
15208 -static atomic_t mce_paniced;
15209 +static atomic_unchecked_t mce_paniced;
15210
15211 static int fake_panic;
15212 -static atomic_t mce_fake_paniced;
15213 +static atomic_unchecked_t mce_fake_paniced;
15214
15215 /* Panic in progress. Enable interrupts and wait for final IPI */
15216 static void wait_for_panic(void)
15217 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15218 /*
15219 * Make sure only one CPU runs in machine check panic
15220 */
15221 - if (atomic_inc_return(&mce_paniced) > 1)
15222 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15223 wait_for_panic();
15224 barrier();
15225
15226 @@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15227 console_verbose();
15228 } else {
15229 /* Don't log too much for fake panic */
15230 - if (atomic_inc_return(&mce_fake_paniced) > 1)
15231 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15232 return;
15233 }
15234 /* First print corrected ones that are still unlogged */
15235 @@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15236 * might have been modified by someone else.
15237 */
15238 rmb();
15239 - if (atomic_read(&mce_paniced))
15240 + if (atomic_read_unchecked(&mce_paniced))
15241 wait_for_panic();
15242 if (!monarch_timeout)
15243 goto out;
15244 @@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15245 }
15246
15247 /* Call the installed machine check handler for this CPU setup. */
15248 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
15249 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15250 unexpected_machine_check;
15251
15252 /*
15253 @@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15254 return;
15255 }
15256
15257 + pax_open_kernel();
15258 machine_check_vector = do_machine_check;
15259 + pax_close_kernel();
15260
15261 __mcheck_cpu_init_generic();
15262 __mcheck_cpu_init_vendor(c);
15263 @@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15264 */
15265
15266 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15267 -static int mce_chrdev_open_count; /* #times opened */
15268 +static local_t mce_chrdev_open_count; /* #times opened */
15269 static int mce_chrdev_open_exclu; /* already open exclusive? */
15270
15271 static int mce_chrdev_open(struct inode *inode, struct file *file)
15272 @@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15273 spin_lock(&mce_chrdev_state_lock);
15274
15275 if (mce_chrdev_open_exclu ||
15276 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15277 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15278 spin_unlock(&mce_chrdev_state_lock);
15279
15280 return -EBUSY;
15281 @@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15282
15283 if (file->f_flags & O_EXCL)
15284 mce_chrdev_open_exclu = 1;
15285 - mce_chrdev_open_count++;
15286 + local_inc(&mce_chrdev_open_count);
15287
15288 spin_unlock(&mce_chrdev_state_lock);
15289
15290 @@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15291 {
15292 spin_lock(&mce_chrdev_state_lock);
15293
15294 - mce_chrdev_open_count--;
15295 + local_dec(&mce_chrdev_open_count);
15296 mce_chrdev_open_exclu = 0;
15297
15298 spin_unlock(&mce_chrdev_state_lock);
15299 @@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15300 return NOTIFY_OK;
15301 }
15302
15303 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15304 +static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15305 .notifier_call = mce_cpu_callback,
15306 };
15307
15308 @@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15309 static void mce_reset(void)
15310 {
15311 cpu_missing = 0;
15312 - atomic_set(&mce_fake_paniced, 0);
15313 + atomic_set_unchecked(&mce_fake_paniced, 0);
15314 atomic_set(&mce_executing, 0);
15315 atomic_set(&mce_callin, 0);
15316 atomic_set(&global_nwo, 0);
15317 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15318 index 2d5454c..51987eb 100644
15319 --- a/arch/x86/kernel/cpu/mcheck/p5.c
15320 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
15321 @@ -11,6 +11,7 @@
15322 #include <asm/processor.h>
15323 #include <asm/mce.h>
15324 #include <asm/msr.h>
15325 +#include <asm/pgtable.h>
15326
15327 /* By default disabled */
15328 int mce_p5_enabled __read_mostly;
15329 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15330 if (!cpu_has(c, X86_FEATURE_MCE))
15331 return;
15332
15333 + pax_open_kernel();
15334 machine_check_vector = pentium_machine_check;
15335 + pax_close_kernel();
15336 /* Make sure the vector pointer is visible before we enable MCEs: */
15337 wmb();
15338
15339 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15340 index 2d7998f..17c9de1 100644
15341 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
15342 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15343 @@ -10,6 +10,7 @@
15344 #include <asm/processor.h>
15345 #include <asm/mce.h>
15346 #include <asm/msr.h>
15347 +#include <asm/pgtable.h>
15348
15349 /* Machine check handler for WinChip C6: */
15350 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15351 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15352 {
15353 u32 lo, hi;
15354
15355 + pax_open_kernel();
15356 machine_check_vector = winchip_machine_check;
15357 + pax_close_kernel();
15358 /* Make sure the vector pointer is visible before we enable MCEs: */
15359 wmb();
15360
15361 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15362 index 6b96110..0da73eb 100644
15363 --- a/arch/x86/kernel/cpu/mtrr/main.c
15364 +++ b/arch/x86/kernel/cpu/mtrr/main.c
15365 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15366 u64 size_or_mask, size_and_mask;
15367 static bool mtrr_aps_delayed_init;
15368
15369 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15370 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15371
15372 const struct mtrr_ops *mtrr_if;
15373
15374 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15375 index df5e41f..816c719 100644
15376 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15377 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15378 @@ -25,7 +25,7 @@ struct mtrr_ops {
15379 int (*validate_add_page)(unsigned long base, unsigned long size,
15380 unsigned int type);
15381 int (*have_wrcomb)(void);
15382 -};
15383 +} __do_const;
15384
15385 extern int generic_get_free_region(unsigned long base, unsigned long size,
15386 int replace_reg);
15387 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15388 index 4a3374e..1ca3ecb 100644
15389 --- a/arch/x86/kernel/cpu/perf_event.c
15390 +++ b/arch/x86/kernel/cpu/perf_event.c
15391 @@ -1765,7 +1765,7 @@ static unsigned long get_segment_base(unsigned int segment)
15392 if (idx > GDT_ENTRIES)
15393 return 0;
15394
15395 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15396 + desc = get_cpu_gdt_table(smp_processor_id());
15397 }
15398
15399 return get_desc_base(desc + idx);
15400 @@ -1855,7 +1855,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15401 break;
15402
15403 perf_callchain_store(entry, frame.return_address);
15404 - fp = frame.next_frame;
15405 + fp = (const void __force_user *)frame.next_frame;
15406 }
15407 }
15408
15409 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15410 index 324bb52..1a93d85 100644
15411 --- a/arch/x86/kernel/cpu/perf_event_intel.c
15412 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
15413 @@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15414 * v2 and above have a perf capabilities MSR
15415 */
15416 if (version > 1) {
15417 - u64 capabilities;
15418 + u64 capabilities = x86_pmu.intel_cap.capabilities;
15419
15420 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15421 - x86_pmu.intel_cap.capabilities = capabilities;
15422 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15423 + x86_pmu.intel_cap.capabilities = capabilities;
15424 }
15425
15426 intel_ds_init();
15427 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
15428 index d22d0c4..088eb6f 100644
15429 --- a/arch/x86/kernel/cpu/vmware.c
15430 +++ b/arch/x86/kernel/cpu/vmware.c
15431 @@ -79,7 +79,7 @@ static void __init vmware_platform_setup(void)
15432 VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
15433
15434 if (ebx != UINT_MAX)
15435 - x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15436 + *(void **)&x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15437 else
15438 printk(KERN_WARNING
15439 "Failed to get TSC freq from the hypervisor\n");
15440 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15441 index 13ad899..f642b9a 100644
15442 --- a/arch/x86/kernel/crash.c
15443 +++ b/arch/x86/kernel/crash.c
15444 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15445 {
15446 #ifdef CONFIG_X86_32
15447 struct pt_regs fixed_regs;
15448 -#endif
15449
15450 -#ifdef CONFIG_X86_32
15451 - if (!user_mode_vm(regs)) {
15452 + if (!user_mode(regs)) {
15453 crash_fixup_ss_esp(&fixed_regs, regs);
15454 regs = &fixed_regs;
15455 }
15456 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15457 index 37250fe..bf2ec74 100644
15458 --- a/arch/x86/kernel/doublefault_32.c
15459 +++ b/arch/x86/kernel/doublefault_32.c
15460 @@ -11,7 +11,7 @@
15461
15462 #define DOUBLEFAULT_STACKSIZE (1024)
15463 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15464 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15465 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15466
15467 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15468
15469 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
15470 unsigned long gdt, tss;
15471
15472 store_gdt(&gdt_desc);
15473 - gdt = gdt_desc.address;
15474 + gdt = (unsigned long)gdt_desc.address;
15475
15476 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15477
15478 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15479 /* 0x2 bit is always set */
15480 .flags = X86_EFLAGS_SF | 0x2,
15481 .sp = STACK_START,
15482 - .es = __USER_DS,
15483 + .es = __KERNEL_DS,
15484 .cs = __KERNEL_CS,
15485 .ss = __KERNEL_DS,
15486 - .ds = __USER_DS,
15487 + .ds = __KERNEL_DS,
15488 .fs = __KERNEL_PERCPU,
15489
15490 .__cr3 = __pa_nodebug(swapper_pg_dir),
15491 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15492 index ae42418b..787c16b 100644
15493 --- a/arch/x86/kernel/dumpstack.c
15494 +++ b/arch/x86/kernel/dumpstack.c
15495 @@ -2,6 +2,9 @@
15496 * Copyright (C) 1991, 1992 Linus Torvalds
15497 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15498 */
15499 +#ifdef CONFIG_GRKERNSEC_HIDESYM
15500 +#define __INCLUDED_BY_HIDESYM 1
15501 +#endif
15502 #include <linux/kallsyms.h>
15503 #include <linux/kprobes.h>
15504 #include <linux/uaccess.h>
15505 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15506 static void
15507 print_ftrace_graph_addr(unsigned long addr, void *data,
15508 const struct stacktrace_ops *ops,
15509 - struct thread_info *tinfo, int *graph)
15510 + struct task_struct *task, int *graph)
15511 {
15512 - struct task_struct *task;
15513 unsigned long ret_addr;
15514 int index;
15515
15516 if (addr != (unsigned long)return_to_handler)
15517 return;
15518
15519 - task = tinfo->task;
15520 index = task->curr_ret_stack;
15521
15522 if (!task->ret_stack || index < *graph)
15523 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15524 static inline void
15525 print_ftrace_graph_addr(unsigned long addr, void *data,
15526 const struct stacktrace_ops *ops,
15527 - struct thread_info *tinfo, int *graph)
15528 + struct task_struct *task, int *graph)
15529 { }
15530 #endif
15531
15532 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15533 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15534 */
15535
15536 -static inline int valid_stack_ptr(struct thread_info *tinfo,
15537 - void *p, unsigned int size, void *end)
15538 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15539 {
15540 - void *t = tinfo;
15541 if (end) {
15542 if (p < end && p >= (end-THREAD_SIZE))
15543 return 1;
15544 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15545 }
15546
15547 unsigned long
15548 -print_context_stack(struct thread_info *tinfo,
15549 +print_context_stack(struct task_struct *task, void *stack_start,
15550 unsigned long *stack, unsigned long bp,
15551 const struct stacktrace_ops *ops, void *data,
15552 unsigned long *end, int *graph)
15553 {
15554 struct stack_frame *frame = (struct stack_frame *)bp;
15555
15556 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15557 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15558 unsigned long addr;
15559
15560 addr = *stack;
15561 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15562 } else {
15563 ops->address(data, addr, 0);
15564 }
15565 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15566 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15567 }
15568 stack++;
15569 }
15570 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
15571 EXPORT_SYMBOL_GPL(print_context_stack);
15572
15573 unsigned long
15574 -print_context_stack_bp(struct thread_info *tinfo,
15575 +print_context_stack_bp(struct task_struct *task, void *stack_start,
15576 unsigned long *stack, unsigned long bp,
15577 const struct stacktrace_ops *ops, void *data,
15578 unsigned long *end, int *graph)
15579 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15580 struct stack_frame *frame = (struct stack_frame *)bp;
15581 unsigned long *ret_addr = &frame->return_address;
15582
15583 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
15584 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
15585 unsigned long addr = *ret_addr;
15586
15587 if (!__kernel_text_address(addr))
15588 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15589 ops->address(data, addr, 1);
15590 frame = frame->next_frame;
15591 ret_addr = &frame->return_address;
15592 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15593 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15594 }
15595
15596 return (unsigned long)frame;
15597 @@ -189,7 +188,7 @@ void dump_stack(void)
15598
15599 bp = stack_frame(current, NULL);
15600 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
15601 - current->pid, current->comm, print_tainted(),
15602 + task_pid_nr(current), current->comm, print_tainted(),
15603 init_utsname()->release,
15604 (int)strcspn(init_utsname()->version, " "),
15605 init_utsname()->version);
15606 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
15607 }
15608 EXPORT_SYMBOL_GPL(oops_begin);
15609
15610 +extern void gr_handle_kernel_exploit(void);
15611 +
15612 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15613 {
15614 if (regs && kexec_should_crash(current))
15615 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15616 panic("Fatal exception in interrupt");
15617 if (panic_on_oops)
15618 panic("Fatal exception");
15619 - do_exit(signr);
15620 +
15621 + gr_handle_kernel_exploit();
15622 +
15623 + do_group_exit(signr);
15624 }
15625
15626 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15627 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15628 print_modules();
15629 show_regs(regs);
15630 #ifdef CONFIG_X86_32
15631 - if (user_mode_vm(regs)) {
15632 + if (user_mode(regs)) {
15633 sp = regs->sp;
15634 ss = regs->ss & 0xffff;
15635 } else {
15636 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
15637 unsigned long flags = oops_begin();
15638 int sig = SIGSEGV;
15639
15640 - if (!user_mode_vm(regs))
15641 + if (!user_mode(regs))
15642 report_bug(regs->ip, regs);
15643
15644 if (__die(str, regs, err))
15645 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
15646 index 1038a41..db2c12b 100644
15647 --- a/arch/x86/kernel/dumpstack_32.c
15648 +++ b/arch/x86/kernel/dumpstack_32.c
15649 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15650 bp = stack_frame(task, regs);
15651
15652 for (;;) {
15653 - struct thread_info *context;
15654 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15655
15656 - context = (struct thread_info *)
15657 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
15658 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
15659 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15660
15661 - stack = (unsigned long *)context->previous_esp;
15662 - if (!stack)
15663 + if (stack_start == task_stack_page(task))
15664 break;
15665 + stack = *(unsigned long **)stack_start;
15666 if (ops->stack(data, "IRQ") < 0)
15667 break;
15668 touch_nmi_watchdog();
15669 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
15670 {
15671 int i;
15672
15673 - __show_regs(regs, !user_mode_vm(regs));
15674 + __show_regs(regs, !user_mode(regs));
15675
15676 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
15677 TASK_COMM_LEN, current->comm, task_pid_nr(current),
15678 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
15679 * When in-kernel, we also print out the stack and code at the
15680 * time of the fault..
15681 */
15682 - if (!user_mode_vm(regs)) {
15683 + if (!user_mode(regs)) {
15684 unsigned int code_prologue = code_bytes * 43 / 64;
15685 unsigned int code_len = code_bytes;
15686 unsigned char c;
15687 u8 *ip;
15688 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
15689
15690 pr_emerg("Stack:\n");
15691 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
15692
15693 pr_emerg("Code:");
15694
15695 - ip = (u8 *)regs->ip - code_prologue;
15696 + ip = (u8 *)regs->ip - code_prologue + cs_base;
15697 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
15698 /* try starting at IP */
15699 - ip = (u8 *)regs->ip;
15700 + ip = (u8 *)regs->ip + cs_base;
15701 code_len = code_len - code_prologue + 1;
15702 }
15703 for (i = 0; i < code_len; i++, ip++) {
15704 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
15705 pr_cont(" Bad EIP value.");
15706 break;
15707 }
15708 - if (ip == (u8 *)regs->ip)
15709 + if (ip == (u8 *)regs->ip + cs_base)
15710 pr_cont(" <%02x>", c);
15711 else
15712 pr_cont(" %02x", c);
15713 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
15714 {
15715 unsigned short ud2;
15716
15717 + ip = ktla_ktva(ip);
15718 if (ip < PAGE_OFFSET)
15719 return 0;
15720 if (probe_kernel_address((unsigned short *)ip, ud2))
15721 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
15722
15723 return ud2 == 0x0b0f;
15724 }
15725 +
15726 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15727 +void pax_check_alloca(unsigned long size)
15728 +{
15729 + unsigned long sp = (unsigned long)&sp, stack_left;
15730 +
15731 + /* all kernel stacks are of the same size */
15732 + stack_left = sp & (THREAD_SIZE - 1);
15733 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15734 +}
15735 +EXPORT_SYMBOL(pax_check_alloca);
15736 +#endif
15737 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
15738 index b653675..51cc8c0 100644
15739 --- a/arch/x86/kernel/dumpstack_64.c
15740 +++ b/arch/x86/kernel/dumpstack_64.c
15741 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15742 unsigned long *irq_stack_end =
15743 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
15744 unsigned used = 0;
15745 - struct thread_info *tinfo;
15746 int graph = 0;
15747 unsigned long dummy;
15748 + void *stack_start;
15749
15750 if (!task)
15751 task = current;
15752 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15753 * current stack address. If the stacks consist of nested
15754 * exceptions
15755 */
15756 - tinfo = task_thread_info(task);
15757 for (;;) {
15758 char *id;
15759 unsigned long *estack_end;
15760 +
15761 estack_end = in_exception_stack(cpu, (unsigned long)stack,
15762 &used, &id);
15763
15764 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15765 if (ops->stack(data, id) < 0)
15766 break;
15767
15768 - bp = ops->walk_stack(tinfo, stack, bp, ops,
15769 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
15770 data, estack_end, &graph);
15771 ops->stack(data, "<EOE>");
15772 /*
15773 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15774 * second-to-last pointer (index -2 to end) in the
15775 * exception stack:
15776 */
15777 + if ((u16)estack_end[-1] != __KERNEL_DS)
15778 + goto out;
15779 stack = (unsigned long *) estack_end[-2];
15780 continue;
15781 }
15782 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15783 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
15784 if (ops->stack(data, "IRQ") < 0)
15785 break;
15786 - bp = ops->walk_stack(tinfo, stack, bp,
15787 + bp = ops->walk_stack(task, irq_stack, stack, bp,
15788 ops, data, irq_stack_end, &graph);
15789 /*
15790 * We link to the next stack (which would be
15791 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15792 /*
15793 * This handles the process stack:
15794 */
15795 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
15796 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15797 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15798 +out:
15799 put_cpu();
15800 }
15801 EXPORT_SYMBOL(dump_trace);
15802 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
15803 {
15804 int i;
15805 unsigned long sp;
15806 - const int cpu = smp_processor_id();
15807 + const int cpu = raw_smp_processor_id();
15808 struct task_struct *cur = current;
15809
15810 sp = regs->sp;
15811 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
15812
15813 return ud2 == 0x0b0f;
15814 }
15815 +
15816 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15817 +void pax_check_alloca(unsigned long size)
15818 +{
15819 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
15820 + unsigned cpu, used;
15821 + char *id;
15822 +
15823 + /* check the process stack first */
15824 + stack_start = (unsigned long)task_stack_page(current);
15825 + stack_end = stack_start + THREAD_SIZE;
15826 + if (likely(stack_start <= sp && sp < stack_end)) {
15827 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
15828 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15829 + return;
15830 + }
15831 +
15832 + cpu = get_cpu();
15833 +
15834 + /* check the irq stacks */
15835 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
15836 + stack_start = stack_end - IRQ_STACK_SIZE;
15837 + if (stack_start <= sp && sp < stack_end) {
15838 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
15839 + put_cpu();
15840 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15841 + return;
15842 + }
15843 +
15844 + /* check the exception stacks */
15845 + used = 0;
15846 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
15847 + stack_start = stack_end - EXCEPTION_STKSZ;
15848 + if (stack_end && stack_start <= sp && sp < stack_end) {
15849 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
15850 + put_cpu();
15851 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15852 + return;
15853 + }
15854 +
15855 + put_cpu();
15856 +
15857 + /* unknown stack */
15858 + BUG();
15859 +}
15860 +EXPORT_SYMBOL(pax_check_alloca);
15861 +#endif
15862 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
15863 index 9b9f18b..9fcaa04 100644
15864 --- a/arch/x86/kernel/early_printk.c
15865 +++ b/arch/x86/kernel/early_printk.c
15866 @@ -7,6 +7,7 @@
15867 #include <linux/pci_regs.h>
15868 #include <linux/pci_ids.h>
15869 #include <linux/errno.h>
15870 +#include <linux/sched.h>
15871 #include <asm/io.h>
15872 #include <asm/processor.h>
15873 #include <asm/fcntl.h>
15874 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15875 index 88b725a..3efabf6 100644
15876 --- a/arch/x86/kernel/entry_32.S
15877 +++ b/arch/x86/kernel/entry_32.S
15878 @@ -177,13 +177,153 @@
15879 /*CFI_REL_OFFSET gs, PT_GS*/
15880 .endm
15881 .macro SET_KERNEL_GS reg
15882 +
15883 +#ifdef CONFIG_CC_STACKPROTECTOR
15884 movl $(__KERNEL_STACK_CANARY), \reg
15885 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15886 + movl $(__USER_DS), \reg
15887 +#else
15888 + xorl \reg, \reg
15889 +#endif
15890 +
15891 movl \reg, %gs
15892 .endm
15893
15894 #endif /* CONFIG_X86_32_LAZY_GS */
15895
15896 -.macro SAVE_ALL
15897 +.macro pax_enter_kernel
15898 +#ifdef CONFIG_PAX_KERNEXEC
15899 + call pax_enter_kernel
15900 +#endif
15901 +.endm
15902 +
15903 +.macro pax_exit_kernel
15904 +#ifdef CONFIG_PAX_KERNEXEC
15905 + call pax_exit_kernel
15906 +#endif
15907 +.endm
15908 +
15909 +#ifdef CONFIG_PAX_KERNEXEC
15910 +ENTRY(pax_enter_kernel)
15911 +#ifdef CONFIG_PARAVIRT
15912 + pushl %eax
15913 + pushl %ecx
15914 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15915 + mov %eax, %esi
15916 +#else
15917 + mov %cr0, %esi
15918 +#endif
15919 + bts $16, %esi
15920 + jnc 1f
15921 + mov %cs, %esi
15922 + cmp $__KERNEL_CS, %esi
15923 + jz 3f
15924 + ljmp $__KERNEL_CS, $3f
15925 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15926 +2:
15927 +#ifdef CONFIG_PARAVIRT
15928 + mov %esi, %eax
15929 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15930 +#else
15931 + mov %esi, %cr0
15932 +#endif
15933 +3:
15934 +#ifdef CONFIG_PARAVIRT
15935 + popl %ecx
15936 + popl %eax
15937 +#endif
15938 + ret
15939 +ENDPROC(pax_enter_kernel)
15940 +
15941 +ENTRY(pax_exit_kernel)
15942 +#ifdef CONFIG_PARAVIRT
15943 + pushl %eax
15944 + pushl %ecx
15945 +#endif
15946 + mov %cs, %esi
15947 + cmp $__KERNEXEC_KERNEL_CS, %esi
15948 + jnz 2f
15949 +#ifdef CONFIG_PARAVIRT
15950 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15951 + mov %eax, %esi
15952 +#else
15953 + mov %cr0, %esi
15954 +#endif
15955 + btr $16, %esi
15956 + ljmp $__KERNEL_CS, $1f
15957 +1:
15958 +#ifdef CONFIG_PARAVIRT
15959 + mov %esi, %eax
15960 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15961 +#else
15962 + mov %esi, %cr0
15963 +#endif
15964 +2:
15965 +#ifdef CONFIG_PARAVIRT
15966 + popl %ecx
15967 + popl %eax
15968 +#endif
15969 + ret
15970 +ENDPROC(pax_exit_kernel)
15971 +#endif
15972 +
15973 +.macro pax_erase_kstack
15974 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15975 + call pax_erase_kstack
15976 +#endif
15977 +.endm
15978 +
15979 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15980 +/*
15981 + * ebp: thread_info
15982 + */
15983 +ENTRY(pax_erase_kstack)
15984 + pushl %edi
15985 + pushl %ecx
15986 + pushl %eax
15987 +
15988 + mov TI_lowest_stack(%ebp), %edi
15989 + mov $-0xBEEF, %eax
15990 + std
15991 +
15992 +1: mov %edi, %ecx
15993 + and $THREAD_SIZE_asm - 1, %ecx
15994 + shr $2, %ecx
15995 + repne scasl
15996 + jecxz 2f
15997 +
15998 + cmp $2*16, %ecx
15999 + jc 2f
16000 +
16001 + mov $2*16, %ecx
16002 + repe scasl
16003 + jecxz 2f
16004 + jne 1b
16005 +
16006 +2: cld
16007 + mov %esp, %ecx
16008 + sub %edi, %ecx
16009 +
16010 + cmp $THREAD_SIZE_asm, %ecx
16011 + jb 3f
16012 + ud2
16013 +3:
16014 +
16015 + shr $2, %ecx
16016 + rep stosl
16017 +
16018 + mov TI_task_thread_sp0(%ebp), %edi
16019 + sub $128, %edi
16020 + mov %edi, TI_lowest_stack(%ebp)
16021 +
16022 + popl %eax
16023 + popl %ecx
16024 + popl %edi
16025 + ret
16026 +ENDPROC(pax_erase_kstack)
16027 +#endif
16028 +
16029 +.macro __SAVE_ALL _DS
16030 cld
16031 PUSH_GS
16032 pushl_cfi %fs
16033 @@ -206,7 +346,7 @@
16034 CFI_REL_OFFSET ecx, 0
16035 pushl_cfi %ebx
16036 CFI_REL_OFFSET ebx, 0
16037 - movl $(__USER_DS), %edx
16038 + movl $\_DS, %edx
16039 movl %edx, %ds
16040 movl %edx, %es
16041 movl $(__KERNEL_PERCPU), %edx
16042 @@ -214,6 +354,15 @@
16043 SET_KERNEL_GS %edx
16044 .endm
16045
16046 +.macro SAVE_ALL
16047 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16048 + __SAVE_ALL __KERNEL_DS
16049 + pax_enter_kernel
16050 +#else
16051 + __SAVE_ALL __USER_DS
16052 +#endif
16053 +.endm
16054 +
16055 .macro RESTORE_INT_REGS
16056 popl_cfi %ebx
16057 CFI_RESTORE ebx
16058 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16059 popfl_cfi
16060 jmp syscall_exit
16061 CFI_ENDPROC
16062 -END(ret_from_fork)
16063 +ENDPROC(ret_from_fork)
16064
16065 ENTRY(ret_from_kernel_thread)
16066 CFI_STARTPROC
16067 @@ -344,7 +493,15 @@ ret_from_intr:
16068 andl $SEGMENT_RPL_MASK, %eax
16069 #endif
16070 cmpl $USER_RPL, %eax
16071 +
16072 +#ifdef CONFIG_PAX_KERNEXEC
16073 + jae resume_userspace
16074 +
16075 + pax_exit_kernel
16076 + jmp resume_kernel
16077 +#else
16078 jb resume_kernel # not returning to v8086 or userspace
16079 +#endif
16080
16081 ENTRY(resume_userspace)
16082 LOCKDEP_SYS_EXIT
16083 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16084 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16085 # int/exception return?
16086 jne work_pending
16087 - jmp restore_all
16088 -END(ret_from_exception)
16089 + jmp restore_all_pax
16090 +ENDPROC(ret_from_exception)
16091
16092 #ifdef CONFIG_PREEMPT
16093 ENTRY(resume_kernel)
16094 @@ -372,7 +529,7 @@ need_resched:
16095 jz restore_all
16096 call preempt_schedule_irq
16097 jmp need_resched
16098 -END(resume_kernel)
16099 +ENDPROC(resume_kernel)
16100 #endif
16101 CFI_ENDPROC
16102 /*
16103 @@ -406,30 +563,45 @@ sysenter_past_esp:
16104 /*CFI_REL_OFFSET cs, 0*/
16105 /*
16106 * Push current_thread_info()->sysenter_return to the stack.
16107 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16108 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
16109 */
16110 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16111 + pushl_cfi $0
16112 CFI_REL_OFFSET eip, 0
16113
16114 pushl_cfi %eax
16115 SAVE_ALL
16116 + GET_THREAD_INFO(%ebp)
16117 + movl TI_sysenter_return(%ebp),%ebp
16118 + movl %ebp,PT_EIP(%esp)
16119 ENABLE_INTERRUPTS(CLBR_NONE)
16120
16121 /*
16122 * Load the potential sixth argument from user stack.
16123 * Careful about security.
16124 */
16125 + movl PT_OLDESP(%esp),%ebp
16126 +
16127 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16128 + mov PT_OLDSS(%esp),%ds
16129 +1: movl %ds:(%ebp),%ebp
16130 + push %ss
16131 + pop %ds
16132 +#else
16133 cmpl $__PAGE_OFFSET-3,%ebp
16134 jae syscall_fault
16135 ASM_STAC
16136 1: movl (%ebp),%ebp
16137 ASM_CLAC
16138 +#endif
16139 +
16140 movl %ebp,PT_EBP(%esp)
16141 _ASM_EXTABLE(1b,syscall_fault)
16142
16143 GET_THREAD_INFO(%ebp)
16144
16145 +#ifdef CONFIG_PAX_RANDKSTACK
16146 + pax_erase_kstack
16147 +#endif
16148 +
16149 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16150 jnz sysenter_audit
16151 sysenter_do_call:
16152 @@ -444,12 +616,24 @@ sysenter_do_call:
16153 testl $_TIF_ALLWORK_MASK, %ecx
16154 jne sysexit_audit
16155 sysenter_exit:
16156 +
16157 +#ifdef CONFIG_PAX_RANDKSTACK
16158 + pushl_cfi %eax
16159 + movl %esp, %eax
16160 + call pax_randomize_kstack
16161 + popl_cfi %eax
16162 +#endif
16163 +
16164 + pax_erase_kstack
16165 +
16166 /* if something modifies registers it must also disable sysexit */
16167 movl PT_EIP(%esp), %edx
16168 movl PT_OLDESP(%esp), %ecx
16169 xorl %ebp,%ebp
16170 TRACE_IRQS_ON
16171 1: mov PT_FS(%esp), %fs
16172 +2: mov PT_DS(%esp), %ds
16173 +3: mov PT_ES(%esp), %es
16174 PTGS_TO_GS
16175 ENABLE_INTERRUPTS_SYSEXIT
16176
16177 @@ -466,6 +650,9 @@ sysenter_audit:
16178 movl %eax,%edx /* 2nd arg: syscall number */
16179 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16180 call __audit_syscall_entry
16181 +
16182 + pax_erase_kstack
16183 +
16184 pushl_cfi %ebx
16185 movl PT_EAX(%esp),%eax /* reload syscall number */
16186 jmp sysenter_do_call
16187 @@ -491,10 +678,16 @@ sysexit_audit:
16188
16189 CFI_ENDPROC
16190 .pushsection .fixup,"ax"
16191 -2: movl $0,PT_FS(%esp)
16192 +4: movl $0,PT_FS(%esp)
16193 + jmp 1b
16194 +5: movl $0,PT_DS(%esp)
16195 + jmp 1b
16196 +6: movl $0,PT_ES(%esp)
16197 jmp 1b
16198 .popsection
16199 - _ASM_EXTABLE(1b,2b)
16200 + _ASM_EXTABLE(1b,4b)
16201 + _ASM_EXTABLE(2b,5b)
16202 + _ASM_EXTABLE(3b,6b)
16203 PTGS_TO_GS_EX
16204 ENDPROC(ia32_sysenter_target)
16205
16206 @@ -509,6 +702,11 @@ ENTRY(system_call)
16207 pushl_cfi %eax # save orig_eax
16208 SAVE_ALL
16209 GET_THREAD_INFO(%ebp)
16210 +
16211 +#ifdef CONFIG_PAX_RANDKSTACK
16212 + pax_erase_kstack
16213 +#endif
16214 +
16215 # system call tracing in operation / emulation
16216 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16217 jnz syscall_trace_entry
16218 @@ -527,6 +725,15 @@ syscall_exit:
16219 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16220 jne syscall_exit_work
16221
16222 +restore_all_pax:
16223 +
16224 +#ifdef CONFIG_PAX_RANDKSTACK
16225 + movl %esp, %eax
16226 + call pax_randomize_kstack
16227 +#endif
16228 +
16229 + pax_erase_kstack
16230 +
16231 restore_all:
16232 TRACE_IRQS_IRET
16233 restore_all_notrace:
16234 @@ -583,14 +790,34 @@ ldt_ss:
16235 * compensating for the offset by changing to the ESPFIX segment with
16236 * a base address that matches for the difference.
16237 */
16238 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16239 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16240 mov %esp, %edx /* load kernel esp */
16241 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16242 mov %dx, %ax /* eax: new kernel esp */
16243 sub %eax, %edx /* offset (low word is 0) */
16244 +#ifdef CONFIG_SMP
16245 + movl PER_CPU_VAR(cpu_number), %ebx
16246 + shll $PAGE_SHIFT_asm, %ebx
16247 + addl $cpu_gdt_table, %ebx
16248 +#else
16249 + movl $cpu_gdt_table, %ebx
16250 +#endif
16251 shr $16, %edx
16252 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16253 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16254 +
16255 +#ifdef CONFIG_PAX_KERNEXEC
16256 + mov %cr0, %esi
16257 + btr $16, %esi
16258 + mov %esi, %cr0
16259 +#endif
16260 +
16261 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16262 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16263 +
16264 +#ifdef CONFIG_PAX_KERNEXEC
16265 + bts $16, %esi
16266 + mov %esi, %cr0
16267 +#endif
16268 +
16269 pushl_cfi $__ESPFIX_SS
16270 pushl_cfi %eax /* new kernel esp */
16271 /* Disable interrupts, but do not irqtrace this section: we
16272 @@ -619,20 +846,18 @@ work_resched:
16273 movl TI_flags(%ebp), %ecx
16274 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16275 # than syscall tracing?
16276 - jz restore_all
16277 + jz restore_all_pax
16278 testb $_TIF_NEED_RESCHED, %cl
16279 jnz work_resched
16280
16281 work_notifysig: # deal with pending signals and
16282 # notify-resume requests
16283 + movl %esp, %eax
16284 #ifdef CONFIG_VM86
16285 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16286 - movl %esp, %eax
16287 jne work_notifysig_v86 # returning to kernel-space or
16288 # vm86-space
16289 1:
16290 -#else
16291 - movl %esp, %eax
16292 #endif
16293 TRACE_IRQS_ON
16294 ENABLE_INTERRUPTS(CLBR_NONE)
16295 @@ -653,7 +878,7 @@ work_notifysig_v86:
16296 movl %eax, %esp
16297 jmp 1b
16298 #endif
16299 -END(work_pending)
16300 +ENDPROC(work_pending)
16301
16302 # perform syscall exit tracing
16303 ALIGN
16304 @@ -661,11 +886,14 @@ syscall_trace_entry:
16305 movl $-ENOSYS,PT_EAX(%esp)
16306 movl %esp, %eax
16307 call syscall_trace_enter
16308 +
16309 + pax_erase_kstack
16310 +
16311 /* What it returned is what we'll actually use. */
16312 cmpl $(NR_syscalls), %eax
16313 jnae syscall_call
16314 jmp syscall_exit
16315 -END(syscall_trace_entry)
16316 +ENDPROC(syscall_trace_entry)
16317
16318 # perform syscall exit tracing
16319 ALIGN
16320 @@ -678,21 +906,25 @@ syscall_exit_work:
16321 movl %esp, %eax
16322 call syscall_trace_leave
16323 jmp resume_userspace
16324 -END(syscall_exit_work)
16325 +ENDPROC(syscall_exit_work)
16326 CFI_ENDPROC
16327
16328 RING0_INT_FRAME # can't unwind into user space anyway
16329 syscall_fault:
16330 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16331 + push %ss
16332 + pop %ds
16333 +#endif
16334 ASM_CLAC
16335 GET_THREAD_INFO(%ebp)
16336 movl $-EFAULT,PT_EAX(%esp)
16337 jmp resume_userspace
16338 -END(syscall_fault)
16339 +ENDPROC(syscall_fault)
16340
16341 syscall_badsys:
16342 movl $-ENOSYS,PT_EAX(%esp)
16343 jmp resume_userspace
16344 -END(syscall_badsys)
16345 +ENDPROC(syscall_badsys)
16346 CFI_ENDPROC
16347 /*
16348 * End of kprobes section
16349 @@ -763,6 +995,36 @@ ENTRY(ptregs_clone)
16350 CFI_ENDPROC
16351 ENDPROC(ptregs_clone)
16352
16353 + ALIGN;
16354 +ENTRY(kernel_execve)
16355 + CFI_STARTPROC
16356 + pushl_cfi %ebp
16357 + sub $PT_OLDSS+4,%esp
16358 + pushl_cfi %edi
16359 + pushl_cfi %ecx
16360 + pushl_cfi %eax
16361 + lea 3*4(%esp),%edi
16362 + mov $PT_OLDSS/4+1,%ecx
16363 + xorl %eax,%eax
16364 + rep stosl
16365 + popl_cfi %eax
16366 + popl_cfi %ecx
16367 + popl_cfi %edi
16368 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
16369 + pushl_cfi %esp
16370 + call sys_execve
16371 + add $4,%esp
16372 + CFI_ADJUST_CFA_OFFSET -4
16373 + GET_THREAD_INFO(%ebp)
16374 + test %eax,%eax
16375 + jz syscall_exit
16376 + add $PT_OLDSS+4,%esp
16377 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
16378 + popl_cfi %ebp
16379 + ret
16380 + CFI_ENDPROC
16381 +ENDPROC(kernel_execve)
16382 +
16383 .macro FIXUP_ESPFIX_STACK
16384 /*
16385 * Switch back for ESPFIX stack to the normal zerobased stack
16386 @@ -772,8 +1034,15 @@ ENDPROC(ptregs_clone)
16387 * normal stack and adjusts ESP with the matching offset.
16388 */
16389 /* fixup the stack */
16390 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16391 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16392 +#ifdef CONFIG_SMP
16393 + movl PER_CPU_VAR(cpu_number), %ebx
16394 + shll $PAGE_SHIFT_asm, %ebx
16395 + addl $cpu_gdt_table, %ebx
16396 +#else
16397 + movl $cpu_gdt_table, %ebx
16398 +#endif
16399 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16400 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16401 shl $16, %eax
16402 addl %esp, %eax /* the adjusted stack pointer */
16403 pushl_cfi $__KERNEL_DS
16404 @@ -826,7 +1095,7 @@ vector=vector+1
16405 .endr
16406 2: jmp common_interrupt
16407 .endr
16408 -END(irq_entries_start)
16409 +ENDPROC(irq_entries_start)
16410
16411 .previous
16412 END(interrupt)
16413 @@ -877,7 +1146,7 @@ ENTRY(coprocessor_error)
16414 pushl_cfi $do_coprocessor_error
16415 jmp error_code
16416 CFI_ENDPROC
16417 -END(coprocessor_error)
16418 +ENDPROC(coprocessor_error)
16419
16420 ENTRY(simd_coprocessor_error)
16421 RING0_INT_FRAME
16422 @@ -899,7 +1168,7 @@ ENTRY(simd_coprocessor_error)
16423 #endif
16424 jmp error_code
16425 CFI_ENDPROC
16426 -END(simd_coprocessor_error)
16427 +ENDPROC(simd_coprocessor_error)
16428
16429 ENTRY(device_not_available)
16430 RING0_INT_FRAME
16431 @@ -908,18 +1177,18 @@ ENTRY(device_not_available)
16432 pushl_cfi $do_device_not_available
16433 jmp error_code
16434 CFI_ENDPROC
16435 -END(device_not_available)
16436 +ENDPROC(device_not_available)
16437
16438 #ifdef CONFIG_PARAVIRT
16439 ENTRY(native_iret)
16440 iret
16441 _ASM_EXTABLE(native_iret, iret_exc)
16442 -END(native_iret)
16443 +ENDPROC(native_iret)
16444
16445 ENTRY(native_irq_enable_sysexit)
16446 sti
16447 sysexit
16448 -END(native_irq_enable_sysexit)
16449 +ENDPROC(native_irq_enable_sysexit)
16450 #endif
16451
16452 ENTRY(overflow)
16453 @@ -929,7 +1198,7 @@ ENTRY(overflow)
16454 pushl_cfi $do_overflow
16455 jmp error_code
16456 CFI_ENDPROC
16457 -END(overflow)
16458 +ENDPROC(overflow)
16459
16460 ENTRY(bounds)
16461 RING0_INT_FRAME
16462 @@ -938,7 +1207,7 @@ ENTRY(bounds)
16463 pushl_cfi $do_bounds
16464 jmp error_code
16465 CFI_ENDPROC
16466 -END(bounds)
16467 +ENDPROC(bounds)
16468
16469 ENTRY(invalid_op)
16470 RING0_INT_FRAME
16471 @@ -947,7 +1216,7 @@ ENTRY(invalid_op)
16472 pushl_cfi $do_invalid_op
16473 jmp error_code
16474 CFI_ENDPROC
16475 -END(invalid_op)
16476 +ENDPROC(invalid_op)
16477
16478 ENTRY(coprocessor_segment_overrun)
16479 RING0_INT_FRAME
16480 @@ -956,7 +1225,7 @@ ENTRY(coprocessor_segment_overrun)
16481 pushl_cfi $do_coprocessor_segment_overrun
16482 jmp error_code
16483 CFI_ENDPROC
16484 -END(coprocessor_segment_overrun)
16485 +ENDPROC(coprocessor_segment_overrun)
16486
16487 ENTRY(invalid_TSS)
16488 RING0_EC_FRAME
16489 @@ -964,7 +1233,7 @@ ENTRY(invalid_TSS)
16490 pushl_cfi $do_invalid_TSS
16491 jmp error_code
16492 CFI_ENDPROC
16493 -END(invalid_TSS)
16494 +ENDPROC(invalid_TSS)
16495
16496 ENTRY(segment_not_present)
16497 RING0_EC_FRAME
16498 @@ -972,7 +1241,7 @@ ENTRY(segment_not_present)
16499 pushl_cfi $do_segment_not_present
16500 jmp error_code
16501 CFI_ENDPROC
16502 -END(segment_not_present)
16503 +ENDPROC(segment_not_present)
16504
16505 ENTRY(stack_segment)
16506 RING0_EC_FRAME
16507 @@ -980,7 +1249,7 @@ ENTRY(stack_segment)
16508 pushl_cfi $do_stack_segment
16509 jmp error_code
16510 CFI_ENDPROC
16511 -END(stack_segment)
16512 +ENDPROC(stack_segment)
16513
16514 ENTRY(alignment_check)
16515 RING0_EC_FRAME
16516 @@ -988,7 +1257,7 @@ ENTRY(alignment_check)
16517 pushl_cfi $do_alignment_check
16518 jmp error_code
16519 CFI_ENDPROC
16520 -END(alignment_check)
16521 +ENDPROC(alignment_check)
16522
16523 ENTRY(divide_error)
16524 RING0_INT_FRAME
16525 @@ -997,7 +1266,7 @@ ENTRY(divide_error)
16526 pushl_cfi $do_divide_error
16527 jmp error_code
16528 CFI_ENDPROC
16529 -END(divide_error)
16530 +ENDPROC(divide_error)
16531
16532 #ifdef CONFIG_X86_MCE
16533 ENTRY(machine_check)
16534 @@ -1007,7 +1276,7 @@ ENTRY(machine_check)
16535 pushl_cfi machine_check_vector
16536 jmp error_code
16537 CFI_ENDPROC
16538 -END(machine_check)
16539 +ENDPROC(machine_check)
16540 #endif
16541
16542 ENTRY(spurious_interrupt_bug)
16543 @@ -1017,7 +1286,7 @@ ENTRY(spurious_interrupt_bug)
16544 pushl_cfi $do_spurious_interrupt_bug
16545 jmp error_code
16546 CFI_ENDPROC
16547 -END(spurious_interrupt_bug)
16548 +ENDPROC(spurious_interrupt_bug)
16549 /*
16550 * End of kprobes section
16551 */
16552 @@ -1121,7 +1390,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16553
16554 ENTRY(mcount)
16555 ret
16556 -END(mcount)
16557 +ENDPROC(mcount)
16558
16559 ENTRY(ftrace_caller)
16560 cmpl $0, function_trace_stop
16561 @@ -1154,7 +1423,7 @@ ftrace_graph_call:
16562 .globl ftrace_stub
16563 ftrace_stub:
16564 ret
16565 -END(ftrace_caller)
16566 +ENDPROC(ftrace_caller)
16567
16568 ENTRY(ftrace_regs_caller)
16569 pushf /* push flags before compare (in cs location) */
16570 @@ -1255,7 +1524,7 @@ trace:
16571 popl %ecx
16572 popl %eax
16573 jmp ftrace_stub
16574 -END(mcount)
16575 +ENDPROC(mcount)
16576 #endif /* CONFIG_DYNAMIC_FTRACE */
16577 #endif /* CONFIG_FUNCTION_TRACER */
16578
16579 @@ -1273,7 +1542,7 @@ ENTRY(ftrace_graph_caller)
16580 popl %ecx
16581 popl %eax
16582 ret
16583 -END(ftrace_graph_caller)
16584 +ENDPROC(ftrace_graph_caller)
16585
16586 .globl return_to_handler
16587 return_to_handler:
16588 @@ -1329,15 +1598,18 @@ error_code:
16589 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16590 REG_TO_PTGS %ecx
16591 SET_KERNEL_GS %ecx
16592 - movl $(__USER_DS), %ecx
16593 + movl $(__KERNEL_DS), %ecx
16594 movl %ecx, %ds
16595 movl %ecx, %es
16596 +
16597 + pax_enter_kernel
16598 +
16599 TRACE_IRQS_OFF
16600 movl %esp,%eax # pt_regs pointer
16601 call *%edi
16602 jmp ret_from_exception
16603 CFI_ENDPROC
16604 -END(page_fault)
16605 +ENDPROC(page_fault)
16606
16607 /*
16608 * Debug traps and NMI can happen at the one SYSENTER instruction
16609 @@ -1380,7 +1652,7 @@ debug_stack_correct:
16610 call do_debug
16611 jmp ret_from_exception
16612 CFI_ENDPROC
16613 -END(debug)
16614 +ENDPROC(debug)
16615
16616 /*
16617 * NMI is doubly nasty. It can happen _while_ we're handling
16618 @@ -1418,6 +1690,9 @@ nmi_stack_correct:
16619 xorl %edx,%edx # zero error code
16620 movl %esp,%eax # pt_regs pointer
16621 call do_nmi
16622 +
16623 + pax_exit_kernel
16624 +
16625 jmp restore_all_notrace
16626 CFI_ENDPROC
16627
16628 @@ -1454,12 +1729,15 @@ nmi_espfix_stack:
16629 FIXUP_ESPFIX_STACK # %eax == %esp
16630 xorl %edx,%edx # zero error code
16631 call do_nmi
16632 +
16633 + pax_exit_kernel
16634 +
16635 RESTORE_REGS
16636 lss 12+4(%esp), %esp # back to espfix stack
16637 CFI_ADJUST_CFA_OFFSET -24
16638 jmp irq_return
16639 CFI_ENDPROC
16640 -END(nmi)
16641 +ENDPROC(nmi)
16642
16643 ENTRY(int3)
16644 RING0_INT_FRAME
16645 @@ -1472,14 +1750,14 @@ ENTRY(int3)
16646 call do_int3
16647 jmp ret_from_exception
16648 CFI_ENDPROC
16649 -END(int3)
16650 +ENDPROC(int3)
16651
16652 ENTRY(general_protection)
16653 RING0_EC_FRAME
16654 pushl_cfi $do_general_protection
16655 jmp error_code
16656 CFI_ENDPROC
16657 -END(general_protection)
16658 +ENDPROC(general_protection)
16659
16660 #ifdef CONFIG_KVM_GUEST
16661 ENTRY(async_page_fault)
16662 @@ -1488,7 +1766,7 @@ ENTRY(async_page_fault)
16663 pushl_cfi $do_async_page_fault
16664 jmp error_code
16665 CFI_ENDPROC
16666 -END(async_page_fault)
16667 +ENDPROC(async_page_fault)
16668 #endif
16669
16670 /*
16671 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
16672 index 1328fe4..cb03298 100644
16673 --- a/arch/x86/kernel/entry_64.S
16674 +++ b/arch/x86/kernel/entry_64.S
16675 @@ -59,6 +59,8 @@
16676 #include <asm/rcu.h>
16677 #include <asm/smap.h>
16678 #include <linux/err.h>
16679 +#include <asm/pgtable.h>
16680 +#include <asm/alternative-asm.h>
16681
16682 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
16683 #include <linux/elf-em.h>
16684 @@ -80,8 +82,9 @@
16685 #ifdef CONFIG_DYNAMIC_FTRACE
16686
16687 ENTRY(function_hook)
16688 + pax_force_retaddr
16689 retq
16690 -END(function_hook)
16691 +ENDPROC(function_hook)
16692
16693 /* skip is set if stack has been adjusted */
16694 .macro ftrace_caller_setup skip=0
16695 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
16696 #endif
16697
16698 GLOBAL(ftrace_stub)
16699 + pax_force_retaddr
16700 retq
16701 -END(ftrace_caller)
16702 +ENDPROC(ftrace_caller)
16703
16704 ENTRY(ftrace_regs_caller)
16705 /* Save the current flags before compare (in SS location)*/
16706 @@ -191,7 +195,7 @@ ftrace_restore_flags:
16707 popfq
16708 jmp ftrace_stub
16709
16710 -END(ftrace_regs_caller)
16711 +ENDPROC(ftrace_regs_caller)
16712
16713
16714 #else /* ! CONFIG_DYNAMIC_FTRACE */
16715 @@ -212,6 +216,7 @@ ENTRY(function_hook)
16716 #endif
16717
16718 GLOBAL(ftrace_stub)
16719 + pax_force_retaddr
16720 retq
16721
16722 trace:
16723 @@ -225,12 +230,13 @@ trace:
16724 #endif
16725 subq $MCOUNT_INSN_SIZE, %rdi
16726
16727 + pax_force_fptr ftrace_trace_function
16728 call *ftrace_trace_function
16729
16730 MCOUNT_RESTORE_FRAME
16731
16732 jmp ftrace_stub
16733 -END(function_hook)
16734 +ENDPROC(function_hook)
16735 #endif /* CONFIG_DYNAMIC_FTRACE */
16736 #endif /* CONFIG_FUNCTION_TRACER */
16737
16738 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
16739
16740 MCOUNT_RESTORE_FRAME
16741
16742 + pax_force_retaddr
16743 retq
16744 -END(ftrace_graph_caller)
16745 +ENDPROC(ftrace_graph_caller)
16746
16747 GLOBAL(return_to_handler)
16748 subq $24, %rsp
16749 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
16750 movq 8(%rsp), %rdx
16751 movq (%rsp), %rax
16752 addq $24, %rsp
16753 + pax_force_fptr %rdi
16754 jmp *%rdi
16755 +ENDPROC(return_to_handler)
16756 #endif
16757
16758
16759 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
16760 ENDPROC(native_usergs_sysret64)
16761 #endif /* CONFIG_PARAVIRT */
16762
16763 + .macro ljmpq sel, off
16764 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
16765 + .byte 0x48; ljmp *1234f(%rip)
16766 + .pushsection .rodata
16767 + .align 16
16768 + 1234: .quad \off; .word \sel
16769 + .popsection
16770 +#else
16771 + pushq $\sel
16772 + pushq $\off
16773 + lretq
16774 +#endif
16775 + .endm
16776 +
16777 + .macro pax_enter_kernel
16778 + pax_set_fptr_mask
16779 +#ifdef CONFIG_PAX_KERNEXEC
16780 + call pax_enter_kernel
16781 +#endif
16782 + .endm
16783 +
16784 + .macro pax_exit_kernel
16785 +#ifdef CONFIG_PAX_KERNEXEC
16786 + call pax_exit_kernel
16787 +#endif
16788 + .endm
16789 +
16790 +#ifdef CONFIG_PAX_KERNEXEC
16791 +ENTRY(pax_enter_kernel)
16792 + pushq %rdi
16793 +
16794 +#ifdef CONFIG_PARAVIRT
16795 + PV_SAVE_REGS(CLBR_RDI)
16796 +#endif
16797 +
16798 + GET_CR0_INTO_RDI
16799 + bts $16,%rdi
16800 + jnc 3f
16801 + mov %cs,%edi
16802 + cmp $__KERNEL_CS,%edi
16803 + jnz 2f
16804 +1:
16805 +
16806 +#ifdef CONFIG_PARAVIRT
16807 + PV_RESTORE_REGS(CLBR_RDI)
16808 +#endif
16809 +
16810 + popq %rdi
16811 + pax_force_retaddr
16812 + retq
16813 +
16814 +2: ljmpq __KERNEL_CS,1f
16815 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
16816 +4: SET_RDI_INTO_CR0
16817 + jmp 1b
16818 +ENDPROC(pax_enter_kernel)
16819 +
16820 +ENTRY(pax_exit_kernel)
16821 + pushq %rdi
16822 +
16823 +#ifdef CONFIG_PARAVIRT
16824 + PV_SAVE_REGS(CLBR_RDI)
16825 +#endif
16826 +
16827 + mov %cs,%rdi
16828 + cmp $__KERNEXEC_KERNEL_CS,%edi
16829 + jz 2f
16830 +1:
16831 +
16832 +#ifdef CONFIG_PARAVIRT
16833 + PV_RESTORE_REGS(CLBR_RDI);
16834 +#endif
16835 +
16836 + popq %rdi
16837 + pax_force_retaddr
16838 + retq
16839 +
16840 +2: GET_CR0_INTO_RDI
16841 + btr $16,%rdi
16842 + ljmpq __KERNEL_CS,3f
16843 +3: SET_RDI_INTO_CR0
16844 + jmp 1b
16845 +ENDPROC(pax_exit_kernel)
16846 +#endif
16847 +
16848 + .macro pax_enter_kernel_user
16849 + pax_set_fptr_mask
16850 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16851 + call pax_enter_kernel_user
16852 +#endif
16853 + .endm
16854 +
16855 + .macro pax_exit_kernel_user
16856 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16857 + call pax_exit_kernel_user
16858 +#endif
16859 +#ifdef CONFIG_PAX_RANDKSTACK
16860 + pushq %rax
16861 + call pax_randomize_kstack
16862 + popq %rax
16863 +#endif
16864 + .endm
16865 +
16866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16867 +ENTRY(pax_enter_kernel_user)
16868 + pushq %rdi
16869 + pushq %rbx
16870 +
16871 +#ifdef CONFIG_PARAVIRT
16872 + PV_SAVE_REGS(CLBR_RDI)
16873 +#endif
16874 +
16875 + GET_CR3_INTO_RDI
16876 + mov %rdi,%rbx
16877 + add $__START_KERNEL_map,%rbx
16878 + sub phys_base(%rip),%rbx
16879 +
16880 +#ifdef CONFIG_PARAVIRT
16881 + pushq %rdi
16882 + cmpl $0, pv_info+PARAVIRT_enabled
16883 + jz 1f
16884 + i = 0
16885 + .rept USER_PGD_PTRS
16886 + mov i*8(%rbx),%rsi
16887 + mov $0,%sil
16888 + lea i*8(%rbx),%rdi
16889 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16890 + i = i + 1
16891 + .endr
16892 + jmp 2f
16893 +1:
16894 +#endif
16895 +
16896 + i = 0
16897 + .rept USER_PGD_PTRS
16898 + movb $0,i*8(%rbx)
16899 + i = i + 1
16900 + .endr
16901 +
16902 +#ifdef CONFIG_PARAVIRT
16903 +2: popq %rdi
16904 +#endif
16905 + SET_RDI_INTO_CR3
16906 +
16907 +#ifdef CONFIG_PAX_KERNEXEC
16908 + GET_CR0_INTO_RDI
16909 + bts $16,%rdi
16910 + SET_RDI_INTO_CR0
16911 +#endif
16912 +
16913 +#ifdef CONFIG_PARAVIRT
16914 + PV_RESTORE_REGS(CLBR_RDI)
16915 +#endif
16916 +
16917 + popq %rbx
16918 + popq %rdi
16919 + pax_force_retaddr
16920 + retq
16921 +ENDPROC(pax_enter_kernel_user)
16922 +
16923 +ENTRY(pax_exit_kernel_user)
16924 + push %rdi
16925 +
16926 +#ifdef CONFIG_PARAVIRT
16927 + pushq %rbx
16928 + PV_SAVE_REGS(CLBR_RDI)
16929 +#endif
16930 +
16931 +#ifdef CONFIG_PAX_KERNEXEC
16932 + GET_CR0_INTO_RDI
16933 + btr $16,%rdi
16934 + SET_RDI_INTO_CR0
16935 +#endif
16936 +
16937 + GET_CR3_INTO_RDI
16938 + add $__START_KERNEL_map,%rdi
16939 + sub phys_base(%rip),%rdi
16940 +
16941 +#ifdef CONFIG_PARAVIRT
16942 + cmpl $0, pv_info+PARAVIRT_enabled
16943 + jz 1f
16944 + mov %rdi,%rbx
16945 + i = 0
16946 + .rept USER_PGD_PTRS
16947 + mov i*8(%rbx),%rsi
16948 + mov $0x67,%sil
16949 + lea i*8(%rbx),%rdi
16950 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16951 + i = i + 1
16952 + .endr
16953 + jmp 2f
16954 +1:
16955 +#endif
16956 +
16957 + i = 0
16958 + .rept USER_PGD_PTRS
16959 + movb $0x67,i*8(%rdi)
16960 + i = i + 1
16961 + .endr
16962 +
16963 +#ifdef CONFIG_PARAVIRT
16964 +2: PV_RESTORE_REGS(CLBR_RDI)
16965 + popq %rbx
16966 +#endif
16967 +
16968 + popq %rdi
16969 + pax_force_retaddr
16970 + retq
16971 +ENDPROC(pax_exit_kernel_user)
16972 +#endif
16973 +
16974 +.macro pax_erase_kstack
16975 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16976 + call pax_erase_kstack
16977 +#endif
16978 +.endm
16979 +
16980 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16981 +ENTRY(pax_erase_kstack)
16982 + pushq %rdi
16983 + pushq %rcx
16984 + pushq %rax
16985 + pushq %r11
16986 +
16987 + GET_THREAD_INFO(%r11)
16988 + mov TI_lowest_stack(%r11), %rdi
16989 + mov $-0xBEEF, %rax
16990 + std
16991 +
16992 +1: mov %edi, %ecx
16993 + and $THREAD_SIZE_asm - 1, %ecx
16994 + shr $3, %ecx
16995 + repne scasq
16996 + jecxz 2f
16997 +
16998 + cmp $2*8, %ecx
16999 + jc 2f
17000 +
17001 + mov $2*8, %ecx
17002 + repe scasq
17003 + jecxz 2f
17004 + jne 1b
17005 +
17006 +2: cld
17007 + mov %esp, %ecx
17008 + sub %edi, %ecx
17009 +
17010 + cmp $THREAD_SIZE_asm, %rcx
17011 + jb 3f
17012 + ud2
17013 +3:
17014 +
17015 + shr $3, %ecx
17016 + rep stosq
17017 +
17018 + mov TI_task_thread_sp0(%r11), %rdi
17019 + sub $256, %rdi
17020 + mov %rdi, TI_lowest_stack(%r11)
17021 +
17022 + popq %r11
17023 + popq %rax
17024 + popq %rcx
17025 + popq %rdi
17026 + pax_force_retaddr
17027 + ret
17028 +ENDPROC(pax_erase_kstack)
17029 +#endif
17030
17031 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17032 #ifdef CONFIG_TRACE_IRQFLAGS
17033 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17034 .endm
17035
17036 .macro UNFAKE_STACK_FRAME
17037 - addq $8*6, %rsp
17038 - CFI_ADJUST_CFA_OFFSET -(6*8)
17039 + addq $8*6 + ARG_SKIP, %rsp
17040 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17041 .endm
17042
17043 /*
17044 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17045 movq %rsp, %rsi
17046
17047 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17048 - testl $3, CS-RBP(%rsi)
17049 + testb $3, CS-RBP(%rsi)
17050 je 1f
17051 SWAPGS
17052 /*
17053 @@ -498,9 +774,10 @@ ENTRY(save_rest)
17054 movq_cfi r15, R15+16
17055 movq %r11, 8(%rsp) /* return address */
17056 FIXUP_TOP_OF_STACK %r11, 16
17057 + pax_force_retaddr
17058 ret
17059 CFI_ENDPROC
17060 -END(save_rest)
17061 +ENDPROC(save_rest)
17062
17063 /* save complete stack frame */
17064 .pushsection .kprobes.text, "ax"
17065 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17066 js 1f /* negative -> in kernel */
17067 SWAPGS
17068 xorl %ebx,%ebx
17069 -1: ret
17070 +1: pax_force_retaddr_bts
17071 + ret
17072 CFI_ENDPROC
17073 -END(save_paranoid)
17074 +ENDPROC(save_paranoid)
17075 .popsection
17076
17077 /*
17078 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17079
17080 RESTORE_REST
17081
17082 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17083 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17084 jz 1f
17085
17086 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17087 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17088 RESTORE_REST
17089 jmp int_ret_from_sys_call
17090 CFI_ENDPROC
17091 -END(ret_from_fork)
17092 +ENDPROC(ret_from_fork)
17093
17094 /*
17095 * System call entry. Up to 6 arguments in registers are supported.
17096 @@ -608,7 +886,7 @@ END(ret_from_fork)
17097 ENTRY(system_call)
17098 CFI_STARTPROC simple
17099 CFI_SIGNAL_FRAME
17100 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17101 + CFI_DEF_CFA rsp,0
17102 CFI_REGISTER rip,rcx
17103 /*CFI_REGISTER rflags,r11*/
17104 SWAPGS_UNSAFE_STACK
17105 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17106
17107 movq %rsp,PER_CPU_VAR(old_rsp)
17108 movq PER_CPU_VAR(kernel_stack),%rsp
17109 + SAVE_ARGS 8*6,0
17110 + pax_enter_kernel_user
17111 +
17112 +#ifdef CONFIG_PAX_RANDKSTACK
17113 + pax_erase_kstack
17114 +#endif
17115 +
17116 /*
17117 * No need to follow this irqs off/on section - it's straight
17118 * and short:
17119 */
17120 ENABLE_INTERRUPTS(CLBR_NONE)
17121 - SAVE_ARGS 8,0
17122 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17123 movq %rcx,RIP-ARGOFFSET(%rsp)
17124 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17125 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17126 + GET_THREAD_INFO(%rcx)
17127 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17128 jnz tracesys
17129 system_call_fastpath:
17130 #if __SYSCALL_MASK == ~0
17131 @@ -640,7 +925,7 @@ system_call_fastpath:
17132 cmpl $__NR_syscall_max,%eax
17133 #endif
17134 ja badsys
17135 - movq %r10,%rcx
17136 + movq R10-ARGOFFSET(%rsp),%rcx
17137 call *sys_call_table(,%rax,8) # XXX: rip relative
17138 movq %rax,RAX-ARGOFFSET(%rsp)
17139 /*
17140 @@ -654,10 +939,13 @@ sysret_check:
17141 LOCKDEP_SYS_EXIT
17142 DISABLE_INTERRUPTS(CLBR_NONE)
17143 TRACE_IRQS_OFF
17144 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17145 + GET_THREAD_INFO(%rcx)
17146 + movl TI_flags(%rcx),%edx
17147 andl %edi,%edx
17148 jnz sysret_careful
17149 CFI_REMEMBER_STATE
17150 + pax_exit_kernel_user
17151 + pax_erase_kstack
17152 /*
17153 * sysretq will re-enable interrupts:
17154 */
17155 @@ -709,14 +997,18 @@ badsys:
17156 * jump back to the normal fast path.
17157 */
17158 auditsys:
17159 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
17160 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17161 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17162 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17163 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17164 movq %rax,%rsi /* 2nd arg: syscall number */
17165 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17166 call __audit_syscall_entry
17167 +
17168 + pax_erase_kstack
17169 +
17170 LOAD_ARGS 0 /* reload call-clobbered registers */
17171 + pax_set_fptr_mask
17172 jmp system_call_fastpath
17173
17174 /*
17175 @@ -737,7 +1029,7 @@ sysret_audit:
17176 /* Do syscall tracing */
17177 tracesys:
17178 #ifdef CONFIG_AUDITSYSCALL
17179 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17180 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17181 jz auditsys
17182 #endif
17183 SAVE_REST
17184 @@ -745,12 +1037,16 @@ tracesys:
17185 FIXUP_TOP_OF_STACK %rdi
17186 movq %rsp,%rdi
17187 call syscall_trace_enter
17188 +
17189 + pax_erase_kstack
17190 +
17191 /*
17192 * Reload arg registers from stack in case ptrace changed them.
17193 * We don't reload %rax because syscall_trace_enter() returned
17194 * the value it wants us to use in the table lookup.
17195 */
17196 LOAD_ARGS ARGOFFSET, 1
17197 + pax_set_fptr_mask
17198 RESTORE_REST
17199 #if __SYSCALL_MASK == ~0
17200 cmpq $__NR_syscall_max,%rax
17201 @@ -759,7 +1055,7 @@ tracesys:
17202 cmpl $__NR_syscall_max,%eax
17203 #endif
17204 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17205 - movq %r10,%rcx /* fixup for C */
17206 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17207 call *sys_call_table(,%rax,8)
17208 movq %rax,RAX-ARGOFFSET(%rsp)
17209 /* Use IRET because user could have changed frame */
17210 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17211 andl %edi,%edx
17212 jnz int_careful
17213 andl $~TS_COMPAT,TI_status(%rcx)
17214 - jmp retint_swapgs
17215 + pax_exit_kernel_user
17216 + pax_erase_kstack
17217 + jmp retint_swapgs_pax
17218
17219 /* Either reschedule or signal or syscall exit tracking needed. */
17220 /* First do a reschedule test. */
17221 @@ -826,7 +1124,7 @@ int_restore_rest:
17222 TRACE_IRQS_OFF
17223 jmp int_with_check
17224 CFI_ENDPROC
17225 -END(system_call)
17226 +ENDPROC(system_call)
17227
17228 /*
17229 * Certain special system calls that need to save a complete full stack frame.
17230 @@ -842,7 +1140,7 @@ ENTRY(\label)
17231 call \func
17232 jmp ptregscall_common
17233 CFI_ENDPROC
17234 -END(\label)
17235 +ENDPROC(\label)
17236 .endm
17237
17238 PTREGSCALL stub_clone, sys_clone, %r8
17239 @@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17240 movq_cfi_restore R12+8, r12
17241 movq_cfi_restore RBP+8, rbp
17242 movq_cfi_restore RBX+8, rbx
17243 + pax_force_retaddr
17244 ret $REST_SKIP /* pop extended registers */
17245 CFI_ENDPROC
17246 -END(ptregscall_common)
17247 +ENDPROC(ptregscall_common)
17248
17249 ENTRY(stub_execve)
17250 CFI_STARTPROC
17251 @@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17252 RESTORE_REST
17253 jmp int_ret_from_sys_call
17254 CFI_ENDPROC
17255 -END(stub_execve)
17256 +ENDPROC(stub_execve)
17257
17258 /*
17259 * sigreturn is special because it needs to restore all registers on return.
17260 @@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17261 RESTORE_REST
17262 jmp int_ret_from_sys_call
17263 CFI_ENDPROC
17264 -END(stub_rt_sigreturn)
17265 +ENDPROC(stub_rt_sigreturn)
17266
17267 #ifdef CONFIG_X86_X32_ABI
17268 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17269 @@ -962,7 +1261,7 @@ vector=vector+1
17270 2: jmp common_interrupt
17271 .endr
17272 CFI_ENDPROC
17273 -END(irq_entries_start)
17274 +ENDPROC(irq_entries_start)
17275
17276 .previous
17277 END(interrupt)
17278 @@ -982,6 +1281,16 @@ END(interrupt)
17279 subq $ORIG_RAX-RBP, %rsp
17280 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17281 SAVE_ARGS_IRQ
17282 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17283 + testb $3, CS(%rdi)
17284 + jnz 1f
17285 + pax_enter_kernel
17286 + jmp 2f
17287 +1: pax_enter_kernel_user
17288 +2:
17289 +#else
17290 + pax_enter_kernel
17291 +#endif
17292 call \func
17293 .endm
17294
17295 @@ -1014,7 +1323,7 @@ ret_from_intr:
17296
17297 exit_intr:
17298 GET_THREAD_INFO(%rcx)
17299 - testl $3,CS-ARGOFFSET(%rsp)
17300 + testb $3,CS-ARGOFFSET(%rsp)
17301 je retint_kernel
17302
17303 /* Interrupt came from user space */
17304 @@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17305 * The iretq could re-enable interrupts:
17306 */
17307 DISABLE_INTERRUPTS(CLBR_ANY)
17308 + pax_exit_kernel_user
17309 +retint_swapgs_pax:
17310 TRACE_IRQS_IRETQ
17311 SWAPGS
17312 jmp restore_args
17313
17314 retint_restore_args: /* return to kernel space */
17315 DISABLE_INTERRUPTS(CLBR_ANY)
17316 + pax_exit_kernel
17317 + pax_force_retaddr (RIP-ARGOFFSET)
17318 /*
17319 * The iretq could re-enable interrupts:
17320 */
17321 @@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17322 #endif
17323
17324 CFI_ENDPROC
17325 -END(common_interrupt)
17326 +ENDPROC(common_interrupt)
17327 /*
17328 * End of kprobes section
17329 */
17330 @@ -1142,7 +1455,7 @@ ENTRY(\sym)
17331 interrupt \do_sym
17332 jmp ret_from_intr
17333 CFI_ENDPROC
17334 -END(\sym)
17335 +ENDPROC(\sym)
17336 .endm
17337
17338 #ifdef CONFIG_SMP
17339 @@ -1198,12 +1511,22 @@ ENTRY(\sym)
17340 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17341 call error_entry
17342 DEFAULT_FRAME 0
17343 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17344 + testb $3, CS(%rsp)
17345 + jnz 1f
17346 + pax_enter_kernel
17347 + jmp 2f
17348 +1: pax_enter_kernel_user
17349 +2:
17350 +#else
17351 + pax_enter_kernel
17352 +#endif
17353 movq %rsp,%rdi /* pt_regs pointer */
17354 xorl %esi,%esi /* no error code */
17355 call \do_sym
17356 jmp error_exit /* %ebx: no swapgs flag */
17357 CFI_ENDPROC
17358 -END(\sym)
17359 +ENDPROC(\sym)
17360 .endm
17361
17362 .macro paranoidzeroentry sym do_sym
17363 @@ -1216,15 +1539,25 @@ ENTRY(\sym)
17364 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17365 call save_paranoid
17366 TRACE_IRQS_OFF
17367 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17368 + testb $3, CS(%rsp)
17369 + jnz 1f
17370 + pax_enter_kernel
17371 + jmp 2f
17372 +1: pax_enter_kernel_user
17373 +2:
17374 +#else
17375 + pax_enter_kernel
17376 +#endif
17377 movq %rsp,%rdi /* pt_regs pointer */
17378 xorl %esi,%esi /* no error code */
17379 call \do_sym
17380 jmp paranoid_exit /* %ebx: no swapgs flag */
17381 CFI_ENDPROC
17382 -END(\sym)
17383 +ENDPROC(\sym)
17384 .endm
17385
17386 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17387 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17388 .macro paranoidzeroentry_ist sym do_sym ist
17389 ENTRY(\sym)
17390 INTR_FRAME
17391 @@ -1235,14 +1568,30 @@ ENTRY(\sym)
17392 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17393 call save_paranoid
17394 TRACE_IRQS_OFF_DEBUG
17395 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17396 + testb $3, CS(%rsp)
17397 + jnz 1f
17398 + pax_enter_kernel
17399 + jmp 2f
17400 +1: pax_enter_kernel_user
17401 +2:
17402 +#else
17403 + pax_enter_kernel
17404 +#endif
17405 movq %rsp,%rdi /* pt_regs pointer */
17406 xorl %esi,%esi /* no error code */
17407 +#ifdef CONFIG_SMP
17408 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17409 + lea init_tss(%r12), %r12
17410 +#else
17411 + lea init_tss(%rip), %r12
17412 +#endif
17413 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17414 call \do_sym
17415 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17416 jmp paranoid_exit /* %ebx: no swapgs flag */
17417 CFI_ENDPROC
17418 -END(\sym)
17419 +ENDPROC(\sym)
17420 .endm
17421
17422 .macro errorentry sym do_sym
17423 @@ -1254,13 +1603,23 @@ ENTRY(\sym)
17424 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17425 call error_entry
17426 DEFAULT_FRAME 0
17427 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17428 + testb $3, CS(%rsp)
17429 + jnz 1f
17430 + pax_enter_kernel
17431 + jmp 2f
17432 +1: pax_enter_kernel_user
17433 +2:
17434 +#else
17435 + pax_enter_kernel
17436 +#endif
17437 movq %rsp,%rdi /* pt_regs pointer */
17438 movq ORIG_RAX(%rsp),%rsi /* get error code */
17439 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17440 call \do_sym
17441 jmp error_exit /* %ebx: no swapgs flag */
17442 CFI_ENDPROC
17443 -END(\sym)
17444 +ENDPROC(\sym)
17445 .endm
17446
17447 /* error code is on the stack already */
17448 @@ -1274,13 +1633,23 @@ ENTRY(\sym)
17449 call save_paranoid
17450 DEFAULT_FRAME 0
17451 TRACE_IRQS_OFF
17452 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17453 + testb $3, CS(%rsp)
17454 + jnz 1f
17455 + pax_enter_kernel
17456 + jmp 2f
17457 +1: pax_enter_kernel_user
17458 +2:
17459 +#else
17460 + pax_enter_kernel
17461 +#endif
17462 movq %rsp,%rdi /* pt_regs pointer */
17463 movq ORIG_RAX(%rsp),%rsi /* get error code */
17464 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17465 call \do_sym
17466 jmp paranoid_exit /* %ebx: no swapgs flag */
17467 CFI_ENDPROC
17468 -END(\sym)
17469 +ENDPROC(\sym)
17470 .endm
17471
17472 zeroentry divide_error do_divide_error
17473 @@ -1310,9 +1679,10 @@ gs_change:
17474 2: mfence /* workaround */
17475 SWAPGS
17476 popfq_cfi
17477 + pax_force_retaddr
17478 ret
17479 CFI_ENDPROC
17480 -END(native_load_gs_index)
17481 +ENDPROC(native_load_gs_index)
17482
17483 _ASM_EXTABLE(gs_change,bad_gs)
17484 .section .fixup,"ax"
17485 @@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17486 CFI_DEF_CFA_REGISTER rsp
17487 CFI_ADJUST_CFA_OFFSET -8
17488 decl PER_CPU_VAR(irq_count)
17489 + pax_force_retaddr
17490 ret
17491 CFI_ENDPROC
17492 -END(call_softirq)
17493 +ENDPROC(call_softirq)
17494
17495 #ifdef CONFIG_XEN
17496 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17497 @@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17498 decl PER_CPU_VAR(irq_count)
17499 jmp error_exit
17500 CFI_ENDPROC
17501 -END(xen_do_hypervisor_callback)
17502 +ENDPROC(xen_do_hypervisor_callback)
17503
17504 /*
17505 * Hypervisor uses this for application faults while it executes.
17506 @@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17507 SAVE_ALL
17508 jmp error_exit
17509 CFI_ENDPROC
17510 -END(xen_failsafe_callback)
17511 +ENDPROC(xen_failsafe_callback)
17512
17513 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17514 xen_hvm_callback_vector xen_evtchn_do_upcall
17515 @@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17516 TRACE_IRQS_OFF_DEBUG
17517 testl %ebx,%ebx /* swapgs needed? */
17518 jnz paranoid_restore
17519 - testl $3,CS(%rsp)
17520 + testb $3,CS(%rsp)
17521 jnz paranoid_userspace
17522 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17523 + pax_exit_kernel
17524 + TRACE_IRQS_IRETQ 0
17525 + SWAPGS_UNSAFE_STACK
17526 + RESTORE_ALL 8
17527 + pax_force_retaddr_bts
17528 + jmp irq_return
17529 +#endif
17530 paranoid_swapgs:
17531 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17532 + pax_exit_kernel_user
17533 +#else
17534 + pax_exit_kernel
17535 +#endif
17536 TRACE_IRQS_IRETQ 0
17537 SWAPGS_UNSAFE_STACK
17538 RESTORE_ALL 8
17539 jmp irq_return
17540 paranoid_restore:
17541 + pax_exit_kernel
17542 TRACE_IRQS_IRETQ_DEBUG 0
17543 RESTORE_ALL 8
17544 + pax_force_retaddr_bts
17545 jmp irq_return
17546 paranoid_userspace:
17547 GET_THREAD_INFO(%rcx)
17548 @@ -1526,7 +1912,7 @@ paranoid_schedule:
17549 TRACE_IRQS_OFF
17550 jmp paranoid_userspace
17551 CFI_ENDPROC
17552 -END(paranoid_exit)
17553 +ENDPROC(paranoid_exit)
17554
17555 /*
17556 * Exception entry point. This expects an error code/orig_rax on the stack.
17557 @@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17558 movq_cfi r14, R14+8
17559 movq_cfi r15, R15+8
17560 xorl %ebx,%ebx
17561 - testl $3,CS+8(%rsp)
17562 + testb $3,CS+8(%rsp)
17563 je error_kernelspace
17564 error_swapgs:
17565 SWAPGS
17566 error_sti:
17567 TRACE_IRQS_OFF
17568 + pax_force_retaddr_bts
17569 ret
17570
17571 /*
17572 @@ -1585,7 +1972,7 @@ bstep_iret:
17573 movq %rcx,RIP+8(%rsp)
17574 jmp error_swapgs
17575 CFI_ENDPROC
17576 -END(error_entry)
17577 +ENDPROC(error_entry)
17578
17579
17580 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17581 @@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17582 jnz retint_careful
17583 jmp retint_swapgs
17584 CFI_ENDPROC
17585 -END(error_exit)
17586 +ENDPROC(error_exit)
17587
17588 /*
17589 * Test if a given stack is an NMI stack or not.
17590 @@ -1663,9 +2050,11 @@ ENTRY(nmi)
17591 * If %cs was not the kernel segment, then the NMI triggered in user
17592 * space, which means it is definitely not nested.
17593 */
17594 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17595 + je 1f
17596 cmpl $__KERNEL_CS, 16(%rsp)
17597 jne first_nmi
17598 -
17599 +1:
17600 /*
17601 * Check the special variable on the stack to see if NMIs are
17602 * executing.
17603 @@ -1824,6 +2213,17 @@ end_repeat_nmi:
17604 */
17605 movq %cr2, %r12
17606
17607 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17608 + testb $3, CS(%rsp)
17609 + jnz 1f
17610 + pax_enter_kernel
17611 + jmp 2f
17612 +1: pax_enter_kernel_user
17613 +2:
17614 +#else
17615 + pax_enter_kernel
17616 +#endif
17617 +
17618 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
17619 movq %rsp,%rdi
17620 movq $-1,%rsi
17621 @@ -1839,21 +2239,32 @@ end_repeat_nmi:
17622 testl %ebx,%ebx /* swapgs needed? */
17623 jnz nmi_restore
17624 nmi_swapgs:
17625 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17626 + pax_exit_kernel_user
17627 +#else
17628 + pax_exit_kernel
17629 +#endif
17630 SWAPGS_UNSAFE_STACK
17631 + RESTORE_ALL 8
17632 + /* Clear the NMI executing stack variable */
17633 + movq $0, 10*8(%rsp)
17634 + jmp irq_return
17635 nmi_restore:
17636 + pax_exit_kernel
17637 RESTORE_ALL 8
17638 + pax_force_retaddr_bts
17639 /* Clear the NMI executing stack variable */
17640 movq $0, 10*8(%rsp)
17641 jmp irq_return
17642 CFI_ENDPROC
17643 -END(nmi)
17644 +ENDPROC(nmi)
17645
17646 ENTRY(ignore_sysret)
17647 CFI_STARTPROC
17648 mov $-ENOSYS,%eax
17649 sysret
17650 CFI_ENDPROC
17651 -END(ignore_sysret)
17652 +ENDPROC(ignore_sysret)
17653
17654 /*
17655 * End of kprobes section
17656 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
17657 index 1d41402..af9a46a 100644
17658 --- a/arch/x86/kernel/ftrace.c
17659 +++ b/arch/x86/kernel/ftrace.c
17660 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
17661 {
17662 unsigned char replaced[MCOUNT_INSN_SIZE];
17663
17664 + ip = ktla_ktva(ip);
17665 +
17666 /*
17667 * Note: Due to modules and __init, code can
17668 * disappear and change, we need to protect against faulting
17669 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17670 unsigned char old[MCOUNT_INSN_SIZE], *new;
17671 int ret;
17672
17673 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
17674 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
17675 new = ftrace_call_replace(ip, (unsigned long)func);
17676
17677 /* See comment above by declaration of modifying_ftrace_code */
17678 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17679 /* Also update the regs callback function */
17680 if (!ret) {
17681 ip = (unsigned long)(&ftrace_regs_call);
17682 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
17683 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
17684 new = ftrace_call_replace(ip, (unsigned long)func);
17685 ret = ftrace_modify_code(ip, old, new);
17686 }
17687 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
17688 * kernel identity mapping to modify code.
17689 */
17690 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
17691 - ip = (unsigned long)__va(__pa(ip));
17692 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
17693
17694 return probe_kernel_write((void *)ip, val, size);
17695 }
17696 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
17697 unsigned char replaced[MCOUNT_INSN_SIZE];
17698 unsigned char brk = BREAKPOINT_INSTRUCTION;
17699
17700 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
17701 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
17702 return -EFAULT;
17703
17704 /* Make sure it is what we expect it to be */
17705 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
17706 return ret;
17707
17708 fail_update:
17709 - probe_kernel_write((void *)ip, &old_code[0], 1);
17710 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
17711 goto out;
17712 }
17713
17714 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
17715 {
17716 unsigned char code[MCOUNT_INSN_SIZE];
17717
17718 + ip = ktla_ktva(ip);
17719 +
17720 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
17721 return -EFAULT;
17722
17723 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
17724 index c18f59d..69ddbc4 100644
17725 --- a/arch/x86/kernel/head32.c
17726 +++ b/arch/x86/kernel/head32.c
17727 @@ -18,20 +18,20 @@
17728 #include <asm/io_apic.h>
17729 #include <asm/bios_ebda.h>
17730 #include <asm/tlbflush.h>
17731 +#include <asm/boot.h>
17732
17733 static void __init i386_default_early_setup(void)
17734 {
17735 /* Initialize 32bit specific setup functions */
17736 - x86_init.resources.reserve_resources = i386_reserve_resources;
17737 - x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
17738 + *(void **)&x86_init.resources.reserve_resources = i386_reserve_resources;
17739 + *(void **)&x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
17740
17741 reserve_ebda_region();
17742 }
17743
17744 void __init i386_start_kernel(void)
17745 {
17746 - memblock_reserve(__pa_symbol(&_text),
17747 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
17748 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
17749
17750 #ifdef CONFIG_BLK_DEV_INITRD
17751 /* Reserve INITRD */
17752 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
17753 index 4dac2f6..bc6a335 100644
17754 --- a/arch/x86/kernel/head_32.S
17755 +++ b/arch/x86/kernel/head_32.S
17756 @@ -26,6 +26,12 @@
17757 /* Physical address */
17758 #define pa(X) ((X) - __PAGE_OFFSET)
17759
17760 +#ifdef CONFIG_PAX_KERNEXEC
17761 +#define ta(X) (X)
17762 +#else
17763 +#define ta(X) ((X) - __PAGE_OFFSET)
17764 +#endif
17765 +
17766 /*
17767 * References to members of the new_cpu_data structure.
17768 */
17769 @@ -55,11 +61,7 @@
17770 * and small than max_low_pfn, otherwise will waste some page table entries
17771 */
17772
17773 -#if PTRS_PER_PMD > 1
17774 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
17775 -#else
17776 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
17777 -#endif
17778 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
17779
17780 /* Number of possible pages in the lowmem region */
17781 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
17782 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
17783 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
17784
17785 /*
17786 + * Real beginning of normal "text" segment
17787 + */
17788 +ENTRY(stext)
17789 +ENTRY(_stext)
17790 +
17791 +/*
17792 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
17793 * %esi points to the real-mode code as a 32-bit pointer.
17794 * CS and DS must be 4 GB flat segments, but we don't depend on
17795 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
17796 * can.
17797 */
17798 __HEAD
17799 +
17800 +#ifdef CONFIG_PAX_KERNEXEC
17801 + jmp startup_32
17802 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
17803 +.fill PAGE_SIZE-5,1,0xcc
17804 +#endif
17805 +
17806 ENTRY(startup_32)
17807 movl pa(stack_start),%ecx
17808
17809 @@ -106,6 +121,59 @@ ENTRY(startup_32)
17810 2:
17811 leal -__PAGE_OFFSET(%ecx),%esp
17812
17813 +#ifdef CONFIG_SMP
17814 + movl $pa(cpu_gdt_table),%edi
17815 + movl $__per_cpu_load,%eax
17816 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
17817 + rorl $16,%eax
17818 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
17819 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
17820 + movl $__per_cpu_end - 1,%eax
17821 + subl $__per_cpu_start,%eax
17822 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
17823 +#endif
17824 +
17825 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17826 + movl $NR_CPUS,%ecx
17827 + movl $pa(cpu_gdt_table),%edi
17828 +1:
17829 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
17830 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
17831 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
17832 + addl $PAGE_SIZE_asm,%edi
17833 + loop 1b
17834 +#endif
17835 +
17836 +#ifdef CONFIG_PAX_KERNEXEC
17837 + movl $pa(boot_gdt),%edi
17838 + movl $__LOAD_PHYSICAL_ADDR,%eax
17839 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
17840 + rorl $16,%eax
17841 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
17842 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
17843 + rorl $16,%eax
17844 +
17845 + ljmp $(__BOOT_CS),$1f
17846 +1:
17847 +
17848 + movl $NR_CPUS,%ecx
17849 + movl $pa(cpu_gdt_table),%edi
17850 + addl $__PAGE_OFFSET,%eax
17851 +1:
17852 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
17853 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
17854 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
17855 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
17856 + rorl $16,%eax
17857 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
17858 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
17859 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
17860 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
17861 + rorl $16,%eax
17862 + addl $PAGE_SIZE_asm,%edi
17863 + loop 1b
17864 +#endif
17865 +
17866 /*
17867 * Clear BSS first so that there are no surprises...
17868 */
17869 @@ -196,8 +264,11 @@ ENTRY(startup_32)
17870 movl %eax, pa(max_pfn_mapped)
17871
17872 /* Do early initialization of the fixmap area */
17873 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17874 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
17875 +#ifdef CONFIG_COMPAT_VDSO
17876 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
17877 +#else
17878 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
17879 +#endif
17880 #else /* Not PAE */
17881
17882 page_pde_offset = (__PAGE_OFFSET >> 20);
17883 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17884 movl %eax, pa(max_pfn_mapped)
17885
17886 /* Do early initialization of the fixmap area */
17887 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17888 - movl %eax,pa(initial_page_table+0xffc)
17889 +#ifdef CONFIG_COMPAT_VDSO
17890 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17891 +#else
17892 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17893 +#endif
17894 #endif
17895
17896 #ifdef CONFIG_PARAVIRT
17897 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17898 cmpl $num_subarch_entries, %eax
17899 jae bad_subarch
17900
17901 - movl pa(subarch_entries)(,%eax,4), %eax
17902 - subl $__PAGE_OFFSET, %eax
17903 - jmp *%eax
17904 + jmp *pa(subarch_entries)(,%eax,4)
17905
17906 bad_subarch:
17907 WEAK(lguest_entry)
17908 @@ -256,10 +328,10 @@ WEAK(xen_entry)
17909 __INITDATA
17910
17911 subarch_entries:
17912 - .long default_entry /* normal x86/PC */
17913 - .long lguest_entry /* lguest hypervisor */
17914 - .long xen_entry /* Xen hypervisor */
17915 - .long default_entry /* Moorestown MID */
17916 + .long ta(default_entry) /* normal x86/PC */
17917 + .long ta(lguest_entry) /* lguest hypervisor */
17918 + .long ta(xen_entry) /* Xen hypervisor */
17919 + .long ta(default_entry) /* Moorestown MID */
17920 num_subarch_entries = (. - subarch_entries) / 4
17921 .previous
17922 #else
17923 @@ -316,6 +388,7 @@ default_entry:
17924 movl pa(mmu_cr4_features),%eax
17925 movl %eax,%cr4
17926
17927 +#ifdef CONFIG_X86_PAE
17928 testb $X86_CR4_PAE, %al # check if PAE is enabled
17929 jz 6f
17930
17931 @@ -344,6 +417,9 @@ default_entry:
17932 /* Make changes effective */
17933 wrmsr
17934
17935 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17936 +#endif
17937 +
17938 6:
17939
17940 /*
17941 @@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
17942 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17943 movl %eax,%ss # after changing gdt.
17944
17945 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17946 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17947 movl %eax,%ds
17948 movl %eax,%es
17949
17950 movl $(__KERNEL_PERCPU), %eax
17951 movl %eax,%fs # set this cpu's percpu
17952
17953 +#ifdef CONFIG_CC_STACKPROTECTOR
17954 movl $(__KERNEL_STACK_CANARY),%eax
17955 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17956 + movl $(__USER_DS),%eax
17957 +#else
17958 + xorl %eax,%eax
17959 +#endif
17960 movl %eax,%gs
17961
17962 xorl %eax,%eax # Clear LDT
17963 @@ -526,8 +608,11 @@ setup_once:
17964 * relocation. Manually set base address in stack canary
17965 * segment descriptor.
17966 */
17967 - movl $gdt_page,%eax
17968 + movl $cpu_gdt_table,%eax
17969 movl $stack_canary,%ecx
17970 +#ifdef CONFIG_SMP
17971 + addl $__per_cpu_load,%ecx
17972 +#endif
17973 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17974 shrl $16, %ecx
17975 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17976 @@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
17977 /* This is global to keep gas from relaxing the jumps */
17978 ENTRY(early_idt_handler)
17979 cld
17980 - cmpl $2,%ss:early_recursion_flag
17981 + cmpl $1,%ss:early_recursion_flag
17982 je hlt_loop
17983 incl %ss:early_recursion_flag
17984
17985 @@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
17986 pushl (20+6*4)(%esp) /* trapno */
17987 pushl $fault_msg
17988 call printk
17989 -#endif
17990 call dump_stack
17991 +#endif
17992 hlt_loop:
17993 hlt
17994 jmp hlt_loop
17995 @@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
17996 /* This is the default interrupt "handler" :-) */
17997 ALIGN
17998 ignore_int:
17999 - cld
18000 #ifdef CONFIG_PRINTK
18001 + cmpl $2,%ss:early_recursion_flag
18002 + je hlt_loop
18003 + incl %ss:early_recursion_flag
18004 + cld
18005 pushl %eax
18006 pushl %ecx
18007 pushl %edx
18008 @@ -626,9 +714,6 @@ ignore_int:
18009 movl $(__KERNEL_DS),%eax
18010 movl %eax,%ds
18011 movl %eax,%es
18012 - cmpl $2,early_recursion_flag
18013 - je hlt_loop
18014 - incl early_recursion_flag
18015 pushl 16(%esp)
18016 pushl 24(%esp)
18017 pushl 32(%esp)
18018 @@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18019 /*
18020 * BSS section
18021 */
18022 -__PAGE_ALIGNED_BSS
18023 - .align PAGE_SIZE
18024 #ifdef CONFIG_X86_PAE
18025 +.section .initial_pg_pmd,"a",@progbits
18026 initial_pg_pmd:
18027 .fill 1024*KPMDS,4,0
18028 #else
18029 +.section .initial_page_table,"a",@progbits
18030 ENTRY(initial_page_table)
18031 .fill 1024,4,0
18032 #endif
18033 +.section .initial_pg_fixmap,"a",@progbits
18034 initial_pg_fixmap:
18035 .fill 1024,4,0
18036 +.section .empty_zero_page,"a",@progbits
18037 ENTRY(empty_zero_page)
18038 .fill 4096,1,0
18039 +.section .swapper_pg_dir,"a",@progbits
18040 ENTRY(swapper_pg_dir)
18041 +#ifdef CONFIG_X86_PAE
18042 + .fill 4,8,0
18043 +#else
18044 .fill 1024,4,0
18045 +#endif
18046 +
18047 +/*
18048 + * The IDT has to be page-aligned to simplify the Pentium
18049 + * F0 0F bug workaround.. We have a special link segment
18050 + * for this.
18051 + */
18052 +.section .idt,"a",@progbits
18053 +ENTRY(idt_table)
18054 + .fill 256,8,0
18055
18056 /*
18057 * This starts the data section.
18058 */
18059 #ifdef CONFIG_X86_PAE
18060 -__PAGE_ALIGNED_DATA
18061 - /* Page-aligned for the benefit of paravirt? */
18062 - .align PAGE_SIZE
18063 +.section .initial_page_table,"a",@progbits
18064 ENTRY(initial_page_table)
18065 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18066 # if KPMDS == 3
18067 @@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18068 # error "Kernel PMDs should be 1, 2 or 3"
18069 # endif
18070 .align PAGE_SIZE /* needs to be page-sized too */
18071 +
18072 +#ifdef CONFIG_PAX_PER_CPU_PGD
18073 +ENTRY(cpu_pgd)
18074 + .rept NR_CPUS
18075 + .fill 4,8,0
18076 + .endr
18077 +#endif
18078 +
18079 #endif
18080
18081 .data
18082 .balign 4
18083 ENTRY(stack_start)
18084 - .long init_thread_union+THREAD_SIZE
18085 + .long init_thread_union+THREAD_SIZE-8
18086
18087 __INITRODATA
18088 int_msg:
18089 @@ -736,7 +843,7 @@ fault_msg:
18090 * segment size, and 32-bit linear address value:
18091 */
18092
18093 - .data
18094 +.section .rodata,"a",@progbits
18095 .globl boot_gdt_descr
18096 .globl idt_descr
18097
18098 @@ -745,7 +852,7 @@ fault_msg:
18099 .word 0 # 32 bit align gdt_desc.address
18100 boot_gdt_descr:
18101 .word __BOOT_DS+7
18102 - .long boot_gdt - __PAGE_OFFSET
18103 + .long pa(boot_gdt)
18104
18105 .word 0 # 32-bit align idt_desc.address
18106 idt_descr:
18107 @@ -756,7 +863,7 @@ idt_descr:
18108 .word 0 # 32 bit align gdt_desc.address
18109 ENTRY(early_gdt_descr)
18110 .word GDT_ENTRIES*8-1
18111 - .long gdt_page /* Overwritten for secondary CPUs */
18112 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
18113
18114 /*
18115 * The boot_gdt must mirror the equivalent in setup.S and is
18116 @@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18117 .align L1_CACHE_BYTES
18118 ENTRY(boot_gdt)
18119 .fill GDT_ENTRY_BOOT_CS,8,0
18120 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18121 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18122 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18123 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18124 +
18125 + .align PAGE_SIZE_asm
18126 +ENTRY(cpu_gdt_table)
18127 + .rept NR_CPUS
18128 + .quad 0x0000000000000000 /* NULL descriptor */
18129 + .quad 0x0000000000000000 /* 0x0b reserved */
18130 + .quad 0x0000000000000000 /* 0x13 reserved */
18131 + .quad 0x0000000000000000 /* 0x1b reserved */
18132 +
18133 +#ifdef CONFIG_PAX_KERNEXEC
18134 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18135 +#else
18136 + .quad 0x0000000000000000 /* 0x20 unused */
18137 +#endif
18138 +
18139 + .quad 0x0000000000000000 /* 0x28 unused */
18140 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18141 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18142 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18143 + .quad 0x0000000000000000 /* 0x4b reserved */
18144 + .quad 0x0000000000000000 /* 0x53 reserved */
18145 + .quad 0x0000000000000000 /* 0x5b reserved */
18146 +
18147 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18148 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18149 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18150 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18151 +
18152 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18153 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18154 +
18155 + /*
18156 + * Segments used for calling PnP BIOS have byte granularity.
18157 + * The code segments and data segments have fixed 64k limits,
18158 + * the transfer segment sizes are set at run time.
18159 + */
18160 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
18161 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
18162 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
18163 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
18164 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
18165 +
18166 + /*
18167 + * The APM segments have byte granularity and their bases
18168 + * are set at run time. All have 64k limits.
18169 + */
18170 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18171 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18172 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
18173 +
18174 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18175 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18176 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18177 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18178 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18179 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18180 +
18181 + /* Be sure this is zeroed to avoid false validations in Xen */
18182 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18183 + .endr
18184 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18185 index 94bf9cc..400455a 100644
18186 --- a/arch/x86/kernel/head_64.S
18187 +++ b/arch/x86/kernel/head_64.S
18188 @@ -20,6 +20,8 @@
18189 #include <asm/processor-flags.h>
18190 #include <asm/percpu.h>
18191 #include <asm/nops.h>
18192 +#include <asm/cpufeature.h>
18193 +#include <asm/alternative-asm.h>
18194
18195 #ifdef CONFIG_PARAVIRT
18196 #include <asm/asm-offsets.h>
18197 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18198 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18199 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18200 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18201 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
18202 +L3_VMALLOC_START = pud_index(VMALLOC_START)
18203 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
18204 +L3_VMALLOC_END = pud_index(VMALLOC_END)
18205 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18206 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18207
18208 .text
18209 __HEAD
18210 @@ -88,35 +96,23 @@ startup_64:
18211 */
18212 addq %rbp, init_level4_pgt + 0(%rip)
18213 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18214 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18215 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18216 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18217 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18218
18219 addq %rbp, level3_ident_pgt + 0(%rip)
18220 +#ifndef CONFIG_XEN
18221 + addq %rbp, level3_ident_pgt + 8(%rip)
18222 +#endif
18223
18224 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18225 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18226 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18227 +
18228 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18229 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18230
18231 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18232 -
18233 - /* Add an Identity mapping if I am above 1G */
18234 - leaq _text(%rip), %rdi
18235 - andq $PMD_PAGE_MASK, %rdi
18236 -
18237 - movq %rdi, %rax
18238 - shrq $PUD_SHIFT, %rax
18239 - andq $(PTRS_PER_PUD - 1), %rax
18240 - jz ident_complete
18241 -
18242 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18243 - leaq level3_ident_pgt(%rip), %rbx
18244 - movq %rdx, 0(%rbx, %rax, 8)
18245 -
18246 - movq %rdi, %rax
18247 - shrq $PMD_SHIFT, %rax
18248 - andq $(PTRS_PER_PMD - 1), %rax
18249 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18250 - leaq level2_spare_pgt(%rip), %rbx
18251 - movq %rdx, 0(%rbx, %rax, 8)
18252 -ident_complete:
18253 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18254
18255 /*
18256 * Fixup the kernel text+data virtual addresses. Note that
18257 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18258 * after the boot processor executes this code.
18259 */
18260
18261 - /* Enable PAE mode and PGE */
18262 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18263 + /* Enable PAE mode and PSE/PGE */
18264 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18265 movq %rax, %cr4
18266
18267 /* Setup early boot stage 4 level pagetables. */
18268 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18269 movl $MSR_EFER, %ecx
18270 rdmsr
18271 btsl $_EFER_SCE, %eax /* Enable System Call */
18272 - btl $20,%edi /* No Execute supported? */
18273 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18274 jnc 1f
18275 btsl $_EFER_NX, %eax
18276 + leaq init_level4_pgt(%rip), %rdi
18277 +#ifndef CONFIG_EFI
18278 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18279 +#endif
18280 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18281 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18282 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18283 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18284 1: wrmsr /* Make changes effective */
18285
18286 /* Setup cr0 */
18287 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18288 * jump. In addition we need to ensure %cs is set so we make this
18289 * a far return.
18290 */
18291 + pax_set_fptr_mask
18292 movq initial_code(%rip),%rax
18293 pushq $0 # fake return address to stop unwinder
18294 pushq $__KERNEL_CS # set correct cs
18295 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18296 bad_address:
18297 jmp bad_address
18298
18299 - .section ".init.text","ax"
18300 + __INIT
18301 .globl early_idt_handlers
18302 early_idt_handlers:
18303 # 104(%rsp) %rflags
18304 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18305 addq $16,%rsp # drop vector number and error code
18306 decl early_recursion_flag(%rip)
18307 INTERRUPT_RETURN
18308 + .previous
18309
18310 + __INITDATA
18311 .balign 4
18312 early_recursion_flag:
18313 .long 0
18314 + .previous
18315
18316 + .section .rodata,"a",@progbits
18317 #ifdef CONFIG_EARLY_PRINTK
18318 early_idt_msg:
18319 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18320 @@ -360,6 +369,7 @@ early_idt_ripmsg:
18321 #endif /* CONFIG_EARLY_PRINTK */
18322 .previous
18323
18324 + .section .rodata,"a",@progbits
18325 #define NEXT_PAGE(name) \
18326 .balign PAGE_SIZE; \
18327 ENTRY(name)
18328 @@ -372,7 +382,6 @@ ENTRY(name)
18329 i = i + 1 ; \
18330 .endr
18331
18332 - .data
18333 /*
18334 * This default setting generates an ident mapping at address 0x100000
18335 * and a mapping for the kernel that precisely maps virtual address
18336 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18337 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18338 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18339 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18340 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
18341 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18342 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
18343 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18344 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18345 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18346 .org init_level4_pgt + L4_START_KERNEL*8, 0
18347 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18348 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18349
18350 +#ifdef CONFIG_PAX_PER_CPU_PGD
18351 +NEXT_PAGE(cpu_pgd)
18352 + .rept NR_CPUS
18353 + .fill 512,8,0
18354 + .endr
18355 +#endif
18356 +
18357 NEXT_PAGE(level3_ident_pgt)
18358 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18359 +#ifdef CONFIG_XEN
18360 .fill 511,8,0
18361 +#else
18362 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18363 + .fill 510,8,0
18364 +#endif
18365 +
18366 +NEXT_PAGE(level3_vmalloc_start_pgt)
18367 + .fill 512,8,0
18368 +
18369 +NEXT_PAGE(level3_vmalloc_end_pgt)
18370 + .fill 512,8,0
18371 +
18372 +NEXT_PAGE(level3_vmemmap_pgt)
18373 + .fill L3_VMEMMAP_START,8,0
18374 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18375
18376 NEXT_PAGE(level3_kernel_pgt)
18377 .fill L3_START_KERNEL,8,0
18378 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18379 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18380 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18381
18382 +NEXT_PAGE(level2_vmemmap_pgt)
18383 + .fill 512,8,0
18384 +
18385 NEXT_PAGE(level2_fixmap_pgt)
18386 - .fill 506,8,0
18387 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18388 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18389 - .fill 5,8,0
18390 + .fill 507,8,0
18391 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18392 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18393 + .fill 4,8,0
18394
18395 -NEXT_PAGE(level1_fixmap_pgt)
18396 +NEXT_PAGE(level1_vsyscall_pgt)
18397 .fill 512,8,0
18398
18399 -NEXT_PAGE(level2_ident_pgt)
18400 - /* Since I easily can, map the first 1G.
18401 + /* Since I easily can, map the first 2G.
18402 * Don't set NX because code runs from these pages.
18403 */
18404 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18405 +NEXT_PAGE(level2_ident_pgt)
18406 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18407
18408 NEXT_PAGE(level2_kernel_pgt)
18409 /*
18410 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18411 * If you want to increase this then increase MODULES_VADDR
18412 * too.)
18413 */
18414 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18415 - KERNEL_IMAGE_SIZE/PMD_SIZE)
18416 -
18417 -NEXT_PAGE(level2_spare_pgt)
18418 - .fill 512, 8, 0
18419 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18420
18421 #undef PMDS
18422 #undef NEXT_PAGE
18423
18424 - .data
18425 + .align PAGE_SIZE
18426 +ENTRY(cpu_gdt_table)
18427 + .rept NR_CPUS
18428 + .quad 0x0000000000000000 /* NULL descriptor */
18429 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18430 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
18431 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
18432 + .quad 0x00cffb000000ffff /* __USER32_CS */
18433 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18434 + .quad 0x00affb000000ffff /* __USER_CS */
18435 +
18436 +#ifdef CONFIG_PAX_KERNEXEC
18437 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18438 +#else
18439 + .quad 0x0 /* unused */
18440 +#endif
18441 +
18442 + .quad 0,0 /* TSS */
18443 + .quad 0,0 /* LDT */
18444 + .quad 0,0,0 /* three TLS descriptors */
18445 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
18446 + /* asm/segment.h:GDT_ENTRIES must match this */
18447 +
18448 + /* zero the remaining page */
18449 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18450 + .endr
18451 +
18452 .align 16
18453 .globl early_gdt_descr
18454 early_gdt_descr:
18455 .word GDT_ENTRIES*8-1
18456 early_gdt_descr_base:
18457 - .quad INIT_PER_CPU_VAR(gdt_page)
18458 + .quad cpu_gdt_table
18459
18460 ENTRY(phys_base)
18461 /* This must match the first entry in level2_kernel_pgt */
18462 .quad 0x0000000000000000
18463
18464 #include "../../x86/xen/xen-head.S"
18465 -
18466 - .section .bss, "aw", @nobits
18467 +
18468 + .section .rodata,"a",@progbits
18469 .align L1_CACHE_BYTES
18470 ENTRY(idt_table)
18471 - .skip IDT_ENTRIES * 16
18472 + .fill 512,8,0
18473
18474 .align L1_CACHE_BYTES
18475 ENTRY(nmi_idt_table)
18476 - .skip IDT_ENTRIES * 16
18477 + .fill 512,8,0
18478
18479 __PAGE_ALIGNED_BSS
18480 .align PAGE_SIZE
18481 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18482 index 9c3bd4a..e1d9b35 100644
18483 --- a/arch/x86/kernel/i386_ksyms_32.c
18484 +++ b/arch/x86/kernel/i386_ksyms_32.c
18485 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18486 EXPORT_SYMBOL(cmpxchg8b_emu);
18487 #endif
18488
18489 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
18490 +
18491 /* Networking helper routines. */
18492 EXPORT_SYMBOL(csum_partial_copy_generic);
18493 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18494 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18495
18496 EXPORT_SYMBOL(__get_user_1);
18497 EXPORT_SYMBOL(__get_user_2);
18498 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18499
18500 EXPORT_SYMBOL(csum_partial);
18501 EXPORT_SYMBOL(empty_zero_page);
18502 +
18503 +#ifdef CONFIG_PAX_KERNEXEC
18504 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18505 +#endif
18506 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18507 index 675a050..95febfd 100644
18508 --- a/arch/x86/kernel/i387.c
18509 +++ b/arch/x86/kernel/i387.c
18510 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18511 static inline bool interrupted_user_mode(void)
18512 {
18513 struct pt_regs *regs = get_irq_regs();
18514 - return regs && user_mode_vm(regs);
18515 + return regs && user_mode(regs);
18516 }
18517
18518 /*
18519 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18520 index 9a5c460..dc4374d 100644
18521 --- a/arch/x86/kernel/i8259.c
18522 +++ b/arch/x86/kernel/i8259.c
18523 @@ -209,7 +209,7 @@ spurious_8259A_irq:
18524 "spurious 8259A interrupt: IRQ%d.\n", irq);
18525 spurious_irq_mask |= irqmask;
18526 }
18527 - atomic_inc(&irq_err_count);
18528 + atomic_inc_unchecked(&irq_err_count);
18529 /*
18530 * Theoretically we do not have to handle this IRQ,
18531 * but in Linux this does not cause problems and is
18532 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18533 index 8c96897..be66bfa 100644
18534 --- a/arch/x86/kernel/ioport.c
18535 +++ b/arch/x86/kernel/ioport.c
18536 @@ -6,6 +6,7 @@
18537 #include <linux/sched.h>
18538 #include <linux/kernel.h>
18539 #include <linux/capability.h>
18540 +#include <linux/security.h>
18541 #include <linux/errno.h>
18542 #include <linux/types.h>
18543 #include <linux/ioport.h>
18544 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18545
18546 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18547 return -EINVAL;
18548 +#ifdef CONFIG_GRKERNSEC_IO
18549 + if (turn_on && grsec_disable_privio) {
18550 + gr_handle_ioperm();
18551 + return -EPERM;
18552 + }
18553 +#endif
18554 if (turn_on && !capable(CAP_SYS_RAWIO))
18555 return -EPERM;
18556
18557 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18558 * because the ->io_bitmap_max value must match the bitmap
18559 * contents:
18560 */
18561 - tss = &per_cpu(init_tss, get_cpu());
18562 + tss = init_tss + get_cpu();
18563
18564 if (turn_on)
18565 bitmap_clear(t->io_bitmap_ptr, from, num);
18566 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18567 return -EINVAL;
18568 /* Trying to gain more privileges? */
18569 if (level > old) {
18570 +#ifdef CONFIG_GRKERNSEC_IO
18571 + if (grsec_disable_privio) {
18572 + gr_handle_iopl();
18573 + return -EPERM;
18574 + }
18575 +#endif
18576 if (!capable(CAP_SYS_RAWIO))
18577 return -EPERM;
18578 }
18579 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18580 index e4595f1..ee3bfb8 100644
18581 --- a/arch/x86/kernel/irq.c
18582 +++ b/arch/x86/kernel/irq.c
18583 @@ -18,7 +18,7 @@
18584 #include <asm/mce.h>
18585 #include <asm/hw_irq.h>
18586
18587 -atomic_t irq_err_count;
18588 +atomic_unchecked_t irq_err_count;
18589
18590 /* Function pointer for generic interrupt vector handling */
18591 void (*x86_platform_ipi_callback)(void) = NULL;
18592 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18593 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18594 seq_printf(p, " Machine check polls\n");
18595 #endif
18596 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18597 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18598 #if defined(CONFIG_X86_IO_APIC)
18599 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18600 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18601 #endif
18602 return 0;
18603 }
18604 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18605
18606 u64 arch_irq_stat(void)
18607 {
18608 - u64 sum = atomic_read(&irq_err_count);
18609 + u64 sum = atomic_read_unchecked(&irq_err_count);
18610
18611 #ifdef CONFIG_X86_IO_APIC
18612 - sum += atomic_read(&irq_mis_count);
18613 + sum += atomic_read_unchecked(&irq_mis_count);
18614 #endif
18615 return sum;
18616 }
18617 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
18618 index 344faf8..355f60d 100644
18619 --- a/arch/x86/kernel/irq_32.c
18620 +++ b/arch/x86/kernel/irq_32.c
18621 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
18622 __asm__ __volatile__("andl %%esp,%0" :
18623 "=r" (sp) : "0" (THREAD_SIZE - 1));
18624
18625 - return sp < (sizeof(struct thread_info) + STACK_WARN);
18626 + return sp < STACK_WARN;
18627 }
18628
18629 static void print_stack_overflow(void)
18630 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
18631 * per-CPU IRQ handling contexts (thread information and stack)
18632 */
18633 union irq_ctx {
18634 - struct thread_info tinfo;
18635 - u32 stack[THREAD_SIZE/sizeof(u32)];
18636 + unsigned long previous_esp;
18637 + u32 stack[THREAD_SIZE/sizeof(u32)];
18638 } __attribute__((aligned(THREAD_SIZE)));
18639
18640 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
18641 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
18642 static inline int
18643 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18644 {
18645 - union irq_ctx *curctx, *irqctx;
18646 + union irq_ctx *irqctx;
18647 u32 *isp, arg1, arg2;
18648
18649 - curctx = (union irq_ctx *) current_thread_info();
18650 irqctx = __this_cpu_read(hardirq_ctx);
18651
18652 /*
18653 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18654 * handler) we can't do that and just have to keep using the
18655 * current stack (which is the irq stack already after all)
18656 */
18657 - if (unlikely(curctx == irqctx))
18658 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
18659 return 0;
18660
18661 /* build the stack frame on the IRQ stack */
18662 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18663 - irqctx->tinfo.task = curctx->tinfo.task;
18664 - irqctx->tinfo.previous_esp = current_stack_pointer;
18665 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18666 + irqctx->previous_esp = current_stack_pointer;
18667
18668 - /* Copy the preempt_count so that the [soft]irq checks work. */
18669 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
18670 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18671 + __set_fs(MAKE_MM_SEG(0));
18672 +#endif
18673
18674 if (unlikely(overflow))
18675 call_on_stack(print_stack_overflow, isp);
18676 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18677 : "0" (irq), "1" (desc), "2" (isp),
18678 "D" (desc->handle_irq)
18679 : "memory", "cc", "ecx");
18680 +
18681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18682 + __set_fs(current_thread_info()->addr_limit);
18683 +#endif
18684 +
18685 return 1;
18686 }
18687
18688 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18689 */
18690 void __cpuinit irq_ctx_init(int cpu)
18691 {
18692 - union irq_ctx *irqctx;
18693 -
18694 if (per_cpu(hardirq_ctx, cpu))
18695 return;
18696
18697 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18698 - THREADINFO_GFP,
18699 - THREAD_SIZE_ORDER));
18700 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18701 - irqctx->tinfo.cpu = cpu;
18702 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
18703 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18704 -
18705 - per_cpu(hardirq_ctx, cpu) = irqctx;
18706 -
18707 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18708 - THREADINFO_GFP,
18709 - THREAD_SIZE_ORDER));
18710 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18711 - irqctx->tinfo.cpu = cpu;
18712 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18713 -
18714 - per_cpu(softirq_ctx, cpu) = irqctx;
18715 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18716 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18717 +
18718 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
18719 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
18720
18721 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
18722 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
18723 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
18724 asmlinkage void do_softirq(void)
18725 {
18726 unsigned long flags;
18727 - struct thread_info *curctx;
18728 union irq_ctx *irqctx;
18729 u32 *isp;
18730
18731 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
18732 local_irq_save(flags);
18733
18734 if (local_softirq_pending()) {
18735 - curctx = current_thread_info();
18736 irqctx = __this_cpu_read(softirq_ctx);
18737 - irqctx->tinfo.task = curctx->task;
18738 - irqctx->tinfo.previous_esp = current_stack_pointer;
18739 + irqctx->previous_esp = current_stack_pointer;
18740
18741 /* build the stack frame on the softirq stack */
18742 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18743 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18744 +
18745 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18746 + __set_fs(MAKE_MM_SEG(0));
18747 +#endif
18748
18749 call_on_stack(__do_softirq, isp);
18750 +
18751 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18752 + __set_fs(current_thread_info()->addr_limit);
18753 +#endif
18754 +
18755 /*
18756 * Shouldn't happen, we returned above if in_interrupt():
18757 */
18758 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
18759 if (unlikely(!desc))
18760 return false;
18761
18762 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
18763 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
18764 if (unlikely(overflow))
18765 print_stack_overflow();
18766 desc->handle_irq(irq, desc);
18767 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
18768 index d04d3ec..ea4b374 100644
18769 --- a/arch/x86/kernel/irq_64.c
18770 +++ b/arch/x86/kernel/irq_64.c
18771 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
18772 u64 estack_top, estack_bottom;
18773 u64 curbase = (u64)task_stack_page(current);
18774
18775 - if (user_mode_vm(regs))
18776 + if (user_mode(regs))
18777 return;
18778
18779 if (regs->sp >= curbase + sizeof(struct thread_info) +
18780 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
18781 index dc1404b..bbc43e7 100644
18782 --- a/arch/x86/kernel/kdebugfs.c
18783 +++ b/arch/x86/kernel/kdebugfs.c
18784 @@ -27,7 +27,7 @@ struct setup_data_node {
18785 u32 len;
18786 };
18787
18788 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
18789 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
18790 size_t count, loff_t *ppos)
18791 {
18792 struct setup_data_node *node = file->private_data;
18793 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
18794 index 836f832..a8bda67 100644
18795 --- a/arch/x86/kernel/kgdb.c
18796 +++ b/arch/x86/kernel/kgdb.c
18797 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
18798 #ifdef CONFIG_X86_32
18799 switch (regno) {
18800 case GDB_SS:
18801 - if (!user_mode_vm(regs))
18802 + if (!user_mode(regs))
18803 *(unsigned long *)mem = __KERNEL_DS;
18804 break;
18805 case GDB_SP:
18806 - if (!user_mode_vm(regs))
18807 + if (!user_mode(regs))
18808 *(unsigned long *)mem = kernel_stack_pointer(regs);
18809 break;
18810 case GDB_GS:
18811 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
18812 bp->attr.bp_addr = breakinfo[breakno].addr;
18813 bp->attr.bp_len = breakinfo[breakno].len;
18814 bp->attr.bp_type = breakinfo[breakno].type;
18815 - info->address = breakinfo[breakno].addr;
18816 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
18817 + info->address = ktla_ktva(breakinfo[breakno].addr);
18818 + else
18819 + info->address = breakinfo[breakno].addr;
18820 info->len = breakinfo[breakno].len;
18821 info->type = breakinfo[breakno].type;
18822 val = arch_install_hw_breakpoint(bp);
18823 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
18824 case 'k':
18825 /* clear the trace bit */
18826 linux_regs->flags &= ~X86_EFLAGS_TF;
18827 - atomic_set(&kgdb_cpu_doing_single_step, -1);
18828 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
18829
18830 /* set the trace bit if we're stepping */
18831 if (remcomInBuffer[0] == 's') {
18832 linux_regs->flags |= X86_EFLAGS_TF;
18833 - atomic_set(&kgdb_cpu_doing_single_step,
18834 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
18835 raw_smp_processor_id());
18836 }
18837
18838 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
18839
18840 switch (cmd) {
18841 case DIE_DEBUG:
18842 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
18843 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
18844 if (user_mode(regs))
18845 return single_step_cont(regs, args);
18846 break;
18847 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
18848 #endif /* CONFIG_DEBUG_RODATA */
18849
18850 bpt->type = BP_BREAKPOINT;
18851 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
18852 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
18853 BREAK_INSTR_SIZE);
18854 if (err)
18855 return err;
18856 - err = probe_kernel_write((char *)bpt->bpt_addr,
18857 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
18858 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
18859 #ifdef CONFIG_DEBUG_RODATA
18860 if (!err)
18861 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
18862 return -EBUSY;
18863 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
18864 BREAK_INSTR_SIZE);
18865 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
18866 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
18867 if (err)
18868 return err;
18869 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
18870 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
18871 if (mutex_is_locked(&text_mutex))
18872 goto knl_write;
18873 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
18874 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
18875 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
18876 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
18877 goto knl_write;
18878 return err;
18879 knl_write:
18880 #endif /* CONFIG_DEBUG_RODATA */
18881 - return probe_kernel_write((char *)bpt->bpt_addr,
18882 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
18883 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
18884 }
18885
18886 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
18887 index c5e410e..ed5a7f0 100644
18888 --- a/arch/x86/kernel/kprobes-opt.c
18889 +++ b/arch/x86/kernel/kprobes-opt.c
18890 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18891 * Verify if the address gap is in 2GB range, because this uses
18892 * a relative jump.
18893 */
18894 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
18895 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
18896 if (abs(rel) > 0x7fffffff)
18897 return -ERANGE;
18898
18899 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18900 op->optinsn.size = ret;
18901
18902 /* Copy arch-dep-instance from template */
18903 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
18904 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
18905
18906 /* Set probe information */
18907 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
18908
18909 /* Set probe function call */
18910 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
18911 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
18912
18913 /* Set returning jmp instruction at the tail of out-of-line buffer */
18914 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
18915 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
18916 (u8 *)op->kp.addr + op->optinsn.size);
18917
18918 flush_icache_range((unsigned long) buf,
18919 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
18920 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
18921
18922 /* Backup instructions which will be replaced by jump address */
18923 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
18924 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
18925 RELATIVE_ADDR_SIZE);
18926
18927 insn_buf[0] = RELATIVEJUMP_OPCODE;
18928 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
18929 /* This kprobe is really able to run optimized path. */
18930 op = container_of(p, struct optimized_kprobe, kp);
18931 /* Detour through copied instructions */
18932 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
18933 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
18934 if (!reenter)
18935 reset_current_kprobe();
18936 preempt_enable_no_resched();
18937 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
18938 index 57916c0..9e0b9d0 100644
18939 --- a/arch/x86/kernel/kprobes.c
18940 +++ b/arch/x86/kernel/kprobes.c
18941 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
18942 s32 raddr;
18943 } __attribute__((packed)) *insn;
18944
18945 - insn = (struct __arch_relative_insn *)from;
18946 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
18947 +
18948 + pax_open_kernel();
18949 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18950 insn->op = op;
18951 + pax_close_kernel();
18952 }
18953
18954 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18955 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18956 kprobe_opcode_t opcode;
18957 kprobe_opcode_t *orig_opcodes = opcodes;
18958
18959 - if (search_exception_tables((unsigned long)opcodes))
18960 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18961 return 0; /* Page fault may occur on this address. */
18962
18963 retry:
18964 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
18965 * for the first byte, we can recover the original instruction
18966 * from it and kp->opcode.
18967 */
18968 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
18969 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
18970 buf[0] = kp->opcode;
18971 - return (unsigned long)buf;
18972 + return ktva_ktla((unsigned long)buf);
18973 }
18974
18975 /*
18976 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18977 /* Another subsystem puts a breakpoint, failed to recover */
18978 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18979 return 0;
18980 + pax_open_kernel();
18981 memcpy(dest, insn.kaddr, insn.length);
18982 + pax_close_kernel();
18983
18984 #ifdef CONFIG_X86_64
18985 if (insn_rip_relative(&insn)) {
18986 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18987 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18988 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18989 disp = (u8 *) dest + insn_offset_displacement(&insn);
18990 + pax_open_kernel();
18991 *(s32 *) disp = (s32) newdisp;
18992 + pax_close_kernel();
18993 }
18994 #endif
18995 return insn.length;
18996 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18997 * nor set current_kprobe, because it doesn't use single
18998 * stepping.
18999 */
19000 - regs->ip = (unsigned long)p->ainsn.insn;
19001 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19002 preempt_enable_no_resched();
19003 return;
19004 }
19005 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19006 regs->flags &= ~X86_EFLAGS_IF;
19007 /* single step inline if the instruction is an int3 */
19008 if (p->opcode == BREAKPOINT_INSTRUCTION)
19009 - regs->ip = (unsigned long)p->addr;
19010 + regs->ip = ktla_ktva((unsigned long)p->addr);
19011 else
19012 - regs->ip = (unsigned long)p->ainsn.insn;
19013 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19014 }
19015
19016 /*
19017 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19018 setup_singlestep(p, regs, kcb, 0);
19019 return 1;
19020 }
19021 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
19022 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19023 /*
19024 * The breakpoint instruction was removed right
19025 * after we hit it. Another cpu has removed
19026 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19027 " movq %rax, 152(%rsp)\n"
19028 RESTORE_REGS_STRING
19029 " popfq\n"
19030 +#ifdef KERNEXEC_PLUGIN
19031 + " btsq $63,(%rsp)\n"
19032 +#endif
19033 #else
19034 " pushf\n"
19035 SAVE_REGS_STRING
19036 @@ -788,7 +798,7 @@ static void __kprobes
19037 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19038 {
19039 unsigned long *tos = stack_addr(regs);
19040 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19041 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19042 unsigned long orig_ip = (unsigned long)p->addr;
19043 kprobe_opcode_t *insn = p->ainsn.insn;
19044
19045 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19046 struct die_args *args = data;
19047 int ret = NOTIFY_DONE;
19048
19049 - if (args->regs && user_mode_vm(args->regs))
19050 + if (args->regs && user_mode(args->regs))
19051 return ret;
19052
19053 switch (val) {
19054 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
19055 index 4180a87..4678e4f 100644
19056 --- a/arch/x86/kernel/kvm.c
19057 +++ b/arch/x86/kernel/kvm.c
19058 @@ -267,7 +267,7 @@ static void __init paravirt_ops_setup(void)
19059 pv_info.paravirt_enabled = 1;
19060
19061 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
19062 - pv_cpu_ops.io_delay = kvm_io_delay;
19063 + *(void **)&pv_cpu_ops.io_delay = kvm_io_delay;
19064
19065 #ifdef CONFIG_X86_IO_APIC
19066 no_timer_check = 1;
19067 @@ -461,18 +461,18 @@ void __init kvm_guest_init(void)
19068 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
19069 spin_lock_init(&async_pf_sleepers[i].lock);
19070 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
19071 - x86_init.irqs.trap_init = kvm_apf_trap_init;
19072 + *(void **)&x86_init.irqs.trap_init = kvm_apf_trap_init;
19073
19074 if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
19075 has_steal_clock = 1;
19076 - pv_time_ops.steal_clock = kvm_steal_clock;
19077 + *(void **)&pv_time_ops.steal_clock = kvm_steal_clock;
19078 }
19079
19080 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
19081 apic_set_eoi_write(kvm_guest_apic_eoi_write);
19082
19083 #ifdef CONFIG_SMP
19084 - smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19085 + *(void **)&smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19086 register_cpu_notifier(&kvm_cpu_notifier);
19087 #else
19088 kvm_guest_cpu_init();
19089 diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
19090 index f1b42b3..27ac4e7 100644
19091 --- a/arch/x86/kernel/kvmclock.c
19092 +++ b/arch/x86/kernel/kvmclock.c
19093 @@ -211,19 +211,19 @@ void __init kvmclock_init(void)
19094
19095 if (kvm_register_clock("boot clock"))
19096 return;
19097 - pv_time_ops.sched_clock = kvm_clock_read;
19098 - x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19099 - x86_platform.get_wallclock = kvm_get_wallclock;
19100 - x86_platform.set_wallclock = kvm_set_wallclock;
19101 + *(void **)&pv_time_ops.sched_clock = kvm_clock_read;
19102 + *(void **)&x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19103 + *(void **)&x86_platform.get_wallclock = kvm_get_wallclock;
19104 + *(void **)&x86_platform.set_wallclock = kvm_set_wallclock;
19105 #ifdef CONFIG_X86_LOCAL_APIC
19106 - x86_cpuinit.early_percpu_clock_init =
19107 + *(void **)&x86_cpuinit.early_percpu_clock_init =
19108 kvm_setup_secondary_clock;
19109 #endif
19110 - x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19111 - x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19112 - machine_ops.shutdown = kvm_shutdown;
19113 + *(void **)&x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19114 + *(void **)&x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19115 + *(void **)&machine_ops.shutdown = kvm_shutdown;
19116 #ifdef CONFIG_KEXEC
19117 - machine_ops.crash_shutdown = kvm_crash_shutdown;
19118 + *(void **)&machine_ops.crash_shutdown = kvm_crash_shutdown;
19119 #endif
19120 kvm_get_preset_lpj();
19121 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
19122 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19123 index ebc9873..1b9724b 100644
19124 --- a/arch/x86/kernel/ldt.c
19125 +++ b/arch/x86/kernel/ldt.c
19126 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19127 if (reload) {
19128 #ifdef CONFIG_SMP
19129 preempt_disable();
19130 - load_LDT(pc);
19131 + load_LDT_nolock(pc);
19132 if (!cpumask_equal(mm_cpumask(current->mm),
19133 cpumask_of(smp_processor_id())))
19134 smp_call_function(flush_ldt, current->mm, 1);
19135 preempt_enable();
19136 #else
19137 - load_LDT(pc);
19138 + load_LDT_nolock(pc);
19139 #endif
19140 }
19141 if (oldsize) {
19142 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19143 return err;
19144
19145 for (i = 0; i < old->size; i++)
19146 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19147 + write_ldt_entry(new->ldt, i, old->ldt + i);
19148 return 0;
19149 }
19150
19151 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19152 retval = copy_ldt(&mm->context, &old_mm->context);
19153 mutex_unlock(&old_mm->context.lock);
19154 }
19155 +
19156 + if (tsk == current) {
19157 + mm->context.vdso = 0;
19158 +
19159 +#ifdef CONFIG_X86_32
19160 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19161 + mm->context.user_cs_base = 0UL;
19162 + mm->context.user_cs_limit = ~0UL;
19163 +
19164 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19165 + cpus_clear(mm->context.cpu_user_cs_mask);
19166 +#endif
19167 +
19168 +#endif
19169 +#endif
19170 +
19171 + }
19172 +
19173 return retval;
19174 }
19175
19176 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19177 }
19178 }
19179
19180 +#ifdef CONFIG_PAX_SEGMEXEC
19181 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19182 + error = -EINVAL;
19183 + goto out_unlock;
19184 + }
19185 +#endif
19186 +
19187 fill_ldt(&ldt, &ldt_info);
19188 if (oldmode)
19189 ldt.avl = 0;
19190 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19191 index 5b19e4d..6476a76 100644
19192 --- a/arch/x86/kernel/machine_kexec_32.c
19193 +++ b/arch/x86/kernel/machine_kexec_32.c
19194 @@ -26,7 +26,7 @@
19195 #include <asm/cacheflush.h>
19196 #include <asm/debugreg.h>
19197
19198 -static void set_idt(void *newidt, __u16 limit)
19199 +static void set_idt(struct desc_struct *newidt, __u16 limit)
19200 {
19201 struct desc_ptr curidt;
19202
19203 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19204 }
19205
19206
19207 -static void set_gdt(void *newgdt, __u16 limit)
19208 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19209 {
19210 struct desc_ptr curgdt;
19211
19212 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19213 }
19214
19215 control_page = page_address(image->control_code_page);
19216 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19217 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19218
19219 relocate_kernel_ptr = control_page;
19220 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19221 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19222 index 3544aed..01ddc1c 100644
19223 --- a/arch/x86/kernel/microcode_intel.c
19224 +++ b/arch/x86/kernel/microcode_intel.c
19225 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19226
19227 static int get_ucode_user(void *to, const void *from, size_t n)
19228 {
19229 - return copy_from_user(to, from, n);
19230 + return copy_from_user(to, (const void __force_user *)from, n);
19231 }
19232
19233 static enum ucode_state
19234 request_microcode_user(int cpu, const void __user *buf, size_t size)
19235 {
19236 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19237 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19238 }
19239
19240 static void microcode_fini_cpu(int cpu)
19241 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19242 index 216a4d7..b328f09 100644
19243 --- a/arch/x86/kernel/module.c
19244 +++ b/arch/x86/kernel/module.c
19245 @@ -43,15 +43,60 @@ do { \
19246 } while (0)
19247 #endif
19248
19249 -void *module_alloc(unsigned long size)
19250 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19251 {
19252 - if (PAGE_ALIGN(size) > MODULES_LEN)
19253 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
19254 return NULL;
19255 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19256 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19257 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19258 -1, __builtin_return_address(0));
19259 }
19260
19261 +void *module_alloc(unsigned long size)
19262 +{
19263 +
19264 +#ifdef CONFIG_PAX_KERNEXEC
19265 + return __module_alloc(size, PAGE_KERNEL);
19266 +#else
19267 + return __module_alloc(size, PAGE_KERNEL_EXEC);
19268 +#endif
19269 +
19270 +}
19271 +
19272 +#ifdef CONFIG_PAX_KERNEXEC
19273 +#ifdef CONFIG_X86_32
19274 +void *module_alloc_exec(unsigned long size)
19275 +{
19276 + struct vm_struct *area;
19277 +
19278 + if (size == 0)
19279 + return NULL;
19280 +
19281 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19282 + return area ? area->addr : NULL;
19283 +}
19284 +EXPORT_SYMBOL(module_alloc_exec);
19285 +
19286 +void module_free_exec(struct module *mod, void *module_region)
19287 +{
19288 + vunmap(module_region);
19289 +}
19290 +EXPORT_SYMBOL(module_free_exec);
19291 +#else
19292 +void module_free_exec(struct module *mod, void *module_region)
19293 +{
19294 + module_free(mod, module_region);
19295 +}
19296 +EXPORT_SYMBOL(module_free_exec);
19297 +
19298 +void *module_alloc_exec(unsigned long size)
19299 +{
19300 + return __module_alloc(size, PAGE_KERNEL_RX);
19301 +}
19302 +EXPORT_SYMBOL(module_alloc_exec);
19303 +#endif
19304 +#endif
19305 +
19306 #ifdef CONFIG_X86_32
19307 int apply_relocate(Elf32_Shdr *sechdrs,
19308 const char *strtab,
19309 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19310 unsigned int i;
19311 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19312 Elf32_Sym *sym;
19313 - uint32_t *location;
19314 + uint32_t *plocation, location;
19315
19316 DEBUGP("Applying relocate section %u to %u\n",
19317 relsec, sechdrs[relsec].sh_info);
19318 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19319 /* This is where to make the change */
19320 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19321 - + rel[i].r_offset;
19322 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19323 + location = (uint32_t)plocation;
19324 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19325 + plocation = ktla_ktva((void *)plocation);
19326 /* This is the symbol it is referring to. Note that all
19327 undefined symbols have been resolved. */
19328 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19329 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19330 switch (ELF32_R_TYPE(rel[i].r_info)) {
19331 case R_386_32:
19332 /* We add the value into the location given */
19333 - *location += sym->st_value;
19334 + pax_open_kernel();
19335 + *plocation += sym->st_value;
19336 + pax_close_kernel();
19337 break;
19338 case R_386_PC32:
19339 /* Add the value, subtract its position */
19340 - *location += sym->st_value - (uint32_t)location;
19341 + pax_open_kernel();
19342 + *plocation += sym->st_value - location;
19343 + pax_close_kernel();
19344 break;
19345 default:
19346 pr_err("%s: Unknown relocation: %u\n",
19347 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19348 case R_X86_64_NONE:
19349 break;
19350 case R_X86_64_64:
19351 + pax_open_kernel();
19352 *(u64 *)loc = val;
19353 + pax_close_kernel();
19354 break;
19355 case R_X86_64_32:
19356 + pax_open_kernel();
19357 *(u32 *)loc = val;
19358 + pax_close_kernel();
19359 if (val != *(u32 *)loc)
19360 goto overflow;
19361 break;
19362 case R_X86_64_32S:
19363 + pax_open_kernel();
19364 *(s32 *)loc = val;
19365 + pax_close_kernel();
19366 if ((s64)val != *(s32 *)loc)
19367 goto overflow;
19368 break;
19369 case R_X86_64_PC32:
19370 val -= (u64)loc;
19371 + pax_open_kernel();
19372 *(u32 *)loc = val;
19373 + pax_close_kernel();
19374 +
19375 #if 0
19376 if ((s64)val != *(s32 *)loc)
19377 goto overflow;
19378 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19379 index f84f5c5..e27e54b 100644
19380 --- a/arch/x86/kernel/nmi.c
19381 +++ b/arch/x86/kernel/nmi.c
19382 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19383 dotraplinkage notrace __kprobes void
19384 do_nmi(struct pt_regs *regs, long error_code)
19385 {
19386 +
19387 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19388 + if (!user_mode(regs)) {
19389 + unsigned long cs = regs->cs & 0xFFFF;
19390 + unsigned long ip = ktva_ktla(regs->ip);
19391 +
19392 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19393 + regs->ip = ip;
19394 + }
19395 +#endif
19396 +
19397 nmi_nesting_preprocess(regs);
19398
19399 nmi_enter();
19400 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19401 index 676b8c7..870ba04 100644
19402 --- a/arch/x86/kernel/paravirt-spinlocks.c
19403 +++ b/arch/x86/kernel/paravirt-spinlocks.c
19404 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19405 arch_spin_lock(lock);
19406 }
19407
19408 -struct pv_lock_ops pv_lock_ops = {
19409 +struct pv_lock_ops pv_lock_ops __read_only = {
19410 #ifdef CONFIG_SMP
19411 .spin_is_locked = __ticket_spin_is_locked,
19412 .spin_is_contended = __ticket_spin_is_contended,
19413 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19414 index 17fff18..0f5f957 100644
19415 --- a/arch/x86/kernel/paravirt.c
19416 +++ b/arch/x86/kernel/paravirt.c
19417 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19418 {
19419 return x;
19420 }
19421 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19422 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19423 +#endif
19424
19425 void __init default_banner(void)
19426 {
19427 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19428 if (opfunc == NULL)
19429 /* If there's no function, patch it with a ud2a (BUG) */
19430 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19431 - else if (opfunc == _paravirt_nop)
19432 + else if (opfunc == (void *)_paravirt_nop)
19433 /* If the operation is a nop, then nop the callsite */
19434 ret = paravirt_patch_nop();
19435
19436 /* identity functions just return their single argument */
19437 - else if (opfunc == _paravirt_ident_32)
19438 + else if (opfunc == (void *)_paravirt_ident_32)
19439 ret = paravirt_patch_ident_32(insnbuf, len);
19440 - else if (opfunc == _paravirt_ident_64)
19441 + else if (opfunc == (void *)_paravirt_ident_64)
19442 ret = paravirt_patch_ident_64(insnbuf, len);
19443 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19444 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19445 + ret = paravirt_patch_ident_64(insnbuf, len);
19446 +#endif
19447
19448 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19449 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19450 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19451 if (insn_len > len || start == NULL)
19452 insn_len = len;
19453 else
19454 - memcpy(insnbuf, start, insn_len);
19455 + memcpy(insnbuf, ktla_ktva(start), insn_len);
19456
19457 return insn_len;
19458 }
19459 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19460 preempt_enable();
19461 }
19462
19463 -struct pv_info pv_info = {
19464 +struct pv_info pv_info __read_only = {
19465 .name = "bare hardware",
19466 .paravirt_enabled = 0,
19467 .kernel_rpl = 0,
19468 @@ -324,7 +331,7 @@ struct pv_time_ops pv_time_ops = {
19469 .steal_clock = native_steal_clock,
19470 };
19471
19472 -struct pv_irq_ops pv_irq_ops = {
19473 +struct pv_irq_ops pv_irq_ops __read_only = {
19474 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19475 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19476 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19477 @@ -401,15 +408,20 @@ struct pv_apic_ops pv_apic_ops = {
19478 #endif
19479 };
19480
19481 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19482 +#ifdef CONFIG_X86_32
19483 +#ifdef CONFIG_X86_PAE
19484 +/* 64-bit pagetable entries */
19485 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19486 +#else
19487 /* 32-bit pagetable entries */
19488 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19489 +#endif
19490 #else
19491 /* 64-bit pagetable entries */
19492 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19493 #endif
19494
19495 -struct pv_mmu_ops pv_mmu_ops = {
19496 +struct pv_mmu_ops pv_mmu_ops __read_only = {
19497
19498 .read_cr2 = native_read_cr2,
19499 .write_cr2 = native_write_cr2,
19500 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19501 .make_pud = PTE_IDENT,
19502
19503 .set_pgd = native_set_pgd,
19504 + .set_pgd_batched = native_set_pgd_batched,
19505 #endif
19506 #endif /* PAGETABLE_LEVELS >= 3 */
19507
19508 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19509 },
19510
19511 .set_fixmap = native_set_fixmap,
19512 +
19513 +#ifdef CONFIG_PAX_KERNEXEC
19514 + .pax_open_kernel = native_pax_open_kernel,
19515 + .pax_close_kernel = native_pax_close_kernel,
19516 +#endif
19517 +
19518 };
19519
19520 EXPORT_SYMBOL_GPL(pv_time_ops);
19521 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
19522 index 299d493..79c13dd 100644
19523 --- a/arch/x86/kernel/pci-calgary_64.c
19524 +++ b/arch/x86/kernel/pci-calgary_64.c
19525 @@ -1461,7 +1461,7 @@ int __init detect_calgary(void)
19526 printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d\n",
19527 specified_table_size);
19528
19529 - x86_init.iommu.iommu_init = calgary_iommu_init;
19530 + *(void **)&x86_init.iommu.iommu_init = calgary_iommu_init;
19531 }
19532 return calgary_found;
19533
19534 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19535 index 35ccf75..7a15747 100644
19536 --- a/arch/x86/kernel/pci-iommu_table.c
19537 +++ b/arch/x86/kernel/pci-iommu_table.c
19538 @@ -2,7 +2,7 @@
19539 #include <asm/iommu_table.h>
19540 #include <linux/string.h>
19541 #include <linux/kallsyms.h>
19542 -
19543 +#include <linux/sched.h>
19544
19545 #define DEBUG 1
19546
19547 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19548 index b644e1c..4a6d379 100644
19549 --- a/arch/x86/kernel/process.c
19550 +++ b/arch/x86/kernel/process.c
19551 @@ -36,7 +36,8 @@
19552 * section. Since TSS's are completely CPU-local, we want them
19553 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19554 */
19555 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19556 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19557 +EXPORT_SYMBOL(init_tss);
19558
19559 #ifdef CONFIG_X86_64
19560 static DEFINE_PER_CPU(unsigned char, is_idle);
19561 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19562 task_xstate_cachep =
19563 kmem_cache_create("task_xstate", xstate_size,
19564 __alignof__(union thread_xstate),
19565 - SLAB_PANIC | SLAB_NOTRACK, NULL);
19566 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19567 }
19568
19569 /*
19570 @@ -105,7 +106,7 @@ void exit_thread(void)
19571 unsigned long *bp = t->io_bitmap_ptr;
19572
19573 if (bp) {
19574 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19575 + struct tss_struct *tss = init_tss + get_cpu();
19576
19577 t->io_bitmap_ptr = NULL;
19578 clear_thread_flag(TIF_IO_BITMAP);
19579 @@ -136,7 +137,7 @@ void show_regs_common(void)
19580 board = dmi_get_system_info(DMI_BOARD_NAME);
19581
19582 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19583 - current->pid, current->comm, print_tainted(),
19584 + task_pid_nr(current), current->comm, print_tainted(),
19585 init_utsname()->release,
19586 (int)strcspn(init_utsname()->version, " "),
19587 init_utsname()->version,
19588 @@ -149,6 +150,9 @@ void flush_thread(void)
19589 {
19590 struct task_struct *tsk = current;
19591
19592 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19593 + loadsegment(gs, 0);
19594 +#endif
19595 flush_ptrace_hw_breakpoint(tsk);
19596 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19597 drop_init_fpu(tsk);
19598 @@ -336,7 +340,7 @@ static void __exit_idle(void)
19599 void exit_idle(void)
19600 {
19601 /* idle loop has pid 0 */
19602 - if (current->pid)
19603 + if (task_pid_nr(current))
19604 return;
19605 __exit_idle();
19606 }
19607 @@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19608
19609 return ret;
19610 }
19611 -void stop_this_cpu(void *dummy)
19612 +__noreturn void stop_this_cpu(void *dummy)
19613 {
19614 local_irq_disable();
19615 /*
19616 @@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19617 }
19618 early_param("idle", idle_setup);
19619
19620 -unsigned long arch_align_stack(unsigned long sp)
19621 +#ifdef CONFIG_PAX_RANDKSTACK
19622 +void pax_randomize_kstack(struct pt_regs *regs)
19623 {
19624 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19625 - sp -= get_random_int() % 8192;
19626 - return sp & ~0xf;
19627 -}
19628 + struct thread_struct *thread = &current->thread;
19629 + unsigned long time;
19630
19631 -unsigned long arch_randomize_brk(struct mm_struct *mm)
19632 -{
19633 - unsigned long range_end = mm->brk + 0x02000000;
19634 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19635 -}
19636 + if (!randomize_va_space)
19637 + return;
19638 +
19639 + if (v8086_mode(regs))
19640 + return;
19641
19642 + rdtscl(time);
19643 +
19644 + /* P4 seems to return a 0 LSB, ignore it */
19645 +#ifdef CONFIG_MPENTIUM4
19646 + time &= 0x3EUL;
19647 + time <<= 2;
19648 +#elif defined(CONFIG_X86_64)
19649 + time &= 0xFUL;
19650 + time <<= 4;
19651 +#else
19652 + time &= 0x1FUL;
19653 + time <<= 3;
19654 +#endif
19655 +
19656 + thread->sp0 ^= time;
19657 + load_sp0(init_tss + smp_processor_id(), thread);
19658 +
19659 +#ifdef CONFIG_X86_64
19660 + this_cpu_write(kernel_stack, thread->sp0);
19661 +#endif
19662 +}
19663 +#endif
19664 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
19665 index 44e0bff..5ceb99c 100644
19666 --- a/arch/x86/kernel/process_32.c
19667 +++ b/arch/x86/kernel/process_32.c
19668 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
19669 unsigned long thread_saved_pc(struct task_struct *tsk)
19670 {
19671 return ((unsigned long *)tsk->thread.sp)[3];
19672 +//XXX return tsk->thread.eip;
19673 }
19674
19675 void __show_regs(struct pt_regs *regs, int all)
19676 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
19677 unsigned long sp;
19678 unsigned short ss, gs;
19679
19680 - if (user_mode_vm(regs)) {
19681 + if (user_mode(regs)) {
19682 sp = regs->sp;
19683 ss = regs->ss & 0xffff;
19684 - gs = get_user_gs(regs);
19685 } else {
19686 sp = kernel_stack_pointer(regs);
19687 savesegment(ss, ss);
19688 - savesegment(gs, gs);
19689 }
19690 + gs = get_user_gs(regs);
19691
19692 show_regs_common();
19693
19694 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
19695 (u16)regs->cs, regs->ip, regs->flags,
19696 - smp_processor_id());
19697 + raw_smp_processor_id());
19698 print_symbol("EIP is at %s\n", regs->ip);
19699
19700 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
19701 @@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19702 unsigned long arg,
19703 struct task_struct *p, struct pt_regs *regs)
19704 {
19705 - struct pt_regs *childregs = task_pt_regs(p);
19706 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
19707 struct task_struct *tsk;
19708 int err;
19709
19710 p->thread.sp = (unsigned long) childregs;
19711 p->thread.sp0 = (unsigned long) (childregs+1);
19712 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
19713
19714 if (unlikely(!regs)) {
19715 /* kernel thread */
19716 memset(childregs, 0, sizeof(struct pt_regs));
19717 p->thread.ip = (unsigned long) ret_from_kernel_thread;
19718 - task_user_gs(p) = __KERNEL_STACK_CANARY;
19719 - childregs->ds = __USER_DS;
19720 - childregs->es = __USER_DS;
19721 + savesegment(gs, childregs->gs);
19722 + childregs->ds = __KERNEL_DS;
19723 + childregs->es = __KERNEL_DS;
19724 childregs->fs = __KERNEL_PERCPU;
19725 childregs->bx = sp; /* function */
19726 childregs->bp = arg;
19727 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19728 struct thread_struct *prev = &prev_p->thread,
19729 *next = &next_p->thread;
19730 int cpu = smp_processor_id();
19731 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
19732 + struct tss_struct *tss = init_tss + cpu;
19733 fpu_switch_t fpu;
19734
19735 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
19736 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19737 */
19738 lazy_save_gs(prev->gs);
19739
19740 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19741 + __set_fs(task_thread_info(next_p)->addr_limit);
19742 +#endif
19743 +
19744 /*
19745 * Load the per-thread Thread-Local Storage descriptor.
19746 */
19747 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19748 */
19749 arch_end_context_switch(next_p);
19750
19751 + this_cpu_write(current_task, next_p);
19752 + this_cpu_write(current_tinfo, &next_p->tinfo);
19753 +
19754 /*
19755 * Restore %gs if needed (which is common)
19756 */
19757 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19758
19759 switch_fpu_finish(next_p, fpu);
19760
19761 - this_cpu_write(current_task, next_p);
19762 -
19763 return prev_p;
19764 }
19765
19766 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
19767 } while (count++ < 16);
19768 return 0;
19769 }
19770 -
19771 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
19772 index 16c6365..5d32218 100644
19773 --- a/arch/x86/kernel/process_64.c
19774 +++ b/arch/x86/kernel/process_64.c
19775 @@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19776 struct pt_regs *childregs;
19777 struct task_struct *me = current;
19778
19779 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
19780 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
19781 childregs = task_pt_regs(p);
19782 p->thread.sp = (unsigned long) childregs;
19783 p->thread.usersp = me->thread.usersp;
19784 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
19785 set_tsk_thread_flag(p, TIF_FORK);
19786 p->fpu_counter = 0;
19787 p->thread.io_bitmap_ptr = NULL;
19788 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19789 struct thread_struct *prev = &prev_p->thread;
19790 struct thread_struct *next = &next_p->thread;
19791 int cpu = smp_processor_id();
19792 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
19793 + struct tss_struct *tss = init_tss + cpu;
19794 unsigned fsindex, gsindex;
19795 fpu_switch_t fpu;
19796
19797 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19798 prev->usersp = this_cpu_read(old_rsp);
19799 this_cpu_write(old_rsp, next->usersp);
19800 this_cpu_write(current_task, next_p);
19801 + this_cpu_write(current_tinfo, &next_p->tinfo);
19802
19803 - this_cpu_write(kernel_stack,
19804 - (unsigned long)task_stack_page(next_p) +
19805 - THREAD_SIZE - KERNEL_STACK_OFFSET);
19806 + this_cpu_write(kernel_stack, next->sp0);
19807
19808 /*
19809 * Now maybe reload the debug registers and handle I/O bitmaps
19810 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
19811 if (!p || p == current || p->state == TASK_RUNNING)
19812 return 0;
19813 stack = (unsigned long)task_stack_page(p);
19814 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
19815 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
19816 return 0;
19817 fp = *(u64 *)(p->thread.sp);
19818 do {
19819 - if (fp < (unsigned long)stack ||
19820 - fp >= (unsigned long)stack+THREAD_SIZE)
19821 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
19822 return 0;
19823 ip = *(u64 *)(fp+8);
19824 if (!in_sched_functions(ip))
19825 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
19826 index 974b67e..044111b 100644
19827 --- a/arch/x86/kernel/ptrace.c
19828 +++ b/arch/x86/kernel/ptrace.c
19829 @@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
19830 {
19831 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
19832 unsigned long sp = (unsigned long)&regs->sp;
19833 - struct thread_info *tinfo;
19834
19835 - if (context == (sp & ~(THREAD_SIZE - 1)))
19836 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
19837 return sp;
19838
19839 - tinfo = (struct thread_info *)context;
19840 - if (tinfo->previous_esp)
19841 - return tinfo->previous_esp;
19842 + sp = *(unsigned long *)context;
19843 + if (sp)
19844 + return sp;
19845
19846 return (unsigned long)regs;
19847 }
19848 @@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
19849 unsigned long addr, unsigned long data)
19850 {
19851 int ret;
19852 - unsigned long __user *datap = (unsigned long __user *)data;
19853 + unsigned long __user *datap = (__force unsigned long __user *)data;
19854
19855 switch (request) {
19856 /* read the word at location addr in the USER area. */
19857 @@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
19858 if ((int) addr < 0)
19859 return -EIO;
19860 ret = do_get_thread_area(child, addr,
19861 - (struct user_desc __user *)data);
19862 + (__force struct user_desc __user *) data);
19863 break;
19864
19865 case PTRACE_SET_THREAD_AREA:
19866 if ((int) addr < 0)
19867 return -EIO;
19868 ret = do_set_thread_area(child, addr,
19869 - (struct user_desc __user *)data, 0);
19870 + (__force struct user_desc __user *) data, 0);
19871 break;
19872 #endif
19873
19874 @@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
19875
19876 #ifdef CONFIG_X86_64
19877
19878 -static struct user_regset x86_64_regsets[] __read_mostly = {
19879 +static struct user_regset x86_64_regsets[] = {
19880 [REGSET_GENERAL] = {
19881 .core_note_type = NT_PRSTATUS,
19882 .n = sizeof(struct user_regs_struct) / sizeof(long),
19883 @@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
19884 #endif /* CONFIG_X86_64 */
19885
19886 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
19887 -static struct user_regset x86_32_regsets[] __read_mostly = {
19888 +static struct user_regset x86_32_regsets[] = {
19889 [REGSET_GENERAL] = {
19890 .core_note_type = NT_PRSTATUS,
19891 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
19892 @@ -1419,13 +1418,13 @@ static const struct user_regset_view user_x86_32_view = {
19893 */
19894 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
19895
19896 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
19897 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
19898 {
19899 #ifdef CONFIG_X86_64
19900 - x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
19901 + *(unsigned int *)&x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
19902 #endif
19903 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
19904 - x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
19905 + *(unsigned int *)&x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
19906 #endif
19907 xstate_fx_sw_bytes[USER_XSTATE_XCR0_WORD] = xstate_mask;
19908 }
19909 @@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
19910 memset(info, 0, sizeof(*info));
19911 info->si_signo = SIGTRAP;
19912 info->si_code = si_code;
19913 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
19914 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
19915 }
19916
19917 void user_single_step_siginfo(struct task_struct *tsk,
19918 @@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
19919 # define IS_IA32 0
19920 #endif
19921
19922 +#ifdef CONFIG_GRKERNSEC_SETXID
19923 +extern void gr_delayed_cred_worker(void);
19924 +#endif
19925 +
19926 /*
19927 * We must return the syscall number to actually look up in the table.
19928 * This can be -1L to skip running any syscall at all.
19929 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
19930
19931 rcu_user_exit();
19932
19933 +#ifdef CONFIG_GRKERNSEC_SETXID
19934 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
19935 + gr_delayed_cred_worker();
19936 +#endif
19937 +
19938 /*
19939 * If we stepped into a sysenter/syscall insn, it trapped in
19940 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
19941 @@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
19942 */
19943 rcu_user_exit();
19944
19945 +#ifdef CONFIG_GRKERNSEC_SETXID
19946 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
19947 + gr_delayed_cred_worker();
19948 +#endif
19949 +
19950 audit_syscall_exit(regs);
19951
19952 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
19953 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
19954 index 42eb330..139955c 100644
19955 --- a/arch/x86/kernel/pvclock.c
19956 +++ b/arch/x86/kernel/pvclock.c
19957 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
19958 return pv_tsc_khz;
19959 }
19960
19961 -static atomic64_t last_value = ATOMIC64_INIT(0);
19962 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
19963
19964 void pvclock_resume(void)
19965 {
19966 - atomic64_set(&last_value, 0);
19967 + atomic64_set_unchecked(&last_value, 0);
19968 }
19969
19970 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19971 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19972 * updating at the same time, and one of them could be slightly behind,
19973 * making the assumption that last_value always go forward fail to hold.
19974 */
19975 - last = atomic64_read(&last_value);
19976 + last = atomic64_read_unchecked(&last_value);
19977 do {
19978 if (ret < last)
19979 return last;
19980 - last = atomic64_cmpxchg(&last_value, last, ret);
19981 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
19982 } while (unlikely(last != ret));
19983
19984 return ret;
19985 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
19986 index 4e8ba39..e0186b3 100644
19987 --- a/arch/x86/kernel/reboot.c
19988 +++ b/arch/x86/kernel/reboot.c
19989 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
19990 EXPORT_SYMBOL(pm_power_off);
19991
19992 static const struct desc_ptr no_idt = {};
19993 -static int reboot_mode;
19994 +static unsigned short reboot_mode;
19995 enum reboot_type reboot_type = BOOT_ACPI;
19996 int reboot_force;
19997
19998 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
19999
20000 void __noreturn machine_real_restart(unsigned int type)
20001 {
20002 +
20003 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20004 + struct desc_struct *gdt;
20005 +#endif
20006 +
20007 local_irq_disable();
20008
20009 /*
20010 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20011
20012 /* Jump to the identity-mapped low memory code */
20013 #ifdef CONFIG_X86_32
20014 - asm volatile("jmpl *%0" : :
20015 +
20016 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20017 + gdt = get_cpu_gdt_table(smp_processor_id());
20018 + pax_open_kernel();
20019 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20020 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20021 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20022 + loadsegment(ds, __KERNEL_DS);
20023 + loadsegment(es, __KERNEL_DS);
20024 + loadsegment(ss, __KERNEL_DS);
20025 +#endif
20026 +#ifdef CONFIG_PAX_KERNEXEC
20027 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20028 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20029 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20030 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20031 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20032 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20033 +#endif
20034 + pax_close_kernel();
20035 +#endif
20036 +
20037 + asm volatile("ljmpl *%0" : :
20038 "rm" (real_mode_header->machine_real_restart_asm),
20039 "a" (type));
20040 #else
20041 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20042 * try to force a triple fault and then cycle between hitting the keyboard
20043 * controller and doing that
20044 */
20045 -static void native_machine_emergency_restart(void)
20046 +static void __noreturn native_machine_emergency_restart(void)
20047 {
20048 int i;
20049 int attempt = 0;
20050 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20051 #endif
20052 }
20053
20054 -static void __machine_emergency_restart(int emergency)
20055 +static void __noreturn __machine_emergency_restart(int emergency)
20056 {
20057 reboot_emergency = emergency;
20058 machine_ops.emergency_restart();
20059 }
20060
20061 -static void native_machine_restart(char *__unused)
20062 +static void __noreturn native_machine_restart(char *__unused)
20063 {
20064 pr_notice("machine restart\n");
20065
20066 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20067 __machine_emergency_restart(0);
20068 }
20069
20070 -static void native_machine_halt(void)
20071 +static void __noreturn native_machine_halt(void)
20072 {
20073 /* Stop other cpus and apics */
20074 machine_shutdown();
20075 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
20076 stop_this_cpu(NULL);
20077 }
20078
20079 -static void native_machine_power_off(void)
20080 +static void __noreturn native_machine_power_off(void)
20081 {
20082 if (pm_power_off) {
20083 if (!reboot_force)
20084 @@ -688,6 +715,7 @@ static void native_machine_power_off(void)
20085 }
20086 /* A fallback in case there is no PM info available */
20087 tboot_shutdown(TB_SHUTDOWN_HALT);
20088 + unreachable();
20089 }
20090
20091 struct machine_ops machine_ops = {
20092 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20093 index 7a6f3b3..bed145d7 100644
20094 --- a/arch/x86/kernel/relocate_kernel_64.S
20095 +++ b/arch/x86/kernel/relocate_kernel_64.S
20096 @@ -11,6 +11,7 @@
20097 #include <asm/kexec.h>
20098 #include <asm/processor-flags.h>
20099 #include <asm/pgtable_types.h>
20100 +#include <asm/alternative-asm.h>
20101
20102 /*
20103 * Must be relocatable PIC code callable as a C function
20104 @@ -160,13 +161,14 @@ identity_mapped:
20105 xorq %rbp, %rbp
20106 xorq %r8, %r8
20107 xorq %r9, %r9
20108 - xorq %r10, %r9
20109 + xorq %r10, %r10
20110 xorq %r11, %r11
20111 xorq %r12, %r12
20112 xorq %r13, %r13
20113 xorq %r14, %r14
20114 xorq %r15, %r15
20115
20116 + pax_force_retaddr 0, 1
20117 ret
20118
20119 1:
20120 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20121 index ca45696..6384a09 100644
20122 --- a/arch/x86/kernel/setup.c
20123 +++ b/arch/x86/kernel/setup.c
20124 @@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20125
20126 switch (data->type) {
20127 case SETUP_E820_EXT:
20128 - parse_e820_ext(data);
20129 + parse_e820_ext((struct setup_data __force_kernel *)data);
20130 break;
20131 case SETUP_DTB:
20132 add_dtb(pa_data);
20133 @@ -633,7 +633,7 @@ static void __init trim_bios_range(void)
20134 * area (640->1Mb) as ram even though it is not.
20135 * take them out.
20136 */
20137 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20138 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20139 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20140 }
20141
20142 @@ -756,14 +756,14 @@ void __init setup_arch(char **cmdline_p)
20143
20144 if (!boot_params.hdr.root_flags)
20145 root_mountflags &= ~MS_RDONLY;
20146 - init_mm.start_code = (unsigned long) _text;
20147 - init_mm.end_code = (unsigned long) _etext;
20148 + init_mm.start_code = ktla_ktva((unsigned long) _text);
20149 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
20150 init_mm.end_data = (unsigned long) _edata;
20151 init_mm.brk = _brk_end;
20152
20153 - code_resource.start = virt_to_phys(_text);
20154 - code_resource.end = virt_to_phys(_etext)-1;
20155 - data_resource.start = virt_to_phys(_etext);
20156 + code_resource.start = virt_to_phys(ktla_ktva(_text));
20157 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20158 + data_resource.start = virt_to_phys(_sdata);
20159 data_resource.end = virt_to_phys(_edata)-1;
20160 bss_resource.start = virt_to_phys(&__bss_start);
20161 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20162 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20163 index 5cdff03..5810740 100644
20164 --- a/arch/x86/kernel/setup_percpu.c
20165 +++ b/arch/x86/kernel/setup_percpu.c
20166 @@ -21,19 +21,17 @@
20167 #include <asm/cpu.h>
20168 #include <asm/stackprotector.h>
20169
20170 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20171 +#ifdef CONFIG_SMP
20172 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20173 EXPORT_PER_CPU_SYMBOL(cpu_number);
20174 +#endif
20175
20176 -#ifdef CONFIG_X86_64
20177 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20178 -#else
20179 -#define BOOT_PERCPU_OFFSET 0
20180 -#endif
20181
20182 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20183 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20184
20185 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20186 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20187 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20188 };
20189 EXPORT_SYMBOL(__per_cpu_offset);
20190 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20191 {
20192 #ifdef CONFIG_X86_32
20193 struct desc_struct gdt;
20194 + unsigned long base = per_cpu_offset(cpu);
20195
20196 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20197 - 0x2 | DESCTYPE_S, 0x8);
20198 - gdt.s = 1;
20199 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20200 + 0x83 | DESCTYPE_S, 0xC);
20201 write_gdt_entry(get_cpu_gdt_table(cpu),
20202 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20203 #endif
20204 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20205 /* alrighty, percpu areas up and running */
20206 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20207 for_each_possible_cpu(cpu) {
20208 +#ifdef CONFIG_CC_STACKPROTECTOR
20209 +#ifdef CONFIG_X86_32
20210 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
20211 +#endif
20212 +#endif
20213 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20214 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20215 per_cpu(cpu_number, cpu) = cpu;
20216 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20217 */
20218 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20219 #endif
20220 +#ifdef CONFIG_CC_STACKPROTECTOR
20221 +#ifdef CONFIG_X86_32
20222 + if (!cpu)
20223 + per_cpu(stack_canary.canary, cpu) = canary;
20224 +#endif
20225 +#endif
20226 /*
20227 * Up to this point, the boot CPU has been using .init.data
20228 * area. Reload any changed state for the boot CPU.
20229 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20230 index 70b27ee..fcf827f 100644
20231 --- a/arch/x86/kernel/signal.c
20232 +++ b/arch/x86/kernel/signal.c
20233 @@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20234 * Align the stack pointer according to the i386 ABI,
20235 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20236 */
20237 - sp = ((sp + 4) & -16ul) - 4;
20238 + sp = ((sp - 12) & -16ul) - 4;
20239 #else /* !CONFIG_X86_32 */
20240 sp = round_down(sp, 16) - 8;
20241 #endif
20242 @@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20243 }
20244
20245 if (current->mm->context.vdso)
20246 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20247 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20248 else
20249 - restorer = &frame->retcode;
20250 + restorer = (void __user *)&frame->retcode;
20251 if (ka->sa.sa_flags & SA_RESTORER)
20252 restorer = ka->sa.sa_restorer;
20253
20254 @@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20255 * reasons and because gdb uses it as a signature to notice
20256 * signal handler stack frames.
20257 */
20258 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20259 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20260
20261 if (err)
20262 return -EFAULT;
20263 @@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20264 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20265
20266 /* Set up to return from userspace. */
20267 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20268 + if (current->mm->context.vdso)
20269 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20270 + else
20271 + restorer = (void __user *)&frame->retcode;
20272 if (ka->sa.sa_flags & SA_RESTORER)
20273 restorer = ka->sa.sa_restorer;
20274 put_user_ex(restorer, &frame->pretcode);
20275 @@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20276 * reasons and because gdb uses it as a signature to notice
20277 * signal handler stack frames.
20278 */
20279 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20280 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20281 } put_user_catch(err);
20282
20283 err |= copy_siginfo_to_user(&frame->info, info);
20284 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20285 index f3e2ec8..ad5287a 100644
20286 --- a/arch/x86/kernel/smpboot.c
20287 +++ b/arch/x86/kernel/smpboot.c
20288 @@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20289 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20290 (THREAD_SIZE + task_stack_page(idle))) - 1);
20291 per_cpu(current_task, cpu) = idle;
20292 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
20293
20294 #ifdef CONFIG_X86_32
20295 /* Stack for startup_32 can be just as for start_secondary onwards */
20296 @@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20297 #else
20298 clear_tsk_thread_flag(idle, TIF_FORK);
20299 initial_gs = per_cpu_offset(cpu);
20300 - per_cpu(kernel_stack, cpu) =
20301 - (unsigned long)task_stack_page(idle) -
20302 - KERNEL_STACK_OFFSET + THREAD_SIZE;
20303 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20304 #endif
20305 +
20306 + pax_open_kernel();
20307 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20308 + pax_close_kernel();
20309 +
20310 initial_code = (unsigned long)start_secondary;
20311 stack_start = idle->thread.sp;
20312
20313 @@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20314 /* the FPU context is blank, nobody can own it */
20315 __cpu_disable_lazy_restore(cpu);
20316
20317 +#ifdef CONFIG_PAX_PER_CPU_PGD
20318 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20319 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20320 + KERNEL_PGD_PTRS);
20321 +#endif
20322 +
20323 + /* the FPU context is blank, nobody can own it */
20324 + __cpu_disable_lazy_restore(cpu);
20325 +
20326 err = do_boot_cpu(apicid, cpu, tidle);
20327 if (err) {
20328 pr_debug("do_boot_cpu failed %d\n", err);
20329 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20330 index cd3b243..4ba27a4 100644
20331 --- a/arch/x86/kernel/step.c
20332 +++ b/arch/x86/kernel/step.c
20333 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20334 struct desc_struct *desc;
20335 unsigned long base;
20336
20337 - seg &= ~7UL;
20338 + seg >>= 3;
20339
20340 mutex_lock(&child->mm->context.lock);
20341 - if (unlikely((seg >> 3) >= child->mm->context.size))
20342 + if (unlikely(seg >= child->mm->context.size))
20343 addr = -1L; /* bogus selector, access would fault */
20344 else {
20345 desc = child->mm->context.ldt + seg;
20346 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20347 addr += base;
20348 }
20349 mutex_unlock(&child->mm->context.lock);
20350 - }
20351 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20352 + addr = ktla_ktva(addr);
20353
20354 return addr;
20355 }
20356 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20357 unsigned char opcode[15];
20358 unsigned long addr = convert_ip_to_linear(child, regs);
20359
20360 + if (addr == -EINVAL)
20361 + return 0;
20362 +
20363 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20364 for (i = 0; i < copied; i++) {
20365 switch (opcode[i]) {
20366 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20367 new file mode 100644
20368 index 0000000..db6b9ed
20369 --- /dev/null
20370 +++ b/arch/x86/kernel/sys_i386_32.c
20371 @@ -0,0 +1,247 @@
20372 +/*
20373 + * This file contains various random system calls that
20374 + * have a non-standard calling sequence on the Linux/i386
20375 + * platform.
20376 + */
20377 +
20378 +#include <linux/errno.h>
20379 +#include <linux/sched.h>
20380 +#include <linux/mm.h>
20381 +#include <linux/fs.h>
20382 +#include <linux/smp.h>
20383 +#include <linux/sem.h>
20384 +#include <linux/msg.h>
20385 +#include <linux/shm.h>
20386 +#include <linux/stat.h>
20387 +#include <linux/syscalls.h>
20388 +#include <linux/mman.h>
20389 +#include <linux/file.h>
20390 +#include <linux/utsname.h>
20391 +#include <linux/ipc.h>
20392 +
20393 +#include <linux/uaccess.h>
20394 +#include <linux/unistd.h>
20395 +
20396 +#include <asm/syscalls.h>
20397 +
20398 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20399 +{
20400 + unsigned long pax_task_size = TASK_SIZE;
20401 +
20402 +#ifdef CONFIG_PAX_SEGMEXEC
20403 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20404 + pax_task_size = SEGMEXEC_TASK_SIZE;
20405 +#endif
20406 +
20407 + if (len > pax_task_size || addr > pax_task_size - len)
20408 + return -EINVAL;
20409 +
20410 + return 0;
20411 +}
20412 +
20413 +unsigned long
20414 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
20415 + unsigned long len, unsigned long pgoff, unsigned long flags)
20416 +{
20417 + struct mm_struct *mm = current->mm;
20418 + struct vm_area_struct *vma;
20419 + unsigned long start_addr, pax_task_size = TASK_SIZE;
20420 +
20421 +#ifdef CONFIG_PAX_SEGMEXEC
20422 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20423 + pax_task_size = SEGMEXEC_TASK_SIZE;
20424 +#endif
20425 +
20426 + pax_task_size -= PAGE_SIZE;
20427 +
20428 + if (len > pax_task_size)
20429 + return -ENOMEM;
20430 +
20431 + if (flags & MAP_FIXED)
20432 + return addr;
20433 +
20434 +#ifdef CONFIG_PAX_RANDMMAP
20435 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20436 +#endif
20437 +
20438 + if (addr) {
20439 + addr = PAGE_ALIGN(addr);
20440 + if (pax_task_size - len >= addr) {
20441 + vma = find_vma(mm, addr);
20442 + if (check_heap_stack_gap(vma, addr, len))
20443 + return addr;
20444 + }
20445 + }
20446 + if (len > mm->cached_hole_size) {
20447 + start_addr = addr = mm->free_area_cache;
20448 + } else {
20449 + start_addr = addr = mm->mmap_base;
20450 + mm->cached_hole_size = 0;
20451 + }
20452 +
20453 +#ifdef CONFIG_PAX_PAGEEXEC
20454 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20455 + start_addr = 0x00110000UL;
20456 +
20457 +#ifdef CONFIG_PAX_RANDMMAP
20458 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20459 + start_addr += mm->delta_mmap & 0x03FFF000UL;
20460 +#endif
20461 +
20462 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20463 + start_addr = addr = mm->mmap_base;
20464 + else
20465 + addr = start_addr;
20466 + }
20467 +#endif
20468 +
20469 +full_search:
20470 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20471 + /* At this point: (!vma || addr < vma->vm_end). */
20472 + if (pax_task_size - len < addr) {
20473 + /*
20474 + * Start a new search - just in case we missed
20475 + * some holes.
20476 + */
20477 + if (start_addr != mm->mmap_base) {
20478 + start_addr = addr = mm->mmap_base;
20479 + mm->cached_hole_size = 0;
20480 + goto full_search;
20481 + }
20482 + return -ENOMEM;
20483 + }
20484 + if (check_heap_stack_gap(vma, addr, len))
20485 + break;
20486 + if (addr + mm->cached_hole_size < vma->vm_start)
20487 + mm->cached_hole_size = vma->vm_start - addr;
20488 + addr = vma->vm_end;
20489 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
20490 + start_addr = addr = mm->mmap_base;
20491 + mm->cached_hole_size = 0;
20492 + goto full_search;
20493 + }
20494 + }
20495 +
20496 + /*
20497 + * Remember the place where we stopped the search:
20498 + */
20499 + mm->free_area_cache = addr + len;
20500 + return addr;
20501 +}
20502 +
20503 +unsigned long
20504 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20505 + const unsigned long len, const unsigned long pgoff,
20506 + const unsigned long flags)
20507 +{
20508 + struct vm_area_struct *vma;
20509 + struct mm_struct *mm = current->mm;
20510 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20511 +
20512 +#ifdef CONFIG_PAX_SEGMEXEC
20513 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20514 + pax_task_size = SEGMEXEC_TASK_SIZE;
20515 +#endif
20516 +
20517 + pax_task_size -= PAGE_SIZE;
20518 +
20519 + /* requested length too big for entire address space */
20520 + if (len > pax_task_size)
20521 + return -ENOMEM;
20522 +
20523 + if (flags & MAP_FIXED)
20524 + return addr;
20525 +
20526 +#ifdef CONFIG_PAX_PAGEEXEC
20527 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20528 + goto bottomup;
20529 +#endif
20530 +
20531 +#ifdef CONFIG_PAX_RANDMMAP
20532 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20533 +#endif
20534 +
20535 + /* requesting a specific address */
20536 + if (addr) {
20537 + addr = PAGE_ALIGN(addr);
20538 + if (pax_task_size - len >= addr) {
20539 + vma = find_vma(mm, addr);
20540 + if (check_heap_stack_gap(vma, addr, len))
20541 + return addr;
20542 + }
20543 + }
20544 +
20545 + /* check if free_area_cache is useful for us */
20546 + if (len <= mm->cached_hole_size) {
20547 + mm->cached_hole_size = 0;
20548 + mm->free_area_cache = mm->mmap_base;
20549 + }
20550 +
20551 + /* either no address requested or can't fit in requested address hole */
20552 + addr = mm->free_area_cache;
20553 +
20554 + /* make sure it can fit in the remaining address space */
20555 + if (addr > len) {
20556 + vma = find_vma(mm, addr-len);
20557 + if (check_heap_stack_gap(vma, addr - len, len))
20558 + /* remember the address as a hint for next time */
20559 + return (mm->free_area_cache = addr-len);
20560 + }
20561 +
20562 + if (mm->mmap_base < len)
20563 + goto bottomup;
20564 +
20565 + addr = mm->mmap_base-len;
20566 +
20567 + do {
20568 + /*
20569 + * Lookup failure means no vma is above this address,
20570 + * else if new region fits below vma->vm_start,
20571 + * return with success:
20572 + */
20573 + vma = find_vma(mm, addr);
20574 + if (check_heap_stack_gap(vma, addr, len))
20575 + /* remember the address as a hint for next time */
20576 + return (mm->free_area_cache = addr);
20577 +
20578 + /* remember the largest hole we saw so far */
20579 + if (addr + mm->cached_hole_size < vma->vm_start)
20580 + mm->cached_hole_size = vma->vm_start - addr;
20581 +
20582 + /* try just below the current vma->vm_start */
20583 + addr = skip_heap_stack_gap(vma, len);
20584 + } while (!IS_ERR_VALUE(addr));
20585 +
20586 +bottomup:
20587 + /*
20588 + * A failed mmap() very likely causes application failure,
20589 + * so fall back to the bottom-up function here. This scenario
20590 + * can happen with large stack limits and large mmap()
20591 + * allocations.
20592 + */
20593 +
20594 +#ifdef CONFIG_PAX_SEGMEXEC
20595 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20596 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20597 + else
20598 +#endif
20599 +
20600 + mm->mmap_base = TASK_UNMAPPED_BASE;
20601 +
20602 +#ifdef CONFIG_PAX_RANDMMAP
20603 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20604 + mm->mmap_base += mm->delta_mmap;
20605 +#endif
20606 +
20607 + mm->free_area_cache = mm->mmap_base;
20608 + mm->cached_hole_size = ~0UL;
20609 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20610 + /*
20611 + * Restore the topdown base:
20612 + */
20613 + mm->mmap_base = base;
20614 + mm->free_area_cache = base;
20615 + mm->cached_hole_size = ~0UL;
20616 +
20617 + return addr;
20618 +}
20619 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20620 index b4d3c39..82bb73b 100644
20621 --- a/arch/x86/kernel/sys_x86_64.c
20622 +++ b/arch/x86/kernel/sys_x86_64.c
20623 @@ -95,8 +95,8 @@ out:
20624 return error;
20625 }
20626
20627 -static void find_start_end(unsigned long flags, unsigned long *begin,
20628 - unsigned long *end)
20629 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
20630 + unsigned long *begin, unsigned long *end)
20631 {
20632 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20633 unsigned long new_begin;
20634 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20635 *begin = new_begin;
20636 }
20637 } else {
20638 - *begin = TASK_UNMAPPED_BASE;
20639 + *begin = mm->mmap_base;
20640 *end = TASK_SIZE;
20641 }
20642 }
20643 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20644 if (flags & MAP_FIXED)
20645 return addr;
20646
20647 - find_start_end(flags, &begin, &end);
20648 + find_start_end(mm, flags, &begin, &end);
20649
20650 if (len > end)
20651 return -ENOMEM;
20652
20653 +#ifdef CONFIG_PAX_RANDMMAP
20654 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20655 +#endif
20656 +
20657 if (addr) {
20658 addr = PAGE_ALIGN(addr);
20659 vma = find_vma(mm, addr);
20660 - if (end - len >= addr &&
20661 - (!vma || addr + len <= vma->vm_start))
20662 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
20663 return addr;
20664 }
20665 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
20666 @@ -172,7 +175,7 @@ full_search:
20667 }
20668 return -ENOMEM;
20669 }
20670 - if (!vma || addr + len <= vma->vm_start) {
20671 + if (check_heap_stack_gap(vma, addr, len)) {
20672 /*
20673 * Remember the place where we stopped the search:
20674 */
20675 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20676 {
20677 struct vm_area_struct *vma;
20678 struct mm_struct *mm = current->mm;
20679 - unsigned long addr = addr0, start_addr;
20680 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
20681
20682 /* requested length too big for entire address space */
20683 if (len > TASK_SIZE)
20684 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20685 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
20686 goto bottomup;
20687
20688 +#ifdef CONFIG_PAX_RANDMMAP
20689 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20690 +#endif
20691 +
20692 /* requesting a specific address */
20693 if (addr) {
20694 addr = PAGE_ALIGN(addr);
20695 - vma = find_vma(mm, addr);
20696 - if (TASK_SIZE - len >= addr &&
20697 - (!vma || addr + len <= vma->vm_start))
20698 - return addr;
20699 + if (TASK_SIZE - len >= addr) {
20700 + vma = find_vma(mm, addr);
20701 + if (check_heap_stack_gap(vma, addr, len))
20702 + return addr;
20703 + }
20704 }
20705
20706 /* check if free_area_cache is useful for us */
20707 @@ -240,7 +248,7 @@ try_again:
20708 * return with success:
20709 */
20710 vma = find_vma(mm, addr);
20711 - if (!vma || addr+len <= vma->vm_start)
20712 + if (check_heap_stack_gap(vma, addr, len))
20713 /* remember the address as a hint for next time */
20714 return mm->free_area_cache = addr;
20715
20716 @@ -249,8 +257,8 @@ try_again:
20717 mm->cached_hole_size = vma->vm_start - addr;
20718
20719 /* try just below the current vma->vm_start */
20720 - addr = vma->vm_start-len;
20721 - } while (len < vma->vm_start);
20722 + addr = skip_heap_stack_gap(vma, len);
20723 + } while (!IS_ERR_VALUE(addr));
20724
20725 fail:
20726 /*
20727 @@ -270,13 +278,21 @@ bottomup:
20728 * can happen with large stack limits and large mmap()
20729 * allocations.
20730 */
20731 + mm->mmap_base = TASK_UNMAPPED_BASE;
20732 +
20733 +#ifdef CONFIG_PAX_RANDMMAP
20734 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20735 + mm->mmap_base += mm->delta_mmap;
20736 +#endif
20737 +
20738 + mm->free_area_cache = mm->mmap_base;
20739 mm->cached_hole_size = ~0UL;
20740 - mm->free_area_cache = TASK_UNMAPPED_BASE;
20741 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20742 /*
20743 * Restore the topdown base:
20744 */
20745 - mm->free_area_cache = mm->mmap_base;
20746 + mm->mmap_base = base;
20747 + mm->free_area_cache = base;
20748 mm->cached_hole_size = ~0UL;
20749
20750 return addr;
20751 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
20752 index f84fe00..93fe08f 100644
20753 --- a/arch/x86/kernel/tboot.c
20754 +++ b/arch/x86/kernel/tboot.c
20755 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
20756
20757 void tboot_shutdown(u32 shutdown_type)
20758 {
20759 - void (*shutdown)(void);
20760 + void (* __noreturn shutdown)(void);
20761
20762 if (!tboot_enabled())
20763 return;
20764 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
20765
20766 switch_to_tboot_pt();
20767
20768 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
20769 + shutdown = (void *)tboot->shutdown_entry;
20770 shutdown();
20771
20772 /* should not reach here */
20773 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
20774 return 0;
20775 }
20776
20777 -static atomic_t ap_wfs_count;
20778 +static atomic_unchecked_t ap_wfs_count;
20779
20780 static int tboot_wait_for_aps(int num_aps)
20781 {
20782 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
20783 {
20784 switch (action) {
20785 case CPU_DYING:
20786 - atomic_inc(&ap_wfs_count);
20787 + atomic_inc_unchecked(&ap_wfs_count);
20788 if (num_online_cpus() == 1)
20789 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
20790 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
20791 return NOTIFY_BAD;
20792 break;
20793 }
20794 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
20795
20796 tboot_create_trampoline();
20797
20798 - atomic_set(&ap_wfs_count, 0);
20799 + atomic_set_unchecked(&ap_wfs_count, 0);
20800 register_hotcpu_notifier(&tboot_cpu_notifier);
20801
20802 acpi_os_set_prepare_sleep(&tboot_sleep);
20803 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
20804 index 24d3c91..d06b473 100644
20805 --- a/arch/x86/kernel/time.c
20806 +++ b/arch/x86/kernel/time.c
20807 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
20808 {
20809 unsigned long pc = instruction_pointer(regs);
20810
20811 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
20812 + if (!user_mode(regs) && in_lock_functions(pc)) {
20813 #ifdef CONFIG_FRAME_POINTER
20814 - return *(unsigned long *)(regs->bp + sizeof(long));
20815 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
20816 #else
20817 unsigned long *sp =
20818 (unsigned long *)kernel_stack_pointer(regs);
20819 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
20820 * or above a saved flags. Eflags has bits 22-31 zero,
20821 * kernel addresses don't.
20822 */
20823 +
20824 +#ifdef CONFIG_PAX_KERNEXEC
20825 + return ktla_ktva(sp[0]);
20826 +#else
20827 if (sp[0] >> 22)
20828 return sp[0];
20829 if (sp[1] >> 22)
20830 return sp[1];
20831 #endif
20832 +
20833 +#endif
20834 }
20835 return pc;
20836 }
20837 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
20838 index 9d9d2f9..cad418a 100644
20839 --- a/arch/x86/kernel/tls.c
20840 +++ b/arch/x86/kernel/tls.c
20841 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
20842 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
20843 return -EINVAL;
20844
20845 +#ifdef CONFIG_PAX_SEGMEXEC
20846 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
20847 + return -EINVAL;
20848 +#endif
20849 +
20850 set_tls_desc(p, idx, &info, 1);
20851
20852 return 0;
20853 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
20854
20855 if (kbuf)
20856 info = kbuf;
20857 - else if (__copy_from_user(infobuf, ubuf, count))
20858 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
20859 return -EFAULT;
20860 else
20861 info = infobuf;
20862 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
20863 index 8276dc6..4ca48a2 100644
20864 --- a/arch/x86/kernel/traps.c
20865 +++ b/arch/x86/kernel/traps.c
20866 @@ -71,12 +71,6 @@ asmlinkage int system_call(void);
20867
20868 /* Do we ignore FPU interrupts ? */
20869 char ignore_fpu_irq;
20870 -
20871 -/*
20872 - * The IDT has to be page-aligned to simplify the Pentium
20873 - * F0 0F bug workaround.
20874 - */
20875 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
20876 #endif
20877
20878 DECLARE_BITMAP(used_vectors, NR_VECTORS);
20879 @@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
20880 }
20881
20882 static int __kprobes
20883 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
20884 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
20885 struct pt_regs *regs, long error_code)
20886 {
20887 #ifdef CONFIG_X86_32
20888 - if (regs->flags & X86_VM_MASK) {
20889 + if (v8086_mode(regs)) {
20890 /*
20891 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
20892 * On nmi (interrupt 2), do_trap should not be called.
20893 @@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
20894 return -1;
20895 }
20896 #endif
20897 - if (!user_mode(regs)) {
20898 + if (!user_mode_novm(regs)) {
20899 if (!fixup_exception(regs)) {
20900 tsk->thread.error_code = error_code;
20901 tsk->thread.trap_nr = trapnr;
20902 +
20903 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20904 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
20905 + str = "PAX: suspicious stack segment fault";
20906 +#endif
20907 +
20908 die(str, regs, error_code);
20909 }
20910 +
20911 +#ifdef CONFIG_PAX_REFCOUNT
20912 + if (trapnr == 4)
20913 + pax_report_refcount_overflow(regs);
20914 +#endif
20915 +
20916 return 0;
20917 }
20918
20919 @@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
20920 }
20921
20922 static void __kprobes
20923 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20924 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
20925 long error_code, siginfo_t *info)
20926 {
20927 struct task_struct *tsk = current;
20928 @@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20929 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
20930 printk_ratelimit()) {
20931 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
20932 - tsk->comm, tsk->pid, str,
20933 + tsk->comm, task_pid_nr(tsk), str,
20934 regs->ip, regs->sp, error_code);
20935 print_vma_addr(" in ", regs->ip);
20936 pr_cont("\n");
20937 @@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
20938 conditional_sti(regs);
20939
20940 #ifdef CONFIG_X86_32
20941 - if (regs->flags & X86_VM_MASK) {
20942 + if (v8086_mode(regs)) {
20943 local_irq_enable();
20944 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
20945 goto exit;
20946 @@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
20947 #endif
20948
20949 tsk = current;
20950 - if (!user_mode(regs)) {
20951 + if (!user_mode_novm(regs)) {
20952 if (fixup_exception(regs))
20953 goto exit;
20954
20955 tsk->thread.error_code = error_code;
20956 tsk->thread.trap_nr = X86_TRAP_GP;
20957 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
20958 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
20959 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
20960 +
20961 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20962 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20963 + die("PAX: suspicious general protection fault", regs, error_code);
20964 + else
20965 +#endif
20966 +
20967 die("general protection fault", regs, error_code);
20968 + }
20969 goto exit;
20970 }
20971
20972 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20973 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
20974 + struct mm_struct *mm = tsk->mm;
20975 + unsigned long limit;
20976 +
20977 + down_write(&mm->mmap_sem);
20978 + limit = mm->context.user_cs_limit;
20979 + if (limit < TASK_SIZE) {
20980 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
20981 + up_write(&mm->mmap_sem);
20982 + return;
20983 + }
20984 + up_write(&mm->mmap_sem);
20985 + }
20986 +#endif
20987 +
20988 tsk->thread.error_code = error_code;
20989 tsk->thread.trap_nr = X86_TRAP_GP;
20990
20991 @@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20992 /* It's safe to allow irq's after DR6 has been saved */
20993 preempt_conditional_sti(regs);
20994
20995 - if (regs->flags & X86_VM_MASK) {
20996 + if (v8086_mode(regs)) {
20997 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
20998 X86_TRAP_DB);
20999 preempt_conditional_cli(regs);
21000 @@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21001 * We already checked v86 mode above, so we can check for kernel mode
21002 * by just checking the CPL of CS.
21003 */
21004 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
21005 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21006 tsk->thread.debugreg6 &= ~DR_STEP;
21007 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21008 regs->flags &= ~X86_EFLAGS_TF;
21009 @@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21010 return;
21011 conditional_sti(regs);
21012
21013 - if (!user_mode_vm(regs))
21014 + if (!user_mode(regs))
21015 {
21016 if (!fixup_exception(regs)) {
21017 task->thread.error_code = error_code;
21018 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21019 index aafa555..a04691a 100644
21020 --- a/arch/x86/kernel/uprobes.c
21021 +++ b/arch/x86/kernel/uprobes.c
21022 @@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21023 int ret = NOTIFY_DONE;
21024
21025 /* We are only interested in userspace traps */
21026 - if (regs && !user_mode_vm(regs))
21027 + if (regs && !user_mode(regs))
21028 return NOTIFY_DONE;
21029
21030 switch (val) {
21031 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21032 index b9242ba..50c5edd 100644
21033 --- a/arch/x86/kernel/verify_cpu.S
21034 +++ b/arch/x86/kernel/verify_cpu.S
21035 @@ -20,6 +20,7 @@
21036 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21037 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21038 * arch/x86/kernel/head_32.S: processor startup
21039 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21040 *
21041 * verify_cpu, returns the status of longmode and SSE in register %eax.
21042 * 0: Success 1: Failure
21043 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21044 index 5c9687b..5f857d3 100644
21045 --- a/arch/x86/kernel/vm86_32.c
21046 +++ b/arch/x86/kernel/vm86_32.c
21047 @@ -43,6 +43,7 @@
21048 #include <linux/ptrace.h>
21049 #include <linux/audit.h>
21050 #include <linux/stddef.h>
21051 +#include <linux/grsecurity.h>
21052
21053 #include <asm/uaccess.h>
21054 #include <asm/io.h>
21055 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21056 do_exit(SIGSEGV);
21057 }
21058
21059 - tss = &per_cpu(init_tss, get_cpu());
21060 + tss = init_tss + get_cpu();
21061 current->thread.sp0 = current->thread.saved_sp0;
21062 current->thread.sysenter_cs = __KERNEL_CS;
21063 load_sp0(tss, &current->thread);
21064 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21065 struct task_struct *tsk;
21066 int tmp, ret = -EPERM;
21067
21068 +#ifdef CONFIG_GRKERNSEC_VM86
21069 + if (!capable(CAP_SYS_RAWIO)) {
21070 + gr_handle_vm86();
21071 + goto out;
21072 + }
21073 +#endif
21074 +
21075 tsk = current;
21076 if (tsk->thread.saved_sp0)
21077 goto out;
21078 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21079 int tmp, ret;
21080 struct vm86plus_struct __user *v86;
21081
21082 +#ifdef CONFIG_GRKERNSEC_VM86
21083 + if (!capable(CAP_SYS_RAWIO)) {
21084 + gr_handle_vm86();
21085 + ret = -EPERM;
21086 + goto out;
21087 + }
21088 +#endif
21089 +
21090 tsk = current;
21091 switch (cmd) {
21092 case VM86_REQUEST_IRQ:
21093 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21094 tsk->thread.saved_fs = info->regs32->fs;
21095 tsk->thread.saved_gs = get_user_gs(info->regs32);
21096
21097 - tss = &per_cpu(init_tss, get_cpu());
21098 + tss = init_tss + get_cpu();
21099 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21100 if (cpu_has_sep)
21101 tsk->thread.sysenter_cs = 0;
21102 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21103 goto cannot_handle;
21104 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21105 goto cannot_handle;
21106 - intr_ptr = (unsigned long __user *) (i << 2);
21107 + intr_ptr = (__force unsigned long __user *) (i << 2);
21108 if (get_user(segoffs, intr_ptr))
21109 goto cannot_handle;
21110 if ((segoffs >> 16) == BIOSSEG)
21111 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21112 index 22a1530..8fbaaad 100644
21113 --- a/arch/x86/kernel/vmlinux.lds.S
21114 +++ b/arch/x86/kernel/vmlinux.lds.S
21115 @@ -26,6 +26,13 @@
21116 #include <asm/page_types.h>
21117 #include <asm/cache.h>
21118 #include <asm/boot.h>
21119 +#include <asm/segment.h>
21120 +
21121 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21122 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21123 +#else
21124 +#define __KERNEL_TEXT_OFFSET 0
21125 +#endif
21126
21127 #undef i386 /* in case the preprocessor is a 32bit one */
21128
21129 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21130
21131 PHDRS {
21132 text PT_LOAD FLAGS(5); /* R_E */
21133 +#ifdef CONFIG_X86_32
21134 + module PT_LOAD FLAGS(5); /* R_E */
21135 +#endif
21136 +#ifdef CONFIG_XEN
21137 + rodata PT_LOAD FLAGS(5); /* R_E */
21138 +#else
21139 + rodata PT_LOAD FLAGS(4); /* R__ */
21140 +#endif
21141 data PT_LOAD FLAGS(6); /* RW_ */
21142 -#ifdef CONFIG_X86_64
21143 + init.begin PT_LOAD FLAGS(6); /* RW_ */
21144 #ifdef CONFIG_SMP
21145 percpu PT_LOAD FLAGS(6); /* RW_ */
21146 #endif
21147 + text.init PT_LOAD FLAGS(5); /* R_E */
21148 + text.exit PT_LOAD FLAGS(5); /* R_E */
21149 init PT_LOAD FLAGS(7); /* RWE */
21150 -#endif
21151 note PT_NOTE FLAGS(0); /* ___ */
21152 }
21153
21154 SECTIONS
21155 {
21156 #ifdef CONFIG_X86_32
21157 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21158 - phys_startup_32 = startup_32 - LOAD_OFFSET;
21159 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21160 #else
21161 - . = __START_KERNEL;
21162 - phys_startup_64 = startup_64 - LOAD_OFFSET;
21163 + . = __START_KERNEL;
21164 #endif
21165
21166 /* Text and read-only data */
21167 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
21168 - _text = .;
21169 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21170 /* bootstrapping code */
21171 +#ifdef CONFIG_X86_32
21172 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21173 +#else
21174 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21175 +#endif
21176 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21177 + _text = .;
21178 HEAD_TEXT
21179 #ifdef CONFIG_X86_32
21180 . = ALIGN(PAGE_SIZE);
21181 @@ -108,13 +128,48 @@ SECTIONS
21182 IRQENTRY_TEXT
21183 *(.fixup)
21184 *(.gnu.warning)
21185 - /* End of text section */
21186 - _etext = .;
21187 } :text = 0x9090
21188
21189 - NOTES :text :note
21190 + . += __KERNEL_TEXT_OFFSET;
21191
21192 - EXCEPTION_TABLE(16) :text = 0x9090
21193 +#ifdef CONFIG_X86_32
21194 + . = ALIGN(PAGE_SIZE);
21195 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21196 +
21197 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21198 + MODULES_EXEC_VADDR = .;
21199 + BYTE(0)
21200 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21201 + . = ALIGN(HPAGE_SIZE) - 1;
21202 + MODULES_EXEC_END = .;
21203 +#endif
21204 +
21205 + } :module
21206 +#endif
21207 +
21208 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21209 + /* End of text section */
21210 + BYTE(0)
21211 + _etext = . - __KERNEL_TEXT_OFFSET;
21212 + }
21213 +
21214 +#ifdef CONFIG_X86_32
21215 + . = ALIGN(PAGE_SIZE);
21216 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21217 + *(.idt)
21218 + . = ALIGN(PAGE_SIZE);
21219 + *(.empty_zero_page)
21220 + *(.initial_pg_fixmap)
21221 + *(.initial_pg_pmd)
21222 + *(.initial_page_table)
21223 + *(.swapper_pg_dir)
21224 + } :rodata
21225 +#endif
21226 +
21227 + . = ALIGN(PAGE_SIZE);
21228 + NOTES :rodata :note
21229 +
21230 + EXCEPTION_TABLE(16) :rodata
21231
21232 #if defined(CONFIG_DEBUG_RODATA)
21233 /* .text should occupy whole number of pages */
21234 @@ -126,16 +181,20 @@ SECTIONS
21235
21236 /* Data */
21237 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21238 +
21239 +#ifdef CONFIG_PAX_KERNEXEC
21240 + . = ALIGN(HPAGE_SIZE);
21241 +#else
21242 + . = ALIGN(PAGE_SIZE);
21243 +#endif
21244 +
21245 /* Start of data section */
21246 _sdata = .;
21247
21248 /* init_task */
21249 INIT_TASK_DATA(THREAD_SIZE)
21250
21251 -#ifdef CONFIG_X86_32
21252 - /* 32 bit has nosave before _edata */
21253 NOSAVE_DATA
21254 -#endif
21255
21256 PAGE_ALIGNED_DATA(PAGE_SIZE)
21257
21258 @@ -176,12 +235,19 @@ SECTIONS
21259 #endif /* CONFIG_X86_64 */
21260
21261 /* Init code and data - will be freed after init */
21262 - . = ALIGN(PAGE_SIZE);
21263 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21264 + BYTE(0)
21265 +
21266 +#ifdef CONFIG_PAX_KERNEXEC
21267 + . = ALIGN(HPAGE_SIZE);
21268 +#else
21269 + . = ALIGN(PAGE_SIZE);
21270 +#endif
21271 +
21272 __init_begin = .; /* paired with __init_end */
21273 - }
21274 + } :init.begin
21275
21276 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21277 +#ifdef CONFIG_SMP
21278 /*
21279 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21280 * output PHDR, so the next output section - .init.text - should
21281 @@ -190,12 +256,27 @@ SECTIONS
21282 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21283 #endif
21284
21285 - INIT_TEXT_SECTION(PAGE_SIZE)
21286 -#ifdef CONFIG_X86_64
21287 - :init
21288 -#endif
21289 + . = ALIGN(PAGE_SIZE);
21290 + init_begin = .;
21291 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21292 + VMLINUX_SYMBOL(_sinittext) = .;
21293 + INIT_TEXT
21294 + VMLINUX_SYMBOL(_einittext) = .;
21295 + . = ALIGN(PAGE_SIZE);
21296 + } :text.init
21297
21298 - INIT_DATA_SECTION(16)
21299 + /*
21300 + * .exit.text is discard at runtime, not link time, to deal with
21301 + * references from .altinstructions and .eh_frame
21302 + */
21303 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21304 + EXIT_TEXT
21305 + . = ALIGN(16);
21306 + } :text.exit
21307 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21308 +
21309 + . = ALIGN(PAGE_SIZE);
21310 + INIT_DATA_SECTION(16) :init
21311
21312 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21313 __x86_cpu_dev_start = .;
21314 @@ -257,19 +338,12 @@ SECTIONS
21315 }
21316
21317 . = ALIGN(8);
21318 - /*
21319 - * .exit.text is discard at runtime, not link time, to deal with
21320 - * references from .altinstructions and .eh_frame
21321 - */
21322 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21323 - EXIT_TEXT
21324 - }
21325
21326 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21327 EXIT_DATA
21328 }
21329
21330 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21331 +#ifndef CONFIG_SMP
21332 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21333 #endif
21334
21335 @@ -288,16 +362,10 @@ SECTIONS
21336 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21337 __smp_locks = .;
21338 *(.smp_locks)
21339 - . = ALIGN(PAGE_SIZE);
21340 __smp_locks_end = .;
21341 + . = ALIGN(PAGE_SIZE);
21342 }
21343
21344 -#ifdef CONFIG_X86_64
21345 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21346 - NOSAVE_DATA
21347 - }
21348 -#endif
21349 -
21350 /* BSS */
21351 . = ALIGN(PAGE_SIZE);
21352 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21353 @@ -313,6 +381,7 @@ SECTIONS
21354 __brk_base = .;
21355 . += 64 * 1024; /* 64k alignment slop space */
21356 *(.brk_reservation) /* areas brk users have reserved */
21357 + . = ALIGN(HPAGE_SIZE);
21358 __brk_limit = .;
21359 }
21360
21361 @@ -339,13 +408,12 @@ SECTIONS
21362 * for the boot processor.
21363 */
21364 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21365 -INIT_PER_CPU(gdt_page);
21366 INIT_PER_CPU(irq_stack_union);
21367
21368 /*
21369 * Build-time check on the image size:
21370 */
21371 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21372 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21373 "kernel image bigger than KERNEL_IMAGE_SIZE");
21374
21375 #ifdef CONFIG_SMP
21376 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
21377 index 992f890..0ab1aae 100644
21378 --- a/arch/x86/kernel/vsmp_64.c
21379 +++ b/arch/x86/kernel/vsmp_64.c
21380 @@ -114,7 +114,7 @@ static void __init set_vsmp_pv_ops(void)
21381 pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
21382 pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
21383 pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
21384 - pv_init_ops.patch = vsmp_patch;
21385 + *(void **)&pv_init_ops.patch = vsmp_patch;
21386 ctl &= ~(1 << 4);
21387 }
21388 writel(ctl, address + 4);
21389 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
21390 static void vsmp_apic_post_init(void)
21391 {
21392 /* need to update phys_pkg_id */
21393 - apic->phys_pkg_id = apicid_phys_pkg_id;
21394 - apic->vector_allocation_domain = fill_vector_allocation_domain;
21395 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
21396 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
21397 }
21398
21399 void __init vsmp_init(void)
21400 @@ -227,7 +227,7 @@ void __init vsmp_init(void)
21401 if (!is_vsmp_box())
21402 return;
21403
21404 - x86_platform.apic_post_init = vsmp_apic_post_init;
21405 + *(void **)&x86_platform.apic_post_init = vsmp_apic_post_init;
21406
21407 vsmp_cap_cpus();
21408
21409 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21410 index 3a3e8c9..1af9465 100644
21411 --- a/arch/x86/kernel/vsyscall_64.c
21412 +++ b/arch/x86/kernel/vsyscall_64.c
21413 @@ -56,15 +56,13 @@
21414 DEFINE_VVAR(int, vgetcpu_mode);
21415 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21416
21417 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21418 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21419
21420 static int __init vsyscall_setup(char *str)
21421 {
21422 if (str) {
21423 if (!strcmp("emulate", str))
21424 vsyscall_mode = EMULATE;
21425 - else if (!strcmp("native", str))
21426 - vsyscall_mode = NATIVE;
21427 else if (!strcmp("none", str))
21428 vsyscall_mode = NONE;
21429 else
21430 @@ -315,8 +313,7 @@ done:
21431 return true;
21432
21433 sigsegv:
21434 - force_sig(SIGSEGV, current);
21435 - return true;
21436 + do_group_exit(SIGKILL);
21437 }
21438
21439 /*
21440 @@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21441 extern char __vvar_page;
21442 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21443
21444 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21445 - vsyscall_mode == NATIVE
21446 - ? PAGE_KERNEL_VSYSCALL
21447 - : PAGE_KERNEL_VVAR);
21448 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21449 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21450 (unsigned long)VSYSCALL_START);
21451
21452 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21453 index 1330dd1..d220b99 100644
21454 --- a/arch/x86/kernel/x8664_ksyms_64.c
21455 +++ b/arch/x86/kernel/x8664_ksyms_64.c
21456 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21457 EXPORT_SYMBOL(copy_user_generic_unrolled);
21458 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21459 EXPORT_SYMBOL(__copy_user_nocache);
21460 -EXPORT_SYMBOL(_copy_from_user);
21461 -EXPORT_SYMBOL(_copy_to_user);
21462
21463 EXPORT_SYMBOL(copy_page);
21464 EXPORT_SYMBOL(clear_page);
21465 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21466 index ada87a3..afea76d 100644
21467 --- a/arch/x86/kernel/xsave.c
21468 +++ b/arch/x86/kernel/xsave.c
21469 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21470 {
21471 int err;
21472
21473 + buf = (struct xsave_struct __user *)____m(buf);
21474 if (use_xsave())
21475 err = xsave_user(buf);
21476 else if (use_fxsr())
21477 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21478 */
21479 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21480 {
21481 + buf = (void __user *)____m(buf);
21482 if (use_xsave()) {
21483 if ((unsigned long)buf % 64 || fx_only) {
21484 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21485 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21486 index ec79e77..420f5cc 100644
21487 --- a/arch/x86/kvm/cpuid.c
21488 +++ b/arch/x86/kvm/cpuid.c
21489 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21490 struct kvm_cpuid2 *cpuid,
21491 struct kvm_cpuid_entry2 __user *entries)
21492 {
21493 - int r;
21494 + int r, i;
21495
21496 r = -E2BIG;
21497 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21498 goto out;
21499 r = -EFAULT;
21500 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21501 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21502 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21503 goto out;
21504 + for (i = 0; i < cpuid->nent; ++i) {
21505 + struct kvm_cpuid_entry2 cpuid_entry;
21506 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21507 + goto out;
21508 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
21509 + }
21510 vcpu->arch.cpuid_nent = cpuid->nent;
21511 kvm_apic_set_version(vcpu);
21512 kvm_x86_ops->cpuid_update(vcpu);
21513 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21514 struct kvm_cpuid2 *cpuid,
21515 struct kvm_cpuid_entry2 __user *entries)
21516 {
21517 - int r;
21518 + int r, i;
21519
21520 r = -E2BIG;
21521 if (cpuid->nent < vcpu->arch.cpuid_nent)
21522 goto out;
21523 r = -EFAULT;
21524 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21525 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21526 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21527 goto out;
21528 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21529 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21530 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21531 + goto out;
21532 + }
21533 return 0;
21534
21535 out:
21536 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21537 index bba39bf..296540a 100644
21538 --- a/arch/x86/kvm/emulate.c
21539 +++ b/arch/x86/kvm/emulate.c
21540 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21541
21542 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21543 do { \
21544 + unsigned long _tmp; \
21545 __asm__ __volatile__ ( \
21546 _PRE_EFLAGS("0", "4", "2") \
21547 _op _suffix " %"_x"3,%1; " \
21548 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21549 /* Raw emulation: instruction has two explicit operands. */
21550 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21551 do { \
21552 - unsigned long _tmp; \
21553 - \
21554 switch ((ctxt)->dst.bytes) { \
21555 case 2: \
21556 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21557 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21558
21559 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21560 do { \
21561 - unsigned long _tmp; \
21562 switch ((ctxt)->dst.bytes) { \
21563 case 1: \
21564 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21565 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21566 index 43e9fad..3b7c059 100644
21567 --- a/arch/x86/kvm/lapic.c
21568 +++ b/arch/x86/kvm/lapic.c
21569 @@ -55,7 +55,7 @@
21570 #define APIC_BUS_CYCLE_NS 1
21571
21572 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21573 -#define apic_debug(fmt, arg...)
21574 +#define apic_debug(fmt, arg...) do {} while (0)
21575
21576 #define APIC_LVT_NUM 6
21577 /* 14 is the version for Xeon and Pentium 8.4.8*/
21578 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21579 index 714e2c0..3f7a086 100644
21580 --- a/arch/x86/kvm/paging_tmpl.h
21581 +++ b/arch/x86/kvm/paging_tmpl.h
21582 @@ -208,7 +208,7 @@ retry_walk:
21583 if (unlikely(kvm_is_error_hva(host_addr)))
21584 goto error;
21585
21586 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21587 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21588 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21589 goto error;
21590 walker->ptep_user[walker->level - 1] = ptep_user;
21591 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21592 index d017df3..61ae42e 100644
21593 --- a/arch/x86/kvm/svm.c
21594 +++ b/arch/x86/kvm/svm.c
21595 @@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21596 int cpu = raw_smp_processor_id();
21597
21598 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21599 +
21600 + pax_open_kernel();
21601 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21602 + pax_close_kernel();
21603 +
21604 load_TR_desc();
21605 }
21606
21607 @@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21608 #endif
21609 #endif
21610
21611 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21612 + __set_fs(current_thread_info()->addr_limit);
21613 +#endif
21614 +
21615 reload_tss(vcpu);
21616
21617 local_irq_disable();
21618 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21619 index f858159..4ab7dba 100644
21620 --- a/arch/x86/kvm/vmx.c
21621 +++ b/arch/x86/kvm/vmx.c
21622 @@ -1332,7 +1332,11 @@ static void reload_tss(void)
21623 struct desc_struct *descs;
21624
21625 descs = (void *)gdt->address;
21626 +
21627 + pax_open_kernel();
21628 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21629 + pax_close_kernel();
21630 +
21631 load_TR_desc();
21632 }
21633
21634 @@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21635 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
21636 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
21637
21638 +#ifdef CONFIG_PAX_PER_CPU_PGD
21639 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21640 +#endif
21641 +
21642 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21643 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21644 vmx->loaded_vmcs->cpu = cpu;
21645 @@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
21646 if (!cpu_has_vmx_flexpriority())
21647 flexpriority_enabled = 0;
21648
21649 - if (!cpu_has_vmx_tpr_shadow())
21650 - kvm_x86_ops->update_cr8_intercept = NULL;
21651 + if (!cpu_has_vmx_tpr_shadow()) {
21652 + pax_open_kernel();
21653 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21654 + pax_close_kernel();
21655 + }
21656
21657 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21658 kvm_disable_largepages();
21659 @@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
21660
21661 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
21662 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
21663 +
21664 +#ifndef CONFIG_PAX_PER_CPU_PGD
21665 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21666 +#endif
21667
21668 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
21669 #ifdef CONFIG_X86_64
21670 @@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
21671 native_store_idt(&dt);
21672 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
21673
21674 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
21675 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
21676
21677 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
21678 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
21679 @@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21680 "jmp 2f \n\t"
21681 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
21682 "2: "
21683 +
21684 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21685 + "ljmp %[cs],$3f\n\t"
21686 + "3: "
21687 +#endif
21688 +
21689 /* Save guest registers, load host registers, keep flags */
21690 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
21691 "pop %0 \n\t"
21692 @@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21693 #endif
21694 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
21695 [wordsize]"i"(sizeof(ulong))
21696 +
21697 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21698 + ,[cs]"i"(__KERNEL_CS)
21699 +#endif
21700 +
21701 : "cc", "memory"
21702 #ifdef CONFIG_X86_64
21703 , "rax", "rbx", "rdi", "rsi"
21704 @@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21705 if (debugctlmsr)
21706 update_debugctlmsr(debugctlmsr);
21707
21708 -#ifndef CONFIG_X86_64
21709 +#ifdef CONFIG_X86_32
21710 /*
21711 * The sysexit path does not restore ds/es, so we must set them to
21712 * a reasonable value ourselves.
21713 @@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21714 * may be executed in interrupt context, which saves and restore segments
21715 * around it, nullifying its effect.
21716 */
21717 - loadsegment(ds, __USER_DS);
21718 - loadsegment(es, __USER_DS);
21719 + loadsegment(ds, __KERNEL_DS);
21720 + loadsegment(es, __KERNEL_DS);
21721 + loadsegment(ss, __KERNEL_DS);
21722 +
21723 +#ifdef CONFIG_PAX_KERNEXEC
21724 + loadsegment(fs, __KERNEL_PERCPU);
21725 +#endif
21726 +
21727 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21728 + __set_fs(current_thread_info()->addr_limit);
21729 +#endif
21730 +
21731 #endif
21732
21733 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
21734 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
21735 index 4f76417..93429b5 100644
21736 --- a/arch/x86/kvm/x86.c
21737 +++ b/arch/x86/kvm/x86.c
21738 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
21739 {
21740 struct kvm *kvm = vcpu->kvm;
21741 int lm = is_long_mode(vcpu);
21742 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
21743 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
21744 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
21745 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
21746 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
21747 : kvm->arch.xen_hvm_config.blob_size_32;
21748 u32 page_num = data & ~PAGE_MASK;
21749 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
21750 if (n < msr_list.nmsrs)
21751 goto out;
21752 r = -EFAULT;
21753 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
21754 + goto out;
21755 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
21756 num_msrs_to_save * sizeof(u32)))
21757 goto out;
21758 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
21759 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
21760 struct kvm_interrupt *irq)
21761 {
21762 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
21763 + if (irq->irq >= KVM_NR_INTERRUPTS)
21764 return -EINVAL;
21765 if (irqchip_in_kernel(vcpu->kvm))
21766 return -ENXIO;
21767 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
21768 kvm_mmu_set_mmio_spte_mask(mask);
21769 }
21770
21771 -int kvm_arch_init(void *opaque)
21772 +int kvm_arch_init(const void *opaque)
21773 {
21774 int r;
21775 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
21776 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
21777 index 642d880..5dd034e 100644
21778 --- a/arch/x86/lguest/boot.c
21779 +++ b/arch/x86/lguest/boot.c
21780 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
21781
21782 static void set_lguest_basic_apic_ops(void)
21783 {
21784 - apic->read = lguest_apic_read;
21785 - apic->write = lguest_apic_write;
21786 - apic->icr_read = lguest_apic_icr_read;
21787 - apic->icr_write = lguest_apic_icr_write;
21788 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
21789 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
21790 + *(void **)&apic->read = lguest_apic_read;
21791 + *(void **)&apic->write = lguest_apic_write;
21792 + *(void **)&apic->icr_read = lguest_apic_icr_read;
21793 + *(void **)&apic->icr_write = lguest_apic_icr_write;
21794 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
21795 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
21796 };
21797 #endif
21798
21799 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
21800 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
21801 * Launcher to reboot us.
21802 */
21803 -static void lguest_restart(char *reason)
21804 +static __noreturn void lguest_restart(char *reason)
21805 {
21806 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
21807 + BUG();
21808 }
21809
21810 /*G:050
21811 @@ -1292,28 +1293,28 @@ __init void lguest_init(void)
21812 pv_irq_ops.safe_halt = lguest_safe_halt;
21813
21814 /* Setup operations */
21815 - pv_init_ops.patch = lguest_patch;
21816 + *(void **)&pv_init_ops.patch = lguest_patch;
21817
21818 /* Intercepts of various CPU instructions */
21819 - pv_cpu_ops.load_gdt = lguest_load_gdt;
21820 - pv_cpu_ops.cpuid = lguest_cpuid;
21821 - pv_cpu_ops.load_idt = lguest_load_idt;
21822 - pv_cpu_ops.iret = lguest_iret;
21823 - pv_cpu_ops.load_sp0 = lguest_load_sp0;
21824 - pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
21825 - pv_cpu_ops.set_ldt = lguest_set_ldt;
21826 - pv_cpu_ops.load_tls = lguest_load_tls;
21827 - pv_cpu_ops.set_debugreg = lguest_set_debugreg;
21828 - pv_cpu_ops.clts = lguest_clts;
21829 - pv_cpu_ops.read_cr0 = lguest_read_cr0;
21830 - pv_cpu_ops.write_cr0 = lguest_write_cr0;
21831 - pv_cpu_ops.read_cr4 = lguest_read_cr4;
21832 - pv_cpu_ops.write_cr4 = lguest_write_cr4;
21833 - pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
21834 - pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
21835 - pv_cpu_ops.wbinvd = lguest_wbinvd;
21836 - pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
21837 - pv_cpu_ops.end_context_switch = lguest_end_context_switch;
21838 + *(void **)&pv_cpu_ops.load_gdt = lguest_load_gdt;
21839 + *(void **)&pv_cpu_ops.cpuid = lguest_cpuid;
21840 + *(void **)&pv_cpu_ops.load_idt = lguest_load_idt;
21841 + *(void **)&pv_cpu_ops.iret = lguest_iret;
21842 + *(void **)&pv_cpu_ops.load_sp0 = lguest_load_sp0;
21843 + *(void **)&pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
21844 + *(void **)&pv_cpu_ops.set_ldt = lguest_set_ldt;
21845 + *(void **)&pv_cpu_ops.load_tls = lguest_load_tls;
21846 + *(void **)&pv_cpu_ops.set_debugreg = lguest_set_debugreg;
21847 + *(void **)&pv_cpu_ops.clts = lguest_clts;
21848 + *(void **)&pv_cpu_ops.read_cr0 = lguest_read_cr0;
21849 + *(void **)&pv_cpu_ops.write_cr0 = lguest_write_cr0;
21850 + *(void **)&pv_cpu_ops.read_cr4 = lguest_read_cr4;
21851 + *(void **)&pv_cpu_ops.write_cr4 = lguest_write_cr4;
21852 + *(void **)&pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
21853 + *(void **)&pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
21854 + *(void **)&pv_cpu_ops.wbinvd = lguest_wbinvd;
21855 + *(void **)&pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
21856 + *(void **)&pv_cpu_ops.end_context_switch = lguest_end_context_switch;
21857
21858 /* Pagetable management */
21859 pv_mmu_ops.write_cr3 = lguest_write_cr3;
21860 @@ -1341,11 +1342,11 @@ __init void lguest_init(void)
21861 set_lguest_basic_apic_ops();
21862 #endif
21863
21864 - x86_init.resources.memory_setup = lguest_memory_setup;
21865 - x86_init.irqs.intr_init = lguest_init_IRQ;
21866 - x86_init.timers.timer_init = lguest_time_init;
21867 - x86_platform.calibrate_tsc = lguest_tsc_khz;
21868 - x86_platform.get_wallclock = lguest_get_wallclock;
21869 + *(void **)&x86_init.resources.memory_setup = lguest_memory_setup;
21870 + *(void **)&x86_init.irqs.intr_init = lguest_init_IRQ;
21871 + *(void **)&x86_init.timers.timer_init = lguest_time_init;
21872 + *(void **)&x86_platform.calibrate_tsc = lguest_tsc_khz;
21873 + *(void **)&x86_platform.get_wallclock = lguest_get_wallclock;
21874
21875 /*
21876 * Now is a good time to look at the implementations of these functions
21877 @@ -1434,7 +1435,7 @@ __init void lguest_init(void)
21878 * routine.
21879 */
21880 pm_power_off = lguest_power_off;
21881 - machine_ops.restart = lguest_restart;
21882 + *(void **)&machine_ops.restart = lguest_restart;
21883
21884 /*
21885 * Now we're set up, call i386_start_kernel() in head32.c and we proceed
21886 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
21887 index 00933d5..3a64af9 100644
21888 --- a/arch/x86/lib/atomic64_386_32.S
21889 +++ b/arch/x86/lib/atomic64_386_32.S
21890 @@ -48,6 +48,10 @@ BEGIN(read)
21891 movl (v), %eax
21892 movl 4(v), %edx
21893 RET_ENDP
21894 +BEGIN(read_unchecked)
21895 + movl (v), %eax
21896 + movl 4(v), %edx
21897 +RET_ENDP
21898 #undef v
21899
21900 #define v %esi
21901 @@ -55,6 +59,10 @@ BEGIN(set)
21902 movl %ebx, (v)
21903 movl %ecx, 4(v)
21904 RET_ENDP
21905 +BEGIN(set_unchecked)
21906 + movl %ebx, (v)
21907 + movl %ecx, 4(v)
21908 +RET_ENDP
21909 #undef v
21910
21911 #define v %esi
21912 @@ -70,6 +78,20 @@ RET_ENDP
21913 BEGIN(add)
21914 addl %eax, (v)
21915 adcl %edx, 4(v)
21916 +
21917 +#ifdef CONFIG_PAX_REFCOUNT
21918 + jno 0f
21919 + subl %eax, (v)
21920 + sbbl %edx, 4(v)
21921 + int $4
21922 +0:
21923 + _ASM_EXTABLE(0b, 0b)
21924 +#endif
21925 +
21926 +RET_ENDP
21927 +BEGIN(add_unchecked)
21928 + addl %eax, (v)
21929 + adcl %edx, 4(v)
21930 RET_ENDP
21931 #undef v
21932
21933 @@ -77,6 +99,24 @@ RET_ENDP
21934 BEGIN(add_return)
21935 addl (v), %eax
21936 adcl 4(v), %edx
21937 +
21938 +#ifdef CONFIG_PAX_REFCOUNT
21939 + into
21940 +1234:
21941 + _ASM_EXTABLE(1234b, 2f)
21942 +#endif
21943 +
21944 + movl %eax, (v)
21945 + movl %edx, 4(v)
21946 +
21947 +#ifdef CONFIG_PAX_REFCOUNT
21948 +2:
21949 +#endif
21950 +
21951 +RET_ENDP
21952 +BEGIN(add_return_unchecked)
21953 + addl (v), %eax
21954 + adcl 4(v), %edx
21955 movl %eax, (v)
21956 movl %edx, 4(v)
21957 RET_ENDP
21958 @@ -86,6 +126,20 @@ RET_ENDP
21959 BEGIN(sub)
21960 subl %eax, (v)
21961 sbbl %edx, 4(v)
21962 +
21963 +#ifdef CONFIG_PAX_REFCOUNT
21964 + jno 0f
21965 + addl %eax, (v)
21966 + adcl %edx, 4(v)
21967 + int $4
21968 +0:
21969 + _ASM_EXTABLE(0b, 0b)
21970 +#endif
21971 +
21972 +RET_ENDP
21973 +BEGIN(sub_unchecked)
21974 + subl %eax, (v)
21975 + sbbl %edx, 4(v)
21976 RET_ENDP
21977 #undef v
21978
21979 @@ -96,6 +150,27 @@ BEGIN(sub_return)
21980 sbbl $0, %edx
21981 addl (v), %eax
21982 adcl 4(v), %edx
21983 +
21984 +#ifdef CONFIG_PAX_REFCOUNT
21985 + into
21986 +1234:
21987 + _ASM_EXTABLE(1234b, 2f)
21988 +#endif
21989 +
21990 + movl %eax, (v)
21991 + movl %edx, 4(v)
21992 +
21993 +#ifdef CONFIG_PAX_REFCOUNT
21994 +2:
21995 +#endif
21996 +
21997 +RET_ENDP
21998 +BEGIN(sub_return_unchecked)
21999 + negl %edx
22000 + negl %eax
22001 + sbbl $0, %edx
22002 + addl (v), %eax
22003 + adcl 4(v), %edx
22004 movl %eax, (v)
22005 movl %edx, 4(v)
22006 RET_ENDP
22007 @@ -105,6 +180,20 @@ RET_ENDP
22008 BEGIN(inc)
22009 addl $1, (v)
22010 adcl $0, 4(v)
22011 +
22012 +#ifdef CONFIG_PAX_REFCOUNT
22013 + jno 0f
22014 + subl $1, (v)
22015 + sbbl $0, 4(v)
22016 + int $4
22017 +0:
22018 + _ASM_EXTABLE(0b, 0b)
22019 +#endif
22020 +
22021 +RET_ENDP
22022 +BEGIN(inc_unchecked)
22023 + addl $1, (v)
22024 + adcl $0, 4(v)
22025 RET_ENDP
22026 #undef v
22027
22028 @@ -114,6 +203,26 @@ BEGIN(inc_return)
22029 movl 4(v), %edx
22030 addl $1, %eax
22031 adcl $0, %edx
22032 +
22033 +#ifdef CONFIG_PAX_REFCOUNT
22034 + into
22035 +1234:
22036 + _ASM_EXTABLE(1234b, 2f)
22037 +#endif
22038 +
22039 + movl %eax, (v)
22040 + movl %edx, 4(v)
22041 +
22042 +#ifdef CONFIG_PAX_REFCOUNT
22043 +2:
22044 +#endif
22045 +
22046 +RET_ENDP
22047 +BEGIN(inc_return_unchecked)
22048 + movl (v), %eax
22049 + movl 4(v), %edx
22050 + addl $1, %eax
22051 + adcl $0, %edx
22052 movl %eax, (v)
22053 movl %edx, 4(v)
22054 RET_ENDP
22055 @@ -123,6 +232,20 @@ RET_ENDP
22056 BEGIN(dec)
22057 subl $1, (v)
22058 sbbl $0, 4(v)
22059 +
22060 +#ifdef CONFIG_PAX_REFCOUNT
22061 + jno 0f
22062 + addl $1, (v)
22063 + adcl $0, 4(v)
22064 + int $4
22065 +0:
22066 + _ASM_EXTABLE(0b, 0b)
22067 +#endif
22068 +
22069 +RET_ENDP
22070 +BEGIN(dec_unchecked)
22071 + subl $1, (v)
22072 + sbbl $0, 4(v)
22073 RET_ENDP
22074 #undef v
22075
22076 @@ -132,6 +255,26 @@ BEGIN(dec_return)
22077 movl 4(v), %edx
22078 subl $1, %eax
22079 sbbl $0, %edx
22080 +
22081 +#ifdef CONFIG_PAX_REFCOUNT
22082 + into
22083 +1234:
22084 + _ASM_EXTABLE(1234b, 2f)
22085 +#endif
22086 +
22087 + movl %eax, (v)
22088 + movl %edx, 4(v)
22089 +
22090 +#ifdef CONFIG_PAX_REFCOUNT
22091 +2:
22092 +#endif
22093 +
22094 +RET_ENDP
22095 +BEGIN(dec_return_unchecked)
22096 + movl (v), %eax
22097 + movl 4(v), %edx
22098 + subl $1, %eax
22099 + sbbl $0, %edx
22100 movl %eax, (v)
22101 movl %edx, 4(v)
22102 RET_ENDP
22103 @@ -143,6 +286,13 @@ BEGIN(add_unless)
22104 adcl %edx, %edi
22105 addl (v), %eax
22106 adcl 4(v), %edx
22107 +
22108 +#ifdef CONFIG_PAX_REFCOUNT
22109 + into
22110 +1234:
22111 + _ASM_EXTABLE(1234b, 2f)
22112 +#endif
22113 +
22114 cmpl %eax, %ecx
22115 je 3f
22116 1:
22117 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22118 1:
22119 addl $1, %eax
22120 adcl $0, %edx
22121 +
22122 +#ifdef CONFIG_PAX_REFCOUNT
22123 + into
22124 +1234:
22125 + _ASM_EXTABLE(1234b, 2f)
22126 +#endif
22127 +
22128 movl %eax, (v)
22129 movl %edx, 4(v)
22130 movl $1, %eax
22131 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22132 movl 4(v), %edx
22133 subl $1, %eax
22134 sbbl $0, %edx
22135 +
22136 +#ifdef CONFIG_PAX_REFCOUNT
22137 + into
22138 +1234:
22139 + _ASM_EXTABLE(1234b, 1f)
22140 +#endif
22141 +
22142 js 1f
22143 movl %eax, (v)
22144 movl %edx, 4(v)
22145 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22146 index f5cc9eb..51fa319 100644
22147 --- a/arch/x86/lib/atomic64_cx8_32.S
22148 +++ b/arch/x86/lib/atomic64_cx8_32.S
22149 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22150 CFI_STARTPROC
22151
22152 read64 %ecx
22153 + pax_force_retaddr
22154 ret
22155 CFI_ENDPROC
22156 ENDPROC(atomic64_read_cx8)
22157
22158 +ENTRY(atomic64_read_unchecked_cx8)
22159 + CFI_STARTPROC
22160 +
22161 + read64 %ecx
22162 + pax_force_retaddr
22163 + ret
22164 + CFI_ENDPROC
22165 +ENDPROC(atomic64_read_unchecked_cx8)
22166 +
22167 ENTRY(atomic64_set_cx8)
22168 CFI_STARTPROC
22169
22170 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22171 cmpxchg8b (%esi)
22172 jne 1b
22173
22174 + pax_force_retaddr
22175 ret
22176 CFI_ENDPROC
22177 ENDPROC(atomic64_set_cx8)
22178
22179 +ENTRY(atomic64_set_unchecked_cx8)
22180 + CFI_STARTPROC
22181 +
22182 +1:
22183 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
22184 + * are atomic on 586 and newer */
22185 + cmpxchg8b (%esi)
22186 + jne 1b
22187 +
22188 + pax_force_retaddr
22189 + ret
22190 + CFI_ENDPROC
22191 +ENDPROC(atomic64_set_unchecked_cx8)
22192 +
22193 ENTRY(atomic64_xchg_cx8)
22194 CFI_STARTPROC
22195
22196 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22197 cmpxchg8b (%esi)
22198 jne 1b
22199
22200 + pax_force_retaddr
22201 ret
22202 CFI_ENDPROC
22203 ENDPROC(atomic64_xchg_cx8)
22204
22205 -.macro addsub_return func ins insc
22206 -ENTRY(atomic64_\func\()_return_cx8)
22207 +.macro addsub_return func ins insc unchecked=""
22208 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22209 CFI_STARTPROC
22210 SAVE ebp
22211 SAVE ebx
22212 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22213 movl %edx, %ecx
22214 \ins\()l %esi, %ebx
22215 \insc\()l %edi, %ecx
22216 +
22217 +.ifb \unchecked
22218 +#ifdef CONFIG_PAX_REFCOUNT
22219 + into
22220 +2:
22221 + _ASM_EXTABLE(2b, 3f)
22222 +#endif
22223 +.endif
22224 +
22225 LOCK_PREFIX
22226 cmpxchg8b (%ebp)
22227 jne 1b
22228 -
22229 -10:
22230 movl %ebx, %eax
22231 movl %ecx, %edx
22232 +
22233 +.ifb \unchecked
22234 +#ifdef CONFIG_PAX_REFCOUNT
22235 +3:
22236 +#endif
22237 +.endif
22238 +
22239 RESTORE edi
22240 RESTORE esi
22241 RESTORE ebx
22242 RESTORE ebp
22243 + pax_force_retaddr
22244 ret
22245 CFI_ENDPROC
22246 -ENDPROC(atomic64_\func\()_return_cx8)
22247 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22248 .endm
22249
22250 addsub_return add add adc
22251 addsub_return sub sub sbb
22252 +addsub_return add add adc _unchecked
22253 +addsub_return sub sub sbb _unchecked
22254
22255 -.macro incdec_return func ins insc
22256 -ENTRY(atomic64_\func\()_return_cx8)
22257 +.macro incdec_return func ins insc unchecked=""
22258 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22259 CFI_STARTPROC
22260 SAVE ebx
22261
22262 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22263 movl %edx, %ecx
22264 \ins\()l $1, %ebx
22265 \insc\()l $0, %ecx
22266 +
22267 +.ifb \unchecked
22268 +#ifdef CONFIG_PAX_REFCOUNT
22269 + into
22270 +2:
22271 + _ASM_EXTABLE(2b, 3f)
22272 +#endif
22273 +.endif
22274 +
22275 LOCK_PREFIX
22276 cmpxchg8b (%esi)
22277 jne 1b
22278
22279 -10:
22280 movl %ebx, %eax
22281 movl %ecx, %edx
22282 +
22283 +.ifb \unchecked
22284 +#ifdef CONFIG_PAX_REFCOUNT
22285 +3:
22286 +#endif
22287 +.endif
22288 +
22289 RESTORE ebx
22290 + pax_force_retaddr
22291 ret
22292 CFI_ENDPROC
22293 -ENDPROC(atomic64_\func\()_return_cx8)
22294 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22295 .endm
22296
22297 incdec_return inc add adc
22298 incdec_return dec sub sbb
22299 +incdec_return inc add adc _unchecked
22300 +incdec_return dec sub sbb _unchecked
22301
22302 ENTRY(atomic64_dec_if_positive_cx8)
22303 CFI_STARTPROC
22304 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22305 movl %edx, %ecx
22306 subl $1, %ebx
22307 sbb $0, %ecx
22308 +
22309 +#ifdef CONFIG_PAX_REFCOUNT
22310 + into
22311 +1234:
22312 + _ASM_EXTABLE(1234b, 2f)
22313 +#endif
22314 +
22315 js 2f
22316 LOCK_PREFIX
22317 cmpxchg8b (%esi)
22318 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22319 movl %ebx, %eax
22320 movl %ecx, %edx
22321 RESTORE ebx
22322 + pax_force_retaddr
22323 ret
22324 CFI_ENDPROC
22325 ENDPROC(atomic64_dec_if_positive_cx8)
22326 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22327 movl %edx, %ecx
22328 addl %ebp, %ebx
22329 adcl %edi, %ecx
22330 +
22331 +#ifdef CONFIG_PAX_REFCOUNT
22332 + into
22333 +1234:
22334 + _ASM_EXTABLE(1234b, 3f)
22335 +#endif
22336 +
22337 LOCK_PREFIX
22338 cmpxchg8b (%esi)
22339 jne 1b
22340 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22341 CFI_ADJUST_CFA_OFFSET -8
22342 RESTORE ebx
22343 RESTORE ebp
22344 + pax_force_retaddr
22345 ret
22346 4:
22347 cmpl %edx, 4(%esp)
22348 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22349 xorl %ecx, %ecx
22350 addl $1, %ebx
22351 adcl %edx, %ecx
22352 +
22353 +#ifdef CONFIG_PAX_REFCOUNT
22354 + into
22355 +1234:
22356 + _ASM_EXTABLE(1234b, 3f)
22357 +#endif
22358 +
22359 LOCK_PREFIX
22360 cmpxchg8b (%esi)
22361 jne 1b
22362 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22363 movl $1, %eax
22364 3:
22365 RESTORE ebx
22366 + pax_force_retaddr
22367 ret
22368 CFI_ENDPROC
22369 ENDPROC(atomic64_inc_not_zero_cx8)
22370 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22371 index 2af5df3..62b1a5a 100644
22372 --- a/arch/x86/lib/checksum_32.S
22373 +++ b/arch/x86/lib/checksum_32.S
22374 @@ -29,7 +29,8 @@
22375 #include <asm/dwarf2.h>
22376 #include <asm/errno.h>
22377 #include <asm/asm.h>
22378 -
22379 +#include <asm/segment.h>
22380 +
22381 /*
22382 * computes a partial checksum, e.g. for TCP/UDP fragments
22383 */
22384 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22385
22386 #define ARGBASE 16
22387 #define FP 12
22388 -
22389 -ENTRY(csum_partial_copy_generic)
22390 +
22391 +ENTRY(csum_partial_copy_generic_to_user)
22392 CFI_STARTPROC
22393 +
22394 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22395 + pushl_cfi %gs
22396 + popl_cfi %es
22397 + jmp csum_partial_copy_generic
22398 +#endif
22399 +
22400 +ENTRY(csum_partial_copy_generic_from_user)
22401 +
22402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22403 + pushl_cfi %gs
22404 + popl_cfi %ds
22405 +#endif
22406 +
22407 +ENTRY(csum_partial_copy_generic)
22408 subl $4,%esp
22409 CFI_ADJUST_CFA_OFFSET 4
22410 pushl_cfi %edi
22411 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22412 jmp 4f
22413 SRC(1: movw (%esi), %bx )
22414 addl $2, %esi
22415 -DST( movw %bx, (%edi) )
22416 +DST( movw %bx, %es:(%edi) )
22417 addl $2, %edi
22418 addw %bx, %ax
22419 adcl $0, %eax
22420 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22421 SRC(1: movl (%esi), %ebx )
22422 SRC( movl 4(%esi), %edx )
22423 adcl %ebx, %eax
22424 -DST( movl %ebx, (%edi) )
22425 +DST( movl %ebx, %es:(%edi) )
22426 adcl %edx, %eax
22427 -DST( movl %edx, 4(%edi) )
22428 +DST( movl %edx, %es:4(%edi) )
22429
22430 SRC( movl 8(%esi), %ebx )
22431 SRC( movl 12(%esi), %edx )
22432 adcl %ebx, %eax
22433 -DST( movl %ebx, 8(%edi) )
22434 +DST( movl %ebx, %es:8(%edi) )
22435 adcl %edx, %eax
22436 -DST( movl %edx, 12(%edi) )
22437 +DST( movl %edx, %es:12(%edi) )
22438
22439 SRC( movl 16(%esi), %ebx )
22440 SRC( movl 20(%esi), %edx )
22441 adcl %ebx, %eax
22442 -DST( movl %ebx, 16(%edi) )
22443 +DST( movl %ebx, %es:16(%edi) )
22444 adcl %edx, %eax
22445 -DST( movl %edx, 20(%edi) )
22446 +DST( movl %edx, %es:20(%edi) )
22447
22448 SRC( movl 24(%esi), %ebx )
22449 SRC( movl 28(%esi), %edx )
22450 adcl %ebx, %eax
22451 -DST( movl %ebx, 24(%edi) )
22452 +DST( movl %ebx, %es:24(%edi) )
22453 adcl %edx, %eax
22454 -DST( movl %edx, 28(%edi) )
22455 +DST( movl %edx, %es:28(%edi) )
22456
22457 lea 32(%esi), %esi
22458 lea 32(%edi), %edi
22459 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22460 shrl $2, %edx # This clears CF
22461 SRC(3: movl (%esi), %ebx )
22462 adcl %ebx, %eax
22463 -DST( movl %ebx, (%edi) )
22464 +DST( movl %ebx, %es:(%edi) )
22465 lea 4(%esi), %esi
22466 lea 4(%edi), %edi
22467 dec %edx
22468 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22469 jb 5f
22470 SRC( movw (%esi), %cx )
22471 leal 2(%esi), %esi
22472 -DST( movw %cx, (%edi) )
22473 +DST( movw %cx, %es:(%edi) )
22474 leal 2(%edi), %edi
22475 je 6f
22476 shll $16,%ecx
22477 SRC(5: movb (%esi), %cl )
22478 -DST( movb %cl, (%edi) )
22479 +DST( movb %cl, %es:(%edi) )
22480 6: addl %ecx, %eax
22481 adcl $0, %eax
22482 7:
22483 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22484
22485 6001:
22486 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22487 - movl $-EFAULT, (%ebx)
22488 + movl $-EFAULT, %ss:(%ebx)
22489
22490 # zero the complete destination - computing the rest
22491 # is too much work
22492 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22493
22494 6002:
22495 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22496 - movl $-EFAULT,(%ebx)
22497 + movl $-EFAULT,%ss:(%ebx)
22498 jmp 5000b
22499
22500 .previous
22501
22502 + pushl_cfi %ss
22503 + popl_cfi %ds
22504 + pushl_cfi %ss
22505 + popl_cfi %es
22506 popl_cfi %ebx
22507 CFI_RESTORE ebx
22508 popl_cfi %esi
22509 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22510 popl_cfi %ecx # equivalent to addl $4,%esp
22511 ret
22512 CFI_ENDPROC
22513 -ENDPROC(csum_partial_copy_generic)
22514 +ENDPROC(csum_partial_copy_generic_to_user)
22515
22516 #else
22517
22518 /* Version for PentiumII/PPro */
22519
22520 #define ROUND1(x) \
22521 + nop; nop; nop; \
22522 SRC(movl x(%esi), %ebx ) ; \
22523 addl %ebx, %eax ; \
22524 - DST(movl %ebx, x(%edi) ) ;
22525 + DST(movl %ebx, %es:x(%edi)) ;
22526
22527 #define ROUND(x) \
22528 + nop; nop; nop; \
22529 SRC(movl x(%esi), %ebx ) ; \
22530 adcl %ebx, %eax ; \
22531 - DST(movl %ebx, x(%edi) ) ;
22532 + DST(movl %ebx, %es:x(%edi)) ;
22533
22534 #define ARGBASE 12
22535 -
22536 -ENTRY(csum_partial_copy_generic)
22537 +
22538 +ENTRY(csum_partial_copy_generic_to_user)
22539 CFI_STARTPROC
22540 +
22541 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22542 + pushl_cfi %gs
22543 + popl_cfi %es
22544 + jmp csum_partial_copy_generic
22545 +#endif
22546 +
22547 +ENTRY(csum_partial_copy_generic_from_user)
22548 +
22549 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22550 + pushl_cfi %gs
22551 + popl_cfi %ds
22552 +#endif
22553 +
22554 +ENTRY(csum_partial_copy_generic)
22555 pushl_cfi %ebx
22556 CFI_REL_OFFSET ebx, 0
22557 pushl_cfi %edi
22558 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22559 subl %ebx, %edi
22560 lea -1(%esi),%edx
22561 andl $-32,%edx
22562 - lea 3f(%ebx,%ebx), %ebx
22563 + lea 3f(%ebx,%ebx,2), %ebx
22564 testl %esi, %esi
22565 jmp *%ebx
22566 1: addl $64,%esi
22567 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22568 jb 5f
22569 SRC( movw (%esi), %dx )
22570 leal 2(%esi), %esi
22571 -DST( movw %dx, (%edi) )
22572 +DST( movw %dx, %es:(%edi) )
22573 leal 2(%edi), %edi
22574 je 6f
22575 shll $16,%edx
22576 5:
22577 SRC( movb (%esi), %dl )
22578 -DST( movb %dl, (%edi) )
22579 +DST( movb %dl, %es:(%edi) )
22580 6: addl %edx, %eax
22581 adcl $0, %eax
22582 7:
22583 .section .fixup, "ax"
22584 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22585 - movl $-EFAULT, (%ebx)
22586 + movl $-EFAULT, %ss:(%ebx)
22587 # zero the complete destination (computing the rest is too much work)
22588 movl ARGBASE+8(%esp),%edi # dst
22589 movl ARGBASE+12(%esp),%ecx # len
22590 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22591 rep; stosb
22592 jmp 7b
22593 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22594 - movl $-EFAULT, (%ebx)
22595 + movl $-EFAULT, %ss:(%ebx)
22596 jmp 7b
22597 .previous
22598
22599 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22600 + pushl_cfi %ss
22601 + popl_cfi %ds
22602 + pushl_cfi %ss
22603 + popl_cfi %es
22604 +#endif
22605 +
22606 popl_cfi %esi
22607 CFI_RESTORE esi
22608 popl_cfi %edi
22609 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22610 CFI_RESTORE ebx
22611 ret
22612 CFI_ENDPROC
22613 -ENDPROC(csum_partial_copy_generic)
22614 +ENDPROC(csum_partial_copy_generic_to_user)
22615
22616 #undef ROUND
22617 #undef ROUND1
22618 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22619 index f2145cf..cea889d 100644
22620 --- a/arch/x86/lib/clear_page_64.S
22621 +++ b/arch/x86/lib/clear_page_64.S
22622 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22623 movl $4096/8,%ecx
22624 xorl %eax,%eax
22625 rep stosq
22626 + pax_force_retaddr
22627 ret
22628 CFI_ENDPROC
22629 ENDPROC(clear_page_c)
22630 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22631 movl $4096,%ecx
22632 xorl %eax,%eax
22633 rep stosb
22634 + pax_force_retaddr
22635 ret
22636 CFI_ENDPROC
22637 ENDPROC(clear_page_c_e)
22638 @@ -43,6 +45,7 @@ ENTRY(clear_page)
22639 leaq 64(%rdi),%rdi
22640 jnz .Lloop
22641 nop
22642 + pax_force_retaddr
22643 ret
22644 CFI_ENDPROC
22645 .Lclear_page_end:
22646 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
22647
22648 #include <asm/cpufeature.h>
22649
22650 - .section .altinstr_replacement,"ax"
22651 + .section .altinstr_replacement,"a"
22652 1: .byte 0xeb /* jmp <disp8> */
22653 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22654 2: .byte 0xeb /* jmp <disp8> */
22655 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22656 index 1e572c5..2a162cd 100644
22657 --- a/arch/x86/lib/cmpxchg16b_emu.S
22658 +++ b/arch/x86/lib/cmpxchg16b_emu.S
22659 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22660
22661 popf
22662 mov $1, %al
22663 + pax_force_retaddr
22664 ret
22665
22666 not_same:
22667 popf
22668 xor %al,%al
22669 + pax_force_retaddr
22670 ret
22671
22672 CFI_ENDPROC
22673 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22674 index 6b34d04..dccb07f 100644
22675 --- a/arch/x86/lib/copy_page_64.S
22676 +++ b/arch/x86/lib/copy_page_64.S
22677 @@ -9,6 +9,7 @@ copy_page_c:
22678 CFI_STARTPROC
22679 movl $4096/8,%ecx
22680 rep movsq
22681 + pax_force_retaddr
22682 ret
22683 CFI_ENDPROC
22684 ENDPROC(copy_page_c)
22685 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22686
22687 ENTRY(copy_page)
22688 CFI_STARTPROC
22689 - subq $2*8,%rsp
22690 - CFI_ADJUST_CFA_OFFSET 2*8
22691 + subq $3*8,%rsp
22692 + CFI_ADJUST_CFA_OFFSET 3*8
22693 movq %rbx,(%rsp)
22694 CFI_REL_OFFSET rbx, 0
22695 movq %r12,1*8(%rsp)
22696 CFI_REL_OFFSET r12, 1*8
22697 + movq %r13,2*8(%rsp)
22698 + CFI_REL_OFFSET r13, 2*8
22699
22700 movl $(4096/64)-5,%ecx
22701 .p2align 4
22702 @@ -37,7 +40,7 @@ ENTRY(copy_page)
22703 movq 16 (%rsi), %rdx
22704 movq 24 (%rsi), %r8
22705 movq 32 (%rsi), %r9
22706 - movq 40 (%rsi), %r10
22707 + movq 40 (%rsi), %r13
22708 movq 48 (%rsi), %r11
22709 movq 56 (%rsi), %r12
22710
22711 @@ -48,7 +51,7 @@ ENTRY(copy_page)
22712 movq %rdx, 16 (%rdi)
22713 movq %r8, 24 (%rdi)
22714 movq %r9, 32 (%rdi)
22715 - movq %r10, 40 (%rdi)
22716 + movq %r13, 40 (%rdi)
22717 movq %r11, 48 (%rdi)
22718 movq %r12, 56 (%rdi)
22719
22720 @@ -67,7 +70,7 @@ ENTRY(copy_page)
22721 movq 16 (%rsi), %rdx
22722 movq 24 (%rsi), %r8
22723 movq 32 (%rsi), %r9
22724 - movq 40 (%rsi), %r10
22725 + movq 40 (%rsi), %r13
22726 movq 48 (%rsi), %r11
22727 movq 56 (%rsi), %r12
22728
22729 @@ -76,7 +79,7 @@ ENTRY(copy_page)
22730 movq %rdx, 16 (%rdi)
22731 movq %r8, 24 (%rdi)
22732 movq %r9, 32 (%rdi)
22733 - movq %r10, 40 (%rdi)
22734 + movq %r13, 40 (%rdi)
22735 movq %r11, 48 (%rdi)
22736 movq %r12, 56 (%rdi)
22737
22738 @@ -89,8 +92,11 @@ ENTRY(copy_page)
22739 CFI_RESTORE rbx
22740 movq 1*8(%rsp),%r12
22741 CFI_RESTORE r12
22742 - addq $2*8,%rsp
22743 - CFI_ADJUST_CFA_OFFSET -2*8
22744 + movq 2*8(%rsp),%r13
22745 + CFI_RESTORE r13
22746 + addq $3*8,%rsp
22747 + CFI_ADJUST_CFA_OFFSET -3*8
22748 + pax_force_retaddr
22749 ret
22750 .Lcopy_page_end:
22751 CFI_ENDPROC
22752 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
22753
22754 #include <asm/cpufeature.h>
22755
22756 - .section .altinstr_replacement,"ax"
22757 + .section .altinstr_replacement,"a"
22758 1: .byte 0xeb /* jmp <disp8> */
22759 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
22760 2:
22761 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
22762 index a30ca15..d25fab6 100644
22763 --- a/arch/x86/lib/copy_user_64.S
22764 +++ b/arch/x86/lib/copy_user_64.S
22765 @@ -18,6 +18,7 @@
22766 #include <asm/alternative-asm.h>
22767 #include <asm/asm.h>
22768 #include <asm/smap.h>
22769 +#include <asm/pgtable.h>
22770
22771 /*
22772 * By placing feature2 after feature1 in altinstructions section, we logically
22773 @@ -31,7 +32,7 @@
22774 .byte 0xe9 /* 32bit jump */
22775 .long \orig-1f /* by default jump to orig */
22776 1:
22777 - .section .altinstr_replacement,"ax"
22778 + .section .altinstr_replacement,"a"
22779 2: .byte 0xe9 /* near jump with 32bit immediate */
22780 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
22781 3: .byte 0xe9 /* near jump with 32bit immediate */
22782 @@ -70,47 +71,20 @@
22783 #endif
22784 .endm
22785
22786 -/* Standard copy_to_user with segment limit checking */
22787 -ENTRY(_copy_to_user)
22788 - CFI_STARTPROC
22789 - GET_THREAD_INFO(%rax)
22790 - movq %rdi,%rcx
22791 - addq %rdx,%rcx
22792 - jc bad_to_user
22793 - cmpq TI_addr_limit(%rax),%rcx
22794 - ja bad_to_user
22795 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
22796 - copy_user_generic_unrolled,copy_user_generic_string, \
22797 - copy_user_enhanced_fast_string
22798 - CFI_ENDPROC
22799 -ENDPROC(_copy_to_user)
22800 -
22801 -/* Standard copy_from_user with segment limit checking */
22802 -ENTRY(_copy_from_user)
22803 - CFI_STARTPROC
22804 - GET_THREAD_INFO(%rax)
22805 - movq %rsi,%rcx
22806 - addq %rdx,%rcx
22807 - jc bad_from_user
22808 - cmpq TI_addr_limit(%rax),%rcx
22809 - ja bad_from_user
22810 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
22811 - copy_user_generic_unrolled,copy_user_generic_string, \
22812 - copy_user_enhanced_fast_string
22813 - CFI_ENDPROC
22814 -ENDPROC(_copy_from_user)
22815 -
22816 .section .fixup,"ax"
22817 /* must zero dest */
22818 ENTRY(bad_from_user)
22819 bad_from_user:
22820 CFI_STARTPROC
22821 + testl %edx,%edx
22822 + js bad_to_user
22823 movl %edx,%ecx
22824 xorl %eax,%eax
22825 rep
22826 stosb
22827 bad_to_user:
22828 movl %edx,%eax
22829 + pax_force_retaddr
22830 ret
22831 CFI_ENDPROC
22832 ENDPROC(bad_from_user)
22833 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
22834 jz 17f
22835 1: movq (%rsi),%r8
22836 2: movq 1*8(%rsi),%r9
22837 -3: movq 2*8(%rsi),%r10
22838 +3: movq 2*8(%rsi),%rax
22839 4: movq 3*8(%rsi),%r11
22840 5: movq %r8,(%rdi)
22841 6: movq %r9,1*8(%rdi)
22842 -7: movq %r10,2*8(%rdi)
22843 +7: movq %rax,2*8(%rdi)
22844 8: movq %r11,3*8(%rdi)
22845 9: movq 4*8(%rsi),%r8
22846 10: movq 5*8(%rsi),%r9
22847 -11: movq 6*8(%rsi),%r10
22848 +11: movq 6*8(%rsi),%rax
22849 12: movq 7*8(%rsi),%r11
22850 13: movq %r8,4*8(%rdi)
22851 14: movq %r9,5*8(%rdi)
22852 -15: movq %r10,6*8(%rdi)
22853 +15: movq %rax,6*8(%rdi)
22854 16: movq %r11,7*8(%rdi)
22855 leaq 64(%rsi),%rsi
22856 leaq 64(%rdi),%rdi
22857 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
22858 jnz 21b
22859 23: xor %eax,%eax
22860 ASM_CLAC
22861 + pax_force_retaddr
22862 ret
22863
22864 .section .fixup,"ax"
22865 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
22866 movsb
22867 4: xorl %eax,%eax
22868 ASM_CLAC
22869 + pax_force_retaddr
22870 ret
22871
22872 .section .fixup,"ax"
22873 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
22874 movsb
22875 2: xorl %eax,%eax
22876 ASM_CLAC
22877 + pax_force_retaddr
22878 ret
22879
22880 .section .fixup,"ax"
22881 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
22882 index 6a4f43c..f5f9e26 100644
22883 --- a/arch/x86/lib/copy_user_nocache_64.S
22884 +++ b/arch/x86/lib/copy_user_nocache_64.S
22885 @@ -8,6 +8,7 @@
22886
22887 #include <linux/linkage.h>
22888 #include <asm/dwarf2.h>
22889 +#include <asm/alternative-asm.h>
22890
22891 #define FIX_ALIGNMENT 1
22892
22893 @@ -16,6 +17,7 @@
22894 #include <asm/thread_info.h>
22895 #include <asm/asm.h>
22896 #include <asm/smap.h>
22897 +#include <asm/pgtable.h>
22898
22899 .macro ALIGN_DESTINATION
22900 #ifdef FIX_ALIGNMENT
22901 @@ -49,6 +51,15 @@
22902 */
22903 ENTRY(__copy_user_nocache)
22904 CFI_STARTPROC
22905 +
22906 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22907 + mov $PAX_USER_SHADOW_BASE,%rcx
22908 + cmp %rcx,%rsi
22909 + jae 1f
22910 + add %rcx,%rsi
22911 +1:
22912 +#endif
22913 +
22914 ASM_STAC
22915 cmpl $8,%edx
22916 jb 20f /* less then 8 bytes, go to byte copy loop */
22917 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
22918 jz 17f
22919 1: movq (%rsi),%r8
22920 2: movq 1*8(%rsi),%r9
22921 -3: movq 2*8(%rsi),%r10
22922 +3: movq 2*8(%rsi),%rax
22923 4: movq 3*8(%rsi),%r11
22924 5: movnti %r8,(%rdi)
22925 6: movnti %r9,1*8(%rdi)
22926 -7: movnti %r10,2*8(%rdi)
22927 +7: movnti %rax,2*8(%rdi)
22928 8: movnti %r11,3*8(%rdi)
22929 9: movq 4*8(%rsi),%r8
22930 10: movq 5*8(%rsi),%r9
22931 -11: movq 6*8(%rsi),%r10
22932 +11: movq 6*8(%rsi),%rax
22933 12: movq 7*8(%rsi),%r11
22934 13: movnti %r8,4*8(%rdi)
22935 14: movnti %r9,5*8(%rdi)
22936 -15: movnti %r10,6*8(%rdi)
22937 +15: movnti %rax,6*8(%rdi)
22938 16: movnti %r11,7*8(%rdi)
22939 leaq 64(%rsi),%rsi
22940 leaq 64(%rdi),%rdi
22941 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
22942 23: xorl %eax,%eax
22943 ASM_CLAC
22944 sfence
22945 + pax_force_retaddr
22946 ret
22947
22948 .section .fixup,"ax"
22949 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
22950 index 2419d5f..953ee51 100644
22951 --- a/arch/x86/lib/csum-copy_64.S
22952 +++ b/arch/x86/lib/csum-copy_64.S
22953 @@ -9,6 +9,7 @@
22954 #include <asm/dwarf2.h>
22955 #include <asm/errno.h>
22956 #include <asm/asm.h>
22957 +#include <asm/alternative-asm.h>
22958
22959 /*
22960 * Checksum copy with exception handling.
22961 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
22962 CFI_RESTORE rbp
22963 addq $7*8, %rsp
22964 CFI_ADJUST_CFA_OFFSET -7*8
22965 + pax_force_retaddr 0, 1
22966 ret
22967 CFI_RESTORE_STATE
22968
22969 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
22970 index 25b7ae8..169fafc 100644
22971 --- a/arch/x86/lib/csum-wrappers_64.c
22972 +++ b/arch/x86/lib/csum-wrappers_64.c
22973 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
22974 len -= 2;
22975 }
22976 }
22977 - isum = csum_partial_copy_generic((__force const void *)src,
22978 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
22979 dst, len, isum, errp, NULL);
22980 if (unlikely(*errp))
22981 goto out_err;
22982 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
22983 }
22984
22985 *errp = 0;
22986 - return csum_partial_copy_generic(src, (void __force *)dst,
22987 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
22988 len, isum, NULL, errp);
22989 }
22990 EXPORT_SYMBOL(csum_partial_copy_to_user);
22991 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
22992 index 156b9c8..b144132 100644
22993 --- a/arch/x86/lib/getuser.S
22994 +++ b/arch/x86/lib/getuser.S
22995 @@ -34,17 +34,40 @@
22996 #include <asm/thread_info.h>
22997 #include <asm/asm.h>
22998 #include <asm/smap.h>
22999 +#include <asm/segment.h>
23000 +#include <asm/pgtable.h>
23001 +#include <asm/alternative-asm.h>
23002 +
23003 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23004 +#define __copyuser_seg gs;
23005 +#else
23006 +#define __copyuser_seg
23007 +#endif
23008
23009 .text
23010 ENTRY(__get_user_1)
23011 CFI_STARTPROC
23012 +
23013 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23014 GET_THREAD_INFO(%_ASM_DX)
23015 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23016 jae bad_get_user
23017 ASM_STAC
23018 -1: movzb (%_ASM_AX),%edx
23019 +
23020 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23021 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23022 + cmp %_ASM_DX,%_ASM_AX
23023 + jae 1234f
23024 + add %_ASM_DX,%_ASM_AX
23025 +1234:
23026 +#endif
23027 +
23028 +#endif
23029 +
23030 +1: __copyuser_seg movzb (%_ASM_AX),%edx
23031 xor %eax,%eax
23032 ASM_CLAC
23033 + pax_force_retaddr
23034 ret
23035 CFI_ENDPROC
23036 ENDPROC(__get_user_1)
23037 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23038 ENTRY(__get_user_2)
23039 CFI_STARTPROC
23040 add $1,%_ASM_AX
23041 +
23042 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23043 jc bad_get_user
23044 GET_THREAD_INFO(%_ASM_DX)
23045 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23046 jae bad_get_user
23047 ASM_STAC
23048 -2: movzwl -1(%_ASM_AX),%edx
23049 +
23050 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23051 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23052 + cmp %_ASM_DX,%_ASM_AX
23053 + jae 1234f
23054 + add %_ASM_DX,%_ASM_AX
23055 +1234:
23056 +#endif
23057 +
23058 +#endif
23059 +
23060 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23061 xor %eax,%eax
23062 ASM_CLAC
23063 + pax_force_retaddr
23064 ret
23065 CFI_ENDPROC
23066 ENDPROC(__get_user_2)
23067 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23068 ENTRY(__get_user_4)
23069 CFI_STARTPROC
23070 add $3,%_ASM_AX
23071 +
23072 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23073 jc bad_get_user
23074 GET_THREAD_INFO(%_ASM_DX)
23075 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23076 jae bad_get_user
23077 ASM_STAC
23078 -3: mov -3(%_ASM_AX),%edx
23079 +
23080 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23081 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23082 + cmp %_ASM_DX,%_ASM_AX
23083 + jae 1234f
23084 + add %_ASM_DX,%_ASM_AX
23085 +1234:
23086 +#endif
23087 +
23088 +#endif
23089 +
23090 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
23091 xor %eax,%eax
23092 ASM_CLAC
23093 + pax_force_retaddr
23094 ret
23095 CFI_ENDPROC
23096 ENDPROC(__get_user_4)
23097 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23098 GET_THREAD_INFO(%_ASM_DX)
23099 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23100 jae bad_get_user
23101 +
23102 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23103 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23104 + cmp %_ASM_DX,%_ASM_AX
23105 + jae 1234f
23106 + add %_ASM_DX,%_ASM_AX
23107 +1234:
23108 +#endif
23109 +
23110 ASM_STAC
23111 4: movq -7(%_ASM_AX),%_ASM_DX
23112 xor %eax,%eax
23113 ASM_CLAC
23114 + pax_force_retaddr
23115 ret
23116 CFI_ENDPROC
23117 ENDPROC(__get_user_8)
23118 @@ -101,6 +162,7 @@ bad_get_user:
23119 xor %edx,%edx
23120 mov $(-EFAULT),%_ASM_AX
23121 ASM_CLAC
23122 + pax_force_retaddr
23123 ret
23124 CFI_ENDPROC
23125 END(bad_get_user)
23126 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23127 index 54fcffe..7be149e 100644
23128 --- a/arch/x86/lib/insn.c
23129 +++ b/arch/x86/lib/insn.c
23130 @@ -20,8 +20,10 @@
23131
23132 #ifdef __KERNEL__
23133 #include <linux/string.h>
23134 +#include <asm/pgtable_types.h>
23135 #else
23136 #include <string.h>
23137 +#define ktla_ktva(addr) addr
23138 #endif
23139 #include <asm/inat.h>
23140 #include <asm/insn.h>
23141 @@ -53,8 +55,8 @@
23142 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23143 {
23144 memset(insn, 0, sizeof(*insn));
23145 - insn->kaddr = kaddr;
23146 - insn->next_byte = kaddr;
23147 + insn->kaddr = ktla_ktva(kaddr);
23148 + insn->next_byte = ktla_ktva(kaddr);
23149 insn->x86_64 = x86_64 ? 1 : 0;
23150 insn->opnd_bytes = 4;
23151 if (x86_64)
23152 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23153 index 05a95e7..326f2fa 100644
23154 --- a/arch/x86/lib/iomap_copy_64.S
23155 +++ b/arch/x86/lib/iomap_copy_64.S
23156 @@ -17,6 +17,7 @@
23157
23158 #include <linux/linkage.h>
23159 #include <asm/dwarf2.h>
23160 +#include <asm/alternative-asm.h>
23161
23162 /*
23163 * override generic version in lib/iomap_copy.c
23164 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23165 CFI_STARTPROC
23166 movl %edx,%ecx
23167 rep movsd
23168 + pax_force_retaddr
23169 ret
23170 CFI_ENDPROC
23171 ENDPROC(__iowrite32_copy)
23172 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23173 index 1c273be..da9cc0e 100644
23174 --- a/arch/x86/lib/memcpy_64.S
23175 +++ b/arch/x86/lib/memcpy_64.S
23176 @@ -33,6 +33,7 @@
23177 rep movsq
23178 movl %edx, %ecx
23179 rep movsb
23180 + pax_force_retaddr
23181 ret
23182 .Lmemcpy_e:
23183 .previous
23184 @@ -49,6 +50,7 @@
23185 movq %rdi, %rax
23186 movq %rdx, %rcx
23187 rep movsb
23188 + pax_force_retaddr
23189 ret
23190 .Lmemcpy_e_e:
23191 .previous
23192 @@ -76,13 +78,13 @@ ENTRY(memcpy)
23193 */
23194 movq 0*8(%rsi), %r8
23195 movq 1*8(%rsi), %r9
23196 - movq 2*8(%rsi), %r10
23197 + movq 2*8(%rsi), %rcx
23198 movq 3*8(%rsi), %r11
23199 leaq 4*8(%rsi), %rsi
23200
23201 movq %r8, 0*8(%rdi)
23202 movq %r9, 1*8(%rdi)
23203 - movq %r10, 2*8(%rdi)
23204 + movq %rcx, 2*8(%rdi)
23205 movq %r11, 3*8(%rdi)
23206 leaq 4*8(%rdi), %rdi
23207 jae .Lcopy_forward_loop
23208 @@ -105,12 +107,12 @@ ENTRY(memcpy)
23209 subq $0x20, %rdx
23210 movq -1*8(%rsi), %r8
23211 movq -2*8(%rsi), %r9
23212 - movq -3*8(%rsi), %r10
23213 + movq -3*8(%rsi), %rcx
23214 movq -4*8(%rsi), %r11
23215 leaq -4*8(%rsi), %rsi
23216 movq %r8, -1*8(%rdi)
23217 movq %r9, -2*8(%rdi)
23218 - movq %r10, -3*8(%rdi)
23219 + movq %rcx, -3*8(%rdi)
23220 movq %r11, -4*8(%rdi)
23221 leaq -4*8(%rdi), %rdi
23222 jae .Lcopy_backward_loop
23223 @@ -130,12 +132,13 @@ ENTRY(memcpy)
23224 */
23225 movq 0*8(%rsi), %r8
23226 movq 1*8(%rsi), %r9
23227 - movq -2*8(%rsi, %rdx), %r10
23228 + movq -2*8(%rsi, %rdx), %rcx
23229 movq -1*8(%rsi, %rdx), %r11
23230 movq %r8, 0*8(%rdi)
23231 movq %r9, 1*8(%rdi)
23232 - movq %r10, -2*8(%rdi, %rdx)
23233 + movq %rcx, -2*8(%rdi, %rdx)
23234 movq %r11, -1*8(%rdi, %rdx)
23235 + pax_force_retaddr
23236 retq
23237 .p2align 4
23238 .Lless_16bytes:
23239 @@ -148,6 +151,7 @@ ENTRY(memcpy)
23240 movq -1*8(%rsi, %rdx), %r9
23241 movq %r8, 0*8(%rdi)
23242 movq %r9, -1*8(%rdi, %rdx)
23243 + pax_force_retaddr
23244 retq
23245 .p2align 4
23246 .Lless_8bytes:
23247 @@ -161,6 +165,7 @@ ENTRY(memcpy)
23248 movl -4(%rsi, %rdx), %r8d
23249 movl %ecx, (%rdi)
23250 movl %r8d, -4(%rdi, %rdx)
23251 + pax_force_retaddr
23252 retq
23253 .p2align 4
23254 .Lless_3bytes:
23255 @@ -179,6 +184,7 @@ ENTRY(memcpy)
23256 movb %cl, (%rdi)
23257
23258 .Lend:
23259 + pax_force_retaddr
23260 retq
23261 CFI_ENDPROC
23262 ENDPROC(memcpy)
23263 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23264 index ee16461..c39c199 100644
23265 --- a/arch/x86/lib/memmove_64.S
23266 +++ b/arch/x86/lib/memmove_64.S
23267 @@ -61,13 +61,13 @@ ENTRY(memmove)
23268 5:
23269 sub $0x20, %rdx
23270 movq 0*8(%rsi), %r11
23271 - movq 1*8(%rsi), %r10
23272 + movq 1*8(%rsi), %rcx
23273 movq 2*8(%rsi), %r9
23274 movq 3*8(%rsi), %r8
23275 leaq 4*8(%rsi), %rsi
23276
23277 movq %r11, 0*8(%rdi)
23278 - movq %r10, 1*8(%rdi)
23279 + movq %rcx, 1*8(%rdi)
23280 movq %r9, 2*8(%rdi)
23281 movq %r8, 3*8(%rdi)
23282 leaq 4*8(%rdi), %rdi
23283 @@ -81,10 +81,10 @@ ENTRY(memmove)
23284 4:
23285 movq %rdx, %rcx
23286 movq -8(%rsi, %rdx), %r11
23287 - lea -8(%rdi, %rdx), %r10
23288 + lea -8(%rdi, %rdx), %r9
23289 shrq $3, %rcx
23290 rep movsq
23291 - movq %r11, (%r10)
23292 + movq %r11, (%r9)
23293 jmp 13f
23294 .Lmemmove_end_forward:
23295
23296 @@ -95,14 +95,14 @@ ENTRY(memmove)
23297 7:
23298 movq %rdx, %rcx
23299 movq (%rsi), %r11
23300 - movq %rdi, %r10
23301 + movq %rdi, %r9
23302 leaq -8(%rsi, %rdx), %rsi
23303 leaq -8(%rdi, %rdx), %rdi
23304 shrq $3, %rcx
23305 std
23306 rep movsq
23307 cld
23308 - movq %r11, (%r10)
23309 + movq %r11, (%r9)
23310 jmp 13f
23311
23312 /*
23313 @@ -127,13 +127,13 @@ ENTRY(memmove)
23314 8:
23315 subq $0x20, %rdx
23316 movq -1*8(%rsi), %r11
23317 - movq -2*8(%rsi), %r10
23318 + movq -2*8(%rsi), %rcx
23319 movq -3*8(%rsi), %r9
23320 movq -4*8(%rsi), %r8
23321 leaq -4*8(%rsi), %rsi
23322
23323 movq %r11, -1*8(%rdi)
23324 - movq %r10, -2*8(%rdi)
23325 + movq %rcx, -2*8(%rdi)
23326 movq %r9, -3*8(%rdi)
23327 movq %r8, -4*8(%rdi)
23328 leaq -4*8(%rdi), %rdi
23329 @@ -151,11 +151,11 @@ ENTRY(memmove)
23330 * Move data from 16 bytes to 31 bytes.
23331 */
23332 movq 0*8(%rsi), %r11
23333 - movq 1*8(%rsi), %r10
23334 + movq 1*8(%rsi), %rcx
23335 movq -2*8(%rsi, %rdx), %r9
23336 movq -1*8(%rsi, %rdx), %r8
23337 movq %r11, 0*8(%rdi)
23338 - movq %r10, 1*8(%rdi)
23339 + movq %rcx, 1*8(%rdi)
23340 movq %r9, -2*8(%rdi, %rdx)
23341 movq %r8, -1*8(%rdi, %rdx)
23342 jmp 13f
23343 @@ -167,9 +167,9 @@ ENTRY(memmove)
23344 * Move data from 8 bytes to 15 bytes.
23345 */
23346 movq 0*8(%rsi), %r11
23347 - movq -1*8(%rsi, %rdx), %r10
23348 + movq -1*8(%rsi, %rdx), %r9
23349 movq %r11, 0*8(%rdi)
23350 - movq %r10, -1*8(%rdi, %rdx)
23351 + movq %r9, -1*8(%rdi, %rdx)
23352 jmp 13f
23353 10:
23354 cmpq $4, %rdx
23355 @@ -178,9 +178,9 @@ ENTRY(memmove)
23356 * Move data from 4 bytes to 7 bytes.
23357 */
23358 movl (%rsi), %r11d
23359 - movl -4(%rsi, %rdx), %r10d
23360 + movl -4(%rsi, %rdx), %r9d
23361 movl %r11d, (%rdi)
23362 - movl %r10d, -4(%rdi, %rdx)
23363 + movl %r9d, -4(%rdi, %rdx)
23364 jmp 13f
23365 11:
23366 cmp $2, %rdx
23367 @@ -189,9 +189,9 @@ ENTRY(memmove)
23368 * Move data from 2 bytes to 3 bytes.
23369 */
23370 movw (%rsi), %r11w
23371 - movw -2(%rsi, %rdx), %r10w
23372 + movw -2(%rsi, %rdx), %r9w
23373 movw %r11w, (%rdi)
23374 - movw %r10w, -2(%rdi, %rdx)
23375 + movw %r9w, -2(%rdi, %rdx)
23376 jmp 13f
23377 12:
23378 cmp $1, %rdx
23379 @@ -202,6 +202,7 @@ ENTRY(memmove)
23380 movb (%rsi), %r11b
23381 movb %r11b, (%rdi)
23382 13:
23383 + pax_force_retaddr
23384 retq
23385 CFI_ENDPROC
23386
23387 @@ -210,6 +211,7 @@ ENTRY(memmove)
23388 /* Forward moving data. */
23389 movq %rdx, %rcx
23390 rep movsb
23391 + pax_force_retaddr
23392 retq
23393 .Lmemmove_end_forward_efs:
23394 .previous
23395 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23396 index 2dcb380..963660a 100644
23397 --- a/arch/x86/lib/memset_64.S
23398 +++ b/arch/x86/lib/memset_64.S
23399 @@ -30,6 +30,7 @@
23400 movl %edx,%ecx
23401 rep stosb
23402 movq %r9,%rax
23403 + pax_force_retaddr
23404 ret
23405 .Lmemset_e:
23406 .previous
23407 @@ -52,6 +53,7 @@
23408 movq %rdx,%rcx
23409 rep stosb
23410 movq %r9,%rax
23411 + pax_force_retaddr
23412 ret
23413 .Lmemset_e_e:
23414 .previous
23415 @@ -59,7 +61,7 @@
23416 ENTRY(memset)
23417 ENTRY(__memset)
23418 CFI_STARTPROC
23419 - movq %rdi,%r10
23420 + movq %rdi,%r11
23421
23422 /* expand byte value */
23423 movzbl %sil,%ecx
23424 @@ -117,7 +119,8 @@ ENTRY(__memset)
23425 jnz .Lloop_1
23426
23427 .Lende:
23428 - movq %r10,%rax
23429 + movq %r11,%rax
23430 + pax_force_retaddr
23431 ret
23432
23433 CFI_RESTORE_STATE
23434 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23435 index c9f2d9b..e7fd2c0 100644
23436 --- a/arch/x86/lib/mmx_32.c
23437 +++ b/arch/x86/lib/mmx_32.c
23438 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23439 {
23440 void *p;
23441 int i;
23442 + unsigned long cr0;
23443
23444 if (unlikely(in_interrupt()))
23445 return __memcpy(to, from, len);
23446 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23447 kernel_fpu_begin();
23448
23449 __asm__ __volatile__ (
23450 - "1: prefetch (%0)\n" /* This set is 28 bytes */
23451 - " prefetch 64(%0)\n"
23452 - " prefetch 128(%0)\n"
23453 - " prefetch 192(%0)\n"
23454 - " prefetch 256(%0)\n"
23455 + "1: prefetch (%1)\n" /* This set is 28 bytes */
23456 + " prefetch 64(%1)\n"
23457 + " prefetch 128(%1)\n"
23458 + " prefetch 192(%1)\n"
23459 + " prefetch 256(%1)\n"
23460 "2: \n"
23461 ".section .fixup, \"ax\"\n"
23462 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23463 + "3: \n"
23464 +
23465 +#ifdef CONFIG_PAX_KERNEXEC
23466 + " movl %%cr0, %0\n"
23467 + " movl %0, %%eax\n"
23468 + " andl $0xFFFEFFFF, %%eax\n"
23469 + " movl %%eax, %%cr0\n"
23470 +#endif
23471 +
23472 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23473 +
23474 +#ifdef CONFIG_PAX_KERNEXEC
23475 + " movl %0, %%cr0\n"
23476 +#endif
23477 +
23478 " jmp 2b\n"
23479 ".previous\n"
23480 _ASM_EXTABLE(1b, 3b)
23481 - : : "r" (from));
23482 + : "=&r" (cr0) : "r" (from) : "ax");
23483
23484 for ( ; i > 5; i--) {
23485 __asm__ __volatile__ (
23486 - "1: prefetch 320(%0)\n"
23487 - "2: movq (%0), %%mm0\n"
23488 - " movq 8(%0), %%mm1\n"
23489 - " movq 16(%0), %%mm2\n"
23490 - " movq 24(%0), %%mm3\n"
23491 - " movq %%mm0, (%1)\n"
23492 - " movq %%mm1, 8(%1)\n"
23493 - " movq %%mm2, 16(%1)\n"
23494 - " movq %%mm3, 24(%1)\n"
23495 - " movq 32(%0), %%mm0\n"
23496 - " movq 40(%0), %%mm1\n"
23497 - " movq 48(%0), %%mm2\n"
23498 - " movq 56(%0), %%mm3\n"
23499 - " movq %%mm0, 32(%1)\n"
23500 - " movq %%mm1, 40(%1)\n"
23501 - " movq %%mm2, 48(%1)\n"
23502 - " movq %%mm3, 56(%1)\n"
23503 + "1: prefetch 320(%1)\n"
23504 + "2: movq (%1), %%mm0\n"
23505 + " movq 8(%1), %%mm1\n"
23506 + " movq 16(%1), %%mm2\n"
23507 + " movq 24(%1), %%mm3\n"
23508 + " movq %%mm0, (%2)\n"
23509 + " movq %%mm1, 8(%2)\n"
23510 + " movq %%mm2, 16(%2)\n"
23511 + " movq %%mm3, 24(%2)\n"
23512 + " movq 32(%1), %%mm0\n"
23513 + " movq 40(%1), %%mm1\n"
23514 + " movq 48(%1), %%mm2\n"
23515 + " movq 56(%1), %%mm3\n"
23516 + " movq %%mm0, 32(%2)\n"
23517 + " movq %%mm1, 40(%2)\n"
23518 + " movq %%mm2, 48(%2)\n"
23519 + " movq %%mm3, 56(%2)\n"
23520 ".section .fixup, \"ax\"\n"
23521 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23522 + "3:\n"
23523 +
23524 +#ifdef CONFIG_PAX_KERNEXEC
23525 + " movl %%cr0, %0\n"
23526 + " movl %0, %%eax\n"
23527 + " andl $0xFFFEFFFF, %%eax\n"
23528 + " movl %%eax, %%cr0\n"
23529 +#endif
23530 +
23531 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23532 +
23533 +#ifdef CONFIG_PAX_KERNEXEC
23534 + " movl %0, %%cr0\n"
23535 +#endif
23536 +
23537 " jmp 2b\n"
23538 ".previous\n"
23539 _ASM_EXTABLE(1b, 3b)
23540 - : : "r" (from), "r" (to) : "memory");
23541 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23542
23543 from += 64;
23544 to += 64;
23545 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23546 static void fast_copy_page(void *to, void *from)
23547 {
23548 int i;
23549 + unsigned long cr0;
23550
23551 kernel_fpu_begin();
23552
23553 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23554 * but that is for later. -AV
23555 */
23556 __asm__ __volatile__(
23557 - "1: prefetch (%0)\n"
23558 - " prefetch 64(%0)\n"
23559 - " prefetch 128(%0)\n"
23560 - " prefetch 192(%0)\n"
23561 - " prefetch 256(%0)\n"
23562 + "1: prefetch (%1)\n"
23563 + " prefetch 64(%1)\n"
23564 + " prefetch 128(%1)\n"
23565 + " prefetch 192(%1)\n"
23566 + " prefetch 256(%1)\n"
23567 "2: \n"
23568 ".section .fixup, \"ax\"\n"
23569 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23570 + "3: \n"
23571 +
23572 +#ifdef CONFIG_PAX_KERNEXEC
23573 + " movl %%cr0, %0\n"
23574 + " movl %0, %%eax\n"
23575 + " andl $0xFFFEFFFF, %%eax\n"
23576 + " movl %%eax, %%cr0\n"
23577 +#endif
23578 +
23579 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23580 +
23581 +#ifdef CONFIG_PAX_KERNEXEC
23582 + " movl %0, %%cr0\n"
23583 +#endif
23584 +
23585 " jmp 2b\n"
23586 ".previous\n"
23587 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23588 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23589
23590 for (i = 0; i < (4096-320)/64; i++) {
23591 __asm__ __volatile__ (
23592 - "1: prefetch 320(%0)\n"
23593 - "2: movq (%0), %%mm0\n"
23594 - " movntq %%mm0, (%1)\n"
23595 - " movq 8(%0), %%mm1\n"
23596 - " movntq %%mm1, 8(%1)\n"
23597 - " movq 16(%0), %%mm2\n"
23598 - " movntq %%mm2, 16(%1)\n"
23599 - " movq 24(%0), %%mm3\n"
23600 - " movntq %%mm3, 24(%1)\n"
23601 - " movq 32(%0), %%mm4\n"
23602 - " movntq %%mm4, 32(%1)\n"
23603 - " movq 40(%0), %%mm5\n"
23604 - " movntq %%mm5, 40(%1)\n"
23605 - " movq 48(%0), %%mm6\n"
23606 - " movntq %%mm6, 48(%1)\n"
23607 - " movq 56(%0), %%mm7\n"
23608 - " movntq %%mm7, 56(%1)\n"
23609 + "1: prefetch 320(%1)\n"
23610 + "2: movq (%1), %%mm0\n"
23611 + " movntq %%mm0, (%2)\n"
23612 + " movq 8(%1), %%mm1\n"
23613 + " movntq %%mm1, 8(%2)\n"
23614 + " movq 16(%1), %%mm2\n"
23615 + " movntq %%mm2, 16(%2)\n"
23616 + " movq 24(%1), %%mm3\n"
23617 + " movntq %%mm3, 24(%2)\n"
23618 + " movq 32(%1), %%mm4\n"
23619 + " movntq %%mm4, 32(%2)\n"
23620 + " movq 40(%1), %%mm5\n"
23621 + " movntq %%mm5, 40(%2)\n"
23622 + " movq 48(%1), %%mm6\n"
23623 + " movntq %%mm6, 48(%2)\n"
23624 + " movq 56(%1), %%mm7\n"
23625 + " movntq %%mm7, 56(%2)\n"
23626 ".section .fixup, \"ax\"\n"
23627 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23628 + "3:\n"
23629 +
23630 +#ifdef CONFIG_PAX_KERNEXEC
23631 + " movl %%cr0, %0\n"
23632 + " movl %0, %%eax\n"
23633 + " andl $0xFFFEFFFF, %%eax\n"
23634 + " movl %%eax, %%cr0\n"
23635 +#endif
23636 +
23637 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23638 +
23639 +#ifdef CONFIG_PAX_KERNEXEC
23640 + " movl %0, %%cr0\n"
23641 +#endif
23642 +
23643 " jmp 2b\n"
23644 ".previous\n"
23645 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23646 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23647
23648 from += 64;
23649 to += 64;
23650 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23651 static void fast_copy_page(void *to, void *from)
23652 {
23653 int i;
23654 + unsigned long cr0;
23655
23656 kernel_fpu_begin();
23657
23658 __asm__ __volatile__ (
23659 - "1: prefetch (%0)\n"
23660 - " prefetch 64(%0)\n"
23661 - " prefetch 128(%0)\n"
23662 - " prefetch 192(%0)\n"
23663 - " prefetch 256(%0)\n"
23664 + "1: prefetch (%1)\n"
23665 + " prefetch 64(%1)\n"
23666 + " prefetch 128(%1)\n"
23667 + " prefetch 192(%1)\n"
23668 + " prefetch 256(%1)\n"
23669 "2: \n"
23670 ".section .fixup, \"ax\"\n"
23671 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23672 + "3: \n"
23673 +
23674 +#ifdef CONFIG_PAX_KERNEXEC
23675 + " movl %%cr0, %0\n"
23676 + " movl %0, %%eax\n"
23677 + " andl $0xFFFEFFFF, %%eax\n"
23678 + " movl %%eax, %%cr0\n"
23679 +#endif
23680 +
23681 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23682 +
23683 +#ifdef CONFIG_PAX_KERNEXEC
23684 + " movl %0, %%cr0\n"
23685 +#endif
23686 +
23687 " jmp 2b\n"
23688 ".previous\n"
23689 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23690 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23691
23692 for (i = 0; i < 4096/64; i++) {
23693 __asm__ __volatile__ (
23694 - "1: prefetch 320(%0)\n"
23695 - "2: movq (%0), %%mm0\n"
23696 - " movq 8(%0), %%mm1\n"
23697 - " movq 16(%0), %%mm2\n"
23698 - " movq 24(%0), %%mm3\n"
23699 - " movq %%mm0, (%1)\n"
23700 - " movq %%mm1, 8(%1)\n"
23701 - " movq %%mm2, 16(%1)\n"
23702 - " movq %%mm3, 24(%1)\n"
23703 - " movq 32(%0), %%mm0\n"
23704 - " movq 40(%0), %%mm1\n"
23705 - " movq 48(%0), %%mm2\n"
23706 - " movq 56(%0), %%mm3\n"
23707 - " movq %%mm0, 32(%1)\n"
23708 - " movq %%mm1, 40(%1)\n"
23709 - " movq %%mm2, 48(%1)\n"
23710 - " movq %%mm3, 56(%1)\n"
23711 + "1: prefetch 320(%1)\n"
23712 + "2: movq (%1), %%mm0\n"
23713 + " movq 8(%1), %%mm1\n"
23714 + " movq 16(%1), %%mm2\n"
23715 + " movq 24(%1), %%mm3\n"
23716 + " movq %%mm0, (%2)\n"
23717 + " movq %%mm1, 8(%2)\n"
23718 + " movq %%mm2, 16(%2)\n"
23719 + " movq %%mm3, 24(%2)\n"
23720 + " movq 32(%1), %%mm0\n"
23721 + " movq 40(%1), %%mm1\n"
23722 + " movq 48(%1), %%mm2\n"
23723 + " movq 56(%1), %%mm3\n"
23724 + " movq %%mm0, 32(%2)\n"
23725 + " movq %%mm1, 40(%2)\n"
23726 + " movq %%mm2, 48(%2)\n"
23727 + " movq %%mm3, 56(%2)\n"
23728 ".section .fixup, \"ax\"\n"
23729 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23730 + "3:\n"
23731 +
23732 +#ifdef CONFIG_PAX_KERNEXEC
23733 + " movl %%cr0, %0\n"
23734 + " movl %0, %%eax\n"
23735 + " andl $0xFFFEFFFF, %%eax\n"
23736 + " movl %%eax, %%cr0\n"
23737 +#endif
23738 +
23739 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23740 +
23741 +#ifdef CONFIG_PAX_KERNEXEC
23742 + " movl %0, %%cr0\n"
23743 +#endif
23744 +
23745 " jmp 2b\n"
23746 ".previous\n"
23747 _ASM_EXTABLE(1b, 3b)
23748 - : : "r" (from), "r" (to) : "memory");
23749 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23750
23751 from += 64;
23752 to += 64;
23753 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
23754 index f6d13ee..aca5f0b 100644
23755 --- a/arch/x86/lib/msr-reg.S
23756 +++ b/arch/x86/lib/msr-reg.S
23757 @@ -3,6 +3,7 @@
23758 #include <asm/dwarf2.h>
23759 #include <asm/asm.h>
23760 #include <asm/msr.h>
23761 +#include <asm/alternative-asm.h>
23762
23763 #ifdef CONFIG_X86_64
23764 /*
23765 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
23766 CFI_STARTPROC
23767 pushq_cfi %rbx
23768 pushq_cfi %rbp
23769 - movq %rdi, %r10 /* Save pointer */
23770 + movq %rdi, %r9 /* Save pointer */
23771 xorl %r11d, %r11d /* Return value */
23772 movl (%rdi), %eax
23773 movl 4(%rdi), %ecx
23774 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
23775 movl 28(%rdi), %edi
23776 CFI_REMEMBER_STATE
23777 1: \op
23778 -2: movl %eax, (%r10)
23779 +2: movl %eax, (%r9)
23780 movl %r11d, %eax /* Return value */
23781 - movl %ecx, 4(%r10)
23782 - movl %edx, 8(%r10)
23783 - movl %ebx, 12(%r10)
23784 - movl %ebp, 20(%r10)
23785 - movl %esi, 24(%r10)
23786 - movl %edi, 28(%r10)
23787 + movl %ecx, 4(%r9)
23788 + movl %edx, 8(%r9)
23789 + movl %ebx, 12(%r9)
23790 + movl %ebp, 20(%r9)
23791 + movl %esi, 24(%r9)
23792 + movl %edi, 28(%r9)
23793 popq_cfi %rbp
23794 popq_cfi %rbx
23795 + pax_force_retaddr
23796 ret
23797 3:
23798 CFI_RESTORE_STATE
23799 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
23800 index fc6ba17..04471c5 100644
23801 --- a/arch/x86/lib/putuser.S
23802 +++ b/arch/x86/lib/putuser.S
23803 @@ -16,7 +16,9 @@
23804 #include <asm/errno.h>
23805 #include <asm/asm.h>
23806 #include <asm/smap.h>
23807 -
23808 +#include <asm/segment.h>
23809 +#include <asm/pgtable.h>
23810 +#include <asm/alternative-asm.h>
23811
23812 /*
23813 * __put_user_X
23814 @@ -30,57 +32,125 @@
23815 * as they get called from within inline assembly.
23816 */
23817
23818 -#define ENTER CFI_STARTPROC ; \
23819 - GET_THREAD_INFO(%_ASM_BX)
23820 -#define EXIT ASM_CLAC ; \
23821 - ret ; \
23822 +#define ENTER CFI_STARTPROC
23823 +#define EXIT ASM_CLAC ; \
23824 + pax_force_retaddr ; \
23825 + ret ; \
23826 CFI_ENDPROC
23827
23828 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23829 +#define _DEST %_ASM_CX,%_ASM_BX
23830 +#else
23831 +#define _DEST %_ASM_CX
23832 +#endif
23833 +
23834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23835 +#define __copyuser_seg gs;
23836 +#else
23837 +#define __copyuser_seg
23838 +#endif
23839 +
23840 .text
23841 ENTRY(__put_user_1)
23842 ENTER
23843 +
23844 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23845 + GET_THREAD_INFO(%_ASM_BX)
23846 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
23847 jae bad_put_user
23848 ASM_STAC
23849 -1: movb %al,(%_ASM_CX)
23850 +
23851 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23852 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23853 + cmp %_ASM_BX,%_ASM_CX
23854 + jb 1234f
23855 + xor %ebx,%ebx
23856 +1234:
23857 +#endif
23858 +
23859 +#endif
23860 +
23861 +1: __copyuser_seg movb %al,(_DEST)
23862 xor %eax,%eax
23863 EXIT
23864 ENDPROC(__put_user_1)
23865
23866 ENTRY(__put_user_2)
23867 ENTER
23868 +
23869 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23870 + GET_THREAD_INFO(%_ASM_BX)
23871 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
23872 sub $1,%_ASM_BX
23873 cmp %_ASM_BX,%_ASM_CX
23874 jae bad_put_user
23875 ASM_STAC
23876 -2: movw %ax,(%_ASM_CX)
23877 +
23878 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23879 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23880 + cmp %_ASM_BX,%_ASM_CX
23881 + jb 1234f
23882 + xor %ebx,%ebx
23883 +1234:
23884 +#endif
23885 +
23886 +#endif
23887 +
23888 +2: __copyuser_seg movw %ax,(_DEST)
23889 xor %eax,%eax
23890 EXIT
23891 ENDPROC(__put_user_2)
23892
23893 ENTRY(__put_user_4)
23894 ENTER
23895 +
23896 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23897 + GET_THREAD_INFO(%_ASM_BX)
23898 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
23899 sub $3,%_ASM_BX
23900 cmp %_ASM_BX,%_ASM_CX
23901 jae bad_put_user
23902 ASM_STAC
23903 -3: movl %eax,(%_ASM_CX)
23904 +
23905 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23906 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23907 + cmp %_ASM_BX,%_ASM_CX
23908 + jb 1234f
23909 + xor %ebx,%ebx
23910 +1234:
23911 +#endif
23912 +
23913 +#endif
23914 +
23915 +3: __copyuser_seg movl %eax,(_DEST)
23916 xor %eax,%eax
23917 EXIT
23918 ENDPROC(__put_user_4)
23919
23920 ENTRY(__put_user_8)
23921 ENTER
23922 +
23923 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23924 + GET_THREAD_INFO(%_ASM_BX)
23925 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
23926 sub $7,%_ASM_BX
23927 cmp %_ASM_BX,%_ASM_CX
23928 jae bad_put_user
23929 ASM_STAC
23930 -4: mov %_ASM_AX,(%_ASM_CX)
23931 +
23932 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23933 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23934 + cmp %_ASM_BX,%_ASM_CX
23935 + jb 1234f
23936 + xor %ebx,%ebx
23937 +1234:
23938 +#endif
23939 +
23940 +#endif
23941 +
23942 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
23943 #ifdef CONFIG_X86_32
23944 -5: movl %edx,4(%_ASM_CX)
23945 +5: __copyuser_seg movl %edx,4(_DEST)
23946 #endif
23947 xor %eax,%eax
23948 EXIT
23949 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
23950 index 1cad221..de671ee 100644
23951 --- a/arch/x86/lib/rwlock.S
23952 +++ b/arch/x86/lib/rwlock.S
23953 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
23954 FRAME
23955 0: LOCK_PREFIX
23956 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
23957 +
23958 +#ifdef CONFIG_PAX_REFCOUNT
23959 + jno 1234f
23960 + LOCK_PREFIX
23961 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
23962 + int $4
23963 +1234:
23964 + _ASM_EXTABLE(1234b, 1234b)
23965 +#endif
23966 +
23967 1: rep; nop
23968 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
23969 jne 1b
23970 LOCK_PREFIX
23971 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
23972 +
23973 +#ifdef CONFIG_PAX_REFCOUNT
23974 + jno 1234f
23975 + LOCK_PREFIX
23976 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
23977 + int $4
23978 +1234:
23979 + _ASM_EXTABLE(1234b, 1234b)
23980 +#endif
23981 +
23982 jnz 0b
23983 ENDFRAME
23984 + pax_force_retaddr
23985 ret
23986 CFI_ENDPROC
23987 END(__write_lock_failed)
23988 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
23989 FRAME
23990 0: LOCK_PREFIX
23991 READ_LOCK_SIZE(inc) (%__lock_ptr)
23992 +
23993 +#ifdef CONFIG_PAX_REFCOUNT
23994 + jno 1234f
23995 + LOCK_PREFIX
23996 + READ_LOCK_SIZE(dec) (%__lock_ptr)
23997 + int $4
23998 +1234:
23999 + _ASM_EXTABLE(1234b, 1234b)
24000 +#endif
24001 +
24002 1: rep; nop
24003 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24004 js 1b
24005 LOCK_PREFIX
24006 READ_LOCK_SIZE(dec) (%__lock_ptr)
24007 +
24008 +#ifdef CONFIG_PAX_REFCOUNT
24009 + jno 1234f
24010 + LOCK_PREFIX
24011 + READ_LOCK_SIZE(inc) (%__lock_ptr)
24012 + int $4
24013 +1234:
24014 + _ASM_EXTABLE(1234b, 1234b)
24015 +#endif
24016 +
24017 js 0b
24018 ENDFRAME
24019 + pax_force_retaddr
24020 ret
24021 CFI_ENDPROC
24022 END(__read_lock_failed)
24023 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24024 index 5dff5f0..cadebf4 100644
24025 --- a/arch/x86/lib/rwsem.S
24026 +++ b/arch/x86/lib/rwsem.S
24027 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24028 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24029 CFI_RESTORE __ASM_REG(dx)
24030 restore_common_regs
24031 + pax_force_retaddr
24032 ret
24033 CFI_ENDPROC
24034 ENDPROC(call_rwsem_down_read_failed)
24035 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24036 movq %rax,%rdi
24037 call rwsem_down_write_failed
24038 restore_common_regs
24039 + pax_force_retaddr
24040 ret
24041 CFI_ENDPROC
24042 ENDPROC(call_rwsem_down_write_failed)
24043 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24044 movq %rax,%rdi
24045 call rwsem_wake
24046 restore_common_regs
24047 -1: ret
24048 +1: pax_force_retaddr
24049 + ret
24050 CFI_ENDPROC
24051 ENDPROC(call_rwsem_wake)
24052
24053 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24054 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24055 CFI_RESTORE __ASM_REG(dx)
24056 restore_common_regs
24057 + pax_force_retaddr
24058 ret
24059 CFI_ENDPROC
24060 ENDPROC(call_rwsem_downgrade_wake)
24061 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24062 index a63efd6..ccecad8 100644
24063 --- a/arch/x86/lib/thunk_64.S
24064 +++ b/arch/x86/lib/thunk_64.S
24065 @@ -8,6 +8,7 @@
24066 #include <linux/linkage.h>
24067 #include <asm/dwarf2.h>
24068 #include <asm/calling.h>
24069 +#include <asm/alternative-asm.h>
24070
24071 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24072 .macro THUNK name, func, put_ret_addr_in_rdi=0
24073 @@ -41,5 +42,6 @@
24074 SAVE_ARGS
24075 restore:
24076 RESTORE_ARGS
24077 + pax_force_retaddr
24078 ret
24079 CFI_ENDPROC
24080 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24081 index 98f6d6b6..d27f045 100644
24082 --- a/arch/x86/lib/usercopy_32.c
24083 +++ b/arch/x86/lib/usercopy_32.c
24084 @@ -42,11 +42,13 @@ do { \
24085 int __d0; \
24086 might_fault(); \
24087 __asm__ __volatile__( \
24088 + __COPYUSER_SET_ES \
24089 ASM_STAC "\n" \
24090 "0: rep; stosl\n" \
24091 " movl %2,%0\n" \
24092 "1: rep; stosb\n" \
24093 "2: " ASM_CLAC "\n" \
24094 + __COPYUSER_RESTORE_ES \
24095 ".section .fixup,\"ax\"\n" \
24096 "3: lea 0(%2,%0,4),%0\n" \
24097 " jmp 2b\n" \
24098 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24099
24100 #ifdef CONFIG_X86_INTEL_USERCOPY
24101 static unsigned long
24102 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
24103 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24104 {
24105 int d0, d1;
24106 __asm__ __volatile__(
24107 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24108 " .align 2,0x90\n"
24109 "3: movl 0(%4), %%eax\n"
24110 "4: movl 4(%4), %%edx\n"
24111 - "5: movl %%eax, 0(%3)\n"
24112 - "6: movl %%edx, 4(%3)\n"
24113 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24114 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24115 "7: movl 8(%4), %%eax\n"
24116 "8: movl 12(%4),%%edx\n"
24117 - "9: movl %%eax, 8(%3)\n"
24118 - "10: movl %%edx, 12(%3)\n"
24119 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24120 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24121 "11: movl 16(%4), %%eax\n"
24122 "12: movl 20(%4), %%edx\n"
24123 - "13: movl %%eax, 16(%3)\n"
24124 - "14: movl %%edx, 20(%3)\n"
24125 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24126 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24127 "15: movl 24(%4), %%eax\n"
24128 "16: movl 28(%4), %%edx\n"
24129 - "17: movl %%eax, 24(%3)\n"
24130 - "18: movl %%edx, 28(%3)\n"
24131 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24132 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24133 "19: movl 32(%4), %%eax\n"
24134 "20: movl 36(%4), %%edx\n"
24135 - "21: movl %%eax, 32(%3)\n"
24136 - "22: movl %%edx, 36(%3)\n"
24137 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24138 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24139 "23: movl 40(%4), %%eax\n"
24140 "24: movl 44(%4), %%edx\n"
24141 - "25: movl %%eax, 40(%3)\n"
24142 - "26: movl %%edx, 44(%3)\n"
24143 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24144 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24145 "27: movl 48(%4), %%eax\n"
24146 "28: movl 52(%4), %%edx\n"
24147 - "29: movl %%eax, 48(%3)\n"
24148 - "30: movl %%edx, 52(%3)\n"
24149 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24150 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24151 "31: movl 56(%4), %%eax\n"
24152 "32: movl 60(%4), %%edx\n"
24153 - "33: movl %%eax, 56(%3)\n"
24154 - "34: movl %%edx, 60(%3)\n"
24155 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24156 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24157 " addl $-64, %0\n"
24158 " addl $64, %4\n"
24159 " addl $64, %3\n"
24160 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24161 " shrl $2, %0\n"
24162 " andl $3, %%eax\n"
24163 " cld\n"
24164 + __COPYUSER_SET_ES
24165 "99: rep; movsl\n"
24166 "36: movl %%eax, %0\n"
24167 "37: rep; movsb\n"
24168 "100:\n"
24169 + __COPYUSER_RESTORE_ES
24170 ".section .fixup,\"ax\"\n"
24171 "101: lea 0(%%eax,%0,4),%0\n"
24172 " jmp 100b\n"
24173 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24174 }
24175
24176 static unsigned long
24177 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24178 +{
24179 + int d0, d1;
24180 + __asm__ __volatile__(
24181 + " .align 2,0x90\n"
24182 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24183 + " cmpl $67, %0\n"
24184 + " jbe 3f\n"
24185 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24186 + " .align 2,0x90\n"
24187 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24188 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24189 + "5: movl %%eax, 0(%3)\n"
24190 + "6: movl %%edx, 4(%3)\n"
24191 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24192 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24193 + "9: movl %%eax, 8(%3)\n"
24194 + "10: movl %%edx, 12(%3)\n"
24195 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24196 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24197 + "13: movl %%eax, 16(%3)\n"
24198 + "14: movl %%edx, 20(%3)\n"
24199 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24200 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24201 + "17: movl %%eax, 24(%3)\n"
24202 + "18: movl %%edx, 28(%3)\n"
24203 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24204 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24205 + "21: movl %%eax, 32(%3)\n"
24206 + "22: movl %%edx, 36(%3)\n"
24207 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24208 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24209 + "25: movl %%eax, 40(%3)\n"
24210 + "26: movl %%edx, 44(%3)\n"
24211 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24212 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24213 + "29: movl %%eax, 48(%3)\n"
24214 + "30: movl %%edx, 52(%3)\n"
24215 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24216 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24217 + "33: movl %%eax, 56(%3)\n"
24218 + "34: movl %%edx, 60(%3)\n"
24219 + " addl $-64, %0\n"
24220 + " addl $64, %4\n"
24221 + " addl $64, %3\n"
24222 + " cmpl $63, %0\n"
24223 + " ja 1b\n"
24224 + "35: movl %0, %%eax\n"
24225 + " shrl $2, %0\n"
24226 + " andl $3, %%eax\n"
24227 + " cld\n"
24228 + "99: rep; "__copyuser_seg" movsl\n"
24229 + "36: movl %%eax, %0\n"
24230 + "37: rep; "__copyuser_seg" movsb\n"
24231 + "100:\n"
24232 + ".section .fixup,\"ax\"\n"
24233 + "101: lea 0(%%eax,%0,4),%0\n"
24234 + " jmp 100b\n"
24235 + ".previous\n"
24236 + _ASM_EXTABLE(1b,100b)
24237 + _ASM_EXTABLE(2b,100b)
24238 + _ASM_EXTABLE(3b,100b)
24239 + _ASM_EXTABLE(4b,100b)
24240 + _ASM_EXTABLE(5b,100b)
24241 + _ASM_EXTABLE(6b,100b)
24242 + _ASM_EXTABLE(7b,100b)
24243 + _ASM_EXTABLE(8b,100b)
24244 + _ASM_EXTABLE(9b,100b)
24245 + _ASM_EXTABLE(10b,100b)
24246 + _ASM_EXTABLE(11b,100b)
24247 + _ASM_EXTABLE(12b,100b)
24248 + _ASM_EXTABLE(13b,100b)
24249 + _ASM_EXTABLE(14b,100b)
24250 + _ASM_EXTABLE(15b,100b)
24251 + _ASM_EXTABLE(16b,100b)
24252 + _ASM_EXTABLE(17b,100b)
24253 + _ASM_EXTABLE(18b,100b)
24254 + _ASM_EXTABLE(19b,100b)
24255 + _ASM_EXTABLE(20b,100b)
24256 + _ASM_EXTABLE(21b,100b)
24257 + _ASM_EXTABLE(22b,100b)
24258 + _ASM_EXTABLE(23b,100b)
24259 + _ASM_EXTABLE(24b,100b)
24260 + _ASM_EXTABLE(25b,100b)
24261 + _ASM_EXTABLE(26b,100b)
24262 + _ASM_EXTABLE(27b,100b)
24263 + _ASM_EXTABLE(28b,100b)
24264 + _ASM_EXTABLE(29b,100b)
24265 + _ASM_EXTABLE(30b,100b)
24266 + _ASM_EXTABLE(31b,100b)
24267 + _ASM_EXTABLE(32b,100b)
24268 + _ASM_EXTABLE(33b,100b)
24269 + _ASM_EXTABLE(34b,100b)
24270 + _ASM_EXTABLE(35b,100b)
24271 + _ASM_EXTABLE(36b,100b)
24272 + _ASM_EXTABLE(37b,100b)
24273 + _ASM_EXTABLE(99b,101b)
24274 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
24275 + : "1"(to), "2"(from), "0"(size)
24276 + : "eax", "edx", "memory");
24277 + return size;
24278 +}
24279 +
24280 +static unsigned long __size_overflow(3)
24281 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24282 {
24283 int d0, d1;
24284 __asm__ __volatile__(
24285 " .align 2,0x90\n"
24286 - "0: movl 32(%4), %%eax\n"
24287 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24288 " cmpl $67, %0\n"
24289 " jbe 2f\n"
24290 - "1: movl 64(%4), %%eax\n"
24291 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24292 " .align 2,0x90\n"
24293 - "2: movl 0(%4), %%eax\n"
24294 - "21: movl 4(%4), %%edx\n"
24295 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24296 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24297 " movl %%eax, 0(%3)\n"
24298 " movl %%edx, 4(%3)\n"
24299 - "3: movl 8(%4), %%eax\n"
24300 - "31: movl 12(%4),%%edx\n"
24301 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24302 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24303 " movl %%eax, 8(%3)\n"
24304 " movl %%edx, 12(%3)\n"
24305 - "4: movl 16(%4), %%eax\n"
24306 - "41: movl 20(%4), %%edx\n"
24307 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24308 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24309 " movl %%eax, 16(%3)\n"
24310 " movl %%edx, 20(%3)\n"
24311 - "10: movl 24(%4), %%eax\n"
24312 - "51: movl 28(%4), %%edx\n"
24313 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24314 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24315 " movl %%eax, 24(%3)\n"
24316 " movl %%edx, 28(%3)\n"
24317 - "11: movl 32(%4), %%eax\n"
24318 - "61: movl 36(%4), %%edx\n"
24319 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24320 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24321 " movl %%eax, 32(%3)\n"
24322 " movl %%edx, 36(%3)\n"
24323 - "12: movl 40(%4), %%eax\n"
24324 - "71: movl 44(%4), %%edx\n"
24325 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24326 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24327 " movl %%eax, 40(%3)\n"
24328 " movl %%edx, 44(%3)\n"
24329 - "13: movl 48(%4), %%eax\n"
24330 - "81: movl 52(%4), %%edx\n"
24331 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24332 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24333 " movl %%eax, 48(%3)\n"
24334 " movl %%edx, 52(%3)\n"
24335 - "14: movl 56(%4), %%eax\n"
24336 - "91: movl 60(%4), %%edx\n"
24337 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24338 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24339 " movl %%eax, 56(%3)\n"
24340 " movl %%edx, 60(%3)\n"
24341 " addl $-64, %0\n"
24342 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24343 " shrl $2, %0\n"
24344 " andl $3, %%eax\n"
24345 " cld\n"
24346 - "6: rep; movsl\n"
24347 + "6: rep; "__copyuser_seg" movsl\n"
24348 " movl %%eax,%0\n"
24349 - "7: rep; movsb\n"
24350 + "7: rep; "__copyuser_seg" movsb\n"
24351 "8:\n"
24352 ".section .fixup,\"ax\"\n"
24353 "9: lea 0(%%eax,%0,4),%0\n"
24354 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24355 * hyoshiok@miraclelinux.com
24356 */
24357
24358 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24359 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24360 const void __user *from, unsigned long size)
24361 {
24362 int d0, d1;
24363
24364 __asm__ __volatile__(
24365 " .align 2,0x90\n"
24366 - "0: movl 32(%4), %%eax\n"
24367 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24368 " cmpl $67, %0\n"
24369 " jbe 2f\n"
24370 - "1: movl 64(%4), %%eax\n"
24371 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24372 " .align 2,0x90\n"
24373 - "2: movl 0(%4), %%eax\n"
24374 - "21: movl 4(%4), %%edx\n"
24375 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24376 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24377 " movnti %%eax, 0(%3)\n"
24378 " movnti %%edx, 4(%3)\n"
24379 - "3: movl 8(%4), %%eax\n"
24380 - "31: movl 12(%4),%%edx\n"
24381 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24382 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24383 " movnti %%eax, 8(%3)\n"
24384 " movnti %%edx, 12(%3)\n"
24385 - "4: movl 16(%4), %%eax\n"
24386 - "41: movl 20(%4), %%edx\n"
24387 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24388 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24389 " movnti %%eax, 16(%3)\n"
24390 " movnti %%edx, 20(%3)\n"
24391 - "10: movl 24(%4), %%eax\n"
24392 - "51: movl 28(%4), %%edx\n"
24393 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24394 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24395 " movnti %%eax, 24(%3)\n"
24396 " movnti %%edx, 28(%3)\n"
24397 - "11: movl 32(%4), %%eax\n"
24398 - "61: movl 36(%4), %%edx\n"
24399 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24400 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24401 " movnti %%eax, 32(%3)\n"
24402 " movnti %%edx, 36(%3)\n"
24403 - "12: movl 40(%4), %%eax\n"
24404 - "71: movl 44(%4), %%edx\n"
24405 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24406 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24407 " movnti %%eax, 40(%3)\n"
24408 " movnti %%edx, 44(%3)\n"
24409 - "13: movl 48(%4), %%eax\n"
24410 - "81: movl 52(%4), %%edx\n"
24411 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24412 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24413 " movnti %%eax, 48(%3)\n"
24414 " movnti %%edx, 52(%3)\n"
24415 - "14: movl 56(%4), %%eax\n"
24416 - "91: movl 60(%4), %%edx\n"
24417 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24418 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24419 " movnti %%eax, 56(%3)\n"
24420 " movnti %%edx, 60(%3)\n"
24421 " addl $-64, %0\n"
24422 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24423 " shrl $2, %0\n"
24424 " andl $3, %%eax\n"
24425 " cld\n"
24426 - "6: rep; movsl\n"
24427 + "6: rep; "__copyuser_seg" movsl\n"
24428 " movl %%eax,%0\n"
24429 - "7: rep; movsb\n"
24430 + "7: rep; "__copyuser_seg" movsb\n"
24431 "8:\n"
24432 ".section .fixup,\"ax\"\n"
24433 "9: lea 0(%%eax,%0,4),%0\n"
24434 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24435 return size;
24436 }
24437
24438 -static unsigned long __copy_user_intel_nocache(void *to,
24439 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24440 const void __user *from, unsigned long size)
24441 {
24442 int d0, d1;
24443
24444 __asm__ __volatile__(
24445 " .align 2,0x90\n"
24446 - "0: movl 32(%4), %%eax\n"
24447 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24448 " cmpl $67, %0\n"
24449 " jbe 2f\n"
24450 - "1: movl 64(%4), %%eax\n"
24451 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24452 " .align 2,0x90\n"
24453 - "2: movl 0(%4), %%eax\n"
24454 - "21: movl 4(%4), %%edx\n"
24455 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24456 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24457 " movnti %%eax, 0(%3)\n"
24458 " movnti %%edx, 4(%3)\n"
24459 - "3: movl 8(%4), %%eax\n"
24460 - "31: movl 12(%4),%%edx\n"
24461 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24462 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24463 " movnti %%eax, 8(%3)\n"
24464 " movnti %%edx, 12(%3)\n"
24465 - "4: movl 16(%4), %%eax\n"
24466 - "41: movl 20(%4), %%edx\n"
24467 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24468 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24469 " movnti %%eax, 16(%3)\n"
24470 " movnti %%edx, 20(%3)\n"
24471 - "10: movl 24(%4), %%eax\n"
24472 - "51: movl 28(%4), %%edx\n"
24473 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24474 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24475 " movnti %%eax, 24(%3)\n"
24476 " movnti %%edx, 28(%3)\n"
24477 - "11: movl 32(%4), %%eax\n"
24478 - "61: movl 36(%4), %%edx\n"
24479 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24480 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24481 " movnti %%eax, 32(%3)\n"
24482 " movnti %%edx, 36(%3)\n"
24483 - "12: movl 40(%4), %%eax\n"
24484 - "71: movl 44(%4), %%edx\n"
24485 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24486 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24487 " movnti %%eax, 40(%3)\n"
24488 " movnti %%edx, 44(%3)\n"
24489 - "13: movl 48(%4), %%eax\n"
24490 - "81: movl 52(%4), %%edx\n"
24491 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24492 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24493 " movnti %%eax, 48(%3)\n"
24494 " movnti %%edx, 52(%3)\n"
24495 - "14: movl 56(%4), %%eax\n"
24496 - "91: movl 60(%4), %%edx\n"
24497 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24498 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24499 " movnti %%eax, 56(%3)\n"
24500 " movnti %%edx, 60(%3)\n"
24501 " addl $-64, %0\n"
24502 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24503 " shrl $2, %0\n"
24504 " andl $3, %%eax\n"
24505 " cld\n"
24506 - "6: rep; movsl\n"
24507 + "6: rep; "__copyuser_seg" movsl\n"
24508 " movl %%eax,%0\n"
24509 - "7: rep; movsb\n"
24510 + "7: rep; "__copyuser_seg" movsb\n"
24511 "8:\n"
24512 ".section .fixup,\"ax\"\n"
24513 "9: lea 0(%%eax,%0,4),%0\n"
24514 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24515 */
24516 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24517 unsigned long size);
24518 -unsigned long __copy_user_intel(void __user *to, const void *from,
24519 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24520 + unsigned long size);
24521 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24522 unsigned long size);
24523 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24524 const void __user *from, unsigned long size);
24525 #endif /* CONFIG_X86_INTEL_USERCOPY */
24526
24527 /* Generic arbitrary sized copy. */
24528 -#define __copy_user(to, from, size) \
24529 +#define __copy_user(to, from, size, prefix, set, restore) \
24530 do { \
24531 int __d0, __d1, __d2; \
24532 __asm__ __volatile__( \
24533 + set \
24534 " cmp $7,%0\n" \
24535 " jbe 1f\n" \
24536 " movl %1,%0\n" \
24537 " negl %0\n" \
24538 " andl $7,%0\n" \
24539 " subl %0,%3\n" \
24540 - "4: rep; movsb\n" \
24541 + "4: rep; "prefix"movsb\n" \
24542 " movl %3,%0\n" \
24543 " shrl $2,%0\n" \
24544 " andl $3,%3\n" \
24545 " .align 2,0x90\n" \
24546 - "0: rep; movsl\n" \
24547 + "0: rep; "prefix"movsl\n" \
24548 " movl %3,%0\n" \
24549 - "1: rep; movsb\n" \
24550 + "1: rep; "prefix"movsb\n" \
24551 "2:\n" \
24552 + restore \
24553 ".section .fixup,\"ax\"\n" \
24554 "5: addl %3,%0\n" \
24555 " jmp 2b\n" \
24556 @@ -538,14 +650,14 @@ do { \
24557 " negl %0\n" \
24558 " andl $7,%0\n" \
24559 " subl %0,%3\n" \
24560 - "4: rep; movsb\n" \
24561 + "4: rep; "__copyuser_seg"movsb\n" \
24562 " movl %3,%0\n" \
24563 " shrl $2,%0\n" \
24564 " andl $3,%3\n" \
24565 " .align 2,0x90\n" \
24566 - "0: rep; movsl\n" \
24567 + "0: rep; "__copyuser_seg"movsl\n" \
24568 " movl %3,%0\n" \
24569 - "1: rep; movsb\n" \
24570 + "1: rep; "__copyuser_seg"movsb\n" \
24571 "2:\n" \
24572 ".section .fixup,\"ax\"\n" \
24573 "5: addl %3,%0\n" \
24574 @@ -629,9 +741,9 @@ survive:
24575 #endif
24576 stac();
24577 if (movsl_is_ok(to, from, n))
24578 - __copy_user(to, from, n);
24579 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24580 else
24581 - n = __copy_user_intel(to, from, n);
24582 + n = __generic_copy_to_user_intel(to, from, n);
24583 clac();
24584 return n;
24585 }
24586 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24587 {
24588 stac();
24589 if (movsl_is_ok(to, from, n))
24590 - __copy_user(to, from, n);
24591 + __copy_user(to, from, n, __copyuser_seg, "", "");
24592 else
24593 - n = __copy_user_intel((void __user *)to,
24594 - (const void *)from, n);
24595 + n = __generic_copy_from_user_intel(to, from, n);
24596 clac();
24597 return n;
24598 }
24599 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24600 if (n > 64 && cpu_has_xmm2)
24601 n = __copy_user_intel_nocache(to, from, n);
24602 else
24603 - __copy_user(to, from, n);
24604 + __copy_user(to, from, n, __copyuser_seg, "", "");
24605 #else
24606 - __copy_user(to, from, n);
24607 + __copy_user(to, from, n, __copyuser_seg, "", "");
24608 #endif
24609 clac();
24610 return n;
24611 }
24612 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24613
24614 -/**
24615 - * copy_to_user: - Copy a block of data into user space.
24616 - * @to: Destination address, in user space.
24617 - * @from: Source address, in kernel space.
24618 - * @n: Number of bytes to copy.
24619 - *
24620 - * Context: User context only. This function may sleep.
24621 - *
24622 - * Copy data from kernel space to user space.
24623 - *
24624 - * Returns number of bytes that could not be copied.
24625 - * On success, this will be zero.
24626 - */
24627 -unsigned long
24628 -copy_to_user(void __user *to, const void *from, unsigned long n)
24629 -{
24630 - if (access_ok(VERIFY_WRITE, to, n))
24631 - n = __copy_to_user(to, from, n);
24632 - return n;
24633 -}
24634 -EXPORT_SYMBOL(copy_to_user);
24635 -
24636 -/**
24637 - * copy_from_user: - Copy a block of data from user space.
24638 - * @to: Destination address, in kernel space.
24639 - * @from: Source address, in user space.
24640 - * @n: Number of bytes to copy.
24641 - *
24642 - * Context: User context only. This function may sleep.
24643 - *
24644 - * Copy data from user space to kernel space.
24645 - *
24646 - * Returns number of bytes that could not be copied.
24647 - * On success, this will be zero.
24648 - *
24649 - * If some data could not be copied, this function will pad the copied
24650 - * data to the requested size using zero bytes.
24651 - */
24652 -unsigned long
24653 -_copy_from_user(void *to, const void __user *from, unsigned long n)
24654 -{
24655 - if (access_ok(VERIFY_READ, from, n))
24656 - n = __copy_from_user(to, from, n);
24657 - else
24658 - memset(to, 0, n);
24659 - return n;
24660 -}
24661 -EXPORT_SYMBOL(_copy_from_user);
24662 -
24663 void copy_from_user_overflow(void)
24664 {
24665 WARN(1, "Buffer overflow detected!\n");
24666 }
24667 EXPORT_SYMBOL(copy_from_user_overflow);
24668 +
24669 +void copy_to_user_overflow(void)
24670 +{
24671 + WARN(1, "Buffer overflow detected!\n");
24672 +}
24673 +EXPORT_SYMBOL(copy_to_user_overflow);
24674 +
24675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24676 +void __set_fs(mm_segment_t x)
24677 +{
24678 + switch (x.seg) {
24679 + case 0:
24680 + loadsegment(gs, 0);
24681 + break;
24682 + case TASK_SIZE_MAX:
24683 + loadsegment(gs, __USER_DS);
24684 + break;
24685 + case -1UL:
24686 + loadsegment(gs, __KERNEL_DS);
24687 + break;
24688 + default:
24689 + BUG();
24690 + }
24691 + return;
24692 +}
24693 +EXPORT_SYMBOL(__set_fs);
24694 +
24695 +void set_fs(mm_segment_t x)
24696 +{
24697 + current_thread_info()->addr_limit = x;
24698 + __set_fs(x);
24699 +}
24700 +EXPORT_SYMBOL(set_fs);
24701 +#endif
24702 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
24703 index 05928aa..b33dea1 100644
24704 --- a/arch/x86/lib/usercopy_64.c
24705 +++ b/arch/x86/lib/usercopy_64.c
24706 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
24707 _ASM_EXTABLE(0b,3b)
24708 _ASM_EXTABLE(1b,2b)
24709 : [size8] "=&c"(size), [dst] "=&D" (__d0)
24710 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
24711 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
24712 [zero] "r" (0UL), [eight] "r" (8UL));
24713 clac();
24714 return size;
24715 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
24716 }
24717 EXPORT_SYMBOL(clear_user);
24718
24719 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
24720 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
24721 {
24722 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
24723 - return copy_user_generic((__force void *)to, (__force void *)from, len);
24724 - }
24725 - return len;
24726 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
24727 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
24728 + return len;
24729 }
24730 EXPORT_SYMBOL(copy_in_user);
24731
24732 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
24733 * it is not necessary to optimize tail handling.
24734 */
24735 unsigned long
24736 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
24737 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
24738 {
24739 char c;
24740 unsigned zero_len;
24741 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
24742 clac();
24743 return len;
24744 }
24745 +
24746 +void copy_from_user_overflow(void)
24747 +{
24748 + WARN(1, "Buffer overflow detected!\n");
24749 +}
24750 +EXPORT_SYMBOL(copy_from_user_overflow);
24751 +
24752 +void copy_to_user_overflow(void)
24753 +{
24754 + WARN(1, "Buffer overflow detected!\n");
24755 +}
24756 +EXPORT_SYMBOL(copy_to_user_overflow);
24757 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
24758 index 903ec1e..c4166b2 100644
24759 --- a/arch/x86/mm/extable.c
24760 +++ b/arch/x86/mm/extable.c
24761 @@ -6,12 +6,24 @@
24762 static inline unsigned long
24763 ex_insn_addr(const struct exception_table_entry *x)
24764 {
24765 - return (unsigned long)&x->insn + x->insn;
24766 + unsigned long reloc = 0;
24767 +
24768 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24769 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
24770 +#endif
24771 +
24772 + return (unsigned long)&x->insn + x->insn + reloc;
24773 }
24774 static inline unsigned long
24775 ex_fixup_addr(const struct exception_table_entry *x)
24776 {
24777 - return (unsigned long)&x->fixup + x->fixup;
24778 + unsigned long reloc = 0;
24779 +
24780 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24781 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
24782 +#endif
24783 +
24784 + return (unsigned long)&x->fixup + x->fixup + reloc;
24785 }
24786
24787 int fixup_exception(struct pt_regs *regs)
24788 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
24789 unsigned long new_ip;
24790
24791 #ifdef CONFIG_PNPBIOS
24792 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
24793 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
24794 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
24795 extern u32 pnp_bios_is_utter_crap;
24796 pnp_bios_is_utter_crap = 1;
24797 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
24798 i += 4;
24799 p->fixup -= i;
24800 i += 4;
24801 +
24802 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24803 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
24804 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
24805 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
24806 +#endif
24807 +
24808 }
24809 }
24810
24811 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
24812 index 8e13ecb..831f2d0 100644
24813 --- a/arch/x86/mm/fault.c
24814 +++ b/arch/x86/mm/fault.c
24815 @@ -13,12 +13,19 @@
24816 #include <linux/perf_event.h> /* perf_sw_event */
24817 #include <linux/hugetlb.h> /* hstate_index_to_shift */
24818 #include <linux/prefetch.h> /* prefetchw */
24819 +#include <linux/unistd.h>
24820 +#include <linux/compiler.h>
24821
24822 #include <asm/traps.h> /* dotraplinkage, ... */
24823 #include <asm/pgalloc.h> /* pgd_*(), ... */
24824 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
24825 #include <asm/fixmap.h> /* VSYSCALL_START */
24826 #include <asm/rcu.h> /* exception_enter(), ... */
24827 +#include <asm/tlbflush.h>
24828 +
24829 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24830 +#include <asm/stacktrace.h>
24831 +#endif
24832
24833 /*
24834 * Page fault error code bits:
24835 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
24836 int ret = 0;
24837
24838 /* kprobe_running() needs smp_processor_id() */
24839 - if (kprobes_built_in() && !user_mode_vm(regs)) {
24840 + if (kprobes_built_in() && !user_mode(regs)) {
24841 preempt_disable();
24842 if (kprobe_running() && kprobe_fault_handler(regs, 14))
24843 ret = 1;
24844 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
24845 return !instr_lo || (instr_lo>>1) == 1;
24846 case 0x00:
24847 /* Prefetch instruction is 0x0F0D or 0x0F18 */
24848 - if (probe_kernel_address(instr, opcode))
24849 + if (user_mode(regs)) {
24850 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
24851 + return 0;
24852 + } else if (probe_kernel_address(instr, opcode))
24853 return 0;
24854
24855 *prefetch = (instr_lo == 0xF) &&
24856 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
24857 while (instr < max_instr) {
24858 unsigned char opcode;
24859
24860 - if (probe_kernel_address(instr, opcode))
24861 + if (user_mode(regs)) {
24862 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
24863 + break;
24864 + } else if (probe_kernel_address(instr, opcode))
24865 break;
24866
24867 instr++;
24868 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
24869 force_sig_info(si_signo, &info, tsk);
24870 }
24871
24872 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24873 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
24874 +#endif
24875 +
24876 +#ifdef CONFIG_PAX_EMUTRAMP
24877 +static int pax_handle_fetch_fault(struct pt_regs *regs);
24878 +#endif
24879 +
24880 +#ifdef CONFIG_PAX_PAGEEXEC
24881 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
24882 +{
24883 + pgd_t *pgd;
24884 + pud_t *pud;
24885 + pmd_t *pmd;
24886 +
24887 + pgd = pgd_offset(mm, address);
24888 + if (!pgd_present(*pgd))
24889 + return NULL;
24890 + pud = pud_offset(pgd, address);
24891 + if (!pud_present(*pud))
24892 + return NULL;
24893 + pmd = pmd_offset(pud, address);
24894 + if (!pmd_present(*pmd))
24895 + return NULL;
24896 + return pmd;
24897 +}
24898 +#endif
24899 +
24900 DEFINE_SPINLOCK(pgd_lock);
24901 LIST_HEAD(pgd_list);
24902
24903 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
24904 for (address = VMALLOC_START & PMD_MASK;
24905 address >= TASK_SIZE && address < FIXADDR_TOP;
24906 address += PMD_SIZE) {
24907 +
24908 +#ifdef CONFIG_PAX_PER_CPU_PGD
24909 + unsigned long cpu;
24910 +#else
24911 struct page *page;
24912 +#endif
24913
24914 spin_lock(&pgd_lock);
24915 +
24916 +#ifdef CONFIG_PAX_PER_CPU_PGD
24917 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24918 + pgd_t *pgd = get_cpu_pgd(cpu);
24919 + pmd_t *ret;
24920 +#else
24921 list_for_each_entry(page, &pgd_list, lru) {
24922 + pgd_t *pgd = page_address(page);
24923 spinlock_t *pgt_lock;
24924 pmd_t *ret;
24925
24926 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
24927 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24928
24929 spin_lock(pgt_lock);
24930 - ret = vmalloc_sync_one(page_address(page), address);
24931 +#endif
24932 +
24933 + ret = vmalloc_sync_one(pgd, address);
24934 +
24935 +#ifndef CONFIG_PAX_PER_CPU_PGD
24936 spin_unlock(pgt_lock);
24937 +#endif
24938
24939 if (!ret)
24940 break;
24941 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
24942 * an interrupt in the middle of a task switch..
24943 */
24944 pgd_paddr = read_cr3();
24945 +
24946 +#ifdef CONFIG_PAX_PER_CPU_PGD
24947 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
24948 +#endif
24949 +
24950 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
24951 if (!pmd_k)
24952 return -1;
24953 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
24954 * happen within a race in page table update. In the later
24955 * case just flush:
24956 */
24957 +
24958 +#ifdef CONFIG_PAX_PER_CPU_PGD
24959 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
24960 + pgd = pgd_offset_cpu(smp_processor_id(), address);
24961 +#else
24962 pgd = pgd_offset(current->active_mm, address);
24963 +#endif
24964 +
24965 pgd_ref = pgd_offset_k(address);
24966 if (pgd_none(*pgd_ref))
24967 return -1;
24968 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
24969 static int is_errata100(struct pt_regs *regs, unsigned long address)
24970 {
24971 #ifdef CONFIG_X86_64
24972 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
24973 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
24974 return 1;
24975 #endif
24976 return 0;
24977 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
24978 }
24979
24980 static const char nx_warning[] = KERN_CRIT
24981 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
24982 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
24983
24984 static void
24985 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
24986 @@ -577,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
24987 if (!oops_may_print())
24988 return;
24989
24990 - if (error_code & PF_INSTR) {
24991 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
24992 unsigned int level;
24993
24994 pte_t *pte = lookup_address(address, &level);
24995
24996 if (pte && pte_present(*pte) && !pte_exec(*pte))
24997 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
24998 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
24999 }
25000
25001 +#ifdef CONFIG_PAX_KERNEXEC
25002 + if (init_mm.start_code <= address && address < init_mm.end_code) {
25003 + if (current->signal->curr_ip)
25004 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25005 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
25006 + else
25007 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25008 + current->comm, task_pid_nr(current), current_uid(), current_euid());
25009 + }
25010 +#endif
25011 +
25012 printk(KERN_ALERT "BUG: unable to handle kernel ");
25013 if (address < PAGE_SIZE)
25014 printk(KERN_CONT "NULL pointer dereference");
25015 @@ -749,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25016 }
25017 #endif
25018
25019 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25020 + if (pax_is_fetch_fault(regs, error_code, address)) {
25021 +
25022 +#ifdef CONFIG_PAX_EMUTRAMP
25023 + switch (pax_handle_fetch_fault(regs)) {
25024 + case 2:
25025 + return;
25026 + }
25027 +#endif
25028 +
25029 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25030 + do_group_exit(SIGKILL);
25031 + }
25032 +#endif
25033 +
25034 if (unlikely(show_unhandled_signals))
25035 show_signal_msg(regs, error_code, address, tsk);
25036
25037 @@ -845,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25038 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25039 printk(KERN_ERR
25040 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25041 - tsk->comm, tsk->pid, address);
25042 + tsk->comm, task_pid_nr(tsk), address);
25043 code = BUS_MCEERR_AR;
25044 }
25045 #endif
25046 @@ -901,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25047 return 1;
25048 }
25049
25050 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25051 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25052 +{
25053 + pte_t *pte;
25054 + pmd_t *pmd;
25055 + spinlock_t *ptl;
25056 + unsigned char pte_mask;
25057 +
25058 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25059 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
25060 + return 0;
25061 +
25062 + /* PaX: it's our fault, let's handle it if we can */
25063 +
25064 + /* PaX: take a look at read faults before acquiring any locks */
25065 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25066 + /* instruction fetch attempt from a protected page in user mode */
25067 + up_read(&mm->mmap_sem);
25068 +
25069 +#ifdef CONFIG_PAX_EMUTRAMP
25070 + switch (pax_handle_fetch_fault(regs)) {
25071 + case 2:
25072 + return 1;
25073 + }
25074 +#endif
25075 +
25076 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25077 + do_group_exit(SIGKILL);
25078 + }
25079 +
25080 + pmd = pax_get_pmd(mm, address);
25081 + if (unlikely(!pmd))
25082 + return 0;
25083 +
25084 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25085 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25086 + pte_unmap_unlock(pte, ptl);
25087 + return 0;
25088 + }
25089 +
25090 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25091 + /* write attempt to a protected page in user mode */
25092 + pte_unmap_unlock(pte, ptl);
25093 + return 0;
25094 + }
25095 +
25096 +#ifdef CONFIG_SMP
25097 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25098 +#else
25099 + if (likely(address > get_limit(regs->cs)))
25100 +#endif
25101 + {
25102 + set_pte(pte, pte_mkread(*pte));
25103 + __flush_tlb_one(address);
25104 + pte_unmap_unlock(pte, ptl);
25105 + up_read(&mm->mmap_sem);
25106 + return 1;
25107 + }
25108 +
25109 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25110 +
25111 + /*
25112 + * PaX: fill DTLB with user rights and retry
25113 + */
25114 + __asm__ __volatile__ (
25115 + "orb %2,(%1)\n"
25116 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25117 +/*
25118 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25119 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25120 + * page fault when examined during a TLB load attempt. this is true not only
25121 + * for PTEs holding a non-present entry but also present entries that will
25122 + * raise a page fault (such as those set up by PaX, or the copy-on-write
25123 + * mechanism). in effect it means that we do *not* need to flush the TLBs
25124 + * for our target pages since their PTEs are simply not in the TLBs at all.
25125 +
25126 + * the best thing in omitting it is that we gain around 15-20% speed in the
25127 + * fast path of the page fault handler and can get rid of tracing since we
25128 + * can no longer flush unintended entries.
25129 + */
25130 + "invlpg (%0)\n"
25131 +#endif
25132 + __copyuser_seg"testb $0,(%0)\n"
25133 + "xorb %3,(%1)\n"
25134 + :
25135 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25136 + : "memory", "cc");
25137 + pte_unmap_unlock(pte, ptl);
25138 + up_read(&mm->mmap_sem);
25139 + return 1;
25140 +}
25141 +#endif
25142 +
25143 /*
25144 * Handle a spurious fault caused by a stale TLB entry.
25145 *
25146 @@ -973,6 +1162,9 @@ int show_unhandled_signals = 1;
25147 static inline int
25148 access_error(unsigned long error_code, struct vm_area_struct *vma)
25149 {
25150 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25151 + return 1;
25152 +
25153 if (error_code & PF_WRITE) {
25154 /* write, present and write, not present: */
25155 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25156 @@ -1001,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25157 if (error_code & PF_USER)
25158 return false;
25159
25160 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25161 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25162 return false;
25163
25164 return true;
25165 @@ -1017,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25166 {
25167 struct vm_area_struct *vma;
25168 struct task_struct *tsk;
25169 - unsigned long address;
25170 struct mm_struct *mm;
25171 int fault;
25172 int write = error_code & PF_WRITE;
25173 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25174 (write ? FAULT_FLAG_WRITE : 0);
25175
25176 - tsk = current;
25177 - mm = tsk->mm;
25178 -
25179 /* Get the faulting address: */
25180 - address = read_cr2();
25181 + unsigned long address = read_cr2();
25182 +
25183 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25184 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25185 + if (!search_exception_tables(regs->ip)) {
25186 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25187 + bad_area_nosemaphore(regs, error_code, address);
25188 + return;
25189 + }
25190 + if (address < PAX_USER_SHADOW_BASE) {
25191 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25192 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25193 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25194 + } else
25195 + address -= PAX_USER_SHADOW_BASE;
25196 + }
25197 +#endif
25198 +
25199 + tsk = current;
25200 + mm = tsk->mm;
25201
25202 /*
25203 * Detect and handle instructions that would cause a page fault for
25204 @@ -1089,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25205 * User-mode registers count as a user access even for any
25206 * potential system fault or CPU buglet:
25207 */
25208 - if (user_mode_vm(regs)) {
25209 + if (user_mode(regs)) {
25210 local_irq_enable();
25211 error_code |= PF_USER;
25212 } else {
25213 @@ -1151,6 +1358,11 @@ retry:
25214 might_sleep();
25215 }
25216
25217 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25218 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25219 + return;
25220 +#endif
25221 +
25222 vma = find_vma(mm, address);
25223 if (unlikely(!vma)) {
25224 bad_area(regs, error_code, address);
25225 @@ -1162,18 +1374,24 @@ retry:
25226 bad_area(regs, error_code, address);
25227 return;
25228 }
25229 - if (error_code & PF_USER) {
25230 - /*
25231 - * Accessing the stack below %sp is always a bug.
25232 - * The large cushion allows instructions like enter
25233 - * and pusha to work. ("enter $65535, $31" pushes
25234 - * 32 pointers and then decrements %sp by 65535.)
25235 - */
25236 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25237 - bad_area(regs, error_code, address);
25238 - return;
25239 - }
25240 + /*
25241 + * Accessing the stack below %sp is always a bug.
25242 + * The large cushion allows instructions like enter
25243 + * and pusha to work. ("enter $65535, $31" pushes
25244 + * 32 pointers and then decrements %sp by 65535.)
25245 + */
25246 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25247 + bad_area(regs, error_code, address);
25248 + return;
25249 }
25250 +
25251 +#ifdef CONFIG_PAX_SEGMEXEC
25252 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25253 + bad_area(regs, error_code, address);
25254 + return;
25255 + }
25256 +#endif
25257 +
25258 if (unlikely(expand_stack(vma, address))) {
25259 bad_area(regs, error_code, address);
25260 return;
25261 @@ -1237,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25262 __do_page_fault(regs, error_code);
25263 exception_exit(regs);
25264 }
25265 +
25266 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25267 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25268 +{
25269 + struct mm_struct *mm = current->mm;
25270 + unsigned long ip = regs->ip;
25271 +
25272 + if (v8086_mode(regs))
25273 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25274 +
25275 +#ifdef CONFIG_PAX_PAGEEXEC
25276 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25277 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25278 + return true;
25279 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25280 + return true;
25281 + return false;
25282 + }
25283 +#endif
25284 +
25285 +#ifdef CONFIG_PAX_SEGMEXEC
25286 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25287 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25288 + return true;
25289 + return false;
25290 + }
25291 +#endif
25292 +
25293 + return false;
25294 +}
25295 +#endif
25296 +
25297 +#ifdef CONFIG_PAX_EMUTRAMP
25298 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25299 +{
25300 + int err;
25301 +
25302 + do { /* PaX: libffi trampoline emulation */
25303 + unsigned char mov, jmp;
25304 + unsigned int addr1, addr2;
25305 +
25306 +#ifdef CONFIG_X86_64
25307 + if ((regs->ip + 9) >> 32)
25308 + break;
25309 +#endif
25310 +
25311 + err = get_user(mov, (unsigned char __user *)regs->ip);
25312 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25313 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25314 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25315 +
25316 + if (err)
25317 + break;
25318 +
25319 + if (mov == 0xB8 && jmp == 0xE9) {
25320 + regs->ax = addr1;
25321 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25322 + return 2;
25323 + }
25324 + } while (0);
25325 +
25326 + do { /* PaX: gcc trampoline emulation #1 */
25327 + unsigned char mov1, mov2;
25328 + unsigned short jmp;
25329 + unsigned int addr1, addr2;
25330 +
25331 +#ifdef CONFIG_X86_64
25332 + if ((regs->ip + 11) >> 32)
25333 + break;
25334 +#endif
25335 +
25336 + err = get_user(mov1, (unsigned char __user *)regs->ip);
25337 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25338 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25339 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25340 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25341 +
25342 + if (err)
25343 + break;
25344 +
25345 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25346 + regs->cx = addr1;
25347 + regs->ax = addr2;
25348 + regs->ip = addr2;
25349 + return 2;
25350 + }
25351 + } while (0);
25352 +
25353 + do { /* PaX: gcc trampoline emulation #2 */
25354 + unsigned char mov, jmp;
25355 + unsigned int addr1, addr2;
25356 +
25357 +#ifdef CONFIG_X86_64
25358 + if ((regs->ip + 9) >> 32)
25359 + break;
25360 +#endif
25361 +
25362 + err = get_user(mov, (unsigned char __user *)regs->ip);
25363 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25364 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25365 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25366 +
25367 + if (err)
25368 + break;
25369 +
25370 + if (mov == 0xB9 && jmp == 0xE9) {
25371 + regs->cx = addr1;
25372 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25373 + return 2;
25374 + }
25375 + } while (0);
25376 +
25377 + return 1; /* PaX in action */
25378 +}
25379 +
25380 +#ifdef CONFIG_X86_64
25381 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25382 +{
25383 + int err;
25384 +
25385 + do { /* PaX: libffi trampoline emulation */
25386 + unsigned short mov1, mov2, jmp1;
25387 + unsigned char stcclc, jmp2;
25388 + unsigned long addr1, addr2;
25389 +
25390 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25391 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25392 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25393 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25394 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25395 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25396 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25397 +
25398 + if (err)
25399 + break;
25400 +
25401 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25402 + regs->r11 = addr1;
25403 + regs->r10 = addr2;
25404 + if (stcclc == 0xF8)
25405 + regs->flags &= ~X86_EFLAGS_CF;
25406 + else
25407 + regs->flags |= X86_EFLAGS_CF;
25408 + regs->ip = addr1;
25409 + return 2;
25410 + }
25411 + } while (0);
25412 +
25413 + do { /* PaX: gcc trampoline emulation #1 */
25414 + unsigned short mov1, mov2, jmp1;
25415 + unsigned char jmp2;
25416 + unsigned int addr1;
25417 + unsigned long addr2;
25418 +
25419 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25420 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25421 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25422 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25423 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25424 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25425 +
25426 + if (err)
25427 + break;
25428 +
25429 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25430 + regs->r11 = addr1;
25431 + regs->r10 = addr2;
25432 + regs->ip = addr1;
25433 + return 2;
25434 + }
25435 + } while (0);
25436 +
25437 + do { /* PaX: gcc trampoline emulation #2 */
25438 + unsigned short mov1, mov2, jmp1;
25439 + unsigned char jmp2;
25440 + unsigned long addr1, addr2;
25441 +
25442 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25443 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25444 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25445 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25446 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25447 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25448 +
25449 + if (err)
25450 + break;
25451 +
25452 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25453 + regs->r11 = addr1;
25454 + regs->r10 = addr2;
25455 + regs->ip = addr1;
25456 + return 2;
25457 + }
25458 + } while (0);
25459 +
25460 + return 1; /* PaX in action */
25461 +}
25462 +#endif
25463 +
25464 +/*
25465 + * PaX: decide what to do with offenders (regs->ip = fault address)
25466 + *
25467 + * returns 1 when task should be killed
25468 + * 2 when gcc trampoline was detected
25469 + */
25470 +static int pax_handle_fetch_fault(struct pt_regs *regs)
25471 +{
25472 + if (v8086_mode(regs))
25473 + return 1;
25474 +
25475 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25476 + return 1;
25477 +
25478 +#ifdef CONFIG_X86_32
25479 + return pax_handle_fetch_fault_32(regs);
25480 +#else
25481 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25482 + return pax_handle_fetch_fault_32(regs);
25483 + else
25484 + return pax_handle_fetch_fault_64(regs);
25485 +#endif
25486 +}
25487 +#endif
25488 +
25489 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25490 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25491 +{
25492 + long i;
25493 +
25494 + printk(KERN_ERR "PAX: bytes at PC: ");
25495 + for (i = 0; i < 20; i++) {
25496 + unsigned char c;
25497 + if (get_user(c, (unsigned char __force_user *)pc+i))
25498 + printk(KERN_CONT "?? ");
25499 + else
25500 + printk(KERN_CONT "%02x ", c);
25501 + }
25502 + printk("\n");
25503 +
25504 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25505 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
25506 + unsigned long c;
25507 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
25508 +#ifdef CONFIG_X86_32
25509 + printk(KERN_CONT "???????? ");
25510 +#else
25511 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25512 + printk(KERN_CONT "???????? ???????? ");
25513 + else
25514 + printk(KERN_CONT "???????????????? ");
25515 +#endif
25516 + } else {
25517 +#ifdef CONFIG_X86_64
25518 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25519 + printk(KERN_CONT "%08x ", (unsigned int)c);
25520 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25521 + } else
25522 +#endif
25523 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25524 + }
25525 + }
25526 + printk("\n");
25527 +}
25528 +#endif
25529 +
25530 +/**
25531 + * probe_kernel_write(): safely attempt to write to a location
25532 + * @dst: address to write to
25533 + * @src: pointer to the data that shall be written
25534 + * @size: size of the data chunk
25535 + *
25536 + * Safely write to address @dst from the buffer at @src. If a kernel fault
25537 + * happens, handle that and return -EFAULT.
25538 + */
25539 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25540 +{
25541 + long ret;
25542 + mm_segment_t old_fs = get_fs();
25543 +
25544 + set_fs(KERNEL_DS);
25545 + pagefault_disable();
25546 + pax_open_kernel();
25547 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25548 + pax_close_kernel();
25549 + pagefault_enable();
25550 + set_fs(old_fs);
25551 +
25552 + return ret ? -EFAULT : 0;
25553 +}
25554 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25555 index dd74e46..7d26398 100644
25556 --- a/arch/x86/mm/gup.c
25557 +++ b/arch/x86/mm/gup.c
25558 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25559 addr = start;
25560 len = (unsigned long) nr_pages << PAGE_SHIFT;
25561 end = start + len;
25562 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25563 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25564 (void __user *)start, len)))
25565 return 0;
25566
25567 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25568 index 6f31ee5..8ee4164 100644
25569 --- a/arch/x86/mm/highmem_32.c
25570 +++ b/arch/x86/mm/highmem_32.c
25571 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25572 idx = type + KM_TYPE_NR*smp_processor_id();
25573 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25574 BUG_ON(!pte_none(*(kmap_pte-idx)));
25575 +
25576 + pax_open_kernel();
25577 set_pte(kmap_pte-idx, mk_pte(page, prot));
25578 + pax_close_kernel();
25579 +
25580 arch_flush_lazy_mmu_mode();
25581
25582 return (void *)vaddr;
25583 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25584 index 937bff5..d777418 100644
25585 --- a/arch/x86/mm/hugetlbpage.c
25586 +++ b/arch/x86/mm/hugetlbpage.c
25587 @@ -276,13 +276,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25588 struct hstate *h = hstate_file(file);
25589 struct mm_struct *mm = current->mm;
25590 struct vm_area_struct *vma;
25591 - unsigned long start_addr;
25592 + unsigned long start_addr, pax_task_size = TASK_SIZE;
25593 +
25594 +#ifdef CONFIG_PAX_SEGMEXEC
25595 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25596 + pax_task_size = SEGMEXEC_TASK_SIZE;
25597 +#endif
25598 +
25599 + pax_task_size -= PAGE_SIZE;
25600
25601 if (len > mm->cached_hole_size) {
25602 - start_addr = mm->free_area_cache;
25603 + start_addr = mm->free_area_cache;
25604 } else {
25605 - start_addr = TASK_UNMAPPED_BASE;
25606 - mm->cached_hole_size = 0;
25607 + start_addr = mm->mmap_base;
25608 + mm->cached_hole_size = 0;
25609 }
25610
25611 full_search:
25612 @@ -290,26 +297,27 @@ full_search:
25613
25614 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25615 /* At this point: (!vma || addr < vma->vm_end). */
25616 - if (TASK_SIZE - len < addr) {
25617 + if (pax_task_size - len < addr) {
25618 /*
25619 * Start a new search - just in case we missed
25620 * some holes.
25621 */
25622 - if (start_addr != TASK_UNMAPPED_BASE) {
25623 - start_addr = TASK_UNMAPPED_BASE;
25624 + if (start_addr != mm->mmap_base) {
25625 + start_addr = mm->mmap_base;
25626 mm->cached_hole_size = 0;
25627 goto full_search;
25628 }
25629 return -ENOMEM;
25630 }
25631 - if (!vma || addr + len <= vma->vm_start) {
25632 - mm->free_area_cache = addr + len;
25633 - return addr;
25634 - }
25635 + if (check_heap_stack_gap(vma, addr, len))
25636 + break;
25637 if (addr + mm->cached_hole_size < vma->vm_start)
25638 mm->cached_hole_size = vma->vm_start - addr;
25639 addr = ALIGN(vma->vm_end, huge_page_size(h));
25640 }
25641 +
25642 + mm->free_area_cache = addr + len;
25643 + return addr;
25644 }
25645
25646 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25647 @@ -320,9 +328,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25648 struct mm_struct *mm = current->mm;
25649 struct vm_area_struct *vma;
25650 unsigned long base = mm->mmap_base;
25651 - unsigned long addr = addr0;
25652 + unsigned long addr;
25653 unsigned long largest_hole = mm->cached_hole_size;
25654 - unsigned long start_addr;
25655
25656 /* don't allow allocations above current base */
25657 if (mm->free_area_cache > base)
25658 @@ -332,16 +339,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25659 largest_hole = 0;
25660 mm->free_area_cache = base;
25661 }
25662 -try_again:
25663 - start_addr = mm->free_area_cache;
25664
25665 /* make sure it can fit in the remaining address space */
25666 if (mm->free_area_cache < len)
25667 goto fail;
25668
25669 /* either no address requested or can't fit in requested address hole */
25670 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
25671 + addr = mm->free_area_cache - len;
25672 do {
25673 + addr &= huge_page_mask(h);
25674 /*
25675 * Lookup failure means no vma is above this address,
25676 * i.e. return with success:
25677 @@ -350,10 +356,10 @@ try_again:
25678 if (!vma)
25679 return addr;
25680
25681 - if (addr + len <= vma->vm_start) {
25682 + if (check_heap_stack_gap(vma, addr, len)) {
25683 /* remember the address as a hint for next time */
25684 - mm->cached_hole_size = largest_hole;
25685 - return (mm->free_area_cache = addr);
25686 + mm->cached_hole_size = largest_hole;
25687 + return (mm->free_area_cache = addr);
25688 } else if (mm->free_area_cache == vma->vm_end) {
25689 /* pull free_area_cache down to the first hole */
25690 mm->free_area_cache = vma->vm_start;
25691 @@ -362,29 +368,34 @@ try_again:
25692
25693 /* remember the largest hole we saw so far */
25694 if (addr + largest_hole < vma->vm_start)
25695 - largest_hole = vma->vm_start - addr;
25696 + largest_hole = vma->vm_start - addr;
25697
25698 /* try just below the current vma->vm_start */
25699 - addr = (vma->vm_start - len) & huge_page_mask(h);
25700 - } while (len <= vma->vm_start);
25701 + addr = skip_heap_stack_gap(vma, len);
25702 + } while (!IS_ERR_VALUE(addr));
25703
25704 fail:
25705 /*
25706 - * if hint left us with no space for the requested
25707 - * mapping then try again:
25708 - */
25709 - if (start_addr != base) {
25710 - mm->free_area_cache = base;
25711 - largest_hole = 0;
25712 - goto try_again;
25713 - }
25714 - /*
25715 * A failed mmap() very likely causes application failure,
25716 * so fall back to the bottom-up function here. This scenario
25717 * can happen with large stack limits and large mmap()
25718 * allocations.
25719 */
25720 - mm->free_area_cache = TASK_UNMAPPED_BASE;
25721 +
25722 +#ifdef CONFIG_PAX_SEGMEXEC
25723 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25724 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
25725 + else
25726 +#endif
25727 +
25728 + mm->mmap_base = TASK_UNMAPPED_BASE;
25729 +
25730 +#ifdef CONFIG_PAX_RANDMMAP
25731 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25732 + mm->mmap_base += mm->delta_mmap;
25733 +#endif
25734 +
25735 + mm->free_area_cache = mm->mmap_base;
25736 mm->cached_hole_size = ~0UL;
25737 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
25738 len, pgoff, flags);
25739 @@ -392,6 +403,7 @@ fail:
25740 /*
25741 * Restore the topdown base:
25742 */
25743 + mm->mmap_base = base;
25744 mm->free_area_cache = base;
25745 mm->cached_hole_size = ~0UL;
25746
25747 @@ -405,10 +417,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
25748 struct hstate *h = hstate_file(file);
25749 struct mm_struct *mm = current->mm;
25750 struct vm_area_struct *vma;
25751 + unsigned long pax_task_size = TASK_SIZE;
25752
25753 if (len & ~huge_page_mask(h))
25754 return -EINVAL;
25755 - if (len > TASK_SIZE)
25756 +
25757 +#ifdef CONFIG_PAX_SEGMEXEC
25758 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25759 + pax_task_size = SEGMEXEC_TASK_SIZE;
25760 +#endif
25761 +
25762 + pax_task_size -= PAGE_SIZE;
25763 +
25764 + if (len > pax_task_size)
25765 return -ENOMEM;
25766
25767 if (flags & MAP_FIXED) {
25768 @@ -420,8 +441,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
25769 if (addr) {
25770 addr = ALIGN(addr, huge_page_size(h));
25771 vma = find_vma(mm, addr);
25772 - if (TASK_SIZE - len >= addr &&
25773 - (!vma || addr + len <= vma->vm_start))
25774 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
25775 return addr;
25776 }
25777 if (mm->get_unmapped_area == arch_get_unmapped_area)
25778 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
25779 index d7aea41..0fc945b 100644
25780 --- a/arch/x86/mm/init.c
25781 +++ b/arch/x86/mm/init.c
25782 @@ -4,6 +4,7 @@
25783 #include <linux/swap.h>
25784 #include <linux/memblock.h>
25785 #include <linux/bootmem.h> /* for max_low_pfn */
25786 +#include <linux/tboot.h>
25787
25788 #include <asm/cacheflush.h>
25789 #include <asm/e820.h>
25790 @@ -16,6 +17,8 @@
25791 #include <asm/tlb.h>
25792 #include <asm/proto.h>
25793 #include <asm/dma.h> /* for MAX_DMA_PFN */
25794 +#include <asm/desc.h>
25795 +#include <asm/bios_ebda.h>
25796
25797 unsigned long __initdata pgt_buf_start;
25798 unsigned long __meminitdata pgt_buf_end;
25799 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
25800 {
25801 int i;
25802 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
25803 - unsigned long start = 0, good_end;
25804 + unsigned long start = 0x100000, good_end;
25805 phys_addr_t base;
25806
25807 for (i = 0; i < nr_range; i++) {
25808 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
25809 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
25810 * mmio resources as well as potential bios/acpi data regions.
25811 */
25812 +
25813 +#ifdef CONFIG_GRKERNSEC_KMEM
25814 +static unsigned int ebda_start __read_only;
25815 +static unsigned int ebda_end __read_only;
25816 +#endif
25817 +
25818 int devmem_is_allowed(unsigned long pagenr)
25819 {
25820 - if (pagenr < 256)
25821 +#ifdef CONFIG_GRKERNSEC_KMEM
25822 + /* allow BDA */
25823 + if (!pagenr)
25824 return 1;
25825 + /* allow EBDA */
25826 + if (pagenr >= ebda_start && pagenr < ebda_end)
25827 + return 1;
25828 + /* if tboot is in use, allow access to its hardcoded serial log range */
25829 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
25830 + return 1;
25831 +#else
25832 + if (!pagenr)
25833 + return 1;
25834 +#ifdef CONFIG_VM86
25835 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
25836 + return 1;
25837 +#endif
25838 +#endif
25839 +
25840 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
25841 + return 1;
25842 +#ifdef CONFIG_GRKERNSEC_KMEM
25843 + /* throw out everything else below 1MB */
25844 + if (pagenr <= 256)
25845 + return 0;
25846 +#endif
25847 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
25848 return 0;
25849 if (!page_is_ram(pagenr))
25850 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
25851 #endif
25852 }
25853
25854 +#ifdef CONFIG_GRKERNSEC_KMEM
25855 +static inline void gr_init_ebda(void)
25856 +{
25857 + unsigned int ebda_addr;
25858 + unsigned int ebda_size = 0;
25859 +
25860 + ebda_addr = get_bios_ebda();
25861 + if (ebda_addr) {
25862 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
25863 + ebda_size <<= 10;
25864 + }
25865 + if (ebda_addr && ebda_size) {
25866 + ebda_start = ebda_addr >> PAGE_SHIFT;
25867 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
25868 + } else {
25869 + ebda_start = 0x9f000 >> PAGE_SHIFT;
25870 + ebda_end = 0xa0000 >> PAGE_SHIFT;
25871 + }
25872 +}
25873 +#else
25874 +static inline void gr_init_ebda(void) { }
25875 +#endif
25876 +
25877 void free_initmem(void)
25878 {
25879 +#ifdef CONFIG_PAX_KERNEXEC
25880 +#ifdef CONFIG_X86_32
25881 + /* PaX: limit KERNEL_CS to actual size */
25882 + unsigned long addr, limit;
25883 + struct desc_struct d;
25884 + int cpu;
25885 +#else
25886 + pgd_t *pgd;
25887 + pud_t *pud;
25888 + pmd_t *pmd;
25889 + unsigned long addr, end;
25890 +#endif
25891 +#endif
25892 +
25893 + gr_init_ebda();
25894 +
25895 +#ifdef CONFIG_PAX_KERNEXEC
25896 +#ifdef CONFIG_X86_32
25897 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
25898 + limit = (limit - 1UL) >> PAGE_SHIFT;
25899 +
25900 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
25901 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25902 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
25903 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
25904 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
25905 + }
25906 +
25907 + /* PaX: make KERNEL_CS read-only */
25908 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
25909 + if (!paravirt_enabled())
25910 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
25911 +/*
25912 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
25913 + pgd = pgd_offset_k(addr);
25914 + pud = pud_offset(pgd, addr);
25915 + pmd = pmd_offset(pud, addr);
25916 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
25917 + }
25918 +*/
25919 +#ifdef CONFIG_X86_PAE
25920 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
25921 +/*
25922 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
25923 + pgd = pgd_offset_k(addr);
25924 + pud = pud_offset(pgd, addr);
25925 + pmd = pmd_offset(pud, addr);
25926 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
25927 + }
25928 +*/
25929 +#endif
25930 +
25931 +#ifdef CONFIG_MODULES
25932 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
25933 +#endif
25934 +
25935 +#else
25936 + /* PaX: make kernel code/rodata read-only, rest non-executable */
25937 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
25938 + pgd = pgd_offset_k(addr);
25939 + pud = pud_offset(pgd, addr);
25940 + pmd = pmd_offset(pud, addr);
25941 + if (!pmd_present(*pmd))
25942 + continue;
25943 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
25944 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
25945 + else
25946 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
25947 + }
25948 +
25949 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
25950 + end = addr + KERNEL_IMAGE_SIZE;
25951 + for (; addr < end; addr += PMD_SIZE) {
25952 + pgd = pgd_offset_k(addr);
25953 + pud = pud_offset(pgd, addr);
25954 + pmd = pmd_offset(pud, addr);
25955 + if (!pmd_present(*pmd))
25956 + continue;
25957 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
25958 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
25959 + }
25960 +#endif
25961 +
25962 + flush_tlb_all();
25963 +#endif
25964 +
25965 free_init_pages("unused kernel memory",
25966 (unsigned long)(&__init_begin),
25967 (unsigned long)(&__init_end));
25968 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
25969 index 11a5800..4bd9977 100644
25970 --- a/arch/x86/mm/init_32.c
25971 +++ b/arch/x86/mm/init_32.c
25972 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
25973 }
25974
25975 /*
25976 - * Creates a middle page table and puts a pointer to it in the
25977 - * given global directory entry. This only returns the gd entry
25978 - * in non-PAE compilation mode, since the middle layer is folded.
25979 - */
25980 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
25981 -{
25982 - pud_t *pud;
25983 - pmd_t *pmd_table;
25984 -
25985 -#ifdef CONFIG_X86_PAE
25986 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
25987 - if (after_bootmem)
25988 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
25989 - else
25990 - pmd_table = (pmd_t *)alloc_low_page();
25991 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
25992 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
25993 - pud = pud_offset(pgd, 0);
25994 - BUG_ON(pmd_table != pmd_offset(pud, 0));
25995 -
25996 - return pmd_table;
25997 - }
25998 -#endif
25999 - pud = pud_offset(pgd, 0);
26000 - pmd_table = pmd_offset(pud, 0);
26001 -
26002 - return pmd_table;
26003 -}
26004 -
26005 -/*
26006 * Create a page table and place a pointer to it in a middle page
26007 * directory entry:
26008 */
26009 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26010 page_table = (pte_t *)alloc_low_page();
26011
26012 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26013 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26014 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26015 +#else
26016 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26017 +#endif
26018 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26019 }
26020
26021 return pte_offset_kernel(pmd, 0);
26022 }
26023
26024 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
26025 +{
26026 + pud_t *pud;
26027 + pmd_t *pmd_table;
26028 +
26029 + pud = pud_offset(pgd, 0);
26030 + pmd_table = pmd_offset(pud, 0);
26031 +
26032 + return pmd_table;
26033 +}
26034 +
26035 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26036 {
26037 int pgd_idx = pgd_index(vaddr);
26038 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26039 int pgd_idx, pmd_idx;
26040 unsigned long vaddr;
26041 pgd_t *pgd;
26042 + pud_t *pud;
26043 pmd_t *pmd;
26044 pte_t *pte = NULL;
26045
26046 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26047 pgd = pgd_base + pgd_idx;
26048
26049 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26050 - pmd = one_md_table_init(pgd);
26051 - pmd = pmd + pmd_index(vaddr);
26052 + pud = pud_offset(pgd, vaddr);
26053 + pmd = pmd_offset(pud, vaddr);
26054 +
26055 +#ifdef CONFIG_X86_PAE
26056 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26057 +#endif
26058 +
26059 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26060 pmd++, pmd_idx++) {
26061 pte = page_table_kmap_check(one_page_table_init(pmd),
26062 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26063 }
26064 }
26065
26066 -static inline int is_kernel_text(unsigned long addr)
26067 +static inline int is_kernel_text(unsigned long start, unsigned long end)
26068 {
26069 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26070 - return 1;
26071 - return 0;
26072 + if ((start > ktla_ktva((unsigned long)_etext) ||
26073 + end <= ktla_ktva((unsigned long)_stext)) &&
26074 + (start > ktla_ktva((unsigned long)_einittext) ||
26075 + end <= ktla_ktva((unsigned long)_sinittext)) &&
26076 +
26077 +#ifdef CONFIG_ACPI_SLEEP
26078 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26079 +#endif
26080 +
26081 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26082 + return 0;
26083 + return 1;
26084 }
26085
26086 /*
26087 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26088 unsigned long last_map_addr = end;
26089 unsigned long start_pfn, end_pfn;
26090 pgd_t *pgd_base = swapper_pg_dir;
26091 - int pgd_idx, pmd_idx, pte_ofs;
26092 + unsigned int pgd_idx, pmd_idx, pte_ofs;
26093 unsigned long pfn;
26094 pgd_t *pgd;
26095 + pud_t *pud;
26096 pmd_t *pmd;
26097 pte_t *pte;
26098 unsigned pages_2m, pages_4k;
26099 @@ -280,8 +281,13 @@ repeat:
26100 pfn = start_pfn;
26101 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26102 pgd = pgd_base + pgd_idx;
26103 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26104 - pmd = one_md_table_init(pgd);
26105 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26106 + pud = pud_offset(pgd, 0);
26107 + pmd = pmd_offset(pud, 0);
26108 +
26109 +#ifdef CONFIG_X86_PAE
26110 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26111 +#endif
26112
26113 if (pfn >= end_pfn)
26114 continue;
26115 @@ -293,14 +299,13 @@ repeat:
26116 #endif
26117 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26118 pmd++, pmd_idx++) {
26119 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26120 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26121
26122 /*
26123 * Map with big pages if possible, otherwise
26124 * create normal page tables:
26125 */
26126 if (use_pse) {
26127 - unsigned int addr2;
26128 pgprot_t prot = PAGE_KERNEL_LARGE;
26129 /*
26130 * first pass will use the same initial
26131 @@ -310,11 +315,7 @@ repeat:
26132 __pgprot(PTE_IDENT_ATTR |
26133 _PAGE_PSE);
26134
26135 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26136 - PAGE_OFFSET + PAGE_SIZE-1;
26137 -
26138 - if (is_kernel_text(addr) ||
26139 - is_kernel_text(addr2))
26140 + if (is_kernel_text(address, address + PMD_SIZE))
26141 prot = PAGE_KERNEL_LARGE_EXEC;
26142
26143 pages_2m++;
26144 @@ -331,7 +332,7 @@ repeat:
26145 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26146 pte += pte_ofs;
26147 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26148 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26149 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26150 pgprot_t prot = PAGE_KERNEL;
26151 /*
26152 * first pass will use the same initial
26153 @@ -339,7 +340,7 @@ repeat:
26154 */
26155 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26156
26157 - if (is_kernel_text(addr))
26158 + if (is_kernel_text(address, address + PAGE_SIZE))
26159 prot = PAGE_KERNEL_EXEC;
26160
26161 pages_4k++;
26162 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26163
26164 pud = pud_offset(pgd, va);
26165 pmd = pmd_offset(pud, va);
26166 - if (!pmd_present(*pmd))
26167 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
26168 break;
26169
26170 pte = pte_offset_kernel(pmd, va);
26171 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26172
26173 static void __init pagetable_init(void)
26174 {
26175 - pgd_t *pgd_base = swapper_pg_dir;
26176 -
26177 - permanent_kmaps_init(pgd_base);
26178 + permanent_kmaps_init(swapper_pg_dir);
26179 }
26180
26181 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26182 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26183 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26184
26185 /* user-defined highmem size */
26186 @@ -731,6 +730,12 @@ void __init mem_init(void)
26187
26188 pci_iommu_alloc();
26189
26190 +#ifdef CONFIG_PAX_PER_CPU_PGD
26191 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26192 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26193 + KERNEL_PGD_PTRS);
26194 +#endif
26195 +
26196 #ifdef CONFIG_FLATMEM
26197 BUG_ON(!mem_map);
26198 #endif
26199 @@ -757,7 +762,7 @@ void __init mem_init(void)
26200 reservedpages++;
26201
26202 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26203 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26204 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26205 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26206
26207 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26208 @@ -798,10 +803,10 @@ void __init mem_init(void)
26209 ((unsigned long)&__init_end -
26210 (unsigned long)&__init_begin) >> 10,
26211
26212 - (unsigned long)&_etext, (unsigned long)&_edata,
26213 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26214 + (unsigned long)&_sdata, (unsigned long)&_edata,
26215 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26216
26217 - (unsigned long)&_text, (unsigned long)&_etext,
26218 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26219 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26220
26221 /*
26222 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26223 if (!kernel_set_to_readonly)
26224 return;
26225
26226 + start = ktla_ktva(start);
26227 pr_debug("Set kernel text: %lx - %lx for read write\n",
26228 start, start+size);
26229
26230 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26231 if (!kernel_set_to_readonly)
26232 return;
26233
26234 + start = ktla_ktva(start);
26235 pr_debug("Set kernel text: %lx - %lx for read only\n",
26236 start, start+size);
26237
26238 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26239 unsigned long start = PFN_ALIGN(_text);
26240 unsigned long size = PFN_ALIGN(_etext) - start;
26241
26242 + start = ktla_ktva(start);
26243 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26244 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26245 size >> 10);
26246 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26247 index 3baff25..8b37564 100644
26248 --- a/arch/x86/mm/init_64.c
26249 +++ b/arch/x86/mm/init_64.c
26250 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26251 * around without checking the pgd every time.
26252 */
26253
26254 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26255 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26256 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26257
26258 int force_personality32;
26259 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26260
26261 for (address = start; address <= end; address += PGDIR_SIZE) {
26262 const pgd_t *pgd_ref = pgd_offset_k(address);
26263 +
26264 +#ifdef CONFIG_PAX_PER_CPU_PGD
26265 + unsigned long cpu;
26266 +#else
26267 struct page *page;
26268 +#endif
26269
26270 if (pgd_none(*pgd_ref))
26271 continue;
26272
26273 spin_lock(&pgd_lock);
26274 +
26275 +#ifdef CONFIG_PAX_PER_CPU_PGD
26276 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26277 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
26278 +#else
26279 list_for_each_entry(page, &pgd_list, lru) {
26280 pgd_t *pgd;
26281 spinlock_t *pgt_lock;
26282 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26283 /* the pgt_lock only for Xen */
26284 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26285 spin_lock(pgt_lock);
26286 +#endif
26287
26288 if (pgd_none(*pgd))
26289 set_pgd(pgd, *pgd_ref);
26290 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26291 BUG_ON(pgd_page_vaddr(*pgd)
26292 != pgd_page_vaddr(*pgd_ref));
26293
26294 +#ifndef CONFIG_PAX_PER_CPU_PGD
26295 spin_unlock(pgt_lock);
26296 +#endif
26297 +
26298 }
26299 spin_unlock(&pgd_lock);
26300 }
26301 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26302 {
26303 if (pgd_none(*pgd)) {
26304 pud_t *pud = (pud_t *)spp_getpage();
26305 - pgd_populate(&init_mm, pgd, pud);
26306 + pgd_populate_kernel(&init_mm, pgd, pud);
26307 if (pud != pud_offset(pgd, 0))
26308 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26309 pud, pud_offset(pgd, 0));
26310 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26311 {
26312 if (pud_none(*pud)) {
26313 pmd_t *pmd = (pmd_t *) spp_getpage();
26314 - pud_populate(&init_mm, pud, pmd);
26315 + pud_populate_kernel(&init_mm, pud, pmd);
26316 if (pmd != pmd_offset(pud, 0))
26317 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26318 pmd, pmd_offset(pud, 0));
26319 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26320 pmd = fill_pmd(pud, vaddr);
26321 pte = fill_pte(pmd, vaddr);
26322
26323 + pax_open_kernel();
26324 set_pte(pte, new_pte);
26325 + pax_close_kernel();
26326
26327 /*
26328 * It's enough to flush this one mapping.
26329 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26330 pgd = pgd_offset_k((unsigned long)__va(phys));
26331 if (pgd_none(*pgd)) {
26332 pud = (pud_t *) spp_getpage();
26333 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26334 - _PAGE_USER));
26335 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26336 }
26337 pud = pud_offset(pgd, (unsigned long)__va(phys));
26338 if (pud_none(*pud)) {
26339 pmd = (pmd_t *) spp_getpage();
26340 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26341 - _PAGE_USER));
26342 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26343 }
26344 pmd = pmd_offset(pud, phys);
26345 BUG_ON(!pmd_none(*pmd));
26346 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26347 if (pfn >= pgt_buf_top)
26348 panic("alloc_low_page: ran out of memory");
26349
26350 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26351 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26352 clear_page(adr);
26353 *phys = pfn * PAGE_SIZE;
26354 return adr;
26355 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26356
26357 phys = __pa(virt);
26358 left = phys & (PAGE_SIZE - 1);
26359 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26360 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26361 adr = (void *)(((unsigned long)adr) | left);
26362
26363 return adr;
26364 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26365 unmap_low_page(pmd);
26366
26367 spin_lock(&init_mm.page_table_lock);
26368 - pud_populate(&init_mm, pud, __va(pmd_phys));
26369 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26370 spin_unlock(&init_mm.page_table_lock);
26371 }
26372 __flush_tlb_all();
26373 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26374 unmap_low_page(pud);
26375
26376 spin_lock(&init_mm.page_table_lock);
26377 - pgd_populate(&init_mm, pgd, __va(pud_phys));
26378 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26379 spin_unlock(&init_mm.page_table_lock);
26380 pgd_changed = true;
26381 }
26382 @@ -691,6 +705,12 @@ void __init mem_init(void)
26383
26384 pci_iommu_alloc();
26385
26386 +#ifdef CONFIG_PAX_PER_CPU_PGD
26387 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26388 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26389 + KERNEL_PGD_PTRS);
26390 +#endif
26391 +
26392 /* clear_bss() already clear the empty_zero_page */
26393
26394 reservedpages = 0;
26395 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
26396 static struct vm_area_struct gate_vma = {
26397 .vm_start = VSYSCALL_START,
26398 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26399 - .vm_page_prot = PAGE_READONLY_EXEC,
26400 - .vm_flags = VM_READ | VM_EXEC
26401 + .vm_page_prot = PAGE_READONLY,
26402 + .vm_flags = VM_READ
26403 };
26404
26405 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26406 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
26407
26408 const char *arch_vma_name(struct vm_area_struct *vma)
26409 {
26410 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26411 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26412 return "[vdso]";
26413 if (vma == &gate_vma)
26414 return "[vsyscall]";
26415 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26416 index 7b179b4..6bd1777 100644
26417 --- a/arch/x86/mm/iomap_32.c
26418 +++ b/arch/x86/mm/iomap_32.c
26419 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26420 type = kmap_atomic_idx_push();
26421 idx = type + KM_TYPE_NR * smp_processor_id();
26422 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26423 +
26424 + pax_open_kernel();
26425 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26426 + pax_close_kernel();
26427 +
26428 arch_flush_lazy_mmu_mode();
26429
26430 return (void *)vaddr;
26431 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26432 index 78fe3f1..2f9433c 100644
26433 --- a/arch/x86/mm/ioremap.c
26434 +++ b/arch/x86/mm/ioremap.c
26435 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26436 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26437 int is_ram = page_is_ram(pfn);
26438
26439 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26440 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26441 return NULL;
26442 WARN_ON_ONCE(is_ram);
26443 }
26444 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26445 *
26446 * Caller must ensure there is only one unmapping for the same pointer.
26447 */
26448 -void iounmap(volatile void __iomem *addr)
26449 +void iounmap(const volatile void __iomem *addr)
26450 {
26451 struct vm_struct *p, *o;
26452
26453 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26454
26455 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26456 if (page_is_ram(start >> PAGE_SHIFT))
26457 +#ifdef CONFIG_HIGHMEM
26458 + if ((start >> PAGE_SHIFT) < max_low_pfn)
26459 +#endif
26460 return __va(phys);
26461
26462 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26463 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26464 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26465
26466 static __initdata int after_paging_init;
26467 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26468 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26469
26470 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26471 {
26472 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26473 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26474
26475 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26476 - memset(bm_pte, 0, sizeof(bm_pte));
26477 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
26478 + pmd_populate_user(&init_mm, pmd, bm_pte);
26479
26480 /*
26481 * The boot-ioremap range spans multiple pmds, for which
26482 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26483 index d87dd6d..bf3fa66 100644
26484 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
26485 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26486 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26487 * memory (e.g. tracked pages)? For now, we need this to avoid
26488 * invoking kmemcheck for PnP BIOS calls.
26489 */
26490 - if (regs->flags & X86_VM_MASK)
26491 + if (v8086_mode(regs))
26492 return false;
26493 - if (regs->cs != __KERNEL_CS)
26494 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26495 return false;
26496
26497 pte = kmemcheck_pte_lookup(address);
26498 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26499 index 845df68..1d8d29f 100644
26500 --- a/arch/x86/mm/mmap.c
26501 +++ b/arch/x86/mm/mmap.c
26502 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26503 * Leave an at least ~128 MB hole with possible stack randomization.
26504 */
26505 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26506 -#define MAX_GAP (TASK_SIZE/6*5)
26507 +#define MAX_GAP (pax_task_size/6*5)
26508
26509 static int mmap_is_legacy(void)
26510 {
26511 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26512 return rnd << PAGE_SHIFT;
26513 }
26514
26515 -static unsigned long mmap_base(void)
26516 +static unsigned long mmap_base(struct mm_struct *mm)
26517 {
26518 unsigned long gap = rlimit(RLIMIT_STACK);
26519 + unsigned long pax_task_size = TASK_SIZE;
26520 +
26521 +#ifdef CONFIG_PAX_SEGMEXEC
26522 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26523 + pax_task_size = SEGMEXEC_TASK_SIZE;
26524 +#endif
26525
26526 if (gap < MIN_GAP)
26527 gap = MIN_GAP;
26528 else if (gap > MAX_GAP)
26529 gap = MAX_GAP;
26530
26531 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26532 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26533 }
26534
26535 /*
26536 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26537 * does, but not when emulating X86_32
26538 */
26539 -static unsigned long mmap_legacy_base(void)
26540 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
26541 {
26542 - if (mmap_is_ia32())
26543 + if (mmap_is_ia32()) {
26544 +
26545 +#ifdef CONFIG_PAX_SEGMEXEC
26546 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26547 + return SEGMEXEC_TASK_UNMAPPED_BASE;
26548 + else
26549 +#endif
26550 +
26551 return TASK_UNMAPPED_BASE;
26552 - else
26553 + } else
26554 return TASK_UNMAPPED_BASE + mmap_rnd();
26555 }
26556
26557 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26558 void arch_pick_mmap_layout(struct mm_struct *mm)
26559 {
26560 if (mmap_is_legacy()) {
26561 - mm->mmap_base = mmap_legacy_base();
26562 + mm->mmap_base = mmap_legacy_base(mm);
26563 +
26564 +#ifdef CONFIG_PAX_RANDMMAP
26565 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26566 + mm->mmap_base += mm->delta_mmap;
26567 +#endif
26568 +
26569 mm->get_unmapped_area = arch_get_unmapped_area;
26570 mm->unmap_area = arch_unmap_area;
26571 } else {
26572 - mm->mmap_base = mmap_base();
26573 + mm->mmap_base = mmap_base(mm);
26574 +
26575 +#ifdef CONFIG_PAX_RANDMMAP
26576 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26577 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26578 +#endif
26579 +
26580 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26581 mm->unmap_area = arch_unmap_area_topdown;
26582 }
26583 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26584 index dc0b727..f612039 100644
26585 --- a/arch/x86/mm/mmio-mod.c
26586 +++ b/arch/x86/mm/mmio-mod.c
26587 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26588 break;
26589 default:
26590 {
26591 - unsigned char *ip = (unsigned char *)instptr;
26592 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26593 my_trace->opcode = MMIO_UNKNOWN_OP;
26594 my_trace->width = 0;
26595 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26596 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26597 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26598 void __iomem *addr)
26599 {
26600 - static atomic_t next_id;
26601 + static atomic_unchecked_t next_id;
26602 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26603 /* These are page-unaligned. */
26604 struct mmiotrace_map map = {
26605 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26606 .private = trace
26607 },
26608 .phys = offset,
26609 - .id = atomic_inc_return(&next_id)
26610 + .id = atomic_inc_return_unchecked(&next_id)
26611 };
26612 map.map_id = trace->id;
26613
26614 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26615 ioremap_trace_core(offset, size, addr);
26616 }
26617
26618 -static void iounmap_trace_core(volatile void __iomem *addr)
26619 +static void iounmap_trace_core(const volatile void __iomem *addr)
26620 {
26621 struct mmiotrace_map map = {
26622 .phys = 0,
26623 @@ -328,7 +328,7 @@ not_enabled:
26624 }
26625 }
26626
26627 -void mmiotrace_iounmap(volatile void __iomem *addr)
26628 +void mmiotrace_iounmap(const volatile void __iomem *addr)
26629 {
26630 might_sleep();
26631 if (is_enabled()) /* recheck and proper locking in *_core() */
26632 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26633 index b008656..773eac2 100644
26634 --- a/arch/x86/mm/pageattr-test.c
26635 +++ b/arch/x86/mm/pageattr-test.c
26636 @@ -36,7 +36,7 @@ enum {
26637
26638 static int pte_testbit(pte_t pte)
26639 {
26640 - return pte_flags(pte) & _PAGE_UNUSED1;
26641 + return pte_flags(pte) & _PAGE_CPA_TEST;
26642 }
26643
26644 struct split_state {
26645 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26646 index a718e0d..77419bc 100644
26647 --- a/arch/x86/mm/pageattr.c
26648 +++ b/arch/x86/mm/pageattr.c
26649 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26650 */
26651 #ifdef CONFIG_PCI_BIOS
26652 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26653 - pgprot_val(forbidden) |= _PAGE_NX;
26654 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26655 #endif
26656
26657 /*
26658 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26659 * Does not cover __inittext since that is gone later on. On
26660 * 64bit we do not enforce !NX on the low mapping
26661 */
26662 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
26663 - pgprot_val(forbidden) |= _PAGE_NX;
26664 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
26665 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26666
26667 +#ifdef CONFIG_DEBUG_RODATA
26668 /*
26669 * The .rodata section needs to be read-only. Using the pfn
26670 * catches all aliases.
26671 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26672 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
26673 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
26674 pgprot_val(forbidden) |= _PAGE_RW;
26675 +#endif
26676
26677 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
26678 /*
26679 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26680 }
26681 #endif
26682
26683 +#ifdef CONFIG_PAX_KERNEXEC
26684 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
26685 + pgprot_val(forbidden) |= _PAGE_RW;
26686 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26687 + }
26688 +#endif
26689 +
26690 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
26691
26692 return prot;
26693 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
26694 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
26695 {
26696 /* change init_mm */
26697 + pax_open_kernel();
26698 set_pte_atomic(kpte, pte);
26699 +
26700 #ifdef CONFIG_X86_32
26701 if (!SHARED_KERNEL_PMD) {
26702 +
26703 +#ifdef CONFIG_PAX_PER_CPU_PGD
26704 + unsigned long cpu;
26705 +#else
26706 struct page *page;
26707 +#endif
26708
26709 +#ifdef CONFIG_PAX_PER_CPU_PGD
26710 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26711 + pgd_t *pgd = get_cpu_pgd(cpu);
26712 +#else
26713 list_for_each_entry(page, &pgd_list, lru) {
26714 - pgd_t *pgd;
26715 + pgd_t *pgd = (pgd_t *)page_address(page);
26716 +#endif
26717 +
26718 pud_t *pud;
26719 pmd_t *pmd;
26720
26721 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
26722 + pgd += pgd_index(address);
26723 pud = pud_offset(pgd, address);
26724 pmd = pmd_offset(pud, address);
26725 set_pte_atomic((pte_t *)pmd, pte);
26726 }
26727 }
26728 #endif
26729 + pax_close_kernel();
26730 }
26731
26732 static int
26733 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
26734 index 0eb572e..92f5c1e 100644
26735 --- a/arch/x86/mm/pat.c
26736 +++ b/arch/x86/mm/pat.c
26737 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
26738
26739 if (!entry) {
26740 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
26741 - current->comm, current->pid, start, end - 1);
26742 + current->comm, task_pid_nr(current), start, end - 1);
26743 return -EINVAL;
26744 }
26745
26746 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
26747
26748 while (cursor < to) {
26749 if (!devmem_is_allowed(pfn)) {
26750 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
26751 - current->comm, from, to - 1);
26752 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
26753 + current->comm, from, to - 1, cursor);
26754 return 0;
26755 }
26756 cursor += PAGE_SIZE;
26757 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
26758 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
26759 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
26760 "for [mem %#010Lx-%#010Lx]\n",
26761 - current->comm, current->pid,
26762 + current->comm, task_pid_nr(current),
26763 cattr_name(flags),
26764 base, (unsigned long long)(base + size-1));
26765 return -EINVAL;
26766 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
26767 flags = lookup_memtype(paddr);
26768 if (want_flags != flags) {
26769 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
26770 - current->comm, current->pid,
26771 + current->comm, task_pid_nr(current),
26772 cattr_name(want_flags),
26773 (unsigned long long)paddr,
26774 (unsigned long long)(paddr + size - 1),
26775 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
26776 free_memtype(paddr, paddr + size);
26777 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
26778 " for [mem %#010Lx-%#010Lx], got %s\n",
26779 - current->comm, current->pid,
26780 + current->comm, task_pid_nr(current),
26781 cattr_name(want_flags),
26782 (unsigned long long)paddr,
26783 (unsigned long long)(paddr + size - 1),
26784 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
26785 index 9f0614d..92ae64a 100644
26786 --- a/arch/x86/mm/pf_in.c
26787 +++ b/arch/x86/mm/pf_in.c
26788 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
26789 int i;
26790 enum reason_type rv = OTHERS;
26791
26792 - p = (unsigned char *)ins_addr;
26793 + p = (unsigned char *)ktla_ktva(ins_addr);
26794 p += skip_prefix(p, &prf);
26795 p += get_opcode(p, &opcode);
26796
26797 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
26798 struct prefix_bits prf;
26799 int i;
26800
26801 - p = (unsigned char *)ins_addr;
26802 + p = (unsigned char *)ktla_ktva(ins_addr);
26803 p += skip_prefix(p, &prf);
26804 p += get_opcode(p, &opcode);
26805
26806 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
26807 struct prefix_bits prf;
26808 int i;
26809
26810 - p = (unsigned char *)ins_addr;
26811 + p = (unsigned char *)ktla_ktva(ins_addr);
26812 p += skip_prefix(p, &prf);
26813 p += get_opcode(p, &opcode);
26814
26815 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
26816 struct prefix_bits prf;
26817 int i;
26818
26819 - p = (unsigned char *)ins_addr;
26820 + p = (unsigned char *)ktla_ktva(ins_addr);
26821 p += skip_prefix(p, &prf);
26822 p += get_opcode(p, &opcode);
26823 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
26824 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
26825 struct prefix_bits prf;
26826 int i;
26827
26828 - p = (unsigned char *)ins_addr;
26829 + p = (unsigned char *)ktla_ktva(ins_addr);
26830 p += skip_prefix(p, &prf);
26831 p += get_opcode(p, &opcode);
26832 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
26833 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
26834 index 8573b83..4f3ed7e 100644
26835 --- a/arch/x86/mm/pgtable.c
26836 +++ b/arch/x86/mm/pgtable.c
26837 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
26838 list_del(&page->lru);
26839 }
26840
26841 -#define UNSHARED_PTRS_PER_PGD \
26842 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
26843 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26844 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
26845
26846 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
26847 +{
26848 + unsigned int count = USER_PGD_PTRS;
26849
26850 + while (count--)
26851 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
26852 +}
26853 +#endif
26854 +
26855 +#ifdef CONFIG_PAX_PER_CPU_PGD
26856 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
26857 +{
26858 + unsigned int count = USER_PGD_PTRS;
26859 +
26860 + while (count--) {
26861 + pgd_t pgd;
26862 +
26863 +#ifdef CONFIG_X86_64
26864 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
26865 +#else
26866 + pgd = *src++;
26867 +#endif
26868 +
26869 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26870 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
26871 +#endif
26872 +
26873 + *dst++ = pgd;
26874 + }
26875 +
26876 +}
26877 +#endif
26878 +
26879 +#ifdef CONFIG_X86_64
26880 +#define pxd_t pud_t
26881 +#define pyd_t pgd_t
26882 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
26883 +#define pxd_free(mm, pud) pud_free((mm), (pud))
26884 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
26885 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
26886 +#define PYD_SIZE PGDIR_SIZE
26887 +#else
26888 +#define pxd_t pmd_t
26889 +#define pyd_t pud_t
26890 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
26891 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
26892 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
26893 +#define pyd_offset(mm, address) pud_offset((mm), (address))
26894 +#define PYD_SIZE PUD_SIZE
26895 +#endif
26896 +
26897 +#ifdef CONFIG_PAX_PER_CPU_PGD
26898 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
26899 +static inline void pgd_dtor(pgd_t *pgd) {}
26900 +#else
26901 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
26902 {
26903 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
26904 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
26905 pgd_list_del(pgd);
26906 spin_unlock(&pgd_lock);
26907 }
26908 +#endif
26909
26910 /*
26911 * List of all pgd's needed for non-PAE so it can invalidate entries
26912 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
26913 * -- wli
26914 */
26915
26916 -#ifdef CONFIG_X86_PAE
26917 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26918 /*
26919 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
26920 * updating the top-level pagetable entries to guarantee the
26921 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
26922 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
26923 * and initialize the kernel pmds here.
26924 */
26925 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
26926 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
26927
26928 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
26929 {
26930 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
26931 */
26932 flush_tlb_mm(mm);
26933 }
26934 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
26935 +#define PREALLOCATED_PXDS USER_PGD_PTRS
26936 #else /* !CONFIG_X86_PAE */
26937
26938 /* No need to prepopulate any pagetable entries in non-PAE modes. */
26939 -#define PREALLOCATED_PMDS 0
26940 +#define PREALLOCATED_PXDS 0
26941
26942 #endif /* CONFIG_X86_PAE */
26943
26944 -static void free_pmds(pmd_t *pmds[])
26945 +static void free_pxds(pxd_t *pxds[])
26946 {
26947 int i;
26948
26949 - for(i = 0; i < PREALLOCATED_PMDS; i++)
26950 - if (pmds[i])
26951 - free_page((unsigned long)pmds[i]);
26952 + for(i = 0; i < PREALLOCATED_PXDS; i++)
26953 + if (pxds[i])
26954 + free_page((unsigned long)pxds[i]);
26955 }
26956
26957 -static int preallocate_pmds(pmd_t *pmds[])
26958 +static int preallocate_pxds(pxd_t *pxds[])
26959 {
26960 int i;
26961 bool failed = false;
26962
26963 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
26964 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
26965 - if (pmd == NULL)
26966 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
26967 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
26968 + if (pxd == NULL)
26969 failed = true;
26970 - pmds[i] = pmd;
26971 + pxds[i] = pxd;
26972 }
26973
26974 if (failed) {
26975 - free_pmds(pmds);
26976 + free_pxds(pxds);
26977 return -ENOMEM;
26978 }
26979
26980 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
26981 * preallocate which never got a corresponding vma will need to be
26982 * freed manually.
26983 */
26984 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
26985 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
26986 {
26987 int i;
26988
26989 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
26990 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
26991 pgd_t pgd = pgdp[i];
26992
26993 if (pgd_val(pgd) != 0) {
26994 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
26995 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
26996
26997 - pgdp[i] = native_make_pgd(0);
26998 + set_pgd(pgdp + i, native_make_pgd(0));
26999
27000 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27001 - pmd_free(mm, pmd);
27002 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27003 + pxd_free(mm, pxd);
27004 }
27005 }
27006 }
27007
27008 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27009 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27010 {
27011 - pud_t *pud;
27012 + pyd_t *pyd;
27013 unsigned long addr;
27014 int i;
27015
27016 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27017 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27018 return;
27019
27020 - pud = pud_offset(pgd, 0);
27021 +#ifdef CONFIG_X86_64
27022 + pyd = pyd_offset(mm, 0L);
27023 +#else
27024 + pyd = pyd_offset(pgd, 0L);
27025 +#endif
27026
27027 - for (addr = i = 0; i < PREALLOCATED_PMDS;
27028 - i++, pud++, addr += PUD_SIZE) {
27029 - pmd_t *pmd = pmds[i];
27030 + for (addr = i = 0; i < PREALLOCATED_PXDS;
27031 + i++, pyd++, addr += PYD_SIZE) {
27032 + pxd_t *pxd = pxds[i];
27033
27034 if (i >= KERNEL_PGD_BOUNDARY)
27035 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27036 - sizeof(pmd_t) * PTRS_PER_PMD);
27037 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27038 + sizeof(pxd_t) * PTRS_PER_PMD);
27039
27040 - pud_populate(mm, pud, pmd);
27041 + pyd_populate(mm, pyd, pxd);
27042 }
27043 }
27044
27045 pgd_t *pgd_alloc(struct mm_struct *mm)
27046 {
27047 pgd_t *pgd;
27048 - pmd_t *pmds[PREALLOCATED_PMDS];
27049 + pxd_t *pxds[PREALLOCATED_PXDS];
27050
27051 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27052
27053 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27054
27055 mm->pgd = pgd;
27056
27057 - if (preallocate_pmds(pmds) != 0)
27058 + if (preallocate_pxds(pxds) != 0)
27059 goto out_free_pgd;
27060
27061 if (paravirt_pgd_alloc(mm) != 0)
27062 - goto out_free_pmds;
27063 + goto out_free_pxds;
27064
27065 /*
27066 * Make sure that pre-populating the pmds is atomic with
27067 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27068 spin_lock(&pgd_lock);
27069
27070 pgd_ctor(mm, pgd);
27071 - pgd_prepopulate_pmd(mm, pgd, pmds);
27072 + pgd_prepopulate_pxd(mm, pgd, pxds);
27073
27074 spin_unlock(&pgd_lock);
27075
27076 return pgd;
27077
27078 -out_free_pmds:
27079 - free_pmds(pmds);
27080 +out_free_pxds:
27081 + free_pxds(pxds);
27082 out_free_pgd:
27083 free_page((unsigned long)pgd);
27084 out:
27085 @@ -295,7 +356,7 @@ out:
27086
27087 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27088 {
27089 - pgd_mop_up_pmds(mm, pgd);
27090 + pgd_mop_up_pxds(mm, pgd);
27091 pgd_dtor(pgd);
27092 paravirt_pgd_free(mm, pgd);
27093 free_page((unsigned long)pgd);
27094 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27095 index a69bcb8..19068ab 100644
27096 --- a/arch/x86/mm/pgtable_32.c
27097 +++ b/arch/x86/mm/pgtable_32.c
27098 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27099 return;
27100 }
27101 pte = pte_offset_kernel(pmd, vaddr);
27102 +
27103 + pax_open_kernel();
27104 if (pte_val(pteval))
27105 set_pte_at(&init_mm, vaddr, pte, pteval);
27106 else
27107 pte_clear(&init_mm, vaddr, pte);
27108 + pax_close_kernel();
27109
27110 /*
27111 * It's enough to flush this one mapping.
27112 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27113 index 410531d..0f16030 100644
27114 --- a/arch/x86/mm/setup_nx.c
27115 +++ b/arch/x86/mm/setup_nx.c
27116 @@ -5,8 +5,10 @@
27117 #include <asm/pgtable.h>
27118 #include <asm/proto.h>
27119
27120 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27121 static int disable_nx __cpuinitdata;
27122
27123 +#ifndef CONFIG_PAX_PAGEEXEC
27124 /*
27125 * noexec = on|off
27126 *
27127 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27128 return 0;
27129 }
27130 early_param("noexec", noexec_setup);
27131 +#endif
27132 +
27133 +#endif
27134
27135 void __cpuinit x86_configure_nx(void)
27136 {
27137 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27138 if (cpu_has_nx && !disable_nx)
27139 __supported_pte_mask |= _PAGE_NX;
27140 else
27141 +#endif
27142 __supported_pte_mask &= ~_PAGE_NX;
27143 }
27144
27145 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27146 index 60f926c..a710970 100644
27147 --- a/arch/x86/mm/tlb.c
27148 +++ b/arch/x86/mm/tlb.c
27149 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
27150 BUG();
27151 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27152 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27153 +
27154 +#ifndef CONFIG_PAX_PER_CPU_PGD
27155 load_cr3(swapper_pg_dir);
27156 +#endif
27157 +
27158 }
27159 }
27160 EXPORT_SYMBOL_GPL(leave_mm);
27161 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27162 index 877b9a1..a8ecf42 100644
27163 --- a/arch/x86/net/bpf_jit.S
27164 +++ b/arch/x86/net/bpf_jit.S
27165 @@ -9,6 +9,7 @@
27166 */
27167 #include <linux/linkage.h>
27168 #include <asm/dwarf2.h>
27169 +#include <asm/alternative-asm.h>
27170
27171 /*
27172 * Calling convention :
27173 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27174 jle bpf_slow_path_word
27175 mov (SKBDATA,%rsi),%eax
27176 bswap %eax /* ntohl() */
27177 + pax_force_retaddr
27178 ret
27179
27180 sk_load_half:
27181 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27182 jle bpf_slow_path_half
27183 movzwl (SKBDATA,%rsi),%eax
27184 rol $8,%ax # ntohs()
27185 + pax_force_retaddr
27186 ret
27187
27188 sk_load_byte:
27189 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27190 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27191 jle bpf_slow_path_byte
27192 movzbl (SKBDATA,%rsi),%eax
27193 + pax_force_retaddr
27194 ret
27195
27196 /**
27197 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27198 movzbl (SKBDATA,%rsi),%ebx
27199 and $15,%bl
27200 shl $2,%bl
27201 + pax_force_retaddr
27202 ret
27203
27204 /* rsi contains offset and can be scratched */
27205 @@ -109,6 +114,7 @@ bpf_slow_path_word:
27206 js bpf_error
27207 mov -12(%rbp),%eax
27208 bswap %eax
27209 + pax_force_retaddr
27210 ret
27211
27212 bpf_slow_path_half:
27213 @@ -117,12 +123,14 @@ bpf_slow_path_half:
27214 mov -12(%rbp),%ax
27215 rol $8,%ax
27216 movzwl %ax,%eax
27217 + pax_force_retaddr
27218 ret
27219
27220 bpf_slow_path_byte:
27221 bpf_slow_path_common(1)
27222 js bpf_error
27223 movzbl -12(%rbp),%eax
27224 + pax_force_retaddr
27225 ret
27226
27227 bpf_slow_path_byte_msh:
27228 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27229 and $15,%al
27230 shl $2,%al
27231 xchg %eax,%ebx
27232 + pax_force_retaddr
27233 ret
27234
27235 #define sk_negative_common(SIZE) \
27236 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27237 sk_negative_common(4)
27238 mov (%rax), %eax
27239 bswap %eax
27240 + pax_force_retaddr
27241 ret
27242
27243 bpf_slow_path_half_neg:
27244 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27245 mov (%rax),%ax
27246 rol $8,%ax
27247 movzwl %ax,%eax
27248 + pax_force_retaddr
27249 ret
27250
27251 bpf_slow_path_byte_neg:
27252 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27253 .globl sk_load_byte_negative_offset
27254 sk_negative_common(1)
27255 movzbl (%rax), %eax
27256 + pax_force_retaddr
27257 ret
27258
27259 bpf_slow_path_byte_msh_neg:
27260 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27261 and $15,%al
27262 shl $2,%al
27263 xchg %eax,%ebx
27264 + pax_force_retaddr
27265 ret
27266
27267 bpf_error:
27268 @@ -197,4 +210,5 @@ bpf_error:
27269 xor %eax,%eax
27270 mov -8(%rbp),%rbx
27271 leaveq
27272 + pax_force_retaddr
27273 ret
27274 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27275 index 520d2bd..b895ef4 100644
27276 --- a/arch/x86/net/bpf_jit_comp.c
27277 +++ b/arch/x86/net/bpf_jit_comp.c
27278 @@ -11,6 +11,7 @@
27279 #include <asm/cacheflush.h>
27280 #include <linux/netdevice.h>
27281 #include <linux/filter.h>
27282 +#include <linux/random.h>
27283
27284 /*
27285 * Conventions :
27286 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27287 return ptr + len;
27288 }
27289
27290 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27291 +#define MAX_INSTR_CODE_SIZE 96
27292 +#else
27293 +#define MAX_INSTR_CODE_SIZE 64
27294 +#endif
27295 +
27296 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27297
27298 #define EMIT1(b1) EMIT(b1, 1)
27299 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27300 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27301 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27302 +
27303 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27304 +/* original constant will appear in ecx */
27305 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
27306 +do { \
27307 + /* mov ecx, randkey */ \
27308 + EMIT1(0xb9); \
27309 + EMIT(_key, 4); \
27310 + /* xor ecx, randkey ^ off */ \
27311 + EMIT2(0x81, 0xf1); \
27312 + EMIT((_key) ^ (_off), 4); \
27313 +} while (0)
27314 +
27315 +#define EMIT1_off32(b1, _off) \
27316 +do { \
27317 + switch (b1) { \
27318 + case 0x05: /* add eax, imm32 */ \
27319 + case 0x2d: /* sub eax, imm32 */ \
27320 + case 0x25: /* and eax, imm32 */ \
27321 + case 0x0d: /* or eax, imm32 */ \
27322 + case 0xb8: /* mov eax, imm32 */ \
27323 + case 0x3d: /* cmp eax, imm32 */ \
27324 + case 0xa9: /* test eax, imm32 */ \
27325 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27326 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27327 + break; \
27328 + case 0xbb: /* mov ebx, imm32 */ \
27329 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27330 + /* mov ebx, ecx */ \
27331 + EMIT2(0x89, 0xcb); \
27332 + break; \
27333 + case 0xbe: /* mov esi, imm32 */ \
27334 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27335 + /* mov esi, ecx */ \
27336 + EMIT2(0x89, 0xce); \
27337 + break; \
27338 + case 0xe9: /* jmp rel imm32 */ \
27339 + EMIT1(b1); \
27340 + EMIT(_off, 4); \
27341 + /* prevent fall-through, we're not called if off = 0 */ \
27342 + EMIT(0xcccccccc, 4); \
27343 + EMIT(0xcccccccc, 4); \
27344 + break; \
27345 + default: \
27346 + EMIT1(b1); \
27347 + EMIT(_off, 4); \
27348 + } \
27349 +} while (0)
27350 +
27351 +#define EMIT2_off32(b1, b2, _off) \
27352 +do { \
27353 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27354 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27355 + EMIT(randkey, 4); \
27356 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27357 + EMIT((_off) - randkey, 4); \
27358 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27359 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27360 + /* imul eax, ecx */ \
27361 + EMIT3(0x0f, 0xaf, 0xc1); \
27362 + } else { \
27363 + EMIT2(b1, b2); \
27364 + EMIT(_off, 4); \
27365 + } \
27366 +} while (0)
27367 +#else
27368 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27369 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27370 +#endif
27371
27372 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27373 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27374 @@ -89,6 +164,24 @@ do { \
27375 #define X86_JBE 0x76
27376 #define X86_JA 0x77
27377
27378 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27379 +#define APPEND_FLOW_VERIFY() \
27380 +do { \
27381 + /* mov ecx, randkey */ \
27382 + EMIT1(0xb9); \
27383 + EMIT(randkey, 4); \
27384 + /* cmp ecx, randkey */ \
27385 + EMIT2(0x81, 0xf9); \
27386 + EMIT(randkey, 4); \
27387 + /* jz after 8 int 3s */ \
27388 + EMIT2(0x74, 0x08); \
27389 + EMIT(0xcccccccc, 4); \
27390 + EMIT(0xcccccccc, 4); \
27391 +} while (0)
27392 +#else
27393 +#define APPEND_FLOW_VERIFY() do { } while (0)
27394 +#endif
27395 +
27396 #define EMIT_COND_JMP(op, offset) \
27397 do { \
27398 if (is_near(offset)) \
27399 @@ -96,6 +189,7 @@ do { \
27400 else { \
27401 EMIT2(0x0f, op + 0x10); \
27402 EMIT(offset, 4); /* jxx .+off32 */ \
27403 + APPEND_FLOW_VERIFY(); \
27404 } \
27405 } while (0)
27406
27407 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27408 set_fs(old_fs);
27409 }
27410
27411 +struct bpf_jit_work {
27412 + struct work_struct work;
27413 + void *image;
27414 +};
27415 +
27416 #define CHOOSE_LOAD_FUNC(K, func) \
27417 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27418
27419 void bpf_jit_compile(struct sk_filter *fp)
27420 {
27421 - u8 temp[64];
27422 + u8 temp[MAX_INSTR_CODE_SIZE];
27423 u8 *prog;
27424 unsigned int proglen, oldproglen = 0;
27425 int ilen, i;
27426 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27427 unsigned int *addrs;
27428 const struct sock_filter *filter = fp->insns;
27429 int flen = fp->len;
27430 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27431 + unsigned int randkey;
27432 +#endif
27433
27434 if (!bpf_jit_enable)
27435 return;
27436 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27437 if (addrs == NULL)
27438 return;
27439
27440 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27441 + if (!fp->work)
27442 + goto out;
27443 +
27444 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27445 + randkey = get_random_int();
27446 +#endif
27447 +
27448 /* Before first pass, make a rough estimation of addrs[]
27449 - * each bpf instruction is translated to less than 64 bytes
27450 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27451 */
27452 for (proglen = 0, i = 0; i < flen; i++) {
27453 - proglen += 64;
27454 + proglen += MAX_INSTR_CODE_SIZE;
27455 addrs[i] = proglen;
27456 }
27457 cleanup_addr = proglen; /* epilogue address */
27458 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27459 case BPF_S_ALU_MUL_K: /* A *= K */
27460 if (is_imm8(K))
27461 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27462 - else {
27463 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27464 - EMIT(K, 4);
27465 - }
27466 + else
27467 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27468 break;
27469 case BPF_S_ALU_DIV_X: /* A /= X; */
27470 seen |= SEEN_XREG;
27471 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27472 break;
27473 case BPF_S_ALU_MOD_K: /* A %= K; */
27474 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27475 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27476 + DILUTE_CONST_SEQUENCE(K, randkey);
27477 +#else
27478 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27479 +#endif
27480 EMIT2(0xf7, 0xf1); /* div %ecx */
27481 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27482 break;
27483 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27484 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27485 + DILUTE_CONST_SEQUENCE(K, randkey);
27486 + // imul rax, rcx
27487 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27488 +#else
27489 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27490 EMIT(K, 4);
27491 +#endif
27492 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27493 break;
27494 case BPF_S_ALU_AND_X:
27495 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27496 if (is_imm8(K)) {
27497 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27498 } else {
27499 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27500 - EMIT(K, 4);
27501 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27502 }
27503 } else {
27504 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27505 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27506 break;
27507 default:
27508 /* hmm, too complex filter, give up with jit compiler */
27509 - goto out;
27510 + goto error;
27511 }
27512 ilen = prog - temp;
27513 if (image) {
27514 if (unlikely(proglen + ilen > oldproglen)) {
27515 pr_err("bpb_jit_compile fatal error\n");
27516 - kfree(addrs);
27517 - module_free(NULL, image);
27518 - return;
27519 + module_free_exec(NULL, image);
27520 + goto error;
27521 }
27522 + pax_open_kernel();
27523 memcpy(image + proglen, temp, ilen);
27524 + pax_close_kernel();
27525 }
27526 proglen += ilen;
27527 addrs[i] = proglen;
27528 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27529 break;
27530 }
27531 if (proglen == oldproglen) {
27532 - image = module_alloc(max_t(unsigned int,
27533 - proglen,
27534 - sizeof(struct work_struct)));
27535 + image = module_alloc_exec(proglen);
27536 if (!image)
27537 - goto out;
27538 + goto error;
27539 }
27540 oldproglen = proglen;
27541 }
27542 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27543 bpf_flush_icache(image, image + proglen);
27544
27545 fp->bpf_func = (void *)image;
27546 - }
27547 + } else
27548 +error:
27549 + kfree(fp->work);
27550 +
27551 out:
27552 kfree(addrs);
27553 return;
27554 @@ -686,18 +805,20 @@ out:
27555
27556 static void jit_free_defer(struct work_struct *arg)
27557 {
27558 - module_free(NULL, arg);
27559 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27560 + kfree(arg);
27561 }
27562
27563 /* run from softirq, we must use a work_struct to call
27564 - * module_free() from process context
27565 + * module_free_exec() from process context
27566 */
27567 void bpf_jit_free(struct sk_filter *fp)
27568 {
27569 if (fp->bpf_func != sk_run_filter) {
27570 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
27571 + struct work_struct *work = &fp->work->work;
27572
27573 INIT_WORK(work, jit_free_defer);
27574 + fp->work->image = fp->bpf_func;
27575 schedule_work(work);
27576 }
27577 }
27578 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27579 index d6aa6e8..266395a 100644
27580 --- a/arch/x86/oprofile/backtrace.c
27581 +++ b/arch/x86/oprofile/backtrace.c
27582 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27583 struct stack_frame_ia32 *fp;
27584 unsigned long bytes;
27585
27586 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27587 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27588 if (bytes != sizeof(bufhead))
27589 return NULL;
27590
27591 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27592 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27593
27594 oprofile_add_trace(bufhead[0].return_address);
27595
27596 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27597 struct stack_frame bufhead[2];
27598 unsigned long bytes;
27599
27600 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27601 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27602 if (bytes != sizeof(bufhead))
27603 return NULL;
27604
27605 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27606 {
27607 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27608
27609 - if (!user_mode_vm(regs)) {
27610 + if (!user_mode(regs)) {
27611 unsigned long stack = kernel_stack_pointer(regs);
27612 if (depth)
27613 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27614 diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
27615 index 192397c..5ba6f9e 100644
27616 --- a/arch/x86/pci/acpi.c
27617 +++ b/arch/x86/pci/acpi.c
27618 @@ -568,7 +568,7 @@ int __init pci_acpi_init(void)
27619 acpi_irq_penalty_init();
27620 pcibios_enable_irq = acpi_pci_irq_enable;
27621 pcibios_disable_irq = acpi_pci_irq_disable;
27622 - x86_init.pci.init_irq = x86_init_noop;
27623 + *(void **)&x86_init.pci.init_irq = x86_init_noop;
27624
27625 if (pci_routeirq) {
27626 /*
27627 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27628 index e14a2ff..3fd6b58 100644
27629 --- a/arch/x86/pci/mrst.c
27630 +++ b/arch/x86/pci/mrst.c
27631 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27632 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27633 pci_mmcfg_late_init();
27634 pcibios_enable_irq = mrst_pci_irq_enable;
27635 - pci_root_ops = pci_mrst_ops;
27636 + pax_open_kernel();
27637 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27638 + pax_close_kernel();
27639 pci_soc_mode = 1;
27640 /* Continue with standard init */
27641 return 1;
27642 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27643 index da8fe05..7ee6704 100644
27644 --- a/arch/x86/pci/pcbios.c
27645 +++ b/arch/x86/pci/pcbios.c
27646 @@ -79,50 +79,93 @@ union bios32 {
27647 static struct {
27648 unsigned long address;
27649 unsigned short segment;
27650 -} bios32_indirect = { 0, __KERNEL_CS };
27651 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27652
27653 /*
27654 * Returns the entry point for the given service, NULL on error
27655 */
27656
27657 -static unsigned long bios32_service(unsigned long service)
27658 +static unsigned long __devinit bios32_service(unsigned long service)
27659 {
27660 unsigned char return_code; /* %al */
27661 unsigned long address; /* %ebx */
27662 unsigned long length; /* %ecx */
27663 unsigned long entry; /* %edx */
27664 unsigned long flags;
27665 + struct desc_struct d, *gdt;
27666
27667 local_irq_save(flags);
27668 - __asm__("lcall *(%%edi); cld"
27669 +
27670 + gdt = get_cpu_gdt_table(smp_processor_id());
27671 +
27672 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
27673 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27674 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
27675 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27676 +
27677 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
27678 : "=a" (return_code),
27679 "=b" (address),
27680 "=c" (length),
27681 "=d" (entry)
27682 : "0" (service),
27683 "1" (0),
27684 - "D" (&bios32_indirect));
27685 + "D" (&bios32_indirect),
27686 + "r"(__PCIBIOS_DS)
27687 + : "memory");
27688 +
27689 + pax_open_kernel();
27690 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
27691 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
27692 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
27693 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
27694 + pax_close_kernel();
27695 +
27696 local_irq_restore(flags);
27697
27698 switch (return_code) {
27699 - case 0:
27700 - return address + entry;
27701 - case 0x80: /* Not present */
27702 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
27703 - return 0;
27704 - default: /* Shouldn't happen */
27705 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
27706 - service, return_code);
27707 + case 0: {
27708 + int cpu;
27709 + unsigned char flags;
27710 +
27711 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
27712 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
27713 + printk(KERN_WARNING "bios32_service: not valid\n");
27714 return 0;
27715 + }
27716 + address = address + PAGE_OFFSET;
27717 + length += 16UL; /* some BIOSs underreport this... */
27718 + flags = 4;
27719 + if (length >= 64*1024*1024) {
27720 + length >>= PAGE_SHIFT;
27721 + flags |= 8;
27722 + }
27723 +
27724 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27725 + gdt = get_cpu_gdt_table(cpu);
27726 + pack_descriptor(&d, address, length, 0x9b, flags);
27727 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27728 + pack_descriptor(&d, address, length, 0x93, flags);
27729 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27730 + }
27731 + return entry;
27732 + }
27733 + case 0x80: /* Not present */
27734 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
27735 + return 0;
27736 + default: /* Shouldn't happen */
27737 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
27738 + service, return_code);
27739 + return 0;
27740 }
27741 }
27742
27743 static struct {
27744 unsigned long address;
27745 unsigned short segment;
27746 -} pci_indirect = { 0, __KERNEL_CS };
27747 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
27748
27749 -static int pci_bios_present;
27750 +static int pci_bios_present __read_only;
27751
27752 static int __devinit check_pcibios(void)
27753 {
27754 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
27755 unsigned long flags, pcibios_entry;
27756
27757 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
27758 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
27759 + pci_indirect.address = pcibios_entry;
27760
27761 local_irq_save(flags);
27762 - __asm__(
27763 - "lcall *(%%edi); cld\n\t"
27764 + __asm__("movw %w6, %%ds\n\t"
27765 + "lcall *%%ss:(%%edi); cld\n\t"
27766 + "push %%ss\n\t"
27767 + "pop %%ds\n\t"
27768 "jc 1f\n\t"
27769 "xor %%ah, %%ah\n"
27770 "1:"
27771 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
27772 "=b" (ebx),
27773 "=c" (ecx)
27774 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
27775 - "D" (&pci_indirect)
27776 + "D" (&pci_indirect),
27777 + "r" (__PCIBIOS_DS)
27778 : "memory");
27779 local_irq_restore(flags);
27780
27781 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27782
27783 switch (len) {
27784 case 1:
27785 - __asm__("lcall *(%%esi); cld\n\t"
27786 + __asm__("movw %w6, %%ds\n\t"
27787 + "lcall *%%ss:(%%esi); cld\n\t"
27788 + "push %%ss\n\t"
27789 + "pop %%ds\n\t"
27790 "jc 1f\n\t"
27791 "xor %%ah, %%ah\n"
27792 "1:"
27793 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27794 : "1" (PCIBIOS_READ_CONFIG_BYTE),
27795 "b" (bx),
27796 "D" ((long)reg),
27797 - "S" (&pci_indirect));
27798 + "S" (&pci_indirect),
27799 + "r" (__PCIBIOS_DS));
27800 /*
27801 * Zero-extend the result beyond 8 bits, do not trust the
27802 * BIOS having done it:
27803 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27804 *value &= 0xff;
27805 break;
27806 case 2:
27807 - __asm__("lcall *(%%esi); cld\n\t"
27808 + __asm__("movw %w6, %%ds\n\t"
27809 + "lcall *%%ss:(%%esi); cld\n\t"
27810 + "push %%ss\n\t"
27811 + "pop %%ds\n\t"
27812 "jc 1f\n\t"
27813 "xor %%ah, %%ah\n"
27814 "1:"
27815 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27816 : "1" (PCIBIOS_READ_CONFIG_WORD),
27817 "b" (bx),
27818 "D" ((long)reg),
27819 - "S" (&pci_indirect));
27820 + "S" (&pci_indirect),
27821 + "r" (__PCIBIOS_DS));
27822 /*
27823 * Zero-extend the result beyond 16 bits, do not trust the
27824 * BIOS having done it:
27825 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27826 *value &= 0xffff;
27827 break;
27828 case 4:
27829 - __asm__("lcall *(%%esi); cld\n\t"
27830 + __asm__("movw %w6, %%ds\n\t"
27831 + "lcall *%%ss:(%%esi); cld\n\t"
27832 + "push %%ss\n\t"
27833 + "pop %%ds\n\t"
27834 "jc 1f\n\t"
27835 "xor %%ah, %%ah\n"
27836 "1:"
27837 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
27838 : "1" (PCIBIOS_READ_CONFIG_DWORD),
27839 "b" (bx),
27840 "D" ((long)reg),
27841 - "S" (&pci_indirect));
27842 + "S" (&pci_indirect),
27843 + "r" (__PCIBIOS_DS));
27844 break;
27845 }
27846
27847 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
27848
27849 switch (len) {
27850 case 1:
27851 - __asm__("lcall *(%%esi); cld\n\t"
27852 + __asm__("movw %w6, %%ds\n\t"
27853 + "lcall *%%ss:(%%esi); cld\n\t"
27854 + "push %%ss\n\t"
27855 + "pop %%ds\n\t"
27856 "jc 1f\n\t"
27857 "xor %%ah, %%ah\n"
27858 "1:"
27859 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
27860 "c" (value),
27861 "b" (bx),
27862 "D" ((long)reg),
27863 - "S" (&pci_indirect));
27864 + "S" (&pci_indirect),
27865 + "r" (__PCIBIOS_DS));
27866 break;
27867 case 2:
27868 - __asm__("lcall *(%%esi); cld\n\t"
27869 + __asm__("movw %w6, %%ds\n\t"
27870 + "lcall *%%ss:(%%esi); cld\n\t"
27871 + "push %%ss\n\t"
27872 + "pop %%ds\n\t"
27873 "jc 1f\n\t"
27874 "xor %%ah, %%ah\n"
27875 "1:"
27876 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
27877 "c" (value),
27878 "b" (bx),
27879 "D" ((long)reg),
27880 - "S" (&pci_indirect));
27881 + "S" (&pci_indirect),
27882 + "r" (__PCIBIOS_DS));
27883 break;
27884 case 4:
27885 - __asm__("lcall *(%%esi); cld\n\t"
27886 + __asm__("movw %w6, %%ds\n\t"
27887 + "lcall *%%ss:(%%esi); cld\n\t"
27888 + "push %%ss\n\t"
27889 + "pop %%ds\n\t"
27890 "jc 1f\n\t"
27891 "xor %%ah, %%ah\n"
27892 "1:"
27893 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
27894 "c" (value),
27895 "b" (bx),
27896 "D" ((long)reg),
27897 - "S" (&pci_indirect));
27898 + "S" (&pci_indirect),
27899 + "r" (__PCIBIOS_DS));
27900 break;
27901 }
27902
27903 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
27904
27905 DBG("PCI: Fetching IRQ routing table... ");
27906 __asm__("push %%es\n\t"
27907 + "movw %w8, %%ds\n\t"
27908 "push %%ds\n\t"
27909 "pop %%es\n\t"
27910 - "lcall *(%%esi); cld\n\t"
27911 + "lcall *%%ss:(%%esi); cld\n\t"
27912 "pop %%es\n\t"
27913 + "push %%ss\n\t"
27914 + "pop %%ds\n"
27915 "jc 1f\n\t"
27916 "xor %%ah, %%ah\n"
27917 "1:"
27918 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
27919 "1" (0),
27920 "D" ((long) &opt),
27921 "S" (&pci_indirect),
27922 - "m" (opt)
27923 + "m" (opt),
27924 + "r" (__PCIBIOS_DS)
27925 : "memory");
27926 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
27927 if (ret & 0xff00)
27928 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
27929 {
27930 int ret;
27931
27932 - __asm__("lcall *(%%esi); cld\n\t"
27933 + __asm__("movw %w5, %%ds\n\t"
27934 + "lcall *%%ss:(%%esi); cld\n\t"
27935 + "push %%ss\n\t"
27936 + "pop %%ds\n"
27937 "jc 1f\n\t"
27938 "xor %%ah, %%ah\n"
27939 "1:"
27940 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
27941 : "0" (PCIBIOS_SET_PCI_HW_INT),
27942 "b" ((dev->bus->number << 8) | dev->devfn),
27943 "c" ((irq << 8) | (pin + 10)),
27944 - "S" (&pci_indirect));
27945 + "S" (&pci_indirect),
27946 + "r" (__PCIBIOS_DS));
27947 return !(ret & 0xff00);
27948 }
27949 EXPORT_SYMBOL(pcibios_set_irq_routing);
27950 diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c
27951 index 56ab749..3cb792a 100644
27952 --- a/arch/x86/pci/xen.c
27953 +++ b/arch/x86/pci/xen.c
27954 @@ -395,9 +395,9 @@ int __init pci_xen_init(void)
27955 #endif
27956
27957 #ifdef CONFIG_PCI_MSI
27958 - x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
27959 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
27960 - x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
27961 + *(void **)&x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
27962 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
27963 + *(void **)&x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
27964 #endif
27965 return 0;
27966 }
27967 @@ -416,8 +416,8 @@ int __init pci_xen_hvm_init(void)
27968 #endif
27969
27970 #ifdef CONFIG_PCI_MSI
27971 - x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
27972 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
27973 + *(void **)&x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
27974 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
27975 #endif
27976 return 0;
27977 }
27978 @@ -474,9 +474,9 @@ int __init pci_xen_initial_domain(void)
27979 int irq;
27980
27981 #ifdef CONFIG_PCI_MSI
27982 - x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
27983 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
27984 - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
27985 + *(void **)&x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
27986 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
27987 + *(void **)&x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
27988 #endif
27989 xen_setup_acpi_sci();
27990 __acpi_register_gsi = acpi_register_gsi_xen;
27991 diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
27992 index ad44391..acef4b5 100644
27993 --- a/arch/x86/platform/efi/efi.c
27994 +++ b/arch/x86/platform/efi/efi.c
27995 @@ -738,8 +738,8 @@ void __init efi_init(void)
27996 }
27997 #ifdef CONFIG_X86_32
27998 if (efi_is_native()) {
27999 - x86_platform.get_wallclock = efi_get_time;
28000 - x86_platform.set_wallclock = efi_set_rtc_mmss;
28001 + *(void **)&x86_platform.get_wallclock = efi_get_time;
28002 + *(void **)&x86_platform.set_wallclock = efi_set_rtc_mmss;
28003 }
28004 #endif
28005
28006 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28007 index 40e4469..1ab536e 100644
28008 --- a/arch/x86/platform/efi/efi_32.c
28009 +++ b/arch/x86/platform/efi/efi_32.c
28010 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28011 {
28012 struct desc_ptr gdt_descr;
28013
28014 +#ifdef CONFIG_PAX_KERNEXEC
28015 + struct desc_struct d;
28016 +#endif
28017 +
28018 local_irq_save(efi_rt_eflags);
28019
28020 load_cr3(initial_page_table);
28021 __flush_tlb_all();
28022
28023 +#ifdef CONFIG_PAX_KERNEXEC
28024 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28025 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28026 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28027 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28028 +#endif
28029 +
28030 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28031 gdt_descr.size = GDT_SIZE - 1;
28032 load_gdt(&gdt_descr);
28033 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28034 {
28035 struct desc_ptr gdt_descr;
28036
28037 +#ifdef CONFIG_PAX_KERNEXEC
28038 + struct desc_struct d;
28039 +
28040 + memset(&d, 0, sizeof d);
28041 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28042 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28043 +#endif
28044 +
28045 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28046 gdt_descr.size = GDT_SIZE - 1;
28047 load_gdt(&gdt_descr);
28048 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28049 index fbe66e6..eae5e38 100644
28050 --- a/arch/x86/platform/efi/efi_stub_32.S
28051 +++ b/arch/x86/platform/efi/efi_stub_32.S
28052 @@ -6,7 +6,9 @@
28053 */
28054
28055 #include <linux/linkage.h>
28056 +#include <linux/init.h>
28057 #include <asm/page_types.h>
28058 +#include <asm/segment.h>
28059
28060 /*
28061 * efi_call_phys(void *, ...) is a function with variable parameters.
28062 @@ -20,7 +22,7 @@
28063 * service functions will comply with gcc calling convention, too.
28064 */
28065
28066 -.text
28067 +__INIT
28068 ENTRY(efi_call_phys)
28069 /*
28070 * 0. The function can only be called in Linux kernel. So CS has been
28071 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28072 * The mapping of lower virtual memory has been created in prelog and
28073 * epilog.
28074 */
28075 - movl $1f, %edx
28076 - subl $__PAGE_OFFSET, %edx
28077 - jmp *%edx
28078 +#ifdef CONFIG_PAX_KERNEXEC
28079 + movl $(__KERNEXEC_EFI_DS), %edx
28080 + mov %edx, %ds
28081 + mov %edx, %es
28082 + mov %edx, %ss
28083 + addl $2f,(1f)
28084 + ljmp *(1f)
28085 +
28086 +__INITDATA
28087 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28088 +.previous
28089 +
28090 +2:
28091 + subl $2b,(1b)
28092 +#else
28093 + jmp 1f-__PAGE_OFFSET
28094 1:
28095 +#endif
28096
28097 /*
28098 * 2. Now on the top of stack is the return
28099 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28100 * parameter 2, ..., param n. To make things easy, we save the return
28101 * address of efi_call_phys in a global variable.
28102 */
28103 - popl %edx
28104 - movl %edx, saved_return_addr
28105 - /* get the function pointer into ECX*/
28106 - popl %ecx
28107 - movl %ecx, efi_rt_function_ptr
28108 - movl $2f, %edx
28109 - subl $__PAGE_OFFSET, %edx
28110 - pushl %edx
28111 + popl (saved_return_addr)
28112 + popl (efi_rt_function_ptr)
28113
28114 /*
28115 * 3. Clear PG bit in %CR0.
28116 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28117 /*
28118 * 5. Call the physical function.
28119 */
28120 - jmp *%ecx
28121 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
28122
28123 -2:
28124 /*
28125 * 6. After EFI runtime service returns, control will return to
28126 * following instruction. We'd better readjust stack pointer first.
28127 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28128 movl %cr0, %edx
28129 orl $0x80000000, %edx
28130 movl %edx, %cr0
28131 - jmp 1f
28132 -1:
28133 +
28134 /*
28135 * 8. Now restore the virtual mode from flat mode by
28136 * adding EIP with PAGE_OFFSET.
28137 */
28138 - movl $1f, %edx
28139 - jmp *%edx
28140 +#ifdef CONFIG_PAX_KERNEXEC
28141 + movl $(__KERNEL_DS), %edx
28142 + mov %edx, %ds
28143 + mov %edx, %es
28144 + mov %edx, %ss
28145 + ljmp $(__KERNEL_CS),$1f
28146 +#else
28147 + jmp 1f+__PAGE_OFFSET
28148 +#endif
28149 1:
28150
28151 /*
28152 * 9. Balance the stack. And because EAX contain the return value,
28153 * we'd better not clobber it.
28154 */
28155 - leal efi_rt_function_ptr, %edx
28156 - movl (%edx), %ecx
28157 - pushl %ecx
28158 + pushl (efi_rt_function_ptr)
28159
28160 /*
28161 - * 10. Push the saved return address onto the stack and return.
28162 + * 10. Return to the saved return address.
28163 */
28164 - leal saved_return_addr, %edx
28165 - movl (%edx), %ecx
28166 - pushl %ecx
28167 - ret
28168 + jmpl *(saved_return_addr)
28169 ENDPROC(efi_call_phys)
28170 .previous
28171
28172 -.data
28173 +__INITDATA
28174 saved_return_addr:
28175 .long 0
28176 efi_rt_function_ptr:
28177 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28178 index 4c07cca..2c8427d 100644
28179 --- a/arch/x86/platform/efi/efi_stub_64.S
28180 +++ b/arch/x86/platform/efi/efi_stub_64.S
28181 @@ -7,6 +7,7 @@
28182 */
28183
28184 #include <linux/linkage.h>
28185 +#include <asm/alternative-asm.h>
28186
28187 #define SAVE_XMM \
28188 mov %rsp, %rax; \
28189 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
28190 call *%rdi
28191 addq $32, %rsp
28192 RESTORE_XMM
28193 + pax_force_retaddr 0, 1
28194 ret
28195 ENDPROC(efi_call0)
28196
28197 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
28198 call *%rdi
28199 addq $32, %rsp
28200 RESTORE_XMM
28201 + pax_force_retaddr 0, 1
28202 ret
28203 ENDPROC(efi_call1)
28204
28205 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
28206 call *%rdi
28207 addq $32, %rsp
28208 RESTORE_XMM
28209 + pax_force_retaddr 0, 1
28210 ret
28211 ENDPROC(efi_call2)
28212
28213 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
28214 call *%rdi
28215 addq $32, %rsp
28216 RESTORE_XMM
28217 + pax_force_retaddr 0, 1
28218 ret
28219 ENDPROC(efi_call3)
28220
28221 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
28222 call *%rdi
28223 addq $32, %rsp
28224 RESTORE_XMM
28225 + pax_force_retaddr 0, 1
28226 ret
28227 ENDPROC(efi_call4)
28228
28229 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
28230 call *%rdi
28231 addq $48, %rsp
28232 RESTORE_XMM
28233 + pax_force_retaddr 0, 1
28234 ret
28235 ENDPROC(efi_call5)
28236
28237 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
28238 call *%rdi
28239 addq $48, %rsp
28240 RESTORE_XMM
28241 + pax_force_retaddr 0, 1
28242 ret
28243 ENDPROC(efi_call6)
28244 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28245 index fd41a92..bc8091d 100644
28246 --- a/arch/x86/platform/mrst/mrst.c
28247 +++ b/arch/x86/platform/mrst/mrst.c
28248 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28249 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28250 int sfi_mrtc_num;
28251
28252 -static void mrst_power_off(void)
28253 +static __noreturn void mrst_power_off(void)
28254 {
28255 + BUG();
28256 }
28257
28258 -static void mrst_reboot(void)
28259 +static __noreturn void mrst_reboot(void)
28260 {
28261 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28262 + BUG();
28263 }
28264
28265 /* parse all the mtimer info to a static mtimer array */
28266 @@ -233,14 +235,14 @@ static void __init mrst_time_init(void)
28267 case MRST_TIMER_APBT_ONLY:
28268 break;
28269 case MRST_TIMER_LAPIC_APBT:
28270 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28271 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28272 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28273 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28274 break;
28275 default:
28276 if (!boot_cpu_has(X86_FEATURE_ARAT))
28277 break;
28278 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28279 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28280 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28281 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28282 return;
28283 }
28284 /* we need at least one APB timer */
28285 @@ -282,35 +284,35 @@ static unsigned char mrst_get_nmi_reason(void)
28286 */
28287 void __init x86_mrst_early_setup(void)
28288 {
28289 - x86_init.resources.probe_roms = x86_init_noop;
28290 - x86_init.resources.reserve_resources = x86_init_noop;
28291 + *(void **)&x86_init.resources.probe_roms = x86_init_noop;
28292 + *(void **)&x86_init.resources.reserve_resources = x86_init_noop;
28293
28294 - x86_init.timers.timer_init = mrst_time_init;
28295 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
28296 + *(void **)&x86_init.timers.timer_init = mrst_time_init;
28297 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
28298
28299 - x86_init.irqs.pre_vector_init = x86_init_noop;
28300 + *(void **)&x86_init.irqs.pre_vector_init = x86_init_noop;
28301
28302 - x86_init.oem.arch_setup = mrst_arch_setup;
28303 + *(void **)&x86_init.oem.arch_setup = mrst_arch_setup;
28304
28305 - x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28306 + *(void **)&x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28307
28308 - x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28309 - x86_platform.i8042_detect = mrst_i8042_detect;
28310 - x86_init.timers.wallclock_init = mrst_rtc_init;
28311 - x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28312 + *(void **)&x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28313 + *(void **)&x86_platform.i8042_detect = mrst_i8042_detect;
28314 + *(void **)&x86_init.timers.wallclock_init = mrst_rtc_init;
28315 + *(void **)&x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28316
28317 - x86_init.pci.init = pci_mrst_init;
28318 - x86_init.pci.fixup_irqs = x86_init_noop;
28319 + *(void **)&x86_init.pci.init = pci_mrst_init;
28320 + *(void **)&x86_init.pci.fixup_irqs = x86_init_noop;
28321
28322 legacy_pic = &null_legacy_pic;
28323
28324 /* Moorestown specific power_off/restart method */
28325 pm_power_off = mrst_power_off;
28326 - machine_ops.emergency_restart = mrst_reboot;
28327 + *(void **)&machine_ops.emergency_restart = mrst_reboot;
28328
28329 /* Avoid searching for BIOS MP tables */
28330 - x86_init.mpparse.find_smp_config = x86_init_noop;
28331 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28332 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
28333 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28334 set_bit(MP_BUS_ISA, mp_bus_not_pci);
28335 }
28336
28337 diff --git a/arch/x86/platform/mrst/vrtc.c b/arch/x86/platform/mrst/vrtc.c
28338 index 225bd0f..22e8086 100644
28339 --- a/arch/x86/platform/mrst/vrtc.c
28340 +++ b/arch/x86/platform/mrst/vrtc.c
28341 @@ -120,8 +120,8 @@ void __init mrst_rtc_init(void)
28342
28343 vrtc_virt_base = (void __iomem *)set_fixmap_offset_nocache(FIX_LNW_VRTC,
28344 vrtc_paddr);
28345 - x86_platform.get_wallclock = vrtc_get_time;
28346 - x86_platform.set_wallclock = vrtc_set_mmss;
28347 + *(void **)&x86_platform.get_wallclock = vrtc_get_time;
28348 + *(void **)&x86_platform.set_wallclock = vrtc_set_mmss;
28349 }
28350
28351 /*
28352 diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
28353 index 2737608..0d62cc2 100644
28354 --- a/arch/x86/platform/olpc/olpc.c
28355 +++ b/arch/x86/platform/olpc/olpc.c
28356 @@ -395,7 +395,7 @@ static int __init olpc_init(void)
28357 * XO-1 only. */
28358 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) &&
28359 !cs5535_has_vsa2())
28360 - x86_init.pci.arch_init = pci_olpc_init;
28361 + *(void **)&x86_init.pci.arch_init = pci_olpc_init;
28362 #endif
28363
28364 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */
28365 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28366 index d6ee929..3637cb5 100644
28367 --- a/arch/x86/platform/olpc/olpc_dt.c
28368 +++ b/arch/x86/platform/olpc/olpc_dt.c
28369 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28370 return res;
28371 }
28372
28373 -static struct of_pdt_ops prom_olpc_ops __initdata = {
28374 +static struct of_pdt_ops prom_olpc_ops __initconst = {
28375 .nextprop = olpc_dt_nextprop,
28376 .getproplen = olpc_dt_getproplen,
28377 .getproperty = olpc_dt_getproperty,
28378 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28379 index 218cdb1..c1178eb 100644
28380 --- a/arch/x86/power/cpu.c
28381 +++ b/arch/x86/power/cpu.c
28382 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
28383 static void fix_processor_context(void)
28384 {
28385 int cpu = smp_processor_id();
28386 - struct tss_struct *t = &per_cpu(init_tss, cpu);
28387 + struct tss_struct *t = init_tss + cpu;
28388
28389 set_tss_desc(cpu, t); /*
28390 * This just modifies memory; should not be
28391 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
28392 */
28393
28394 #ifdef CONFIG_X86_64
28395 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28396 -
28397 syscall_init(); /* This sets MSR_*STAR and related */
28398 #endif
28399 load_TR_desc(); /* This does ltr */
28400 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28401 index cbca565..bae7133 100644
28402 --- a/arch/x86/realmode/init.c
28403 +++ b/arch/x86/realmode/init.c
28404 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28405 __va(real_mode_header->trampoline_header);
28406
28407 #ifdef CONFIG_X86_32
28408 - trampoline_header->start = __pa(startup_32_smp);
28409 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28410 +
28411 +#ifdef CONFIG_PAX_KERNEXEC
28412 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28413 +#endif
28414 +
28415 + trampoline_header->boot_cs = __BOOT_CS;
28416 trampoline_header->gdt_limit = __BOOT_DS + 7;
28417 trampoline_header->gdt_base = __pa(boot_gdt);
28418 #else
28419 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28420 index 8869287..d577672 100644
28421 --- a/arch/x86/realmode/rm/Makefile
28422 +++ b/arch/x86/realmode/rm/Makefile
28423 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28424 $(call cc-option, -fno-unit-at-a-time)) \
28425 $(call cc-option, -fno-stack-protector) \
28426 $(call cc-option, -mpreferred-stack-boundary=2)
28427 +ifdef CONSTIFY_PLUGIN
28428 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28429 +endif
28430 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28431 GCOV_PROFILE := n
28432 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28433 index a28221d..93c40f1 100644
28434 --- a/arch/x86/realmode/rm/header.S
28435 +++ b/arch/x86/realmode/rm/header.S
28436 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28437 #endif
28438 /* APM/BIOS reboot */
28439 .long pa_machine_real_restart_asm
28440 -#ifdef CONFIG_X86_64
28441 +#ifdef CONFIG_X86_32
28442 + .long __KERNEL_CS
28443 +#else
28444 .long __KERNEL32_CS
28445 #endif
28446 END(real_mode_header)
28447 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28448 index c1b2791..f9e31c7 100644
28449 --- a/arch/x86/realmode/rm/trampoline_32.S
28450 +++ b/arch/x86/realmode/rm/trampoline_32.S
28451 @@ -25,6 +25,12 @@
28452 #include <asm/page_types.h>
28453 #include "realmode.h"
28454
28455 +#ifdef CONFIG_PAX_KERNEXEC
28456 +#define ta(X) (X)
28457 +#else
28458 +#define ta(X) (pa_ ## X)
28459 +#endif
28460 +
28461 .text
28462 .code16
28463
28464 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28465
28466 cli # We should be safe anyway
28467
28468 - movl tr_start, %eax # where we need to go
28469 -
28470 movl $0xA5A5A5A5, trampoline_status
28471 # write marker for master knows we're running
28472
28473 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28474 movw $1, %dx # protected mode (PE) bit
28475 lmsw %dx # into protected mode
28476
28477 - ljmpl $__BOOT_CS, $pa_startup_32
28478 + ljmpl *(trampoline_header)
28479
28480 .section ".text32","ax"
28481 .code32
28482 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28483 .balign 8
28484 GLOBAL(trampoline_header)
28485 tr_start: .space 4
28486 - tr_gdt_pad: .space 2
28487 + tr_boot_cs: .space 2
28488 tr_gdt: .space 6
28489 END(trampoline_header)
28490
28491 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28492 index bb360dc..3e5945f 100644
28493 --- a/arch/x86/realmode/rm/trampoline_64.S
28494 +++ b/arch/x86/realmode/rm/trampoline_64.S
28495 @@ -107,7 +107,7 @@ ENTRY(startup_32)
28496 wrmsr
28497
28498 # Enable paging and in turn activate Long Mode
28499 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28500 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
28501 movl %eax, %cr0
28502
28503 /*
28504 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28505 index 5a1847d..deccb30 100644
28506 --- a/arch/x86/tools/relocs.c
28507 +++ b/arch/x86/tools/relocs.c
28508 @@ -12,10 +12,13 @@
28509 #include <regex.h>
28510 #include <tools/le_byteshift.h>
28511
28512 +#include "../../../include/generated/autoconf.h"
28513 +
28514 static void die(char *fmt, ...);
28515
28516 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28517 static Elf32_Ehdr ehdr;
28518 +static Elf32_Phdr *phdr;
28519 static unsigned long reloc_count, reloc_idx;
28520 static unsigned long *relocs;
28521 static unsigned long reloc16_count, reloc16_idx;
28522 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28523 }
28524 }
28525
28526 +static void read_phdrs(FILE *fp)
28527 +{
28528 + unsigned int i;
28529 +
28530 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28531 + if (!phdr) {
28532 + die("Unable to allocate %d program headers\n",
28533 + ehdr.e_phnum);
28534 + }
28535 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28536 + die("Seek to %d failed: %s\n",
28537 + ehdr.e_phoff, strerror(errno));
28538 + }
28539 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28540 + die("Cannot read ELF program headers: %s\n",
28541 + strerror(errno));
28542 + }
28543 + for(i = 0; i < ehdr.e_phnum; i++) {
28544 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28545 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28546 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28547 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28548 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28549 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28550 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28551 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28552 + }
28553 +
28554 +}
28555 +
28556 static void read_shdrs(FILE *fp)
28557 {
28558 - int i;
28559 + unsigned int i;
28560 Elf32_Shdr shdr;
28561
28562 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28563 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28564
28565 static void read_strtabs(FILE *fp)
28566 {
28567 - int i;
28568 + unsigned int i;
28569 for (i = 0; i < ehdr.e_shnum; i++) {
28570 struct section *sec = &secs[i];
28571 if (sec->shdr.sh_type != SHT_STRTAB) {
28572 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28573
28574 static void read_symtabs(FILE *fp)
28575 {
28576 - int i,j;
28577 + unsigned int i,j;
28578 for (i = 0; i < ehdr.e_shnum; i++) {
28579 struct section *sec = &secs[i];
28580 if (sec->shdr.sh_type != SHT_SYMTAB) {
28581 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28582 }
28583
28584
28585 -static void read_relocs(FILE *fp)
28586 +static void read_relocs(FILE *fp, int use_real_mode)
28587 {
28588 - int i,j;
28589 + unsigned int i,j;
28590 + uint32_t base;
28591 +
28592 for (i = 0; i < ehdr.e_shnum; i++) {
28593 struct section *sec = &secs[i];
28594 if (sec->shdr.sh_type != SHT_REL) {
28595 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28596 die("Cannot read symbol table: %s\n",
28597 strerror(errno));
28598 }
28599 + base = 0;
28600 +
28601 +#ifdef CONFIG_X86_32
28602 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28603 + if (phdr[j].p_type != PT_LOAD )
28604 + continue;
28605 + 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)
28606 + continue;
28607 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28608 + break;
28609 + }
28610 +#endif
28611 +
28612 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28613 Elf32_Rel *rel = &sec->reltab[j];
28614 - rel->r_offset = elf32_to_cpu(rel->r_offset);
28615 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28616 rel->r_info = elf32_to_cpu(rel->r_info);
28617 }
28618 }
28619 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28620
28621 static void print_absolute_symbols(void)
28622 {
28623 - int i;
28624 + unsigned int i;
28625 printf("Absolute symbols\n");
28626 printf(" Num: Value Size Type Bind Visibility Name\n");
28627 for (i = 0; i < ehdr.e_shnum; i++) {
28628 struct section *sec = &secs[i];
28629 char *sym_strtab;
28630 - int j;
28631 + unsigned int j;
28632
28633 if (sec->shdr.sh_type != SHT_SYMTAB) {
28634 continue;
28635 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28636
28637 static void print_absolute_relocs(void)
28638 {
28639 - int i, printed = 0;
28640 + unsigned int i, printed = 0;
28641
28642 for (i = 0; i < ehdr.e_shnum; i++) {
28643 struct section *sec = &secs[i];
28644 struct section *sec_applies, *sec_symtab;
28645 char *sym_strtab;
28646 Elf32_Sym *sh_symtab;
28647 - int j;
28648 + unsigned int j;
28649 if (sec->shdr.sh_type != SHT_REL) {
28650 continue;
28651 }
28652 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28653 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28654 int use_real_mode)
28655 {
28656 - int i;
28657 + unsigned int i;
28658 /* Walk through the relocations */
28659 for (i = 0; i < ehdr.e_shnum; i++) {
28660 char *sym_strtab;
28661 Elf32_Sym *sh_symtab;
28662 struct section *sec_applies, *sec_symtab;
28663 - int j;
28664 + unsigned int j;
28665 struct section *sec = &secs[i];
28666
28667 if (sec->shdr.sh_type != SHT_REL) {
28668 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28669 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
28670 r_type = ELF32_R_TYPE(rel->r_info);
28671
28672 + if (!use_real_mode) {
28673 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
28674 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
28675 + continue;
28676 +
28677 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
28678 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
28679 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
28680 + continue;
28681 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
28682 + continue;
28683 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
28684 + continue;
28685 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
28686 + continue;
28687 +#endif
28688 + }
28689 +
28690 shn_abs = sym->st_shndx == SHN_ABS;
28691
28692 switch (r_type) {
28693 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
28694
28695 static void emit_relocs(int as_text, int use_real_mode)
28696 {
28697 - int i;
28698 + unsigned int i;
28699 /* Count how many relocations I have and allocate space for them. */
28700 reloc_count = 0;
28701 walk_relocs(count_reloc, use_real_mode);
28702 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
28703 fname, strerror(errno));
28704 }
28705 read_ehdr(fp);
28706 + read_phdrs(fp);
28707 read_shdrs(fp);
28708 read_strtabs(fp);
28709 read_symtabs(fp);
28710 - read_relocs(fp);
28711 + read_relocs(fp, use_real_mode);
28712 if (show_absolute_syms) {
28713 print_absolute_symbols();
28714 return 0;
28715 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
28716 index fd14be1..e3c79c0 100644
28717 --- a/arch/x86/vdso/Makefile
28718 +++ b/arch/x86/vdso/Makefile
28719 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
28720 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
28721 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
28722
28723 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28724 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28725 GCOV_PROFILE := n
28726
28727 #
28728 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
28729 index 0faad64..39ef157 100644
28730 --- a/arch/x86/vdso/vdso32-setup.c
28731 +++ b/arch/x86/vdso/vdso32-setup.c
28732 @@ -25,6 +25,7 @@
28733 #include <asm/tlbflush.h>
28734 #include <asm/vdso.h>
28735 #include <asm/proto.h>
28736 +#include <asm/mman.h>
28737
28738 enum {
28739 VDSO_DISABLED = 0,
28740 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
28741 void enable_sep_cpu(void)
28742 {
28743 int cpu = get_cpu();
28744 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
28745 + struct tss_struct *tss = init_tss + cpu;
28746
28747 if (!boot_cpu_has(X86_FEATURE_SEP)) {
28748 put_cpu();
28749 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
28750 gate_vma.vm_start = FIXADDR_USER_START;
28751 gate_vma.vm_end = FIXADDR_USER_END;
28752 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
28753 - gate_vma.vm_page_prot = __P101;
28754 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
28755
28756 return 0;
28757 }
28758 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28759 if (compat)
28760 addr = VDSO_HIGH_BASE;
28761 else {
28762 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
28763 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
28764 if (IS_ERR_VALUE(addr)) {
28765 ret = addr;
28766 goto up_fail;
28767 }
28768 }
28769
28770 - current->mm->context.vdso = (void *)addr;
28771 + current->mm->context.vdso = addr;
28772
28773 if (compat_uses_vma || !compat) {
28774 /*
28775 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28776 }
28777
28778 current_thread_info()->sysenter_return =
28779 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
28780 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
28781
28782 up_fail:
28783 if (ret)
28784 - current->mm->context.vdso = NULL;
28785 + current->mm->context.vdso = 0;
28786
28787 up_write(&mm->mmap_sem);
28788
28789 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
28790
28791 const char *arch_vma_name(struct vm_area_struct *vma)
28792 {
28793 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28794 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28795 return "[vdso]";
28796 +
28797 +#ifdef CONFIG_PAX_SEGMEXEC
28798 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
28799 + return "[vdso]";
28800 +#endif
28801 +
28802 return NULL;
28803 }
28804
28805 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28806 * Check to see if the corresponding task was created in compat vdso
28807 * mode.
28808 */
28809 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
28810 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
28811 return &gate_vma;
28812 return NULL;
28813 }
28814 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
28815 index 00aaf04..4a26505 100644
28816 --- a/arch/x86/vdso/vma.c
28817 +++ b/arch/x86/vdso/vma.c
28818 @@ -16,8 +16,6 @@
28819 #include <asm/vdso.h>
28820 #include <asm/page.h>
28821
28822 -unsigned int __read_mostly vdso_enabled = 1;
28823 -
28824 extern char vdso_start[], vdso_end[];
28825 extern unsigned short vdso_sync_cpuid;
28826
28827 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
28828 * unaligned here as a result of stack start randomization.
28829 */
28830 addr = PAGE_ALIGN(addr);
28831 - addr = align_addr(addr, NULL, ALIGN_VDSO);
28832
28833 return addr;
28834 }
28835 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
28836 unsigned size)
28837 {
28838 struct mm_struct *mm = current->mm;
28839 - unsigned long addr;
28840 + unsigned long addr = 0;
28841 int ret;
28842
28843 - if (!vdso_enabled)
28844 - return 0;
28845 -
28846 down_write(&mm->mmap_sem);
28847 +
28848 +#ifdef CONFIG_PAX_RANDMMAP
28849 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28850 +#endif
28851 +
28852 addr = vdso_addr(mm->start_stack, size);
28853 + addr = align_addr(addr, NULL, ALIGN_VDSO);
28854 addr = get_unmapped_area(NULL, addr, size, 0, 0);
28855 if (IS_ERR_VALUE(addr)) {
28856 ret = addr;
28857 goto up_fail;
28858 }
28859
28860 - current->mm->context.vdso = (void *)addr;
28861 + mm->context.vdso = addr;
28862
28863 ret = install_special_mapping(mm, addr, size,
28864 VM_READ|VM_EXEC|
28865 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
28866 pages);
28867 - if (ret) {
28868 - current->mm->context.vdso = NULL;
28869 - goto up_fail;
28870 - }
28871 + if (ret)
28872 + mm->context.vdso = 0;
28873
28874 up_fail:
28875 up_write(&mm->mmap_sem);
28876 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28877 vdsox32_size);
28878 }
28879 #endif
28880 -
28881 -static __init int vdso_setup(char *s)
28882 -{
28883 - vdso_enabled = simple_strtoul(s, NULL, 0);
28884 - return 0;
28885 -}
28886 -__setup("vdso=", vdso_setup);
28887 diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c
28888 index 7005ced..530d6eb 100644
28889 --- a/arch/x86/xen/apic.c
28890 +++ b/arch/x86/xen/apic.c
28891 @@ -30,5 +30,5 @@ static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
28892
28893 void __init xen_init_apic(void)
28894 {
28895 - x86_io_apic_ops.read = xen_io_apic_read;
28896 + *(void **)&x86_io_apic_ops.read = xen_io_apic_read;
28897 }
28898 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
28899 index 586d838..a973e1c 100644
28900 --- a/arch/x86/xen/enlighten.c
28901 +++ b/arch/x86/xen/enlighten.c
28902 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
28903
28904 struct shared_info xen_dummy_shared_info;
28905
28906 -void *xen_initial_gdt;
28907 -
28908 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
28909 __read_mostly int xen_have_vector_callback;
28910 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
28911 @@ -918,21 +916,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
28912
28913 static void set_xen_basic_apic_ops(void)
28914 {
28915 - apic->read = xen_apic_read;
28916 - apic->write = xen_apic_write;
28917 - apic->icr_read = xen_apic_icr_read;
28918 - apic->icr_write = xen_apic_icr_write;
28919 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
28920 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
28921 - apic->set_apic_id = xen_set_apic_id;
28922 - apic->get_apic_id = xen_get_apic_id;
28923 + *(void **)&apic->read = xen_apic_read;
28924 + *(void **)&apic->write = xen_apic_write;
28925 + *(void **)&apic->icr_read = xen_apic_icr_read;
28926 + *(void **)&apic->icr_write = xen_apic_icr_write;
28927 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
28928 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
28929 + *(void **)&apic->set_apic_id = xen_set_apic_id;
28930 + *(void **)&apic->get_apic_id = xen_get_apic_id;
28931
28932 #ifdef CONFIG_SMP
28933 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
28934 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
28935 - apic->send_IPI_mask = xen_send_IPI_mask;
28936 - apic->send_IPI_all = xen_send_IPI_all;
28937 - apic->send_IPI_self = xen_send_IPI_self;
28938 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
28939 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
28940 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
28941 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
28942 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
28943 #endif
28944 }
28945
28946 @@ -1222,30 +1220,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
28947 #endif
28948 };
28949
28950 -static void xen_reboot(int reason)
28951 +static __noreturn void xen_reboot(int reason)
28952 {
28953 struct sched_shutdown r = { .reason = reason };
28954
28955 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
28956 - BUG();
28957 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
28958 + BUG();
28959 }
28960
28961 -static void xen_restart(char *msg)
28962 +static __noreturn void xen_restart(char *msg)
28963 {
28964 xen_reboot(SHUTDOWN_reboot);
28965 }
28966
28967 -static void xen_emergency_restart(void)
28968 +static __noreturn void xen_emergency_restart(void)
28969 {
28970 xen_reboot(SHUTDOWN_reboot);
28971 }
28972
28973 -static void xen_machine_halt(void)
28974 +static __noreturn void xen_machine_halt(void)
28975 {
28976 xen_reboot(SHUTDOWN_poweroff);
28977 }
28978
28979 -static void xen_machine_power_off(void)
28980 +static __noreturn void xen_machine_power_off(void)
28981 {
28982 if (pm_power_off)
28983 pm_power_off();
28984 @@ -1290,14 +1288,14 @@ static const struct machine_ops xen_machine_ops __initconst = {
28985 */
28986 static void __init xen_setup_stackprotector(void)
28987 {
28988 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
28989 - pv_cpu_ops.load_gdt = xen_load_gdt_boot;
28990 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
28991 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt_boot;
28992
28993 setup_stack_canary_segment(0);
28994 switch_to_new_gdt(0);
28995
28996 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
28997 - pv_cpu_ops.load_gdt = xen_load_gdt;
28998 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
28999 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt;
29000 }
29001
29002 /* First C function to be called on Xen boot */
29003 @@ -1315,13 +1313,13 @@ asmlinkage void __init xen_start_kernel(void)
29004
29005 /* Install Xen paravirt ops */
29006 pv_info = xen_info;
29007 - pv_init_ops = xen_init_ops;
29008 - pv_cpu_ops = xen_cpu_ops;
29009 - pv_apic_ops = xen_apic_ops;
29010 + memcpy((void *)&pv_init_ops, &xen_init_ops, sizeof pv_init_ops);
29011 + memcpy((void *)&pv_cpu_ops, &xen_cpu_ops, sizeof pv_cpu_ops);
29012 + memcpy((void *)&pv_apic_ops, &xen_apic_ops, sizeof pv_apic_ops);
29013
29014 - x86_init.resources.memory_setup = xen_memory_setup;
29015 - x86_init.oem.arch_setup = xen_arch_setup;
29016 - x86_init.oem.banner = xen_banner;
29017 + *(void **)&x86_init.resources.memory_setup = xen_memory_setup;
29018 + *(void **)&x86_init.oem.arch_setup = xen_arch_setup;
29019 + *(void **)&x86_init.oem.banner = xen_banner;
29020
29021 xen_init_time_ops();
29022
29023 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
29024 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29025
29026 /* Work out if we support NX */
29027 - x86_configure_nx();
29028 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29029 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29030 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29031 + unsigned l, h;
29032 +
29033 + __supported_pte_mask |= _PAGE_NX;
29034 + rdmsr(MSR_EFER, l, h);
29035 + l |= EFER_NX;
29036 + wrmsr(MSR_EFER, l, h);
29037 + }
29038 +#endif
29039
29040 xen_setup_features();
29041
29042 @@ -1376,14 +1384,7 @@ asmlinkage void __init xen_start_kernel(void)
29043 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29044 }
29045
29046 - machine_ops = xen_machine_ops;
29047 -
29048 - /*
29049 - * The only reliable way to retain the initial address of the
29050 - * percpu gdt_page is to remember it here, so we can go and
29051 - * mark it RW later, when the initial percpu area is freed.
29052 - */
29053 - xen_initial_gdt = &per_cpu(gdt_page, 0);
29054 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29055
29056 xen_smp_init();
29057
29058 @@ -1450,7 +1451,7 @@ asmlinkage void __init xen_start_kernel(void)
29059 add_preferred_console("tty", 0, NULL);
29060 add_preferred_console("hvc", 0, NULL);
29061 if (pci_xen)
29062 - x86_init.pci.arch_init = pci_xen_init;
29063 + *(void **)&x86_init.pci.arch_init = pci_xen_init;
29064 } else {
29065 const struct dom0_vga_console_info *info =
29066 (void *)((char *)xen_start_info +
29067 @@ -1476,8 +1477,8 @@ asmlinkage void __init xen_start_kernel(void)
29068 xen_acpi_sleep_register();
29069
29070 /* Avoid searching for BIOS MP tables */
29071 - x86_init.mpparse.find_smp_config = x86_init_noop;
29072 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29073 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
29074 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29075 }
29076 #ifdef CONFIG_PCI
29077 /* PCI BIOS service won't work from a PV guest. */
29078 @@ -1583,7 +1584,7 @@ static void __init xen_hvm_guest_init(void)
29079 xen_hvm_smp_init();
29080 register_cpu_notifier(&xen_hvm_cpu_notifier);
29081 xen_unplug_emulated_devices();
29082 - x86_init.irqs.intr_init = xen_init_IRQ;
29083 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29084 xen_hvm_init_time_ops();
29085 xen_hvm_init_mmu_ops();
29086 }
29087 diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c
29088 index 01a4dc0..3ca0cc9 100644
29089 --- a/arch/x86/xen/irq.c
29090 +++ b/arch/x86/xen/irq.c
29091 @@ -130,5 +130,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {
29092 void __init xen_init_irq_ops(void)
29093 {
29094 pv_irq_ops = xen_irq_ops;
29095 - x86_init.irqs.intr_init = xen_init_IRQ;
29096 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29097 }
29098 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29099 index dcf5f2d..5f72fe7 100644
29100 --- a/arch/x86/xen/mmu.c
29101 +++ b/arch/x86/xen/mmu.c
29102 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29103 /* L3_k[510] -> level2_kernel_pgt
29104 * L3_i[511] -> level2_fixmap_pgt */
29105 convert_pfn_mfn(level3_kernel_pgt);
29106 + convert_pfn_mfn(level3_vmalloc_start_pgt);
29107 + convert_pfn_mfn(level3_vmalloc_end_pgt);
29108 + convert_pfn_mfn(level3_vmemmap_pgt);
29109
29110 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29111 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29112 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29113 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29114 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29115 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29116 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29117 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29118 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29119 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29120 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29121 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29122 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29123 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29124
29125 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29126 pv_mmu_ops.set_pud = xen_set_pud;
29127 #if PAGETABLE_LEVELS == 4
29128 pv_mmu_ops.set_pgd = xen_set_pgd;
29129 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29130 #endif
29131
29132 /* This will work as long as patching hasn't happened yet
29133 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29134 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29135 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29136 .set_pgd = xen_set_pgd_hyper,
29137 + .set_pgd_batched = xen_set_pgd_hyper,
29138
29139 .alloc_pud = xen_alloc_pmd_init,
29140 .release_pud = xen_release_pmd_init,
29141 @@ -2197,8 +2206,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29142
29143 void __init xen_init_mmu_ops(void)
29144 {
29145 - x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29146 - x86_init.paging.pagetable_init = xen_pagetable_init;
29147 + *(void **)&x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29148 + *(void **)&x86_init.paging.pagetable_init = xen_pagetable_init;
29149 pv_mmu_ops = xen_mmu_ops;
29150
29151 memset(dummy_mapping, 0xff, PAGE_SIZE);
29152 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29153 index 353c50f..a0b9b0d 100644
29154 --- a/arch/x86/xen/smp.c
29155 +++ b/arch/x86/xen/smp.c
29156 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29157 {
29158 BUG_ON(smp_processor_id() != 0);
29159 native_smp_prepare_boot_cpu();
29160 -
29161 - /* We've switched to the "real" per-cpu gdt, so make sure the
29162 - old memory can be recycled */
29163 - make_lowmem_page_readwrite(xen_initial_gdt);
29164 -
29165 xen_filter_cpu_maps();
29166 xen_setup_vcpu_info_placement();
29167 }
29168 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29169 gdt = get_cpu_gdt_table(cpu);
29170
29171 ctxt->flags = VGCF_IN_KERNEL;
29172 - ctxt->user_regs.ds = __USER_DS;
29173 - ctxt->user_regs.es = __USER_DS;
29174 + ctxt->user_regs.ds = __KERNEL_DS;
29175 + ctxt->user_regs.es = __KERNEL_DS;
29176 ctxt->user_regs.ss = __KERNEL_DS;
29177 #ifdef CONFIG_X86_32
29178 ctxt->user_regs.fs = __KERNEL_PERCPU;
29179 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29180 + savesegment(gs, ctxt->user_regs.gs);
29181 #else
29182 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29183 #endif
29184 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29185 int rc;
29186
29187 per_cpu(current_task, cpu) = idle;
29188 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
29189 #ifdef CONFIG_X86_32
29190 irq_ctx_init(cpu);
29191 #else
29192 clear_tsk_thread_flag(idle, TIF_FORK);
29193 - per_cpu(kernel_stack, cpu) =
29194 - (unsigned long)task_stack_page(idle) -
29195 - KERNEL_STACK_OFFSET + THREAD_SIZE;
29196 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29197 #endif
29198 xen_setup_runstate_info(cpu);
29199 xen_setup_timer(cpu);
29200 @@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29201
29202 void __init xen_smp_init(void)
29203 {
29204 - smp_ops = xen_smp_ops;
29205 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29206 xen_fill_possible_map();
29207 xen_init_spinlocks();
29208 }
29209 @@ -672,10 +666,10 @@ void __init xen_hvm_smp_init(void)
29210 {
29211 if (!xen_have_vector_callback)
29212 return;
29213 - smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29214 - smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29215 - smp_ops.cpu_up = xen_hvm_cpu_up;
29216 - smp_ops.cpu_die = xen_hvm_cpu_die;
29217 - smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29218 - smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29219 + *(void **)&smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29220 + *(void **)&smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29221 + *(void **)&smp_ops.cpu_up = xen_hvm_cpu_up;
29222 + *(void **)&smp_ops.cpu_die = xen_hvm_cpu_die;
29223 + *(void **)&smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29224 + *(void **)&smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29225 }
29226 diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
29227 index 83e866d..ef60385 100644
29228 --- a/arch/x86/xen/spinlock.c
29229 +++ b/arch/x86/xen/spinlock.c
29230 @@ -390,12 +390,12 @@ void __init xen_init_spinlocks(void)
29231 {
29232 BUILD_BUG_ON(sizeof(struct xen_spinlock) > sizeof(arch_spinlock_t));
29233
29234 - pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29235 - pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29236 - pv_lock_ops.spin_lock = xen_spin_lock;
29237 - pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29238 - pv_lock_ops.spin_trylock = xen_spin_trylock;
29239 - pv_lock_ops.spin_unlock = xen_spin_unlock;
29240 + *(void **)&pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29241 + *(void **)&pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29242 + *(void **)&pv_lock_ops.spin_lock = xen_spin_lock;
29243 + *(void **)&pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29244 + *(void **)&pv_lock_ops.spin_trylock = xen_spin_trylock;
29245 + *(void **)&pv_lock_ops.spin_unlock = xen_spin_unlock;
29246 }
29247
29248 #ifdef CONFIG_XEN_DEBUG_FS
29249 diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
29250 index 0296a95..3c51a2d 100644
29251 --- a/arch/x86/xen/time.c
29252 +++ b/arch/x86/xen/time.c
29253 @@ -481,15 +481,15 @@ static void __init xen_time_init(void)
29254
29255 void __init xen_init_time_ops(void)
29256 {
29257 - pv_time_ops = xen_time_ops;
29258 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29259
29260 - x86_init.timers.timer_init = xen_time_init;
29261 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
29262 - x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29263 + *(void **)&x86_init.timers.timer_init = xen_time_init;
29264 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
29265 + *(void **)&x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29266
29267 - x86_platform.calibrate_tsc = xen_tsc_khz;
29268 - x86_platform.get_wallclock = xen_get_wallclock;
29269 - x86_platform.set_wallclock = xen_set_wallclock;
29270 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29271 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29272 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29273 }
29274
29275 #ifdef CONFIG_XEN_PVHVM
29276 @@ -514,12 +514,12 @@ void __init xen_hvm_init_time_ops(void)
29277 return;
29278 }
29279
29280 - pv_time_ops = xen_time_ops;
29281 - x86_init.timers.setup_percpu_clockev = xen_time_init;
29282 - x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29283 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29284 + *(void **)&x86_init.timers.setup_percpu_clockev = xen_time_init;
29285 + *(void **)&x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29286
29287 - x86_platform.calibrate_tsc = xen_tsc_khz;
29288 - x86_platform.get_wallclock = xen_get_wallclock;
29289 - x86_platform.set_wallclock = xen_set_wallclock;
29290 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29291 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29292 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29293 }
29294 #endif
29295 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29296 index f9643fc..602e8af 100644
29297 --- a/arch/x86/xen/xen-asm_32.S
29298 +++ b/arch/x86/xen/xen-asm_32.S
29299 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
29300 ESP_OFFSET=4 # bytes pushed onto stack
29301
29302 /*
29303 - * Store vcpu_info pointer for easy access. Do it this way to
29304 - * avoid having to reload %fs
29305 + * Store vcpu_info pointer for easy access.
29306 */
29307 #ifdef CONFIG_SMP
29308 - GET_THREAD_INFO(%eax)
29309 - movl TI_cpu(%eax), %eax
29310 - movl __per_cpu_offset(,%eax,4), %eax
29311 - mov xen_vcpu(%eax), %eax
29312 + push %fs
29313 + mov $(__KERNEL_PERCPU), %eax
29314 + mov %eax, %fs
29315 + mov PER_CPU_VAR(xen_vcpu), %eax
29316 + pop %fs
29317 #else
29318 movl xen_vcpu, %eax
29319 #endif
29320 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29321 index 7faed58..ba4427c 100644
29322 --- a/arch/x86/xen/xen-head.S
29323 +++ b/arch/x86/xen/xen-head.S
29324 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
29325 #ifdef CONFIG_X86_32
29326 mov %esi,xen_start_info
29327 mov $init_thread_union+THREAD_SIZE,%esp
29328 +#ifdef CONFIG_SMP
29329 + movl $cpu_gdt_table,%edi
29330 + movl $__per_cpu_load,%eax
29331 + movw %ax,__KERNEL_PERCPU + 2(%edi)
29332 + rorl $16,%eax
29333 + movb %al,__KERNEL_PERCPU + 4(%edi)
29334 + movb %ah,__KERNEL_PERCPU + 7(%edi)
29335 + movl $__per_cpu_end - 1,%eax
29336 + subl $__per_cpu_start,%eax
29337 + movw %ax,__KERNEL_PERCPU + 0(%edi)
29338 +#endif
29339 #else
29340 mov %rsi,xen_start_info
29341 mov $init_thread_union+THREAD_SIZE,%rsp
29342 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29343 index a95b417..b6dbd0b 100644
29344 --- a/arch/x86/xen/xen-ops.h
29345 +++ b/arch/x86/xen/xen-ops.h
29346 @@ -10,8 +10,6 @@
29347 extern const char xen_hypervisor_callback[];
29348 extern const char xen_failsafe_callback[];
29349
29350 -extern void *xen_initial_gdt;
29351 -
29352 struct trap_info;
29353 void xen_copy_trap_info(struct trap_info *traps);
29354
29355 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29356 index 525bd3d..ef888b1 100644
29357 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
29358 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29359 @@ -119,9 +119,9 @@
29360 ----------------------------------------------------------------------*/
29361
29362 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29363 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29364 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29365 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
29366 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29367
29368 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
29369 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29370 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29371 index 2f33760..835e50a 100644
29372 --- a/arch/xtensa/variants/fsf/include/variant/core.h
29373 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
29374 @@ -11,6 +11,7 @@
29375 #ifndef _XTENSA_CORE_H
29376 #define _XTENSA_CORE_H
29377
29378 +#include <linux/const.h>
29379
29380 /****************************************************************************
29381 Parameters Useful for Any Code, USER or PRIVILEGED
29382 @@ -112,9 +113,9 @@
29383 ----------------------------------------------------------------------*/
29384
29385 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29386 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29387 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29388 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29389 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29390
29391 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29392 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29393 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29394 index af00795..2bb8105 100644
29395 --- a/arch/xtensa/variants/s6000/include/variant/core.h
29396 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
29397 @@ -11,6 +11,7 @@
29398 #ifndef _XTENSA_CORE_CONFIGURATION_H
29399 #define _XTENSA_CORE_CONFIGURATION_H
29400
29401 +#include <linux/const.h>
29402
29403 /****************************************************************************
29404 Parameters Useful for Any Code, USER or PRIVILEGED
29405 @@ -118,9 +119,9 @@
29406 ----------------------------------------------------------------------*/
29407
29408 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29409 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29410 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29411 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29412 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29413
29414 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29415 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29416 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29417 index 58916af..9cb880b 100644
29418 --- a/block/blk-iopoll.c
29419 +++ b/block/blk-iopoll.c
29420 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29421 }
29422 EXPORT_SYMBOL(blk_iopoll_complete);
29423
29424 -static void blk_iopoll_softirq(struct softirq_action *h)
29425 +static void blk_iopoll_softirq(void)
29426 {
29427 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29428 int rearm = 0, budget = blk_iopoll_budget;
29429 diff --git a/block/blk-map.c b/block/blk-map.c
29430 index 623e1cd..ca1e109 100644
29431 --- a/block/blk-map.c
29432 +++ b/block/blk-map.c
29433 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29434 if (!len || !kbuf)
29435 return -EINVAL;
29436
29437 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29438 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29439 if (do_copy)
29440 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29441 else
29442 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29443 index 467c8de..4bddc6d 100644
29444 --- a/block/blk-softirq.c
29445 +++ b/block/blk-softirq.c
29446 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29447 * Softirq action handler - move entries to local list and loop over them
29448 * while passing them to the queue registered handler.
29449 */
29450 -static void blk_done_softirq(struct softirq_action *h)
29451 +static void blk_done_softirq(void)
29452 {
29453 struct list_head *cpu_list, local_list;
29454
29455 diff --git a/block/bsg.c b/block/bsg.c
29456 index ff64ae3..593560c 100644
29457 --- a/block/bsg.c
29458 +++ b/block/bsg.c
29459 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29460 struct sg_io_v4 *hdr, struct bsg_device *bd,
29461 fmode_t has_write_perm)
29462 {
29463 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29464 + unsigned char *cmdptr;
29465 +
29466 if (hdr->request_len > BLK_MAX_CDB) {
29467 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29468 if (!rq->cmd)
29469 return -ENOMEM;
29470 - }
29471 + cmdptr = rq->cmd;
29472 + } else
29473 + cmdptr = tmpcmd;
29474
29475 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29476 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29477 hdr->request_len))
29478 return -EFAULT;
29479
29480 + if (cmdptr != rq->cmd)
29481 + memcpy(rq->cmd, cmdptr, hdr->request_len);
29482 +
29483 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29484 if (blk_verify_command(rq->cmd, has_write_perm))
29485 return -EPERM;
29486 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29487 index 7c668c8..db3521c 100644
29488 --- a/block/compat_ioctl.c
29489 +++ b/block/compat_ioctl.c
29490 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29491 err |= __get_user(f->spec1, &uf->spec1);
29492 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29493 err |= __get_user(name, &uf->name);
29494 - f->name = compat_ptr(name);
29495 + f->name = (void __force_kernel *)compat_ptr(name);
29496 if (err) {
29497 err = -EFAULT;
29498 goto out;
29499 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29500 index 6296b40..417c00f 100644
29501 --- a/block/partitions/efi.c
29502 +++ b/block/partitions/efi.c
29503 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29504 if (!gpt)
29505 return NULL;
29506
29507 + if (!le32_to_cpu(gpt->num_partition_entries))
29508 + return NULL;
29509 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29510 + if (!pte)
29511 + return NULL;
29512 +
29513 count = le32_to_cpu(gpt->num_partition_entries) *
29514 le32_to_cpu(gpt->sizeof_partition_entry);
29515 - if (!count)
29516 - return NULL;
29517 - pte = kzalloc(count, GFP_KERNEL);
29518 - if (!pte)
29519 - return NULL;
29520 -
29521 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29522 (u8 *) pte,
29523 count) < count) {
29524 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29525 index 9a87daa..fb17486 100644
29526 --- a/block/scsi_ioctl.c
29527 +++ b/block/scsi_ioctl.c
29528 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29529 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29530 struct sg_io_hdr *hdr, fmode_t mode)
29531 {
29532 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29533 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29534 + unsigned char *cmdptr;
29535 +
29536 + if (rq->cmd != rq->__cmd)
29537 + cmdptr = rq->cmd;
29538 + else
29539 + cmdptr = tmpcmd;
29540 +
29541 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29542 return -EFAULT;
29543 +
29544 + if (cmdptr != rq->cmd)
29545 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29546 +
29547 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29548 return -EPERM;
29549
29550 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29551 int err;
29552 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29553 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29554 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29555 + unsigned char *cmdptr;
29556
29557 if (!sic)
29558 return -EINVAL;
29559 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29560 */
29561 err = -EFAULT;
29562 rq->cmd_len = cmdlen;
29563 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
29564 +
29565 + if (rq->cmd != rq->__cmd)
29566 + cmdptr = rq->cmd;
29567 + else
29568 + cmdptr = tmpcmd;
29569 +
29570 + if (copy_from_user(cmdptr, sic->data, cmdlen))
29571 goto error;
29572
29573 + if (rq->cmd != cmdptr)
29574 + memcpy(rq->cmd, cmdptr, cmdlen);
29575 +
29576 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29577 goto error;
29578
29579 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29580 index 7bdd61b..afec999 100644
29581 --- a/crypto/cryptd.c
29582 +++ b/crypto/cryptd.c
29583 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29584
29585 struct cryptd_blkcipher_request_ctx {
29586 crypto_completion_t complete;
29587 -};
29588 +} __no_const;
29589
29590 struct cryptd_hash_ctx {
29591 struct crypto_shash *child;
29592 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29593
29594 struct cryptd_aead_request_ctx {
29595 crypto_completion_t complete;
29596 -};
29597 +} __no_const;
29598
29599 static void cryptd_queue_worker(struct work_struct *work);
29600
29601 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29602 index e6defd8..c26a225 100644
29603 --- a/drivers/acpi/apei/cper.c
29604 +++ b/drivers/acpi/apei/cper.c
29605 @@ -38,12 +38,12 @@
29606 */
29607 u64 cper_next_record_id(void)
29608 {
29609 - static atomic64_t seq;
29610 + static atomic64_unchecked_t seq;
29611
29612 - if (!atomic64_read(&seq))
29613 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
29614 + if (!atomic64_read_unchecked(&seq))
29615 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29616
29617 - return atomic64_inc_return(&seq);
29618 + return atomic64_inc_return_unchecked(&seq);
29619 }
29620 EXPORT_SYMBOL_GPL(cper_next_record_id);
29621
29622 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29623 index 7586544..636a2f0 100644
29624 --- a/drivers/acpi/ec_sys.c
29625 +++ b/drivers/acpi/ec_sys.c
29626 @@ -12,6 +12,7 @@
29627 #include <linux/acpi.h>
29628 #include <linux/debugfs.h>
29629 #include <linux/module.h>
29630 +#include <linux/uaccess.h>
29631 #include "internal.h"
29632
29633 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29634 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29635 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29636 */
29637 unsigned int size = EC_SPACE_SIZE;
29638 - u8 *data = (u8 *) buf;
29639 + u8 data;
29640 loff_t init_off = *off;
29641 int err = 0;
29642
29643 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29644 size = count;
29645
29646 while (size) {
29647 - err = ec_read(*off, &data[*off - init_off]);
29648 + err = ec_read(*off, &data);
29649 if (err)
29650 return err;
29651 + if (put_user(data, &buf[*off - init_off]))
29652 + return -EFAULT;
29653 *off += 1;
29654 size--;
29655 }
29656 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29657
29658 unsigned int size = count;
29659 loff_t init_off = *off;
29660 - u8 *data = (u8 *) buf;
29661 int err = 0;
29662
29663 if (*off >= EC_SPACE_SIZE)
29664 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29665 }
29666
29667 while (size) {
29668 - u8 byte_write = data[*off - init_off];
29669 + u8 byte_write;
29670 + if (get_user(byte_write, &buf[*off - init_off]))
29671 + return -EFAULT;
29672 err = ec_write(*off, byte_write);
29673 if (err)
29674 return err;
29675 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
29676 index 27adb09..1ed412d 100644
29677 --- a/drivers/acpi/proc.c
29678 +++ b/drivers/acpi/proc.c
29679 @@ -360,19 +360,13 @@ acpi_system_write_wakeup_device(struct file *file,
29680 size_t count, loff_t * ppos)
29681 {
29682 struct list_head *node, *next;
29683 - char strbuf[5];
29684 - char str[5] = "";
29685 - unsigned int len = count;
29686 + char strbuf[5] = {0};
29687
29688 - if (len > 4)
29689 - len = 4;
29690 - if (len < 0)
29691 + if (count > 4)
29692 + count = 4;
29693 + if (copy_from_user(strbuf, buffer, count))
29694 return -EFAULT;
29695 -
29696 - if (copy_from_user(strbuf, buffer, len))
29697 - return -EFAULT;
29698 - strbuf[len] = '\0';
29699 - sscanf(strbuf, "%s", str);
29700 + strbuf[count] = '\0';
29701
29702 mutex_lock(&acpi_device_lock);
29703 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
29704 @@ -381,7 +375,7 @@ acpi_system_write_wakeup_device(struct file *file,
29705 if (!dev->wakeup.flags.valid)
29706 continue;
29707
29708 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
29709 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
29710 if (device_can_wakeup(&dev->dev)) {
29711 bool enable = !device_may_wakeup(&dev->dev);
29712 device_set_wakeup_enable(&dev->dev, enable);
29713 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
29714 index bd4e5dc..0497b66 100644
29715 --- a/drivers/acpi/processor_driver.c
29716 +++ b/drivers/acpi/processor_driver.c
29717 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
29718 return 0;
29719 #endif
29720
29721 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
29722 + BUG_ON(pr->id >= nr_cpu_ids);
29723
29724 /*
29725 * Buggy BIOS check
29726 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
29727 index 586362e..ca71b9b 100644
29728 --- a/drivers/ata/libata-core.c
29729 +++ b/drivers/ata/libata-core.c
29730 @@ -4775,7 +4775,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
29731 struct ata_port *ap;
29732 unsigned int tag;
29733
29734 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29735 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29736 ap = qc->ap;
29737
29738 qc->flags = 0;
29739 @@ -4791,7 +4791,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
29740 struct ata_port *ap;
29741 struct ata_link *link;
29742
29743 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29744 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29745 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
29746 ap = qc->ap;
29747 link = qc->dev->link;
29748 @@ -5887,6 +5887,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
29749 return;
29750
29751 spin_lock(&lock);
29752 + pax_open_kernel();
29753
29754 for (cur = ops->inherits; cur; cur = cur->inherits) {
29755 void **inherit = (void **)cur;
29756 @@ -5900,8 +5901,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
29757 if (IS_ERR(*pp))
29758 *pp = NULL;
29759
29760 - ops->inherits = NULL;
29761 + *(struct ata_port_operations **)&ops->inherits = NULL;
29762
29763 + pax_close_kernel();
29764 spin_unlock(&lock);
29765 }
29766
29767 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
29768 index 371fd2c..0836c78 100644
29769 --- a/drivers/ata/pata_arasan_cf.c
29770 +++ b/drivers/ata/pata_arasan_cf.c
29771 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
29772 /* Handle platform specific quirks */
29773 if (pdata->quirk) {
29774 if (pdata->quirk & CF_BROKEN_PIO) {
29775 - ap->ops->set_piomode = NULL;
29776 + pax_open_kernel();
29777 + *(void **)&ap->ops->set_piomode = NULL;
29778 + pax_close_kernel();
29779 ap->pio_mask = 0;
29780 }
29781 if (pdata->quirk & CF_BROKEN_MWDMA)
29782 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
29783 index f9b983a..887b9d8 100644
29784 --- a/drivers/atm/adummy.c
29785 +++ b/drivers/atm/adummy.c
29786 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
29787 vcc->pop(vcc, skb);
29788 else
29789 dev_kfree_skb_any(skb);
29790 - atomic_inc(&vcc->stats->tx);
29791 + atomic_inc_unchecked(&vcc->stats->tx);
29792
29793 return 0;
29794 }
29795 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
29796 index ff7bb8a..568fc0b 100644
29797 --- a/drivers/atm/ambassador.c
29798 +++ b/drivers/atm/ambassador.c
29799 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
29800 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
29801
29802 // VC layer stats
29803 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29804 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29805
29806 // free the descriptor
29807 kfree (tx_descr);
29808 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29809 dump_skb ("<<<", vc, skb);
29810
29811 // VC layer stats
29812 - atomic_inc(&atm_vcc->stats->rx);
29813 + atomic_inc_unchecked(&atm_vcc->stats->rx);
29814 __net_timestamp(skb);
29815 // end of our responsibility
29816 atm_vcc->push (atm_vcc, skb);
29817 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29818 } else {
29819 PRINTK (KERN_INFO, "dropped over-size frame");
29820 // should we count this?
29821 - atomic_inc(&atm_vcc->stats->rx_drop);
29822 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29823 }
29824
29825 } else {
29826 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
29827 }
29828
29829 if (check_area (skb->data, skb->len)) {
29830 - atomic_inc(&atm_vcc->stats->tx_err);
29831 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
29832 return -ENOMEM; // ?
29833 }
29834
29835 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
29836 index b22d71c..d6e1049 100644
29837 --- a/drivers/atm/atmtcp.c
29838 +++ b/drivers/atm/atmtcp.c
29839 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29840 if (vcc->pop) vcc->pop(vcc,skb);
29841 else dev_kfree_skb(skb);
29842 if (dev_data) return 0;
29843 - atomic_inc(&vcc->stats->tx_err);
29844 + atomic_inc_unchecked(&vcc->stats->tx_err);
29845 return -ENOLINK;
29846 }
29847 size = skb->len+sizeof(struct atmtcp_hdr);
29848 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29849 if (!new_skb) {
29850 if (vcc->pop) vcc->pop(vcc,skb);
29851 else dev_kfree_skb(skb);
29852 - atomic_inc(&vcc->stats->tx_err);
29853 + atomic_inc_unchecked(&vcc->stats->tx_err);
29854 return -ENOBUFS;
29855 }
29856 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
29857 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29858 if (vcc->pop) vcc->pop(vcc,skb);
29859 else dev_kfree_skb(skb);
29860 out_vcc->push(out_vcc,new_skb);
29861 - atomic_inc(&vcc->stats->tx);
29862 - atomic_inc(&out_vcc->stats->rx);
29863 + atomic_inc_unchecked(&vcc->stats->tx);
29864 + atomic_inc_unchecked(&out_vcc->stats->rx);
29865 return 0;
29866 }
29867
29868 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29869 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
29870 read_unlock(&vcc_sklist_lock);
29871 if (!out_vcc) {
29872 - atomic_inc(&vcc->stats->tx_err);
29873 + atomic_inc_unchecked(&vcc->stats->tx_err);
29874 goto done;
29875 }
29876 skb_pull(skb,sizeof(struct atmtcp_hdr));
29877 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29878 __net_timestamp(new_skb);
29879 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
29880 out_vcc->push(out_vcc,new_skb);
29881 - atomic_inc(&vcc->stats->tx);
29882 - atomic_inc(&out_vcc->stats->rx);
29883 + atomic_inc_unchecked(&vcc->stats->tx);
29884 + atomic_inc_unchecked(&out_vcc->stats->rx);
29885 done:
29886 if (vcc->pop) vcc->pop(vcc,skb);
29887 else dev_kfree_skb(skb);
29888 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
29889 index 81e44f7..498ea36 100644
29890 --- a/drivers/atm/eni.c
29891 +++ b/drivers/atm/eni.c
29892 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
29893 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
29894 vcc->dev->number);
29895 length = 0;
29896 - atomic_inc(&vcc->stats->rx_err);
29897 + atomic_inc_unchecked(&vcc->stats->rx_err);
29898 }
29899 else {
29900 length = ATM_CELL_SIZE-1; /* no HEC */
29901 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29902 size);
29903 }
29904 eff = length = 0;
29905 - atomic_inc(&vcc->stats->rx_err);
29906 + atomic_inc_unchecked(&vcc->stats->rx_err);
29907 }
29908 else {
29909 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
29910 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29911 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
29912 vcc->dev->number,vcc->vci,length,size << 2,descr);
29913 length = eff = 0;
29914 - atomic_inc(&vcc->stats->rx_err);
29915 + atomic_inc_unchecked(&vcc->stats->rx_err);
29916 }
29917 }
29918 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
29919 @@ -767,7 +767,7 @@ rx_dequeued++;
29920 vcc->push(vcc,skb);
29921 pushed++;
29922 }
29923 - atomic_inc(&vcc->stats->rx);
29924 + atomic_inc_unchecked(&vcc->stats->rx);
29925 }
29926 wake_up(&eni_dev->rx_wait);
29927 }
29928 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
29929 PCI_DMA_TODEVICE);
29930 if (vcc->pop) vcc->pop(vcc,skb);
29931 else dev_kfree_skb_irq(skb);
29932 - atomic_inc(&vcc->stats->tx);
29933 + atomic_inc_unchecked(&vcc->stats->tx);
29934 wake_up(&eni_dev->tx_wait);
29935 dma_complete++;
29936 }
29937 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
29938 index 86fed1b..6dc4721 100644
29939 --- a/drivers/atm/firestream.c
29940 +++ b/drivers/atm/firestream.c
29941 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
29942 }
29943 }
29944
29945 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29946 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29947
29948 fs_dprintk (FS_DEBUG_TXMEM, "i");
29949 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
29950 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29951 #endif
29952 skb_put (skb, qe->p1 & 0xffff);
29953 ATM_SKB(skb)->vcc = atm_vcc;
29954 - atomic_inc(&atm_vcc->stats->rx);
29955 + atomic_inc_unchecked(&atm_vcc->stats->rx);
29956 __net_timestamp(skb);
29957 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
29958 atm_vcc->push (atm_vcc, skb);
29959 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29960 kfree (pe);
29961 }
29962 if (atm_vcc)
29963 - atomic_inc(&atm_vcc->stats->rx_drop);
29964 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29965 break;
29966 case 0x1f: /* Reassembly abort: no buffers. */
29967 /* Silently increment error counter. */
29968 if (atm_vcc)
29969 - atomic_inc(&atm_vcc->stats->rx_drop);
29970 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29971 break;
29972 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
29973 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
29974 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
29975 index 361f5ae..7fc552d 100644
29976 --- a/drivers/atm/fore200e.c
29977 +++ b/drivers/atm/fore200e.c
29978 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
29979 #endif
29980 /* check error condition */
29981 if (*entry->status & STATUS_ERROR)
29982 - atomic_inc(&vcc->stats->tx_err);
29983 + atomic_inc_unchecked(&vcc->stats->tx_err);
29984 else
29985 - atomic_inc(&vcc->stats->tx);
29986 + atomic_inc_unchecked(&vcc->stats->tx);
29987 }
29988 }
29989
29990 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29991 if (skb == NULL) {
29992 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
29993
29994 - atomic_inc(&vcc->stats->rx_drop);
29995 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29996 return -ENOMEM;
29997 }
29998
29999 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30000
30001 dev_kfree_skb_any(skb);
30002
30003 - atomic_inc(&vcc->stats->rx_drop);
30004 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30005 return -ENOMEM;
30006 }
30007
30008 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30009
30010 vcc->push(vcc, skb);
30011 - atomic_inc(&vcc->stats->rx);
30012 + atomic_inc_unchecked(&vcc->stats->rx);
30013
30014 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30015
30016 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
30017 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
30018 fore200e->atm_dev->number,
30019 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
30020 - atomic_inc(&vcc->stats->rx_err);
30021 + atomic_inc_unchecked(&vcc->stats->rx_err);
30022 }
30023 }
30024
30025 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
30026 goto retry_here;
30027 }
30028
30029 - atomic_inc(&vcc->stats->tx_err);
30030 + atomic_inc_unchecked(&vcc->stats->tx_err);
30031
30032 fore200e->tx_sat++;
30033 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
30034 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
30035 index b182c2f..1c6fa8a 100644
30036 --- a/drivers/atm/he.c
30037 +++ b/drivers/atm/he.c
30038 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30039
30040 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
30041 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
30042 - atomic_inc(&vcc->stats->rx_drop);
30043 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30044 goto return_host_buffers;
30045 }
30046
30047 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30048 RBRQ_LEN_ERR(he_dev->rbrq_head)
30049 ? "LEN_ERR" : "",
30050 vcc->vpi, vcc->vci);
30051 - atomic_inc(&vcc->stats->rx_err);
30052 + atomic_inc_unchecked(&vcc->stats->rx_err);
30053 goto return_host_buffers;
30054 }
30055
30056 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30057 vcc->push(vcc, skb);
30058 spin_lock(&he_dev->global_lock);
30059
30060 - atomic_inc(&vcc->stats->rx);
30061 + atomic_inc_unchecked(&vcc->stats->rx);
30062
30063 return_host_buffers:
30064 ++pdus_assembled;
30065 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30066 tpd->vcc->pop(tpd->vcc, tpd->skb);
30067 else
30068 dev_kfree_skb_any(tpd->skb);
30069 - atomic_inc(&tpd->vcc->stats->tx_err);
30070 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30071 }
30072 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30073 return;
30074 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30075 vcc->pop(vcc, skb);
30076 else
30077 dev_kfree_skb_any(skb);
30078 - atomic_inc(&vcc->stats->tx_err);
30079 + atomic_inc_unchecked(&vcc->stats->tx_err);
30080 return -EINVAL;
30081 }
30082
30083 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30084 vcc->pop(vcc, skb);
30085 else
30086 dev_kfree_skb_any(skb);
30087 - atomic_inc(&vcc->stats->tx_err);
30088 + atomic_inc_unchecked(&vcc->stats->tx_err);
30089 return -EINVAL;
30090 }
30091 #endif
30092 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30093 vcc->pop(vcc, skb);
30094 else
30095 dev_kfree_skb_any(skb);
30096 - atomic_inc(&vcc->stats->tx_err);
30097 + atomic_inc_unchecked(&vcc->stats->tx_err);
30098 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30099 return -ENOMEM;
30100 }
30101 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30102 vcc->pop(vcc, skb);
30103 else
30104 dev_kfree_skb_any(skb);
30105 - atomic_inc(&vcc->stats->tx_err);
30106 + atomic_inc_unchecked(&vcc->stats->tx_err);
30107 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30108 return -ENOMEM;
30109 }
30110 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30111 __enqueue_tpd(he_dev, tpd, cid);
30112 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30113
30114 - atomic_inc(&vcc->stats->tx);
30115 + atomic_inc_unchecked(&vcc->stats->tx);
30116
30117 return 0;
30118 }
30119 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30120 index 7d01c2a..4e3ac01 100644
30121 --- a/drivers/atm/horizon.c
30122 +++ b/drivers/atm/horizon.c
30123 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30124 {
30125 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30126 // VC layer stats
30127 - atomic_inc(&vcc->stats->rx);
30128 + atomic_inc_unchecked(&vcc->stats->rx);
30129 __net_timestamp(skb);
30130 // end of our responsibility
30131 vcc->push (vcc, skb);
30132 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30133 dev->tx_iovec = NULL;
30134
30135 // VC layer stats
30136 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30137 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30138
30139 // free the skb
30140 hrz_kfree_skb (skb);
30141 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30142 index 8974bd2..b856f85 100644
30143 --- a/drivers/atm/idt77252.c
30144 +++ b/drivers/atm/idt77252.c
30145 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30146 else
30147 dev_kfree_skb(skb);
30148
30149 - atomic_inc(&vcc->stats->tx);
30150 + atomic_inc_unchecked(&vcc->stats->tx);
30151 }
30152
30153 atomic_dec(&scq->used);
30154 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30155 if ((sb = dev_alloc_skb(64)) == NULL) {
30156 printk("%s: Can't allocate buffers for aal0.\n",
30157 card->name);
30158 - atomic_add(i, &vcc->stats->rx_drop);
30159 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30160 break;
30161 }
30162 if (!atm_charge(vcc, sb->truesize)) {
30163 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30164 card->name);
30165 - atomic_add(i - 1, &vcc->stats->rx_drop);
30166 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30167 dev_kfree_skb(sb);
30168 break;
30169 }
30170 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30171 ATM_SKB(sb)->vcc = vcc;
30172 __net_timestamp(sb);
30173 vcc->push(vcc, sb);
30174 - atomic_inc(&vcc->stats->rx);
30175 + atomic_inc_unchecked(&vcc->stats->rx);
30176
30177 cell += ATM_CELL_PAYLOAD;
30178 }
30179 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30180 "(CDC: %08x)\n",
30181 card->name, len, rpp->len, readl(SAR_REG_CDC));
30182 recycle_rx_pool_skb(card, rpp);
30183 - atomic_inc(&vcc->stats->rx_err);
30184 + atomic_inc_unchecked(&vcc->stats->rx_err);
30185 return;
30186 }
30187 if (stat & SAR_RSQE_CRC) {
30188 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30189 recycle_rx_pool_skb(card, rpp);
30190 - atomic_inc(&vcc->stats->rx_err);
30191 + atomic_inc_unchecked(&vcc->stats->rx_err);
30192 return;
30193 }
30194 if (skb_queue_len(&rpp->queue) > 1) {
30195 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30196 RXPRINTK("%s: Can't alloc RX skb.\n",
30197 card->name);
30198 recycle_rx_pool_skb(card, rpp);
30199 - atomic_inc(&vcc->stats->rx_err);
30200 + atomic_inc_unchecked(&vcc->stats->rx_err);
30201 return;
30202 }
30203 if (!atm_charge(vcc, skb->truesize)) {
30204 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30205 __net_timestamp(skb);
30206
30207 vcc->push(vcc, skb);
30208 - atomic_inc(&vcc->stats->rx);
30209 + atomic_inc_unchecked(&vcc->stats->rx);
30210
30211 return;
30212 }
30213 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30214 __net_timestamp(skb);
30215
30216 vcc->push(vcc, skb);
30217 - atomic_inc(&vcc->stats->rx);
30218 + atomic_inc_unchecked(&vcc->stats->rx);
30219
30220 if (skb->truesize > SAR_FB_SIZE_3)
30221 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30222 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30223 if (vcc->qos.aal != ATM_AAL0) {
30224 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30225 card->name, vpi, vci);
30226 - atomic_inc(&vcc->stats->rx_drop);
30227 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30228 goto drop;
30229 }
30230
30231 if ((sb = dev_alloc_skb(64)) == NULL) {
30232 printk("%s: Can't allocate buffers for AAL0.\n",
30233 card->name);
30234 - atomic_inc(&vcc->stats->rx_err);
30235 + atomic_inc_unchecked(&vcc->stats->rx_err);
30236 goto drop;
30237 }
30238
30239 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30240 ATM_SKB(sb)->vcc = vcc;
30241 __net_timestamp(sb);
30242 vcc->push(vcc, sb);
30243 - atomic_inc(&vcc->stats->rx);
30244 + atomic_inc_unchecked(&vcc->stats->rx);
30245
30246 drop:
30247 skb_pull(queue, 64);
30248 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30249
30250 if (vc == NULL) {
30251 printk("%s: NULL connection in send().\n", card->name);
30252 - atomic_inc(&vcc->stats->tx_err);
30253 + atomic_inc_unchecked(&vcc->stats->tx_err);
30254 dev_kfree_skb(skb);
30255 return -EINVAL;
30256 }
30257 if (!test_bit(VCF_TX, &vc->flags)) {
30258 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30259 - atomic_inc(&vcc->stats->tx_err);
30260 + atomic_inc_unchecked(&vcc->stats->tx_err);
30261 dev_kfree_skb(skb);
30262 return -EINVAL;
30263 }
30264 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30265 break;
30266 default:
30267 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30268 - atomic_inc(&vcc->stats->tx_err);
30269 + atomic_inc_unchecked(&vcc->stats->tx_err);
30270 dev_kfree_skb(skb);
30271 return -EINVAL;
30272 }
30273
30274 if (skb_shinfo(skb)->nr_frags != 0) {
30275 printk("%s: No scatter-gather yet.\n", card->name);
30276 - atomic_inc(&vcc->stats->tx_err);
30277 + atomic_inc_unchecked(&vcc->stats->tx_err);
30278 dev_kfree_skb(skb);
30279 return -EINVAL;
30280 }
30281 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30282
30283 err = queue_skb(card, vc, skb, oam);
30284 if (err) {
30285 - atomic_inc(&vcc->stats->tx_err);
30286 + atomic_inc_unchecked(&vcc->stats->tx_err);
30287 dev_kfree_skb(skb);
30288 return err;
30289 }
30290 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30291 skb = dev_alloc_skb(64);
30292 if (!skb) {
30293 printk("%s: Out of memory in send_oam().\n", card->name);
30294 - atomic_inc(&vcc->stats->tx_err);
30295 + atomic_inc_unchecked(&vcc->stats->tx_err);
30296 return -ENOMEM;
30297 }
30298 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30299 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30300 index 96cce6d..62c3ec5 100644
30301 --- a/drivers/atm/iphase.c
30302 +++ b/drivers/atm/iphase.c
30303 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30304 status = (u_short) (buf_desc_ptr->desc_mode);
30305 if (status & (RX_CER | RX_PTE | RX_OFL))
30306 {
30307 - atomic_inc(&vcc->stats->rx_err);
30308 + atomic_inc_unchecked(&vcc->stats->rx_err);
30309 IF_ERR(printk("IA: bad packet, dropping it");)
30310 if (status & RX_CER) {
30311 IF_ERR(printk(" cause: packet CRC error\n");)
30312 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30313 len = dma_addr - buf_addr;
30314 if (len > iadev->rx_buf_sz) {
30315 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30316 - atomic_inc(&vcc->stats->rx_err);
30317 + atomic_inc_unchecked(&vcc->stats->rx_err);
30318 goto out_free_desc;
30319 }
30320
30321 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30322 ia_vcc = INPH_IA_VCC(vcc);
30323 if (ia_vcc == NULL)
30324 {
30325 - atomic_inc(&vcc->stats->rx_err);
30326 + atomic_inc_unchecked(&vcc->stats->rx_err);
30327 atm_return(vcc, skb->truesize);
30328 dev_kfree_skb_any(skb);
30329 goto INCR_DLE;
30330 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30331 if ((length > iadev->rx_buf_sz) || (length >
30332 (skb->len - sizeof(struct cpcs_trailer))))
30333 {
30334 - atomic_inc(&vcc->stats->rx_err);
30335 + atomic_inc_unchecked(&vcc->stats->rx_err);
30336 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30337 length, skb->len);)
30338 atm_return(vcc, skb->truesize);
30339 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30340
30341 IF_RX(printk("rx_dle_intr: skb push");)
30342 vcc->push(vcc,skb);
30343 - atomic_inc(&vcc->stats->rx);
30344 + atomic_inc_unchecked(&vcc->stats->rx);
30345 iadev->rx_pkt_cnt++;
30346 }
30347 INCR_DLE:
30348 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30349 {
30350 struct k_sonet_stats *stats;
30351 stats = &PRIV(_ia_dev[board])->sonet_stats;
30352 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30353 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30354 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30355 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30356 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30357 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30358 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30359 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30360 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30361 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30362 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30363 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30364 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30365 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30366 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30367 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30368 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30369 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30370 }
30371 ia_cmds.status = 0;
30372 break;
30373 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30374 if ((desc == 0) || (desc > iadev->num_tx_desc))
30375 {
30376 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30377 - atomic_inc(&vcc->stats->tx);
30378 + atomic_inc_unchecked(&vcc->stats->tx);
30379 if (vcc->pop)
30380 vcc->pop(vcc, skb);
30381 else
30382 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30383 ATM_DESC(skb) = vcc->vci;
30384 skb_queue_tail(&iadev->tx_dma_q, skb);
30385
30386 - atomic_inc(&vcc->stats->tx);
30387 + atomic_inc_unchecked(&vcc->stats->tx);
30388 iadev->tx_pkt_cnt++;
30389 /* Increment transaction counter */
30390 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30391
30392 #if 0
30393 /* add flow control logic */
30394 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30395 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30396 if (iavcc->vc_desc_cnt > 10) {
30397 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30398 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30399 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30400 index 68c7588..7036683 100644
30401 --- a/drivers/atm/lanai.c
30402 +++ b/drivers/atm/lanai.c
30403 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30404 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30405 lanai_endtx(lanai, lvcc);
30406 lanai_free_skb(lvcc->tx.atmvcc, skb);
30407 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30408 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30409 }
30410
30411 /* Try to fill the buffer - don't call unless there is backlog */
30412 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30413 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30414 __net_timestamp(skb);
30415 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30416 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30417 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30418 out:
30419 lvcc->rx.buf.ptr = end;
30420 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30421 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30422 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30423 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30424 lanai->stats.service_rxnotaal5++;
30425 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30426 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30427 return 0;
30428 }
30429 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30430 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30431 int bytes;
30432 read_unlock(&vcc_sklist_lock);
30433 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30434 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30435 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30436 lvcc->stats.x.aal5.service_trash++;
30437 bytes = (SERVICE_GET_END(s) * 16) -
30438 (((unsigned long) lvcc->rx.buf.ptr) -
30439 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30440 }
30441 if (s & SERVICE_STREAM) {
30442 read_unlock(&vcc_sklist_lock);
30443 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30444 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30445 lvcc->stats.x.aal5.service_stream++;
30446 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30447 "PDU on VCI %d!\n", lanai->number, vci);
30448 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30449 return 0;
30450 }
30451 DPRINTK("got rx crc error on vci %d\n", vci);
30452 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30453 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30454 lvcc->stats.x.aal5.service_rxcrc++;
30455 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30456 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30457 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30458 index 1c70c45..300718d 100644
30459 --- a/drivers/atm/nicstar.c
30460 +++ b/drivers/atm/nicstar.c
30461 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30462 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30463 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30464 card->index);
30465 - atomic_inc(&vcc->stats->tx_err);
30466 + atomic_inc_unchecked(&vcc->stats->tx_err);
30467 dev_kfree_skb_any(skb);
30468 return -EINVAL;
30469 }
30470 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30471 if (!vc->tx) {
30472 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30473 card->index);
30474 - atomic_inc(&vcc->stats->tx_err);
30475 + atomic_inc_unchecked(&vcc->stats->tx_err);
30476 dev_kfree_skb_any(skb);
30477 return -EINVAL;
30478 }
30479 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30480 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30481 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30482 card->index);
30483 - atomic_inc(&vcc->stats->tx_err);
30484 + atomic_inc_unchecked(&vcc->stats->tx_err);
30485 dev_kfree_skb_any(skb);
30486 return -EINVAL;
30487 }
30488
30489 if (skb_shinfo(skb)->nr_frags != 0) {
30490 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30491 - atomic_inc(&vcc->stats->tx_err);
30492 + atomic_inc_unchecked(&vcc->stats->tx_err);
30493 dev_kfree_skb_any(skb);
30494 return -EINVAL;
30495 }
30496 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30497 }
30498
30499 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30500 - atomic_inc(&vcc->stats->tx_err);
30501 + atomic_inc_unchecked(&vcc->stats->tx_err);
30502 dev_kfree_skb_any(skb);
30503 return -EIO;
30504 }
30505 - atomic_inc(&vcc->stats->tx);
30506 + atomic_inc_unchecked(&vcc->stats->tx);
30507
30508 return 0;
30509 }
30510 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30511 printk
30512 ("nicstar%d: Can't allocate buffers for aal0.\n",
30513 card->index);
30514 - atomic_add(i, &vcc->stats->rx_drop);
30515 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30516 break;
30517 }
30518 if (!atm_charge(vcc, sb->truesize)) {
30519 RXPRINTK
30520 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30521 card->index);
30522 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30523 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30524 dev_kfree_skb_any(sb);
30525 break;
30526 }
30527 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30528 ATM_SKB(sb)->vcc = vcc;
30529 __net_timestamp(sb);
30530 vcc->push(vcc, sb);
30531 - atomic_inc(&vcc->stats->rx);
30532 + atomic_inc_unchecked(&vcc->stats->rx);
30533 cell += ATM_CELL_PAYLOAD;
30534 }
30535
30536 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30537 if (iovb == NULL) {
30538 printk("nicstar%d: Out of iovec buffers.\n",
30539 card->index);
30540 - atomic_inc(&vcc->stats->rx_drop);
30541 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30542 recycle_rx_buf(card, skb);
30543 return;
30544 }
30545 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30546 small or large buffer itself. */
30547 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30548 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30549 - atomic_inc(&vcc->stats->rx_err);
30550 + atomic_inc_unchecked(&vcc->stats->rx_err);
30551 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30552 NS_MAX_IOVECS);
30553 NS_PRV_IOVCNT(iovb) = 0;
30554 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30555 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30556 card->index);
30557 which_list(card, skb);
30558 - atomic_inc(&vcc->stats->rx_err);
30559 + atomic_inc_unchecked(&vcc->stats->rx_err);
30560 recycle_rx_buf(card, skb);
30561 vc->rx_iov = NULL;
30562 recycle_iov_buf(card, iovb);
30563 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30564 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30565 card->index);
30566 which_list(card, skb);
30567 - atomic_inc(&vcc->stats->rx_err);
30568 + atomic_inc_unchecked(&vcc->stats->rx_err);
30569 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30570 NS_PRV_IOVCNT(iovb));
30571 vc->rx_iov = NULL;
30572 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30573 printk(" - PDU size mismatch.\n");
30574 else
30575 printk(".\n");
30576 - atomic_inc(&vcc->stats->rx_err);
30577 + atomic_inc_unchecked(&vcc->stats->rx_err);
30578 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30579 NS_PRV_IOVCNT(iovb));
30580 vc->rx_iov = NULL;
30581 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30582 /* skb points to a small buffer */
30583 if (!atm_charge(vcc, skb->truesize)) {
30584 push_rxbufs(card, skb);
30585 - atomic_inc(&vcc->stats->rx_drop);
30586 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30587 } else {
30588 skb_put(skb, len);
30589 dequeue_sm_buf(card, skb);
30590 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30591 ATM_SKB(skb)->vcc = vcc;
30592 __net_timestamp(skb);
30593 vcc->push(vcc, skb);
30594 - atomic_inc(&vcc->stats->rx);
30595 + atomic_inc_unchecked(&vcc->stats->rx);
30596 }
30597 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30598 struct sk_buff *sb;
30599 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30600 if (len <= NS_SMBUFSIZE) {
30601 if (!atm_charge(vcc, sb->truesize)) {
30602 push_rxbufs(card, sb);
30603 - atomic_inc(&vcc->stats->rx_drop);
30604 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30605 } else {
30606 skb_put(sb, len);
30607 dequeue_sm_buf(card, sb);
30608 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30609 ATM_SKB(sb)->vcc = vcc;
30610 __net_timestamp(sb);
30611 vcc->push(vcc, sb);
30612 - atomic_inc(&vcc->stats->rx);
30613 + atomic_inc_unchecked(&vcc->stats->rx);
30614 }
30615
30616 push_rxbufs(card, skb);
30617 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30618
30619 if (!atm_charge(vcc, skb->truesize)) {
30620 push_rxbufs(card, skb);
30621 - atomic_inc(&vcc->stats->rx_drop);
30622 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30623 } else {
30624 dequeue_lg_buf(card, skb);
30625 #ifdef NS_USE_DESTRUCTORS
30626 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30627 ATM_SKB(skb)->vcc = vcc;
30628 __net_timestamp(skb);
30629 vcc->push(vcc, skb);
30630 - atomic_inc(&vcc->stats->rx);
30631 + atomic_inc_unchecked(&vcc->stats->rx);
30632 }
30633
30634 push_rxbufs(card, sb);
30635 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30636 printk
30637 ("nicstar%d: Out of huge buffers.\n",
30638 card->index);
30639 - atomic_inc(&vcc->stats->rx_drop);
30640 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30641 recycle_iovec_rx_bufs(card,
30642 (struct iovec *)
30643 iovb->data,
30644 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30645 card->hbpool.count++;
30646 } else
30647 dev_kfree_skb_any(hb);
30648 - atomic_inc(&vcc->stats->rx_drop);
30649 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30650 } else {
30651 /* Copy the small buffer to the huge buffer */
30652 sb = (struct sk_buff *)iov->iov_base;
30653 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30654 #endif /* NS_USE_DESTRUCTORS */
30655 __net_timestamp(hb);
30656 vcc->push(vcc, hb);
30657 - atomic_inc(&vcc->stats->rx);
30658 + atomic_inc_unchecked(&vcc->stats->rx);
30659 }
30660 }
30661
30662 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30663 index 1853a45..cf2426d 100644
30664 --- a/drivers/atm/solos-pci.c
30665 +++ b/drivers/atm/solos-pci.c
30666 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
30667 }
30668 atm_charge(vcc, skb->truesize);
30669 vcc->push(vcc, skb);
30670 - atomic_inc(&vcc->stats->rx);
30671 + atomic_inc_unchecked(&vcc->stats->rx);
30672 break;
30673
30674 case PKT_STATUS:
30675 @@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30676 vcc = SKB_CB(oldskb)->vcc;
30677
30678 if (vcc) {
30679 - atomic_inc(&vcc->stats->tx);
30680 + atomic_inc_unchecked(&vcc->stats->tx);
30681 solos_pop(vcc, oldskb);
30682 } else
30683 dev_kfree_skb_irq(oldskb);
30684 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30685 index 0215934..ce9f5b1 100644
30686 --- a/drivers/atm/suni.c
30687 +++ b/drivers/atm/suni.c
30688 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30689
30690
30691 #define ADD_LIMITED(s,v) \
30692 - atomic_add((v),&stats->s); \
30693 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30694 + atomic_add_unchecked((v),&stats->s); \
30695 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30696
30697
30698 static void suni_hz(unsigned long from_timer)
30699 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30700 index 5120a96..e2572bd 100644
30701 --- a/drivers/atm/uPD98402.c
30702 +++ b/drivers/atm/uPD98402.c
30703 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30704 struct sonet_stats tmp;
30705 int error = 0;
30706
30707 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30708 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30709 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30710 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30711 if (zero && !error) {
30712 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30713
30714
30715 #define ADD_LIMITED(s,v) \
30716 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30717 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30718 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30719 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30720 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30721 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30722
30723
30724 static void stat_event(struct atm_dev *dev)
30725 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
30726 if (reason & uPD98402_INT_PFM) stat_event(dev);
30727 if (reason & uPD98402_INT_PCO) {
30728 (void) GET(PCOCR); /* clear interrupt cause */
30729 - atomic_add(GET(HECCT),
30730 + atomic_add_unchecked(GET(HECCT),
30731 &PRIV(dev)->sonet_stats.uncorr_hcs);
30732 }
30733 if ((reason & uPD98402_INT_RFO) &&
30734 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
30735 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
30736 uPD98402_INT_LOS),PIMR); /* enable them */
30737 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
30738 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30739 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
30740 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
30741 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30742 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
30743 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
30744 return 0;
30745 }
30746
30747 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
30748 index abe4e20..83c4727 100644
30749 --- a/drivers/atm/zatm.c
30750 +++ b/drivers/atm/zatm.c
30751 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30752 }
30753 if (!size) {
30754 dev_kfree_skb_irq(skb);
30755 - if (vcc) atomic_inc(&vcc->stats->rx_err);
30756 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
30757 continue;
30758 }
30759 if (!atm_charge(vcc,skb->truesize)) {
30760 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30761 skb->len = size;
30762 ATM_SKB(skb)->vcc = vcc;
30763 vcc->push(vcc,skb);
30764 - atomic_inc(&vcc->stats->rx);
30765 + atomic_inc_unchecked(&vcc->stats->rx);
30766 }
30767 zout(pos & 0xffff,MTA(mbx));
30768 #if 0 /* probably a stupid idea */
30769 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
30770 skb_queue_head(&zatm_vcc->backlog,skb);
30771 break;
30772 }
30773 - atomic_inc(&vcc->stats->tx);
30774 + atomic_inc_unchecked(&vcc->stats->tx);
30775 wake_up(&zatm_vcc->tx_wait);
30776 }
30777
30778 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
30779 index 147d1a4..d0fd4b0 100644
30780 --- a/drivers/base/devtmpfs.c
30781 +++ b/drivers/base/devtmpfs.c
30782 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
30783 if (!thread)
30784 return 0;
30785
30786 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
30787 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
30788 if (err)
30789 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
30790 else
30791 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
30792 index e6ee5e8..98ad7fc 100644
30793 --- a/drivers/base/power/wakeup.c
30794 +++ b/drivers/base/power/wakeup.c
30795 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
30796 * They need to be modified together atomically, so it's better to use one
30797 * atomic variable to hold them both.
30798 */
30799 -static atomic_t combined_event_count = ATOMIC_INIT(0);
30800 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
30801
30802 #define IN_PROGRESS_BITS (sizeof(int) * 4)
30803 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
30804
30805 static void split_counters(unsigned int *cnt, unsigned int *inpr)
30806 {
30807 - unsigned int comb = atomic_read(&combined_event_count);
30808 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
30809
30810 *cnt = (comb >> IN_PROGRESS_BITS);
30811 *inpr = comb & MAX_IN_PROGRESS;
30812 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
30813 ws->start_prevent_time = ws->last_time;
30814
30815 /* Increment the counter of events in progress. */
30816 - cec = atomic_inc_return(&combined_event_count);
30817 + cec = atomic_inc_return_unchecked(&combined_event_count);
30818
30819 trace_wakeup_source_activate(ws->name, cec);
30820 }
30821 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
30822 * Increment the counter of registered wakeup events and decrement the
30823 * couter of wakeup events in progress simultaneously.
30824 */
30825 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
30826 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
30827 trace_wakeup_source_deactivate(ws->name, cec);
30828
30829 split_counters(&cnt, &inpr);
30830 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
30831 index ca83f96..69d4ea9 100644
30832 --- a/drivers/block/cciss.c
30833 +++ b/drivers/block/cciss.c
30834 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
30835 int err;
30836 u32 cp;
30837
30838 + memset(&arg64, 0, sizeof(arg64));
30839 +
30840 err = 0;
30841 err |=
30842 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
30843 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
30844 while (!list_empty(&h->reqQ)) {
30845 c = list_entry(h->reqQ.next, CommandList_struct, list);
30846 /* can't do anything if fifo is full */
30847 - if ((h->access.fifo_full(h))) {
30848 + if ((h->access->fifo_full(h))) {
30849 dev_warn(&h->pdev->dev, "fifo full\n");
30850 break;
30851 }
30852 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
30853 h->Qdepth--;
30854
30855 /* Tell the controller execute command */
30856 - h->access.submit_command(h, c);
30857 + h->access->submit_command(h, c);
30858
30859 /* Put job onto the completed Q */
30860 addQ(&h->cmpQ, c);
30861 @@ -3443,17 +3445,17 @@ startio:
30862
30863 static inline unsigned long get_next_completion(ctlr_info_t *h)
30864 {
30865 - return h->access.command_completed(h);
30866 + return h->access->command_completed(h);
30867 }
30868
30869 static inline int interrupt_pending(ctlr_info_t *h)
30870 {
30871 - return h->access.intr_pending(h);
30872 + return h->access->intr_pending(h);
30873 }
30874
30875 static inline long interrupt_not_for_us(ctlr_info_t *h)
30876 {
30877 - return ((h->access.intr_pending(h) == 0) ||
30878 + return ((h->access->intr_pending(h) == 0) ||
30879 (h->interrupts_enabled == 0));
30880 }
30881
30882 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
30883 u32 a;
30884
30885 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
30886 - return h->access.command_completed(h);
30887 + return h->access->command_completed(h);
30888
30889 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
30890 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
30891 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
30892 trans_support & CFGTBL_Trans_use_short_tags);
30893
30894 /* Change the access methods to the performant access methods */
30895 - h->access = SA5_performant_access;
30896 + h->access = &SA5_performant_access;
30897 h->transMethod = CFGTBL_Trans_Performant;
30898
30899 return;
30900 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
30901 if (prod_index < 0)
30902 return -ENODEV;
30903 h->product_name = products[prod_index].product_name;
30904 - h->access = *(products[prod_index].access);
30905 + h->access = products[prod_index].access;
30906
30907 if (cciss_board_disabled(h)) {
30908 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
30909 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
30910 }
30911
30912 /* make sure the board interrupts are off */
30913 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
30914 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
30915 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
30916 if (rc)
30917 goto clean2;
30918 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
30919 * fake ones to scoop up any residual completions.
30920 */
30921 spin_lock_irqsave(&h->lock, flags);
30922 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
30923 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
30924 spin_unlock_irqrestore(&h->lock, flags);
30925 free_irq(h->intr[h->intr_mode], h);
30926 rc = cciss_request_irq(h, cciss_msix_discard_completions,
30927 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
30928 dev_info(&h->pdev->dev, "Board READY.\n");
30929 dev_info(&h->pdev->dev,
30930 "Waiting for stale completions to drain.\n");
30931 - h->access.set_intr_mask(h, CCISS_INTR_ON);
30932 + h->access->set_intr_mask(h, CCISS_INTR_ON);
30933 msleep(10000);
30934 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
30935 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
30936
30937 rc = controller_reset_failed(h->cfgtable);
30938 if (rc)
30939 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
30940 cciss_scsi_setup(h);
30941
30942 /* Turn the interrupts on so we can service requests */
30943 - h->access.set_intr_mask(h, CCISS_INTR_ON);
30944 + h->access->set_intr_mask(h, CCISS_INTR_ON);
30945
30946 /* Get the firmware version */
30947 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
30948 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
30949 kfree(flush_buf);
30950 if (return_code != IO_OK)
30951 dev_warn(&h->pdev->dev, "Error flushing cache\n");
30952 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
30953 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
30954 free_irq(h->intr[h->intr_mode], h);
30955 }
30956
30957 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
30958 index 7fda30e..eb5dfe0 100644
30959 --- a/drivers/block/cciss.h
30960 +++ b/drivers/block/cciss.h
30961 @@ -101,7 +101,7 @@ struct ctlr_info
30962 /* information about each logical volume */
30963 drive_info_struct *drv[CISS_MAX_LUN];
30964
30965 - struct access_method access;
30966 + struct access_method *access;
30967
30968 /* queue and queue Info */
30969 struct list_head reqQ;
30970 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
30971 index 9125bbe..eede5c8 100644
30972 --- a/drivers/block/cpqarray.c
30973 +++ b/drivers/block/cpqarray.c
30974 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30975 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
30976 goto Enomem4;
30977 }
30978 - hba[i]->access.set_intr_mask(hba[i], 0);
30979 + hba[i]->access->set_intr_mask(hba[i], 0);
30980 if (request_irq(hba[i]->intr, do_ida_intr,
30981 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
30982 {
30983 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30984 add_timer(&hba[i]->timer);
30985
30986 /* Enable IRQ now that spinlock and rate limit timer are set up */
30987 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30988 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30989
30990 for(j=0; j<NWD; j++) {
30991 struct gendisk *disk = ida_gendisk[i][j];
30992 @@ -694,7 +694,7 @@ DBGINFO(
30993 for(i=0; i<NR_PRODUCTS; i++) {
30994 if (board_id == products[i].board_id) {
30995 c->product_name = products[i].product_name;
30996 - c->access = *(products[i].access);
30997 + c->access = products[i].access;
30998 break;
30999 }
31000 }
31001 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
31002 hba[ctlr]->intr = intr;
31003 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
31004 hba[ctlr]->product_name = products[j].product_name;
31005 - hba[ctlr]->access = *(products[j].access);
31006 + hba[ctlr]->access = products[j].access;
31007 hba[ctlr]->ctlr = ctlr;
31008 hba[ctlr]->board_id = board_id;
31009 hba[ctlr]->pci_dev = NULL; /* not PCI */
31010 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
31011
31012 while((c = h->reqQ) != NULL) {
31013 /* Can't do anything if we're busy */
31014 - if (h->access.fifo_full(h) == 0)
31015 + if (h->access->fifo_full(h) == 0)
31016 return;
31017
31018 /* Get the first entry from the request Q */
31019 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
31020 h->Qdepth--;
31021
31022 /* Tell the controller to do our bidding */
31023 - h->access.submit_command(h, c);
31024 + h->access->submit_command(h, c);
31025
31026 /* Get onto the completion Q */
31027 addQ(&h->cmpQ, c);
31028 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31029 unsigned long flags;
31030 __u32 a,a1;
31031
31032 - istat = h->access.intr_pending(h);
31033 + istat = h->access->intr_pending(h);
31034 /* Is this interrupt for us? */
31035 if (istat == 0)
31036 return IRQ_NONE;
31037 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31038 */
31039 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
31040 if (istat & FIFO_NOT_EMPTY) {
31041 - while((a = h->access.command_completed(h))) {
31042 + while((a = h->access->command_completed(h))) {
31043 a1 = a; a &= ~3;
31044 if ((c = h->cmpQ) == NULL)
31045 {
31046 @@ -1449,11 +1449,11 @@ static int sendcmd(
31047 /*
31048 * Disable interrupt
31049 */
31050 - info_p->access.set_intr_mask(info_p, 0);
31051 + info_p->access->set_intr_mask(info_p, 0);
31052 /* Make sure there is room in the command FIFO */
31053 /* Actually it should be completely empty at this time. */
31054 for (i = 200000; i > 0; i--) {
31055 - temp = info_p->access.fifo_full(info_p);
31056 + temp = info_p->access->fifo_full(info_p);
31057 if (temp != 0) {
31058 break;
31059 }
31060 @@ -1466,7 +1466,7 @@ DBG(
31061 /*
31062 * Send the cmd
31063 */
31064 - info_p->access.submit_command(info_p, c);
31065 + info_p->access->submit_command(info_p, c);
31066 complete = pollcomplete(ctlr);
31067
31068 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31069 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31070 * we check the new geometry. Then turn interrupts back on when
31071 * we're done.
31072 */
31073 - host->access.set_intr_mask(host, 0);
31074 + host->access->set_intr_mask(host, 0);
31075 getgeometry(ctlr);
31076 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31077 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31078
31079 for(i=0; i<NWD; i++) {
31080 struct gendisk *disk = ida_gendisk[ctlr][i];
31081 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31082 /* Wait (up to 2 seconds) for a command to complete */
31083
31084 for (i = 200000; i > 0; i--) {
31085 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
31086 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
31087 if (done == 0) {
31088 udelay(10); /* a short fixed delay */
31089 } else
31090 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31091 index be73e9d..7fbf140 100644
31092 --- a/drivers/block/cpqarray.h
31093 +++ b/drivers/block/cpqarray.h
31094 @@ -99,7 +99,7 @@ struct ctlr_info {
31095 drv_info_t drv[NWD];
31096 struct proc_dir_entry *proc;
31097
31098 - struct access_method access;
31099 + struct access_method *access;
31100
31101 cmdlist_t *reqQ;
31102 cmdlist_t *cmpQ;
31103 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31104 index b953cc7..e3dc580 100644
31105 --- a/drivers/block/drbd/drbd_int.h
31106 +++ b/drivers/block/drbd/drbd_int.h
31107 @@ -735,7 +735,7 @@ struct drbd_request;
31108 struct drbd_epoch {
31109 struct list_head list;
31110 unsigned int barrier_nr;
31111 - atomic_t epoch_size; /* increased on every request added. */
31112 + atomic_unchecked_t epoch_size; /* increased on every request added. */
31113 atomic_t active; /* increased on every req. added, and dec on every finished. */
31114 unsigned long flags;
31115 };
31116 @@ -1116,7 +1116,7 @@ struct drbd_conf {
31117 void *int_dig_in;
31118 void *int_dig_vv;
31119 wait_queue_head_t seq_wait;
31120 - atomic_t packet_seq;
31121 + atomic_unchecked_t packet_seq;
31122 unsigned int peer_seq;
31123 spinlock_t peer_seq_lock;
31124 unsigned int minor;
31125 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31126
31127 static inline void drbd_tcp_cork(struct socket *sock)
31128 {
31129 - int __user val = 1;
31130 + int val = 1;
31131 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31132 - (char __user *)&val, sizeof(val));
31133 + (char __force_user *)&val, sizeof(val));
31134 }
31135
31136 static inline void drbd_tcp_uncork(struct socket *sock)
31137 {
31138 - int __user val = 0;
31139 + int val = 0;
31140 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31141 - (char __user *)&val, sizeof(val));
31142 + (char __force_user *)&val, sizeof(val));
31143 }
31144
31145 static inline void drbd_tcp_nodelay(struct socket *sock)
31146 {
31147 - int __user val = 1;
31148 + int val = 1;
31149 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31150 - (char __user *)&val, sizeof(val));
31151 + (char __force_user *)&val, sizeof(val));
31152 }
31153
31154 static inline void drbd_tcp_quickack(struct socket *sock)
31155 {
31156 - int __user val = 2;
31157 + int val = 2;
31158 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31159 - (char __user *)&val, sizeof(val));
31160 + (char __force_user *)&val, sizeof(val));
31161 }
31162
31163 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31164 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31165 index f55683a..2101b96 100644
31166 --- a/drivers/block/drbd/drbd_main.c
31167 +++ b/drivers/block/drbd/drbd_main.c
31168 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31169 p.sector = sector;
31170 p.block_id = block_id;
31171 p.blksize = blksize;
31172 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31173 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31174
31175 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31176 return false;
31177 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31178
31179 p.sector = cpu_to_be64(req->sector);
31180 p.block_id = (unsigned long)req;
31181 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31182 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31183
31184 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31185
31186 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31187 atomic_set(&mdev->unacked_cnt, 0);
31188 atomic_set(&mdev->local_cnt, 0);
31189 atomic_set(&mdev->net_cnt, 0);
31190 - atomic_set(&mdev->packet_seq, 0);
31191 + atomic_set_unchecked(&mdev->packet_seq, 0);
31192 atomic_set(&mdev->pp_in_use, 0);
31193 atomic_set(&mdev->pp_in_use_by_net, 0);
31194 atomic_set(&mdev->rs_sect_in, 0);
31195 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31196 mdev->receiver.t_state);
31197
31198 /* no need to lock it, I'm the only thread alive */
31199 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31200 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31201 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31202 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31203 mdev->al_writ_cnt =
31204 mdev->bm_writ_cnt =
31205 mdev->read_cnt =
31206 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31207 index edb490a..ecd69da 100644
31208 --- a/drivers/block/drbd/drbd_nl.c
31209 +++ b/drivers/block/drbd/drbd_nl.c
31210 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31211 module_put(THIS_MODULE);
31212 }
31213
31214 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31215 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31216
31217 static unsigned short *
31218 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31219 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31220 cn_reply->id.idx = CN_IDX_DRBD;
31221 cn_reply->id.val = CN_VAL_DRBD;
31222
31223 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31224 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31225 cn_reply->ack = 0; /* not used here. */
31226 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31227 (int)((char *)tl - (char *)reply->tag_list);
31228 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31229 cn_reply->id.idx = CN_IDX_DRBD;
31230 cn_reply->id.val = CN_VAL_DRBD;
31231
31232 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31233 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31234 cn_reply->ack = 0; /* not used here. */
31235 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31236 (int)((char *)tl - (char *)reply->tag_list);
31237 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31238 cn_reply->id.idx = CN_IDX_DRBD;
31239 cn_reply->id.val = CN_VAL_DRBD;
31240
31241 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31242 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31243 cn_reply->ack = 0; // not used here.
31244 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31245 (int)((char*)tl - (char*)reply->tag_list);
31246 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31247 cn_reply->id.idx = CN_IDX_DRBD;
31248 cn_reply->id.val = CN_VAL_DRBD;
31249
31250 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31251 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31252 cn_reply->ack = 0; /* not used here. */
31253 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31254 (int)((char *)tl - (char *)reply->tag_list);
31255 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31256 index c74ca2d..860c819 100644
31257 --- a/drivers/block/drbd/drbd_receiver.c
31258 +++ b/drivers/block/drbd/drbd_receiver.c
31259 @@ -898,7 +898,7 @@ retry:
31260 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31261 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31262
31263 - atomic_set(&mdev->packet_seq, 0);
31264 + atomic_set_unchecked(&mdev->packet_seq, 0);
31265 mdev->peer_seq = 0;
31266
31267 if (drbd_send_protocol(mdev) == -1)
31268 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31269 do {
31270 next_epoch = NULL;
31271
31272 - epoch_size = atomic_read(&epoch->epoch_size);
31273 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31274
31275 switch (ev & ~EV_CLEANUP) {
31276 case EV_PUT:
31277 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31278 rv = FE_DESTROYED;
31279 } else {
31280 epoch->flags = 0;
31281 - atomic_set(&epoch->epoch_size, 0);
31282 + atomic_set_unchecked(&epoch->epoch_size, 0);
31283 /* atomic_set(&epoch->active, 0); is already zero */
31284 if (rv == FE_STILL_LIVE)
31285 rv = FE_RECYCLED;
31286 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31287 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31288 drbd_flush(mdev);
31289
31290 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31291 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31292 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31293 if (epoch)
31294 break;
31295 }
31296
31297 epoch = mdev->current_epoch;
31298 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31299 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31300
31301 D_ASSERT(atomic_read(&epoch->active) == 0);
31302 D_ASSERT(epoch->flags == 0);
31303 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31304 }
31305
31306 epoch->flags = 0;
31307 - atomic_set(&epoch->epoch_size, 0);
31308 + atomic_set_unchecked(&epoch->epoch_size, 0);
31309 atomic_set(&epoch->active, 0);
31310
31311 spin_lock(&mdev->epoch_lock);
31312 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31313 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31314 list_add(&epoch->list, &mdev->current_epoch->list);
31315 mdev->current_epoch = epoch;
31316 mdev->epochs++;
31317 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31318 spin_unlock(&mdev->peer_seq_lock);
31319
31320 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31321 - atomic_inc(&mdev->current_epoch->epoch_size);
31322 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31323 return drbd_drain_block(mdev, data_size);
31324 }
31325
31326 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31327
31328 spin_lock(&mdev->epoch_lock);
31329 e->epoch = mdev->current_epoch;
31330 - atomic_inc(&e->epoch->epoch_size);
31331 + atomic_inc_unchecked(&e->epoch->epoch_size);
31332 atomic_inc(&e->epoch->active);
31333 spin_unlock(&mdev->epoch_lock);
31334
31335 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31336 D_ASSERT(list_empty(&mdev->done_ee));
31337
31338 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31339 - atomic_set(&mdev->current_epoch->epoch_size, 0);
31340 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31341 D_ASSERT(list_empty(&mdev->current_epoch->list));
31342 }
31343
31344 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31345 index 54046e5..7759c55 100644
31346 --- a/drivers/block/loop.c
31347 +++ b/drivers/block/loop.c
31348 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31349 mm_segment_t old_fs = get_fs();
31350
31351 set_fs(get_ds());
31352 - bw = file->f_op->write(file, buf, len, &pos);
31353 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31354 set_fs(old_fs);
31355 if (likely(bw == len))
31356 return 0;
31357 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31358 index d620b44..587561e 100644
31359 --- a/drivers/cdrom/cdrom.c
31360 +++ b/drivers/cdrom/cdrom.c
31361 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31362 ENSURE(reset, CDC_RESET);
31363 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31364 cdi->mc_flags = 0;
31365 - cdo->n_minors = 0;
31366 cdi->options = CDO_USE_FFLAGS;
31367
31368 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31369 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31370 else
31371 cdi->cdda_method = CDDA_OLD;
31372
31373 - if (!cdo->generic_packet)
31374 - cdo->generic_packet = cdrom_dummy_generic_packet;
31375 + if (!cdo->generic_packet) {
31376 + pax_open_kernel();
31377 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31378 + pax_close_kernel();
31379 + }
31380
31381 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31382 mutex_lock(&cdrom_mutex);
31383 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31384 if (cdi->exit)
31385 cdi->exit(cdi);
31386
31387 - cdi->ops->n_minors--;
31388 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31389 }
31390
31391 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31392 index 75d485a..2809958 100644
31393 --- a/drivers/cdrom/gdrom.c
31394 +++ b/drivers/cdrom/gdrom.c
31395 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31396 .audio_ioctl = gdrom_audio_ioctl,
31397 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31398 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31399 - .n_minors = 1,
31400 };
31401
31402 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31403 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31404 index 72bedad..8181ce1 100644
31405 --- a/drivers/char/Kconfig
31406 +++ b/drivers/char/Kconfig
31407 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31408
31409 config DEVKMEM
31410 bool "/dev/kmem virtual device support"
31411 - default y
31412 + default n
31413 + depends on !GRKERNSEC_KMEM
31414 help
31415 Say Y here if you want to support the /dev/kmem device. The
31416 /dev/kmem device is rarely used, but can be used for certain
31417 @@ -581,6 +582,7 @@ config DEVPORT
31418 bool
31419 depends on !M68K
31420 depends on ISA || PCI
31421 + depends on !GRKERNSEC_KMEM
31422 default y
31423
31424 source "drivers/s390/char/Kconfig"
31425 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31426 index 2e04433..22afc64 100644
31427 --- a/drivers/char/agp/frontend.c
31428 +++ b/drivers/char/agp/frontend.c
31429 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31430 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31431 return -EFAULT;
31432
31433 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31434 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31435 return -EFAULT;
31436
31437 client = agp_find_client_by_pid(reserve.pid);
31438 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31439 index 21cb980..f15107c 100644
31440 --- a/drivers/char/genrtc.c
31441 +++ b/drivers/char/genrtc.c
31442 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31443 switch (cmd) {
31444
31445 case RTC_PLL_GET:
31446 + memset(&pll, 0, sizeof(pll));
31447 if (get_rtc_pll(&pll))
31448 return -EINVAL;
31449 else
31450 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31451 index dfd7876..c0b0885 100644
31452 --- a/drivers/char/hpet.c
31453 +++ b/drivers/char/hpet.c
31454 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31455 }
31456
31457 static int
31458 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31459 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31460 struct hpet_info *info)
31461 {
31462 struct hpet_timer __iomem *timer;
31463 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31464 index a0c84bb..9edcf60 100644
31465 --- a/drivers/char/ipmi/ipmi_msghandler.c
31466 +++ b/drivers/char/ipmi/ipmi_msghandler.c
31467 @@ -420,7 +420,7 @@ struct ipmi_smi {
31468 struct proc_dir_entry *proc_dir;
31469 char proc_dir_name[10];
31470
31471 - atomic_t stats[IPMI_NUM_STATS];
31472 + atomic_unchecked_t stats[IPMI_NUM_STATS];
31473
31474 /*
31475 * run_to_completion duplicate of smb_info, smi_info
31476 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31477
31478
31479 #define ipmi_inc_stat(intf, stat) \
31480 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31481 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31482 #define ipmi_get_stat(intf, stat) \
31483 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31484 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31485
31486 static int is_lan_addr(struct ipmi_addr *addr)
31487 {
31488 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31489 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31490 init_waitqueue_head(&intf->waitq);
31491 for (i = 0; i < IPMI_NUM_STATS; i++)
31492 - atomic_set(&intf->stats[i], 0);
31493 + atomic_set_unchecked(&intf->stats[i], 0);
31494
31495 intf->proc_dir = NULL;
31496
31497 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31498 index 32a6c7e..f6966a9 100644
31499 --- a/drivers/char/ipmi/ipmi_si_intf.c
31500 +++ b/drivers/char/ipmi/ipmi_si_intf.c
31501 @@ -275,7 +275,7 @@ struct smi_info {
31502 unsigned char slave_addr;
31503
31504 /* Counters and things for the proc filesystem. */
31505 - atomic_t stats[SI_NUM_STATS];
31506 + atomic_unchecked_t stats[SI_NUM_STATS];
31507
31508 struct task_struct *thread;
31509
31510 @@ -284,9 +284,9 @@ struct smi_info {
31511 };
31512
31513 #define smi_inc_stat(smi, stat) \
31514 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31515 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31516 #define smi_get_stat(smi, stat) \
31517 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31518 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31519
31520 #define SI_MAX_PARMS 4
31521
31522 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31523 atomic_set(&new_smi->req_events, 0);
31524 new_smi->run_to_completion = 0;
31525 for (i = 0; i < SI_NUM_STATS; i++)
31526 - atomic_set(&new_smi->stats[i], 0);
31527 + atomic_set_unchecked(&new_smi->stats[i], 0);
31528
31529 new_smi->interrupt_disabled = 1;
31530 atomic_set(&new_smi->stop_operation, 0);
31531 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31532 index 0537903..121c699 100644
31533 --- a/drivers/char/mem.c
31534 +++ b/drivers/char/mem.c
31535 @@ -18,6 +18,7 @@
31536 #include <linux/raw.h>
31537 #include <linux/tty.h>
31538 #include <linux/capability.h>
31539 +#include <linux/security.h>
31540 #include <linux/ptrace.h>
31541 #include <linux/device.h>
31542 #include <linux/highmem.h>
31543 @@ -37,6 +38,10 @@
31544
31545 #define DEVPORT_MINOR 4
31546
31547 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31548 +extern const struct file_operations grsec_fops;
31549 +#endif
31550 +
31551 static inline unsigned long size_inside_page(unsigned long start,
31552 unsigned long size)
31553 {
31554 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31555
31556 while (cursor < to) {
31557 if (!devmem_is_allowed(pfn)) {
31558 +#ifdef CONFIG_GRKERNSEC_KMEM
31559 + gr_handle_mem_readwrite(from, to);
31560 +#else
31561 printk(KERN_INFO
31562 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31563 current->comm, from, to);
31564 +#endif
31565 return 0;
31566 }
31567 cursor += PAGE_SIZE;
31568 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31569 }
31570 return 1;
31571 }
31572 +#elif defined(CONFIG_GRKERNSEC_KMEM)
31573 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31574 +{
31575 + return 0;
31576 +}
31577 #else
31578 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31579 {
31580 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31581
31582 while (count > 0) {
31583 unsigned long remaining;
31584 + char *temp;
31585
31586 sz = size_inside_page(p, count);
31587
31588 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31589 if (!ptr)
31590 return -EFAULT;
31591
31592 - remaining = copy_to_user(buf, ptr, sz);
31593 +#ifdef CONFIG_PAX_USERCOPY
31594 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31595 + if (!temp) {
31596 + unxlate_dev_mem_ptr(p, ptr);
31597 + return -ENOMEM;
31598 + }
31599 + memcpy(temp, ptr, sz);
31600 +#else
31601 + temp = ptr;
31602 +#endif
31603 +
31604 + remaining = copy_to_user(buf, temp, sz);
31605 +
31606 +#ifdef CONFIG_PAX_USERCOPY
31607 + kfree(temp);
31608 +#endif
31609 +
31610 unxlate_dev_mem_ptr(p, ptr);
31611 if (remaining)
31612 return -EFAULT;
31613 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31614 size_t count, loff_t *ppos)
31615 {
31616 unsigned long p = *ppos;
31617 - ssize_t low_count, read, sz;
31618 + ssize_t low_count, read, sz, err = 0;
31619 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31620 - int err = 0;
31621
31622 read = 0;
31623 if (p < (unsigned long) high_memory) {
31624 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31625 }
31626 #endif
31627 while (low_count > 0) {
31628 + char *temp;
31629 +
31630 sz = size_inside_page(p, low_count);
31631
31632 /*
31633 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31634 */
31635 kbuf = xlate_dev_kmem_ptr((char *)p);
31636
31637 - if (copy_to_user(buf, kbuf, sz))
31638 +#ifdef CONFIG_PAX_USERCOPY
31639 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31640 + if (!temp)
31641 + return -ENOMEM;
31642 + memcpy(temp, kbuf, sz);
31643 +#else
31644 + temp = kbuf;
31645 +#endif
31646 +
31647 + err = copy_to_user(buf, temp, sz);
31648 +
31649 +#ifdef CONFIG_PAX_USERCOPY
31650 + kfree(temp);
31651 +#endif
31652 +
31653 + if (err)
31654 return -EFAULT;
31655 buf += sz;
31656 p += sz;
31657 @@ -833,6 +880,9 @@ static const struct memdev {
31658 #ifdef CONFIG_CRASH_DUMP
31659 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31660 #endif
31661 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31662 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31663 +#endif
31664 };
31665
31666 static int memory_open(struct inode *inode, struct file *filp)
31667 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
31668 index 9df78e2..01ba9ae 100644
31669 --- a/drivers/char/nvram.c
31670 +++ b/drivers/char/nvram.c
31671 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
31672
31673 spin_unlock_irq(&rtc_lock);
31674
31675 - if (copy_to_user(buf, contents, tmp - contents))
31676 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
31677 return -EFAULT;
31678
31679 *ppos = i;
31680 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
31681 index 21721d2..4e98777 100644
31682 --- a/drivers/char/pcmcia/synclink_cs.c
31683 +++ b/drivers/char/pcmcia/synclink_cs.c
31684 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31685
31686 if (debug_level >= DEBUG_LEVEL_INFO)
31687 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
31688 - __FILE__,__LINE__, info->device_name, port->count);
31689 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
31690
31691 - WARN_ON(!port->count);
31692 + WARN_ON(!atomic_read(&port->count));
31693
31694 if (tty_port_close_start(port, tty, filp) == 0)
31695 goto cleanup;
31696 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31697 cleanup:
31698 if (debug_level >= DEBUG_LEVEL_INFO)
31699 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
31700 - tty->driver->name, port->count);
31701 + tty->driver->name, atomic_read(&port->count));
31702 }
31703
31704 /* Wait until the transmitter is empty.
31705 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31706
31707 if (debug_level >= DEBUG_LEVEL_INFO)
31708 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
31709 - __FILE__,__LINE__,tty->driver->name, port->count);
31710 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
31711
31712 /* If port is closing, signal caller to try again */
31713 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
31714 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31715 goto cleanup;
31716 }
31717 spin_lock(&port->lock);
31718 - port->count++;
31719 + atomic_inc(&port->count);
31720 spin_unlock(&port->lock);
31721 spin_unlock_irqrestore(&info->netlock, flags);
31722
31723 - if (port->count == 1) {
31724 + if (atomic_read(&port->count) == 1) {
31725 /* 1st open on this device, init hardware */
31726 retval = startup(info, tty);
31727 if (retval < 0)
31728 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
31729 unsigned short new_crctype;
31730
31731 /* return error if TTY interface open */
31732 - if (info->port.count)
31733 + if (atomic_read(&info->port.count))
31734 return -EBUSY;
31735
31736 switch (encoding)
31737 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
31738
31739 /* arbitrate between network and tty opens */
31740 spin_lock_irqsave(&info->netlock, flags);
31741 - if (info->port.count != 0 || info->netcount != 0) {
31742 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
31743 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
31744 spin_unlock_irqrestore(&info->netlock, flags);
31745 return -EBUSY;
31746 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
31747 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
31748
31749 /* return error if TTY interface open */
31750 - if (info->port.count)
31751 + if (atomic_read(&info->port.count))
31752 return -EBUSY;
31753
31754 if (cmd != SIOCWANDEV)
31755 diff --git a/drivers/char/random.c b/drivers/char/random.c
31756 index b86eae9..b9c2ed7 100644
31757 --- a/drivers/char/random.c
31758 +++ b/drivers/char/random.c
31759 @@ -272,8 +272,13 @@
31760 /*
31761 * Configuration information
31762 */
31763 +#ifdef CONFIG_GRKERNSEC_RANDNET
31764 +#define INPUT_POOL_WORDS 512
31765 +#define OUTPUT_POOL_WORDS 128
31766 +#else
31767 #define INPUT_POOL_WORDS 128
31768 #define OUTPUT_POOL_WORDS 32
31769 +#endif
31770 #define SEC_XFER_SIZE 512
31771 #define EXTRACT_SIZE 10
31772
31773 @@ -313,10 +318,17 @@ static struct poolinfo {
31774 int poolwords;
31775 int tap1, tap2, tap3, tap4, tap5;
31776 } poolinfo_table[] = {
31777 +#ifdef CONFIG_GRKERNSEC_RANDNET
31778 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
31779 + { 512, 411, 308, 208, 104, 1 },
31780 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
31781 + { 128, 103, 76, 51, 25, 1 },
31782 +#else
31783 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
31784 { 128, 103, 76, 51, 25, 1 },
31785 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
31786 { 32, 26, 20, 14, 7, 1 },
31787 +#endif
31788 #if 0
31789 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
31790 { 2048, 1638, 1231, 819, 411, 1 },
31791 @@ -437,6 +449,7 @@ struct entropy_store {
31792 int entropy_count;
31793 int entropy_total;
31794 unsigned int initialized:1;
31795 + bool last_data_init;
31796 __u8 last_data[EXTRACT_SIZE];
31797 };
31798
31799 @@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
31800 input_rotate += i ? 7 : 14;
31801 }
31802
31803 - ACCESS_ONCE(r->input_rotate) = input_rotate;
31804 - ACCESS_ONCE(r->add_ptr) = i;
31805 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
31806 + ACCESS_ONCE_RW(r->add_ptr) = i;
31807 smp_wmb();
31808
31809 if (out)
31810 @@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
31811 ssize_t ret = 0, i;
31812 __u8 tmp[EXTRACT_SIZE];
31813
31814 + /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
31815 + if (fips_enabled && !r->last_data_init)
31816 + nbytes += EXTRACT_SIZE;
31817 +
31818 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
31819 xfer_secondary_pool(r, nbytes);
31820 nbytes = account(r, nbytes, min, reserved);
31821 @@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
31822 if (fips_enabled) {
31823 unsigned long flags;
31824
31825 +
31826 + /* prime last_data value if need be, per fips 140-2 */
31827 + if (!r->last_data_init) {
31828 + spin_lock_irqsave(&r->lock, flags);
31829 + memcpy(r->last_data, tmp, EXTRACT_SIZE);
31830 + r->last_data_init = true;
31831 + nbytes -= EXTRACT_SIZE;
31832 + spin_unlock_irqrestore(&r->lock, flags);
31833 + extract_buf(r, tmp);
31834 + }
31835 +
31836 spin_lock_irqsave(&r->lock, flags);
31837 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
31838 panic("Hardware RNG duplicated output!\n");
31839 @@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
31840
31841 extract_buf(r, tmp);
31842 i = min_t(int, nbytes, EXTRACT_SIZE);
31843 - if (copy_to_user(buf, tmp, i)) {
31844 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
31845 ret = -EFAULT;
31846 break;
31847 }
31848 @@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
31849
31850 r->entropy_count = 0;
31851 r->entropy_total = 0;
31852 + r->last_data_init = false;
31853 mix_pool_bytes(r, &now, sizeof(now), NULL);
31854 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
31855 if (!arch_get_random_long(&rv))
31856 @@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
31857 #include <linux/sysctl.h>
31858
31859 static int min_read_thresh = 8, min_write_thresh;
31860 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
31861 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
31862 static int max_write_thresh = INPUT_POOL_WORDS * 32;
31863 static char sysctl_bootid[16];
31864
31865 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
31866 index 9b4f011..b7e0a1a 100644
31867 --- a/drivers/char/sonypi.c
31868 +++ b/drivers/char/sonypi.c
31869 @@ -54,6 +54,7 @@
31870
31871 #include <asm/uaccess.h>
31872 #include <asm/io.h>
31873 +#include <asm/local.h>
31874
31875 #include <linux/sonypi.h>
31876
31877 @@ -490,7 +491,7 @@ static struct sonypi_device {
31878 spinlock_t fifo_lock;
31879 wait_queue_head_t fifo_proc_list;
31880 struct fasync_struct *fifo_async;
31881 - int open_count;
31882 + local_t open_count;
31883 int model;
31884 struct input_dev *input_jog_dev;
31885 struct input_dev *input_key_dev;
31886 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
31887 static int sonypi_misc_release(struct inode *inode, struct file *file)
31888 {
31889 mutex_lock(&sonypi_device.lock);
31890 - sonypi_device.open_count--;
31891 + local_dec(&sonypi_device.open_count);
31892 mutex_unlock(&sonypi_device.lock);
31893 return 0;
31894 }
31895 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
31896 {
31897 mutex_lock(&sonypi_device.lock);
31898 /* Flush input queue on first open */
31899 - if (!sonypi_device.open_count)
31900 + if (!local_read(&sonypi_device.open_count))
31901 kfifo_reset(&sonypi_device.fifo);
31902 - sonypi_device.open_count++;
31903 + local_inc(&sonypi_device.open_count);
31904 mutex_unlock(&sonypi_device.lock);
31905
31906 return 0;
31907 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
31908 index 93211df..c7805f7 100644
31909 --- a/drivers/char/tpm/tpm.c
31910 +++ b/drivers/char/tpm/tpm.c
31911 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
31912 chip->vendor.req_complete_val)
31913 goto out_recv;
31914
31915 - if ((status == chip->vendor.req_canceled)) {
31916 + if (status == chip->vendor.req_canceled) {
31917 dev_err(chip->dev, "Operation Canceled\n");
31918 rc = -ECANCELED;
31919 goto out;
31920 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
31921 index 56051d0..11cf3b7 100644
31922 --- a/drivers/char/tpm/tpm_acpi.c
31923 +++ b/drivers/char/tpm/tpm_acpi.c
31924 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
31925 virt = acpi_os_map_memory(start, len);
31926 if (!virt) {
31927 kfree(log->bios_event_log);
31928 + log->bios_event_log = NULL;
31929 printk("%s: ERROR - Unable to map memory\n", __func__);
31930 return -EIO;
31931 }
31932
31933 - memcpy_fromio(log->bios_event_log, virt, len);
31934 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
31935
31936 acpi_os_unmap_memory(virt, len);
31937 return 0;
31938 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
31939 index 84ddc55..1d32f1e 100644
31940 --- a/drivers/char/tpm/tpm_eventlog.c
31941 +++ b/drivers/char/tpm/tpm_eventlog.c
31942 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
31943 event = addr;
31944
31945 if ((event->event_type == 0 && event->event_size == 0) ||
31946 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
31947 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
31948 return NULL;
31949
31950 return addr;
31951 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
31952 return NULL;
31953
31954 if ((event->event_type == 0 && event->event_size == 0) ||
31955 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
31956 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
31957 return NULL;
31958
31959 (*pos)++;
31960 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
31961 int i;
31962
31963 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
31964 - seq_putc(m, data[i]);
31965 + if (!seq_putc(m, data[i]))
31966 + return -EFAULT;
31967
31968 return 0;
31969 }
31970 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
31971 index 8ab9c3d..c3e65d3 100644
31972 --- a/drivers/char/virtio_console.c
31973 +++ b/drivers/char/virtio_console.c
31974 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
31975 if (to_user) {
31976 ssize_t ret;
31977
31978 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
31979 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
31980 if (ret)
31981 return -EFAULT;
31982 } else {
31983 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
31984 if (!port_has_data(port) && !port->host_connected)
31985 return 0;
31986
31987 - return fill_readbuf(port, ubuf, count, true);
31988 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
31989 }
31990
31991 static int wait_port_writable(struct port *port, bool nonblock)
31992 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
31993 index e164c55..3aabb50 100644
31994 --- a/drivers/edac/edac_pci_sysfs.c
31995 +++ b/drivers/edac/edac_pci_sysfs.c
31996 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
31997 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
31998 static int edac_pci_poll_msec = 1000; /* one second workq period */
31999
32000 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
32001 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32002 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32003 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32004
32005 static struct kobject *edac_pci_top_main_kobj;
32006 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32007 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32008 edac_printk(KERN_CRIT, EDAC_PCI,
32009 "Signaled System Error on %s\n",
32010 pci_name(dev));
32011 - atomic_inc(&pci_nonparity_count);
32012 + atomic_inc_unchecked(&pci_nonparity_count);
32013 }
32014
32015 if (status & (PCI_STATUS_PARITY)) {
32016 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32017 "Master Data Parity Error on %s\n",
32018 pci_name(dev));
32019
32020 - atomic_inc(&pci_parity_count);
32021 + atomic_inc_unchecked(&pci_parity_count);
32022 }
32023
32024 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32025 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32026 "Detected Parity Error on %s\n",
32027 pci_name(dev));
32028
32029 - atomic_inc(&pci_parity_count);
32030 + atomic_inc_unchecked(&pci_parity_count);
32031 }
32032 }
32033
32034 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32035 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32036 "Signaled System Error on %s\n",
32037 pci_name(dev));
32038 - atomic_inc(&pci_nonparity_count);
32039 + atomic_inc_unchecked(&pci_nonparity_count);
32040 }
32041
32042 if (status & (PCI_STATUS_PARITY)) {
32043 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32044 "Master Data Parity Error on "
32045 "%s\n", pci_name(dev));
32046
32047 - atomic_inc(&pci_parity_count);
32048 + atomic_inc_unchecked(&pci_parity_count);
32049 }
32050
32051 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32052 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32053 "Detected Parity Error on %s\n",
32054 pci_name(dev));
32055
32056 - atomic_inc(&pci_parity_count);
32057 + atomic_inc_unchecked(&pci_parity_count);
32058 }
32059 }
32060 }
32061 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32062 if (!check_pci_errors)
32063 return;
32064
32065 - before_count = atomic_read(&pci_parity_count);
32066 + before_count = atomic_read_unchecked(&pci_parity_count);
32067
32068 /* scan all PCI devices looking for a Parity Error on devices and
32069 * bridges.
32070 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32071 /* Only if operator has selected panic on PCI Error */
32072 if (edac_pci_get_panic_on_pe()) {
32073 /* If the count is different 'after' from 'before' */
32074 - if (before_count != atomic_read(&pci_parity_count))
32075 + if (before_count != atomic_read_unchecked(&pci_parity_count))
32076 panic("EDAC: PCI Parity Error");
32077 }
32078 }
32079 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32080 index 8c87a5e..a19cbd7 100644
32081 --- a/drivers/edac/mce_amd.h
32082 +++ b/drivers/edac/mce_amd.h
32083 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32084 struct amd_decoder_ops {
32085 bool (*dc_mce)(u16, u8);
32086 bool (*ic_mce)(u16, u8);
32087 -};
32088 +} __no_const;
32089
32090 void amd_report_gart_errors(bool);
32091 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32092 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32093 index 57ea7f4..789e3c3 100644
32094 --- a/drivers/firewire/core-card.c
32095 +++ b/drivers/firewire/core-card.c
32096 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32097
32098 void fw_core_remove_card(struct fw_card *card)
32099 {
32100 - struct fw_card_driver dummy_driver = dummy_driver_template;
32101 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
32102
32103 card->driver->update_phy_reg(card, 4,
32104 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32105 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32106 index f8d2287..5aaf4db 100644
32107 --- a/drivers/firewire/core-cdev.c
32108 +++ b/drivers/firewire/core-cdev.c
32109 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32110 int ret;
32111
32112 if ((request->channels == 0 && request->bandwidth == 0) ||
32113 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32114 - request->bandwidth < 0)
32115 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32116 return -EINVAL;
32117
32118 r = kmalloc(sizeof(*r), GFP_KERNEL);
32119 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32120 index 28a94c7..58da63a 100644
32121 --- a/drivers/firewire/core-transaction.c
32122 +++ b/drivers/firewire/core-transaction.c
32123 @@ -38,6 +38,7 @@
32124 #include <linux/timer.h>
32125 #include <linux/types.h>
32126 #include <linux/workqueue.h>
32127 +#include <linux/sched.h>
32128
32129 #include <asm/byteorder.h>
32130
32131 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32132 index 515a42c..5ecf3ba 100644
32133 --- a/drivers/firewire/core.h
32134 +++ b/drivers/firewire/core.h
32135 @@ -111,6 +111,7 @@ struct fw_card_driver {
32136
32137 int (*stop_iso)(struct fw_iso_context *ctx);
32138 };
32139 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32140
32141 void fw_card_initialize(struct fw_card *card,
32142 const struct fw_card_driver *driver, struct device *device);
32143 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32144 index b298158..7ed8432 100644
32145 --- a/drivers/firmware/dmi_scan.c
32146 +++ b/drivers/firmware/dmi_scan.c
32147 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
32148 }
32149 }
32150 else {
32151 - /*
32152 - * no iounmap() for that ioremap(); it would be a no-op, but
32153 - * it's so early in setup that sucker gets confused into doing
32154 - * what it shouldn't if we actually call it.
32155 - */
32156 p = dmi_ioremap(0xF0000, 0x10000);
32157 if (p == NULL)
32158 goto error;
32159 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32160 if (buf == NULL)
32161 return -1;
32162
32163 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32164 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32165
32166 iounmap(buf);
32167 return 0;
32168 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32169 index d10c987..ebe5400 100644
32170 --- a/drivers/firmware/efivars.c
32171 +++ b/drivers/firmware/efivars.c
32172 @@ -1234,9 +1234,9 @@ efivars_init(void)
32173 return -ENOMEM;
32174 }
32175
32176 - ops.get_variable = efi.get_variable;
32177 - ops.set_variable = efi.set_variable;
32178 - ops.get_next_variable = efi.get_next_variable;
32179 + *(void **)&ops.get_variable = efi.get_variable;
32180 + *(void **)&ops.set_variable = efi.set_variable;
32181 + *(void **)&ops.get_next_variable = efi.get_next_variable;
32182 error = register_efivars(&__efivars, &ops, efi_kobj);
32183 if (error)
32184 goto err_put;
32185 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32186 index 82d5c20..44a7177 100644
32187 --- a/drivers/gpio/gpio-vr41xx.c
32188 +++ b/drivers/gpio/gpio-vr41xx.c
32189 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32190 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32191 maskl, pendl, maskh, pendh);
32192
32193 - atomic_inc(&irq_err_count);
32194 + atomic_inc_unchecked(&irq_err_count);
32195
32196 return -EINVAL;
32197 }
32198 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32199 index 1227adf..f2301c2 100644
32200 --- a/drivers/gpu/drm/drm_crtc_helper.c
32201 +++ b/drivers/gpu/drm/drm_crtc_helper.c
32202 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32203 struct drm_crtc *tmp;
32204 int crtc_mask = 1;
32205
32206 - WARN(!crtc, "checking null crtc?\n");
32207 + BUG_ON(!crtc);
32208
32209 dev = crtc->dev;
32210
32211 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32212 index be174ca..0bcbb71 100644
32213 --- a/drivers/gpu/drm/drm_drv.c
32214 +++ b/drivers/gpu/drm/drm_drv.c
32215 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32216 /**
32217 * Copy and IOCTL return string to user space
32218 */
32219 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32220 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32221 {
32222 int len;
32223
32224 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32225 return -ENODEV;
32226
32227 atomic_inc(&dev->ioctl_count);
32228 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32229 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32230 ++file_priv->ioctl_count;
32231
32232 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32233 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32234 index 133b413..fd68225 100644
32235 --- a/drivers/gpu/drm/drm_fops.c
32236 +++ b/drivers/gpu/drm/drm_fops.c
32237 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32238 }
32239
32240 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32241 - atomic_set(&dev->counts[i], 0);
32242 + atomic_set_unchecked(&dev->counts[i], 0);
32243
32244 dev->sigdata.lock = NULL;
32245
32246 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32247 if (drm_device_is_unplugged(dev))
32248 return -ENODEV;
32249
32250 - if (!dev->open_count++)
32251 + if (local_inc_return(&dev->open_count) == 1)
32252 need_setup = 1;
32253 mutex_lock(&dev->struct_mutex);
32254 old_mapping = dev->dev_mapping;
32255 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32256 retcode = drm_open_helper(inode, filp, dev);
32257 if (retcode)
32258 goto err_undo;
32259 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32260 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32261 if (need_setup) {
32262 retcode = drm_setup(dev);
32263 if (retcode)
32264 @@ -164,7 +164,7 @@ err_undo:
32265 iput(container_of(dev->dev_mapping, struct inode, i_data));
32266 dev->dev_mapping = old_mapping;
32267 mutex_unlock(&dev->struct_mutex);
32268 - dev->open_count--;
32269 + local_dec(&dev->open_count);
32270 return retcode;
32271 }
32272 EXPORT_SYMBOL(drm_open);
32273 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32274
32275 mutex_lock(&drm_global_mutex);
32276
32277 - DRM_DEBUG("open_count = %d\n", dev->open_count);
32278 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32279
32280 if (dev->driver->preclose)
32281 dev->driver->preclose(dev, file_priv);
32282 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32283 * Begin inline drm_release
32284 */
32285
32286 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32287 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32288 task_pid_nr(current),
32289 (long)old_encode_dev(file_priv->minor->device),
32290 - dev->open_count);
32291 + local_read(&dev->open_count));
32292
32293 /* Release any auth tokens that might point to this file_priv,
32294 (do that under the drm_global_mutex) */
32295 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32296 * End inline drm_release
32297 */
32298
32299 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32300 - if (!--dev->open_count) {
32301 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32302 + if (local_dec_and_test(&dev->open_count)) {
32303 if (atomic_read(&dev->ioctl_count)) {
32304 DRM_ERROR("Device busy: %d\n",
32305 atomic_read(&dev->ioctl_count));
32306 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32307 index f731116..629842c 100644
32308 --- a/drivers/gpu/drm/drm_global.c
32309 +++ b/drivers/gpu/drm/drm_global.c
32310 @@ -36,7 +36,7 @@
32311 struct drm_global_item {
32312 struct mutex mutex;
32313 void *object;
32314 - int refcount;
32315 + atomic_t refcount;
32316 };
32317
32318 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32319 @@ -49,7 +49,7 @@ void drm_global_init(void)
32320 struct drm_global_item *item = &glob[i];
32321 mutex_init(&item->mutex);
32322 item->object = NULL;
32323 - item->refcount = 0;
32324 + atomic_set(&item->refcount, 0);
32325 }
32326 }
32327
32328 @@ -59,7 +59,7 @@ void drm_global_release(void)
32329 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32330 struct drm_global_item *item = &glob[i];
32331 BUG_ON(item->object != NULL);
32332 - BUG_ON(item->refcount != 0);
32333 + BUG_ON(atomic_read(&item->refcount) != 0);
32334 }
32335 }
32336
32337 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32338 void *object;
32339
32340 mutex_lock(&item->mutex);
32341 - if (item->refcount == 0) {
32342 + if (atomic_read(&item->refcount) == 0) {
32343 item->object = kzalloc(ref->size, GFP_KERNEL);
32344 if (unlikely(item->object == NULL)) {
32345 ret = -ENOMEM;
32346 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32347 goto out_err;
32348
32349 }
32350 - ++item->refcount;
32351 + atomic_inc(&item->refcount);
32352 ref->object = item->object;
32353 object = item->object;
32354 mutex_unlock(&item->mutex);
32355 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32356 struct drm_global_item *item = &glob[ref->global_type];
32357
32358 mutex_lock(&item->mutex);
32359 - BUG_ON(item->refcount == 0);
32360 + BUG_ON(atomic_read(&item->refcount) == 0);
32361 BUG_ON(ref->object != item->object);
32362 - if (--item->refcount == 0) {
32363 + if (atomic_dec_and_test(&item->refcount)) {
32364 ref->release(ref);
32365 item->object = NULL;
32366 }
32367 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32368 index d4b20ce..77a8d41 100644
32369 --- a/drivers/gpu/drm/drm_info.c
32370 +++ b/drivers/gpu/drm/drm_info.c
32371 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32372 struct drm_local_map *map;
32373 struct drm_map_list *r_list;
32374
32375 - /* Hardcoded from _DRM_FRAME_BUFFER,
32376 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32377 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32378 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32379 + static const char * const types[] = {
32380 + [_DRM_FRAME_BUFFER] = "FB",
32381 + [_DRM_REGISTERS] = "REG",
32382 + [_DRM_SHM] = "SHM",
32383 + [_DRM_AGP] = "AGP",
32384 + [_DRM_SCATTER_GATHER] = "SG",
32385 + [_DRM_CONSISTENT] = "PCI",
32386 + [_DRM_GEM] = "GEM" };
32387 const char *type;
32388 int i;
32389
32390 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32391 map = r_list->map;
32392 if (!map)
32393 continue;
32394 - if (map->type < 0 || map->type > 5)
32395 + if (map->type >= ARRAY_SIZE(types))
32396 type = "??";
32397 else
32398 type = types[map->type];
32399 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32400 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32401 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32402 vma->vm_flags & VM_IO ? 'i' : '-',
32403 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32404 + 0);
32405 +#else
32406 vma->vm_pgoff);
32407 +#endif
32408
32409 #if defined(__i386__)
32410 pgprot = pgprot_val(vma->vm_page_prot);
32411 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32412 index 2f4c434..764794b 100644
32413 --- a/drivers/gpu/drm/drm_ioc32.c
32414 +++ b/drivers/gpu/drm/drm_ioc32.c
32415 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32416 request = compat_alloc_user_space(nbytes);
32417 if (!access_ok(VERIFY_WRITE, request, nbytes))
32418 return -EFAULT;
32419 - list = (struct drm_buf_desc *) (request + 1);
32420 + list = (struct drm_buf_desc __user *) (request + 1);
32421
32422 if (__put_user(count, &request->count)
32423 || __put_user(list, &request->list))
32424 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32425 request = compat_alloc_user_space(nbytes);
32426 if (!access_ok(VERIFY_WRITE, request, nbytes))
32427 return -EFAULT;
32428 - list = (struct drm_buf_pub *) (request + 1);
32429 + list = (struct drm_buf_pub __user *) (request + 1);
32430
32431 if (__put_user(count, &request->count)
32432 || __put_user(list, &request->list))
32433 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32434 index 23dd975..63e9801 100644
32435 --- a/drivers/gpu/drm/drm_ioctl.c
32436 +++ b/drivers/gpu/drm/drm_ioctl.c
32437 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32438 stats->data[i].value =
32439 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32440 else
32441 - stats->data[i].value = atomic_read(&dev->counts[i]);
32442 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32443 stats->data[i].type = dev->types[i];
32444 }
32445
32446 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32447 index d752c96..fe08455 100644
32448 --- a/drivers/gpu/drm/drm_lock.c
32449 +++ b/drivers/gpu/drm/drm_lock.c
32450 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32451 if (drm_lock_take(&master->lock, lock->context)) {
32452 master->lock.file_priv = file_priv;
32453 master->lock.lock_time = jiffies;
32454 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32455 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32456 break; /* Got lock */
32457 }
32458
32459 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32460 return -EINVAL;
32461 }
32462
32463 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32464 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32465
32466 if (drm_lock_free(&master->lock, lock->context)) {
32467 /* FIXME: Should really bail out here. */
32468 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32469 index c236fd2..6b5f2e7 100644
32470 --- a/drivers/gpu/drm/drm_stub.c
32471 +++ b/drivers/gpu/drm/drm_stub.c
32472 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32473
32474 drm_device_set_unplugged(dev);
32475
32476 - if (dev->open_count == 0) {
32477 + if (local_read(&dev->open_count) == 0) {
32478 drm_put_dev(dev);
32479 }
32480 mutex_unlock(&drm_global_mutex);
32481 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32482 index 004ecdf..db1f6e0 100644
32483 --- a/drivers/gpu/drm/i810/i810_dma.c
32484 +++ b/drivers/gpu/drm/i810/i810_dma.c
32485 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32486 dma->buflist[vertex->idx],
32487 vertex->discard, vertex->used);
32488
32489 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32490 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32491 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32492 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32493 sarea_priv->last_enqueue = dev_priv->counter - 1;
32494 sarea_priv->last_dispatch = (int)hw_status[5];
32495
32496 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32497 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32498 mc->last_render);
32499
32500 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32501 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32502 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32503 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32504 sarea_priv->last_enqueue = dev_priv->counter - 1;
32505 sarea_priv->last_dispatch = (int)hw_status[5];
32506
32507 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32508 index 6e0acad..93c8289 100644
32509 --- a/drivers/gpu/drm/i810/i810_drv.h
32510 +++ b/drivers/gpu/drm/i810/i810_drv.h
32511 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32512 int page_flipping;
32513
32514 wait_queue_head_t irq_queue;
32515 - atomic_t irq_received;
32516 - atomic_t irq_emitted;
32517 + atomic_unchecked_t irq_received;
32518 + atomic_unchecked_t irq_emitted;
32519
32520 int front_offset;
32521 } drm_i810_private_t;
32522 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32523 index da21b11..14c8749 100644
32524 --- a/drivers/gpu/drm/i915/i915_debugfs.c
32525 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
32526 @@ -495,7 +495,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32527 I915_READ(GTIMR));
32528 }
32529 seq_printf(m, "Interrupts received: %d\n",
32530 - atomic_read(&dev_priv->irq_received));
32531 + atomic_read_unchecked(&dev_priv->irq_received));
32532 for_each_ring(ring, dev_priv, i) {
32533 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32534 seq_printf(m,
32535 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32536 index 61ae104..f8a4bc1 100644
32537 --- a/drivers/gpu/drm/i915/i915_dma.c
32538 +++ b/drivers/gpu/drm/i915/i915_dma.c
32539 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32540 bool can_switch;
32541
32542 spin_lock(&dev->count_lock);
32543 - can_switch = (dev->open_count == 0);
32544 + can_switch = (local_read(&dev->open_count) == 0);
32545 spin_unlock(&dev->count_lock);
32546 return can_switch;
32547 }
32548 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32549 index 92f1750..3beba74 100644
32550 --- a/drivers/gpu/drm/i915/i915_drv.h
32551 +++ b/drivers/gpu/drm/i915/i915_drv.h
32552 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32553
32554 struct resource mch_res;
32555
32556 - atomic_t irq_received;
32557 + atomic_unchecked_t irq_received;
32558
32559 /* protects the irq masks */
32560 spinlock_t irq_lock;
32561 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32562 * will be page flipped away on the next vblank. When it
32563 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32564 */
32565 - atomic_t pending_flip;
32566 + atomic_unchecked_t pending_flip;
32567 };
32568
32569 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32570 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32571 struct drm_i915_private *dev_priv, unsigned port);
32572 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32573 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32574 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32575 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32576 {
32577 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32578 }
32579 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32580 index 3eea143..a0b77db 100644
32581 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32582 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32583 @@ -660,7 +660,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32584 i915_gem_clflush_object(obj);
32585
32586 if (obj->base.pending_write_domain)
32587 - flips |= atomic_read(&obj->pending_flip);
32588 + flips |= atomic_read_unchecked(&obj->pending_flip);
32589
32590 flush_domains |= obj->base.write_domain;
32591 }
32592 @@ -691,9 +691,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32593
32594 static int
32595 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32596 - int count)
32597 + unsigned int count)
32598 {
32599 - int i;
32600 + unsigned int i;
32601
32602 for (i = 0; i < count; i++) {
32603 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32604 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32605 index dc29ace..137d83a 100644
32606 --- a/drivers/gpu/drm/i915/i915_irq.c
32607 +++ b/drivers/gpu/drm/i915/i915_irq.c
32608 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32609 u32 pipe_stats[I915_MAX_PIPES];
32610 bool blc_event;
32611
32612 - atomic_inc(&dev_priv->irq_received);
32613 + atomic_inc_unchecked(&dev_priv->irq_received);
32614
32615 while (true) {
32616 iir = I915_READ(VLV_IIR);
32617 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32618 irqreturn_t ret = IRQ_NONE;
32619 int i;
32620
32621 - atomic_inc(&dev_priv->irq_received);
32622 + atomic_inc_unchecked(&dev_priv->irq_received);
32623
32624 /* disable master interrupt before clearing iir */
32625 de_ier = I915_READ(DEIER);
32626 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
32627 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
32628 u32 hotplug_mask;
32629
32630 - atomic_inc(&dev_priv->irq_received);
32631 + atomic_inc_unchecked(&dev_priv->irq_received);
32632
32633 /* disable master interrupt before clearing iir */
32634 de_ier = I915_READ(DEIER);
32635 @@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
32636 {
32637 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32638
32639 - atomic_set(&dev_priv->irq_received, 0);
32640 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32641
32642 I915_WRITE(HWSTAM, 0xeffe);
32643
32644 @@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
32645 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32646 int pipe;
32647
32648 - atomic_set(&dev_priv->irq_received, 0);
32649 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32650
32651 /* VLV magic */
32652 I915_WRITE(VLV_IMR, 0);
32653 @@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
32654 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32655 int pipe;
32656
32657 - atomic_set(&dev_priv->irq_received, 0);
32658 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32659
32660 for_each_pipe(pipe)
32661 I915_WRITE(PIPESTAT(pipe), 0);
32662 @@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
32663 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
32664 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
32665
32666 - atomic_inc(&dev_priv->irq_received);
32667 + atomic_inc_unchecked(&dev_priv->irq_received);
32668
32669 iir = I915_READ16(IIR);
32670 if (iir == 0)
32671 @@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
32672 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32673 int pipe;
32674
32675 - atomic_set(&dev_priv->irq_received, 0);
32676 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32677
32678 if (I915_HAS_HOTPLUG(dev)) {
32679 I915_WRITE(PORT_HOTPLUG_EN, 0);
32680 @@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
32681 };
32682 int pipe, ret = IRQ_NONE;
32683
32684 - atomic_inc(&dev_priv->irq_received);
32685 + atomic_inc_unchecked(&dev_priv->irq_received);
32686
32687 iir = I915_READ(IIR);
32688 do {
32689 @@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
32690 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32691 int pipe;
32692
32693 - atomic_set(&dev_priv->irq_received, 0);
32694 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32695
32696 I915_WRITE(PORT_HOTPLUG_EN, 0);
32697 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
32698 @@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
32699 int irq_received;
32700 int ret = IRQ_NONE, pipe;
32701
32702 - atomic_inc(&dev_priv->irq_received);
32703 + atomic_inc_unchecked(&dev_priv->irq_received);
32704
32705 iir = I915_READ(IIR);
32706
32707 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
32708 index 4d3c7c6..eaac87b 100644
32709 --- a/drivers/gpu/drm/i915/intel_display.c
32710 +++ b/drivers/gpu/drm/i915/intel_display.c
32711 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
32712
32713 wait_event(dev_priv->pending_flip_queue,
32714 atomic_read(&dev_priv->mm.wedged) ||
32715 - atomic_read(&obj->pending_flip) == 0);
32716 + atomic_read_unchecked(&obj->pending_flip) == 0);
32717
32718 /* Big Hammer, we also need to ensure that any pending
32719 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
32720 @@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
32721
32722 obj = work->old_fb_obj;
32723
32724 - atomic_clear_mask(1 << intel_crtc->plane,
32725 - &obj->pending_flip.counter);
32726 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
32727 wake_up(&dev_priv->pending_flip_queue);
32728
32729 queue_work(dev_priv->wq, &work->work);
32730 @@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
32731 /* Block clients from rendering to the new back buffer until
32732 * the flip occurs and the object is no longer visible.
32733 */
32734 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32735 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32736 atomic_inc(&intel_crtc->unpin_work_count);
32737
32738 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
32739 @@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
32740
32741 cleanup_pending:
32742 atomic_dec(&intel_crtc->unpin_work_count);
32743 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32744 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32745 drm_gem_object_unreference(&work->old_fb_obj->base);
32746 drm_gem_object_unreference(&obj->base);
32747 mutex_unlock(&dev->struct_mutex);
32748 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
32749 index 54558a0..2d97005 100644
32750 --- a/drivers/gpu/drm/mga/mga_drv.h
32751 +++ b/drivers/gpu/drm/mga/mga_drv.h
32752 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
32753 u32 clear_cmd;
32754 u32 maccess;
32755
32756 - atomic_t vbl_received; /**< Number of vblanks received. */
32757 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
32758 wait_queue_head_t fence_queue;
32759 - atomic_t last_fence_retired;
32760 + atomic_unchecked_t last_fence_retired;
32761 u32 next_fence_to_post;
32762
32763 unsigned int fb_cpp;
32764 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
32765 index 598c281..60d590e 100644
32766 --- a/drivers/gpu/drm/mga/mga_irq.c
32767 +++ b/drivers/gpu/drm/mga/mga_irq.c
32768 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
32769 if (crtc != 0)
32770 return 0;
32771
32772 - return atomic_read(&dev_priv->vbl_received);
32773 + return atomic_read_unchecked(&dev_priv->vbl_received);
32774 }
32775
32776
32777 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
32778 /* VBLANK interrupt */
32779 if (status & MGA_VLINEPEN) {
32780 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
32781 - atomic_inc(&dev_priv->vbl_received);
32782 + atomic_inc_unchecked(&dev_priv->vbl_received);
32783 drm_handle_vblank(dev, 0);
32784 handled = 1;
32785 }
32786 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
32787 if ((prim_start & ~0x03) != (prim_end & ~0x03))
32788 MGA_WRITE(MGA_PRIMEND, prim_end);
32789
32790 - atomic_inc(&dev_priv->last_fence_retired);
32791 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
32792 DRM_WAKEUP(&dev_priv->fence_queue);
32793 handled = 1;
32794 }
32795 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
32796 * using fences.
32797 */
32798 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
32799 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
32800 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
32801 - *sequence) <= (1 << 23)));
32802
32803 *sequence = cur_fence;
32804 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
32805 index 09fdef2..57f5c3b 100644
32806 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
32807 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
32808 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
32809 struct bit_table {
32810 const char id;
32811 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
32812 -};
32813 +} __no_const;
32814
32815 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
32816
32817 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
32818 index a101699..a163f0a 100644
32819 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
32820 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
32821 @@ -80,7 +80,7 @@ struct nouveau_drm {
32822 struct drm_global_reference mem_global_ref;
32823 struct ttm_bo_global_ref bo_global_ref;
32824 struct ttm_bo_device bdev;
32825 - atomic_t validate_sequence;
32826 + atomic_unchecked_t validate_sequence;
32827 int (*move)(struct nouveau_channel *,
32828 struct ttm_buffer_object *,
32829 struct ttm_mem_reg *, struct ttm_mem_reg *);
32830 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
32831 index cdb83ac..27f0a16 100644
32832 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
32833 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
32834 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
32835 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
32836 struct nouveau_channel *);
32837 u32 (*read)(struct nouveau_channel *);
32838 -};
32839 +} __no_const;
32840
32841 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
32842
32843 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
32844 index 5e2f521..0d21436 100644
32845 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
32846 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
32847 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
32848 int trycnt = 0;
32849 int ret, i;
32850
32851 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
32852 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
32853 retry:
32854 if (++trycnt > 100000) {
32855 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
32856 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
32857 index 6f0ac64..9c2dfb4 100644
32858 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
32859 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
32860 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
32861 bool can_switch;
32862
32863 spin_lock(&dev->count_lock);
32864 - can_switch = (dev->open_count == 0);
32865 + can_switch = (local_read(&dev->open_count) == 0);
32866 spin_unlock(&dev->count_lock);
32867 return can_switch;
32868 }
32869 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
32870 index 9f6f55c..30e3a29 100644
32871 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
32872 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
32873 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
32874 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
32875 evo->object->oclass->ofuncs =
32876 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
32877 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
32878 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
32879 - evo->object->oclass->ofuncs->rd08 =
32880 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
32881 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
32882 + *(void**)&evo->object->oclass->ofuncs->rd08 =
32883 ioremap(pci_resource_start(dev->pdev, 0) +
32884 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
32885 return 0;
32886 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
32887 index b562b59..9d725a8 100644
32888 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
32889 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
32890 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
32891 }
32892
32893 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
32894 - struct dp_train_func func = {
32895 + static struct dp_train_func func = {
32896 .link_set = nv50_sor_dp_link_set,
32897 .train_set = nv50_sor_dp_train_set,
32898 .train_adj = nv50_sor_dp_train_adj
32899 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
32900 index c402fca..f1d694b 100644
32901 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
32902 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
32903 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
32904 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
32905
32906 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
32907 - struct dp_train_func func = {
32908 + static struct dp_train_func func = {
32909 .link_set = nvd0_sor_dp_link_set,
32910 .train_set = nvd0_sor_dp_train_set,
32911 .train_adj = nvd0_sor_dp_train_adj
32912 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
32913 index d4660cf..70dbe65 100644
32914 --- a/drivers/gpu/drm/r128/r128_cce.c
32915 +++ b/drivers/gpu/drm/r128/r128_cce.c
32916 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
32917
32918 /* GH: Simple idle check.
32919 */
32920 - atomic_set(&dev_priv->idle_count, 0);
32921 + atomic_set_unchecked(&dev_priv->idle_count, 0);
32922
32923 /* We don't support anything other than bus-mastering ring mode,
32924 * but the ring can be in either AGP or PCI space for the ring
32925 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
32926 index 930c71b..499aded 100644
32927 --- a/drivers/gpu/drm/r128/r128_drv.h
32928 +++ b/drivers/gpu/drm/r128/r128_drv.h
32929 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
32930 int is_pci;
32931 unsigned long cce_buffers_offset;
32932
32933 - atomic_t idle_count;
32934 + atomic_unchecked_t idle_count;
32935
32936 int page_flipping;
32937 int current_page;
32938 u32 crtc_offset;
32939 u32 crtc_offset_cntl;
32940
32941 - atomic_t vbl_received;
32942 + atomic_unchecked_t vbl_received;
32943
32944 u32 color_fmt;
32945 unsigned int front_offset;
32946 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
32947 index 2ea4f09..d391371 100644
32948 --- a/drivers/gpu/drm/r128/r128_irq.c
32949 +++ b/drivers/gpu/drm/r128/r128_irq.c
32950 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
32951 if (crtc != 0)
32952 return 0;
32953
32954 - return atomic_read(&dev_priv->vbl_received);
32955 + return atomic_read_unchecked(&dev_priv->vbl_received);
32956 }
32957
32958 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
32959 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
32960 /* VBLANK interrupt */
32961 if (status & R128_CRTC_VBLANK_INT) {
32962 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
32963 - atomic_inc(&dev_priv->vbl_received);
32964 + atomic_inc_unchecked(&dev_priv->vbl_received);
32965 drm_handle_vblank(dev, 0);
32966 return IRQ_HANDLED;
32967 }
32968 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
32969 index 19bb7e6..de7e2a2 100644
32970 --- a/drivers/gpu/drm/r128/r128_state.c
32971 +++ b/drivers/gpu/drm/r128/r128_state.c
32972 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
32973
32974 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
32975 {
32976 - if (atomic_read(&dev_priv->idle_count) == 0)
32977 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
32978 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
32979 else
32980 - atomic_set(&dev_priv->idle_count, 0);
32981 + atomic_set_unchecked(&dev_priv->idle_count, 0);
32982 }
32983
32984 #endif
32985 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
32986 index 5a82b6b..9e69c73 100644
32987 --- a/drivers/gpu/drm/radeon/mkregtable.c
32988 +++ b/drivers/gpu/drm/radeon/mkregtable.c
32989 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
32990 regex_t mask_rex;
32991 regmatch_t match[4];
32992 char buf[1024];
32993 - size_t end;
32994 + long end;
32995 int len;
32996 int done = 0;
32997 int r;
32998 unsigned o;
32999 struct offset *offset;
33000 char last_reg_s[10];
33001 - int last_reg;
33002 + unsigned long last_reg;
33003
33004 if (regcomp
33005 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33006 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
33007 index ad4c973..aa27bcb 100644
33008 --- a/drivers/gpu/drm/radeon/radeon_device.c
33009 +++ b/drivers/gpu/drm/radeon/radeon_device.c
33010 @@ -940,7 +940,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
33011 bool can_switch;
33012
33013 spin_lock(&dev->count_lock);
33014 - can_switch = (dev->open_count == 0);
33015 + can_switch = (local_read(&dev->open_count) == 0);
33016 spin_unlock(&dev->count_lock);
33017 return can_switch;
33018 }
33019 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33020 index a1b59ca..86f2d44 100644
33021 --- a/drivers/gpu/drm/radeon/radeon_drv.h
33022 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
33023 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
33024
33025 /* SW interrupt */
33026 wait_queue_head_t swi_queue;
33027 - atomic_t swi_emitted;
33028 + atomic_unchecked_t swi_emitted;
33029 int vblank_crtc;
33030 uint32_t irq_enable_reg;
33031 uint32_t r500_disp_irq_reg;
33032 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33033 index c180df8..cd80dd2d 100644
33034 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33035 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33036 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33037 request = compat_alloc_user_space(sizeof(*request));
33038 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33039 || __put_user(req32.param, &request->param)
33040 - || __put_user((void __user *)(unsigned long)req32.value,
33041 + || __put_user((unsigned long)req32.value,
33042 &request->value))
33043 return -EFAULT;
33044
33045 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33046 index e771033..a0bc6b3 100644
33047 --- a/drivers/gpu/drm/radeon/radeon_irq.c
33048 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
33049 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33050 unsigned int ret;
33051 RING_LOCALS;
33052
33053 - atomic_inc(&dev_priv->swi_emitted);
33054 - ret = atomic_read(&dev_priv->swi_emitted);
33055 + atomic_inc_unchecked(&dev_priv->swi_emitted);
33056 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33057
33058 BEGIN_RING(4);
33059 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33060 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33061 drm_radeon_private_t *dev_priv =
33062 (drm_radeon_private_t *) dev->dev_private;
33063
33064 - atomic_set(&dev_priv->swi_emitted, 0);
33065 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33066 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33067
33068 dev->max_vblank_count = 0x001fffff;
33069 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33070 index 8e9057b..af6dacb 100644
33071 --- a/drivers/gpu/drm/radeon/radeon_state.c
33072 +++ b/drivers/gpu/drm/radeon/radeon_state.c
33073 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33074 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33075 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33076
33077 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33078 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33079 sarea_priv->nbox * sizeof(depth_boxes[0])))
33080 return -EFAULT;
33081
33082 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33083 {
33084 drm_radeon_private_t *dev_priv = dev->dev_private;
33085 drm_radeon_getparam_t *param = data;
33086 - int value;
33087 + int value = 0;
33088
33089 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33090
33091 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33092 index 5ebe1b3..1ed9426 100644
33093 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
33094 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33095 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33096 }
33097 if (unlikely(ttm_vm_ops == NULL)) {
33098 ttm_vm_ops = vma->vm_ops;
33099 - radeon_ttm_vm_ops = *ttm_vm_ops;
33100 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33101 + pax_open_kernel();
33102 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
33103 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33104 + pax_close_kernel();
33105 }
33106 vma->vm_ops = &radeon_ttm_vm_ops;
33107 return 0;
33108 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33109 index 5706d2a..17aedaa 100644
33110 --- a/drivers/gpu/drm/radeon/rs690.c
33111 +++ b/drivers/gpu/drm/radeon/rs690.c
33112 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33113 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33114 rdev->pm.sideport_bandwidth.full)
33115 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33116 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33117 + read_delay_latency.full = dfixed_const(800 * 1000);
33118 read_delay_latency.full = dfixed_div(read_delay_latency,
33119 rdev->pm.igp_sideport_mclk);
33120 + a.full = dfixed_const(370);
33121 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33122 } else {
33123 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33124 rdev->pm.k8_bandwidth.full)
33125 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33126 index bd2a3b4..122d9ad 100644
33127 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33128 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33129 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33130 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33131 struct shrink_control *sc)
33132 {
33133 - static atomic_t start_pool = ATOMIC_INIT(0);
33134 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33135 unsigned i;
33136 - unsigned pool_offset = atomic_add_return(1, &start_pool);
33137 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33138 struct ttm_page_pool *pool;
33139 int shrink_pages = sc->nr_to_scan;
33140
33141 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33142 index 893a650..6190d3b 100644
33143 --- a/drivers/gpu/drm/via/via_drv.h
33144 +++ b/drivers/gpu/drm/via/via_drv.h
33145 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33146 typedef uint32_t maskarray_t[5];
33147
33148 typedef struct drm_via_irq {
33149 - atomic_t irq_received;
33150 + atomic_unchecked_t irq_received;
33151 uint32_t pending_mask;
33152 uint32_t enable_mask;
33153 wait_queue_head_t irq_queue;
33154 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
33155 struct timeval last_vblank;
33156 int last_vblank_valid;
33157 unsigned usec_per_vblank;
33158 - atomic_t vbl_received;
33159 + atomic_unchecked_t vbl_received;
33160 drm_via_state_t hc_state;
33161 char pci_buf[VIA_PCI_BUF_SIZE];
33162 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33163 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33164 index ac98964..5dbf512 100644
33165 --- a/drivers/gpu/drm/via/via_irq.c
33166 +++ b/drivers/gpu/drm/via/via_irq.c
33167 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33168 if (crtc != 0)
33169 return 0;
33170
33171 - return atomic_read(&dev_priv->vbl_received);
33172 + return atomic_read_unchecked(&dev_priv->vbl_received);
33173 }
33174
33175 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33176 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33177
33178 status = VIA_READ(VIA_REG_INTERRUPT);
33179 if (status & VIA_IRQ_VBLANK_PENDING) {
33180 - atomic_inc(&dev_priv->vbl_received);
33181 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33182 + atomic_inc_unchecked(&dev_priv->vbl_received);
33183 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33184 do_gettimeofday(&cur_vblank);
33185 if (dev_priv->last_vblank_valid) {
33186 dev_priv->usec_per_vblank =
33187 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33188 dev_priv->last_vblank = cur_vblank;
33189 dev_priv->last_vblank_valid = 1;
33190 }
33191 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33192 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33193 DRM_DEBUG("US per vblank is: %u\n",
33194 dev_priv->usec_per_vblank);
33195 }
33196 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33197
33198 for (i = 0; i < dev_priv->num_irqs; ++i) {
33199 if (status & cur_irq->pending_mask) {
33200 - atomic_inc(&cur_irq->irq_received);
33201 + atomic_inc_unchecked(&cur_irq->irq_received);
33202 DRM_WAKEUP(&cur_irq->irq_queue);
33203 handled = 1;
33204 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33205 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33206 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33207 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33208 masks[irq][4]));
33209 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33210 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33211 } else {
33212 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33213 (((cur_irq_sequence =
33214 - atomic_read(&cur_irq->irq_received)) -
33215 + atomic_read_unchecked(&cur_irq->irq_received)) -
33216 *sequence) <= (1 << 23)));
33217 }
33218 *sequence = cur_irq_sequence;
33219 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33220 }
33221
33222 for (i = 0; i < dev_priv->num_irqs; ++i) {
33223 - atomic_set(&cur_irq->irq_received, 0);
33224 + atomic_set_unchecked(&cur_irq->irq_received, 0);
33225 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33226 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33227 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33228 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33229 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33230 case VIA_IRQ_RELATIVE:
33231 irqwait->request.sequence +=
33232 - atomic_read(&cur_irq->irq_received);
33233 + atomic_read_unchecked(&cur_irq->irq_received);
33234 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33235 case VIA_IRQ_ABSOLUTE:
33236 break;
33237 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33238 index 88a179e..57fe50481c 100644
33239 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33240 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33241 @@ -263,7 +263,7 @@ struct vmw_private {
33242 * Fencing and IRQs.
33243 */
33244
33245 - atomic_t marker_seq;
33246 + atomic_unchecked_t marker_seq;
33247 wait_queue_head_t fence_queue;
33248 wait_queue_head_t fifo_queue;
33249 int fence_queue_waiters; /* Protected by hw_mutex */
33250 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33251 index 3eb1486..0a47ee9 100644
33252 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33253 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33254 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33255 (unsigned int) min,
33256 (unsigned int) fifo->capabilities);
33257
33258 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33259 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33260 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33261 vmw_marker_queue_init(&fifo->marker_queue);
33262 return vmw_fifo_send_fence(dev_priv, &dummy);
33263 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33264 if (reserveable)
33265 iowrite32(bytes, fifo_mem +
33266 SVGA_FIFO_RESERVED);
33267 - return fifo_mem + (next_cmd >> 2);
33268 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33269 } else {
33270 need_bounce = true;
33271 }
33272 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33273
33274 fm = vmw_fifo_reserve(dev_priv, bytes);
33275 if (unlikely(fm == NULL)) {
33276 - *seqno = atomic_read(&dev_priv->marker_seq);
33277 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33278 ret = -ENOMEM;
33279 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33280 false, 3*HZ);
33281 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33282 }
33283
33284 do {
33285 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33286 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33287 } while (*seqno == 0);
33288
33289 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33290 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33291 index 4640adb..e1384ed 100644
33292 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33293 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33294 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33295 * emitted. Then the fence is stale and signaled.
33296 */
33297
33298 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33299 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33300 > VMW_FENCE_WRAP);
33301
33302 return ret;
33303 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33304
33305 if (fifo_idle)
33306 down_read(&fifo_state->rwsem);
33307 - signal_seq = atomic_read(&dev_priv->marker_seq);
33308 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33309 ret = 0;
33310
33311 for (;;) {
33312 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33313 index 8a8725c..afed796 100644
33314 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33315 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33316 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33317 while (!vmw_lag_lt(queue, us)) {
33318 spin_lock(&queue->lock);
33319 if (list_empty(&queue->head))
33320 - seqno = atomic_read(&dev_priv->marker_seq);
33321 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33322 else {
33323 marker = list_first_entry(&queue->head,
33324 struct vmw_marker, head);
33325 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33326 index 52146db..ae33762 100644
33327 --- a/drivers/hid/hid-core.c
33328 +++ b/drivers/hid/hid-core.c
33329 @@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33330
33331 int hid_add_device(struct hid_device *hdev)
33332 {
33333 - static atomic_t id = ATOMIC_INIT(0);
33334 + static atomic_unchecked_t id = ATOMIC_INIT(0);
33335 int ret;
33336
33337 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33338 @@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33339 /* XXX hack, any other cleaner solution after the driver core
33340 * is converted to allow more than 20 bytes as the device name? */
33341 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33342 - hdev->vendor, hdev->product, atomic_inc_return(&id));
33343 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33344
33345 hid_debug_register(hdev, dev_name(&hdev->dev));
33346 ret = device_add(&hdev->dev);
33347 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33348 index eec3291..8ed706b 100644
33349 --- a/drivers/hid/hid-wiimote-debug.c
33350 +++ b/drivers/hid/hid-wiimote-debug.c
33351 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33352 else if (size == 0)
33353 return -EIO;
33354
33355 - if (copy_to_user(u, buf, size))
33356 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
33357 return -EFAULT;
33358
33359 *off += size;
33360 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33361 index 14599e2..711c965 100644
33362 --- a/drivers/hid/usbhid/hiddev.c
33363 +++ b/drivers/hid/usbhid/hiddev.c
33364 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33365 break;
33366
33367 case HIDIOCAPPLICATION:
33368 - if (arg < 0 || arg >= hid->maxapplication)
33369 + if (arg >= hid->maxapplication)
33370 break;
33371
33372 for (i = 0; i < hid->maxcollection; i++)
33373 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33374 index f4c3d28..82f45a9 100644
33375 --- a/drivers/hv/channel.c
33376 +++ b/drivers/hv/channel.c
33377 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33378 int ret = 0;
33379 int t;
33380
33381 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33382 - atomic_inc(&vmbus_connection.next_gpadl_handle);
33383 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33384 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33385
33386 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33387 if (ret)
33388 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33389 index 3648f8f..30ef30d 100644
33390 --- a/drivers/hv/hv.c
33391 +++ b/drivers/hv/hv.c
33392 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33393 u64 output_address = (output) ? virt_to_phys(output) : 0;
33394 u32 output_address_hi = output_address >> 32;
33395 u32 output_address_lo = output_address & 0xFFFFFFFF;
33396 - void *hypercall_page = hv_context.hypercall_page;
33397 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33398
33399 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33400 "=a"(hv_status_lo) : "d" (control_hi),
33401 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33402 index d8d1fad..b91caf7 100644
33403 --- a/drivers/hv/hyperv_vmbus.h
33404 +++ b/drivers/hv/hyperv_vmbus.h
33405 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
33406 struct vmbus_connection {
33407 enum vmbus_connect_state conn_state;
33408
33409 - atomic_t next_gpadl_handle;
33410 + atomic_unchecked_t next_gpadl_handle;
33411
33412 /*
33413 * Represents channel interrupts. Each bit position represents a
33414 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33415 index 8e1a9ec..4687821 100644
33416 --- a/drivers/hv/vmbus_drv.c
33417 +++ b/drivers/hv/vmbus_drv.c
33418 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33419 {
33420 int ret = 0;
33421
33422 - static atomic_t device_num = ATOMIC_INIT(0);
33423 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33424
33425 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33426 - atomic_inc_return(&device_num));
33427 + atomic_inc_return_unchecked(&device_num));
33428
33429 child_device_obj->device.bus = &hv_bus;
33430 child_device_obj->device.parent = &hv_acpi_dev->dev;
33431 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33432 index 07a0c1a..0cac334 100644
33433 --- a/drivers/hwmon/sht15.c
33434 +++ b/drivers/hwmon/sht15.c
33435 @@ -169,7 +169,7 @@ struct sht15_data {
33436 int supply_uV;
33437 bool supply_uV_valid;
33438 struct work_struct update_supply_work;
33439 - atomic_t interrupt_handled;
33440 + atomic_unchecked_t interrupt_handled;
33441 };
33442
33443 /**
33444 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33445 return ret;
33446
33447 gpio_direction_input(data->pdata->gpio_data);
33448 - atomic_set(&data->interrupt_handled, 0);
33449 + atomic_set_unchecked(&data->interrupt_handled, 0);
33450
33451 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33452 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33453 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33454 /* Only relevant if the interrupt hasn't occurred. */
33455 - if (!atomic_read(&data->interrupt_handled))
33456 + if (!atomic_read_unchecked(&data->interrupt_handled))
33457 schedule_work(&data->read_work);
33458 }
33459 ret = wait_event_timeout(data->wait_queue,
33460 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33461
33462 /* First disable the interrupt */
33463 disable_irq_nosync(irq);
33464 - atomic_inc(&data->interrupt_handled);
33465 + atomic_inc_unchecked(&data->interrupt_handled);
33466 /* Then schedule a reading work struct */
33467 if (data->state != SHT15_READING_NOTHING)
33468 schedule_work(&data->read_work);
33469 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33470 * If not, then start the interrupt again - care here as could
33471 * have gone low in meantime so verify it hasn't!
33472 */
33473 - atomic_set(&data->interrupt_handled, 0);
33474 + atomic_set_unchecked(&data->interrupt_handled, 0);
33475 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33476 /* If still not occurred or another handler was scheduled */
33477 if (gpio_get_value(data->pdata->gpio_data)
33478 - || atomic_read(&data->interrupt_handled))
33479 + || atomic_read_unchecked(&data->interrupt_handled))
33480 return;
33481 }
33482
33483 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33484 index 378fcb5..5e91fa8 100644
33485 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
33486 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33487 @@ -43,7 +43,7 @@
33488 extern struct i2c_adapter amd756_smbus;
33489
33490 static struct i2c_adapter *s4882_adapter;
33491 -static struct i2c_algorithm *s4882_algo;
33492 +static i2c_algorithm_no_const *s4882_algo;
33493
33494 /* Wrapper access functions for multiplexed SMBus */
33495 static DEFINE_MUTEX(amd756_lock);
33496 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33497 index 29015eb..af2d8e9 100644
33498 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33499 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33500 @@ -41,7 +41,7 @@
33501 extern struct i2c_adapter *nforce2_smbus;
33502
33503 static struct i2c_adapter *s4985_adapter;
33504 -static struct i2c_algorithm *s4985_algo;
33505 +static i2c_algorithm_no_const *s4985_algo;
33506
33507 /* Wrapper access functions for multiplexed SMBus */
33508 static DEFINE_MUTEX(nforce2_lock);
33509 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33510 index 8126824..55a2798 100644
33511 --- a/drivers/ide/ide-cd.c
33512 +++ b/drivers/ide/ide-cd.c
33513 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33514 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33515 if ((unsigned long)buf & alignment
33516 || blk_rq_bytes(rq) & q->dma_pad_mask
33517 - || object_is_on_stack(buf))
33518 + || object_starts_on_stack(buf))
33519 drive->dma = 0;
33520 }
33521 }
33522 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33523 index 394fea2..c833880 100644
33524 --- a/drivers/infiniband/core/cm.c
33525 +++ b/drivers/infiniband/core/cm.c
33526 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33527
33528 struct cm_counter_group {
33529 struct kobject obj;
33530 - atomic_long_t counter[CM_ATTR_COUNT];
33531 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33532 };
33533
33534 struct cm_counter_attribute {
33535 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33536 struct ib_mad_send_buf *msg = NULL;
33537 int ret;
33538
33539 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33540 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33541 counter[CM_REQ_COUNTER]);
33542
33543 /* Quick state check to discard duplicate REQs. */
33544 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33545 if (!cm_id_priv)
33546 return;
33547
33548 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33549 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33550 counter[CM_REP_COUNTER]);
33551 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33552 if (ret)
33553 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33554 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33555 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33556 spin_unlock_irq(&cm_id_priv->lock);
33557 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33558 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33559 counter[CM_RTU_COUNTER]);
33560 goto out;
33561 }
33562 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33563 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33564 dreq_msg->local_comm_id);
33565 if (!cm_id_priv) {
33566 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33567 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33568 counter[CM_DREQ_COUNTER]);
33569 cm_issue_drep(work->port, work->mad_recv_wc);
33570 return -EINVAL;
33571 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33572 case IB_CM_MRA_REP_RCVD:
33573 break;
33574 case IB_CM_TIMEWAIT:
33575 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33576 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33577 counter[CM_DREQ_COUNTER]);
33578 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33579 goto unlock;
33580 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33581 cm_free_msg(msg);
33582 goto deref;
33583 case IB_CM_DREQ_RCVD:
33584 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33585 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33586 counter[CM_DREQ_COUNTER]);
33587 goto unlock;
33588 default:
33589 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33590 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33591 cm_id_priv->msg, timeout)) {
33592 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33593 - atomic_long_inc(&work->port->
33594 + atomic_long_inc_unchecked(&work->port->
33595 counter_group[CM_RECV_DUPLICATES].
33596 counter[CM_MRA_COUNTER]);
33597 goto out;
33598 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33599 break;
33600 case IB_CM_MRA_REQ_RCVD:
33601 case IB_CM_MRA_REP_RCVD:
33602 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33603 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33604 counter[CM_MRA_COUNTER]);
33605 /* fall through */
33606 default:
33607 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33608 case IB_CM_LAP_IDLE:
33609 break;
33610 case IB_CM_MRA_LAP_SENT:
33611 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33612 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33613 counter[CM_LAP_COUNTER]);
33614 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33615 goto unlock;
33616 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33617 cm_free_msg(msg);
33618 goto deref;
33619 case IB_CM_LAP_RCVD:
33620 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33621 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33622 counter[CM_LAP_COUNTER]);
33623 goto unlock;
33624 default:
33625 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33626 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
33627 if (cur_cm_id_priv) {
33628 spin_unlock_irq(&cm.lock);
33629 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33630 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33631 counter[CM_SIDR_REQ_COUNTER]);
33632 goto out; /* Duplicate message. */
33633 }
33634 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
33635 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
33636 msg->retries = 1;
33637
33638 - atomic_long_add(1 + msg->retries,
33639 + atomic_long_add_unchecked(1 + msg->retries,
33640 &port->counter_group[CM_XMIT].counter[attr_index]);
33641 if (msg->retries)
33642 - atomic_long_add(msg->retries,
33643 + atomic_long_add_unchecked(msg->retries,
33644 &port->counter_group[CM_XMIT_RETRIES].
33645 counter[attr_index]);
33646
33647 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
33648 }
33649
33650 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
33651 - atomic_long_inc(&port->counter_group[CM_RECV].
33652 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
33653 counter[attr_id - CM_ATTR_ID_OFFSET]);
33654
33655 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
33656 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
33657 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
33658
33659 return sprintf(buf, "%ld\n",
33660 - atomic_long_read(&group->counter[cm_attr->index]));
33661 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
33662 }
33663
33664 static const struct sysfs_ops cm_counter_ops = {
33665 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
33666 index 176c8f9..2627b62 100644
33667 --- a/drivers/infiniband/core/fmr_pool.c
33668 +++ b/drivers/infiniband/core/fmr_pool.c
33669 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
33670
33671 struct task_struct *thread;
33672
33673 - atomic_t req_ser;
33674 - atomic_t flush_ser;
33675 + atomic_unchecked_t req_ser;
33676 + atomic_unchecked_t flush_ser;
33677
33678 wait_queue_head_t force_wait;
33679 };
33680 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33681 struct ib_fmr_pool *pool = pool_ptr;
33682
33683 do {
33684 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
33685 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
33686 ib_fmr_batch_release(pool);
33687
33688 - atomic_inc(&pool->flush_ser);
33689 + atomic_inc_unchecked(&pool->flush_ser);
33690 wake_up_interruptible(&pool->force_wait);
33691
33692 if (pool->flush_function)
33693 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33694 }
33695
33696 set_current_state(TASK_INTERRUPTIBLE);
33697 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
33698 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
33699 !kthread_should_stop())
33700 schedule();
33701 __set_current_state(TASK_RUNNING);
33702 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
33703 pool->dirty_watermark = params->dirty_watermark;
33704 pool->dirty_len = 0;
33705 spin_lock_init(&pool->pool_lock);
33706 - atomic_set(&pool->req_ser, 0);
33707 - atomic_set(&pool->flush_ser, 0);
33708 + atomic_set_unchecked(&pool->req_ser, 0);
33709 + atomic_set_unchecked(&pool->flush_ser, 0);
33710 init_waitqueue_head(&pool->force_wait);
33711
33712 pool->thread = kthread_run(ib_fmr_cleanup_thread,
33713 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
33714 }
33715 spin_unlock_irq(&pool->pool_lock);
33716
33717 - serial = atomic_inc_return(&pool->req_ser);
33718 + serial = atomic_inc_return_unchecked(&pool->req_ser);
33719 wake_up_process(pool->thread);
33720
33721 if (wait_event_interruptible(pool->force_wait,
33722 - atomic_read(&pool->flush_ser) - serial >= 0))
33723 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
33724 return -EINTR;
33725
33726 return 0;
33727 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
33728 } else {
33729 list_add_tail(&fmr->list, &pool->dirty_list);
33730 if (++pool->dirty_len >= pool->dirty_watermark) {
33731 - atomic_inc(&pool->req_ser);
33732 + atomic_inc_unchecked(&pool->req_ser);
33733 wake_up_process(pool->thread);
33734 }
33735 }
33736 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
33737 index afd8179..598063f 100644
33738 --- a/drivers/infiniband/hw/cxgb4/mem.c
33739 +++ b/drivers/infiniband/hw/cxgb4/mem.c
33740 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
33741 int err;
33742 struct fw_ri_tpte tpt;
33743 u32 stag_idx;
33744 - static atomic_t key;
33745 + static atomic_unchecked_t key;
33746
33747 if (c4iw_fatal_error(rdev))
33748 return -EIO;
33749 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
33750 if (rdev->stats.stag.cur > rdev->stats.stag.max)
33751 rdev->stats.stag.max = rdev->stats.stag.cur;
33752 mutex_unlock(&rdev->stats.lock);
33753 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
33754 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
33755 }
33756 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
33757 __func__, stag_state, type, pdid, stag_idx);
33758 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
33759 index 79b3dbc..96e5fcc 100644
33760 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
33761 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
33762 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
33763 struct ib_atomic_eth *ateth;
33764 struct ipath_ack_entry *e;
33765 u64 vaddr;
33766 - atomic64_t *maddr;
33767 + atomic64_unchecked_t *maddr;
33768 u64 sdata;
33769 u32 rkey;
33770 u8 next;
33771 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
33772 IB_ACCESS_REMOTE_ATOMIC)))
33773 goto nack_acc_unlck;
33774 /* Perform atomic OP and save result. */
33775 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
33776 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
33777 sdata = be64_to_cpu(ateth->swap_data);
33778 e = &qp->s_ack_queue[qp->r_head_ack_queue];
33779 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
33780 - (u64) atomic64_add_return(sdata, maddr) - sdata :
33781 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
33782 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
33783 be64_to_cpu(ateth->compare_data),
33784 sdata);
33785 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
33786 index 1f95bba..9530f87 100644
33787 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
33788 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
33789 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
33790 unsigned long flags;
33791 struct ib_wc wc;
33792 u64 sdata;
33793 - atomic64_t *maddr;
33794 + atomic64_unchecked_t *maddr;
33795 enum ib_wc_status send_status;
33796
33797 /*
33798 @@ -382,11 +382,11 @@ again:
33799 IB_ACCESS_REMOTE_ATOMIC)))
33800 goto acc_err;
33801 /* Perform atomic OP and save result. */
33802 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
33803 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
33804 sdata = wqe->wr.wr.atomic.compare_add;
33805 *(u64 *) sqp->s_sge.sge.vaddr =
33806 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
33807 - (u64) atomic64_add_return(sdata, maddr) - sdata :
33808 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
33809 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
33810 sdata, wqe->wr.wr.atomic.swap);
33811 goto send_comp;
33812 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
33813 index 748db2d..5f75cc3 100644
33814 --- a/drivers/infiniband/hw/nes/nes.c
33815 +++ b/drivers/infiniband/hw/nes/nes.c
33816 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
33817 LIST_HEAD(nes_adapter_list);
33818 static LIST_HEAD(nes_dev_list);
33819
33820 -atomic_t qps_destroyed;
33821 +atomic_unchecked_t qps_destroyed;
33822
33823 static unsigned int ee_flsh_adapter;
33824 static unsigned int sysfs_nonidx_addr;
33825 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
33826 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
33827 struct nes_adapter *nesadapter = nesdev->nesadapter;
33828
33829 - atomic_inc(&qps_destroyed);
33830 + atomic_inc_unchecked(&qps_destroyed);
33831
33832 /* Free the control structures */
33833
33834 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
33835 index 33cc589..3bd6538 100644
33836 --- a/drivers/infiniband/hw/nes/nes.h
33837 +++ b/drivers/infiniband/hw/nes/nes.h
33838 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
33839 extern unsigned int wqm_quanta;
33840 extern struct list_head nes_adapter_list;
33841
33842 -extern atomic_t cm_connects;
33843 -extern atomic_t cm_accepts;
33844 -extern atomic_t cm_disconnects;
33845 -extern atomic_t cm_closes;
33846 -extern atomic_t cm_connecteds;
33847 -extern atomic_t cm_connect_reqs;
33848 -extern atomic_t cm_rejects;
33849 -extern atomic_t mod_qp_timouts;
33850 -extern atomic_t qps_created;
33851 -extern atomic_t qps_destroyed;
33852 -extern atomic_t sw_qps_destroyed;
33853 +extern atomic_unchecked_t cm_connects;
33854 +extern atomic_unchecked_t cm_accepts;
33855 +extern atomic_unchecked_t cm_disconnects;
33856 +extern atomic_unchecked_t cm_closes;
33857 +extern atomic_unchecked_t cm_connecteds;
33858 +extern atomic_unchecked_t cm_connect_reqs;
33859 +extern atomic_unchecked_t cm_rejects;
33860 +extern atomic_unchecked_t mod_qp_timouts;
33861 +extern atomic_unchecked_t qps_created;
33862 +extern atomic_unchecked_t qps_destroyed;
33863 +extern atomic_unchecked_t sw_qps_destroyed;
33864 extern u32 mh_detected;
33865 extern u32 mh_pauses_sent;
33866 extern u32 cm_packets_sent;
33867 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
33868 extern u32 cm_packets_received;
33869 extern u32 cm_packets_dropped;
33870 extern u32 cm_packets_retrans;
33871 -extern atomic_t cm_listens_created;
33872 -extern atomic_t cm_listens_destroyed;
33873 +extern atomic_unchecked_t cm_listens_created;
33874 +extern atomic_unchecked_t cm_listens_destroyed;
33875 extern u32 cm_backlog_drops;
33876 -extern atomic_t cm_loopbacks;
33877 -extern atomic_t cm_nodes_created;
33878 -extern atomic_t cm_nodes_destroyed;
33879 -extern atomic_t cm_accel_dropped_pkts;
33880 -extern atomic_t cm_resets_recvd;
33881 -extern atomic_t pau_qps_created;
33882 -extern atomic_t pau_qps_destroyed;
33883 +extern atomic_unchecked_t cm_loopbacks;
33884 +extern atomic_unchecked_t cm_nodes_created;
33885 +extern atomic_unchecked_t cm_nodes_destroyed;
33886 +extern atomic_unchecked_t cm_accel_dropped_pkts;
33887 +extern atomic_unchecked_t cm_resets_recvd;
33888 +extern atomic_unchecked_t pau_qps_created;
33889 +extern atomic_unchecked_t pau_qps_destroyed;
33890
33891 extern u32 int_mod_timer_init;
33892 extern u32 int_mod_cq_depth_256;
33893 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
33894 index cfaacaf..fa0722e 100644
33895 --- a/drivers/infiniband/hw/nes/nes_cm.c
33896 +++ b/drivers/infiniband/hw/nes/nes_cm.c
33897 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
33898 u32 cm_packets_retrans;
33899 u32 cm_packets_created;
33900 u32 cm_packets_received;
33901 -atomic_t cm_listens_created;
33902 -atomic_t cm_listens_destroyed;
33903 +atomic_unchecked_t cm_listens_created;
33904 +atomic_unchecked_t cm_listens_destroyed;
33905 u32 cm_backlog_drops;
33906 -atomic_t cm_loopbacks;
33907 -atomic_t cm_nodes_created;
33908 -atomic_t cm_nodes_destroyed;
33909 -atomic_t cm_accel_dropped_pkts;
33910 -atomic_t cm_resets_recvd;
33911 +atomic_unchecked_t cm_loopbacks;
33912 +atomic_unchecked_t cm_nodes_created;
33913 +atomic_unchecked_t cm_nodes_destroyed;
33914 +atomic_unchecked_t cm_accel_dropped_pkts;
33915 +atomic_unchecked_t cm_resets_recvd;
33916
33917 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
33918 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
33919 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
33920
33921 static struct nes_cm_core *g_cm_core;
33922
33923 -atomic_t cm_connects;
33924 -atomic_t cm_accepts;
33925 -atomic_t cm_disconnects;
33926 -atomic_t cm_closes;
33927 -atomic_t cm_connecteds;
33928 -atomic_t cm_connect_reqs;
33929 -atomic_t cm_rejects;
33930 +atomic_unchecked_t cm_connects;
33931 +atomic_unchecked_t cm_accepts;
33932 +atomic_unchecked_t cm_disconnects;
33933 +atomic_unchecked_t cm_closes;
33934 +atomic_unchecked_t cm_connecteds;
33935 +atomic_unchecked_t cm_connect_reqs;
33936 +atomic_unchecked_t cm_rejects;
33937
33938 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
33939 {
33940 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
33941 kfree(listener);
33942 listener = NULL;
33943 ret = 0;
33944 - atomic_inc(&cm_listens_destroyed);
33945 + atomic_inc_unchecked(&cm_listens_destroyed);
33946 } else {
33947 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
33948 }
33949 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
33950 cm_node->rem_mac);
33951
33952 add_hte_node(cm_core, cm_node);
33953 - atomic_inc(&cm_nodes_created);
33954 + atomic_inc_unchecked(&cm_nodes_created);
33955
33956 return cm_node;
33957 }
33958 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
33959 }
33960
33961 atomic_dec(&cm_core->node_cnt);
33962 - atomic_inc(&cm_nodes_destroyed);
33963 + atomic_inc_unchecked(&cm_nodes_destroyed);
33964 nesqp = cm_node->nesqp;
33965 if (nesqp) {
33966 nesqp->cm_node = NULL;
33967 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
33968
33969 static void drop_packet(struct sk_buff *skb)
33970 {
33971 - atomic_inc(&cm_accel_dropped_pkts);
33972 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
33973 dev_kfree_skb_any(skb);
33974 }
33975
33976 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
33977 {
33978
33979 int reset = 0; /* whether to send reset in case of err.. */
33980 - atomic_inc(&cm_resets_recvd);
33981 + atomic_inc_unchecked(&cm_resets_recvd);
33982 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
33983 " refcnt=%d\n", cm_node, cm_node->state,
33984 atomic_read(&cm_node->ref_count));
33985 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
33986 rem_ref_cm_node(cm_node->cm_core, cm_node);
33987 return NULL;
33988 }
33989 - atomic_inc(&cm_loopbacks);
33990 + atomic_inc_unchecked(&cm_loopbacks);
33991 loopbackremotenode->loopbackpartner = cm_node;
33992 loopbackremotenode->tcp_cntxt.rcv_wscale =
33993 NES_CM_DEFAULT_RCV_WND_SCALE;
33994 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
33995 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
33996 else {
33997 rem_ref_cm_node(cm_core, cm_node);
33998 - atomic_inc(&cm_accel_dropped_pkts);
33999 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34000 dev_kfree_skb_any(skb);
34001 }
34002 break;
34003 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34004
34005 if ((cm_id) && (cm_id->event_handler)) {
34006 if (issue_disconn) {
34007 - atomic_inc(&cm_disconnects);
34008 + atomic_inc_unchecked(&cm_disconnects);
34009 cm_event.event = IW_CM_EVENT_DISCONNECT;
34010 cm_event.status = disconn_status;
34011 cm_event.local_addr = cm_id->local_addr;
34012 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34013 }
34014
34015 if (issue_close) {
34016 - atomic_inc(&cm_closes);
34017 + atomic_inc_unchecked(&cm_closes);
34018 nes_disconnect(nesqp, 1);
34019
34020 cm_id->provider_data = nesqp;
34021 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34022
34023 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
34024 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
34025 - atomic_inc(&cm_accepts);
34026 + atomic_inc_unchecked(&cm_accepts);
34027
34028 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
34029 netdev_refcnt_read(nesvnic->netdev));
34030 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
34031 struct nes_cm_core *cm_core;
34032 u8 *start_buff;
34033
34034 - atomic_inc(&cm_rejects);
34035 + atomic_inc_unchecked(&cm_rejects);
34036 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34037 loopback = cm_node->loopbackpartner;
34038 cm_core = cm_node->cm_core;
34039 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34040 ntohl(cm_id->local_addr.sin_addr.s_addr),
34041 ntohs(cm_id->local_addr.sin_port));
34042
34043 - atomic_inc(&cm_connects);
34044 + atomic_inc_unchecked(&cm_connects);
34045 nesqp->active_conn = 1;
34046
34047 /* cache the cm_id in the qp */
34048 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34049 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34050 return err;
34051 }
34052 - atomic_inc(&cm_listens_created);
34053 + atomic_inc_unchecked(&cm_listens_created);
34054 }
34055
34056 cm_id->add_ref(cm_id);
34057 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34058
34059 if (nesqp->destroyed)
34060 return;
34061 - atomic_inc(&cm_connecteds);
34062 + atomic_inc_unchecked(&cm_connecteds);
34063 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34064 " local port 0x%04X. jiffies = %lu.\n",
34065 nesqp->hwqp.qp_id,
34066 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34067
34068 cm_id->add_ref(cm_id);
34069 ret = cm_id->event_handler(cm_id, &cm_event);
34070 - atomic_inc(&cm_closes);
34071 + atomic_inc_unchecked(&cm_closes);
34072 cm_event.event = IW_CM_EVENT_CLOSE;
34073 cm_event.status = 0;
34074 cm_event.provider_data = cm_id->provider_data;
34075 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34076 return;
34077 cm_id = cm_node->cm_id;
34078
34079 - atomic_inc(&cm_connect_reqs);
34080 + atomic_inc_unchecked(&cm_connect_reqs);
34081 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34082 cm_node, cm_id, jiffies);
34083
34084 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34085 return;
34086 cm_id = cm_node->cm_id;
34087
34088 - atomic_inc(&cm_connect_reqs);
34089 + atomic_inc_unchecked(&cm_connect_reqs);
34090 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34091 cm_node, cm_id, jiffies);
34092
34093 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34094 index 3ba7be3..c81f6ff 100644
34095 --- a/drivers/infiniband/hw/nes/nes_mgt.c
34096 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
34097 @@ -40,8 +40,8 @@
34098 #include "nes.h"
34099 #include "nes_mgt.h"
34100
34101 -atomic_t pau_qps_created;
34102 -atomic_t pau_qps_destroyed;
34103 +atomic_unchecked_t pau_qps_created;
34104 +atomic_unchecked_t pau_qps_destroyed;
34105
34106 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34107 {
34108 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34109 {
34110 struct sk_buff *skb;
34111 unsigned long flags;
34112 - atomic_inc(&pau_qps_destroyed);
34113 + atomic_inc_unchecked(&pau_qps_destroyed);
34114
34115 /* Free packets that have not yet been forwarded */
34116 /* Lock is acquired by skb_dequeue when removing the skb */
34117 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34118 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34119 skb_queue_head_init(&nesqp->pau_list);
34120 spin_lock_init(&nesqp->pau_lock);
34121 - atomic_inc(&pau_qps_created);
34122 + atomic_inc_unchecked(&pau_qps_created);
34123 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34124 }
34125
34126 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34127 index 0564be7..f68b0f1 100644
34128 --- a/drivers/infiniband/hw/nes/nes_nic.c
34129 +++ b/drivers/infiniband/hw/nes/nes_nic.c
34130 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34131 target_stat_values[++index] = mh_detected;
34132 target_stat_values[++index] = mh_pauses_sent;
34133 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34134 - target_stat_values[++index] = atomic_read(&cm_connects);
34135 - target_stat_values[++index] = atomic_read(&cm_accepts);
34136 - target_stat_values[++index] = atomic_read(&cm_disconnects);
34137 - target_stat_values[++index] = atomic_read(&cm_connecteds);
34138 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34139 - target_stat_values[++index] = atomic_read(&cm_rejects);
34140 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34141 - target_stat_values[++index] = atomic_read(&qps_created);
34142 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34143 - target_stat_values[++index] = atomic_read(&qps_destroyed);
34144 - target_stat_values[++index] = atomic_read(&cm_closes);
34145 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34146 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34147 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34148 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34149 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34150 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34151 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34152 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34153 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34154 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34155 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34156 target_stat_values[++index] = cm_packets_sent;
34157 target_stat_values[++index] = cm_packets_bounced;
34158 target_stat_values[++index] = cm_packets_created;
34159 target_stat_values[++index] = cm_packets_received;
34160 target_stat_values[++index] = cm_packets_dropped;
34161 target_stat_values[++index] = cm_packets_retrans;
34162 - target_stat_values[++index] = atomic_read(&cm_listens_created);
34163 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34164 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34165 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34166 target_stat_values[++index] = cm_backlog_drops;
34167 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
34168 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
34169 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34170 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34171 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34172 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34173 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34174 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34175 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34176 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34177 target_stat_values[++index] = nesadapter->free_4kpbl;
34178 target_stat_values[++index] = nesadapter->free_256pbl;
34179 target_stat_values[++index] = int_mod_timer_init;
34180 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34181 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34182 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34183 - target_stat_values[++index] = atomic_read(&pau_qps_created);
34184 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34185 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34186 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34187 }
34188
34189 /**
34190 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34191 index 07e4fba..685f041 100644
34192 --- a/drivers/infiniband/hw/nes/nes_verbs.c
34193 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
34194 @@ -46,9 +46,9 @@
34195
34196 #include <rdma/ib_umem.h>
34197
34198 -atomic_t mod_qp_timouts;
34199 -atomic_t qps_created;
34200 -atomic_t sw_qps_destroyed;
34201 +atomic_unchecked_t mod_qp_timouts;
34202 +atomic_unchecked_t qps_created;
34203 +atomic_unchecked_t sw_qps_destroyed;
34204
34205 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34206
34207 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34208 if (init_attr->create_flags)
34209 return ERR_PTR(-EINVAL);
34210
34211 - atomic_inc(&qps_created);
34212 + atomic_inc_unchecked(&qps_created);
34213 switch (init_attr->qp_type) {
34214 case IB_QPT_RC:
34215 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34216 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34217 struct iw_cm_event cm_event;
34218 int ret = 0;
34219
34220 - atomic_inc(&sw_qps_destroyed);
34221 + atomic_inc_unchecked(&sw_qps_destroyed);
34222 nesqp->destroyed = 1;
34223
34224 /* Blow away the connection if it exists. */
34225 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34226 index 4d11575..3e890e5 100644
34227 --- a/drivers/infiniband/hw/qib/qib.h
34228 +++ b/drivers/infiniband/hw/qib/qib.h
34229 @@ -51,6 +51,7 @@
34230 #include <linux/completion.h>
34231 #include <linux/kref.h>
34232 #include <linux/sched.h>
34233 +#include <linux/slab.h>
34234
34235 #include "qib_common.h"
34236 #include "qib_verbs.h"
34237 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34238 index da739d9..da1c7f4 100644
34239 --- a/drivers/input/gameport/gameport.c
34240 +++ b/drivers/input/gameport/gameport.c
34241 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34242 */
34243 static void gameport_init_port(struct gameport *gameport)
34244 {
34245 - static atomic_t gameport_no = ATOMIC_INIT(0);
34246 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34247
34248 __module_get(THIS_MODULE);
34249
34250 mutex_init(&gameport->drv_mutex);
34251 device_initialize(&gameport->dev);
34252 dev_set_name(&gameport->dev, "gameport%lu",
34253 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
34254 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34255 gameport->dev.bus = &gameport_bus;
34256 gameport->dev.release = gameport_release_port;
34257 if (gameport->parent)
34258 diff --git a/drivers/input/input.c b/drivers/input/input.c
34259 index 53a0dde..abffda7 100644
34260 --- a/drivers/input/input.c
34261 +++ b/drivers/input/input.c
34262 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34263 */
34264 int input_register_device(struct input_dev *dev)
34265 {
34266 - static atomic_t input_no = ATOMIC_INIT(0);
34267 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34268 struct input_handler *handler;
34269 unsigned int packet_size;
34270 const char *path;
34271 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34272 dev->setkeycode = input_default_setkeycode;
34273
34274 dev_set_name(&dev->dev, "input%ld",
34275 - (unsigned long) atomic_inc_return(&input_no) - 1);
34276 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34277
34278 error = device_add(&dev->dev);
34279 if (error)
34280 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34281 index 04c69af..5f92d00 100644
34282 --- a/drivers/input/joystick/sidewinder.c
34283 +++ b/drivers/input/joystick/sidewinder.c
34284 @@ -30,6 +30,7 @@
34285 #include <linux/kernel.h>
34286 #include <linux/module.h>
34287 #include <linux/slab.h>
34288 +#include <linux/sched.h>
34289 #include <linux/init.h>
34290 #include <linux/input.h>
34291 #include <linux/gameport.h>
34292 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34293 index 83811e4..0822b90 100644
34294 --- a/drivers/input/joystick/xpad.c
34295 +++ b/drivers/input/joystick/xpad.c
34296 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34297
34298 static int xpad_led_probe(struct usb_xpad *xpad)
34299 {
34300 - static atomic_t led_seq = ATOMIC_INIT(0);
34301 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34302 long led_no;
34303 struct xpad_led *led;
34304 struct led_classdev *led_cdev;
34305 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34306 if (!led)
34307 return -ENOMEM;
34308
34309 - led_no = (long)atomic_inc_return(&led_seq) - 1;
34310 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34311
34312 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34313 led->xpad = xpad;
34314 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34315 index 4c842c3..590b0bf 100644
34316 --- a/drivers/input/mousedev.c
34317 +++ b/drivers/input/mousedev.c
34318 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34319
34320 spin_unlock_irq(&client->packet_lock);
34321
34322 - if (copy_to_user(buffer, data, count))
34323 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
34324 return -EFAULT;
34325
34326 return count;
34327 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34328 index d0f7533..fb8215b 100644
34329 --- a/drivers/input/serio/serio.c
34330 +++ b/drivers/input/serio/serio.c
34331 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34332 */
34333 static void serio_init_port(struct serio *serio)
34334 {
34335 - static atomic_t serio_no = ATOMIC_INIT(0);
34336 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34337
34338 __module_get(THIS_MODULE);
34339
34340 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34341 mutex_init(&serio->drv_mutex);
34342 device_initialize(&serio->dev);
34343 dev_set_name(&serio->dev, "serio%ld",
34344 - (long)atomic_inc_return(&serio_no) - 1);
34345 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
34346 serio->dev.bus = &serio_bus;
34347 serio->dev.release = serio_release_port;
34348 serio->dev.groups = serio_device_attr_groups;
34349 diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
34350 index 81837b0..d7470e8 100644
34351 --- a/drivers/iommu/amd_iommu_init.c
34352 +++ b/drivers/iommu/amd_iommu_init.c
34353 @@ -1888,7 +1888,7 @@ static int __init state_next(void)
34354 case IOMMU_ACPI_FINISHED:
34355 early_enable_iommus();
34356 register_syscore_ops(&amd_iommu_syscore_ops);
34357 - x86_platform.iommu_shutdown = disable_iommus;
34358 + *(void **)&x86_platform.iommu_shutdown = disable_iommus;
34359 init_state = IOMMU_ENABLED;
34360 break;
34361 case IOMMU_ENABLED:
34362 @@ -2030,7 +2030,7 @@ int __init amd_iommu_detect(void)
34363
34364 amd_iommu_detected = true;
34365 iommu_detected = 1;
34366 - x86_init.iommu.iommu_init = amd_iommu_init;
34367 + *(void **)&x86_init.iommu.iommu_init = amd_iommu_init;
34368
34369 return 0;
34370 }
34371 diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
34372 index 86e2f4a..d1cec5d 100644
34373 --- a/drivers/iommu/dmar.c
34374 +++ b/drivers/iommu/dmar.c
34375 @@ -555,7 +555,7 @@ int __init detect_intel_iommu(void)
34376
34377 #ifdef CONFIG_X86
34378 if (ret)
34379 - x86_init.iommu.iommu_init = intel_iommu_init;
34380 + *(void **)&x86_init.iommu.iommu_init = intel_iommu_init;
34381 #endif
34382 }
34383 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
34384 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34385 index c679867..6e2e34d 100644
34386 --- a/drivers/isdn/capi/capi.c
34387 +++ b/drivers/isdn/capi/capi.c
34388 @@ -83,8 +83,8 @@ struct capiminor {
34389
34390 struct capi20_appl *ap;
34391 u32 ncci;
34392 - atomic_t datahandle;
34393 - atomic_t msgid;
34394 + atomic_unchecked_t datahandle;
34395 + atomic_unchecked_t msgid;
34396
34397 struct tty_port port;
34398 int ttyinstop;
34399 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34400 capimsg_setu16(s, 2, mp->ap->applid);
34401 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34402 capimsg_setu8 (s, 5, CAPI_RESP);
34403 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34404 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34405 capimsg_setu32(s, 8, mp->ncci);
34406 capimsg_setu16(s, 12, datahandle);
34407 }
34408 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34409 mp->outbytes -= len;
34410 spin_unlock_bh(&mp->outlock);
34411
34412 - datahandle = atomic_inc_return(&mp->datahandle);
34413 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34414 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34415 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34416 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34417 capimsg_setu16(skb->data, 2, mp->ap->applid);
34418 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34419 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34420 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34421 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34422 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34423 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34424 capimsg_setu16(skb->data, 16, len); /* Data length */
34425 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34426 index 67abf3f..076b3a6 100644
34427 --- a/drivers/isdn/gigaset/interface.c
34428 +++ b/drivers/isdn/gigaset/interface.c
34429 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34430 }
34431 tty->driver_data = cs;
34432
34433 - ++cs->port.count;
34434 + atomic_inc(&cs->port.count);
34435
34436 - if (cs->port.count == 1) {
34437 + if (atomic_read(&cs->port.count) == 1) {
34438 tty_port_tty_set(&cs->port, tty);
34439 tty->low_latency = 1;
34440 }
34441 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34442
34443 if (!cs->connected)
34444 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34445 - else if (!cs->port.count)
34446 + else if (!atomic_read(&cs->port.count))
34447 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34448 - else if (!--cs->port.count)
34449 + else if (!atomic_dec_return(&cs->port.count))
34450 tty_port_tty_set(&cs->port, NULL);
34451
34452 mutex_unlock(&cs->mutex);
34453 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34454 index 821f7ac..28d4030 100644
34455 --- a/drivers/isdn/hardware/avm/b1.c
34456 +++ b/drivers/isdn/hardware/avm/b1.c
34457 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34458 }
34459 if (left) {
34460 if (t4file->user) {
34461 - if (copy_from_user(buf, dp, left))
34462 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34463 return -EFAULT;
34464 } else {
34465 memcpy(buf, dp, left);
34466 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34467 }
34468 if (left) {
34469 if (config->user) {
34470 - if (copy_from_user(buf, dp, left))
34471 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34472 return -EFAULT;
34473 } else {
34474 memcpy(buf, dp, left);
34475 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34476 index b817809..409caff 100644
34477 --- a/drivers/isdn/i4l/isdn_tty.c
34478 +++ b/drivers/isdn/i4l/isdn_tty.c
34479 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34480
34481 #ifdef ISDN_DEBUG_MODEM_OPEN
34482 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34483 - port->count);
34484 + atomic_read(&port->count));
34485 #endif
34486 - port->count++;
34487 + atomic_inc(&port->count);
34488 port->tty = tty;
34489 /*
34490 * Start up serial port
34491 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34492 #endif
34493 return;
34494 }
34495 - if ((tty->count == 1) && (port->count != 1)) {
34496 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34497 /*
34498 * Uh, oh. tty->count is 1, which means that the tty
34499 * structure will be freed. Info->count should always
34500 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34501 * serial port won't be shutdown.
34502 */
34503 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34504 - "info->count is %d\n", port->count);
34505 - port->count = 1;
34506 + "info->count is %d\n", atomic_read(&port->count));
34507 + atomic_set(&port->count, 1);
34508 }
34509 - if (--port->count < 0) {
34510 + if (atomic_dec_return(&port->count) < 0) {
34511 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34512 - info->line, port->count);
34513 - port->count = 0;
34514 + info->line, atomic_read(&port->count));
34515 + atomic_set(&port->count, 0);
34516 }
34517 - if (port->count) {
34518 + if (atomic_read(&port->count)) {
34519 #ifdef ISDN_DEBUG_MODEM_OPEN
34520 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34521 #endif
34522 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34523 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34524 return;
34525 isdn_tty_shutdown(info);
34526 - port->count = 0;
34527 + atomic_set(&port->count, 0);
34528 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34529 port->tty = NULL;
34530 wake_up_interruptible(&port->open_wait);
34531 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34532 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34533 modem_info *info = &dev->mdm.info[i];
34534
34535 - if (info->port.count == 0)
34536 + if (atomic_read(&info->port.count) == 0)
34537 continue;
34538 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34539 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34540 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34541 index e74df7c..03a03ba 100644
34542 --- a/drivers/isdn/icn/icn.c
34543 +++ b/drivers/isdn/icn/icn.c
34544 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34545 if (count > len)
34546 count = len;
34547 if (user) {
34548 - if (copy_from_user(msg, buf, count))
34549 + if (count > sizeof msg || copy_from_user(msg, buf, count))
34550 return -EFAULT;
34551 } else
34552 memcpy(msg, buf, count);
34553 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34554 index b5fdcb7..5b6c59f 100644
34555 --- a/drivers/lguest/core.c
34556 +++ b/drivers/lguest/core.c
34557 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
34558 * it's worked so far. The end address needs +1 because __get_vm_area
34559 * allocates an extra guard page, so we need space for that.
34560 */
34561 +
34562 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34563 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34564 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34565 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34566 +#else
34567 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34568 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34569 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34570 +#endif
34571 +
34572 if (!switcher_vma) {
34573 err = -ENOMEM;
34574 printk("lguest: could not map switcher pages high\n");
34575 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
34576 * Now the Switcher is mapped at the right address, we can't fail!
34577 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34578 */
34579 - memcpy(switcher_vma->addr, start_switcher_text,
34580 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34581 end_switcher_text - start_switcher_text);
34582
34583 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34584 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34585 index 4af12e1..0e89afe 100644
34586 --- a/drivers/lguest/x86/core.c
34587 +++ b/drivers/lguest/x86/core.c
34588 @@ -59,7 +59,7 @@ static struct {
34589 /* Offset from where switcher.S was compiled to where we've copied it */
34590 static unsigned long switcher_offset(void)
34591 {
34592 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34593 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34594 }
34595
34596 /* This cpu's struct lguest_pages. */
34597 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34598 * These copies are pretty cheap, so we do them unconditionally: */
34599 /* Save the current Host top-level page directory.
34600 */
34601 +
34602 +#ifdef CONFIG_PAX_PER_CPU_PGD
34603 + pages->state.host_cr3 = read_cr3();
34604 +#else
34605 pages->state.host_cr3 = __pa(current->mm->pgd);
34606 +#endif
34607 +
34608 /*
34609 * Set up the Guest's page tables to see this CPU's pages (and no
34610 * other CPU's pages).
34611 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34612 * compiled-in switcher code and the high-mapped copy we just made.
34613 */
34614 for (i = 0; i < IDT_ENTRIES; i++)
34615 - default_idt_entries[i] += switcher_offset();
34616 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34617
34618 /*
34619 * Set up the Switcher's per-cpu areas.
34620 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34621 * it will be undisturbed when we switch. To change %cs and jump we
34622 * need this structure to feed to Intel's "lcall" instruction.
34623 */
34624 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34625 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34626 lguest_entry.segment = LGUEST_CS;
34627
34628 /*
34629 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
34630 index 40634b0..4f5855e 100644
34631 --- a/drivers/lguest/x86/switcher_32.S
34632 +++ b/drivers/lguest/x86/switcher_32.S
34633 @@ -87,6 +87,7 @@
34634 #include <asm/page.h>
34635 #include <asm/segment.h>
34636 #include <asm/lguest.h>
34637 +#include <asm/processor-flags.h>
34638
34639 // We mark the start of the code to copy
34640 // It's placed in .text tho it's never run here
34641 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
34642 // Changes type when we load it: damn Intel!
34643 // For after we switch over our page tables
34644 // That entry will be read-only: we'd crash.
34645 +
34646 +#ifdef CONFIG_PAX_KERNEXEC
34647 + mov %cr0, %edx
34648 + xor $X86_CR0_WP, %edx
34649 + mov %edx, %cr0
34650 +#endif
34651 +
34652 movl $(GDT_ENTRY_TSS*8), %edx
34653 ltr %dx
34654
34655 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
34656 // Let's clear it again for our return.
34657 // The GDT descriptor of the Host
34658 // Points to the table after two "size" bytes
34659 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
34660 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
34661 // Clear "used" from type field (byte 5, bit 2)
34662 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
34663 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
34664 +
34665 +#ifdef CONFIG_PAX_KERNEXEC
34666 + mov %cr0, %eax
34667 + xor $X86_CR0_WP, %eax
34668 + mov %eax, %cr0
34669 +#endif
34670
34671 // Once our page table's switched, the Guest is live!
34672 // The Host fades as we run this final step.
34673 @@ -295,13 +309,12 @@ deliver_to_host:
34674 // I consulted gcc, and it gave
34675 // These instructions, which I gladly credit:
34676 leal (%edx,%ebx,8), %eax
34677 - movzwl (%eax),%edx
34678 - movl 4(%eax), %eax
34679 - xorw %ax, %ax
34680 - orl %eax, %edx
34681 + movl 4(%eax), %edx
34682 + movw (%eax), %dx
34683 // Now the address of the handler's in %edx
34684 // We call it now: its "iret" drops us home.
34685 - jmp *%edx
34686 + ljmp $__KERNEL_CS, $1f
34687 +1: jmp *%edx
34688
34689 // Every interrupt can come to us here
34690 // But we must truly tell each apart.
34691 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
34692 index 7155945..4bcc562 100644
34693 --- a/drivers/md/bitmap.c
34694 +++ b/drivers/md/bitmap.c
34695 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
34696 chunk_kb ? "KB" : "B");
34697 if (bitmap->storage.file) {
34698 seq_printf(seq, ", file: ");
34699 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
34700 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
34701 }
34702
34703 seq_printf(seq, "\n");
34704 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
34705 index a651d52..82f8a95 100644
34706 --- a/drivers/md/dm-ioctl.c
34707 +++ b/drivers/md/dm-ioctl.c
34708 @@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
34709 cmd == DM_LIST_VERSIONS_CMD)
34710 return 0;
34711
34712 - if ((cmd == DM_DEV_CREATE_CMD)) {
34713 + if (cmd == DM_DEV_CREATE_CMD) {
34714 if (!*param->name) {
34715 DMWARN("name not supplied when creating device");
34716 return -EINVAL;
34717 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
34718 index fd61f98..8050783 100644
34719 --- a/drivers/md/dm-raid1.c
34720 +++ b/drivers/md/dm-raid1.c
34721 @@ -40,7 +40,7 @@ enum dm_raid1_error {
34722
34723 struct mirror {
34724 struct mirror_set *ms;
34725 - atomic_t error_count;
34726 + atomic_unchecked_t error_count;
34727 unsigned long error_type;
34728 struct dm_dev *dev;
34729 sector_t offset;
34730 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
34731 struct mirror *m;
34732
34733 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
34734 - if (!atomic_read(&m->error_count))
34735 + if (!atomic_read_unchecked(&m->error_count))
34736 return m;
34737
34738 return NULL;
34739 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
34740 * simple way to tell if a device has encountered
34741 * errors.
34742 */
34743 - atomic_inc(&m->error_count);
34744 + atomic_inc_unchecked(&m->error_count);
34745
34746 if (test_and_set_bit(error_type, &m->error_type))
34747 return;
34748 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
34749 struct mirror *m = get_default_mirror(ms);
34750
34751 do {
34752 - if (likely(!atomic_read(&m->error_count)))
34753 + if (likely(!atomic_read_unchecked(&m->error_count)))
34754 return m;
34755
34756 if (m-- == ms->mirror)
34757 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
34758 {
34759 struct mirror *default_mirror = get_default_mirror(m->ms);
34760
34761 - return !atomic_read(&default_mirror->error_count);
34762 + return !atomic_read_unchecked(&default_mirror->error_count);
34763 }
34764
34765 static int mirror_available(struct mirror_set *ms, struct bio *bio)
34766 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
34767 */
34768 if (likely(region_in_sync(ms, region, 1)))
34769 m = choose_mirror(ms, bio->bi_sector);
34770 - else if (m && atomic_read(&m->error_count))
34771 + else if (m && atomic_read_unchecked(&m->error_count))
34772 m = NULL;
34773
34774 if (likely(m))
34775 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
34776 }
34777
34778 ms->mirror[mirror].ms = ms;
34779 - atomic_set(&(ms->mirror[mirror].error_count), 0);
34780 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
34781 ms->mirror[mirror].error_type = 0;
34782 ms->mirror[mirror].offset = offset;
34783
34784 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
34785 */
34786 static char device_status_char(struct mirror *m)
34787 {
34788 - if (!atomic_read(&(m->error_count)))
34789 + if (!atomic_read_unchecked(&(m->error_count)))
34790 return 'A';
34791
34792 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
34793 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
34794 index e2f87653..f279abe 100644
34795 --- a/drivers/md/dm-stripe.c
34796 +++ b/drivers/md/dm-stripe.c
34797 @@ -20,7 +20,7 @@ struct stripe {
34798 struct dm_dev *dev;
34799 sector_t physical_start;
34800
34801 - atomic_t error_count;
34802 + atomic_unchecked_t error_count;
34803 };
34804
34805 struct stripe_c {
34806 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
34807 kfree(sc);
34808 return r;
34809 }
34810 - atomic_set(&(sc->stripe[i].error_count), 0);
34811 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
34812 }
34813
34814 ti->private = sc;
34815 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
34816 DMEMIT("%d ", sc->stripes);
34817 for (i = 0; i < sc->stripes; i++) {
34818 DMEMIT("%s ", sc->stripe[i].dev->name);
34819 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
34820 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
34821 'D' : 'A';
34822 }
34823 buffer[i] = '\0';
34824 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
34825 */
34826 for (i = 0; i < sc->stripes; i++)
34827 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
34828 - atomic_inc(&(sc->stripe[i].error_count));
34829 - if (atomic_read(&(sc->stripe[i].error_count)) <
34830 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
34831 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
34832 DM_IO_ERROR_THRESHOLD)
34833 schedule_work(&sc->trigger_event);
34834 }
34835 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
34836 index fa29557..d24a5b7 100644
34837 --- a/drivers/md/dm-table.c
34838 +++ b/drivers/md/dm-table.c
34839 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
34840 if (!dev_size)
34841 return 0;
34842
34843 - if ((start >= dev_size) || (start + len > dev_size)) {
34844 + if ((start >= dev_size) || (len > dev_size - start)) {
34845 DMWARN("%s: %s too small for target: "
34846 "start=%llu, len=%llu, dev_size=%llu",
34847 dm_device_name(ti->table->md), bdevname(bdev, b),
34848 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
34849 index 693e149..b7e0fde 100644
34850 --- a/drivers/md/dm-thin-metadata.c
34851 +++ b/drivers/md/dm-thin-metadata.c
34852 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
34853 {
34854 pmd->info.tm = pmd->tm;
34855 pmd->info.levels = 2;
34856 - pmd->info.value_type.context = pmd->data_sm;
34857 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
34858 pmd->info.value_type.size = sizeof(__le64);
34859 pmd->info.value_type.inc = data_block_inc;
34860 pmd->info.value_type.dec = data_block_dec;
34861 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
34862
34863 pmd->bl_info.tm = pmd->tm;
34864 pmd->bl_info.levels = 1;
34865 - pmd->bl_info.value_type.context = pmd->data_sm;
34866 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
34867 pmd->bl_info.value_type.size = sizeof(__le64);
34868 pmd->bl_info.value_type.inc = data_block_inc;
34869 pmd->bl_info.value_type.dec = data_block_dec;
34870 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
34871 index 77e6eff..913d695 100644
34872 --- a/drivers/md/dm.c
34873 +++ b/drivers/md/dm.c
34874 @@ -182,9 +182,9 @@ struct mapped_device {
34875 /*
34876 * Event handling.
34877 */
34878 - atomic_t event_nr;
34879 + atomic_unchecked_t event_nr;
34880 wait_queue_head_t eventq;
34881 - atomic_t uevent_seq;
34882 + atomic_unchecked_t uevent_seq;
34883 struct list_head uevent_list;
34884 spinlock_t uevent_lock; /* Protect access to uevent_list */
34885
34886 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
34887 rwlock_init(&md->map_lock);
34888 atomic_set(&md->holders, 1);
34889 atomic_set(&md->open_count, 0);
34890 - atomic_set(&md->event_nr, 0);
34891 - atomic_set(&md->uevent_seq, 0);
34892 + atomic_set_unchecked(&md->event_nr, 0);
34893 + atomic_set_unchecked(&md->uevent_seq, 0);
34894 INIT_LIST_HEAD(&md->uevent_list);
34895 spin_lock_init(&md->uevent_lock);
34896
34897 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
34898
34899 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
34900
34901 - atomic_inc(&md->event_nr);
34902 + atomic_inc_unchecked(&md->event_nr);
34903 wake_up(&md->eventq);
34904 }
34905
34906 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
34907
34908 uint32_t dm_next_uevent_seq(struct mapped_device *md)
34909 {
34910 - return atomic_add_return(1, &md->uevent_seq);
34911 + return atomic_add_return_unchecked(1, &md->uevent_seq);
34912 }
34913
34914 uint32_t dm_get_event_nr(struct mapped_device *md)
34915 {
34916 - return atomic_read(&md->event_nr);
34917 + return atomic_read_unchecked(&md->event_nr);
34918 }
34919
34920 int dm_wait_event(struct mapped_device *md, int event_nr)
34921 {
34922 return wait_event_interruptible(md->eventq,
34923 - (event_nr != atomic_read(&md->event_nr)));
34924 + (event_nr != atomic_read_unchecked(&md->event_nr)));
34925 }
34926
34927 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
34928 diff --git a/drivers/md/md.c b/drivers/md/md.c
34929 index 6120071..31d9be2 100644
34930 --- a/drivers/md/md.c
34931 +++ b/drivers/md/md.c
34932 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
34933 * start build, activate spare
34934 */
34935 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
34936 -static atomic_t md_event_count;
34937 +static atomic_unchecked_t md_event_count;
34938 void md_new_event(struct mddev *mddev)
34939 {
34940 - atomic_inc(&md_event_count);
34941 + atomic_inc_unchecked(&md_event_count);
34942 wake_up(&md_event_waiters);
34943 }
34944 EXPORT_SYMBOL_GPL(md_new_event);
34945 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
34946 */
34947 static void md_new_event_inintr(struct mddev *mddev)
34948 {
34949 - atomic_inc(&md_event_count);
34950 + atomic_inc_unchecked(&md_event_count);
34951 wake_up(&md_event_waiters);
34952 }
34953
34954 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
34955 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
34956 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
34957 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
34958 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
34959 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
34960
34961 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
34962 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
34963 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
34964 else
34965 sb->resync_offset = cpu_to_le64(0);
34966
34967 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
34968 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
34969
34970 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
34971 sb->size = cpu_to_le64(mddev->dev_sectors);
34972 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
34973 static ssize_t
34974 errors_show(struct md_rdev *rdev, char *page)
34975 {
34976 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
34977 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
34978 }
34979
34980 static ssize_t
34981 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
34982 char *e;
34983 unsigned long n = simple_strtoul(buf, &e, 10);
34984 if (*buf && (*e == 0 || *e == '\n')) {
34985 - atomic_set(&rdev->corrected_errors, n);
34986 + atomic_set_unchecked(&rdev->corrected_errors, n);
34987 return len;
34988 }
34989 return -EINVAL;
34990 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
34991 rdev->sb_loaded = 0;
34992 rdev->bb_page = NULL;
34993 atomic_set(&rdev->nr_pending, 0);
34994 - atomic_set(&rdev->read_errors, 0);
34995 - atomic_set(&rdev->corrected_errors, 0);
34996 + atomic_set_unchecked(&rdev->read_errors, 0);
34997 + atomic_set_unchecked(&rdev->corrected_errors, 0);
34998
34999 INIT_LIST_HEAD(&rdev->same_set);
35000 init_waitqueue_head(&rdev->blocked_wait);
35001 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
35002
35003 spin_unlock(&pers_lock);
35004 seq_printf(seq, "\n");
35005 - seq->poll_event = atomic_read(&md_event_count);
35006 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35007 return 0;
35008 }
35009 if (v == (void*)2) {
35010 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
35011 return error;
35012
35013 seq = file->private_data;
35014 - seq->poll_event = atomic_read(&md_event_count);
35015 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35016 return error;
35017 }
35018
35019 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
35020 /* always allow read */
35021 mask = POLLIN | POLLRDNORM;
35022
35023 - if (seq->poll_event != atomic_read(&md_event_count))
35024 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
35025 mask |= POLLERR | POLLPRI;
35026 return mask;
35027 }
35028 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
35029 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
35030 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
35031 (int)part_stat_read(&disk->part0, sectors[1]) -
35032 - atomic_read(&disk->sync_io);
35033 + atomic_read_unchecked(&disk->sync_io);
35034 /* sync IO will cause sync_io to increase before the disk_stats
35035 * as sync_io is counted when a request starts, and
35036 * disk_stats is counted when it completes.
35037 diff --git a/drivers/md/md.h b/drivers/md/md.h
35038 index af443ab..0f93be3 100644
35039 --- a/drivers/md/md.h
35040 +++ b/drivers/md/md.h
35041 @@ -94,13 +94,13 @@ struct md_rdev {
35042 * only maintained for arrays that
35043 * support hot removal
35044 */
35045 - atomic_t read_errors; /* number of consecutive read errors that
35046 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
35047 * we have tried to ignore.
35048 */
35049 struct timespec last_read_error; /* monotonic time since our
35050 * last read error
35051 */
35052 - atomic_t corrected_errors; /* number of corrected read errors,
35053 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
35054 * for reporting to userspace and storing
35055 * in superblock.
35056 */
35057 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
35058
35059 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
35060 {
35061 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35062 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35063 }
35064
35065 struct md_personality
35066 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
35067 index 1cbfc6b..56e1dbb 100644
35068 --- a/drivers/md/persistent-data/dm-space-map.h
35069 +++ b/drivers/md/persistent-data/dm-space-map.h
35070 @@ -60,6 +60,7 @@ struct dm_space_map {
35071 int (*root_size)(struct dm_space_map *sm, size_t *result);
35072 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35073 };
35074 +typedef struct dm_space_map __no_const dm_space_map_no_const;
35075
35076 /*----------------------------------------------------------------*/
35077
35078 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35079 index a0f7309..5599dbc 100644
35080 --- a/drivers/md/raid1.c
35081 +++ b/drivers/md/raid1.c
35082 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35083 if (r1_sync_page_io(rdev, sect, s,
35084 bio->bi_io_vec[idx].bv_page,
35085 READ) != 0)
35086 - atomic_add(s, &rdev->corrected_errors);
35087 + atomic_add_unchecked(s, &rdev->corrected_errors);
35088 }
35089 sectors -= s;
35090 sect += s;
35091 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35092 test_bit(In_sync, &rdev->flags)) {
35093 if (r1_sync_page_io(rdev, sect, s,
35094 conf->tmppage, READ)) {
35095 - atomic_add(s, &rdev->corrected_errors);
35096 + atomic_add_unchecked(s, &rdev->corrected_errors);
35097 printk(KERN_INFO
35098 "md/raid1:%s: read error corrected "
35099 "(%d sectors at %llu on %s)\n",
35100 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35101 index c9acbd7..386cd3e 100644
35102 --- a/drivers/md/raid10.c
35103 +++ b/drivers/md/raid10.c
35104 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35105 /* The write handler will notice the lack of
35106 * R10BIO_Uptodate and record any errors etc
35107 */
35108 - atomic_add(r10_bio->sectors,
35109 + atomic_add_unchecked(r10_bio->sectors,
35110 &conf->mirrors[d].rdev->corrected_errors);
35111
35112 /* for reconstruct, we always reschedule after a read.
35113 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35114 {
35115 struct timespec cur_time_mon;
35116 unsigned long hours_since_last;
35117 - unsigned int read_errors = atomic_read(&rdev->read_errors);
35118 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35119
35120 ktime_get_ts(&cur_time_mon);
35121
35122 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35123 * overflowing the shift of read_errors by hours_since_last.
35124 */
35125 if (hours_since_last >= 8 * sizeof(read_errors))
35126 - atomic_set(&rdev->read_errors, 0);
35127 + atomic_set_unchecked(&rdev->read_errors, 0);
35128 else
35129 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35130 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35131 }
35132
35133 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35134 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35135 return;
35136
35137 check_decay_read_errors(mddev, rdev);
35138 - atomic_inc(&rdev->read_errors);
35139 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
35140 + atomic_inc_unchecked(&rdev->read_errors);
35141 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35142 char b[BDEVNAME_SIZE];
35143 bdevname(rdev->bdev, b);
35144
35145 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35146 "md/raid10:%s: %s: Raid device exceeded "
35147 "read_error threshold [cur %d:max %d]\n",
35148 mdname(mddev), b,
35149 - atomic_read(&rdev->read_errors), max_read_errors);
35150 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35151 printk(KERN_NOTICE
35152 "md/raid10:%s: %s: Failing raid device\n",
35153 mdname(mddev), b);
35154 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35155 sect +
35156 choose_data_offset(r10_bio, rdev)),
35157 bdevname(rdev->bdev, b));
35158 - atomic_add(s, &rdev->corrected_errors);
35159 + atomic_add_unchecked(s, &rdev->corrected_errors);
35160 }
35161
35162 rdev_dec_pending(rdev, mddev);
35163 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35164 index a450268..c4168a9 100644
35165 --- a/drivers/md/raid5.c
35166 +++ b/drivers/md/raid5.c
35167 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35168 mdname(conf->mddev), STRIPE_SECTORS,
35169 (unsigned long long)s,
35170 bdevname(rdev->bdev, b));
35171 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35172 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35173 clear_bit(R5_ReadError, &sh->dev[i].flags);
35174 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35175 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35176 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35177
35178 - if (atomic_read(&rdev->read_errors))
35179 - atomic_set(&rdev->read_errors, 0);
35180 + if (atomic_read_unchecked(&rdev->read_errors))
35181 + atomic_set_unchecked(&rdev->read_errors, 0);
35182 } else {
35183 const char *bdn = bdevname(rdev->bdev, b);
35184 int retry = 0;
35185 int set_bad = 0;
35186
35187 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35188 - atomic_inc(&rdev->read_errors);
35189 + atomic_inc_unchecked(&rdev->read_errors);
35190 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35191 printk_ratelimited(
35192 KERN_WARNING
35193 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35194 mdname(conf->mddev),
35195 (unsigned long long)s,
35196 bdn);
35197 - } else if (atomic_read(&rdev->read_errors)
35198 + } else if (atomic_read_unchecked(&rdev->read_errors)
35199 > conf->max_nr_stripes)
35200 printk(KERN_WARNING
35201 "md/raid:%s: Too many read errors, failing device %s.\n",
35202 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35203 index d33101a..6b13069 100644
35204 --- a/drivers/media/dvb-core/dvbdev.c
35205 +++ b/drivers/media/dvb-core/dvbdev.c
35206 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35207 const struct dvb_device *template, void *priv, int type)
35208 {
35209 struct dvb_device *dvbdev;
35210 - struct file_operations *dvbdevfops;
35211 + file_operations_no_const *dvbdevfops;
35212 struct device *clsdev;
35213 int minor;
35214 int id;
35215 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35216 index 404f63a..4796533 100644
35217 --- a/drivers/media/dvb-frontends/dib3000.h
35218 +++ b/drivers/media/dvb-frontends/dib3000.h
35219 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35220 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35221 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35222 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35223 -};
35224 +} __no_const;
35225
35226 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35227 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35228 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35229 index 3aa6856..435ad25 100644
35230 --- a/drivers/media/pci/cx88/cx88-alsa.c
35231 +++ b/drivers/media/pci/cx88/cx88-alsa.c
35232 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35233 * Only boards with eeprom and byte 1 at eeprom=1 have it
35234 */
35235
35236 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35237 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35238 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35239 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35240 {0, }
35241 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35242 index feff57e..66a2c67 100644
35243 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
35244 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35245 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35246 .subvendor = _subvend, .subdevice = _subdev, \
35247 .driver_data = (unsigned long)&_driverdata }
35248
35249 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35250 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35251 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35252 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35253 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35254 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35255 index 96a13ed..6df45b4 100644
35256 --- a/drivers/media/pci/ngene/ngene-cards.c
35257 +++ b/drivers/media/pci/ngene/ngene-cards.c
35258 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35259
35260 /****************************************************************************/
35261
35262 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35263 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35264 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35265 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35266 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35267 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35268 index a3b1a34..71ce0e3 100644
35269 --- a/drivers/media/platform/omap/omap_vout.c
35270 +++ b/drivers/media/platform/omap/omap_vout.c
35271 @@ -65,7 +65,6 @@ enum omap_vout_channels {
35272 OMAP_VIDEO2,
35273 };
35274
35275 -static struct videobuf_queue_ops video_vbq_ops;
35276 /* Variables configurable through module params*/
35277 static u32 video1_numbuffers = 3;
35278 static u32 video2_numbuffers = 3;
35279 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35280 {
35281 struct videobuf_queue *q;
35282 struct omap_vout_device *vout = NULL;
35283 + static struct videobuf_queue_ops video_vbq_ops = {
35284 + .buf_setup = omap_vout_buffer_setup,
35285 + .buf_prepare = omap_vout_buffer_prepare,
35286 + .buf_release = omap_vout_buffer_release,
35287 + .buf_queue = omap_vout_buffer_queue,
35288 + };
35289
35290 vout = video_drvdata(file);
35291 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35292 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35293 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35294
35295 q = &vout->vbq;
35296 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35297 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35298 - video_vbq_ops.buf_release = omap_vout_buffer_release;
35299 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35300 spin_lock_init(&vout->vbq_lock);
35301
35302 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35303 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35304 index 02194c0..36d69c1 100644
35305 --- a/drivers/media/platform/timblogiw.c
35306 +++ b/drivers/media/platform/timblogiw.c
35307 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35308
35309 /* Platform device functions */
35310
35311 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35312 +static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35313 .vidioc_querycap = timblogiw_querycap,
35314 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35315 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35316 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35317 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35318 };
35319
35320 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35321 +static struct v4l2_file_operations timblogiw_fops = {
35322 .owner = THIS_MODULE,
35323 .open = timblogiw_open,
35324 .release = timblogiw_close,
35325 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35326 index 697a421..16c5a5f 100644
35327 --- a/drivers/media/radio/radio-cadet.c
35328 +++ b/drivers/media/radio/radio-cadet.c
35329 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35330 unsigned char readbuf[RDS_BUFFER];
35331 int i = 0;
35332
35333 + if (count > RDS_BUFFER)
35334 + return -EFAULT;
35335 mutex_lock(&dev->lock);
35336 if (dev->rdsstat == 0)
35337 cadet_start_rds(dev);
35338 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35339 while (i < count && dev->rdsin != dev->rdsout)
35340 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35341
35342 - if (i && copy_to_user(data, readbuf, i))
35343 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35344 i = -EFAULT;
35345 unlock:
35346 mutex_unlock(&dev->lock);
35347 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35348 index 3940bb0..fb3952a 100644
35349 --- a/drivers/media/usb/dvb-usb/cxusb.c
35350 +++ b/drivers/media/usb/dvb-usb/cxusb.c
35351 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35352
35353 struct dib0700_adapter_state {
35354 int (*set_param_save) (struct dvb_frontend *);
35355 -};
35356 +} __no_const;
35357
35358 static int dib7070_set_param_override(struct dvb_frontend *fe)
35359 {
35360 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35361 index 9382895..ac8093c 100644
35362 --- a/drivers/media/usb/dvb-usb/dw2102.c
35363 +++ b/drivers/media/usb/dvb-usb/dw2102.c
35364 @@ -95,7 +95,7 @@ struct su3000_state {
35365
35366 struct s6x0_state {
35367 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35368 -};
35369 +} __no_const;
35370
35371 /* debug */
35372 static int dvb_usb_dw2102_debug;
35373 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35374 index fb69baa..cf7ad22 100644
35375 --- a/drivers/message/fusion/mptbase.c
35376 +++ b/drivers/message/fusion/mptbase.c
35377 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35378 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35379 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35380
35381 +#ifdef CONFIG_GRKERNSEC_HIDESYM
35382 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35383 +#else
35384 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35385 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35386 +#endif
35387 +
35388 /*
35389 * Rounding UP to nearest 4-kB boundary here...
35390 */
35391 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35392 index 551262e..7551198 100644
35393 --- a/drivers/message/fusion/mptsas.c
35394 +++ b/drivers/message/fusion/mptsas.c
35395 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35396 return 0;
35397 }
35398
35399 +static inline void
35400 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35401 +{
35402 + if (phy_info->port_details) {
35403 + phy_info->port_details->rphy = rphy;
35404 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35405 + ioc->name, rphy));
35406 + }
35407 +
35408 + if (rphy) {
35409 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35410 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35411 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35412 + ioc->name, rphy, rphy->dev.release));
35413 + }
35414 +}
35415 +
35416 /* no mutex */
35417 static void
35418 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35419 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35420 return NULL;
35421 }
35422
35423 -static inline void
35424 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35425 -{
35426 - if (phy_info->port_details) {
35427 - phy_info->port_details->rphy = rphy;
35428 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35429 - ioc->name, rphy));
35430 - }
35431 -
35432 - if (rphy) {
35433 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35434 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35435 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35436 - ioc->name, rphy, rphy->dev.release));
35437 - }
35438 -}
35439 -
35440 static inline struct sas_port *
35441 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35442 {
35443 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35444 index 0c3ced7..1fe34ec 100644
35445 --- a/drivers/message/fusion/mptscsih.c
35446 +++ b/drivers/message/fusion/mptscsih.c
35447 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35448
35449 h = shost_priv(SChost);
35450
35451 - if (h) {
35452 - if (h->info_kbuf == NULL)
35453 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35454 - return h->info_kbuf;
35455 - h->info_kbuf[0] = '\0';
35456 + if (!h)
35457 + return NULL;
35458
35459 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35460 - h->info_kbuf[size-1] = '\0';
35461 - }
35462 + if (h->info_kbuf == NULL)
35463 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35464 + return h->info_kbuf;
35465 + h->info_kbuf[0] = '\0';
35466 +
35467 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35468 + h->info_kbuf[size-1] = '\0';
35469
35470 return h->info_kbuf;
35471 }
35472 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35473 index 8001aa6..b137580 100644
35474 --- a/drivers/message/i2o/i2o_proc.c
35475 +++ b/drivers/message/i2o/i2o_proc.c
35476 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
35477 "Array Controller Device"
35478 };
35479
35480 -static char *chtostr(char *tmp, u8 *chars, int n)
35481 -{
35482 - tmp[0] = 0;
35483 - return strncat(tmp, (char *)chars, n);
35484 -}
35485 -
35486 static int i2o_report_query_status(struct seq_file *seq, int block_status,
35487 char *group)
35488 {
35489 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35490 } *result;
35491
35492 i2o_exec_execute_ddm_table ddm_table;
35493 - char tmp[28 + 1];
35494
35495 result = kmalloc(sizeof(*result), GFP_KERNEL);
35496 if (!result)
35497 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35498
35499 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
35500 seq_printf(seq, "%-#8x", ddm_table.module_id);
35501 - seq_printf(seq, "%-29s",
35502 - chtostr(tmp, ddm_table.module_name_version, 28));
35503 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
35504 seq_printf(seq, "%9d ", ddm_table.data_size);
35505 seq_printf(seq, "%8d", ddm_table.code_size);
35506
35507 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35508
35509 i2o_driver_result_table *result;
35510 i2o_driver_store_table *dst;
35511 - char tmp[28 + 1];
35512
35513 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
35514 if (result == NULL)
35515 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35516
35517 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
35518 seq_printf(seq, "%-#8x", dst->module_id);
35519 - seq_printf(seq, "%-29s",
35520 - chtostr(tmp, dst->module_name_version, 28));
35521 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
35522 + seq_printf(seq, "%-.28s", dst->module_name_version);
35523 + seq_printf(seq, "%-.8s", dst->date);
35524 seq_printf(seq, "%8d ", dst->module_size);
35525 seq_printf(seq, "%8d ", dst->mpb_size);
35526 seq_printf(seq, "0x%04x", dst->module_flags);
35527 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35528 // == (allow) 512d bytes (max)
35529 static u16 *work16 = (u16 *) work32;
35530 int token;
35531 - char tmp[16 + 1];
35532
35533 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
35534
35535 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35536 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
35537 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
35538 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
35539 - seq_printf(seq, "Vendor info : %s\n",
35540 - chtostr(tmp, (u8 *) (work32 + 2), 16));
35541 - seq_printf(seq, "Product info : %s\n",
35542 - chtostr(tmp, (u8 *) (work32 + 6), 16));
35543 - seq_printf(seq, "Description : %s\n",
35544 - chtostr(tmp, (u8 *) (work32 + 10), 16));
35545 - seq_printf(seq, "Product rev. : %s\n",
35546 - chtostr(tmp, (u8 *) (work32 + 14), 8));
35547 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
35548 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
35549 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
35550 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
35551
35552 seq_printf(seq, "Serial number : ");
35553 print_serial_number(seq, (u8 *) (work32 + 16),
35554 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35555 u8 pad[256]; // allow up to 256 byte (max) serial number
35556 } result;
35557
35558 - char tmp[24 + 1];
35559 -
35560 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
35561
35562 if (token < 0) {
35563 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35564 }
35565
35566 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
35567 - seq_printf(seq, "Module name : %s\n",
35568 - chtostr(tmp, result.module_name, 24));
35569 - seq_printf(seq, "Module revision : %s\n",
35570 - chtostr(tmp, result.module_rev, 8));
35571 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
35572 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
35573
35574 seq_printf(seq, "Serial number : ");
35575 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
35576 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35577 u8 instance_number[4];
35578 } result;
35579
35580 - char tmp[64 + 1];
35581 -
35582 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
35583
35584 if (token < 0) {
35585 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35586 return 0;
35587 }
35588
35589 - seq_printf(seq, "Device name : %s\n",
35590 - chtostr(tmp, result.device_name, 64));
35591 - seq_printf(seq, "Service name : %s\n",
35592 - chtostr(tmp, result.service_name, 64));
35593 - seq_printf(seq, "Physical name : %s\n",
35594 - chtostr(tmp, result.physical_location, 64));
35595 - seq_printf(seq, "Instance number : %s\n",
35596 - chtostr(tmp, result.instance_number, 4));
35597 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
35598 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
35599 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
35600 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
35601
35602 return 0;
35603 }
35604 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
35605 index a8c08f3..155fe3d 100644
35606 --- a/drivers/message/i2o/iop.c
35607 +++ b/drivers/message/i2o/iop.c
35608 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
35609
35610 spin_lock_irqsave(&c->context_list_lock, flags);
35611
35612 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
35613 - atomic_inc(&c->context_list_counter);
35614 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
35615 + atomic_inc_unchecked(&c->context_list_counter);
35616
35617 - entry->context = atomic_read(&c->context_list_counter);
35618 + entry->context = atomic_read_unchecked(&c->context_list_counter);
35619
35620 list_add(&entry->list, &c->context_list);
35621
35622 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
35623
35624 #if BITS_PER_LONG == 64
35625 spin_lock_init(&c->context_list_lock);
35626 - atomic_set(&c->context_list_counter, 0);
35627 + atomic_set_unchecked(&c->context_list_counter, 0);
35628 INIT_LIST_HEAD(&c->context_list);
35629 #endif
35630
35631 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
35632 index 965c480..71f2db9 100644
35633 --- a/drivers/mfd/janz-cmodio.c
35634 +++ b/drivers/mfd/janz-cmodio.c
35635 @@ -13,6 +13,7 @@
35636
35637 #include <linux/kernel.h>
35638 #include <linux/module.h>
35639 +#include <linux/slab.h>
35640 #include <linux/init.h>
35641 #include <linux/pci.h>
35642 #include <linux/interrupt.h>
35643 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
35644 index 3aa9a96..59cf685 100644
35645 --- a/drivers/misc/kgdbts.c
35646 +++ b/drivers/misc/kgdbts.c
35647 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
35648 char before[BREAK_INSTR_SIZE];
35649 char after[BREAK_INSTR_SIZE];
35650
35651 - probe_kernel_read(before, (char *)kgdbts_break_test,
35652 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
35653 BREAK_INSTR_SIZE);
35654 init_simple_test();
35655 ts.tst = plant_and_detach_test;
35656 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
35657 /* Activate test with initial breakpoint */
35658 if (!is_early)
35659 kgdb_breakpoint();
35660 - probe_kernel_read(after, (char *)kgdbts_break_test,
35661 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
35662 BREAK_INSTR_SIZE);
35663 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
35664 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
35665 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
35666 index 4a87e5c..76bdf5c 100644
35667 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
35668 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
35669 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
35670 * the lid is closed. This leads to interrupts as soon as a little move
35671 * is done.
35672 */
35673 - atomic_inc(&lis3->count);
35674 + atomic_inc_unchecked(&lis3->count);
35675
35676 wake_up_interruptible(&lis3->misc_wait);
35677 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
35678 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
35679 if (lis3->pm_dev)
35680 pm_runtime_get_sync(lis3->pm_dev);
35681
35682 - atomic_set(&lis3->count, 0);
35683 + atomic_set_unchecked(&lis3->count, 0);
35684 return 0;
35685 }
35686
35687 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
35688 add_wait_queue(&lis3->misc_wait, &wait);
35689 while (true) {
35690 set_current_state(TASK_INTERRUPTIBLE);
35691 - data = atomic_xchg(&lis3->count, 0);
35692 + data = atomic_xchg_unchecked(&lis3->count, 0);
35693 if (data)
35694 break;
35695
35696 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
35697 struct lis3lv02d, miscdev);
35698
35699 poll_wait(file, &lis3->misc_wait, wait);
35700 - if (atomic_read(&lis3->count))
35701 + if (atomic_read_unchecked(&lis3->count))
35702 return POLLIN | POLLRDNORM;
35703 return 0;
35704 }
35705 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
35706 index c439c82..1f20f57 100644
35707 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
35708 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
35709 @@ -297,7 +297,7 @@ struct lis3lv02d {
35710 struct input_polled_dev *idev; /* input device */
35711 struct platform_device *pdev; /* platform device */
35712 struct regulator_bulk_data regulators[2];
35713 - atomic_t count; /* interrupt count after last read */
35714 + atomic_unchecked_t count; /* interrupt count after last read */
35715 union axis_conversion ac; /* hw -> logical axis */
35716 int mapped_btns[3];
35717
35718 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
35719 index 2f30bad..c4c13d0 100644
35720 --- a/drivers/misc/sgi-gru/gruhandles.c
35721 +++ b/drivers/misc/sgi-gru/gruhandles.c
35722 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
35723 unsigned long nsec;
35724
35725 nsec = CLKS2NSEC(clks);
35726 - atomic_long_inc(&mcs_op_statistics[op].count);
35727 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
35728 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
35729 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
35730 if (mcs_op_statistics[op].max < nsec)
35731 mcs_op_statistics[op].max = nsec;
35732 }
35733 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
35734 index 950dbe9..eeef0f8 100644
35735 --- a/drivers/misc/sgi-gru/gruprocfs.c
35736 +++ b/drivers/misc/sgi-gru/gruprocfs.c
35737 @@ -32,9 +32,9 @@
35738
35739 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
35740
35741 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
35742 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
35743 {
35744 - unsigned long val = atomic_long_read(v);
35745 + unsigned long val = atomic_long_read_unchecked(v);
35746
35747 seq_printf(s, "%16lu %s\n", val, id);
35748 }
35749 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
35750
35751 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
35752 for (op = 0; op < mcsop_last; op++) {
35753 - count = atomic_long_read(&mcs_op_statistics[op].count);
35754 - total = atomic_long_read(&mcs_op_statistics[op].total);
35755 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
35756 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
35757 max = mcs_op_statistics[op].max;
35758 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
35759 count ? total / count : 0, max);
35760 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
35761 index 5c3ce24..4915ccb 100644
35762 --- a/drivers/misc/sgi-gru/grutables.h
35763 +++ b/drivers/misc/sgi-gru/grutables.h
35764 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
35765 * GRU statistics.
35766 */
35767 struct gru_stats_s {
35768 - atomic_long_t vdata_alloc;
35769 - atomic_long_t vdata_free;
35770 - atomic_long_t gts_alloc;
35771 - atomic_long_t gts_free;
35772 - atomic_long_t gms_alloc;
35773 - atomic_long_t gms_free;
35774 - atomic_long_t gts_double_allocate;
35775 - atomic_long_t assign_context;
35776 - atomic_long_t assign_context_failed;
35777 - atomic_long_t free_context;
35778 - atomic_long_t load_user_context;
35779 - atomic_long_t load_kernel_context;
35780 - atomic_long_t lock_kernel_context;
35781 - atomic_long_t unlock_kernel_context;
35782 - atomic_long_t steal_user_context;
35783 - atomic_long_t steal_kernel_context;
35784 - atomic_long_t steal_context_failed;
35785 - atomic_long_t nopfn;
35786 - atomic_long_t asid_new;
35787 - atomic_long_t asid_next;
35788 - atomic_long_t asid_wrap;
35789 - atomic_long_t asid_reuse;
35790 - atomic_long_t intr;
35791 - atomic_long_t intr_cbr;
35792 - atomic_long_t intr_tfh;
35793 - atomic_long_t intr_spurious;
35794 - atomic_long_t intr_mm_lock_failed;
35795 - atomic_long_t call_os;
35796 - atomic_long_t call_os_wait_queue;
35797 - atomic_long_t user_flush_tlb;
35798 - atomic_long_t user_unload_context;
35799 - atomic_long_t user_exception;
35800 - atomic_long_t set_context_option;
35801 - atomic_long_t check_context_retarget_intr;
35802 - atomic_long_t check_context_unload;
35803 - atomic_long_t tlb_dropin;
35804 - atomic_long_t tlb_preload_page;
35805 - atomic_long_t tlb_dropin_fail_no_asid;
35806 - atomic_long_t tlb_dropin_fail_upm;
35807 - atomic_long_t tlb_dropin_fail_invalid;
35808 - atomic_long_t tlb_dropin_fail_range_active;
35809 - atomic_long_t tlb_dropin_fail_idle;
35810 - atomic_long_t tlb_dropin_fail_fmm;
35811 - atomic_long_t tlb_dropin_fail_no_exception;
35812 - atomic_long_t tfh_stale_on_fault;
35813 - atomic_long_t mmu_invalidate_range;
35814 - atomic_long_t mmu_invalidate_page;
35815 - atomic_long_t flush_tlb;
35816 - atomic_long_t flush_tlb_gru;
35817 - atomic_long_t flush_tlb_gru_tgh;
35818 - atomic_long_t flush_tlb_gru_zero_asid;
35819 + atomic_long_unchecked_t vdata_alloc;
35820 + atomic_long_unchecked_t vdata_free;
35821 + atomic_long_unchecked_t gts_alloc;
35822 + atomic_long_unchecked_t gts_free;
35823 + atomic_long_unchecked_t gms_alloc;
35824 + atomic_long_unchecked_t gms_free;
35825 + atomic_long_unchecked_t gts_double_allocate;
35826 + atomic_long_unchecked_t assign_context;
35827 + atomic_long_unchecked_t assign_context_failed;
35828 + atomic_long_unchecked_t free_context;
35829 + atomic_long_unchecked_t load_user_context;
35830 + atomic_long_unchecked_t load_kernel_context;
35831 + atomic_long_unchecked_t lock_kernel_context;
35832 + atomic_long_unchecked_t unlock_kernel_context;
35833 + atomic_long_unchecked_t steal_user_context;
35834 + atomic_long_unchecked_t steal_kernel_context;
35835 + atomic_long_unchecked_t steal_context_failed;
35836 + atomic_long_unchecked_t nopfn;
35837 + atomic_long_unchecked_t asid_new;
35838 + atomic_long_unchecked_t asid_next;
35839 + atomic_long_unchecked_t asid_wrap;
35840 + atomic_long_unchecked_t asid_reuse;
35841 + atomic_long_unchecked_t intr;
35842 + atomic_long_unchecked_t intr_cbr;
35843 + atomic_long_unchecked_t intr_tfh;
35844 + atomic_long_unchecked_t intr_spurious;
35845 + atomic_long_unchecked_t intr_mm_lock_failed;
35846 + atomic_long_unchecked_t call_os;
35847 + atomic_long_unchecked_t call_os_wait_queue;
35848 + atomic_long_unchecked_t user_flush_tlb;
35849 + atomic_long_unchecked_t user_unload_context;
35850 + atomic_long_unchecked_t user_exception;
35851 + atomic_long_unchecked_t set_context_option;
35852 + atomic_long_unchecked_t check_context_retarget_intr;
35853 + atomic_long_unchecked_t check_context_unload;
35854 + atomic_long_unchecked_t tlb_dropin;
35855 + atomic_long_unchecked_t tlb_preload_page;
35856 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
35857 + atomic_long_unchecked_t tlb_dropin_fail_upm;
35858 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
35859 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
35860 + atomic_long_unchecked_t tlb_dropin_fail_idle;
35861 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
35862 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
35863 + atomic_long_unchecked_t tfh_stale_on_fault;
35864 + atomic_long_unchecked_t mmu_invalidate_range;
35865 + atomic_long_unchecked_t mmu_invalidate_page;
35866 + atomic_long_unchecked_t flush_tlb;
35867 + atomic_long_unchecked_t flush_tlb_gru;
35868 + atomic_long_unchecked_t flush_tlb_gru_tgh;
35869 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
35870
35871 - atomic_long_t copy_gpa;
35872 - atomic_long_t read_gpa;
35873 + atomic_long_unchecked_t copy_gpa;
35874 + atomic_long_unchecked_t read_gpa;
35875
35876 - atomic_long_t mesq_receive;
35877 - atomic_long_t mesq_receive_none;
35878 - atomic_long_t mesq_send;
35879 - atomic_long_t mesq_send_failed;
35880 - atomic_long_t mesq_noop;
35881 - atomic_long_t mesq_send_unexpected_error;
35882 - atomic_long_t mesq_send_lb_overflow;
35883 - atomic_long_t mesq_send_qlimit_reached;
35884 - atomic_long_t mesq_send_amo_nacked;
35885 - atomic_long_t mesq_send_put_nacked;
35886 - atomic_long_t mesq_page_overflow;
35887 - atomic_long_t mesq_qf_locked;
35888 - atomic_long_t mesq_qf_noop_not_full;
35889 - atomic_long_t mesq_qf_switch_head_failed;
35890 - atomic_long_t mesq_qf_unexpected_error;
35891 - atomic_long_t mesq_noop_unexpected_error;
35892 - atomic_long_t mesq_noop_lb_overflow;
35893 - atomic_long_t mesq_noop_qlimit_reached;
35894 - atomic_long_t mesq_noop_amo_nacked;
35895 - atomic_long_t mesq_noop_put_nacked;
35896 - atomic_long_t mesq_noop_page_overflow;
35897 + atomic_long_unchecked_t mesq_receive;
35898 + atomic_long_unchecked_t mesq_receive_none;
35899 + atomic_long_unchecked_t mesq_send;
35900 + atomic_long_unchecked_t mesq_send_failed;
35901 + atomic_long_unchecked_t mesq_noop;
35902 + atomic_long_unchecked_t mesq_send_unexpected_error;
35903 + atomic_long_unchecked_t mesq_send_lb_overflow;
35904 + atomic_long_unchecked_t mesq_send_qlimit_reached;
35905 + atomic_long_unchecked_t mesq_send_amo_nacked;
35906 + atomic_long_unchecked_t mesq_send_put_nacked;
35907 + atomic_long_unchecked_t mesq_page_overflow;
35908 + atomic_long_unchecked_t mesq_qf_locked;
35909 + atomic_long_unchecked_t mesq_qf_noop_not_full;
35910 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
35911 + atomic_long_unchecked_t mesq_qf_unexpected_error;
35912 + atomic_long_unchecked_t mesq_noop_unexpected_error;
35913 + atomic_long_unchecked_t mesq_noop_lb_overflow;
35914 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
35915 + atomic_long_unchecked_t mesq_noop_amo_nacked;
35916 + atomic_long_unchecked_t mesq_noop_put_nacked;
35917 + atomic_long_unchecked_t mesq_noop_page_overflow;
35918
35919 };
35920
35921 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
35922 tghop_invalidate, mcsop_last};
35923
35924 struct mcs_op_statistic {
35925 - atomic_long_t count;
35926 - atomic_long_t total;
35927 + atomic_long_unchecked_t count;
35928 + atomic_long_unchecked_t total;
35929 unsigned long max;
35930 };
35931
35932 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
35933
35934 #define STAT(id) do { \
35935 if (gru_options & OPT_STATS) \
35936 - atomic_long_inc(&gru_stats.id); \
35937 + atomic_long_inc_unchecked(&gru_stats.id); \
35938 } while (0)
35939
35940 #ifdef CONFIG_SGI_GRU_DEBUG
35941 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
35942 index c862cd4..0d176fe 100644
35943 --- a/drivers/misc/sgi-xp/xp.h
35944 +++ b/drivers/misc/sgi-xp/xp.h
35945 @@ -288,7 +288,7 @@ struct xpc_interface {
35946 xpc_notify_func, void *);
35947 void (*received) (short, int, void *);
35948 enum xp_retval (*partid_to_nasids) (short, void *);
35949 -};
35950 +} __no_const;
35951
35952 extern struct xpc_interface xpc_interface;
35953
35954 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
35955 index b94d5f7..7f494c5 100644
35956 --- a/drivers/misc/sgi-xp/xpc.h
35957 +++ b/drivers/misc/sgi-xp/xpc.h
35958 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
35959 void (*received_payload) (struct xpc_channel *, void *);
35960 void (*notify_senders_of_disconnect) (struct xpc_channel *);
35961 };
35962 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
35963
35964 /* struct xpc_partition act_state values (for XPC HB) */
35965
35966 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
35967 /* found in xpc_main.c */
35968 extern struct device *xpc_part;
35969 extern struct device *xpc_chan;
35970 -extern struct xpc_arch_operations xpc_arch_ops;
35971 +extern xpc_arch_operations_no_const xpc_arch_ops;
35972 extern int xpc_disengage_timelimit;
35973 extern int xpc_disengage_timedout;
35974 extern int xpc_activate_IRQ_rcvd;
35975 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
35976 index d971817..3805cce 100644
35977 --- a/drivers/misc/sgi-xp/xpc_main.c
35978 +++ b/drivers/misc/sgi-xp/xpc_main.c
35979 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
35980 .notifier_call = xpc_system_die,
35981 };
35982
35983 -struct xpc_arch_operations xpc_arch_ops;
35984 +xpc_arch_operations_no_const xpc_arch_ops;
35985
35986 /*
35987 * Timer function to enforce the timelimit on the partition disengage.
35988 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
35989 index a0e1720..ee63d0b 100644
35990 --- a/drivers/mmc/core/mmc_ops.c
35991 +++ b/drivers/mmc/core/mmc_ops.c
35992 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
35993 void *data_buf;
35994 int is_on_stack;
35995
35996 - is_on_stack = object_is_on_stack(buf);
35997 + is_on_stack = object_starts_on_stack(buf);
35998 if (is_on_stack) {
35999 /*
36000 * dma onto stack is unsafe/nonportable, but callers to this
36001 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36002 index 53b8fd9..615b462 100644
36003 --- a/drivers/mmc/host/dw_mmc.h
36004 +++ b/drivers/mmc/host/dw_mmc.h
36005 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36006 int (*parse_dt)(struct dw_mci *host);
36007 int (*setup_bus)(struct dw_mci *host,
36008 struct device_node *slot_np, u8 bus_width);
36009 -};
36010 +} __do_const;
36011 #endif /* _DW_MMC_H_ */
36012 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36013 index a4eb8b5..8c0628f 100644
36014 --- a/drivers/mtd/devices/doc2000.c
36015 +++ b/drivers/mtd/devices/doc2000.c
36016 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36017
36018 /* The ECC will not be calculated correctly if less than 512 is written */
36019 /* DBB-
36020 - if (len != 0x200 && eccbuf)
36021 + if (len != 0x200)
36022 printk(KERN_WARNING
36023 "ECC needs a full sector write (adr: %lx size %lx)\n",
36024 (long) to, (long) len);
36025 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36026 index e706a23..b3d262f 100644
36027 --- a/drivers/mtd/nand/denali.c
36028 +++ b/drivers/mtd/nand/denali.c
36029 @@ -26,6 +26,7 @@
36030 #include <linux/pci.h>
36031 #include <linux/mtd/mtd.h>
36032 #include <linux/module.h>
36033 +#include <linux/slab.h>
36034
36035 #include "denali.h"
36036
36037 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36038 index 51b9d6a..52af9a7 100644
36039 --- a/drivers/mtd/nftlmount.c
36040 +++ b/drivers/mtd/nftlmount.c
36041 @@ -24,6 +24,7 @@
36042 #include <asm/errno.h>
36043 #include <linux/delay.h>
36044 #include <linux/slab.h>
36045 +#include <linux/sched.h>
36046 #include <linux/mtd/mtd.h>
36047 #include <linux/mtd/nand.h>
36048 #include <linux/mtd/nftl.h>
36049 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36050 index 203ff9d..0968ca8 100644
36051 --- a/drivers/net/ethernet/8390/ax88796.c
36052 +++ b/drivers/net/ethernet/8390/ax88796.c
36053 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36054 if (ax->plat->reg_offsets)
36055 ei_local->reg_offset = ax->plat->reg_offsets;
36056 else {
36057 + resource_size_t _mem_size = mem_size;
36058 + do_div(_mem_size, 0x18);
36059 ei_local->reg_offset = ax->reg_offsets;
36060 for (ret = 0; ret < 0x18; ret++)
36061 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36062 + ax->reg_offsets[ret] = _mem_size * ret;
36063 }
36064
36065 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36066 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36067 index 9c5ea6c..eaad276 100644
36068 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36069 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36070 @@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36071 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36072 {
36073 /* RX_MODE controlling object */
36074 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36075 + bnx2x_init_rx_mode_obj(bp);
36076
36077 /* multicast configuration controlling object */
36078 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36079 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36080 index 614981c..11216c7 100644
36081 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36082 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36083 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36084 return rc;
36085 }
36086
36087 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36088 - struct bnx2x_rx_mode_obj *o)
36089 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36090 {
36091 if (CHIP_IS_E1x(bp)) {
36092 - o->wait_comp = bnx2x_empty_rx_mode_wait;
36093 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36094 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36095 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36096 } else {
36097 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36098 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
36099 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36100 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36101 }
36102 }
36103
36104 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36105 index acf2fe4..efb96df 100644
36106 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36107 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36108 @@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36109
36110 /********************* RX MODE ****************/
36111
36112 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36113 - struct bnx2x_rx_mode_obj *o);
36114 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36115
36116 /**
36117 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36118 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36119 index d9308c32..d87b824 100644
36120 --- a/drivers/net/ethernet/broadcom/tg3.h
36121 +++ b/drivers/net/ethernet/broadcom/tg3.h
36122 @@ -140,6 +140,7 @@
36123 #define CHIPREV_ID_5750_A0 0x4000
36124 #define CHIPREV_ID_5750_A1 0x4001
36125 #define CHIPREV_ID_5750_A3 0x4003
36126 +#define CHIPREV_ID_5750_C1 0x4201
36127 #define CHIPREV_ID_5750_C2 0x4202
36128 #define CHIPREV_ID_5752_A0_HW 0x5000
36129 #define CHIPREV_ID_5752_A0 0x6000
36130 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36131 index 8cffcdf..aadf043 100644
36132 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36133 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36134 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36135 */
36136 struct l2t_skb_cb {
36137 arp_failure_handler_func arp_failure_handler;
36138 -};
36139 +} __no_const;
36140
36141 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36142
36143 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36144 index f879e92..726f20f 100644
36145 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
36146 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36147 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36148 for (i=0; i<ETH_ALEN; i++) {
36149 tmp.addr[i] = dev->dev_addr[i];
36150 }
36151 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36152 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36153 break;
36154
36155 case DE4X5_SET_HWADDR: /* Set the hardware address */
36156 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36157 spin_lock_irqsave(&lp->lock, flags);
36158 memcpy(&statbuf, &lp->pktStats, ioc->len);
36159 spin_unlock_irqrestore(&lp->lock, flags);
36160 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
36161 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36162 return -EFAULT;
36163 break;
36164 }
36165 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36166 index d1b6cc5..cde0d97 100644
36167 --- a/drivers/net/ethernet/emulex/benet/be_main.c
36168 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
36169 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36170
36171 if (wrapped)
36172 newacc += 65536;
36173 - ACCESS_ONCE(*acc) = newacc;
36174 + ACCESS_ONCE_RW(*acc) = newacc;
36175 }
36176
36177 void be_parse_stats(struct be_adapter *adapter)
36178 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36179 index 74d749e..eefb1bd 100644
36180 --- a/drivers/net/ethernet/faraday/ftgmac100.c
36181 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
36182 @@ -31,6 +31,8 @@
36183 #include <linux/netdevice.h>
36184 #include <linux/phy.h>
36185 #include <linux/platform_device.h>
36186 +#include <linux/interrupt.h>
36187 +#include <linux/irqreturn.h>
36188 #include <net/ip.h>
36189
36190 #include "ftgmac100.h"
36191 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36192 index b901a01..1ff32ee 100644
36193 --- a/drivers/net/ethernet/faraday/ftmac100.c
36194 +++ b/drivers/net/ethernet/faraday/ftmac100.c
36195 @@ -31,6 +31,8 @@
36196 #include <linux/module.h>
36197 #include <linux/netdevice.h>
36198 #include <linux/platform_device.h>
36199 +#include <linux/interrupt.h>
36200 +#include <linux/irqreturn.h>
36201
36202 #include "ftmac100.h"
36203
36204 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36205 index d929131..aed108f 100644
36206 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36207 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36208 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36209 /* store the new cycle speed */
36210 adapter->cycle_speed = cycle_speed;
36211
36212 - ACCESS_ONCE(adapter->base_incval) = incval;
36213 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
36214 smp_mb();
36215
36216 /* grab the ptp lock */
36217 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36218 index c2e420a..26a75e0 100644
36219 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36220 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36221 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36222 struct __vxge_hw_fifo *fifo;
36223 struct vxge_hw_fifo_config *config;
36224 u32 txdl_size, txdl_per_memblock;
36225 - struct vxge_hw_mempool_cbs fifo_mp_callback;
36226 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36227 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36228 + };
36229 +
36230 struct __vxge_hw_virtualpath *vpath;
36231
36232 if ((vp == NULL) || (attr == NULL)) {
36233 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36234 goto exit;
36235 }
36236
36237 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36238 -
36239 fifo->mempool =
36240 __vxge_hw_mempool_create(vpath->hldev,
36241 fifo->config->memblock_size,
36242 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36243 index 927aa33..a6c2518 100644
36244 --- a/drivers/net/ethernet/realtek/r8169.c
36245 +++ b/drivers/net/ethernet/realtek/r8169.c
36246 @@ -747,22 +747,22 @@ struct rtl8169_private {
36247 struct mdio_ops {
36248 void (*write)(struct rtl8169_private *, int, int);
36249 int (*read)(struct rtl8169_private *, int);
36250 - } mdio_ops;
36251 + } __no_const mdio_ops;
36252
36253 struct pll_power_ops {
36254 void (*down)(struct rtl8169_private *);
36255 void (*up)(struct rtl8169_private *);
36256 - } pll_power_ops;
36257 + } __no_const pll_power_ops;
36258
36259 struct jumbo_ops {
36260 void (*enable)(struct rtl8169_private *);
36261 void (*disable)(struct rtl8169_private *);
36262 - } jumbo_ops;
36263 + } __no_const jumbo_ops;
36264
36265 struct csi_ops {
36266 void (*write)(struct rtl8169_private *, int, int);
36267 u32 (*read)(struct rtl8169_private *, int);
36268 - } csi_ops;
36269 + } __no_const csi_ops;
36270
36271 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36272 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36273 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36274 index 0767043f..08c2553 100644
36275 --- a/drivers/net/ethernet/sfc/ptp.c
36276 +++ b/drivers/net/ethernet/sfc/ptp.c
36277 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36278 (u32)((u64)ptp->start.dma_addr >> 32));
36279
36280 /* Clear flag that signals MC ready */
36281 - ACCESS_ONCE(*start) = 0;
36282 + ACCESS_ONCE_RW(*start) = 0;
36283 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36284 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36285
36286 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36287 index 0c74a70..3bc6f68 100644
36288 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36289 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36290 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36291
36292 writel(value, ioaddr + MMC_CNTRL);
36293
36294 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36295 - MMC_CNTRL, value);
36296 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36297 +// MMC_CNTRL, value);
36298 }
36299
36300 /* To mask all all interrupts.*/
36301 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36302 index 5fd6f46..ee1f265 100644
36303 --- a/drivers/net/hyperv/hyperv_net.h
36304 +++ b/drivers/net/hyperv/hyperv_net.h
36305 @@ -101,7 +101,7 @@ struct rndis_device {
36306
36307 enum rndis_device_state state;
36308 bool link_state;
36309 - atomic_t new_req_id;
36310 + atomic_unchecked_t new_req_id;
36311
36312 spinlock_t request_lock;
36313 struct list_head req_list;
36314 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36315 index 928148c..d83298e 100644
36316 --- a/drivers/net/hyperv/rndis_filter.c
36317 +++ b/drivers/net/hyperv/rndis_filter.c
36318 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36319 * template
36320 */
36321 set = &rndis_msg->msg.set_req;
36322 - set->req_id = atomic_inc_return(&dev->new_req_id);
36323 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36324
36325 /* Add to the request list */
36326 spin_lock_irqsave(&dev->request_lock, flags);
36327 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36328
36329 /* Setup the rndis set */
36330 halt = &request->request_msg.msg.halt_req;
36331 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36332 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36333
36334 /* Ignore return since this msg is optional. */
36335 rndis_filter_send_request(dev, request);
36336 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36337 index 7d39add..037e1da 100644
36338 --- a/drivers/net/ieee802154/fakehard.c
36339 +++ b/drivers/net/ieee802154/fakehard.c
36340 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36341 phy->transmit_power = 0xbf;
36342
36343 dev->netdev_ops = &fake_ops;
36344 - dev->ml_priv = &fake_mlme;
36345 + dev->ml_priv = (void *)&fake_mlme;
36346
36347 priv = netdev_priv(dev);
36348 priv->phy = phy;
36349 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36350 index 0f0f9ce..0ca5819 100644
36351 --- a/drivers/net/macvtap.c
36352 +++ b/drivers/net/macvtap.c
36353 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36354 return NOTIFY_DONE;
36355 }
36356
36357 -static struct notifier_block macvtap_notifier_block __read_mostly = {
36358 +static struct notifier_block macvtap_notifier_block = {
36359 .notifier_call = macvtap_device_event,
36360 };
36361
36362 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36363 index daec9b0..6428fcb 100644
36364 --- a/drivers/net/phy/mdio-bitbang.c
36365 +++ b/drivers/net/phy/mdio-bitbang.c
36366 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36367 struct mdiobb_ctrl *ctrl = bus->priv;
36368
36369 module_put(ctrl->ops->owner);
36370 + mdiobus_unregister(bus);
36371 mdiobus_free(bus);
36372 }
36373 EXPORT_SYMBOL(free_mdio_bitbang);
36374 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36375 index eb3f5ce..d773730 100644
36376 --- a/drivers/net/ppp/ppp_generic.c
36377 +++ b/drivers/net/ppp/ppp_generic.c
36378 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36379 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36380 struct ppp_stats stats;
36381 struct ppp_comp_stats cstats;
36382 - char *vers;
36383
36384 switch (cmd) {
36385 case SIOCGPPPSTATS:
36386 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36387 break;
36388
36389 case SIOCGPPPVER:
36390 - vers = PPP_VERSION;
36391 - if (copy_to_user(addr, vers, strlen(vers) + 1))
36392 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36393 break;
36394 err = 0;
36395 break;
36396 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36397 index ad86660..9fd0884 100644
36398 --- a/drivers/net/team/team.c
36399 +++ b/drivers/net/team/team.c
36400 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36401 return NOTIFY_DONE;
36402 }
36403
36404 -static struct notifier_block team_notifier_block __read_mostly = {
36405 +static struct notifier_block team_notifier_block = {
36406 .notifier_call = team_device_event,
36407 };
36408
36409 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36410 index 0873cdc..ddb178e 100644
36411 --- a/drivers/net/tun.c
36412 +++ b/drivers/net/tun.c
36413 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36414 }
36415
36416 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36417 - unsigned long arg, int ifreq_len)
36418 + unsigned long arg, size_t ifreq_len)
36419 {
36420 struct tun_file *tfile = file->private_data;
36421 struct tun_struct *tun;
36422 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36423 int vnet_hdr_sz;
36424 int ret;
36425
36426 + if (ifreq_len > sizeof ifr)
36427 + return -EFAULT;
36428 +
36429 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36430 if (copy_from_user(&ifr, argp, ifreq_len))
36431 return -EFAULT;
36432 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36433 index 605a4ba..a883dd1 100644
36434 --- a/drivers/net/usb/hso.c
36435 +++ b/drivers/net/usb/hso.c
36436 @@ -71,7 +71,7 @@
36437 #include <asm/byteorder.h>
36438 #include <linux/serial_core.h>
36439 #include <linux/serial.h>
36440 -
36441 +#include <asm/local.h>
36442
36443 #define MOD_AUTHOR "Option Wireless"
36444 #define MOD_DESCRIPTION "USB High Speed Option driver"
36445 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36446 struct urb *urb;
36447
36448 urb = serial->rx_urb[0];
36449 - if (serial->port.count > 0) {
36450 + if (atomic_read(&serial->port.count) > 0) {
36451 count = put_rxbuf_data(urb, serial);
36452 if (count == -1)
36453 return;
36454 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
36455 DUMP1(urb->transfer_buffer, urb->actual_length);
36456
36457 /* Anyone listening? */
36458 - if (serial->port.count == 0)
36459 + if (atomic_read(&serial->port.count) == 0)
36460 return;
36461
36462 if (status == 0) {
36463 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36464 tty_port_tty_set(&serial->port, tty);
36465
36466 /* check for port already opened, if not set the termios */
36467 - serial->port.count++;
36468 - if (serial->port.count == 1) {
36469 + if (atomic_inc_return(&serial->port.count) == 1) {
36470 serial->rx_state = RX_IDLE;
36471 /* Force default termio settings */
36472 _hso_serial_set_termios(tty, NULL);
36473 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36474 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
36475 if (result) {
36476 hso_stop_serial_device(serial->parent);
36477 - serial->port.count--;
36478 + atomic_dec(&serial->port.count);
36479 kref_put(&serial->parent->ref, hso_serial_ref_free);
36480 }
36481 } else {
36482 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
36483
36484 /* reset the rts and dtr */
36485 /* do the actual close */
36486 - serial->port.count--;
36487 + atomic_dec(&serial->port.count);
36488
36489 - if (serial->port.count <= 0) {
36490 - serial->port.count = 0;
36491 + if (atomic_read(&serial->port.count) <= 0) {
36492 + atomic_set(&serial->port.count, 0);
36493 tty_port_tty_set(&serial->port, NULL);
36494 if (!usb_gone)
36495 hso_stop_serial_device(serial->parent);
36496 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
36497
36498 /* the actual setup */
36499 spin_lock_irqsave(&serial->serial_lock, flags);
36500 - if (serial->port.count)
36501 + if (atomic_read(&serial->port.count))
36502 _hso_serial_set_termios(tty, old);
36503 else
36504 tty->termios = *old;
36505 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
36506 D1("Pending read interrupt on port %d\n", i);
36507 spin_lock(&serial->serial_lock);
36508 if (serial->rx_state == RX_IDLE &&
36509 - serial->port.count > 0) {
36510 + atomic_read(&serial->port.count) > 0) {
36511 /* Setup and send a ctrl req read on
36512 * port i */
36513 if (!serial->rx_urb_filled[0]) {
36514 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
36515 /* Start all serial ports */
36516 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
36517 if (serial_table[i] && (serial_table[i]->interface == iface)) {
36518 - if (dev2ser(serial_table[i])->port.count) {
36519 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
36520 result =
36521 hso_start_serial_device(serial_table[i], GFP_NOIO);
36522 hso_kick_transmit(dev2ser(serial_table[i]));
36523 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36524 index 8d78253..bebbb68 100644
36525 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36526 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36527 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36528 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
36529 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
36530
36531 - ACCESS_ONCE(ads->ds_link) = i->link;
36532 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
36533 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
36534 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
36535
36536 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
36537 ctl6 = SM(i->keytype, AR_EncrType);
36538 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36539
36540 if ((i->is_first || i->is_last) &&
36541 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
36542 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
36543 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
36544 | set11nTries(i->rates, 1)
36545 | set11nTries(i->rates, 2)
36546 | set11nTries(i->rates, 3)
36547 | (i->dur_update ? AR_DurUpdateEna : 0)
36548 | SM(0, AR_BurstDur);
36549
36550 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
36551 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
36552 | set11nRate(i->rates, 1)
36553 | set11nRate(i->rates, 2)
36554 | set11nRate(i->rates, 3);
36555 } else {
36556 - ACCESS_ONCE(ads->ds_ctl2) = 0;
36557 - ACCESS_ONCE(ads->ds_ctl3) = 0;
36558 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
36559 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
36560 }
36561
36562 if (!i->is_first) {
36563 - ACCESS_ONCE(ads->ds_ctl0) = 0;
36564 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36565 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36566 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
36567 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36568 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36569 return;
36570 }
36571
36572 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36573 break;
36574 }
36575
36576 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36577 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36578 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36579 | SM(i->txpower, AR_XmitPower)
36580 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36581 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36582 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
36583 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
36584
36585 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36586 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36587 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36588 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36589
36590 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
36591 return;
36592
36593 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36594 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36595 | set11nPktDurRTSCTS(i->rates, 1);
36596
36597 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36598 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36599 | set11nPktDurRTSCTS(i->rates, 3);
36600
36601 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36602 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36603 | set11nRateFlags(i->rates, 1)
36604 | set11nRateFlags(i->rates, 2)
36605 | set11nRateFlags(i->rates, 3)
36606 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36607 index 301bf72..3f5654f 100644
36608 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36609 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36610 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36611 (i->qcu << AR_TxQcuNum_S) | desc_len;
36612
36613 checksum += val;
36614 - ACCESS_ONCE(ads->info) = val;
36615 + ACCESS_ONCE_RW(ads->info) = val;
36616
36617 checksum += i->link;
36618 - ACCESS_ONCE(ads->link) = i->link;
36619 + ACCESS_ONCE_RW(ads->link) = i->link;
36620
36621 checksum += i->buf_addr[0];
36622 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
36623 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
36624 checksum += i->buf_addr[1];
36625 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
36626 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
36627 checksum += i->buf_addr[2];
36628 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
36629 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
36630 checksum += i->buf_addr[3];
36631 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
36632 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
36633
36634 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
36635 - ACCESS_ONCE(ads->ctl3) = val;
36636 + ACCESS_ONCE_RW(ads->ctl3) = val;
36637 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
36638 - ACCESS_ONCE(ads->ctl5) = val;
36639 + ACCESS_ONCE_RW(ads->ctl5) = val;
36640 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
36641 - ACCESS_ONCE(ads->ctl7) = val;
36642 + ACCESS_ONCE_RW(ads->ctl7) = val;
36643 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
36644 - ACCESS_ONCE(ads->ctl9) = val;
36645 + ACCESS_ONCE_RW(ads->ctl9) = val;
36646
36647 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
36648 - ACCESS_ONCE(ads->ctl10) = checksum;
36649 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
36650
36651 if (i->is_first || i->is_last) {
36652 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
36653 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
36654 | set11nTries(i->rates, 1)
36655 | set11nTries(i->rates, 2)
36656 | set11nTries(i->rates, 3)
36657 | (i->dur_update ? AR_DurUpdateEna : 0)
36658 | SM(0, AR_BurstDur);
36659
36660 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
36661 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
36662 | set11nRate(i->rates, 1)
36663 | set11nRate(i->rates, 2)
36664 | set11nRate(i->rates, 3);
36665 } else {
36666 - ACCESS_ONCE(ads->ctl13) = 0;
36667 - ACCESS_ONCE(ads->ctl14) = 0;
36668 + ACCESS_ONCE_RW(ads->ctl13) = 0;
36669 + ACCESS_ONCE_RW(ads->ctl14) = 0;
36670 }
36671
36672 ads->ctl20 = 0;
36673 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36674
36675 ctl17 = SM(i->keytype, AR_EncrType);
36676 if (!i->is_first) {
36677 - ACCESS_ONCE(ads->ctl11) = 0;
36678 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36679 - ACCESS_ONCE(ads->ctl15) = 0;
36680 - ACCESS_ONCE(ads->ctl16) = 0;
36681 - ACCESS_ONCE(ads->ctl17) = ctl17;
36682 - ACCESS_ONCE(ads->ctl18) = 0;
36683 - ACCESS_ONCE(ads->ctl19) = 0;
36684 + ACCESS_ONCE_RW(ads->ctl11) = 0;
36685 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36686 + ACCESS_ONCE_RW(ads->ctl15) = 0;
36687 + ACCESS_ONCE_RW(ads->ctl16) = 0;
36688 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36689 + ACCESS_ONCE_RW(ads->ctl18) = 0;
36690 + ACCESS_ONCE_RW(ads->ctl19) = 0;
36691 return;
36692 }
36693
36694 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36695 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36696 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36697 | SM(i->txpower, AR_XmitPower)
36698 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36699 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36700 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36701 ctl12 |= SM(val, AR_PAPRDChainMask);
36702
36703 - ACCESS_ONCE(ads->ctl12) = ctl12;
36704 - ACCESS_ONCE(ads->ctl17) = ctl17;
36705 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36706 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36707
36708 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36709 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36710 | set11nPktDurRTSCTS(i->rates, 1);
36711
36712 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36713 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36714 | set11nPktDurRTSCTS(i->rates, 3);
36715
36716 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36717 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36718 | set11nRateFlags(i->rates, 1)
36719 | set11nRateFlags(i->rates, 2)
36720 | set11nRateFlags(i->rates, 3)
36721 | SM(i->rtscts_rate, AR_RTSCTSRate);
36722
36723 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36724 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36725 }
36726
36727 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36728 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36729 index dbc1b7a..67e2ca2 100644
36730 --- a/drivers/net/wireless/ath/ath9k/hw.h
36731 +++ b/drivers/net/wireless/ath/ath9k/hw.h
36732 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
36733
36734 /* ANI */
36735 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36736 -};
36737 +} __no_const;
36738
36739 /**
36740 * struct ath_hw_ops - callbacks used by hardware code and driver code
36741 @@ -687,7 +687,7 @@ struct ath_hw_ops {
36742 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36743 struct ath_hw_antcomb_conf *antconf);
36744 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
36745 -};
36746 +} __no_const;
36747
36748 struct ath_nf_limits {
36749 s16 max;
36750 diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
36751 index 71ced17..cd82b12 100644
36752 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
36753 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
36754 @@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
36755 struct net_device *ndev,
36756 const struct brcmf_event_msg *e,
36757 void *data);
36758 -};
36759 +} __no_const;
36760
36761 /* basic structure of scan request */
36762 struct brcmf_cfg80211_scan_req {
36763 @@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
36764 struct brcmf_cfg80211_iscan_eloop {
36765 s32 (*handler[WL_SCAN_ERSULTS_LAST])
36766 (struct brcmf_cfg80211_info *cfg);
36767 -};
36768 +} __no_const;
36769
36770 /* dongle iscan controller */
36771 struct brcmf_cfg80211_iscan_ctrl {
36772 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36773 index e252acb..6ad1e65 100644
36774 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
36775 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36776 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36777 */
36778 if (il3945_mod_params.disable_hw_scan) {
36779 D_INFO("Disabling hw_scan\n");
36780 - il3945_mac_ops.hw_scan = NULL;
36781 + pax_open_kernel();
36782 + *(void **)&il3945_mac_ops.hw_scan = NULL;
36783 + pax_close_kernel();
36784 }
36785
36786 D_INFO("*** LOAD DRIVER ***\n");
36787 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36788 index 1a98fa3..51e6661 100644
36789 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36790 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36791 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
36792 {
36793 struct iwl_priv *priv = file->private_data;
36794 char buf[64];
36795 - int buf_size;
36796 + size_t buf_size;
36797 u32 offset, len;
36798
36799 memset(buf, 0, sizeof(buf));
36800 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
36801 struct iwl_priv *priv = file->private_data;
36802
36803 char buf[8];
36804 - int buf_size;
36805 + size_t buf_size;
36806 u32 reset_flag;
36807
36808 memset(buf, 0, sizeof(buf));
36809 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
36810 {
36811 struct iwl_priv *priv = file->private_data;
36812 char buf[8];
36813 - int buf_size;
36814 + size_t buf_size;
36815 int ht40;
36816
36817 memset(buf, 0, sizeof(buf));
36818 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
36819 {
36820 struct iwl_priv *priv = file->private_data;
36821 char buf[8];
36822 - int buf_size;
36823 + size_t buf_size;
36824 int value;
36825
36826 memset(buf, 0, sizeof(buf));
36827 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
36828 {
36829 struct iwl_priv *priv = file->private_data;
36830 char buf[8];
36831 - int buf_size;
36832 + size_t buf_size;
36833 int clear;
36834
36835 memset(buf, 0, sizeof(buf));
36836 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
36837 {
36838 struct iwl_priv *priv = file->private_data;
36839 char buf[8];
36840 - int buf_size;
36841 + size_t buf_size;
36842 int trace;
36843
36844 memset(buf, 0, sizeof(buf));
36845 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
36846 {
36847 struct iwl_priv *priv = file->private_data;
36848 char buf[8];
36849 - int buf_size;
36850 + size_t buf_size;
36851 int missed;
36852
36853 memset(buf, 0, sizeof(buf));
36854 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
36855
36856 struct iwl_priv *priv = file->private_data;
36857 char buf[8];
36858 - int buf_size;
36859 + size_t buf_size;
36860 int plcp;
36861
36862 memset(buf, 0, sizeof(buf));
36863 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
36864
36865 struct iwl_priv *priv = file->private_data;
36866 char buf[8];
36867 - int buf_size;
36868 + size_t buf_size;
36869 int flush;
36870
36871 memset(buf, 0, sizeof(buf));
36872 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
36873
36874 struct iwl_priv *priv = file->private_data;
36875 char buf[8];
36876 - int buf_size;
36877 + size_t buf_size;
36878 int rts;
36879
36880 if (!priv->cfg->ht_params)
36881 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36882 {
36883 struct iwl_priv *priv = file->private_data;
36884 char buf[8];
36885 - int buf_size;
36886 + size_t buf_size;
36887
36888 memset(buf, 0, sizeof(buf));
36889 buf_size = min(count, sizeof(buf) - 1);
36890 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36891 struct iwl_priv *priv = file->private_data;
36892 u32 event_log_flag;
36893 char buf[8];
36894 - int buf_size;
36895 + size_t buf_size;
36896
36897 /* check that the interface is up */
36898 if (!iwl_is_ready(priv))
36899 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36900 struct iwl_priv *priv = file->private_data;
36901 char buf[8];
36902 u32 calib_disabled;
36903 - int buf_size;
36904 + size_t buf_size;
36905
36906 memset(buf, 0, sizeof(buf));
36907 buf_size = min(count, sizeof(buf) - 1);
36908 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36909 index fe0fffd..b4c5724 100644
36910 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36911 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36912 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36913 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36914
36915 char buf[8];
36916 - int buf_size;
36917 + size_t buf_size;
36918 u32 reset_flag;
36919
36920 memset(buf, 0, sizeof(buf));
36921 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36922 {
36923 struct iwl_trans *trans = file->private_data;
36924 char buf[8];
36925 - int buf_size;
36926 + size_t buf_size;
36927 int csr;
36928
36929 memset(buf, 0, sizeof(buf));
36930 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36931 index 429ca32..f86236b 100644
36932 --- a/drivers/net/wireless/mac80211_hwsim.c
36933 +++ b/drivers/net/wireless/mac80211_hwsim.c
36934 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
36935 return -EINVAL;
36936
36937 if (fake_hw_scan) {
36938 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36939 - mac80211_hwsim_ops.sw_scan_start = NULL;
36940 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36941 + pax_open_kernel();
36942 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36943 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36944 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36945 + pax_close_kernel();
36946 }
36947
36948 spin_lock_init(&hwsim_radio_lock);
36949 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36950 index bd1f0cb..db85ab0 100644
36951 --- a/drivers/net/wireless/rndis_wlan.c
36952 +++ b/drivers/net/wireless/rndis_wlan.c
36953 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36954
36955 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36956
36957 - if (rts_threshold < 0 || rts_threshold > 2347)
36958 + if (rts_threshold > 2347)
36959 rts_threshold = 2347;
36960
36961 tmp = cpu_to_le32(rts_threshold);
36962 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36963 index 0751b35..246ba3e 100644
36964 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36965 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36966 @@ -398,7 +398,7 @@ struct rt2x00_intf {
36967 * for hardware which doesn't support hardware
36968 * sequence counting.
36969 */
36970 - atomic_t seqno;
36971 + atomic_unchecked_t seqno;
36972 };
36973
36974 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36975 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36976 index e488b94..14b6a0c 100644
36977 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36978 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36979 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36980 * sequence counter given by mac80211.
36981 */
36982 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36983 - seqno = atomic_add_return(0x10, &intf->seqno);
36984 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36985 else
36986 - seqno = atomic_read(&intf->seqno);
36987 + seqno = atomic_read_unchecked(&intf->seqno);
36988
36989 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36990 hdr->seq_ctrl |= cpu_to_le16(seqno);
36991 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
36992 index e2750a1..797e179 100644
36993 --- a/drivers/net/wireless/ti/wl1251/sdio.c
36994 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
36995 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
36996
36997 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
36998
36999 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37000 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37001 + pax_open_kernel();
37002 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37003 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37004 + pax_close_kernel();
37005
37006 wl1251_info("using dedicated interrupt line");
37007 } else {
37008 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37009 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37010 + pax_open_kernel();
37011 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37012 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37013 + pax_close_kernel();
37014
37015 wl1251_info("using SDIO interrupt");
37016 }
37017 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37018 index dadf1db..d9db7a7 100644
37019 --- a/drivers/net/wireless/ti/wl12xx/main.c
37020 +++ b/drivers/net/wireless/ti/wl12xx/main.c
37021 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37022 sizeof(wl->conf.mem));
37023
37024 /* read data preparation is only needed by wl127x */
37025 - wl->ops->prepare_read = wl127x_prepare_read;
37026 + pax_open_kernel();
37027 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37028 + pax_close_kernel();
37029
37030 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37031 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37032 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37033 sizeof(wl->conf.mem));
37034
37035 /* read data preparation is only needed by wl127x */
37036 - wl->ops->prepare_read = wl127x_prepare_read;
37037 + pax_open_kernel();
37038 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37039 + pax_close_kernel();
37040
37041 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37042 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37043 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37044 index a39682a..1e8220c 100644
37045 --- a/drivers/net/wireless/ti/wl18xx/main.c
37046 +++ b/drivers/net/wireless/ti/wl18xx/main.c
37047 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37048 }
37049
37050 if (!checksum_param) {
37051 - wl18xx_ops.set_rx_csum = NULL;
37052 - wl18xx_ops.init_vif = NULL;
37053 + pax_open_kernel();
37054 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
37055 + *(void **)&wl18xx_ops.init_vif = NULL;
37056 + pax_close_kernel();
37057 }
37058
37059 /* Enable 11a Band only if we have 5G antennas */
37060 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37061 index d93b2b6..ae50401 100644
37062 --- a/drivers/oprofile/buffer_sync.c
37063 +++ b/drivers/oprofile/buffer_sync.c
37064 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37065 if (cookie == NO_COOKIE)
37066 offset = pc;
37067 if (cookie == INVALID_COOKIE) {
37068 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37069 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37070 offset = pc;
37071 }
37072 if (cookie != last_cookie) {
37073 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37074 /* add userspace sample */
37075
37076 if (!mm) {
37077 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
37078 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37079 return 0;
37080 }
37081
37082 cookie = lookup_dcookie(mm, s->eip, &offset);
37083
37084 if (cookie == INVALID_COOKIE) {
37085 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37086 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37087 return 0;
37088 }
37089
37090 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37091 /* ignore backtraces if failed to add a sample */
37092 if (state == sb_bt_start) {
37093 state = sb_bt_ignore;
37094 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37095 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37096 }
37097 }
37098 release_mm(mm);
37099 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37100 index c0cc4e7..44d4e54 100644
37101 --- a/drivers/oprofile/event_buffer.c
37102 +++ b/drivers/oprofile/event_buffer.c
37103 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37104 }
37105
37106 if (buffer_pos == buffer_size) {
37107 - atomic_inc(&oprofile_stats.event_lost_overflow);
37108 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37109 return;
37110 }
37111
37112 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37113 index ed2c3ec..deda85a 100644
37114 --- a/drivers/oprofile/oprof.c
37115 +++ b/drivers/oprofile/oprof.c
37116 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37117 if (oprofile_ops.switch_events())
37118 return;
37119
37120 - atomic_inc(&oprofile_stats.multiplex_counter);
37121 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37122 start_switch_worker();
37123 }
37124
37125 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37126 index 917d28e..d62d981 100644
37127 --- a/drivers/oprofile/oprofile_stats.c
37128 +++ b/drivers/oprofile/oprofile_stats.c
37129 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37130 cpu_buf->sample_invalid_eip = 0;
37131 }
37132
37133 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37134 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37135 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
37136 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37137 - atomic_set(&oprofile_stats.multiplex_counter, 0);
37138 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37139 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37140 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37141 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37142 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37143 }
37144
37145
37146 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37147 index 38b6fc0..b5cbfce 100644
37148 --- a/drivers/oprofile/oprofile_stats.h
37149 +++ b/drivers/oprofile/oprofile_stats.h
37150 @@ -13,11 +13,11 @@
37151 #include <linux/atomic.h>
37152
37153 struct oprofile_stat_struct {
37154 - atomic_t sample_lost_no_mm;
37155 - atomic_t sample_lost_no_mapping;
37156 - atomic_t bt_lost_no_mapping;
37157 - atomic_t event_lost_overflow;
37158 - atomic_t multiplex_counter;
37159 + atomic_unchecked_t sample_lost_no_mm;
37160 + atomic_unchecked_t sample_lost_no_mapping;
37161 + atomic_unchecked_t bt_lost_no_mapping;
37162 + atomic_unchecked_t event_lost_overflow;
37163 + atomic_unchecked_t multiplex_counter;
37164 };
37165
37166 extern struct oprofile_stat_struct oprofile_stats;
37167 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37168 index 849357c..b83c1e0 100644
37169 --- a/drivers/oprofile/oprofilefs.c
37170 +++ b/drivers/oprofile/oprofilefs.c
37171 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37172
37173
37174 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37175 - char const *name, atomic_t *val)
37176 + char const *name, atomic_unchecked_t *val)
37177 {
37178 return __oprofilefs_create_file(sb, root, name,
37179 &atomic_ro_fops, 0444, val);
37180 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37181 index 3f56bc0..707d642 100644
37182 --- a/drivers/parport/procfs.c
37183 +++ b/drivers/parport/procfs.c
37184 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37185
37186 *ppos += len;
37187
37188 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37189 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37190 }
37191
37192 #ifdef CONFIG_PARPORT_1284
37193 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37194
37195 *ppos += len;
37196
37197 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37198 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37199 }
37200 #endif /* IEEE1284.3 support. */
37201
37202 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37203 index a6a71c4..c91097b 100644
37204 --- a/drivers/pci/hotplug/cpcihp_generic.c
37205 +++ b/drivers/pci/hotplug/cpcihp_generic.c
37206 @@ -73,7 +73,6 @@ static u16 port;
37207 static unsigned int enum_bit;
37208 static u8 enum_mask;
37209
37210 -static struct cpci_hp_controller_ops generic_hpc_ops;
37211 static struct cpci_hp_controller generic_hpc;
37212
37213 static int __init validate_parameters(void)
37214 @@ -139,6 +138,10 @@ static int query_enum(void)
37215 return ((value & enum_mask) == enum_mask);
37216 }
37217
37218 +static struct cpci_hp_controller_ops generic_hpc_ops = {
37219 + .query_enum = query_enum,
37220 +};
37221 +
37222 static int __init cpcihp_generic_init(void)
37223 {
37224 int status;
37225 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37226 pci_dev_put(dev);
37227
37228 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37229 - generic_hpc_ops.query_enum = query_enum;
37230 generic_hpc.ops = &generic_hpc_ops;
37231
37232 status = cpci_hp_register_controller(&generic_hpc);
37233 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37234 index 6bf8d2a..9711ce0 100644
37235 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
37236 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37237 @@ -59,7 +59,6 @@
37238 /* local variables */
37239 static bool debug;
37240 static bool poll;
37241 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
37242 static struct cpci_hp_controller zt5550_hpc;
37243
37244 /* Primary cPCI bus bridge device */
37245 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37246 return 0;
37247 }
37248
37249 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37250 + .query_enum = zt5550_hc_query_enum,
37251 +};
37252 +
37253 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37254 {
37255 int status;
37256 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37257 dbg("returned from zt5550_hc_config");
37258
37259 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37260 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37261 zt5550_hpc.ops = &zt5550_hpc_ops;
37262 if(!poll) {
37263 zt5550_hpc.irq = hc_dev->irq;
37264 zt5550_hpc.irq_flags = IRQF_SHARED;
37265 zt5550_hpc.dev_id = hc_dev;
37266
37267 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37268 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37269 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37270 + pax_open_kernel();
37271 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37272 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37273 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37274 + pax_open_kernel();
37275 } else {
37276 info("using ENUM# polling mode");
37277 }
37278 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37279 index 76ba8a1..20ca857 100644
37280 --- a/drivers/pci/hotplug/cpqphp_nvram.c
37281 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
37282 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37283
37284 void compaq_nvram_init (void __iomem *rom_start)
37285 {
37286 +
37287 +#ifndef CONFIG_PAX_KERNEXEC
37288 if (rom_start) {
37289 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37290 }
37291 +#endif
37292 +
37293 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37294
37295 /* initialize our int15 lock */
37296 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37297 index 213753b..b4abaac 100644
37298 --- a/drivers/pci/pcie/aspm.c
37299 +++ b/drivers/pci/pcie/aspm.c
37300 @@ -27,9 +27,9 @@
37301 #define MODULE_PARAM_PREFIX "pcie_aspm."
37302
37303 /* Note: those are not register definitions */
37304 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37305 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37306 -#define ASPM_STATE_L1 (4) /* L1 state */
37307 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37308 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37309 +#define ASPM_STATE_L1 (4U) /* L1 state */
37310 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37311 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37312
37313 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37314 index ec909af..e7517f3 100644
37315 --- a/drivers/pci/probe.c
37316 +++ b/drivers/pci/probe.c
37317 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37318 struct pci_bus_region region;
37319 bool bar_too_big = false, bar_disabled = false;
37320
37321 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37322 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37323
37324 /* No printks while decoding is disabled! */
37325 if (!dev->mmio_always_on) {
37326 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37327 index 9b8505c..f00870a 100644
37328 --- a/drivers/pci/proc.c
37329 +++ b/drivers/pci/proc.c
37330 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37331 static int __init pci_proc_init(void)
37332 {
37333 struct pci_dev *dev = NULL;
37334 +
37335 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
37336 +#ifdef CONFIG_GRKERNSEC_PROC_USER
37337 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37338 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37339 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37340 +#endif
37341 +#else
37342 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37343 +#endif
37344 proc_create("devices", 0, proc_bus_pci_dir,
37345 &proc_bus_pci_dev_operations);
37346 proc_initialized = 1;
37347 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37348 index 75dd651..2af4c9a 100644
37349 --- a/drivers/platform/x86/thinkpad_acpi.c
37350 +++ b/drivers/platform/x86/thinkpad_acpi.c
37351 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37352 return 0;
37353 }
37354
37355 -void static hotkey_mask_warn_incomplete_mask(void)
37356 +static void hotkey_mask_warn_incomplete_mask(void)
37357 {
37358 /* log only what the user can fix... */
37359 const u32 wantedmask = hotkey_driver_mask &
37360 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37361 }
37362 }
37363
37364 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37365 - struct tp_nvram_state *newn,
37366 - const u32 event_mask)
37367 -{
37368 -
37369 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37370 do { \
37371 if ((event_mask & (1 << __scancode)) && \
37372 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37373 tpacpi_hotkey_send_key(__scancode); \
37374 } while (0)
37375
37376 - void issue_volchange(const unsigned int oldvol,
37377 - const unsigned int newvol)
37378 - {
37379 - unsigned int i = oldvol;
37380 +static void issue_volchange(const unsigned int oldvol,
37381 + const unsigned int newvol,
37382 + const u32 event_mask)
37383 +{
37384 + unsigned int i = oldvol;
37385
37386 - while (i > newvol) {
37387 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37388 - i--;
37389 - }
37390 - while (i < newvol) {
37391 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37392 - i++;
37393 - }
37394 + while (i > newvol) {
37395 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37396 + i--;
37397 }
37398 + while (i < newvol) {
37399 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37400 + i++;
37401 + }
37402 +}
37403
37404 - void issue_brightnesschange(const unsigned int oldbrt,
37405 - const unsigned int newbrt)
37406 - {
37407 - unsigned int i = oldbrt;
37408 +static void issue_brightnesschange(const unsigned int oldbrt,
37409 + const unsigned int newbrt,
37410 + const u32 event_mask)
37411 +{
37412 + unsigned int i = oldbrt;
37413
37414 - while (i > newbrt) {
37415 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37416 - i--;
37417 - }
37418 - while (i < newbrt) {
37419 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37420 - i++;
37421 - }
37422 + while (i > newbrt) {
37423 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37424 + i--;
37425 + }
37426 + while (i < newbrt) {
37427 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37428 + i++;
37429 }
37430 +}
37431
37432 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37433 + struct tp_nvram_state *newn,
37434 + const u32 event_mask)
37435 +{
37436 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37437 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37438 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37439 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37440 oldn->volume_level != newn->volume_level) {
37441 /* recently muted, or repeated mute keypress, or
37442 * multiple presses ending in mute */
37443 - issue_volchange(oldn->volume_level, newn->volume_level);
37444 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37445 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37446 }
37447 } else {
37448 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37449 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37450 }
37451 if (oldn->volume_level != newn->volume_level) {
37452 - issue_volchange(oldn->volume_level, newn->volume_level);
37453 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37454 } else if (oldn->volume_toggle != newn->volume_toggle) {
37455 /* repeated vol up/down keypress at end of scale ? */
37456 if (newn->volume_level == 0)
37457 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37458 /* handle brightness */
37459 if (oldn->brightness_level != newn->brightness_level) {
37460 issue_brightnesschange(oldn->brightness_level,
37461 - newn->brightness_level);
37462 + newn->brightness_level,
37463 + event_mask);
37464 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
37465 /* repeated key presses that didn't change state */
37466 if (newn->brightness_level == 0)
37467 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37468 && !tp_features.bright_unkfw)
37469 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37470 }
37471 +}
37472
37473 #undef TPACPI_COMPARE_KEY
37474 #undef TPACPI_MAY_SEND_KEY
37475 -}
37476
37477 /*
37478 * Polling driver
37479 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
37480 index 769d265..a3a05ca 100644
37481 --- a/drivers/pnp/pnpbios/bioscalls.c
37482 +++ b/drivers/pnp/pnpbios/bioscalls.c
37483 @@ -58,7 +58,7 @@ do { \
37484 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37485 } while(0)
37486
37487 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37488 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37489 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37490
37491 /*
37492 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37493
37494 cpu = get_cpu();
37495 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37496 +
37497 + pax_open_kernel();
37498 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37499 + pax_close_kernel();
37500
37501 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37502 spin_lock_irqsave(&pnp_bios_lock, flags);
37503 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37504 :"memory");
37505 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37506
37507 + pax_open_kernel();
37508 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37509 + pax_close_kernel();
37510 +
37511 put_cpu();
37512
37513 /* If we get here and this is set then the PnP BIOS faulted on us. */
37514 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
37515 return status;
37516 }
37517
37518 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
37519 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37520 {
37521 int i;
37522
37523 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37524 pnp_bios_callpoint.offset = header->fields.pm16offset;
37525 pnp_bios_callpoint.segment = PNP_CS16;
37526
37527 + pax_open_kernel();
37528 +
37529 for_each_possible_cpu(i) {
37530 struct desc_struct *gdt = get_cpu_gdt_table(i);
37531 if (!gdt)
37532 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37533 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37534 (unsigned long)__va(header->fields.pm16dseg));
37535 }
37536 +
37537 + pax_close_kernel();
37538 }
37539 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
37540 index b0ecacb..7c9da2e 100644
37541 --- a/drivers/pnp/resource.c
37542 +++ b/drivers/pnp/resource.c
37543 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
37544 return 1;
37545
37546 /* check if the resource is valid */
37547 - if (*irq < 0 || *irq > 15)
37548 + if (*irq > 15)
37549 return 0;
37550
37551 /* check if the resource is reserved */
37552 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
37553 return 1;
37554
37555 /* check if the resource is valid */
37556 - if (*dma < 0 || *dma == 4 || *dma > 7)
37557 + if (*dma == 4 || *dma > 7)
37558 return 0;
37559
37560 /* check if the resource is reserved */
37561 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
37562 index 7df7c5f..bd48c47 100644
37563 --- a/drivers/power/pda_power.c
37564 +++ b/drivers/power/pda_power.c
37565 @@ -37,7 +37,11 @@ static int polling;
37566
37567 #ifdef CONFIG_USB_OTG_UTILS
37568 static struct usb_phy *transceiver;
37569 -static struct notifier_block otg_nb;
37570 +static int otg_handle_notification(struct notifier_block *nb,
37571 + unsigned long event, void *unused);
37572 +static struct notifier_block otg_nb = {
37573 + .notifier_call = otg_handle_notification
37574 +};
37575 #endif
37576
37577 static struct regulator *ac_draw;
37578 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
37579
37580 #ifdef CONFIG_USB_OTG_UTILS
37581 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
37582 - otg_nb.notifier_call = otg_handle_notification;
37583 ret = usb_register_notifier(transceiver, &otg_nb);
37584 if (ret) {
37585 dev_err(dev, "failure to register otg notifier\n");
37586 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
37587 index 8d53174..04c65de 100644
37588 --- a/drivers/regulator/max8660.c
37589 +++ b/drivers/regulator/max8660.c
37590 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
37591 max8660->shadow_regs[MAX8660_OVER1] = 5;
37592 } else {
37593 /* Otherwise devices can be toggled via software */
37594 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
37595 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
37596 + pax_open_kernel();
37597 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
37598 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
37599 + pax_close_kernel();
37600 }
37601
37602 /*
37603 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
37604 index 1fa6381..f58834e 100644
37605 --- a/drivers/regulator/mc13892-regulator.c
37606 +++ b/drivers/regulator/mc13892-regulator.c
37607 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
37608 }
37609 mc13xxx_unlock(mc13892);
37610
37611 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37612 + pax_open_kernel();
37613 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37614 = mc13892_vcam_set_mode;
37615 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37616 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37617 = mc13892_vcam_get_mode;
37618 + pax_close_kernel();
37619
37620 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
37621 ARRAY_SIZE(mc13892_regulators));
37622 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
37623 index cace6d3..f623fda 100644
37624 --- a/drivers/rtc/rtc-dev.c
37625 +++ b/drivers/rtc/rtc-dev.c
37626 @@ -14,6 +14,7 @@
37627 #include <linux/module.h>
37628 #include <linux/rtc.h>
37629 #include <linux/sched.h>
37630 +#include <linux/grsecurity.h>
37631 #include "rtc-core.h"
37632
37633 static dev_t rtc_devt;
37634 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
37635 if (copy_from_user(&tm, uarg, sizeof(tm)))
37636 return -EFAULT;
37637
37638 + gr_log_timechange();
37639 +
37640 return rtc_set_time(rtc, &tm);
37641
37642 case RTC_PIE_ON:
37643 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
37644 index 4ad7e36..d004679 100644
37645 --- a/drivers/scsi/bfa/bfa.h
37646 +++ b/drivers/scsi/bfa/bfa.h
37647 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
37648 u32 *end);
37649 int cpe_vec_q0;
37650 int rme_vec_q0;
37651 -};
37652 +} __no_const;
37653 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
37654
37655 struct bfa_faa_cbfn_s {
37656 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
37657 index e693af6..2e525b6 100644
37658 --- a/drivers/scsi/bfa/bfa_fcpim.h
37659 +++ b/drivers/scsi/bfa/bfa_fcpim.h
37660 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
37661
37662 struct bfa_itn_s {
37663 bfa_isr_func_t isr;
37664 -};
37665 +} __no_const;
37666
37667 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37668 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
37669 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
37670 index 23a90e7..9cf04ee 100644
37671 --- a/drivers/scsi/bfa/bfa_ioc.h
37672 +++ b/drivers/scsi/bfa/bfa_ioc.h
37673 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
37674 bfa_ioc_disable_cbfn_t disable_cbfn;
37675 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
37676 bfa_ioc_reset_cbfn_t reset_cbfn;
37677 -};
37678 +} __no_const;
37679
37680 /*
37681 * IOC event notification mechanism.
37682 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
37683 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
37684 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
37685 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
37686 -};
37687 +} __no_const;
37688
37689 /*
37690 * Queue element to wait for room in request queue. FIFO order is
37691 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
37692 index 593085a..47aa999 100644
37693 --- a/drivers/scsi/hosts.c
37694 +++ b/drivers/scsi/hosts.c
37695 @@ -42,7 +42,7 @@
37696 #include "scsi_logging.h"
37697
37698
37699 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37700 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37701
37702
37703 static void scsi_host_cls_release(struct device *dev)
37704 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
37705 * subtract one because we increment first then return, but we need to
37706 * know what the next host number was before increment
37707 */
37708 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37709 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37710 shost->dma_channel = 0xff;
37711
37712 /* These three are default values which can be overridden */
37713 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37714 index 4217e49..9c77e3e 100644
37715 --- a/drivers/scsi/hpsa.c
37716 +++ b/drivers/scsi/hpsa.c
37717 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
37718 unsigned long flags;
37719
37720 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37721 - return h->access.command_completed(h, q);
37722 + return h->access->command_completed(h, q);
37723
37724 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
37725 a = rq->head[rq->current_entry];
37726 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
37727 while (!list_empty(&h->reqQ)) {
37728 c = list_entry(h->reqQ.next, struct CommandList, list);
37729 /* can't do anything if fifo is full */
37730 - if ((h->access.fifo_full(h))) {
37731 + if ((h->access->fifo_full(h))) {
37732 dev_warn(&h->pdev->dev, "fifo full\n");
37733 break;
37734 }
37735 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
37736
37737 /* Tell the controller execute command */
37738 spin_unlock_irqrestore(&h->lock, flags);
37739 - h->access.submit_command(h, c);
37740 + h->access->submit_command(h, c);
37741 spin_lock_irqsave(&h->lock, flags);
37742 }
37743 spin_unlock_irqrestore(&h->lock, flags);
37744 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
37745
37746 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
37747 {
37748 - return h->access.command_completed(h, q);
37749 + return h->access->command_completed(h, q);
37750 }
37751
37752 static inline bool interrupt_pending(struct ctlr_info *h)
37753 {
37754 - return h->access.intr_pending(h);
37755 + return h->access->intr_pending(h);
37756 }
37757
37758 static inline long interrupt_not_for_us(struct ctlr_info *h)
37759 {
37760 - return (h->access.intr_pending(h) == 0) ||
37761 + return (h->access->intr_pending(h) == 0) ||
37762 (h->interrupts_enabled == 0);
37763 }
37764
37765 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
37766 if (prod_index < 0)
37767 return -ENODEV;
37768 h->product_name = products[prod_index].product_name;
37769 - h->access = *(products[prod_index].access);
37770 + h->access = products[prod_index].access;
37771
37772 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
37773 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
37774 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
37775
37776 assert_spin_locked(&lockup_detector_lock);
37777 remove_ctlr_from_lockup_detector_list(h);
37778 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37779 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37780 spin_lock_irqsave(&h->lock, flags);
37781 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
37782 spin_unlock_irqrestore(&h->lock, flags);
37783 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
37784 }
37785
37786 /* make sure the board interrupts are off */
37787 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37788 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37789
37790 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
37791 goto clean2;
37792 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
37793 * fake ones to scoop up any residual completions.
37794 */
37795 spin_lock_irqsave(&h->lock, flags);
37796 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37797 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37798 spin_unlock_irqrestore(&h->lock, flags);
37799 free_irqs(h);
37800 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
37801 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
37802 dev_info(&h->pdev->dev, "Board READY.\n");
37803 dev_info(&h->pdev->dev,
37804 "Waiting for stale completions to drain.\n");
37805 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37806 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37807 msleep(10000);
37808 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37809 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37810
37811 rc = controller_reset_failed(h->cfgtable);
37812 if (rc)
37813 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
37814 }
37815
37816 /* Turn the interrupts on so we can service requests */
37817 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37818 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37819
37820 hpsa_hba_inquiry(h);
37821 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37822 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37823 * To write all data in the battery backed cache to disks
37824 */
37825 hpsa_flush_cache(h);
37826 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37827 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37828 hpsa_free_irqs_and_disable_msix(h);
37829 }
37830
37831 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
37832 return;
37833 }
37834 /* Change the access methods to the performant access methods */
37835 - h->access = SA5_performant_access;
37836 + h->access = &SA5_performant_access;
37837 h->transMethod = CFGTBL_Trans_Performant;
37838 }
37839
37840 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
37841 index 9816479..c5d4e97 100644
37842 --- a/drivers/scsi/hpsa.h
37843 +++ b/drivers/scsi/hpsa.h
37844 @@ -79,7 +79,7 @@ struct ctlr_info {
37845 unsigned int msix_vector;
37846 unsigned int msi_vector;
37847 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
37848 - struct access_method access;
37849 + struct access_method *access;
37850
37851 /* queue and queue Info */
37852 struct list_head reqQ;
37853 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
37854 index c772d8d..35c362c 100644
37855 --- a/drivers/scsi/libfc/fc_exch.c
37856 +++ b/drivers/scsi/libfc/fc_exch.c
37857 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
37858 u16 pool_max_index;
37859
37860 struct {
37861 - atomic_t no_free_exch;
37862 - atomic_t no_free_exch_xid;
37863 - atomic_t xid_not_found;
37864 - atomic_t xid_busy;
37865 - atomic_t seq_not_found;
37866 - atomic_t non_bls_resp;
37867 + atomic_unchecked_t no_free_exch;
37868 + atomic_unchecked_t no_free_exch_xid;
37869 + atomic_unchecked_t xid_not_found;
37870 + atomic_unchecked_t xid_busy;
37871 + atomic_unchecked_t seq_not_found;
37872 + atomic_unchecked_t non_bls_resp;
37873 } stats;
37874 };
37875
37876 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37877 /* allocate memory for exchange */
37878 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37879 if (!ep) {
37880 - atomic_inc(&mp->stats.no_free_exch);
37881 + atomic_inc_unchecked(&mp->stats.no_free_exch);
37882 goto out;
37883 }
37884 memset(ep, 0, sizeof(*ep));
37885 @@ -786,7 +786,7 @@ out:
37886 return ep;
37887 err:
37888 spin_unlock_bh(&pool->lock);
37889 - atomic_inc(&mp->stats.no_free_exch_xid);
37890 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37891 mempool_free(ep, mp->ep_pool);
37892 return NULL;
37893 }
37894 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37895 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37896 ep = fc_exch_find(mp, xid);
37897 if (!ep) {
37898 - atomic_inc(&mp->stats.xid_not_found);
37899 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37900 reject = FC_RJT_OX_ID;
37901 goto out;
37902 }
37903 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37904 ep = fc_exch_find(mp, xid);
37905 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37906 if (ep) {
37907 - atomic_inc(&mp->stats.xid_busy);
37908 + atomic_inc_unchecked(&mp->stats.xid_busy);
37909 reject = FC_RJT_RX_ID;
37910 goto rel;
37911 }
37912 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37913 }
37914 xid = ep->xid; /* get our XID */
37915 } else if (!ep) {
37916 - atomic_inc(&mp->stats.xid_not_found);
37917 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37918 reject = FC_RJT_RX_ID; /* XID not found */
37919 goto out;
37920 }
37921 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37922 } else {
37923 sp = &ep->seq;
37924 if (sp->id != fh->fh_seq_id) {
37925 - atomic_inc(&mp->stats.seq_not_found);
37926 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37927 if (f_ctl & FC_FC_END_SEQ) {
37928 /*
37929 * Update sequence_id based on incoming last
37930 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37931
37932 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37933 if (!ep) {
37934 - atomic_inc(&mp->stats.xid_not_found);
37935 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37936 goto out;
37937 }
37938 if (ep->esb_stat & ESB_ST_COMPLETE) {
37939 - atomic_inc(&mp->stats.xid_not_found);
37940 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37941 goto rel;
37942 }
37943 if (ep->rxid == FC_XID_UNKNOWN)
37944 ep->rxid = ntohs(fh->fh_rx_id);
37945 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37946 - atomic_inc(&mp->stats.xid_not_found);
37947 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37948 goto rel;
37949 }
37950 if (ep->did != ntoh24(fh->fh_s_id) &&
37951 ep->did != FC_FID_FLOGI) {
37952 - atomic_inc(&mp->stats.xid_not_found);
37953 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37954 goto rel;
37955 }
37956 sof = fr_sof(fp);
37957 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37958 sp->ssb_stat |= SSB_ST_RESP;
37959 sp->id = fh->fh_seq_id;
37960 } else if (sp->id != fh->fh_seq_id) {
37961 - atomic_inc(&mp->stats.seq_not_found);
37962 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37963 goto rel;
37964 }
37965
37966 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37967 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37968
37969 if (!sp)
37970 - atomic_inc(&mp->stats.xid_not_found);
37971 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37972 else
37973 - atomic_inc(&mp->stats.non_bls_resp);
37974 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37975
37976 fc_frame_free(fp);
37977 }
37978 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37979
37980 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37981 mp = ema->mp;
37982 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37983 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37984 st->fc_no_free_exch_xid +=
37985 - atomic_read(&mp->stats.no_free_exch_xid);
37986 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37987 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37988 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37989 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37990 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37991 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37992 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37993 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37994 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37995 }
37996 }
37997 EXPORT_SYMBOL(fc_exch_update_stats);
37998 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37999 index bdb81cd..d3c7c2c 100644
38000 --- a/drivers/scsi/libsas/sas_ata.c
38001 +++ b/drivers/scsi/libsas/sas_ata.c
38002 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38003 .postreset = ata_std_postreset,
38004 .error_handler = ata_std_error_handler,
38005 .post_internal_cmd = sas_ata_post_internal,
38006 - .qc_defer = ata_std_qc_defer,
38007 + .qc_defer = ata_std_qc_defer,
38008 .qc_prep = ata_noop_qc_prep,
38009 .qc_issue = sas_ata_qc_issue,
38010 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38011 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38012 index 69b5993..1ac9dce 100644
38013 --- a/drivers/scsi/lpfc/lpfc.h
38014 +++ b/drivers/scsi/lpfc/lpfc.h
38015 @@ -424,7 +424,7 @@ struct lpfc_vport {
38016 struct dentry *debug_nodelist;
38017 struct dentry *vport_debugfs_root;
38018 struct lpfc_debugfs_trc *disc_trc;
38019 - atomic_t disc_trc_cnt;
38020 + atomic_unchecked_t disc_trc_cnt;
38021 #endif
38022 uint8_t stat_data_enabled;
38023 uint8_t stat_data_blocked;
38024 @@ -840,8 +840,8 @@ struct lpfc_hba {
38025 struct timer_list fabric_block_timer;
38026 unsigned long bit_flags;
38027 #define FABRIC_COMANDS_BLOCKED 0
38028 - atomic_t num_rsrc_err;
38029 - atomic_t num_cmd_success;
38030 + atomic_unchecked_t num_rsrc_err;
38031 + atomic_unchecked_t num_cmd_success;
38032 unsigned long last_rsrc_error_time;
38033 unsigned long last_ramp_down_time;
38034 unsigned long last_ramp_up_time;
38035 @@ -877,7 +877,7 @@ struct lpfc_hba {
38036
38037 struct dentry *debug_slow_ring_trc;
38038 struct lpfc_debugfs_trc *slow_ring_trc;
38039 - atomic_t slow_ring_trc_cnt;
38040 + atomic_unchecked_t slow_ring_trc_cnt;
38041 /* iDiag debugfs sub-directory */
38042 struct dentry *idiag_root;
38043 struct dentry *idiag_pci_cfg;
38044 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38045 index f63f5ff..de29189 100644
38046 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
38047 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38048 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38049
38050 #include <linux/debugfs.h>
38051
38052 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38053 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38054 static unsigned long lpfc_debugfs_start_time = 0L;
38055
38056 /* iDiag */
38057 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38058 lpfc_debugfs_enable = 0;
38059
38060 len = 0;
38061 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38062 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38063 (lpfc_debugfs_max_disc_trc - 1);
38064 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38065 dtp = vport->disc_trc + i;
38066 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38067 lpfc_debugfs_enable = 0;
38068
38069 len = 0;
38070 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38071 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38072 (lpfc_debugfs_max_slow_ring_trc - 1);
38073 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38074 dtp = phba->slow_ring_trc + i;
38075 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38076 !vport || !vport->disc_trc)
38077 return;
38078
38079 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38080 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38081 (lpfc_debugfs_max_disc_trc - 1);
38082 dtp = vport->disc_trc + index;
38083 dtp->fmt = fmt;
38084 dtp->data1 = data1;
38085 dtp->data2 = data2;
38086 dtp->data3 = data3;
38087 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38088 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38089 dtp->jif = jiffies;
38090 #endif
38091 return;
38092 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38093 !phba || !phba->slow_ring_trc)
38094 return;
38095
38096 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38097 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38098 (lpfc_debugfs_max_slow_ring_trc - 1);
38099 dtp = phba->slow_ring_trc + index;
38100 dtp->fmt = fmt;
38101 dtp->data1 = data1;
38102 dtp->data2 = data2;
38103 dtp->data3 = data3;
38104 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38105 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38106 dtp->jif = jiffies;
38107 #endif
38108 return;
38109 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38110 "slow_ring buffer\n");
38111 goto debug_failed;
38112 }
38113 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38114 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38115 memset(phba->slow_ring_trc, 0,
38116 (sizeof(struct lpfc_debugfs_trc) *
38117 lpfc_debugfs_max_slow_ring_trc));
38118 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38119 "buffer\n");
38120 goto debug_failed;
38121 }
38122 - atomic_set(&vport->disc_trc_cnt, 0);
38123 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38124
38125 snprintf(name, sizeof(name), "discovery_trace");
38126 vport->debug_disc_trc =
38127 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38128 index 7dc4218..3436f08 100644
38129 --- a/drivers/scsi/lpfc/lpfc_init.c
38130 +++ b/drivers/scsi/lpfc/lpfc_init.c
38131 @@ -10589,8 +10589,10 @@ lpfc_init(void)
38132 "misc_register returned with status %d", error);
38133
38134 if (lpfc_enable_npiv) {
38135 - lpfc_transport_functions.vport_create = lpfc_vport_create;
38136 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38137 + pax_open_kernel();
38138 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38139 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38140 + pax_close_kernel();
38141 }
38142 lpfc_transport_template =
38143 fc_attach_transport(&lpfc_transport_functions);
38144 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38145 index 7f45ac9..cf62eda 100644
38146 --- a/drivers/scsi/lpfc/lpfc_scsi.c
38147 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
38148 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38149 uint32_t evt_posted;
38150
38151 spin_lock_irqsave(&phba->hbalock, flags);
38152 - atomic_inc(&phba->num_rsrc_err);
38153 + atomic_inc_unchecked(&phba->num_rsrc_err);
38154 phba->last_rsrc_error_time = jiffies;
38155
38156 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38157 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38158 unsigned long flags;
38159 struct lpfc_hba *phba = vport->phba;
38160 uint32_t evt_posted;
38161 - atomic_inc(&phba->num_cmd_success);
38162 + atomic_inc_unchecked(&phba->num_cmd_success);
38163
38164 if (vport->cfg_lun_queue_depth <= queue_depth)
38165 return;
38166 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38167 unsigned long num_rsrc_err, num_cmd_success;
38168 int i;
38169
38170 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38171 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38172 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38173 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38174
38175 /*
38176 * The error and success command counters are global per
38177 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38178 }
38179 }
38180 lpfc_destroy_vport_work_array(phba, vports);
38181 - atomic_set(&phba->num_rsrc_err, 0);
38182 - atomic_set(&phba->num_cmd_success, 0);
38183 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38184 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38185 }
38186
38187 /**
38188 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38189 }
38190 }
38191 lpfc_destroy_vport_work_array(phba, vports);
38192 - atomic_set(&phba->num_rsrc_err, 0);
38193 - atomic_set(&phba->num_cmd_success, 0);
38194 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38195 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38196 }
38197
38198 /**
38199 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38200 index af763ea..41904f7 100644
38201 --- a/drivers/scsi/pmcraid.c
38202 +++ b/drivers/scsi/pmcraid.c
38203 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38204 res->scsi_dev = scsi_dev;
38205 scsi_dev->hostdata = res;
38206 res->change_detected = 0;
38207 - atomic_set(&res->read_failures, 0);
38208 - atomic_set(&res->write_failures, 0);
38209 + atomic_set_unchecked(&res->read_failures, 0);
38210 + atomic_set_unchecked(&res->write_failures, 0);
38211 rc = 0;
38212 }
38213 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38214 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38215
38216 /* If this was a SCSI read/write command keep count of errors */
38217 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38218 - atomic_inc(&res->read_failures);
38219 + atomic_inc_unchecked(&res->read_failures);
38220 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38221 - atomic_inc(&res->write_failures);
38222 + atomic_inc_unchecked(&res->write_failures);
38223
38224 if (!RES_IS_GSCSI(res->cfg_entry) &&
38225 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38226 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38227 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38228 * hrrq_id assigned here in queuecommand
38229 */
38230 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38231 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38232 pinstance->num_hrrq;
38233 cmd->cmd_done = pmcraid_io_done;
38234
38235 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38236 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38237 * hrrq_id assigned here in queuecommand
38238 */
38239 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38240 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38241 pinstance->num_hrrq;
38242
38243 if (request_size) {
38244 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38245
38246 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38247 /* add resources only after host is added into system */
38248 - if (!atomic_read(&pinstance->expose_resources))
38249 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38250 return;
38251
38252 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38253 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38254 init_waitqueue_head(&pinstance->reset_wait_q);
38255
38256 atomic_set(&pinstance->outstanding_cmds, 0);
38257 - atomic_set(&pinstance->last_message_id, 0);
38258 - atomic_set(&pinstance->expose_resources, 0);
38259 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38260 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38261
38262 INIT_LIST_HEAD(&pinstance->free_res_q);
38263 INIT_LIST_HEAD(&pinstance->used_res_q);
38264 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38265 /* Schedule worker thread to handle CCN and take care of adding and
38266 * removing devices to OS
38267 */
38268 - atomic_set(&pinstance->expose_resources, 1);
38269 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38270 schedule_work(&pinstance->worker_q);
38271 return rc;
38272
38273 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38274 index e1d150f..6c6df44 100644
38275 --- a/drivers/scsi/pmcraid.h
38276 +++ b/drivers/scsi/pmcraid.h
38277 @@ -748,7 +748,7 @@ struct pmcraid_instance {
38278 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38279
38280 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38281 - atomic_t last_message_id;
38282 + atomic_unchecked_t last_message_id;
38283
38284 /* configuration table */
38285 struct pmcraid_config_table *cfg_table;
38286 @@ -777,7 +777,7 @@ struct pmcraid_instance {
38287 atomic_t outstanding_cmds;
38288
38289 /* should add/delete resources to mid-layer now ?*/
38290 - atomic_t expose_resources;
38291 + atomic_unchecked_t expose_resources;
38292
38293
38294
38295 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38296 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38297 };
38298 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38299 - atomic_t read_failures; /* count of failed READ commands */
38300 - atomic_t write_failures; /* count of failed WRITE commands */
38301 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38302 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38303
38304 /* To indicate add/delete/modify during CCN */
38305 u8 change_detected;
38306 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38307 index 83d7984..a27d947 100644
38308 --- a/drivers/scsi/qla2xxx/qla_attr.c
38309 +++ b/drivers/scsi/qla2xxx/qla_attr.c
38310 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38311 return 0;
38312 }
38313
38314 -struct fc_function_template qla2xxx_transport_functions = {
38315 +fc_function_template_no_const qla2xxx_transport_functions = {
38316
38317 .show_host_node_name = 1,
38318 .show_host_port_name = 1,
38319 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38320 .bsg_timeout = qla24xx_bsg_timeout,
38321 };
38322
38323 -struct fc_function_template qla2xxx_transport_vport_functions = {
38324 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
38325
38326 .show_host_node_name = 1,
38327 .show_host_port_name = 1,
38328 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38329 index 6acb397..d86e3e0 100644
38330 --- a/drivers/scsi/qla2xxx/qla_gbl.h
38331 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
38332 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38333 struct device_attribute;
38334 extern struct device_attribute *qla2x00_host_attrs[];
38335 struct fc_function_template;
38336 -extern struct fc_function_template qla2xxx_transport_functions;
38337 -extern struct fc_function_template qla2xxx_transport_vport_functions;
38338 +extern fc_function_template_no_const qla2xxx_transport_functions;
38339 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38340 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38341 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38342 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38343 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38344 index f4b1fc8..a1ce4dd 100644
38345 --- a/drivers/scsi/qla2xxx/qla_os.c
38346 +++ b/drivers/scsi/qla2xxx/qla_os.c
38347 @@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38348 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38349 /* Ok, a 64bit DMA mask is applicable. */
38350 ha->flags.enable_64bit_addressing = 1;
38351 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38352 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38353 + pax_open_kernel();
38354 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38355 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38356 + pax_close_kernel();
38357 return;
38358 }
38359 }
38360 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38361 index 329d553..f20d31d 100644
38362 --- a/drivers/scsi/qla4xxx/ql4_def.h
38363 +++ b/drivers/scsi/qla4xxx/ql4_def.h
38364 @@ -273,7 +273,7 @@ struct ddb_entry {
38365 * (4000 only) */
38366 atomic_t relogin_timer; /* Max Time to wait for
38367 * relogin to complete */
38368 - atomic_t relogin_retry_count; /* Num of times relogin has been
38369 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38370 * retried */
38371 uint32_t default_time2wait; /* Default Min time between
38372 * relogins (+aens) */
38373 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38374 index fbc546e..c7d1b48 100644
38375 --- a/drivers/scsi/qla4xxx/ql4_os.c
38376 +++ b/drivers/scsi/qla4xxx/ql4_os.c
38377 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38378 */
38379 if (!iscsi_is_session_online(cls_sess)) {
38380 /* Reset retry relogin timer */
38381 - atomic_inc(&ddb_entry->relogin_retry_count);
38382 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38383 DEBUG2(ql4_printk(KERN_INFO, ha,
38384 "%s: index[%d] relogin timed out-retrying"
38385 " relogin (%d), retry (%d)\n", __func__,
38386 ddb_entry->fw_ddb_index,
38387 - atomic_read(&ddb_entry->relogin_retry_count),
38388 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38389 ddb_entry->default_time2wait + 4));
38390 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38391 atomic_set(&ddb_entry->retry_relogin_timer,
38392 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38393
38394 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38395 atomic_set(&ddb_entry->relogin_timer, 0);
38396 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38397 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38398 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38399 ddb_entry->default_relogin_timeout =
38400 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38401 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38402 index 2c0d0ec..4e8681a 100644
38403 --- a/drivers/scsi/scsi.c
38404 +++ b/drivers/scsi/scsi.c
38405 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38406 unsigned long timeout;
38407 int rtn = 0;
38408
38409 - atomic_inc(&cmd->device->iorequest_cnt);
38410 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38411
38412 /* check if the device is still usable */
38413 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38414 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38415 index 9032e91..7a805d0 100644
38416 --- a/drivers/scsi/scsi_lib.c
38417 +++ b/drivers/scsi/scsi_lib.c
38418 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38419 shost = sdev->host;
38420 scsi_init_cmd_errh(cmd);
38421 cmd->result = DID_NO_CONNECT << 16;
38422 - atomic_inc(&cmd->device->iorequest_cnt);
38423 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38424
38425 /*
38426 * SCSI request completion path will do scsi_device_unbusy(),
38427 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
38428
38429 INIT_LIST_HEAD(&cmd->eh_entry);
38430
38431 - atomic_inc(&cmd->device->iodone_cnt);
38432 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
38433 if (cmd->result)
38434 - atomic_inc(&cmd->device->ioerr_cnt);
38435 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38436
38437 disposition = scsi_decide_disposition(cmd);
38438 if (disposition != SUCCESS &&
38439 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38440 index 931a7d9..0c2a754 100644
38441 --- a/drivers/scsi/scsi_sysfs.c
38442 +++ b/drivers/scsi/scsi_sysfs.c
38443 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38444 char *buf) \
38445 { \
38446 struct scsi_device *sdev = to_scsi_device(dev); \
38447 - unsigned long long count = atomic_read(&sdev->field); \
38448 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
38449 return snprintf(buf, 20, "0x%llx\n", count); \
38450 } \
38451 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38452 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
38453 index 84a1fdf..693b0d6 100644
38454 --- a/drivers/scsi/scsi_tgt_lib.c
38455 +++ b/drivers/scsi/scsi_tgt_lib.c
38456 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
38457 int err;
38458
38459 dprintk("%lx %u\n", uaddr, len);
38460 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
38461 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
38462 if (err) {
38463 /*
38464 * TODO: need to fixup sg_tablesize, max_segment_size,
38465 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
38466 index e894ca7..de9d7660 100644
38467 --- a/drivers/scsi/scsi_transport_fc.c
38468 +++ b/drivers/scsi/scsi_transport_fc.c
38469 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
38470 * Netlink Infrastructure
38471 */
38472
38473 -static atomic_t fc_event_seq;
38474 +static atomic_unchecked_t fc_event_seq;
38475
38476 /**
38477 * fc_get_event_number - Obtain the next sequential FC event number
38478 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
38479 u32
38480 fc_get_event_number(void)
38481 {
38482 - return atomic_add_return(1, &fc_event_seq);
38483 + return atomic_add_return_unchecked(1, &fc_event_seq);
38484 }
38485 EXPORT_SYMBOL(fc_get_event_number);
38486
38487 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
38488 {
38489 int error;
38490
38491 - atomic_set(&fc_event_seq, 0);
38492 + atomic_set_unchecked(&fc_event_seq, 0);
38493
38494 error = transport_class_register(&fc_host_class);
38495 if (error)
38496 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
38497 char *cp;
38498
38499 *val = simple_strtoul(buf, &cp, 0);
38500 - if ((*cp && (*cp != '\n')) || (*val < 0))
38501 + if (*cp && (*cp != '\n'))
38502 return -EINVAL;
38503 /*
38504 * Check for overflow; dev_loss_tmo is u32
38505 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
38506 index 31969f2..2b348f0 100644
38507 --- a/drivers/scsi/scsi_transport_iscsi.c
38508 +++ b/drivers/scsi/scsi_transport_iscsi.c
38509 @@ -79,7 +79,7 @@ struct iscsi_internal {
38510 struct transport_container session_cont;
38511 };
38512
38513 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
38514 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
38515 static struct workqueue_struct *iscsi_eh_timer_workq;
38516
38517 static DEFINE_IDA(iscsi_sess_ida);
38518 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
38519 int err;
38520
38521 ihost = shost->shost_data;
38522 - session->sid = atomic_add_return(1, &iscsi_session_nr);
38523 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
38524
38525 if (target_id == ISCSI_MAX_TARGET) {
38526 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
38527 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
38528 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
38529 ISCSI_TRANSPORT_VERSION);
38530
38531 - atomic_set(&iscsi_session_nr, 0);
38532 + atomic_set_unchecked(&iscsi_session_nr, 0);
38533
38534 err = class_register(&iscsi_transport_class);
38535 if (err)
38536 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
38537 index 21a045e..ec89e03 100644
38538 --- a/drivers/scsi/scsi_transport_srp.c
38539 +++ b/drivers/scsi/scsi_transport_srp.c
38540 @@ -33,7 +33,7 @@
38541 #include "scsi_transport_srp_internal.h"
38542
38543 struct srp_host_attrs {
38544 - atomic_t next_port_id;
38545 + atomic_unchecked_t next_port_id;
38546 };
38547 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
38548
38549 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
38550 struct Scsi_Host *shost = dev_to_shost(dev);
38551 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
38552
38553 - atomic_set(&srp_host->next_port_id, 0);
38554 + atomic_set_unchecked(&srp_host->next_port_id, 0);
38555 return 0;
38556 }
38557
38558 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
38559 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
38560 rport->roles = ids->roles;
38561
38562 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
38563 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
38564 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
38565
38566 transport_setup_device(&rport->dev);
38567 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
38568 index 352bc77..c049b14 100644
38569 --- a/drivers/scsi/sd.c
38570 +++ b/drivers/scsi/sd.c
38571 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
38572 sdkp->disk = gd;
38573 sdkp->index = index;
38574 atomic_set(&sdkp->openers, 0);
38575 - atomic_set(&sdkp->device->ioerr_cnt, 0);
38576 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
38577
38578 if (!sdp->request_queue->rq_timeout) {
38579 if (sdp->type != TYPE_MOD)
38580 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
38581 index be2c9a6..275525c 100644
38582 --- a/drivers/scsi/sg.c
38583 +++ b/drivers/scsi/sg.c
38584 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
38585 sdp->disk->disk_name,
38586 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
38587 NULL,
38588 - (char *)arg);
38589 + (char __user *)arg);
38590 case BLKTRACESTART:
38591 return blk_trace_startstop(sdp->device->request_queue, 1);
38592 case BLKTRACESTOP:
38593 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
38594 index 84c2861..ece0a31 100644
38595 --- a/drivers/spi/spi.c
38596 +++ b/drivers/spi/spi.c
38597 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
38598 EXPORT_SYMBOL_GPL(spi_bus_unlock);
38599
38600 /* portable code must never pass more than 32 bytes */
38601 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
38602 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
38603
38604 static u8 *buf;
38605
38606 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
38607 index 34afc16..ffe44dd 100644
38608 --- a/drivers/staging/octeon/ethernet-rx.c
38609 +++ b/drivers/staging/octeon/ethernet-rx.c
38610 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38611 /* Increment RX stats for virtual ports */
38612 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
38613 #ifdef CONFIG_64BIT
38614 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
38615 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
38616 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
38617 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
38618 #else
38619 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
38620 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
38621 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
38622 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
38623 #endif
38624 }
38625 netif_receive_skb(skb);
38626 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38627 dev->name);
38628 */
38629 #ifdef CONFIG_64BIT
38630 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
38631 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38632 #else
38633 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
38634 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
38635 #endif
38636 dev_kfree_skb_irq(skb);
38637 }
38638 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
38639 index 683bedc..86dba9a 100644
38640 --- a/drivers/staging/octeon/ethernet.c
38641 +++ b/drivers/staging/octeon/ethernet.c
38642 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
38643 * since the RX tasklet also increments it.
38644 */
38645 #ifdef CONFIG_64BIT
38646 - atomic64_add(rx_status.dropped_packets,
38647 - (atomic64_t *)&priv->stats.rx_dropped);
38648 + atomic64_add_unchecked(rx_status.dropped_packets,
38649 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38650 #else
38651 - atomic_add(rx_status.dropped_packets,
38652 - (atomic_t *)&priv->stats.rx_dropped);
38653 + atomic_add_unchecked(rx_status.dropped_packets,
38654 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
38655 #endif
38656 }
38657
38658 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
38659 index a2b7e03..aaf3630 100644
38660 --- a/drivers/staging/ramster/tmem.c
38661 +++ b/drivers/staging/ramster/tmem.c
38662 @@ -50,25 +50,25 @@
38663 * A tmem host implementation must use this function to register callbacks
38664 * for memory allocation.
38665 */
38666 -static struct tmem_hostops tmem_hostops;
38667 +static struct tmem_hostops *tmem_hostops;
38668
38669 static void tmem_objnode_tree_init(void);
38670
38671 void tmem_register_hostops(struct tmem_hostops *m)
38672 {
38673 tmem_objnode_tree_init();
38674 - tmem_hostops = *m;
38675 + tmem_hostops = m;
38676 }
38677
38678 /*
38679 * A tmem host implementation must use this function to register
38680 * callbacks for a page-accessible memory (PAM) implementation.
38681 */
38682 -static struct tmem_pamops tmem_pamops;
38683 +static struct tmem_pamops *tmem_pamops;
38684
38685 void tmem_register_pamops(struct tmem_pamops *m)
38686 {
38687 - tmem_pamops = *m;
38688 + tmem_pamops = m;
38689 }
38690
38691 /*
38692 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
38693 obj->pampd_count = 0;
38694 #ifdef CONFIG_RAMSTER
38695 if (tmem_pamops.new_obj != NULL)
38696 - (*tmem_pamops.new_obj)(obj);
38697 + (tmem_pamops->new_obj)(obj);
38698 #endif
38699 SET_SENTINEL(obj, OBJ);
38700
38701 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
38702 rbnode = rb_next(rbnode);
38703 tmem_pampd_destroy_all_in_obj(obj, true);
38704 tmem_obj_free(obj, hb);
38705 - (*tmem_hostops.obj_free)(obj, pool);
38706 + (tmem_hostops->obj_free)(obj, pool);
38707 }
38708 spin_unlock(&hb->lock);
38709 }
38710 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
38711 ASSERT_SENTINEL(obj, OBJ);
38712 BUG_ON(obj->pool == NULL);
38713 ASSERT_SENTINEL(obj->pool, POOL);
38714 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
38715 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
38716 if (unlikely(objnode == NULL))
38717 goto out;
38718 objnode->obj = obj;
38719 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
38720 ASSERT_SENTINEL(pool, POOL);
38721 objnode->obj->objnode_count--;
38722 objnode->obj = NULL;
38723 - (*tmem_hostops.objnode_free)(objnode, pool);
38724 + (tmem_hostops->objnode_free)(objnode, pool);
38725 }
38726
38727 /*
38728 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
38729 void *old_pampd = *(void **)slot;
38730 *(void **)slot = new_pampd;
38731 if (!no_free)
38732 - (*tmem_pamops.free)(old_pampd, obj->pool,
38733 + (tmem_pamops->free)(old_pampd, obj->pool,
38734 NULL, 0, false);
38735 ret = new_pampd;
38736 }
38737 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
38738 if (objnode->slots[i]) {
38739 if (ht == 1) {
38740 obj->pampd_count--;
38741 - (*tmem_pamops.free)(objnode->slots[i],
38742 + (tmem_pamops->free)(objnode->slots[i],
38743 obj->pool, NULL, 0, true);
38744 objnode->slots[i] = NULL;
38745 continue;
38746 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
38747 return;
38748 if (obj->objnode_tree_height == 0) {
38749 obj->pampd_count--;
38750 - (*tmem_pamops.free)(obj->objnode_tree_root,
38751 + (tmem_pamops->free)(obj->objnode_tree_root,
38752 obj->pool, NULL, 0, true);
38753 } else {
38754 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
38755 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
38756 obj->objnode_tree_root = NULL;
38757 #ifdef CONFIG_RAMSTER
38758 if (tmem_pamops.free_obj != NULL)
38759 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
38760 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
38761 #endif
38762 }
38763
38764 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38765 /* if found, is a dup put, flush the old one */
38766 pampd_del = tmem_pampd_delete_from_obj(obj, index);
38767 BUG_ON(pampd_del != pampd);
38768 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
38769 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
38770 if (obj->pampd_count == 0) {
38771 objnew = obj;
38772 objfound = NULL;
38773 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38774 pampd = NULL;
38775 }
38776 } else {
38777 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
38778 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
38779 if (unlikely(obj == NULL)) {
38780 ret = -ENOMEM;
38781 goto out;
38782 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38783 if (unlikely(ret == -ENOMEM))
38784 /* may have partially built objnode tree ("stump") */
38785 goto delete_and_free;
38786 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
38787 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
38788 goto out;
38789
38790 delete_and_free:
38791 (void)tmem_pampd_delete_from_obj(obj, index);
38792 if (pampd)
38793 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
38794 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
38795 if (objnew) {
38796 tmem_obj_free(objnew, hb);
38797 - (*tmem_hostops.obj_free)(objnew, pool);
38798 + (tmem_hostops->obj_free)(objnew, pool);
38799 }
38800 out:
38801 spin_unlock(&hb->lock);
38802 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
38803 if (pampd != NULL) {
38804 BUG_ON(obj == NULL);
38805 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
38806 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
38807 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
38808 } else if (delete) {
38809 BUG_ON(obj == NULL);
38810 (void)tmem_pampd_delete_from_obj(obj, index);
38811 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
38812 int ret = 0;
38813
38814 if (!is_ephemeral(pool))
38815 - new_pampd = (*tmem_pamops.repatriate_preload)(
38816 + new_pampd = (tmem_pamops->repatriate_preload)(
38817 old_pampd, pool, oidp, index, &intransit);
38818 if (intransit)
38819 ret = -EAGAIN;
38820 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
38821 /* must release the hb->lock else repatriate can't sleep */
38822 spin_unlock(&hb->lock);
38823 if (!intransit)
38824 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
38825 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
38826 oidp, index, free, data);
38827 if (ret == -EAGAIN) {
38828 /* rare I think, but should cond_resched()??? */
38829 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
38830 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
38831 /* if we bug here, pamops wasn't properly set up for ramster */
38832 BUG_ON(tmem_pamops.replace_in_obj == NULL);
38833 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
38834 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
38835 out:
38836 spin_unlock(&hb->lock);
38837 return ret;
38838 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38839 if (free) {
38840 if (obj->pampd_count == 0) {
38841 tmem_obj_free(obj, hb);
38842 - (*tmem_hostops.obj_free)(obj, pool);
38843 + (tmem_hostops->obj_free)(obj, pool);
38844 obj = NULL;
38845 }
38846 }
38847 if (free)
38848 - ret = (*tmem_pamops.get_data_and_free)(
38849 + ret = (tmem_pamops->get_data_and_free)(
38850 data, sizep, raw, pampd, pool, oidp, index);
38851 else
38852 - ret = (*tmem_pamops.get_data)(
38853 + ret = (tmem_pamops->get_data)(
38854 data, sizep, raw, pampd, pool, oidp, index);
38855 if (ret < 0)
38856 goto out;
38857 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
38858 pampd = tmem_pampd_delete_from_obj(obj, index);
38859 if (pampd == NULL)
38860 goto out;
38861 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
38862 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
38863 if (obj->pampd_count == 0) {
38864 tmem_obj_free(obj, hb);
38865 - (*tmem_hostops.obj_free)(obj, pool);
38866 + (tmem_hostops->obj_free)(obj, pool);
38867 }
38868 ret = 0;
38869
38870 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
38871 goto out;
38872 tmem_pampd_destroy_all_in_obj(obj, false);
38873 tmem_obj_free(obj, hb);
38874 - (*tmem_hostops.obj_free)(obj, pool);
38875 + (tmem_hostops->obj_free)(obj, pool);
38876 ret = 0;
38877
38878 out:
38879 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
38880 index dc23395..cf7e9b1 100644
38881 --- a/drivers/staging/rtl8712/rtl871x_io.h
38882 +++ b/drivers/staging/rtl8712/rtl871x_io.h
38883 @@ -108,7 +108,7 @@ struct _io_ops {
38884 u8 *pmem);
38885 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
38886 u8 *pmem);
38887 -};
38888 +} __no_const;
38889
38890 struct io_req {
38891 struct list_head list;
38892 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
38893 index 180c963..1f18377 100644
38894 --- a/drivers/staging/sbe-2t3e3/netdev.c
38895 +++ b/drivers/staging/sbe-2t3e3/netdev.c
38896 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38897 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
38898
38899 if (rlen)
38900 - if (copy_to_user(data, &resp, rlen))
38901 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
38902 return -EFAULT;
38903
38904 return 0;
38905 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
38906 index c66b8b3..a4a035b 100644
38907 --- a/drivers/staging/usbip/vhci.h
38908 +++ b/drivers/staging/usbip/vhci.h
38909 @@ -83,7 +83,7 @@ struct vhci_hcd {
38910 unsigned resuming:1;
38911 unsigned long re_timeout;
38912
38913 - atomic_t seqnum;
38914 + atomic_unchecked_t seqnum;
38915
38916 /*
38917 * NOTE:
38918 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
38919 index 620d1be..1cd6711 100644
38920 --- a/drivers/staging/usbip/vhci_hcd.c
38921 +++ b/drivers/staging/usbip/vhci_hcd.c
38922 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
38923 return;
38924 }
38925
38926 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
38927 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38928 if (priv->seqnum == 0xffff)
38929 dev_info(&urb->dev->dev, "seqnum max\n");
38930
38931 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
38932 return -ENOMEM;
38933 }
38934
38935 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
38936 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38937 if (unlink->seqnum == 0xffff)
38938 pr_info("seqnum max\n");
38939
38940 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
38941 vdev->rhport = rhport;
38942 }
38943
38944 - atomic_set(&vhci->seqnum, 0);
38945 + atomic_set_unchecked(&vhci->seqnum, 0);
38946 spin_lock_init(&vhci->lock);
38947
38948 hcd->power_budget = 0; /* no limit */
38949 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
38950 index f0eaf04..5a82e06 100644
38951 --- a/drivers/staging/usbip/vhci_rx.c
38952 +++ b/drivers/staging/usbip/vhci_rx.c
38953 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
38954 if (!urb) {
38955 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
38956 pr_info("max seqnum %d\n",
38957 - atomic_read(&the_controller->seqnum));
38958 + atomic_read_unchecked(&the_controller->seqnum));
38959 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38960 return;
38961 }
38962 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
38963 index 67b1b88..6392fe9 100644
38964 --- a/drivers/staging/vt6655/hostap.c
38965 +++ b/drivers/staging/vt6655/hostap.c
38966 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
38967 *
38968 */
38969
38970 +static net_device_ops_no_const apdev_netdev_ops;
38971 +
38972 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38973 {
38974 PSDevice apdev_priv;
38975 struct net_device *dev = pDevice->dev;
38976 int ret;
38977 - const struct net_device_ops apdev_netdev_ops = {
38978 - .ndo_start_xmit = pDevice->tx_80211,
38979 - };
38980
38981 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38982
38983 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38984 *apdev_priv = *pDevice;
38985 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38986
38987 + /* only half broken now */
38988 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38989 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38990
38991 pDevice->apdev->type = ARPHRD_IEEE80211;
38992 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
38993 index 0a73d40..6fda560 100644
38994 --- a/drivers/staging/vt6656/hostap.c
38995 +++ b/drivers/staging/vt6656/hostap.c
38996 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
38997 *
38998 */
38999
39000 +static net_device_ops_no_const apdev_netdev_ops;
39001 +
39002 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39003 {
39004 PSDevice apdev_priv;
39005 struct net_device *dev = pDevice->dev;
39006 int ret;
39007 - const struct net_device_ops apdev_netdev_ops = {
39008 - .ndo_start_xmit = pDevice->tx_80211,
39009 - };
39010
39011 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39012
39013 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39014 *apdev_priv = *pDevice;
39015 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39016
39017 + /* only half broken now */
39018 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39019 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39020
39021 pDevice->apdev->type = ARPHRD_IEEE80211;
39022 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39023 index 56c8e60..1920c63 100644
39024 --- a/drivers/staging/zcache/tmem.c
39025 +++ b/drivers/staging/zcache/tmem.c
39026 @@ -39,7 +39,7 @@
39027 * A tmem host implementation must use this function to register callbacks
39028 * for memory allocation.
39029 */
39030 -static struct tmem_hostops tmem_hostops;
39031 +static tmem_hostops_no_const tmem_hostops;
39032
39033 static void tmem_objnode_tree_init(void);
39034
39035 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39036 * A tmem host implementation must use this function to register
39037 * callbacks for a page-accessible memory (PAM) implementation
39038 */
39039 -static struct tmem_pamops tmem_pamops;
39040 +static tmem_pamops_no_const tmem_pamops;
39041
39042 void tmem_register_pamops(struct tmem_pamops *m)
39043 {
39044 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39045 index 0d4aa82..f7832d4 100644
39046 --- a/drivers/staging/zcache/tmem.h
39047 +++ b/drivers/staging/zcache/tmem.h
39048 @@ -180,6 +180,7 @@ struct tmem_pamops {
39049 void (*new_obj)(struct tmem_obj *);
39050 int (*replace_in_obj)(void *, struct tmem_obj *);
39051 };
39052 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39053 extern void tmem_register_pamops(struct tmem_pamops *m);
39054
39055 /* memory allocation methods provided by the host implementation */
39056 @@ -189,6 +190,7 @@ struct tmem_hostops {
39057 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39058 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39059 };
39060 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39061 extern void tmem_register_hostops(struct tmem_hostops *m);
39062
39063 /* core tmem accessor functions */
39064 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39065 index dcecbfb..4fad7d5 100644
39066 --- a/drivers/target/target_core_transport.c
39067 +++ b/drivers/target/target_core_transport.c
39068 @@ -1087,7 +1087,7 @@ struct se_device *transport_add_device_to_core_hba(
39069 spin_lock_init(&dev->se_port_lock);
39070 spin_lock_init(&dev->se_tmr_lock);
39071 spin_lock_init(&dev->qf_cmd_lock);
39072 - atomic_set(&dev->dev_ordered_id, 0);
39073 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
39074
39075 se_dev_set_default_attribs(dev, dev_limits);
39076
39077 @@ -1277,7 +1277,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39078 * Used to determine when ORDERED commands should go from
39079 * Dormant to Active status.
39080 */
39081 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39082 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39083 smp_mb__after_atomic_inc();
39084 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39085 cmd->se_ordered_id, cmd->sam_task_attr,
39086 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39087 index 0a6a0bc..5501b06 100644
39088 --- a/drivers/tty/cyclades.c
39089 +++ b/drivers/tty/cyclades.c
39090 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39091 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39092 info->port.count);
39093 #endif
39094 - info->port.count++;
39095 + atomic_inc(&info->port.count);
39096 #ifdef CY_DEBUG_COUNT
39097 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39098 - current->pid, info->port.count);
39099 + current->pid, atomic_read(&info->port.count));
39100 #endif
39101
39102 /*
39103 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39104 for (j = 0; j < cy_card[i].nports; j++) {
39105 info = &cy_card[i].ports[j];
39106
39107 - if (info->port.count) {
39108 + if (atomic_read(&info->port.count)) {
39109 /* XXX is the ldisc num worth this? */
39110 struct tty_struct *tty;
39111 struct tty_ldisc *ld;
39112 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39113 index 13ee53b..418d164 100644
39114 --- a/drivers/tty/hvc/hvc_console.c
39115 +++ b/drivers/tty/hvc/hvc_console.c
39116 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39117
39118 spin_lock_irqsave(&hp->port.lock, flags);
39119 /* Check and then increment for fast path open. */
39120 - if (hp->port.count++ > 0) {
39121 + if (atomic_inc_return(&hp->port.count) > 1) {
39122 spin_unlock_irqrestore(&hp->port.lock, flags);
39123 hvc_kick();
39124 return 0;
39125 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39126
39127 spin_lock_irqsave(&hp->port.lock, flags);
39128
39129 - if (--hp->port.count == 0) {
39130 + if (atomic_dec_return(&hp->port.count) == 0) {
39131 spin_unlock_irqrestore(&hp->port.lock, flags);
39132 /* We are done with the tty pointer now. */
39133 tty_port_tty_set(&hp->port, NULL);
39134 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39135 */
39136 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39137 } else {
39138 - if (hp->port.count < 0)
39139 + if (atomic_read(&hp->port.count) < 0)
39140 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39141 - hp->vtermno, hp->port.count);
39142 + hp->vtermno, atomic_read(&hp->port.count));
39143 spin_unlock_irqrestore(&hp->port.lock, flags);
39144 }
39145 }
39146 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39147 * open->hangup case this can be called after the final close so prevent
39148 * that from happening for now.
39149 */
39150 - if (hp->port.count <= 0) {
39151 + if (atomic_read(&hp->port.count) <= 0) {
39152 spin_unlock_irqrestore(&hp->port.lock, flags);
39153 return;
39154 }
39155
39156 - hp->port.count = 0;
39157 + atomic_set(&hp->port.count, 0);
39158 spin_unlock_irqrestore(&hp->port.lock, flags);
39159 tty_port_tty_set(&hp->port, NULL);
39160
39161 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39162 return -EPIPE;
39163
39164 /* FIXME what's this (unprotected) check for? */
39165 - if (hp->port.count <= 0)
39166 + if (atomic_read(&hp->port.count) <= 0)
39167 return -EIO;
39168
39169 spin_lock_irqsave(&hp->lock, flags);
39170 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39171 index cab5c7a..4cc66ea 100644
39172 --- a/drivers/tty/hvc/hvcs.c
39173 +++ b/drivers/tty/hvc/hvcs.c
39174 @@ -83,6 +83,7 @@
39175 #include <asm/hvcserver.h>
39176 #include <asm/uaccess.h>
39177 #include <asm/vio.h>
39178 +#include <asm/local.h>
39179
39180 /*
39181 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39182 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39183
39184 spin_lock_irqsave(&hvcsd->lock, flags);
39185
39186 - if (hvcsd->port.count > 0) {
39187 + if (atomic_read(&hvcsd->port.count) > 0) {
39188 spin_unlock_irqrestore(&hvcsd->lock, flags);
39189 printk(KERN_INFO "HVCS: vterm state unchanged. "
39190 "The hvcs device node is still in use.\n");
39191 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39192 }
39193 }
39194
39195 - hvcsd->port.count = 0;
39196 + atomic_set(&hvcsd->port.count, 0);
39197 hvcsd->port.tty = tty;
39198 tty->driver_data = hvcsd;
39199
39200 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39201 unsigned long flags;
39202
39203 spin_lock_irqsave(&hvcsd->lock, flags);
39204 - hvcsd->port.count++;
39205 + atomic_inc(&hvcsd->port.count);
39206 hvcsd->todo_mask |= HVCS_SCHED_READ;
39207 spin_unlock_irqrestore(&hvcsd->lock, flags);
39208
39209 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39210 hvcsd = tty->driver_data;
39211
39212 spin_lock_irqsave(&hvcsd->lock, flags);
39213 - if (--hvcsd->port.count == 0) {
39214 + if (atomic_dec_and_test(&hvcsd->port.count)) {
39215
39216 vio_disable_interrupts(hvcsd->vdev);
39217
39218 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39219
39220 free_irq(irq, hvcsd);
39221 return;
39222 - } else if (hvcsd->port.count < 0) {
39223 + } else if (atomic_read(&hvcsd->port.count) < 0) {
39224 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39225 " is missmanaged.\n",
39226 - hvcsd->vdev->unit_address, hvcsd->port.count);
39227 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39228 }
39229
39230 spin_unlock_irqrestore(&hvcsd->lock, flags);
39231 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39232
39233 spin_lock_irqsave(&hvcsd->lock, flags);
39234 /* Preserve this so that we know how many kref refs to put */
39235 - temp_open_count = hvcsd->port.count;
39236 + temp_open_count = atomic_read(&hvcsd->port.count);
39237
39238 /*
39239 * Don't kref put inside the spinlock because the destruction
39240 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39241 tty->driver_data = NULL;
39242 hvcsd->port.tty = NULL;
39243
39244 - hvcsd->port.count = 0;
39245 + atomic_set(&hvcsd->port.count, 0);
39246
39247 /* This will drop any buffered data on the floor which is OK in a hangup
39248 * scenario. */
39249 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39250 * the middle of a write operation? This is a crummy place to do this
39251 * but we want to keep it all in the spinlock.
39252 */
39253 - if (hvcsd->port.count <= 0) {
39254 + if (atomic_read(&hvcsd->port.count) <= 0) {
39255 spin_unlock_irqrestore(&hvcsd->lock, flags);
39256 return -ENODEV;
39257 }
39258 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39259 {
39260 struct hvcs_struct *hvcsd = tty->driver_data;
39261
39262 - if (!hvcsd || hvcsd->port.count <= 0)
39263 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39264 return 0;
39265
39266 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39267 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39268 index 160f0ad..588b853 100644
39269 --- a/drivers/tty/ipwireless/tty.c
39270 +++ b/drivers/tty/ipwireless/tty.c
39271 @@ -29,6 +29,7 @@
39272 #include <linux/tty_driver.h>
39273 #include <linux/tty_flip.h>
39274 #include <linux/uaccess.h>
39275 +#include <asm/local.h>
39276
39277 #include "tty.h"
39278 #include "network.h"
39279 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39280 mutex_unlock(&tty->ipw_tty_mutex);
39281 return -ENODEV;
39282 }
39283 - if (tty->port.count == 0)
39284 + if (atomic_read(&tty->port.count) == 0)
39285 tty->tx_bytes_queued = 0;
39286
39287 - tty->port.count++;
39288 + atomic_inc(&tty->port.count);
39289
39290 tty->port.tty = linux_tty;
39291 linux_tty->driver_data = tty;
39292 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39293
39294 static void do_ipw_close(struct ipw_tty *tty)
39295 {
39296 - tty->port.count--;
39297 -
39298 - if (tty->port.count == 0) {
39299 + if (atomic_dec_return(&tty->port.count) == 0) {
39300 struct tty_struct *linux_tty = tty->port.tty;
39301
39302 if (linux_tty != NULL) {
39303 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39304 return;
39305
39306 mutex_lock(&tty->ipw_tty_mutex);
39307 - if (tty->port.count == 0) {
39308 + if (atomic_read(&tty->port.count) == 0) {
39309 mutex_unlock(&tty->ipw_tty_mutex);
39310 return;
39311 }
39312 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39313 return;
39314 }
39315
39316 - if (!tty->port.count) {
39317 + if (!atomic_read(&tty->port.count)) {
39318 mutex_unlock(&tty->ipw_tty_mutex);
39319 return;
39320 }
39321 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39322 return -ENODEV;
39323
39324 mutex_lock(&tty->ipw_tty_mutex);
39325 - if (!tty->port.count) {
39326 + if (!atomic_read(&tty->port.count)) {
39327 mutex_unlock(&tty->ipw_tty_mutex);
39328 return -EINVAL;
39329 }
39330 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39331 if (!tty)
39332 return -ENODEV;
39333
39334 - if (!tty->port.count)
39335 + if (!atomic_read(&tty->port.count))
39336 return -EINVAL;
39337
39338 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39339 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39340 if (!tty)
39341 return 0;
39342
39343 - if (!tty->port.count)
39344 + if (!atomic_read(&tty->port.count))
39345 return 0;
39346
39347 return tty->tx_bytes_queued;
39348 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39349 if (!tty)
39350 return -ENODEV;
39351
39352 - if (!tty->port.count)
39353 + if (!atomic_read(&tty->port.count))
39354 return -EINVAL;
39355
39356 return get_control_lines(tty);
39357 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39358 if (!tty)
39359 return -ENODEV;
39360
39361 - if (!tty->port.count)
39362 + if (!atomic_read(&tty->port.count))
39363 return -EINVAL;
39364
39365 return set_control_lines(tty, set, clear);
39366 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39367 if (!tty)
39368 return -ENODEV;
39369
39370 - if (!tty->port.count)
39371 + if (!atomic_read(&tty->port.count))
39372 return -EINVAL;
39373
39374 /* FIXME: Exactly how is the tty object locked here .. */
39375 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39376 * are gone */
39377 mutex_lock(&ttyj->ipw_tty_mutex);
39378 }
39379 - while (ttyj->port.count)
39380 + while (atomic_read(&ttyj->port.count))
39381 do_ipw_close(ttyj);
39382 ipwireless_disassociate_network_ttys(network,
39383 ttyj->channel_idx);
39384 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39385 index 56e616b..9d9f10a 100644
39386 --- a/drivers/tty/moxa.c
39387 +++ b/drivers/tty/moxa.c
39388 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39389 }
39390
39391 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
39392 - ch->port.count++;
39393 + atomic_inc(&ch->port.count);
39394 tty->driver_data = ch;
39395 tty_port_tty_set(&ch->port, tty);
39396 mutex_lock(&ch->port.mutex);
39397 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
39398 index 1e8e8ce..a9efc93 100644
39399 --- a/drivers/tty/n_gsm.c
39400 +++ b/drivers/tty/n_gsm.c
39401 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
39402 kref_init(&dlci->ref);
39403 mutex_init(&dlci->mutex);
39404 dlci->fifo = &dlci->_fifo;
39405 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
39406 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
39407 kfree(dlci);
39408 return NULL;
39409 }
39410 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
39411 struct gsm_dlci *dlci = tty->driver_data;
39412 struct tty_port *port = &dlci->port;
39413
39414 - port->count++;
39415 + atomic_inc(&port->count);
39416 dlci_get(dlci);
39417 dlci_get(dlci->gsm->dlci[0]);
39418 mux_get(dlci->gsm);
39419 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39420 index 8c0b7b4..e88f052 100644
39421 --- a/drivers/tty/n_tty.c
39422 +++ b/drivers/tty/n_tty.c
39423 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39424 {
39425 *ops = tty_ldisc_N_TTY;
39426 ops->owner = NULL;
39427 - ops->refcount = ops->flags = 0;
39428 + atomic_set(&ops->refcount, 0);
39429 + ops->flags = 0;
39430 }
39431 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39432 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39433 index a82b399..331a220 100644
39434 --- a/drivers/tty/pty.c
39435 +++ b/drivers/tty/pty.c
39436 @@ -728,8 +728,10 @@ static void __init unix98_pty_init(void)
39437 panic("Couldn't register Unix98 pts driver");
39438
39439 /* Now create the /dev/ptmx special device */
39440 + pax_open_kernel();
39441 tty_default_fops(&ptmx_fops);
39442 - ptmx_fops.open = ptmx_open;
39443 + *(void **)&ptmx_fops.open = ptmx_open;
39444 + pax_close_kernel();
39445
39446 cdev_init(&ptmx_cdev, &ptmx_fops);
39447 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
39448 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
39449 index 9700d34..df7520c 100644
39450 --- a/drivers/tty/rocket.c
39451 +++ b/drivers/tty/rocket.c
39452 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39453 tty->driver_data = info;
39454 tty_port_tty_set(port, tty);
39455
39456 - if (port->count++ == 0) {
39457 + if (atomic_inc_return(&port->count) == 1) {
39458 atomic_inc(&rp_num_ports_open);
39459
39460 #ifdef ROCKET_DEBUG_OPEN
39461 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39462 #endif
39463 }
39464 #ifdef ROCKET_DEBUG_OPEN
39465 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
39466 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
39467 #endif
39468
39469 /*
39470 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
39471 spin_unlock_irqrestore(&info->port.lock, flags);
39472 return;
39473 }
39474 - if (info->port.count)
39475 + if (atomic_read(&info->port.count))
39476 atomic_dec(&rp_num_ports_open);
39477 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
39478 spin_unlock_irqrestore(&info->port.lock, flags);
39479 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
39480 index 1002054..dd644a8 100644
39481 --- a/drivers/tty/serial/kgdboc.c
39482 +++ b/drivers/tty/serial/kgdboc.c
39483 @@ -24,8 +24,9 @@
39484 #define MAX_CONFIG_LEN 40
39485
39486 static struct kgdb_io kgdboc_io_ops;
39487 +static struct kgdb_io kgdboc_io_ops_console;
39488
39489 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
39490 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
39491 static int configured = -1;
39492
39493 static char config[MAX_CONFIG_LEN];
39494 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
39495 kgdboc_unregister_kbd();
39496 if (configured == 1)
39497 kgdb_unregister_io_module(&kgdboc_io_ops);
39498 + else if (configured == 2)
39499 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
39500 }
39501
39502 static int configure_kgdboc(void)
39503 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
39504 int err;
39505 char *cptr = config;
39506 struct console *cons;
39507 + int is_console = 0;
39508
39509 err = kgdboc_option_setup(config);
39510 if (err || !strlen(config) || isspace(config[0]))
39511 goto noconfig;
39512
39513 err = -ENODEV;
39514 - kgdboc_io_ops.is_console = 0;
39515 kgdb_tty_driver = NULL;
39516
39517 kgdboc_use_kms = 0;
39518 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
39519 int idx;
39520 if (cons->device && cons->device(cons, &idx) == p &&
39521 idx == tty_line) {
39522 - kgdboc_io_ops.is_console = 1;
39523 + is_console = 1;
39524 break;
39525 }
39526 cons = cons->next;
39527 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
39528 kgdb_tty_line = tty_line;
39529
39530 do_register:
39531 - err = kgdb_register_io_module(&kgdboc_io_ops);
39532 + if (is_console) {
39533 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
39534 + configured = 2;
39535 + } else {
39536 + err = kgdb_register_io_module(&kgdboc_io_ops);
39537 + configured = 1;
39538 + }
39539 if (err)
39540 goto noconfig;
39541
39542 @@ -205,8 +214,6 @@ do_register:
39543 if (err)
39544 goto nmi_con_failed;
39545
39546 - configured = 1;
39547 -
39548 return 0;
39549
39550 nmi_con_failed:
39551 @@ -223,7 +230,7 @@ noconfig:
39552 static int __init init_kgdboc(void)
39553 {
39554 /* Already configured? */
39555 - if (configured == 1)
39556 + if (configured >= 1)
39557 return 0;
39558
39559 return configure_kgdboc();
39560 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
39561 if (config[len - 1] == '\n')
39562 config[len - 1] = '\0';
39563
39564 - if (configured == 1)
39565 + if (configured >= 1)
39566 cleanup_kgdboc();
39567
39568 /* Go and configure with the new params. */
39569 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
39570 .post_exception = kgdboc_post_exp_handler,
39571 };
39572
39573 +static struct kgdb_io kgdboc_io_ops_console = {
39574 + .name = "kgdboc",
39575 + .read_char = kgdboc_get_char,
39576 + .write_char = kgdboc_put_char,
39577 + .pre_exception = kgdboc_pre_exp_handler,
39578 + .post_exception = kgdboc_post_exp_handler,
39579 + .is_console = 1
39580 +};
39581 +
39582 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
39583 /* This is only available if kgdboc is a built in for early debugging */
39584 static int __init kgdboc_early_init(char *opt)
39585 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
39586 index 7f04717..0f3794f 100644
39587 --- a/drivers/tty/serial/samsung.c
39588 +++ b/drivers/tty/serial/samsung.c
39589 @@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
39590 }
39591 }
39592
39593 +static int s3c64xx_serial_startup(struct uart_port *port);
39594 static int s3c24xx_serial_startup(struct uart_port *port)
39595 {
39596 struct s3c24xx_uart_port *ourport = to_ourport(port);
39597 int ret;
39598
39599 + /* Startup sequence is different for s3c64xx and higher SoC's */
39600 + if (s3c24xx_serial_has_interrupt_mask(port))
39601 + return s3c64xx_serial_startup(port);
39602 +
39603 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
39604 port->mapbase, port->membase);
39605
39606 @@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
39607 /* setup info for port */
39608 port->dev = &platdev->dev;
39609
39610 - /* Startup sequence is different for s3c64xx and higher SoC's */
39611 - if (s3c24xx_serial_has_interrupt_mask(port))
39612 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
39613 -
39614 port->uartclk = 1;
39615
39616 if (cfg->uart_flags & UPF_CONS_FLOW) {
39617 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
39618 index 0fcfd98..8244fce 100644
39619 --- a/drivers/tty/serial/serial_core.c
39620 +++ b/drivers/tty/serial/serial_core.c
39621 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
39622 uart_flush_buffer(tty);
39623 uart_shutdown(tty, state);
39624 spin_lock_irqsave(&port->lock, flags);
39625 - port->count = 0;
39626 + atomic_set(&port->count, 0);
39627 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
39628 spin_unlock_irqrestore(&port->lock, flags);
39629 tty_port_tty_set(port, NULL);
39630 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39631 goto end;
39632 }
39633
39634 - port->count++;
39635 + atomic_inc(&port->count);
39636 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
39637 retval = -ENXIO;
39638 goto err_dec_count;
39639 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39640 /*
39641 * Make sure the device is in D0 state.
39642 */
39643 - if (port->count == 1)
39644 + if (atomic_read(&port->count) == 1)
39645 uart_change_pm(state, 0);
39646
39647 /*
39648 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39649 end:
39650 return retval;
39651 err_dec_count:
39652 - port->count--;
39653 + atomic_inc(&port->count);
39654 mutex_unlock(&port->mutex);
39655 goto end;
39656 }
39657 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
39658 index 70e3a52..5742052 100644
39659 --- a/drivers/tty/synclink.c
39660 +++ b/drivers/tty/synclink.c
39661 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39662
39663 if (debug_level >= DEBUG_LEVEL_INFO)
39664 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
39665 - __FILE__,__LINE__, info->device_name, info->port.count);
39666 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39667
39668 if (tty_port_close_start(&info->port, tty, filp) == 0)
39669 goto cleanup;
39670 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39671 cleanup:
39672 if (debug_level >= DEBUG_LEVEL_INFO)
39673 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
39674 - tty->driver->name, info->port.count);
39675 + tty->driver->name, atomic_read(&info->port.count));
39676
39677 } /* end of mgsl_close() */
39678
39679 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
39680
39681 mgsl_flush_buffer(tty);
39682 shutdown(info);
39683 -
39684 - info->port.count = 0;
39685 +
39686 + atomic_set(&info->port.count, 0);
39687 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39688 info->port.tty = NULL;
39689
39690 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39691
39692 if (debug_level >= DEBUG_LEVEL_INFO)
39693 printk("%s(%d):block_til_ready before block on %s count=%d\n",
39694 - __FILE__,__LINE__, tty->driver->name, port->count );
39695 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39696
39697 spin_lock_irqsave(&info->irq_spinlock, flags);
39698 if (!tty_hung_up_p(filp)) {
39699 extra_count = true;
39700 - port->count--;
39701 + atomic_dec(&port->count);
39702 }
39703 spin_unlock_irqrestore(&info->irq_spinlock, flags);
39704 port->blocked_open++;
39705 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39706
39707 if (debug_level >= DEBUG_LEVEL_INFO)
39708 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
39709 - __FILE__,__LINE__, tty->driver->name, port->count );
39710 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39711
39712 tty_unlock(tty);
39713 schedule();
39714 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39715
39716 /* FIXME: Racy on hangup during close wait */
39717 if (extra_count)
39718 - port->count++;
39719 + atomic_inc(&port->count);
39720 port->blocked_open--;
39721
39722 if (debug_level >= DEBUG_LEVEL_INFO)
39723 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
39724 - __FILE__,__LINE__, tty->driver->name, port->count );
39725 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39726
39727 if (!retval)
39728 port->flags |= ASYNC_NORMAL_ACTIVE;
39729 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
39730
39731 if (debug_level >= DEBUG_LEVEL_INFO)
39732 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
39733 - __FILE__,__LINE__,tty->driver->name, info->port.count);
39734 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
39735
39736 /* If port is closing, signal caller to try again */
39737 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39738 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
39739 spin_unlock_irqrestore(&info->netlock, flags);
39740 goto cleanup;
39741 }
39742 - info->port.count++;
39743 + atomic_inc(&info->port.count);
39744 spin_unlock_irqrestore(&info->netlock, flags);
39745
39746 - if (info->port.count == 1) {
39747 + if (atomic_read(&info->port.count) == 1) {
39748 /* 1st open on this device, init hardware */
39749 retval = startup(info);
39750 if (retval < 0)
39751 @@ -3451,8 +3451,8 @@ cleanup:
39752 if (retval) {
39753 if (tty->count == 1)
39754 info->port.tty = NULL; /* tty layer will release tty struct */
39755 - if(info->port.count)
39756 - info->port.count--;
39757 + if (atomic_read(&info->port.count))
39758 + atomic_dec(&info->port.count);
39759 }
39760
39761 return retval;
39762 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39763 unsigned short new_crctype;
39764
39765 /* return error if TTY interface open */
39766 - if (info->port.count)
39767 + if (atomic_read(&info->port.count))
39768 return -EBUSY;
39769
39770 switch (encoding)
39771 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
39772
39773 /* arbitrate between network and tty opens */
39774 spin_lock_irqsave(&info->netlock, flags);
39775 - if (info->port.count != 0 || info->netcount != 0) {
39776 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39777 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39778 spin_unlock_irqrestore(&info->netlock, flags);
39779 return -EBUSY;
39780 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39781 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
39782
39783 /* return error if TTY interface open */
39784 - if (info->port.count)
39785 + if (atomic_read(&info->port.count))
39786 return -EBUSY;
39787
39788 if (cmd != SIOCWANDEV)
39789 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
39790 index b38e954..ce45b38 100644
39791 --- a/drivers/tty/synclink_gt.c
39792 +++ b/drivers/tty/synclink_gt.c
39793 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
39794 tty->driver_data = info;
39795 info->port.tty = tty;
39796
39797 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
39798 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
39799
39800 /* If port is closing, signal caller to try again */
39801 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39802 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
39803 mutex_unlock(&info->port.mutex);
39804 goto cleanup;
39805 }
39806 - info->port.count++;
39807 + atomic_inc(&info->port.count);
39808 spin_unlock_irqrestore(&info->netlock, flags);
39809
39810 - if (info->port.count == 1) {
39811 + if (atomic_read(&info->port.count) == 1) {
39812 /* 1st open on this device, init hardware */
39813 retval = startup(info);
39814 if (retval < 0) {
39815 @@ -716,8 +716,8 @@ cleanup:
39816 if (retval) {
39817 if (tty->count == 1)
39818 info->port.tty = NULL; /* tty layer will release tty struct */
39819 - if(info->port.count)
39820 - info->port.count--;
39821 + if(atomic_read(&info->port.count))
39822 + atomic_dec(&info->port.count);
39823 }
39824
39825 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
39826 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39827
39828 if (sanity_check(info, tty->name, "close"))
39829 return;
39830 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
39831 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
39832
39833 if (tty_port_close_start(&info->port, tty, filp) == 0)
39834 goto cleanup;
39835 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39836 tty_port_close_end(&info->port, tty);
39837 info->port.tty = NULL;
39838 cleanup:
39839 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
39840 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
39841 }
39842
39843 static void hangup(struct tty_struct *tty)
39844 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
39845 shutdown(info);
39846
39847 spin_lock_irqsave(&info->port.lock, flags);
39848 - info->port.count = 0;
39849 + atomic_set(&info->port.count, 0);
39850 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39851 info->port.tty = NULL;
39852 spin_unlock_irqrestore(&info->port.lock, flags);
39853 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39854 unsigned short new_crctype;
39855
39856 /* return error if TTY interface open */
39857 - if (info->port.count)
39858 + if (atomic_read(&info->port.count))
39859 return -EBUSY;
39860
39861 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
39862 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
39863
39864 /* arbitrate between network and tty opens */
39865 spin_lock_irqsave(&info->netlock, flags);
39866 - if (info->port.count != 0 || info->netcount != 0) {
39867 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39868 DBGINFO(("%s hdlc_open busy\n", dev->name));
39869 spin_unlock_irqrestore(&info->netlock, flags);
39870 return -EBUSY;
39871 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39872 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
39873
39874 /* return error if TTY interface open */
39875 - if (info->port.count)
39876 + if (atomic_read(&info->port.count))
39877 return -EBUSY;
39878
39879 if (cmd != SIOCWANDEV)
39880 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
39881 if (port == NULL)
39882 continue;
39883 spin_lock(&port->lock);
39884 - if ((port->port.count || port->netcount) &&
39885 + if ((atomic_read(&port->port.count) || port->netcount) &&
39886 port->pending_bh && !port->bh_running &&
39887 !port->bh_requested) {
39888 DBGISR(("%s bh queued\n", port->device_name));
39889 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39890 spin_lock_irqsave(&info->lock, flags);
39891 if (!tty_hung_up_p(filp)) {
39892 extra_count = true;
39893 - port->count--;
39894 + atomic_dec(&port->count);
39895 }
39896 spin_unlock_irqrestore(&info->lock, flags);
39897 port->blocked_open++;
39898 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39899 remove_wait_queue(&port->open_wait, &wait);
39900
39901 if (extra_count)
39902 - port->count++;
39903 + atomic_inc(&port->count);
39904 port->blocked_open--;
39905
39906 if (!retval)
39907 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
39908 index f17d9f3..27a041b 100644
39909 --- a/drivers/tty/synclinkmp.c
39910 +++ b/drivers/tty/synclinkmp.c
39911 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
39912
39913 if (debug_level >= DEBUG_LEVEL_INFO)
39914 printk("%s(%d):%s open(), old ref count = %d\n",
39915 - __FILE__,__LINE__,tty->driver->name, info->port.count);
39916 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
39917
39918 /* If port is closing, signal caller to try again */
39919 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39920 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
39921 spin_unlock_irqrestore(&info->netlock, flags);
39922 goto cleanup;
39923 }
39924 - info->port.count++;
39925 + atomic_inc(&info->port.count);
39926 spin_unlock_irqrestore(&info->netlock, flags);
39927
39928 - if (info->port.count == 1) {
39929 + if (atomic_read(&info->port.count) == 1) {
39930 /* 1st open on this device, init hardware */
39931 retval = startup(info);
39932 if (retval < 0)
39933 @@ -797,8 +797,8 @@ cleanup:
39934 if (retval) {
39935 if (tty->count == 1)
39936 info->port.tty = NULL; /* tty layer will release tty struct */
39937 - if(info->port.count)
39938 - info->port.count--;
39939 + if(atomic_read(&info->port.count))
39940 + atomic_dec(&info->port.count);
39941 }
39942
39943 return retval;
39944 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39945
39946 if (debug_level >= DEBUG_LEVEL_INFO)
39947 printk("%s(%d):%s close() entry, count=%d\n",
39948 - __FILE__,__LINE__, info->device_name, info->port.count);
39949 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39950
39951 if (tty_port_close_start(&info->port, tty, filp) == 0)
39952 goto cleanup;
39953 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39954 cleanup:
39955 if (debug_level >= DEBUG_LEVEL_INFO)
39956 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
39957 - tty->driver->name, info->port.count);
39958 + tty->driver->name, atomic_read(&info->port.count));
39959 }
39960
39961 /* Called by tty_hangup() when a hangup is signaled.
39962 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
39963 shutdown(info);
39964
39965 spin_lock_irqsave(&info->port.lock, flags);
39966 - info->port.count = 0;
39967 + atomic_set(&info->port.count, 0);
39968 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39969 info->port.tty = NULL;
39970 spin_unlock_irqrestore(&info->port.lock, flags);
39971 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39972 unsigned short new_crctype;
39973
39974 /* return error if TTY interface open */
39975 - if (info->port.count)
39976 + if (atomic_read(&info->port.count))
39977 return -EBUSY;
39978
39979 switch (encoding)
39980 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
39981
39982 /* arbitrate between network and tty opens */
39983 spin_lock_irqsave(&info->netlock, flags);
39984 - if (info->port.count != 0 || info->netcount != 0) {
39985 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39986 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39987 spin_unlock_irqrestore(&info->netlock, flags);
39988 return -EBUSY;
39989 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39990 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
39991
39992 /* return error if TTY interface open */
39993 - if (info->port.count)
39994 + if (atomic_read(&info->port.count))
39995 return -EBUSY;
39996
39997 if (cmd != SIOCWANDEV)
39998 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
39999 * do not request bottom half processing if the
40000 * device is not open in a normal mode.
40001 */
40002 - if ( port && (port->port.count || port->netcount) &&
40003 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40004 port->pending_bh && !port->bh_running &&
40005 !port->bh_requested ) {
40006 if ( debug_level >= DEBUG_LEVEL_ISR )
40007 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40008
40009 if (debug_level >= DEBUG_LEVEL_INFO)
40010 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40011 - __FILE__,__LINE__, tty->driver->name, port->count );
40012 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40013
40014 spin_lock_irqsave(&info->lock, flags);
40015 if (!tty_hung_up_p(filp)) {
40016 extra_count = true;
40017 - port->count--;
40018 + atomic_dec(&port->count);
40019 }
40020 spin_unlock_irqrestore(&info->lock, flags);
40021 port->blocked_open++;
40022 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40023
40024 if (debug_level >= DEBUG_LEVEL_INFO)
40025 printk("%s(%d):%s block_til_ready() count=%d\n",
40026 - __FILE__,__LINE__, tty->driver->name, port->count );
40027 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40028
40029 tty_unlock(tty);
40030 schedule();
40031 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40032 remove_wait_queue(&port->open_wait, &wait);
40033
40034 if (extra_count)
40035 - port->count++;
40036 + atomic_inc(&port->count);
40037 port->blocked_open--;
40038
40039 if (debug_level >= DEBUG_LEVEL_INFO)
40040 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40041 - __FILE__,__LINE__, tty->driver->name, port->count );
40042 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40043
40044 if (!retval)
40045 port->flags |= ASYNC_NORMAL_ACTIVE;
40046 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40047 index 16ee6ce..bfcac57 100644
40048 --- a/drivers/tty/sysrq.c
40049 +++ b/drivers/tty/sysrq.c
40050 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40051 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40052 size_t count, loff_t *ppos)
40053 {
40054 - if (count) {
40055 + if (count && capable(CAP_SYS_ADMIN)) {
40056 char c;
40057
40058 if (get_user(c, buf))
40059 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40060 index 2ea176b..2877bc8 100644
40061 --- a/drivers/tty/tty_io.c
40062 +++ b/drivers/tty/tty_io.c
40063 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40064
40065 void tty_default_fops(struct file_operations *fops)
40066 {
40067 - *fops = tty_fops;
40068 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40069 }
40070
40071 /*
40072 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40073 index 0f2a2c5..471e228 100644
40074 --- a/drivers/tty/tty_ldisc.c
40075 +++ b/drivers/tty/tty_ldisc.c
40076 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40077 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40078 struct tty_ldisc_ops *ldo = ld->ops;
40079
40080 - ldo->refcount--;
40081 + atomic_dec(&ldo->refcount);
40082 module_put(ldo->owner);
40083 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40084
40085 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40086 spin_lock_irqsave(&tty_ldisc_lock, flags);
40087 tty_ldiscs[disc] = new_ldisc;
40088 new_ldisc->num = disc;
40089 - new_ldisc->refcount = 0;
40090 + atomic_set(&new_ldisc->refcount, 0);
40091 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40092
40093 return ret;
40094 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40095 return -EINVAL;
40096
40097 spin_lock_irqsave(&tty_ldisc_lock, flags);
40098 - if (tty_ldiscs[disc]->refcount)
40099 + if (atomic_read(&tty_ldiscs[disc]->refcount))
40100 ret = -EBUSY;
40101 else
40102 tty_ldiscs[disc] = NULL;
40103 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40104 if (ldops) {
40105 ret = ERR_PTR(-EAGAIN);
40106 if (try_module_get(ldops->owner)) {
40107 - ldops->refcount++;
40108 + atomic_inc(&ldops->refcount);
40109 ret = ldops;
40110 }
40111 }
40112 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40113 unsigned long flags;
40114
40115 spin_lock_irqsave(&tty_ldisc_lock, flags);
40116 - ldops->refcount--;
40117 + atomic_dec(&ldops->refcount);
40118 module_put(ldops->owner);
40119 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40120 }
40121 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40122 index d7bdd8d..feaef30 100644
40123 --- a/drivers/tty/tty_port.c
40124 +++ b/drivers/tty/tty_port.c
40125 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40126 unsigned long flags;
40127
40128 spin_lock_irqsave(&port->lock, flags);
40129 - port->count = 0;
40130 + atomic_set(&port->count, 0);
40131 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40132 if (port->tty) {
40133 set_bit(TTY_IO_ERROR, &port->tty->flags);
40134 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40135 /* The port lock protects the port counts */
40136 spin_lock_irqsave(&port->lock, flags);
40137 if (!tty_hung_up_p(filp))
40138 - port->count--;
40139 + atomic_dec(&port->count);
40140 port->blocked_open++;
40141 spin_unlock_irqrestore(&port->lock, flags);
40142
40143 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40144 we must not mess that up further */
40145 spin_lock_irqsave(&port->lock, flags);
40146 if (!tty_hung_up_p(filp))
40147 - port->count++;
40148 + atomic_inc(&port->count);
40149 port->blocked_open--;
40150 if (retval == 0)
40151 port->flags |= ASYNC_NORMAL_ACTIVE;
40152 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40153 return 0;
40154 }
40155
40156 - if (tty->count == 1 && port->count != 1) {
40157 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
40158 printk(KERN_WARNING
40159 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40160 - port->count);
40161 - port->count = 1;
40162 + atomic_read(&port->count));
40163 + atomic_set(&port->count, 1);
40164 }
40165 - if (--port->count < 0) {
40166 + if (atomic_dec_return(&port->count) < 0) {
40167 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40168 - port->count);
40169 - port->count = 0;
40170 + atomic_read(&port->count));
40171 + atomic_set(&port->count, 0);
40172 }
40173
40174 - if (port->count) {
40175 + if (atomic_read(&port->count)) {
40176 spin_unlock_irqrestore(&port->lock, flags);
40177 if (port->ops->drop)
40178 port->ops->drop(port);
40179 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40180 {
40181 spin_lock_irq(&port->lock);
40182 if (!tty_hung_up_p(filp))
40183 - ++port->count;
40184 + atomic_inc(&port->count);
40185 spin_unlock_irq(&port->lock);
40186 tty_port_tty_set(port, tty);
40187
40188 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40189 index 681765b..d3ccdf2 100644
40190 --- a/drivers/tty/vt/keyboard.c
40191 +++ b/drivers/tty/vt/keyboard.c
40192 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40193 kbd->kbdmode == VC_OFF) &&
40194 value != KVAL(K_SAK))
40195 return; /* SAK is allowed even in raw mode */
40196 +
40197 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40198 + {
40199 + void *func = fn_handler[value];
40200 + if (func == fn_show_state || func == fn_show_ptregs ||
40201 + func == fn_show_mem)
40202 + return;
40203 + }
40204 +#endif
40205 +
40206 fn_handler[value](vc);
40207 }
40208
40209 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40210 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40211 return -EFAULT;
40212
40213 - if (!capable(CAP_SYS_TTY_CONFIG))
40214 - perm = 0;
40215 -
40216 switch (cmd) {
40217 case KDGKBENT:
40218 /* Ensure another thread doesn't free it under us */
40219 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40220 spin_unlock_irqrestore(&kbd_event_lock, flags);
40221 return put_user(val, &user_kbe->kb_value);
40222 case KDSKBENT:
40223 + if (!capable(CAP_SYS_TTY_CONFIG))
40224 + perm = 0;
40225 +
40226 if (!perm)
40227 return -EPERM;
40228 if (!i && v == K_NOSUCHMAP) {
40229 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40230 int i, j, k;
40231 int ret;
40232
40233 - if (!capable(CAP_SYS_TTY_CONFIG))
40234 - perm = 0;
40235 -
40236 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40237 if (!kbs) {
40238 ret = -ENOMEM;
40239 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40240 kfree(kbs);
40241 return ((p && *p) ? -EOVERFLOW : 0);
40242 case KDSKBSENT:
40243 + if (!capable(CAP_SYS_TTY_CONFIG))
40244 + perm = 0;
40245 +
40246 if (!perm) {
40247 ret = -EPERM;
40248 goto reterr;
40249 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40250 index 5110f36..8dc0a74 100644
40251 --- a/drivers/uio/uio.c
40252 +++ b/drivers/uio/uio.c
40253 @@ -25,6 +25,7 @@
40254 #include <linux/kobject.h>
40255 #include <linux/cdev.h>
40256 #include <linux/uio_driver.h>
40257 +#include <asm/local.h>
40258
40259 #define UIO_MAX_DEVICES (1U << MINORBITS)
40260
40261 @@ -32,10 +33,10 @@ struct uio_device {
40262 struct module *owner;
40263 struct device *dev;
40264 int minor;
40265 - atomic_t event;
40266 + atomic_unchecked_t event;
40267 struct fasync_struct *async_queue;
40268 wait_queue_head_t wait;
40269 - int vma_count;
40270 + local_t vma_count;
40271 struct uio_info *info;
40272 struct kobject *map_dir;
40273 struct kobject *portio_dir;
40274 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40275 struct device_attribute *attr, char *buf)
40276 {
40277 struct uio_device *idev = dev_get_drvdata(dev);
40278 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40279 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40280 }
40281
40282 static struct device_attribute uio_class_attributes[] = {
40283 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40284 {
40285 struct uio_device *idev = info->uio_dev;
40286
40287 - atomic_inc(&idev->event);
40288 + atomic_inc_unchecked(&idev->event);
40289 wake_up_interruptible(&idev->wait);
40290 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40291 }
40292 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40293 }
40294
40295 listener->dev = idev;
40296 - listener->event_count = atomic_read(&idev->event);
40297 + listener->event_count = atomic_read_unchecked(&idev->event);
40298 filep->private_data = listener;
40299
40300 if (idev->info->open) {
40301 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40302 return -EIO;
40303
40304 poll_wait(filep, &idev->wait, wait);
40305 - if (listener->event_count != atomic_read(&idev->event))
40306 + if (listener->event_count != atomic_read_unchecked(&idev->event))
40307 return POLLIN | POLLRDNORM;
40308 return 0;
40309 }
40310 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40311 do {
40312 set_current_state(TASK_INTERRUPTIBLE);
40313
40314 - event_count = atomic_read(&idev->event);
40315 + event_count = atomic_read_unchecked(&idev->event);
40316 if (event_count != listener->event_count) {
40317 if (copy_to_user(buf, &event_count, count))
40318 retval = -EFAULT;
40319 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40320 static void uio_vma_open(struct vm_area_struct *vma)
40321 {
40322 struct uio_device *idev = vma->vm_private_data;
40323 - idev->vma_count++;
40324 + local_inc(&idev->vma_count);
40325 }
40326
40327 static void uio_vma_close(struct vm_area_struct *vma)
40328 {
40329 struct uio_device *idev = vma->vm_private_data;
40330 - idev->vma_count--;
40331 + local_dec(&idev->vma_count);
40332 }
40333
40334 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40335 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40336 idev->owner = owner;
40337 idev->info = info;
40338 init_waitqueue_head(&idev->wait);
40339 - atomic_set(&idev->event, 0);
40340 + atomic_set_unchecked(&idev->event, 0);
40341
40342 ret = uio_get_minor(idev);
40343 if (ret)
40344 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40345 index b7eb86a..36d28af 100644
40346 --- a/drivers/usb/atm/cxacru.c
40347 +++ b/drivers/usb/atm/cxacru.c
40348 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40349 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40350 if (ret < 2)
40351 return -EINVAL;
40352 - if (index < 0 || index > 0x7f)
40353 + if (index > 0x7f)
40354 return -EINVAL;
40355 pos += tmp;
40356
40357 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40358 index 35f10bf..6a38a0b 100644
40359 --- a/drivers/usb/atm/usbatm.c
40360 +++ b/drivers/usb/atm/usbatm.c
40361 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40362 if (printk_ratelimit())
40363 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40364 __func__, vpi, vci);
40365 - atomic_inc(&vcc->stats->rx_err);
40366 + atomic_inc_unchecked(&vcc->stats->rx_err);
40367 return;
40368 }
40369
40370 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40371 if (length > ATM_MAX_AAL5_PDU) {
40372 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40373 __func__, length, vcc);
40374 - atomic_inc(&vcc->stats->rx_err);
40375 + atomic_inc_unchecked(&vcc->stats->rx_err);
40376 goto out;
40377 }
40378
40379 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40380 if (sarb->len < pdu_length) {
40381 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40382 __func__, pdu_length, sarb->len, vcc);
40383 - atomic_inc(&vcc->stats->rx_err);
40384 + atomic_inc_unchecked(&vcc->stats->rx_err);
40385 goto out;
40386 }
40387
40388 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40389 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
40390 __func__, vcc);
40391 - atomic_inc(&vcc->stats->rx_err);
40392 + atomic_inc_unchecked(&vcc->stats->rx_err);
40393 goto out;
40394 }
40395
40396 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40397 if (printk_ratelimit())
40398 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
40399 __func__, length);
40400 - atomic_inc(&vcc->stats->rx_drop);
40401 + atomic_inc_unchecked(&vcc->stats->rx_drop);
40402 goto out;
40403 }
40404
40405 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40406
40407 vcc->push(vcc, skb);
40408
40409 - atomic_inc(&vcc->stats->rx);
40410 + atomic_inc_unchecked(&vcc->stats->rx);
40411 out:
40412 skb_trim(sarb, 0);
40413 }
40414 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
40415 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
40416
40417 usbatm_pop(vcc, skb);
40418 - atomic_inc(&vcc->stats->tx);
40419 + atomic_inc_unchecked(&vcc->stats->tx);
40420
40421 skb = skb_dequeue(&instance->sndqueue);
40422 }
40423 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
40424 if (!left--)
40425 return sprintf(page,
40426 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
40427 - atomic_read(&atm_dev->stats.aal5.tx),
40428 - atomic_read(&atm_dev->stats.aal5.tx_err),
40429 - atomic_read(&atm_dev->stats.aal5.rx),
40430 - atomic_read(&atm_dev->stats.aal5.rx_err),
40431 - atomic_read(&atm_dev->stats.aal5.rx_drop));
40432 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
40433 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
40434 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
40435 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
40436 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
40437
40438 if (!left--) {
40439 if (instance->disconnected)
40440 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
40441 index f460de3..95ba1f6 100644
40442 --- a/drivers/usb/core/devices.c
40443 +++ b/drivers/usb/core/devices.c
40444 @@ -126,7 +126,7 @@ static const char format_endpt[] =
40445 * time it gets called.
40446 */
40447 static struct device_connect_event {
40448 - atomic_t count;
40449 + atomic_unchecked_t count;
40450 wait_queue_head_t wait;
40451 } device_event = {
40452 .count = ATOMIC_INIT(1),
40453 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
40454
40455 void usbfs_conn_disc_event(void)
40456 {
40457 - atomic_add(2, &device_event.count);
40458 + atomic_add_unchecked(2, &device_event.count);
40459 wake_up(&device_event.wait);
40460 }
40461
40462 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
40463
40464 poll_wait(file, &device_event.wait, wait);
40465
40466 - event_count = atomic_read(&device_event.count);
40467 + event_count = atomic_read_unchecked(&device_event.count);
40468 if (file->f_version != event_count) {
40469 file->f_version = event_count;
40470 return POLLIN | POLLRDNORM;
40471 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
40472 index f034716..aed0368 100644
40473 --- a/drivers/usb/core/hcd.c
40474 +++ b/drivers/usb/core/hcd.c
40475 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40476 */
40477 usb_get_urb(urb);
40478 atomic_inc(&urb->use_count);
40479 - atomic_inc(&urb->dev->urbnum);
40480 + atomic_inc_unchecked(&urb->dev->urbnum);
40481 usbmon_urb_submit(&hcd->self, urb);
40482
40483 /* NOTE requirements on root-hub callers (usbfs and the hub
40484 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40485 urb->hcpriv = NULL;
40486 INIT_LIST_HEAD(&urb->urb_list);
40487 atomic_dec(&urb->use_count);
40488 - atomic_dec(&urb->dev->urbnum);
40489 + atomic_dec_unchecked(&urb->dev->urbnum);
40490 if (atomic_read(&urb->reject))
40491 wake_up(&usb_kill_urb_queue);
40492 usb_put_urb(urb);
40493 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
40494 index 818e4a0..0fc9589 100644
40495 --- a/drivers/usb/core/sysfs.c
40496 +++ b/drivers/usb/core/sysfs.c
40497 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
40498 struct usb_device *udev;
40499
40500 udev = to_usb_device(dev);
40501 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
40502 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
40503 }
40504 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
40505
40506 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
40507 index cd8fb44..17fbe0c 100644
40508 --- a/drivers/usb/core/usb.c
40509 +++ b/drivers/usb/core/usb.c
40510 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
40511 set_dev_node(&dev->dev, dev_to_node(bus->controller));
40512 dev->state = USB_STATE_ATTACHED;
40513 dev->lpm_disable_count = 1;
40514 - atomic_set(&dev->urbnum, 0);
40515 + atomic_set_unchecked(&dev->urbnum, 0);
40516
40517 INIT_LIST_HEAD(&dev->ep0.urb_list);
40518 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
40519 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
40520 index 4bfa78a..902bfbd 100644
40521 --- a/drivers/usb/early/ehci-dbgp.c
40522 +++ b/drivers/usb/early/ehci-dbgp.c
40523 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
40524
40525 #ifdef CONFIG_KGDB
40526 static struct kgdb_io kgdbdbgp_io_ops;
40527 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
40528 +static struct kgdb_io kgdbdbgp_io_ops_console;
40529 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
40530 #else
40531 #define dbgp_kgdb_mode (0)
40532 #endif
40533 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
40534 .write_char = kgdbdbgp_write_char,
40535 };
40536
40537 +static struct kgdb_io kgdbdbgp_io_ops_console = {
40538 + .name = "kgdbdbgp",
40539 + .read_char = kgdbdbgp_read_char,
40540 + .write_char = kgdbdbgp_write_char,
40541 + .is_console = 1
40542 +};
40543 +
40544 static int kgdbdbgp_wait_time;
40545
40546 static int __init kgdbdbgp_parse_config(char *str)
40547 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
40548 ptr++;
40549 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
40550 }
40551 - kgdb_register_io_module(&kgdbdbgp_io_ops);
40552 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
40553 + if (early_dbgp_console.index != -1)
40554 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
40555 + else
40556 + kgdb_register_io_module(&kgdbdbgp_io_ops);
40557
40558 return 0;
40559 }
40560 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
40561 index f173952..83d6ec0 100644
40562 --- a/drivers/usb/gadget/u_serial.c
40563 +++ b/drivers/usb/gadget/u_serial.c
40564 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40565 spin_lock_irq(&port->port_lock);
40566
40567 /* already open? Great. */
40568 - if (port->port.count) {
40569 + if (atomic_read(&port->port.count)) {
40570 status = 0;
40571 - port->port.count++;
40572 + atomic_inc(&port->port.count);
40573
40574 /* currently opening/closing? wait ... */
40575 } else if (port->openclose) {
40576 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40577 tty->driver_data = port;
40578 port->port.tty = tty;
40579
40580 - port->port.count = 1;
40581 + atomic_set(&port->port.count, 1);
40582 port->openclose = false;
40583
40584 /* if connected, start the I/O stream */
40585 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40586
40587 spin_lock_irq(&port->port_lock);
40588
40589 - if (port->port.count != 1) {
40590 - if (port->port.count == 0)
40591 + if (atomic_read(&port->port.count) != 1) {
40592 + if (atomic_read(&port->port.count) == 0)
40593 WARN_ON(1);
40594 else
40595 - --port->port.count;
40596 + atomic_dec(&port->port.count);
40597 goto exit;
40598 }
40599
40600 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40601 * and sleep if necessary
40602 */
40603 port->openclose = true;
40604 - port->port.count = 0;
40605 + atomic_set(&port->port.count, 0);
40606
40607 gser = port->port_usb;
40608 if (gser && gser->disconnect)
40609 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
40610 int cond;
40611
40612 spin_lock_irq(&port->port_lock);
40613 - cond = (port->port.count == 0) && !port->openclose;
40614 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
40615 spin_unlock_irq(&port->port_lock);
40616 return cond;
40617 }
40618 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
40619 /* if it's already open, start I/O ... and notify the serial
40620 * protocol about open/close status (connect/disconnect).
40621 */
40622 - if (port->port.count) {
40623 + if (atomic_read(&port->port.count)) {
40624 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
40625 gs_start_io(port);
40626 if (gser->connect)
40627 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
40628
40629 port->port_usb = NULL;
40630 gser->ioport = NULL;
40631 - if (port->port.count > 0 || port->openclose) {
40632 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
40633 wake_up_interruptible(&port->drain_wait);
40634 if (port->port.tty)
40635 tty_hangup(port->port.tty);
40636 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
40637
40638 /* finally, free any unused/unusable I/O buffers */
40639 spin_lock_irqsave(&port->port_lock, flags);
40640 - if (port->port.count == 0 && !port->openclose)
40641 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
40642 gs_buf_free(&port->port_write_buf);
40643 gs_free_requests(gser->out, &port->read_pool, NULL);
40644 gs_free_requests(gser->out, &port->read_queue, NULL);
40645 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
40646 index 5f3bcd3..bfca43f 100644
40647 --- a/drivers/usb/serial/console.c
40648 +++ b/drivers/usb/serial/console.c
40649 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
40650
40651 info->port = port;
40652
40653 - ++port->port.count;
40654 + atomic_inc(&port->port.count);
40655 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
40656 if (serial->type->set_termios) {
40657 /*
40658 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
40659 }
40660 /* Now that any required fake tty operations are completed restore
40661 * the tty port count */
40662 - --port->port.count;
40663 + atomic_dec(&port->port.count);
40664 /* The console is special in terms of closing the device so
40665 * indicate this port is now acting as a system console. */
40666 port->port.console = 1;
40667 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
40668 free_tty:
40669 kfree(tty);
40670 reset_open_count:
40671 - port->port.count = 0;
40672 + atomic_set(&port->port.count, 0);
40673 usb_autopm_put_interface(serial->interface);
40674 error_get_interface:
40675 usb_serial_put(serial);
40676 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
40677 index d6bea3e..60b250e 100644
40678 --- a/drivers/usb/wusbcore/wa-hc.h
40679 +++ b/drivers/usb/wusbcore/wa-hc.h
40680 @@ -192,7 +192,7 @@ struct wahc {
40681 struct list_head xfer_delayed_list;
40682 spinlock_t xfer_list_lock;
40683 struct work_struct xfer_work;
40684 - atomic_t xfer_id_count;
40685 + atomic_unchecked_t xfer_id_count;
40686 };
40687
40688
40689 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
40690 INIT_LIST_HEAD(&wa->xfer_delayed_list);
40691 spin_lock_init(&wa->xfer_list_lock);
40692 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
40693 - atomic_set(&wa->xfer_id_count, 1);
40694 + atomic_set_unchecked(&wa->xfer_id_count, 1);
40695 }
40696
40697 /**
40698 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
40699 index 57c01ab..8a05959 100644
40700 --- a/drivers/usb/wusbcore/wa-xfer.c
40701 +++ b/drivers/usb/wusbcore/wa-xfer.c
40702 @@ -296,7 +296,7 @@ out:
40703 */
40704 static void wa_xfer_id_init(struct wa_xfer *xfer)
40705 {
40706 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
40707 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
40708 }
40709
40710 /*
40711 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
40712 index dedaf81..b0f11ab 100644
40713 --- a/drivers/vhost/vhost.c
40714 +++ b/drivers/vhost/vhost.c
40715 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
40716 return 0;
40717 }
40718
40719 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
40720 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
40721 {
40722 struct file *eventfp, *filep = NULL;
40723 bool pollstart = false, pollstop = false;
40724 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
40725 index 0fefa84..7a9d581 100644
40726 --- a/drivers/video/aty/aty128fb.c
40727 +++ b/drivers/video/aty/aty128fb.c
40728 @@ -149,7 +149,7 @@ enum {
40729 };
40730
40731 /* Must match above enum */
40732 -static char * const r128_family[] __devinitconst = {
40733 +static const char * const r128_family[] __devinitconst = {
40734 "AGP",
40735 "PCI",
40736 "PRO AGP",
40737 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
40738 index 5c3960d..15cf8fc 100644
40739 --- a/drivers/video/fbcmap.c
40740 +++ b/drivers/video/fbcmap.c
40741 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
40742 rc = -ENODEV;
40743 goto out;
40744 }
40745 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
40746 - !info->fbops->fb_setcmap)) {
40747 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
40748 rc = -EINVAL;
40749 goto out1;
40750 }
40751 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
40752 index 3ff0105..7589d98 100644
40753 --- a/drivers/video/fbmem.c
40754 +++ b/drivers/video/fbmem.c
40755 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
40756 image->dx += image->width + 8;
40757 }
40758 } else if (rotate == FB_ROTATE_UD) {
40759 - for (x = 0; x < num && image->dx >= 0; x++) {
40760 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
40761 info->fbops->fb_imageblit(info, image);
40762 image->dx -= image->width + 8;
40763 }
40764 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
40765 image->dy += image->height + 8;
40766 }
40767 } else if (rotate == FB_ROTATE_CCW) {
40768 - for (x = 0; x < num && image->dy >= 0; x++) {
40769 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
40770 info->fbops->fb_imageblit(info, image);
40771 image->dy -= image->height + 8;
40772 }
40773 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
40774 return -EFAULT;
40775 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
40776 return -EINVAL;
40777 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
40778 + if (con2fb.framebuffer >= FB_MAX)
40779 return -EINVAL;
40780 if (!registered_fb[con2fb.framebuffer])
40781 request_module("fb%d", con2fb.framebuffer);
40782 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
40783 index 7672d2e..b56437f 100644
40784 --- a/drivers/video/i810/i810_accel.c
40785 +++ b/drivers/video/i810/i810_accel.c
40786 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
40787 }
40788 }
40789 printk("ringbuffer lockup!!!\n");
40790 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
40791 i810_report_error(mmio);
40792 par->dev_flags |= LOCKUP;
40793 info->pixmap.scan_align = 1;
40794 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
40795 index 3c14e43..eafa544 100644
40796 --- a/drivers/video/logo/logo_linux_clut224.ppm
40797 +++ b/drivers/video/logo/logo_linux_clut224.ppm
40798 @@ -1,1604 +1,1123 @@
40799 P3
40800 -# Standard 224-color Linux logo
40801 80 80
40802 255
40803 - 0 0 0 0 0 0 0 0 0 0 0 0
40804 - 0 0 0 0 0 0 0 0 0 0 0 0
40805 - 0 0 0 0 0 0 0 0 0 0 0 0
40806 - 0 0 0 0 0 0 0 0 0 0 0 0
40807 - 0 0 0 0 0 0 0 0 0 0 0 0
40808 - 0 0 0 0 0 0 0 0 0 0 0 0
40809 - 0 0 0 0 0 0 0 0 0 0 0 0
40810 - 0 0 0 0 0 0 0 0 0 0 0 0
40811 - 0 0 0 0 0 0 0 0 0 0 0 0
40812 - 6 6 6 6 6 6 10 10 10 10 10 10
40813 - 10 10 10 6 6 6 6 6 6 6 6 6
40814 - 0 0 0 0 0 0 0 0 0 0 0 0
40815 - 0 0 0 0 0 0 0 0 0 0 0 0
40816 - 0 0 0 0 0 0 0 0 0 0 0 0
40817 - 0 0 0 0 0 0 0 0 0 0 0 0
40818 - 0 0 0 0 0 0 0 0 0 0 0 0
40819 - 0 0 0 0 0 0 0 0 0 0 0 0
40820 - 0 0 0 0 0 0 0 0 0 0 0 0
40821 - 0 0 0 0 0 0 0 0 0 0 0 0
40822 - 0 0 0 0 0 0 0 0 0 0 0 0
40823 - 0 0 0 0 0 0 0 0 0 0 0 0
40824 - 0 0 0 0 0 0 0 0 0 0 0 0
40825 - 0 0 0 0 0 0 0 0 0 0 0 0
40826 - 0 0 0 0 0 0 0 0 0 0 0 0
40827 - 0 0 0 0 0 0 0 0 0 0 0 0
40828 - 0 0 0 0 0 0 0 0 0 0 0 0
40829 - 0 0 0 0 0 0 0 0 0 0 0 0
40830 - 0 0 0 0 0 0 0 0 0 0 0 0
40831 - 0 0 0 6 6 6 10 10 10 14 14 14
40832 - 22 22 22 26 26 26 30 30 30 34 34 34
40833 - 30 30 30 30 30 30 26 26 26 18 18 18
40834 - 14 14 14 10 10 10 6 6 6 0 0 0
40835 - 0 0 0 0 0 0 0 0 0 0 0 0
40836 - 0 0 0 0 0 0 0 0 0 0 0 0
40837 - 0 0 0 0 0 0 0 0 0 0 0 0
40838 - 0 0 0 0 0 0 0 0 0 0 0 0
40839 - 0 0 0 0 0 0 0 0 0 0 0 0
40840 - 0 0 0 0 0 0 0 0 0 0 0 0
40841 - 0 0 0 0 0 0 0 0 0 0 0 0
40842 - 0 0 0 0 0 0 0 0 0 0 0 0
40843 - 0 0 0 0 0 0 0 0 0 0 0 0
40844 - 0 0 0 0 0 1 0 0 1 0 0 0
40845 - 0 0 0 0 0 0 0 0 0 0 0 0
40846 - 0 0 0 0 0 0 0 0 0 0 0 0
40847 - 0 0 0 0 0 0 0 0 0 0 0 0
40848 - 0 0 0 0 0 0 0 0 0 0 0 0
40849 - 0 0 0 0 0 0 0 0 0 0 0 0
40850 - 0 0 0 0 0 0 0 0 0 0 0 0
40851 - 6 6 6 14 14 14 26 26 26 42 42 42
40852 - 54 54 54 66 66 66 78 78 78 78 78 78
40853 - 78 78 78 74 74 74 66 66 66 54 54 54
40854 - 42 42 42 26 26 26 18 18 18 10 10 10
40855 - 6 6 6 0 0 0 0 0 0 0 0 0
40856 - 0 0 0 0 0 0 0 0 0 0 0 0
40857 - 0 0 0 0 0 0 0 0 0 0 0 0
40858 - 0 0 0 0 0 0 0 0 0 0 0 0
40859 - 0 0 0 0 0 0 0 0 0 0 0 0
40860 - 0 0 0 0 0 0 0 0 0 0 0 0
40861 - 0 0 0 0 0 0 0 0 0 0 0 0
40862 - 0 0 0 0 0 0 0 0 0 0 0 0
40863 - 0 0 0 0 0 0 0 0 0 0 0 0
40864 - 0 0 1 0 0 0 0 0 0 0 0 0
40865 - 0 0 0 0 0 0 0 0 0 0 0 0
40866 - 0 0 0 0 0 0 0 0 0 0 0 0
40867 - 0 0 0 0 0 0 0 0 0 0 0 0
40868 - 0 0 0 0 0 0 0 0 0 0 0 0
40869 - 0 0 0 0 0 0 0 0 0 0 0 0
40870 - 0 0 0 0 0 0 0 0 0 10 10 10
40871 - 22 22 22 42 42 42 66 66 66 86 86 86
40872 - 66 66 66 38 38 38 38 38 38 22 22 22
40873 - 26 26 26 34 34 34 54 54 54 66 66 66
40874 - 86 86 86 70 70 70 46 46 46 26 26 26
40875 - 14 14 14 6 6 6 0 0 0 0 0 0
40876 - 0 0 0 0 0 0 0 0 0 0 0 0
40877 - 0 0 0 0 0 0 0 0 0 0 0 0
40878 - 0 0 0 0 0 0 0 0 0 0 0 0
40879 - 0 0 0 0 0 0 0 0 0 0 0 0
40880 - 0 0 0 0 0 0 0 0 0 0 0 0
40881 - 0 0 0 0 0 0 0 0 0 0 0 0
40882 - 0 0 0 0 0 0 0 0 0 0 0 0
40883 - 0 0 0 0 0 0 0 0 0 0 0 0
40884 - 0 0 1 0 0 1 0 0 1 0 0 0
40885 - 0 0 0 0 0 0 0 0 0 0 0 0
40886 - 0 0 0 0 0 0 0 0 0 0 0 0
40887 - 0 0 0 0 0 0 0 0 0 0 0 0
40888 - 0 0 0 0 0 0 0 0 0 0 0 0
40889 - 0 0 0 0 0 0 0 0 0 0 0 0
40890 - 0 0 0 0 0 0 10 10 10 26 26 26
40891 - 50 50 50 82 82 82 58 58 58 6 6 6
40892 - 2 2 6 2 2 6 2 2 6 2 2 6
40893 - 2 2 6 2 2 6 2 2 6 2 2 6
40894 - 6 6 6 54 54 54 86 86 86 66 66 66
40895 - 38 38 38 18 18 18 6 6 6 0 0 0
40896 - 0 0 0 0 0 0 0 0 0 0 0 0
40897 - 0 0 0 0 0 0 0 0 0 0 0 0
40898 - 0 0 0 0 0 0 0 0 0 0 0 0
40899 - 0 0 0 0 0 0 0 0 0 0 0 0
40900 - 0 0 0 0 0 0 0 0 0 0 0 0
40901 - 0 0 0 0 0 0 0 0 0 0 0 0
40902 - 0 0 0 0 0 0 0 0 0 0 0 0
40903 - 0 0 0 0 0 0 0 0 0 0 0 0
40904 - 0 0 0 0 0 0 0 0 0 0 0 0
40905 - 0 0 0 0 0 0 0 0 0 0 0 0
40906 - 0 0 0 0 0 0 0 0 0 0 0 0
40907 - 0 0 0 0 0 0 0 0 0 0 0 0
40908 - 0 0 0 0 0 0 0 0 0 0 0 0
40909 - 0 0 0 0 0 0 0 0 0 0 0 0
40910 - 0 0 0 6 6 6 22 22 22 50 50 50
40911 - 78 78 78 34 34 34 2 2 6 2 2 6
40912 - 2 2 6 2 2 6 2 2 6 2 2 6
40913 - 2 2 6 2 2 6 2 2 6 2 2 6
40914 - 2 2 6 2 2 6 6 6 6 70 70 70
40915 - 78 78 78 46 46 46 22 22 22 6 6 6
40916 - 0 0 0 0 0 0 0 0 0 0 0 0
40917 - 0 0 0 0 0 0 0 0 0 0 0 0
40918 - 0 0 0 0 0 0 0 0 0 0 0 0
40919 - 0 0 0 0 0 0 0 0 0 0 0 0
40920 - 0 0 0 0 0 0 0 0 0 0 0 0
40921 - 0 0 0 0 0 0 0 0 0 0 0 0
40922 - 0 0 0 0 0 0 0 0 0 0 0 0
40923 - 0 0 0 0 0 0 0 0 0 0 0 0
40924 - 0 0 1 0 0 1 0 0 1 0 0 0
40925 - 0 0 0 0 0 0 0 0 0 0 0 0
40926 - 0 0 0 0 0 0 0 0 0 0 0 0
40927 - 0 0 0 0 0 0 0 0 0 0 0 0
40928 - 0 0 0 0 0 0 0 0 0 0 0 0
40929 - 0 0 0 0 0 0 0 0 0 0 0 0
40930 - 6 6 6 18 18 18 42 42 42 82 82 82
40931 - 26 26 26 2 2 6 2 2 6 2 2 6
40932 - 2 2 6 2 2 6 2 2 6 2 2 6
40933 - 2 2 6 2 2 6 2 2 6 14 14 14
40934 - 46 46 46 34 34 34 6 6 6 2 2 6
40935 - 42 42 42 78 78 78 42 42 42 18 18 18
40936 - 6 6 6 0 0 0 0 0 0 0 0 0
40937 - 0 0 0 0 0 0 0 0 0 0 0 0
40938 - 0 0 0 0 0 0 0 0 0 0 0 0
40939 - 0 0 0 0 0 0 0 0 0 0 0 0
40940 - 0 0 0 0 0 0 0 0 0 0 0 0
40941 - 0 0 0 0 0 0 0 0 0 0 0 0
40942 - 0 0 0 0 0 0 0 0 0 0 0 0
40943 - 0 0 0 0 0 0 0 0 0 0 0 0
40944 - 0 0 1 0 0 0 0 0 1 0 0 0
40945 - 0 0 0 0 0 0 0 0 0 0 0 0
40946 - 0 0 0 0 0 0 0 0 0 0 0 0
40947 - 0 0 0 0 0 0 0 0 0 0 0 0
40948 - 0 0 0 0 0 0 0 0 0 0 0 0
40949 - 0 0 0 0 0 0 0 0 0 0 0 0
40950 - 10 10 10 30 30 30 66 66 66 58 58 58
40951 - 2 2 6 2 2 6 2 2 6 2 2 6
40952 - 2 2 6 2 2 6 2 2 6 2 2 6
40953 - 2 2 6 2 2 6 2 2 6 26 26 26
40954 - 86 86 86 101 101 101 46 46 46 10 10 10
40955 - 2 2 6 58 58 58 70 70 70 34 34 34
40956 - 10 10 10 0 0 0 0 0 0 0 0 0
40957 - 0 0 0 0 0 0 0 0 0 0 0 0
40958 - 0 0 0 0 0 0 0 0 0 0 0 0
40959 - 0 0 0 0 0 0 0 0 0 0 0 0
40960 - 0 0 0 0 0 0 0 0 0 0 0 0
40961 - 0 0 0 0 0 0 0 0 0 0 0 0
40962 - 0 0 0 0 0 0 0 0 0 0 0 0
40963 - 0 0 0 0 0 0 0 0 0 0 0 0
40964 - 0 0 1 0 0 1 0 0 1 0 0 0
40965 - 0 0 0 0 0 0 0 0 0 0 0 0
40966 - 0 0 0 0 0 0 0 0 0 0 0 0
40967 - 0 0 0 0 0 0 0 0 0 0 0 0
40968 - 0 0 0 0 0 0 0 0 0 0 0 0
40969 - 0 0 0 0 0 0 0 0 0 0 0 0
40970 - 14 14 14 42 42 42 86 86 86 10 10 10
40971 - 2 2 6 2 2 6 2 2 6 2 2 6
40972 - 2 2 6 2 2 6 2 2 6 2 2 6
40973 - 2 2 6 2 2 6 2 2 6 30 30 30
40974 - 94 94 94 94 94 94 58 58 58 26 26 26
40975 - 2 2 6 6 6 6 78 78 78 54 54 54
40976 - 22 22 22 6 6 6 0 0 0 0 0 0
40977 - 0 0 0 0 0 0 0 0 0 0 0 0
40978 - 0 0 0 0 0 0 0 0 0 0 0 0
40979 - 0 0 0 0 0 0 0 0 0 0 0 0
40980 - 0 0 0 0 0 0 0 0 0 0 0 0
40981 - 0 0 0 0 0 0 0 0 0 0 0 0
40982 - 0 0 0 0 0 0 0 0 0 0 0 0
40983 - 0 0 0 0 0 0 0 0 0 0 0 0
40984 - 0 0 0 0 0 0 0 0 0 0 0 0
40985 - 0 0 0 0 0 0 0 0 0 0 0 0
40986 - 0 0 0 0 0 0 0 0 0 0 0 0
40987 - 0 0 0 0 0 0 0 0 0 0 0 0
40988 - 0 0 0 0 0 0 0 0 0 0 0 0
40989 - 0 0 0 0 0 0 0 0 0 6 6 6
40990 - 22 22 22 62 62 62 62 62 62 2 2 6
40991 - 2 2 6 2 2 6 2 2 6 2 2 6
40992 - 2 2 6 2 2 6 2 2 6 2 2 6
40993 - 2 2 6 2 2 6 2 2 6 26 26 26
40994 - 54 54 54 38 38 38 18 18 18 10 10 10
40995 - 2 2 6 2 2 6 34 34 34 82 82 82
40996 - 38 38 38 14 14 14 0 0 0 0 0 0
40997 - 0 0 0 0 0 0 0 0 0 0 0 0
40998 - 0 0 0 0 0 0 0 0 0 0 0 0
40999 - 0 0 0 0 0 0 0 0 0 0 0 0
41000 - 0 0 0 0 0 0 0 0 0 0 0 0
41001 - 0 0 0 0 0 0 0 0 0 0 0 0
41002 - 0 0 0 0 0 0 0 0 0 0 0 0
41003 - 0 0 0 0 0 0 0 0 0 0 0 0
41004 - 0 0 0 0 0 1 0 0 1 0 0 0
41005 - 0 0 0 0 0 0 0 0 0 0 0 0
41006 - 0 0 0 0 0 0 0 0 0 0 0 0
41007 - 0 0 0 0 0 0 0 0 0 0 0 0
41008 - 0 0 0 0 0 0 0 0 0 0 0 0
41009 - 0 0 0 0 0 0 0 0 0 6 6 6
41010 - 30 30 30 78 78 78 30 30 30 2 2 6
41011 - 2 2 6 2 2 6 2 2 6 2 2 6
41012 - 2 2 6 2 2 6 2 2 6 2 2 6
41013 - 2 2 6 2 2 6 2 2 6 10 10 10
41014 - 10 10 10 2 2 6 2 2 6 2 2 6
41015 - 2 2 6 2 2 6 2 2 6 78 78 78
41016 - 50 50 50 18 18 18 6 6 6 0 0 0
41017 - 0 0 0 0 0 0 0 0 0 0 0 0
41018 - 0 0 0 0 0 0 0 0 0 0 0 0
41019 - 0 0 0 0 0 0 0 0 0 0 0 0
41020 - 0 0 0 0 0 0 0 0 0 0 0 0
41021 - 0 0 0 0 0 0 0 0 0 0 0 0
41022 - 0 0 0 0 0 0 0 0 0 0 0 0
41023 - 0 0 0 0 0 0 0 0 0 0 0 0
41024 - 0 0 1 0 0 0 0 0 0 0 0 0
41025 - 0 0 0 0 0 0 0 0 0 0 0 0
41026 - 0 0 0 0 0 0 0 0 0 0 0 0
41027 - 0 0 0 0 0 0 0 0 0 0 0 0
41028 - 0 0 0 0 0 0 0 0 0 0 0 0
41029 - 0 0 0 0 0 0 0 0 0 10 10 10
41030 - 38 38 38 86 86 86 14 14 14 2 2 6
41031 - 2 2 6 2 2 6 2 2 6 2 2 6
41032 - 2 2 6 2 2 6 2 2 6 2 2 6
41033 - 2 2 6 2 2 6 2 2 6 2 2 6
41034 - 2 2 6 2 2 6 2 2 6 2 2 6
41035 - 2 2 6 2 2 6 2 2 6 54 54 54
41036 - 66 66 66 26 26 26 6 6 6 0 0 0
41037 - 0 0 0 0 0 0 0 0 0 0 0 0
41038 - 0 0 0 0 0 0 0 0 0 0 0 0
41039 - 0 0 0 0 0 0 0 0 0 0 0 0
41040 - 0 0 0 0 0 0 0 0 0 0 0 0
41041 - 0 0 0 0 0 0 0 0 0 0 0 0
41042 - 0 0 0 0 0 0 0 0 0 0 0 0
41043 - 0 0 0 0 0 0 0 0 0 0 0 0
41044 - 0 0 0 0 0 1 0 0 1 0 0 0
41045 - 0 0 0 0 0 0 0 0 0 0 0 0
41046 - 0 0 0 0 0 0 0 0 0 0 0 0
41047 - 0 0 0 0 0 0 0 0 0 0 0 0
41048 - 0 0 0 0 0 0 0 0 0 0 0 0
41049 - 0 0 0 0 0 0 0 0 0 14 14 14
41050 - 42 42 42 82 82 82 2 2 6 2 2 6
41051 - 2 2 6 6 6 6 10 10 10 2 2 6
41052 - 2 2 6 2 2 6 2 2 6 2 2 6
41053 - 2 2 6 2 2 6 2 2 6 6 6 6
41054 - 14 14 14 10 10 10 2 2 6 2 2 6
41055 - 2 2 6 2 2 6 2 2 6 18 18 18
41056 - 82 82 82 34 34 34 10 10 10 0 0 0
41057 - 0 0 0 0 0 0 0 0 0 0 0 0
41058 - 0 0 0 0 0 0 0 0 0 0 0 0
41059 - 0 0 0 0 0 0 0 0 0 0 0 0
41060 - 0 0 0 0 0 0 0 0 0 0 0 0
41061 - 0 0 0 0 0 0 0 0 0 0 0 0
41062 - 0 0 0 0 0 0 0 0 0 0 0 0
41063 - 0 0 0 0 0 0 0 0 0 0 0 0
41064 - 0 0 1 0 0 0 0 0 0 0 0 0
41065 - 0 0 0 0 0 0 0 0 0 0 0 0
41066 - 0 0 0 0 0 0 0 0 0 0 0 0
41067 - 0 0 0 0 0 0 0 0 0 0 0 0
41068 - 0 0 0 0 0 0 0 0 0 0 0 0
41069 - 0 0 0 0 0 0 0 0 0 14 14 14
41070 - 46 46 46 86 86 86 2 2 6 2 2 6
41071 - 6 6 6 6 6 6 22 22 22 34 34 34
41072 - 6 6 6 2 2 6 2 2 6 2 2 6
41073 - 2 2 6 2 2 6 18 18 18 34 34 34
41074 - 10 10 10 50 50 50 22 22 22 2 2 6
41075 - 2 2 6 2 2 6 2 2 6 10 10 10
41076 - 86 86 86 42 42 42 14 14 14 0 0 0
41077 - 0 0 0 0 0 0 0 0 0 0 0 0
41078 - 0 0 0 0 0 0 0 0 0 0 0 0
41079 - 0 0 0 0 0 0 0 0 0 0 0 0
41080 - 0 0 0 0 0 0 0 0 0 0 0 0
41081 - 0 0 0 0 0 0 0 0 0 0 0 0
41082 - 0 0 0 0 0 0 0 0 0 0 0 0
41083 - 0 0 0 0 0 0 0 0 0 0 0 0
41084 - 0 0 1 0 0 1 0 0 1 0 0 0
41085 - 0 0 0 0 0 0 0 0 0 0 0 0
41086 - 0 0 0 0 0 0 0 0 0 0 0 0
41087 - 0 0 0 0 0 0 0 0 0 0 0 0
41088 - 0 0 0 0 0 0 0 0 0 0 0 0
41089 - 0 0 0 0 0 0 0 0 0 14 14 14
41090 - 46 46 46 86 86 86 2 2 6 2 2 6
41091 - 38 38 38 116 116 116 94 94 94 22 22 22
41092 - 22 22 22 2 2 6 2 2 6 2 2 6
41093 - 14 14 14 86 86 86 138 138 138 162 162 162
41094 -154 154 154 38 38 38 26 26 26 6 6 6
41095 - 2 2 6 2 2 6 2 2 6 2 2 6
41096 - 86 86 86 46 46 46 14 14 14 0 0 0
41097 - 0 0 0 0 0 0 0 0 0 0 0 0
41098 - 0 0 0 0 0 0 0 0 0 0 0 0
41099 - 0 0 0 0 0 0 0 0 0 0 0 0
41100 - 0 0 0 0 0 0 0 0 0 0 0 0
41101 - 0 0 0 0 0 0 0 0 0 0 0 0
41102 - 0 0 0 0 0 0 0 0 0 0 0 0
41103 - 0 0 0 0 0 0 0 0 0 0 0 0
41104 - 0 0 0 0 0 0 0 0 0 0 0 0
41105 - 0 0 0 0 0 0 0 0 0 0 0 0
41106 - 0 0 0 0 0 0 0 0 0 0 0 0
41107 - 0 0 0 0 0 0 0 0 0 0 0 0
41108 - 0 0 0 0 0 0 0 0 0 0 0 0
41109 - 0 0 0 0 0 0 0 0 0 14 14 14
41110 - 46 46 46 86 86 86 2 2 6 14 14 14
41111 -134 134 134 198 198 198 195 195 195 116 116 116
41112 - 10 10 10 2 2 6 2 2 6 6 6 6
41113 -101 98 89 187 187 187 210 210 210 218 218 218
41114 -214 214 214 134 134 134 14 14 14 6 6 6
41115 - 2 2 6 2 2 6 2 2 6 2 2 6
41116 - 86 86 86 50 50 50 18 18 18 6 6 6
41117 - 0 0 0 0 0 0 0 0 0 0 0 0
41118 - 0 0 0 0 0 0 0 0 0 0 0 0
41119 - 0 0 0 0 0 0 0 0 0 0 0 0
41120 - 0 0 0 0 0 0 0 0 0 0 0 0
41121 - 0 0 0 0 0 0 0 0 0 0 0 0
41122 - 0 0 0 0 0 0 0 0 0 0 0 0
41123 - 0 0 0 0 0 0 0 0 1 0 0 0
41124 - 0 0 1 0 0 1 0 0 1 0 0 0
41125 - 0 0 0 0 0 0 0 0 0 0 0 0
41126 - 0 0 0 0 0 0 0 0 0 0 0 0
41127 - 0 0 0 0 0 0 0 0 0 0 0 0
41128 - 0 0 0 0 0 0 0 0 0 0 0 0
41129 - 0 0 0 0 0 0 0 0 0 14 14 14
41130 - 46 46 46 86 86 86 2 2 6 54 54 54
41131 -218 218 218 195 195 195 226 226 226 246 246 246
41132 - 58 58 58 2 2 6 2 2 6 30 30 30
41133 -210 210 210 253 253 253 174 174 174 123 123 123
41134 -221 221 221 234 234 234 74 74 74 2 2 6
41135 - 2 2 6 2 2 6 2 2 6 2 2 6
41136 - 70 70 70 58 58 58 22 22 22 6 6 6
41137 - 0 0 0 0 0 0 0 0 0 0 0 0
41138 - 0 0 0 0 0 0 0 0 0 0 0 0
41139 - 0 0 0 0 0 0 0 0 0 0 0 0
41140 - 0 0 0 0 0 0 0 0 0 0 0 0
41141 - 0 0 0 0 0 0 0 0 0 0 0 0
41142 - 0 0 0 0 0 0 0 0 0 0 0 0
41143 - 0 0 0 0 0 0 0 0 0 0 0 0
41144 - 0 0 0 0 0 0 0 0 0 0 0 0
41145 - 0 0 0 0 0 0 0 0 0 0 0 0
41146 - 0 0 0 0 0 0 0 0 0 0 0 0
41147 - 0 0 0 0 0 0 0 0 0 0 0 0
41148 - 0 0 0 0 0 0 0 0 0 0 0 0
41149 - 0 0 0 0 0 0 0 0 0 14 14 14
41150 - 46 46 46 82 82 82 2 2 6 106 106 106
41151 -170 170 170 26 26 26 86 86 86 226 226 226
41152 -123 123 123 10 10 10 14 14 14 46 46 46
41153 -231 231 231 190 190 190 6 6 6 70 70 70
41154 - 90 90 90 238 238 238 158 158 158 2 2 6
41155 - 2 2 6 2 2 6 2 2 6 2 2 6
41156 - 70 70 70 58 58 58 22 22 22 6 6 6
41157 - 0 0 0 0 0 0 0 0 0 0 0 0
41158 - 0 0 0 0 0 0 0 0 0 0 0 0
41159 - 0 0 0 0 0 0 0 0 0 0 0 0
41160 - 0 0 0 0 0 0 0 0 0 0 0 0
41161 - 0 0 0 0 0 0 0 0 0 0 0 0
41162 - 0 0 0 0 0 0 0 0 0 0 0 0
41163 - 0 0 0 0 0 0 0 0 1 0 0 0
41164 - 0 0 1 0 0 1 0 0 1 0 0 0
41165 - 0 0 0 0 0 0 0 0 0 0 0 0
41166 - 0 0 0 0 0 0 0 0 0 0 0 0
41167 - 0 0 0 0 0 0 0 0 0 0 0 0
41168 - 0 0 0 0 0 0 0 0 0 0 0 0
41169 - 0 0 0 0 0 0 0 0 0 14 14 14
41170 - 42 42 42 86 86 86 6 6 6 116 116 116
41171 -106 106 106 6 6 6 70 70 70 149 149 149
41172 -128 128 128 18 18 18 38 38 38 54 54 54
41173 -221 221 221 106 106 106 2 2 6 14 14 14
41174 - 46 46 46 190 190 190 198 198 198 2 2 6
41175 - 2 2 6 2 2 6 2 2 6 2 2 6
41176 - 74 74 74 62 62 62 22 22 22 6 6 6
41177 - 0 0 0 0 0 0 0 0 0 0 0 0
41178 - 0 0 0 0 0 0 0 0 0 0 0 0
41179 - 0 0 0 0 0 0 0 0 0 0 0 0
41180 - 0 0 0 0 0 0 0 0 0 0 0 0
41181 - 0 0 0 0 0 0 0 0 0 0 0 0
41182 - 0 0 0 0 0 0 0 0 0 0 0 0
41183 - 0 0 0 0 0 0 0 0 1 0 0 0
41184 - 0 0 1 0 0 0 0 0 1 0 0 0
41185 - 0 0 0 0 0 0 0 0 0 0 0 0
41186 - 0 0 0 0 0 0 0 0 0 0 0 0
41187 - 0 0 0 0 0 0 0 0 0 0 0 0
41188 - 0 0 0 0 0 0 0 0 0 0 0 0
41189 - 0 0 0 0 0 0 0 0 0 14 14 14
41190 - 42 42 42 94 94 94 14 14 14 101 101 101
41191 -128 128 128 2 2 6 18 18 18 116 116 116
41192 -118 98 46 121 92 8 121 92 8 98 78 10
41193 -162 162 162 106 106 106 2 2 6 2 2 6
41194 - 2 2 6 195 195 195 195 195 195 6 6 6
41195 - 2 2 6 2 2 6 2 2 6 2 2 6
41196 - 74 74 74 62 62 62 22 22 22 6 6 6
41197 - 0 0 0 0 0 0 0 0 0 0 0 0
41198 - 0 0 0 0 0 0 0 0 0 0 0 0
41199 - 0 0 0 0 0 0 0 0 0 0 0 0
41200 - 0 0 0 0 0 0 0 0 0 0 0 0
41201 - 0 0 0 0 0 0 0 0 0 0 0 0
41202 - 0 0 0 0 0 0 0 0 0 0 0 0
41203 - 0 0 0 0 0 0 0 0 1 0 0 1
41204 - 0 0 1 0 0 0 0 0 1 0 0 0
41205 - 0 0 0 0 0 0 0 0 0 0 0 0
41206 - 0 0 0 0 0 0 0 0 0 0 0 0
41207 - 0 0 0 0 0 0 0 0 0 0 0 0
41208 - 0 0 0 0 0 0 0 0 0 0 0 0
41209 - 0 0 0 0 0 0 0 0 0 10 10 10
41210 - 38 38 38 90 90 90 14 14 14 58 58 58
41211 -210 210 210 26 26 26 54 38 6 154 114 10
41212 -226 170 11 236 186 11 225 175 15 184 144 12
41213 -215 174 15 175 146 61 37 26 9 2 2 6
41214 - 70 70 70 246 246 246 138 138 138 2 2 6
41215 - 2 2 6 2 2 6 2 2 6 2 2 6
41216 - 70 70 70 66 66 66 26 26 26 6 6 6
41217 - 0 0 0 0 0 0 0 0 0 0 0 0
41218 - 0 0 0 0 0 0 0 0 0 0 0 0
41219 - 0 0 0 0 0 0 0 0 0 0 0 0
41220 - 0 0 0 0 0 0 0 0 0 0 0 0
41221 - 0 0 0 0 0 0 0 0 0 0 0 0
41222 - 0 0 0 0 0 0 0 0 0 0 0 0
41223 - 0 0 0 0 0 0 0 0 0 0 0 0
41224 - 0 0 0 0 0 0 0 0 0 0 0 0
41225 - 0 0 0 0 0 0 0 0 0 0 0 0
41226 - 0 0 0 0 0 0 0 0 0 0 0 0
41227 - 0 0 0 0 0 0 0 0 0 0 0 0
41228 - 0 0 0 0 0 0 0 0 0 0 0 0
41229 - 0 0 0 0 0 0 0 0 0 10 10 10
41230 - 38 38 38 86 86 86 14 14 14 10 10 10
41231 -195 195 195 188 164 115 192 133 9 225 175 15
41232 -239 182 13 234 190 10 232 195 16 232 200 30
41233 -245 207 45 241 208 19 232 195 16 184 144 12
41234 -218 194 134 211 206 186 42 42 42 2 2 6
41235 - 2 2 6 2 2 6 2 2 6 2 2 6
41236 - 50 50 50 74 74 74 30 30 30 6 6 6
41237 - 0 0 0 0 0 0 0 0 0 0 0 0
41238 - 0 0 0 0 0 0 0 0 0 0 0 0
41239 - 0 0 0 0 0 0 0 0 0 0 0 0
41240 - 0 0 0 0 0 0 0 0 0 0 0 0
41241 - 0 0 0 0 0 0 0 0 0 0 0 0
41242 - 0 0 0 0 0 0 0 0 0 0 0 0
41243 - 0 0 0 0 0 0 0 0 0 0 0 0
41244 - 0 0 0 0 0 0 0 0 0 0 0 0
41245 - 0 0 0 0 0 0 0 0 0 0 0 0
41246 - 0 0 0 0 0 0 0 0 0 0 0 0
41247 - 0 0 0 0 0 0 0 0 0 0 0 0
41248 - 0 0 0 0 0 0 0 0 0 0 0 0
41249 - 0 0 0 0 0 0 0 0 0 10 10 10
41250 - 34 34 34 86 86 86 14 14 14 2 2 6
41251 -121 87 25 192 133 9 219 162 10 239 182 13
41252 -236 186 11 232 195 16 241 208 19 244 214 54
41253 -246 218 60 246 218 38 246 215 20 241 208 19
41254 -241 208 19 226 184 13 121 87 25 2 2 6
41255 - 2 2 6 2 2 6 2 2 6 2 2 6
41256 - 50 50 50 82 82 82 34 34 34 10 10 10
41257 - 0 0 0 0 0 0 0 0 0 0 0 0
41258 - 0 0 0 0 0 0 0 0 0 0 0 0
41259 - 0 0 0 0 0 0 0 0 0 0 0 0
41260 - 0 0 0 0 0 0 0 0 0 0 0 0
41261 - 0 0 0 0 0 0 0 0 0 0 0 0
41262 - 0 0 0 0 0 0 0 0 0 0 0 0
41263 - 0 0 0 0 0 0 0 0 0 0 0 0
41264 - 0 0 0 0 0 0 0 0 0 0 0 0
41265 - 0 0 0 0 0 0 0 0 0 0 0 0
41266 - 0 0 0 0 0 0 0 0 0 0 0 0
41267 - 0 0 0 0 0 0 0 0 0 0 0 0
41268 - 0 0 0 0 0 0 0 0 0 0 0 0
41269 - 0 0 0 0 0 0 0 0 0 10 10 10
41270 - 34 34 34 82 82 82 30 30 30 61 42 6
41271 -180 123 7 206 145 10 230 174 11 239 182 13
41272 -234 190 10 238 202 15 241 208 19 246 218 74
41273 -246 218 38 246 215 20 246 215 20 246 215 20
41274 -226 184 13 215 174 15 184 144 12 6 6 6
41275 - 2 2 6 2 2 6 2 2 6 2 2 6
41276 - 26 26 26 94 94 94 42 42 42 14 14 14
41277 - 0 0 0 0 0 0 0 0 0 0 0 0
41278 - 0 0 0 0 0 0 0 0 0 0 0 0
41279 - 0 0 0 0 0 0 0 0 0 0 0 0
41280 - 0 0 0 0 0 0 0 0 0 0 0 0
41281 - 0 0 0 0 0 0 0 0 0 0 0 0
41282 - 0 0 0 0 0 0 0 0 0 0 0 0
41283 - 0 0 0 0 0 0 0 0 0 0 0 0
41284 - 0 0 0 0 0 0 0 0 0 0 0 0
41285 - 0 0 0 0 0 0 0 0 0 0 0 0
41286 - 0 0 0 0 0 0 0 0 0 0 0 0
41287 - 0 0 0 0 0 0 0 0 0 0 0 0
41288 - 0 0 0 0 0 0 0 0 0 0 0 0
41289 - 0 0 0 0 0 0 0 0 0 10 10 10
41290 - 30 30 30 78 78 78 50 50 50 104 69 6
41291 -192 133 9 216 158 10 236 178 12 236 186 11
41292 -232 195 16 241 208 19 244 214 54 245 215 43
41293 -246 215 20 246 215 20 241 208 19 198 155 10
41294 -200 144 11 216 158 10 156 118 10 2 2 6
41295 - 2 2 6 2 2 6 2 2 6 2 2 6
41296 - 6 6 6 90 90 90 54 54 54 18 18 18
41297 - 6 6 6 0 0 0 0 0 0 0 0 0
41298 - 0 0 0 0 0 0 0 0 0 0 0 0
41299 - 0 0 0 0 0 0 0 0 0 0 0 0
41300 - 0 0 0 0 0 0 0 0 0 0 0 0
41301 - 0 0 0 0 0 0 0 0 0 0 0 0
41302 - 0 0 0 0 0 0 0 0 0 0 0 0
41303 - 0 0 0 0 0 0 0 0 0 0 0 0
41304 - 0 0 0 0 0 0 0 0 0 0 0 0
41305 - 0 0 0 0 0 0 0 0 0 0 0 0
41306 - 0 0 0 0 0 0 0 0 0 0 0 0
41307 - 0 0 0 0 0 0 0 0 0 0 0 0
41308 - 0 0 0 0 0 0 0 0 0 0 0 0
41309 - 0 0 0 0 0 0 0 0 0 10 10 10
41310 - 30 30 30 78 78 78 46 46 46 22 22 22
41311 -137 92 6 210 162 10 239 182 13 238 190 10
41312 -238 202 15 241 208 19 246 215 20 246 215 20
41313 -241 208 19 203 166 17 185 133 11 210 150 10
41314 -216 158 10 210 150 10 102 78 10 2 2 6
41315 - 6 6 6 54 54 54 14 14 14 2 2 6
41316 - 2 2 6 62 62 62 74 74 74 30 30 30
41317 - 10 10 10 0 0 0 0 0 0 0 0 0
41318 - 0 0 0 0 0 0 0 0 0 0 0 0
41319 - 0 0 0 0 0 0 0 0 0 0 0 0
41320 - 0 0 0 0 0 0 0 0 0 0 0 0
41321 - 0 0 0 0 0 0 0 0 0 0 0 0
41322 - 0 0 0 0 0 0 0 0 0 0 0 0
41323 - 0 0 0 0 0 0 0 0 0 0 0 0
41324 - 0 0 0 0 0 0 0 0 0 0 0 0
41325 - 0 0 0 0 0 0 0 0 0 0 0 0
41326 - 0 0 0 0 0 0 0 0 0 0 0 0
41327 - 0 0 0 0 0 0 0 0 0 0 0 0
41328 - 0 0 0 0 0 0 0 0 0 0 0 0
41329 - 0 0 0 0 0 0 0 0 0 10 10 10
41330 - 34 34 34 78 78 78 50 50 50 6 6 6
41331 - 94 70 30 139 102 15 190 146 13 226 184 13
41332 -232 200 30 232 195 16 215 174 15 190 146 13
41333 -168 122 10 192 133 9 210 150 10 213 154 11
41334 -202 150 34 182 157 106 101 98 89 2 2 6
41335 - 2 2 6 78 78 78 116 116 116 58 58 58
41336 - 2 2 6 22 22 22 90 90 90 46 46 46
41337 - 18 18 18 6 6 6 0 0 0 0 0 0
41338 - 0 0 0 0 0 0 0 0 0 0 0 0
41339 - 0 0 0 0 0 0 0 0 0 0 0 0
41340 - 0 0 0 0 0 0 0 0 0 0 0 0
41341 - 0 0 0 0 0 0 0 0 0 0 0 0
41342 - 0 0 0 0 0 0 0 0 0 0 0 0
41343 - 0 0 0 0 0 0 0 0 0 0 0 0
41344 - 0 0 0 0 0 0 0 0 0 0 0 0
41345 - 0 0 0 0 0 0 0 0 0 0 0 0
41346 - 0 0 0 0 0 0 0 0 0 0 0 0
41347 - 0 0 0 0 0 0 0 0 0 0 0 0
41348 - 0 0 0 0 0 0 0 0 0 0 0 0
41349 - 0 0 0 0 0 0 0 0 0 10 10 10
41350 - 38 38 38 86 86 86 50 50 50 6 6 6
41351 -128 128 128 174 154 114 156 107 11 168 122 10
41352 -198 155 10 184 144 12 197 138 11 200 144 11
41353 -206 145 10 206 145 10 197 138 11 188 164 115
41354 -195 195 195 198 198 198 174 174 174 14 14 14
41355 - 2 2 6 22 22 22 116 116 116 116 116 116
41356 - 22 22 22 2 2 6 74 74 74 70 70 70
41357 - 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41366 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
41370 - 50 50 50 101 101 101 26 26 26 10 10 10
41371 -138 138 138 190 190 190 174 154 114 156 107 11
41372 -197 138 11 200 144 11 197 138 11 192 133 9
41373 -180 123 7 190 142 34 190 178 144 187 187 187
41374 -202 202 202 221 221 221 214 214 214 66 66 66
41375 - 2 2 6 2 2 6 50 50 50 62 62 62
41376 - 6 6 6 2 2 6 10 10 10 90 90 90
41377 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
41385 - 0 0 0 0 0 0 0 0 0 0 0 0
41386 - 0 0 0 0 0 0 0 0 0 0 0 0
41387 - 0 0 0 0 0 0 0 0 0 0 0 0
41388 - 0 0 0 0 0 0 0 0 0 0 0 0
41389 - 0 0 0 0 0 0 10 10 10 34 34 34
41390 - 74 74 74 74 74 74 2 2 6 6 6 6
41391 -144 144 144 198 198 198 190 190 190 178 166 146
41392 -154 121 60 156 107 11 156 107 11 168 124 44
41393 -174 154 114 187 187 187 190 190 190 210 210 210
41394 -246 246 246 253 253 253 253 253 253 182 182 182
41395 - 6 6 6 2 2 6 2 2 6 2 2 6
41396 - 2 2 6 2 2 6 2 2 6 62 62 62
41397 - 74 74 74 34 34 34 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41405 - 0 0 0 0 0 0 0 0 0 0 0 0
41406 - 0 0 0 0 0 0 0 0 0 0 0 0
41407 - 0 0 0 0 0 0 0 0 0 0 0 0
41408 - 0 0 0 0 0 0 0 0 0 0 0 0
41409 - 0 0 0 10 10 10 22 22 22 54 54 54
41410 - 94 94 94 18 18 18 2 2 6 46 46 46
41411 -234 234 234 221 221 221 190 190 190 190 190 190
41412 -190 190 190 187 187 187 187 187 187 190 190 190
41413 -190 190 190 195 195 195 214 214 214 242 242 242
41414 -253 253 253 253 253 253 253 253 253 253 253 253
41415 - 82 82 82 2 2 6 2 2 6 2 2 6
41416 - 2 2 6 2 2 6 2 2 6 14 14 14
41417 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
41424 - 0 0 0 0 0 0 0 0 0 0 0 0
41425 - 0 0 0 0 0 0 0 0 0 0 0 0
41426 - 0 0 0 0 0 0 0 0 0 0 0 0
41427 - 0 0 0 0 0 0 0 0 0 0 0 0
41428 - 0 0 0 0 0 0 0 0 0 0 0 0
41429 - 6 6 6 18 18 18 46 46 46 90 90 90
41430 - 46 46 46 18 18 18 6 6 6 182 182 182
41431 -253 253 253 246 246 246 206 206 206 190 190 190
41432 -190 190 190 190 190 190 190 190 190 190 190 190
41433 -206 206 206 231 231 231 250 250 250 253 253 253
41434 -253 253 253 253 253 253 253 253 253 253 253 253
41435 -202 202 202 14 14 14 2 2 6 2 2 6
41436 - 2 2 6 2 2 6 2 2 6 2 2 6
41437 - 42 42 42 86 86 86 42 42 42 18 18 18
41438 - 6 6 6 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 0 0 0 0 0 0
41444 - 0 0 0 0 0 0 0 0 0 0 0 0
41445 - 0 0 0 0 0 0 0 0 0 0 0 0
41446 - 0 0 0 0 0 0 0 0 0 0 0 0
41447 - 0 0 0 0 0 0 0 0 0 0 0 0
41448 - 0 0 0 0 0 0 0 0 0 6 6 6
41449 - 14 14 14 38 38 38 74 74 74 66 66 66
41450 - 2 2 6 6 6 6 90 90 90 250 250 250
41451 -253 253 253 253 253 253 238 238 238 198 198 198
41452 -190 190 190 190 190 190 195 195 195 221 221 221
41453 -246 246 246 253 253 253 253 253 253 253 253 253
41454 -253 253 253 253 253 253 253 253 253 253 253 253
41455 -253 253 253 82 82 82 2 2 6 2 2 6
41456 - 2 2 6 2 2 6 2 2 6 2 2 6
41457 - 2 2 6 78 78 78 70 70 70 34 34 34
41458 - 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0
41464 - 0 0 0 0 0 0 0 0 0 0 0 0
41465 - 0 0 0 0 0 0 0 0 0 0 0 0
41466 - 0 0 0 0 0 0 0 0 0 0 0 0
41467 - 0 0 0 0 0 0 0 0 0 0 0 0
41468 - 0 0 0 0 0 0 0 0 0 14 14 14
41469 - 34 34 34 66 66 66 78 78 78 6 6 6
41470 - 2 2 6 18 18 18 218 218 218 253 253 253
41471 -253 253 253 253 253 253 253 253 253 246 246 246
41472 -226 226 226 231 231 231 246 246 246 253 253 253
41473 -253 253 253 253 253 253 253 253 253 253 253 253
41474 -253 253 253 253 253 253 253 253 253 253 253 253
41475 -253 253 253 178 178 178 2 2 6 2 2 6
41476 - 2 2 6 2 2 6 2 2 6 2 2 6
41477 - 2 2 6 18 18 18 90 90 90 62 62 62
41478 - 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41484 - 0 0 0 0 0 0 0 0 0 0 0 0
41485 - 0 0 0 0 0 0 0 0 0 0 0 0
41486 - 0 0 0 0 0 0 0 0 0 0 0 0
41487 - 0 0 0 0 0 0 0 0 0 0 0 0
41488 - 0 0 0 0 0 0 10 10 10 26 26 26
41489 - 58 58 58 90 90 90 18 18 18 2 2 6
41490 - 2 2 6 110 110 110 253 253 253 253 253 253
41491 -253 253 253 253 253 253 253 253 253 253 253 253
41492 -250 250 250 253 253 253 253 253 253 253 253 253
41493 -253 253 253 253 253 253 253 253 253 253 253 253
41494 -253 253 253 253 253 253 253 253 253 253 253 253
41495 -253 253 253 231 231 231 18 18 18 2 2 6
41496 - 2 2 6 2 2 6 2 2 6 2 2 6
41497 - 2 2 6 2 2 6 18 18 18 94 94 94
41498 - 54 54 54 26 26 26 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41504 - 0 0 0 0 0 0 0 0 0 0 0 0
41505 - 0 0 0 0 0 0 0 0 0 0 0 0
41506 - 0 0 0 0 0 0 0 0 0 0 0 0
41507 - 0 0 0 0 0 0 0 0 0 0 0 0
41508 - 0 0 0 6 6 6 22 22 22 50 50 50
41509 - 90 90 90 26 26 26 2 2 6 2 2 6
41510 - 14 14 14 195 195 195 250 250 250 253 253 253
41511 -253 253 253 253 253 253 253 253 253 253 253 253
41512 -253 253 253 253 253 253 253 253 253 253 253 253
41513 -253 253 253 253 253 253 253 253 253 253 253 253
41514 -253 253 253 253 253 253 253 253 253 253 253 253
41515 -250 250 250 242 242 242 54 54 54 2 2 6
41516 - 2 2 6 2 2 6 2 2 6 2 2 6
41517 - 2 2 6 2 2 6 2 2 6 38 38 38
41518 - 86 86 86 50 50 50 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
41524 - 0 0 0 0 0 0 0 0 0 0 0 0
41525 - 0 0 0 0 0 0 0 0 0 0 0 0
41526 - 0 0 0 0 0 0 0 0 0 0 0 0
41527 - 0 0 0 0 0 0 0 0 0 0 0 0
41528 - 6 6 6 14 14 14 38 38 38 82 82 82
41529 - 34 34 34 2 2 6 2 2 6 2 2 6
41530 - 42 42 42 195 195 195 246 246 246 253 253 253
41531 -253 253 253 253 253 253 253 253 253 250 250 250
41532 -242 242 242 242 242 242 250 250 250 253 253 253
41533 -253 253 253 253 253 253 253 253 253 253 253 253
41534 -253 253 253 250 250 250 246 246 246 238 238 238
41535 -226 226 226 231 231 231 101 101 101 6 6 6
41536 - 2 2 6 2 2 6 2 2 6 2 2 6
41537 - 2 2 6 2 2 6 2 2 6 2 2 6
41538 - 38 38 38 82 82 82 42 42 42 14 14 14
41539 - 6 6 6 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 0 0 0
41543 - 0 0 0 0 0 0 0 0 0 0 0 0
41544 - 0 0 0 0 0 0 0 0 0 0 0 0
41545 - 0 0 0 0 0 0 0 0 0 0 0 0
41546 - 0 0 0 0 0 0 0 0 0 0 0 0
41547 - 0 0 0 0 0 0 0 0 0 0 0 0
41548 - 10 10 10 26 26 26 62 62 62 66 66 66
41549 - 2 2 6 2 2 6 2 2 6 6 6 6
41550 - 70 70 70 170 170 170 206 206 206 234 234 234
41551 -246 246 246 250 250 250 250 250 250 238 238 238
41552 -226 226 226 231 231 231 238 238 238 250 250 250
41553 -250 250 250 250 250 250 246 246 246 231 231 231
41554 -214 214 214 206 206 206 202 202 202 202 202 202
41555 -198 198 198 202 202 202 182 182 182 18 18 18
41556 - 2 2 6 2 2 6 2 2 6 2 2 6
41557 - 2 2 6 2 2 6 2 2 6 2 2 6
41558 - 2 2 6 62 62 62 66 66 66 30 30 30
41559 - 10 10 10 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 0 0 0
41563 - 0 0 0 0 0 0 0 0 0 0 0 0
41564 - 0 0 0 0 0 0 0 0 0 0 0 0
41565 - 0 0 0 0 0 0 0 0 0 0 0 0
41566 - 0 0 0 0 0 0 0 0 0 0 0 0
41567 - 0 0 0 0 0 0 0 0 0 0 0 0
41568 - 14 14 14 42 42 42 82 82 82 18 18 18
41569 - 2 2 6 2 2 6 2 2 6 10 10 10
41570 - 94 94 94 182 182 182 218 218 218 242 242 242
41571 -250 250 250 253 253 253 253 253 253 250 250 250
41572 -234 234 234 253 253 253 253 253 253 253 253 253
41573 -253 253 253 253 253 253 253 253 253 246 246 246
41574 -238 238 238 226 226 226 210 210 210 202 202 202
41575 -195 195 195 195 195 195 210 210 210 158 158 158
41576 - 6 6 6 14 14 14 50 50 50 14 14 14
41577 - 2 2 6 2 2 6 2 2 6 2 2 6
41578 - 2 2 6 6 6 6 86 86 86 46 46 46
41579 - 18 18 18 6 6 6 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 0 0 0
41583 - 0 0 0 0 0 0 0 0 0 0 0 0
41584 - 0 0 0 0 0 0 0 0 0 0 0 0
41585 - 0 0 0 0 0 0 0 0 0 0 0 0
41586 - 0 0 0 0 0 0 0 0 0 0 0 0
41587 - 0 0 0 0 0 0 0 0 0 6 6 6
41588 - 22 22 22 54 54 54 70 70 70 2 2 6
41589 - 2 2 6 10 10 10 2 2 6 22 22 22
41590 -166 166 166 231 231 231 250 250 250 253 253 253
41591 -253 253 253 253 253 253 253 253 253 250 250 250
41592 -242 242 242 253 253 253 253 253 253 253 253 253
41593 -253 253 253 253 253 253 253 253 253 253 253 253
41594 -253 253 253 253 253 253 253 253 253 246 246 246
41595 -231 231 231 206 206 206 198 198 198 226 226 226
41596 - 94 94 94 2 2 6 6 6 6 38 38 38
41597 - 30 30 30 2 2 6 2 2 6 2 2 6
41598 - 2 2 6 2 2 6 62 62 62 66 66 66
41599 - 26 26 26 10 10 10 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 0 0 0
41603 - 0 0 0 0 0 0 0 0 0 0 0 0
41604 - 0 0 0 0 0 0 0 0 0 0 0 0
41605 - 0 0 0 0 0 0 0 0 0 0 0 0
41606 - 0 0 0 0 0 0 0 0 0 0 0 0
41607 - 0 0 0 0 0 0 0 0 0 10 10 10
41608 - 30 30 30 74 74 74 50 50 50 2 2 6
41609 - 26 26 26 26 26 26 2 2 6 106 106 106
41610 -238 238 238 253 253 253 253 253 253 253 253 253
41611 -253 253 253 253 253 253 253 253 253 253 253 253
41612 -253 253 253 253 253 253 253 253 253 253 253 253
41613 -253 253 253 253 253 253 253 253 253 253 253 253
41614 -253 253 253 253 253 253 253 253 253 253 253 253
41615 -253 253 253 246 246 246 218 218 218 202 202 202
41616 -210 210 210 14 14 14 2 2 6 2 2 6
41617 - 30 30 30 22 22 22 2 2 6 2 2 6
41618 - 2 2 6 2 2 6 18 18 18 86 86 86
41619 - 42 42 42 14 14 14 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 0 0 0
41623 - 0 0 0 0 0 0 0 0 0 0 0 0
41624 - 0 0 0 0 0 0 0 0 0 0 0 0
41625 - 0 0 0 0 0 0 0 0 0 0 0 0
41626 - 0 0 0 0 0 0 0 0 0 0 0 0
41627 - 0 0 0 0 0 0 0 0 0 14 14 14
41628 - 42 42 42 90 90 90 22 22 22 2 2 6
41629 - 42 42 42 2 2 6 18 18 18 218 218 218
41630 -253 253 253 253 253 253 253 253 253 253 253 253
41631 -253 253 253 253 253 253 253 253 253 253 253 253
41632 -253 253 253 253 253 253 253 253 253 253 253 253
41633 -253 253 253 253 253 253 253 253 253 253 253 253
41634 -253 253 253 253 253 253 253 253 253 253 253 253
41635 -253 253 253 253 253 253 250 250 250 221 221 221
41636 -218 218 218 101 101 101 2 2 6 14 14 14
41637 - 18 18 18 38 38 38 10 10 10 2 2 6
41638 - 2 2 6 2 2 6 2 2 6 78 78 78
41639 - 58 58 58 22 22 22 6 6 6 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 0 0 0
41643 - 0 0 0 0 0 0 0 0 0 0 0 0
41644 - 0 0 0 0 0 0 0 0 0 0 0 0
41645 - 0 0 0 0 0 0 0 0 0 0 0 0
41646 - 0 0 0 0 0 0 0 0 0 0 0 0
41647 - 0 0 0 0 0 0 6 6 6 18 18 18
41648 - 54 54 54 82 82 82 2 2 6 26 26 26
41649 - 22 22 22 2 2 6 123 123 123 253 253 253
41650 -253 253 253 253 253 253 253 253 253 253 253 253
41651 -253 253 253 253 253 253 253 253 253 253 253 253
41652 -253 253 253 253 253 253 253 253 253 253 253 253
41653 -253 253 253 253 253 253 253 253 253 253 253 253
41654 -253 253 253 253 253 253 253 253 253 253 253 253
41655 -253 253 253 253 253 253 253 253 253 250 250 250
41656 -238 238 238 198 198 198 6 6 6 38 38 38
41657 - 58 58 58 26 26 26 38 38 38 2 2 6
41658 - 2 2 6 2 2 6 2 2 6 46 46 46
41659 - 78 78 78 30 30 30 10 10 10 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 0 0 0
41663 - 0 0 0 0 0 0 0 0 0 0 0 0
41664 - 0 0 0 0 0 0 0 0 0 0 0 0
41665 - 0 0 0 0 0 0 0 0 0 0 0 0
41666 - 0 0 0 0 0 0 0 0 0 0 0 0
41667 - 0 0 0 0 0 0 10 10 10 30 30 30
41668 - 74 74 74 58 58 58 2 2 6 42 42 42
41669 - 2 2 6 22 22 22 231 231 231 253 253 253
41670 -253 253 253 253 253 253 253 253 253 253 253 253
41671 -253 253 253 253 253 253 253 253 253 250 250 250
41672 -253 253 253 253 253 253 253 253 253 253 253 253
41673 -253 253 253 253 253 253 253 253 253 253 253 253
41674 -253 253 253 253 253 253 253 253 253 253 253 253
41675 -253 253 253 253 253 253 253 253 253 253 253 253
41676 -253 253 253 246 246 246 46 46 46 38 38 38
41677 - 42 42 42 14 14 14 38 38 38 14 14 14
41678 - 2 2 6 2 2 6 2 2 6 6 6 6
41679 - 86 86 86 46 46 46 14 14 14 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 0 0 0
41683 - 0 0 0 0 0 0 0 0 0 0 0 0
41684 - 0 0 0 0 0 0 0 0 0 0 0 0
41685 - 0 0 0 0 0 0 0 0 0 0 0 0
41686 - 0 0 0 0 0 0 0 0 0 0 0 0
41687 - 0 0 0 6 6 6 14 14 14 42 42 42
41688 - 90 90 90 18 18 18 18 18 18 26 26 26
41689 - 2 2 6 116 116 116 253 253 253 253 253 253
41690 -253 253 253 253 253 253 253 253 253 253 253 253
41691 -253 253 253 253 253 253 250 250 250 238 238 238
41692 -253 253 253 253 253 253 253 253 253 253 253 253
41693 -253 253 253 253 253 253 253 253 253 253 253 253
41694 -253 253 253 253 253 253 253 253 253 253 253 253
41695 -253 253 253 253 253 253 253 253 253 253 253 253
41696 -253 253 253 253 253 253 94 94 94 6 6 6
41697 - 2 2 6 2 2 6 10 10 10 34 34 34
41698 - 2 2 6 2 2 6 2 2 6 2 2 6
41699 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0
41703 - 0 0 0 0 0 0 0 0 0 0 0 0
41704 - 0 0 0 0 0 0 0 0 0 0 0 0
41705 - 0 0 0 0 0 0 0 0 0 0 0 0
41706 - 0 0 0 0 0 0 0 0 0 0 0 0
41707 - 0 0 0 10 10 10 26 26 26 66 66 66
41708 - 82 82 82 2 2 6 38 38 38 6 6 6
41709 - 14 14 14 210 210 210 253 253 253 253 253 253
41710 -253 253 253 253 253 253 253 253 253 253 253 253
41711 -253 253 253 253 253 253 246 246 246 242 242 242
41712 -253 253 253 253 253 253 253 253 253 253 253 253
41713 -253 253 253 253 253 253 253 253 253 253 253 253
41714 -253 253 253 253 253 253 253 253 253 253 253 253
41715 -253 253 253 253 253 253 253 253 253 253 253 253
41716 -253 253 253 253 253 253 144 144 144 2 2 6
41717 - 2 2 6 2 2 6 2 2 6 46 46 46
41718 - 2 2 6 2 2 6 2 2 6 2 2 6
41719 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
41723 - 0 0 0 0 0 0 0 0 0 0 0 0
41724 - 0 0 0 0 0 0 0 0 0 0 0 0
41725 - 0 0 0 0 0 0 0 0 0 0 0 0
41726 - 0 0 0 0 0 0 0 0 0 0 0 0
41727 - 6 6 6 14 14 14 42 42 42 90 90 90
41728 - 26 26 26 6 6 6 42 42 42 2 2 6
41729 - 74 74 74 250 250 250 253 253 253 253 253 253
41730 -253 253 253 253 253 253 253 253 253 253 253 253
41731 -253 253 253 253 253 253 242 242 242 242 242 242
41732 -253 253 253 253 253 253 253 253 253 253 253 253
41733 -253 253 253 253 253 253 253 253 253 253 253 253
41734 -253 253 253 253 253 253 253 253 253 253 253 253
41735 -253 253 253 253 253 253 253 253 253 253 253 253
41736 -253 253 253 253 253 253 182 182 182 2 2 6
41737 - 2 2 6 2 2 6 2 2 6 46 46 46
41738 - 2 2 6 2 2 6 2 2 6 2 2 6
41739 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0
41743 - 0 0 0 0 0 0 0 0 0 0 0 0
41744 - 0 0 0 0 0 0 0 0 0 0 0 0
41745 - 0 0 0 0 0 0 0 0 0 0 0 0
41746 - 0 0 0 0 0 0 0 0 0 0 0 0
41747 - 10 10 10 26 26 26 66 66 66 82 82 82
41748 - 2 2 6 22 22 22 18 18 18 2 2 6
41749 -149 149 149 253 253 253 253 253 253 253 253 253
41750 -253 253 253 253 253 253 253 253 253 253 253 253
41751 -253 253 253 253 253 253 234 234 234 242 242 242
41752 -253 253 253 253 253 253 253 253 253 253 253 253
41753 -253 253 253 253 253 253 253 253 253 253 253 253
41754 -253 253 253 253 253 253 253 253 253 253 253 253
41755 -253 253 253 253 253 253 253 253 253 253 253 253
41756 -253 253 253 253 253 253 206 206 206 2 2 6
41757 - 2 2 6 2 2 6 2 2 6 38 38 38
41758 - 2 2 6 2 2 6 2 2 6 2 2 6
41759 - 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0
41763 - 0 0 0 0 0 0 0 0 0 0 0 0
41764 - 0 0 0 0 0 0 0 0 0 0 0 0
41765 - 0 0 0 0 0 0 0 0 0 0 0 0
41766 - 0 0 0 0 0 0 0 0 0 6 6 6
41767 - 18 18 18 46 46 46 86 86 86 18 18 18
41768 - 2 2 6 34 34 34 10 10 10 6 6 6
41769 -210 210 210 253 253 253 253 253 253 253 253 253
41770 -253 253 253 253 253 253 253 253 253 253 253 253
41771 -253 253 253 253 253 253 234 234 234 242 242 242
41772 -253 253 253 253 253 253 253 253 253 253 253 253
41773 -253 253 253 253 253 253 253 253 253 253 253 253
41774 -253 253 253 253 253 253 253 253 253 253 253 253
41775 -253 253 253 253 253 253 253 253 253 253 253 253
41776 -253 253 253 253 253 253 221 221 221 6 6 6
41777 - 2 2 6 2 2 6 6 6 6 30 30 30
41778 - 2 2 6 2 2 6 2 2 6 2 2 6
41779 - 2 2 6 82 82 82 54 54 54 18 18 18
41780 - 6 6 6 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 0 0 0
41783 - 0 0 0 0 0 0 0 0 0 0 0 0
41784 - 0 0 0 0 0 0 0 0 0 0 0 0
41785 - 0 0 0 0 0 0 0 0 0 0 0 0
41786 - 0 0 0 0 0 0 0 0 0 10 10 10
41787 - 26 26 26 66 66 66 62 62 62 2 2 6
41788 - 2 2 6 38 38 38 10 10 10 26 26 26
41789 -238 238 238 253 253 253 253 253 253 253 253 253
41790 -253 253 253 253 253 253 253 253 253 253 253 253
41791 -253 253 253 253 253 253 231 231 231 238 238 238
41792 -253 253 253 253 253 253 253 253 253 253 253 253
41793 -253 253 253 253 253 253 253 253 253 253 253 253
41794 -253 253 253 253 253 253 253 253 253 253 253 253
41795 -253 253 253 253 253 253 253 253 253 253 253 253
41796 -253 253 253 253 253 253 231 231 231 6 6 6
41797 - 2 2 6 2 2 6 10 10 10 30 30 30
41798 - 2 2 6 2 2 6 2 2 6 2 2 6
41799 - 2 2 6 66 66 66 58 58 58 22 22 22
41800 - 6 6 6 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 0 0 0
41803 - 0 0 0 0 0 0 0 0 0 0 0 0
41804 - 0 0 0 0 0 0 0 0 0 0 0 0
41805 - 0 0 0 0 0 0 0 0 0 0 0 0
41806 - 0 0 0 0 0 0 0 0 0 10 10 10
41807 - 38 38 38 78 78 78 6 6 6 2 2 6
41808 - 2 2 6 46 46 46 14 14 14 42 42 42
41809 -246 246 246 253 253 253 253 253 253 253 253 253
41810 -253 253 253 253 253 253 253 253 253 253 253 253
41811 -253 253 253 253 253 253 231 231 231 242 242 242
41812 -253 253 253 253 253 253 253 253 253 253 253 253
41813 -253 253 253 253 253 253 253 253 253 253 253 253
41814 -253 253 253 253 253 253 253 253 253 253 253 253
41815 -253 253 253 253 253 253 253 253 253 253 253 253
41816 -253 253 253 253 253 253 234 234 234 10 10 10
41817 - 2 2 6 2 2 6 22 22 22 14 14 14
41818 - 2 2 6 2 2 6 2 2 6 2 2 6
41819 - 2 2 6 66 66 66 62 62 62 22 22 22
41820 - 6 6 6 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 0 0 0
41823 - 0 0 0 0 0 0 0 0 0 0 0 0
41824 - 0 0 0 0 0 0 0 0 0 0 0 0
41825 - 0 0 0 0 0 0 0 0 0 0 0 0
41826 - 0 0 0 0 0 0 6 6 6 18 18 18
41827 - 50 50 50 74 74 74 2 2 6 2 2 6
41828 - 14 14 14 70 70 70 34 34 34 62 62 62
41829 -250 250 250 253 253 253 253 253 253 253 253 253
41830 -253 253 253 253 253 253 253 253 253 253 253 253
41831 -253 253 253 253 253 253 231 231 231 246 246 246
41832 -253 253 253 253 253 253 253 253 253 253 253 253
41833 -253 253 253 253 253 253 253 253 253 253 253 253
41834 -253 253 253 253 253 253 253 253 253 253 253 253
41835 -253 253 253 253 253 253 253 253 253 253 253 253
41836 -253 253 253 253 253 253 234 234 234 14 14 14
41837 - 2 2 6 2 2 6 30 30 30 2 2 6
41838 - 2 2 6 2 2 6 2 2 6 2 2 6
41839 - 2 2 6 66 66 66 62 62 62 22 22 22
41840 - 6 6 6 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 0 0 0
41843 - 0 0 0 0 0 0 0 0 0 0 0 0
41844 - 0 0 0 0 0 0 0 0 0 0 0 0
41845 - 0 0 0 0 0 0 0 0 0 0 0 0
41846 - 0 0 0 0 0 0 6 6 6 18 18 18
41847 - 54 54 54 62 62 62 2 2 6 2 2 6
41848 - 2 2 6 30 30 30 46 46 46 70 70 70
41849 -250 250 250 253 253 253 253 253 253 253 253 253
41850 -253 253 253 253 253 253 253 253 253 253 253 253
41851 -253 253 253 253 253 253 231 231 231 246 246 246
41852 -253 253 253 253 253 253 253 253 253 253 253 253
41853 -253 253 253 253 253 253 253 253 253 253 253 253
41854 -253 253 253 253 253 253 253 253 253 253 253 253
41855 -253 253 253 253 253 253 253 253 253 253 253 253
41856 -253 253 253 253 253 253 226 226 226 10 10 10
41857 - 2 2 6 6 6 6 30 30 30 2 2 6
41858 - 2 2 6 2 2 6 2 2 6 2 2 6
41859 - 2 2 6 66 66 66 58 58 58 22 22 22
41860 - 6 6 6 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 0 0 0
41863 - 0 0 0 0 0 0 0 0 0 0 0 0
41864 - 0 0 0 0 0 0 0 0 0 0 0 0
41865 - 0 0 0 0 0 0 0 0 0 0 0 0
41866 - 0 0 0 0 0 0 6 6 6 22 22 22
41867 - 58 58 58 62 62 62 2 2 6 2 2 6
41868 - 2 2 6 2 2 6 30 30 30 78 78 78
41869 -250 250 250 253 253 253 253 253 253 253 253 253
41870 -253 253 253 253 253 253 253 253 253 253 253 253
41871 -253 253 253 253 253 253 231 231 231 246 246 246
41872 -253 253 253 253 253 253 253 253 253 253 253 253
41873 -253 253 253 253 253 253 253 253 253 253 253 253
41874 -253 253 253 253 253 253 253 253 253 253 253 253
41875 -253 253 253 253 253 253 253 253 253 253 253 253
41876 -253 253 253 253 253 253 206 206 206 2 2 6
41877 - 22 22 22 34 34 34 18 14 6 22 22 22
41878 - 26 26 26 18 18 18 6 6 6 2 2 6
41879 - 2 2 6 82 82 82 54 54 54 18 18 18
41880 - 6 6 6 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 0 0 0
41883 - 0 0 0 0 0 0 0 0 0 0 0 0
41884 - 0 0 0 0 0 0 0 0 0 0 0 0
41885 - 0 0 0 0 0 0 0 0 0 0 0 0
41886 - 0 0 0 0 0 0 6 6 6 26 26 26
41887 - 62 62 62 106 106 106 74 54 14 185 133 11
41888 -210 162 10 121 92 8 6 6 6 62 62 62
41889 -238 238 238 253 253 253 253 253 253 253 253 253
41890 -253 253 253 253 253 253 253 253 253 253 253 253
41891 -253 253 253 253 253 253 231 231 231 246 246 246
41892 -253 253 253 253 253 253 253 253 253 253 253 253
41893 -253 253 253 253 253 253 253 253 253 253 253 253
41894 -253 253 253 253 253 253 253 253 253 253 253 253
41895 -253 253 253 253 253 253 253 253 253 253 253 253
41896 -253 253 253 253 253 253 158 158 158 18 18 18
41897 - 14 14 14 2 2 6 2 2 6 2 2 6
41898 - 6 6 6 18 18 18 66 66 66 38 38 38
41899 - 6 6 6 94 94 94 50 50 50 18 18 18
41900 - 6 6 6 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 0 0 0
41903 - 0 0 0 0 0 0 0 0 0 0 0 0
41904 - 0 0 0 0 0 0 0 0 0 0 0 0
41905 - 0 0 0 0 0 0 0 0 0 6 6 6
41906 - 10 10 10 10 10 10 18 18 18 38 38 38
41907 - 78 78 78 142 134 106 216 158 10 242 186 14
41908 -246 190 14 246 190 14 156 118 10 10 10 10
41909 - 90 90 90 238 238 238 253 253 253 253 253 253
41910 -253 253 253 253 253 253 253 253 253 253 253 253
41911 -253 253 253 253 253 253 231 231 231 250 250 250
41912 -253 253 253 253 253 253 253 253 253 253 253 253
41913 -253 253 253 253 253 253 253 253 253 253 253 253
41914 -253 253 253 253 253 253 253 253 253 253 253 253
41915 -253 253 253 253 253 253 253 253 253 246 230 190
41916 -238 204 91 238 204 91 181 142 44 37 26 9
41917 - 2 2 6 2 2 6 2 2 6 2 2 6
41918 - 2 2 6 2 2 6 38 38 38 46 46 46
41919 - 26 26 26 106 106 106 54 54 54 18 18 18
41920 - 6 6 6 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 0 0 0 0 0 0
41923 - 0 0 0 0 0 0 0 0 0 0 0 0
41924 - 0 0 0 0 0 0 0 0 0 0 0 0
41925 - 0 0 0 6 6 6 14 14 14 22 22 22
41926 - 30 30 30 38 38 38 50 50 50 70 70 70
41927 -106 106 106 190 142 34 226 170 11 242 186 14
41928 -246 190 14 246 190 14 246 190 14 154 114 10
41929 - 6 6 6 74 74 74 226 226 226 253 253 253
41930 -253 253 253 253 253 253 253 253 253 253 253 253
41931 -253 253 253 253 253 253 231 231 231 250 250 250
41932 -253 253 253 253 253 253 253 253 253 253 253 253
41933 -253 253 253 253 253 253 253 253 253 253 253 253
41934 -253 253 253 253 253 253 253 253 253 253 253 253
41935 -253 253 253 253 253 253 253 253 253 228 184 62
41936 -241 196 14 241 208 19 232 195 16 38 30 10
41937 - 2 2 6 2 2 6 2 2 6 2 2 6
41938 - 2 2 6 6 6 6 30 30 30 26 26 26
41939 -203 166 17 154 142 90 66 66 66 26 26 26
41940 - 6 6 6 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 0 0 0 0 0 0
41943 - 0 0 0 0 0 0 0 0 0 0 0 0
41944 - 0 0 0 0 0 0 0 0 0 0 0 0
41945 - 6 6 6 18 18 18 38 38 38 58 58 58
41946 - 78 78 78 86 86 86 101 101 101 123 123 123
41947 -175 146 61 210 150 10 234 174 13 246 186 14
41948 -246 190 14 246 190 14 246 190 14 238 190 10
41949 -102 78 10 2 2 6 46 46 46 198 198 198
41950 -253 253 253 253 253 253 253 253 253 253 253 253
41951 -253 253 253 253 253 253 234 234 234 242 242 242
41952 -253 253 253 253 253 253 253 253 253 253 253 253
41953 -253 253 253 253 253 253 253 253 253 253 253 253
41954 -253 253 253 253 253 253 253 253 253 253 253 253
41955 -253 253 253 253 253 253 253 253 253 224 178 62
41956 -242 186 14 241 196 14 210 166 10 22 18 6
41957 - 2 2 6 2 2 6 2 2 6 2 2 6
41958 - 2 2 6 2 2 6 6 6 6 121 92 8
41959 -238 202 15 232 195 16 82 82 82 34 34 34
41960 - 10 10 10 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 0 0 0 0 0 0 0 0 0
41963 - 0 0 0 0 0 0 0 0 0 0 0 0
41964 - 0 0 0 0 0 0 0 0 0 0 0 0
41965 - 14 14 14 38 38 38 70 70 70 154 122 46
41966 -190 142 34 200 144 11 197 138 11 197 138 11
41967 -213 154 11 226 170 11 242 186 14 246 190 14
41968 -246 190 14 246 190 14 246 190 14 246 190 14
41969 -225 175 15 46 32 6 2 2 6 22 22 22
41970 -158 158 158 250 250 250 253 253 253 253 253 253
41971 -253 253 253 253 253 253 253 253 253 253 253 253
41972 -253 253 253 253 253 253 253 253 253 253 253 253
41973 -253 253 253 253 253 253 253 253 253 253 253 253
41974 -253 253 253 253 253 253 253 253 253 253 253 253
41975 -253 253 253 250 250 250 242 242 242 224 178 62
41976 -239 182 13 236 186 11 213 154 11 46 32 6
41977 - 2 2 6 2 2 6 2 2 6 2 2 6
41978 - 2 2 6 2 2 6 61 42 6 225 175 15
41979 -238 190 10 236 186 11 112 100 78 42 42 42
41980 - 14 14 14 0 0 0 0 0 0 0 0 0
41981 - 0 0 0 0 0 0 0 0 0 0 0 0
41982 - 0 0 0 0 0 0 0 0 0 0 0 0
41983 - 0 0 0 0 0 0 0 0 0 0 0 0
41984 - 0 0 0 0 0 0 0 0 0 6 6 6
41985 - 22 22 22 54 54 54 154 122 46 213 154 11
41986 -226 170 11 230 174 11 226 170 11 226 170 11
41987 -236 178 12 242 186 14 246 190 14 246 190 14
41988 -246 190 14 246 190 14 246 190 14 246 190 14
41989 -241 196 14 184 144 12 10 10 10 2 2 6
41990 - 6 6 6 116 116 116 242 242 242 253 253 253
41991 -253 253 253 253 253 253 253 253 253 253 253 253
41992 -253 253 253 253 253 253 253 253 253 253 253 253
41993 -253 253 253 253 253 253 253 253 253 253 253 253
41994 -253 253 253 253 253 253 253 253 253 253 253 253
41995 -253 253 253 231 231 231 198 198 198 214 170 54
41996 -236 178 12 236 178 12 210 150 10 137 92 6
41997 - 18 14 6 2 2 6 2 2 6 2 2 6
41998 - 6 6 6 70 47 6 200 144 11 236 178 12
41999 -239 182 13 239 182 13 124 112 88 58 58 58
42000 - 22 22 22 6 6 6 0 0 0 0 0 0
42001 - 0 0 0 0 0 0 0 0 0 0 0 0
42002 - 0 0 0 0 0 0 0 0 0 0 0 0
42003 - 0 0 0 0 0 0 0 0 0 0 0 0
42004 - 0 0 0 0 0 0 0 0 0 10 10 10
42005 - 30 30 30 70 70 70 180 133 36 226 170 11
42006 -239 182 13 242 186 14 242 186 14 246 186 14
42007 -246 190 14 246 190 14 246 190 14 246 190 14
42008 -246 190 14 246 190 14 246 190 14 246 190 14
42009 -246 190 14 232 195 16 98 70 6 2 2 6
42010 - 2 2 6 2 2 6 66 66 66 221 221 221
42011 -253 253 253 253 253 253 253 253 253 253 253 253
42012 -253 253 253 253 253 253 253 253 253 253 253 253
42013 -253 253 253 253 253 253 253 253 253 253 253 253
42014 -253 253 253 253 253 253 253 253 253 253 253 253
42015 -253 253 253 206 206 206 198 198 198 214 166 58
42016 -230 174 11 230 174 11 216 158 10 192 133 9
42017 -163 110 8 116 81 8 102 78 10 116 81 8
42018 -167 114 7 197 138 11 226 170 11 239 182 13
42019 -242 186 14 242 186 14 162 146 94 78 78 78
42020 - 34 34 34 14 14 14 6 6 6 0 0 0
42021 - 0 0 0 0 0 0 0 0 0 0 0 0
42022 - 0 0 0 0 0 0 0 0 0 0 0 0
42023 - 0 0 0 0 0 0 0 0 0 0 0 0
42024 - 0 0 0 0 0 0 0 0 0 6 6 6
42025 - 30 30 30 78 78 78 190 142 34 226 170 11
42026 -239 182 13 246 190 14 246 190 14 246 190 14
42027 -246 190 14 246 190 14 246 190 14 246 190 14
42028 -246 190 14 246 190 14 246 190 14 246 190 14
42029 -246 190 14 241 196 14 203 166 17 22 18 6
42030 - 2 2 6 2 2 6 2 2 6 38 38 38
42031 -218 218 218 253 253 253 253 253 253 253 253 253
42032 -253 253 253 253 253 253 253 253 253 253 253 253
42033 -253 253 253 253 253 253 253 253 253 253 253 253
42034 -253 253 253 253 253 253 253 253 253 253 253 253
42035 -250 250 250 206 206 206 198 198 198 202 162 69
42036 -226 170 11 236 178 12 224 166 10 210 150 10
42037 -200 144 11 197 138 11 192 133 9 197 138 11
42038 -210 150 10 226 170 11 242 186 14 246 190 14
42039 -246 190 14 246 186 14 225 175 15 124 112 88
42040 - 62 62 62 30 30 30 14 14 14 6 6 6
42041 - 0 0 0 0 0 0 0 0 0 0 0 0
42042 - 0 0 0 0 0 0 0 0 0 0 0 0
42043 - 0 0 0 0 0 0 0 0 0 0 0 0
42044 - 0 0 0 0 0 0 0 0 0 10 10 10
42045 - 30 30 30 78 78 78 174 135 50 224 166 10
42046 -239 182 13 246 190 14 246 190 14 246 190 14
42047 -246 190 14 246 190 14 246 190 14 246 190 14
42048 -246 190 14 246 190 14 246 190 14 246 190 14
42049 -246 190 14 246 190 14 241 196 14 139 102 15
42050 - 2 2 6 2 2 6 2 2 6 2 2 6
42051 - 78 78 78 250 250 250 253 253 253 253 253 253
42052 -253 253 253 253 253 253 253 253 253 253 253 253
42053 -253 253 253 253 253 253 253 253 253 253 253 253
42054 -253 253 253 253 253 253 253 253 253 253 253 253
42055 -250 250 250 214 214 214 198 198 198 190 150 46
42056 -219 162 10 236 178 12 234 174 13 224 166 10
42057 -216 158 10 213 154 11 213 154 11 216 158 10
42058 -226 170 11 239 182 13 246 190 14 246 190 14
42059 -246 190 14 246 190 14 242 186 14 206 162 42
42060 -101 101 101 58 58 58 30 30 30 14 14 14
42061 - 6 6 6 0 0 0 0 0 0 0 0 0
42062 - 0 0 0 0 0 0 0 0 0 0 0 0
42063 - 0 0 0 0 0 0 0 0 0 0 0 0
42064 - 0 0 0 0 0 0 0 0 0 10 10 10
42065 - 30 30 30 74 74 74 174 135 50 216 158 10
42066 -236 178 12 246 190 14 246 190 14 246 190 14
42067 -246 190 14 246 190 14 246 190 14 246 190 14
42068 -246 190 14 246 190 14 246 190 14 246 190 14
42069 -246 190 14 246 190 14 241 196 14 226 184 13
42070 - 61 42 6 2 2 6 2 2 6 2 2 6
42071 - 22 22 22 238 238 238 253 253 253 253 253 253
42072 -253 253 253 253 253 253 253 253 253 253 253 253
42073 -253 253 253 253 253 253 253 253 253 253 253 253
42074 -253 253 253 253 253 253 253 253 253 253 253 253
42075 -253 253 253 226 226 226 187 187 187 180 133 36
42076 -216 158 10 236 178 12 239 182 13 236 178 12
42077 -230 174 11 226 170 11 226 170 11 230 174 11
42078 -236 178 12 242 186 14 246 190 14 246 190 14
42079 -246 190 14 246 190 14 246 186 14 239 182 13
42080 -206 162 42 106 106 106 66 66 66 34 34 34
42081 - 14 14 14 6 6 6 0 0 0 0 0 0
42082 - 0 0 0 0 0 0 0 0 0 0 0 0
42083 - 0 0 0 0 0 0 0 0 0 0 0 0
42084 - 0 0 0 0 0 0 0 0 0 6 6 6
42085 - 26 26 26 70 70 70 163 133 67 213 154 11
42086 -236 178 12 246 190 14 246 190 14 246 190 14
42087 -246 190 14 246 190 14 246 190 14 246 190 14
42088 -246 190 14 246 190 14 246 190 14 246 190 14
42089 -246 190 14 246 190 14 246 190 14 241 196 14
42090 -190 146 13 18 14 6 2 2 6 2 2 6
42091 - 46 46 46 246 246 246 253 253 253 253 253 253
42092 -253 253 253 253 253 253 253 253 253 253 253 253
42093 -253 253 253 253 253 253 253 253 253 253 253 253
42094 -253 253 253 253 253 253 253 253 253 253 253 253
42095 -253 253 253 221 221 221 86 86 86 156 107 11
42096 -216 158 10 236 178 12 242 186 14 246 186 14
42097 -242 186 14 239 182 13 239 182 13 242 186 14
42098 -242 186 14 246 186 14 246 190 14 246 190 14
42099 -246 190 14 246 190 14 246 190 14 246 190 14
42100 -242 186 14 225 175 15 142 122 72 66 66 66
42101 - 30 30 30 10 10 10 0 0 0 0 0 0
42102 - 0 0 0 0 0 0 0 0 0 0 0 0
42103 - 0 0 0 0 0 0 0 0 0 0 0 0
42104 - 0 0 0 0 0 0 0 0 0 6 6 6
42105 - 26 26 26 70 70 70 163 133 67 210 150 10
42106 -236 178 12 246 190 14 246 190 14 246 190 14
42107 -246 190 14 246 190 14 246 190 14 246 190 14
42108 -246 190 14 246 190 14 246 190 14 246 190 14
42109 -246 190 14 246 190 14 246 190 14 246 190 14
42110 -232 195 16 121 92 8 34 34 34 106 106 106
42111 -221 221 221 253 253 253 253 253 253 253 253 253
42112 -253 253 253 253 253 253 253 253 253 253 253 253
42113 -253 253 253 253 253 253 253 253 253 253 253 253
42114 -253 253 253 253 253 253 253 253 253 253 253 253
42115 -242 242 242 82 82 82 18 14 6 163 110 8
42116 -216 158 10 236 178 12 242 186 14 246 190 14
42117 -246 190 14 246 190 14 246 190 14 246 190 14
42118 -246 190 14 246 190 14 246 190 14 246 190 14
42119 -246 190 14 246 190 14 246 190 14 246 190 14
42120 -246 190 14 246 190 14 242 186 14 163 133 67
42121 - 46 46 46 18 18 18 6 6 6 0 0 0
42122 - 0 0 0 0 0 0 0 0 0 0 0 0
42123 - 0 0 0 0 0 0 0 0 0 0 0 0
42124 - 0 0 0 0 0 0 0 0 0 10 10 10
42125 - 30 30 30 78 78 78 163 133 67 210 150 10
42126 -236 178 12 246 186 14 246 190 14 246 190 14
42127 -246 190 14 246 190 14 246 190 14 246 190 14
42128 -246 190 14 246 190 14 246 190 14 246 190 14
42129 -246 190 14 246 190 14 246 190 14 246 190 14
42130 -241 196 14 215 174 15 190 178 144 253 253 253
42131 -253 253 253 253 253 253 253 253 253 253 253 253
42132 -253 253 253 253 253 253 253 253 253 253 253 253
42133 -253 253 253 253 253 253 253 253 253 253 253 253
42134 -253 253 253 253 253 253 253 253 253 218 218 218
42135 - 58 58 58 2 2 6 22 18 6 167 114 7
42136 -216 158 10 236 178 12 246 186 14 246 190 14
42137 -246 190 14 246 190 14 246 190 14 246 190 14
42138 -246 190 14 246 190 14 246 190 14 246 190 14
42139 -246 190 14 246 190 14 246 190 14 246 190 14
42140 -246 190 14 246 186 14 242 186 14 190 150 46
42141 - 54 54 54 22 22 22 6 6 6 0 0 0
42142 - 0 0 0 0 0 0 0 0 0 0 0 0
42143 - 0 0 0 0 0 0 0 0 0 0 0 0
42144 - 0 0 0 0 0 0 0 0 0 14 14 14
42145 - 38 38 38 86 86 86 180 133 36 213 154 11
42146 -236 178 12 246 186 14 246 190 14 246 190 14
42147 -246 190 14 246 190 14 246 190 14 246 190 14
42148 -246 190 14 246 190 14 246 190 14 246 190 14
42149 -246 190 14 246 190 14 246 190 14 246 190 14
42150 -246 190 14 232 195 16 190 146 13 214 214 214
42151 -253 253 253 253 253 253 253 253 253 253 253 253
42152 -253 253 253 253 253 253 253 253 253 253 253 253
42153 -253 253 253 253 253 253 253 253 253 253 253 253
42154 -253 253 253 250 250 250 170 170 170 26 26 26
42155 - 2 2 6 2 2 6 37 26 9 163 110 8
42156 -219 162 10 239 182 13 246 186 14 246 190 14
42157 -246 190 14 246 190 14 246 190 14 246 190 14
42158 -246 190 14 246 190 14 246 190 14 246 190 14
42159 -246 190 14 246 190 14 246 190 14 246 190 14
42160 -246 186 14 236 178 12 224 166 10 142 122 72
42161 - 46 46 46 18 18 18 6 6 6 0 0 0
42162 - 0 0 0 0 0 0 0 0 0 0 0 0
42163 - 0 0 0 0 0 0 0 0 0 0 0 0
42164 - 0 0 0 0 0 0 6 6 6 18 18 18
42165 - 50 50 50 109 106 95 192 133 9 224 166 10
42166 -242 186 14 246 190 14 246 190 14 246 190 14
42167 -246 190 14 246 190 14 246 190 14 246 190 14
42168 -246 190 14 246 190 14 246 190 14 246 190 14
42169 -246 190 14 246 190 14 246 190 14 246 190 14
42170 -242 186 14 226 184 13 210 162 10 142 110 46
42171 -226 226 226 253 253 253 253 253 253 253 253 253
42172 -253 253 253 253 253 253 253 253 253 253 253 253
42173 -253 253 253 253 253 253 253 253 253 253 253 253
42174 -198 198 198 66 66 66 2 2 6 2 2 6
42175 - 2 2 6 2 2 6 50 34 6 156 107 11
42176 -219 162 10 239 182 13 246 186 14 246 190 14
42177 -246 190 14 246 190 14 246 190 14 246 190 14
42178 -246 190 14 246 190 14 246 190 14 246 190 14
42179 -246 190 14 246 190 14 246 190 14 242 186 14
42180 -234 174 13 213 154 11 154 122 46 66 66 66
42181 - 30 30 30 10 10 10 0 0 0 0 0 0
42182 - 0 0 0 0 0 0 0 0 0 0 0 0
42183 - 0 0 0 0 0 0 0 0 0 0 0 0
42184 - 0 0 0 0 0 0 6 6 6 22 22 22
42185 - 58 58 58 154 121 60 206 145 10 234 174 13
42186 -242 186 14 246 186 14 246 190 14 246 190 14
42187 -246 190 14 246 190 14 246 190 14 246 190 14
42188 -246 190 14 246 190 14 246 190 14 246 190 14
42189 -246 190 14 246 190 14 246 190 14 246 190 14
42190 -246 186 14 236 178 12 210 162 10 163 110 8
42191 - 61 42 6 138 138 138 218 218 218 250 250 250
42192 -253 253 253 253 253 253 253 253 253 250 250 250
42193 -242 242 242 210 210 210 144 144 144 66 66 66
42194 - 6 6 6 2 2 6 2 2 6 2 2 6
42195 - 2 2 6 2 2 6 61 42 6 163 110 8
42196 -216 158 10 236 178 12 246 190 14 246 190 14
42197 -246 190 14 246 190 14 246 190 14 246 190 14
42198 -246 190 14 246 190 14 246 190 14 246 190 14
42199 -246 190 14 239 182 13 230 174 11 216 158 10
42200 -190 142 34 124 112 88 70 70 70 38 38 38
42201 - 18 18 18 6 6 6 0 0 0 0 0 0
42202 - 0 0 0 0 0 0 0 0 0 0 0 0
42203 - 0 0 0 0 0 0 0 0 0 0 0 0
42204 - 0 0 0 0 0 0 6 6 6 22 22 22
42205 - 62 62 62 168 124 44 206 145 10 224 166 10
42206 -236 178 12 239 182 13 242 186 14 242 186 14
42207 -246 186 14 246 190 14 246 190 14 246 190 14
42208 -246 190 14 246 190 14 246 190 14 246 190 14
42209 -246 190 14 246 190 14 246 190 14 246 190 14
42210 -246 190 14 236 178 12 216 158 10 175 118 6
42211 - 80 54 7 2 2 6 6 6 6 30 30 30
42212 - 54 54 54 62 62 62 50 50 50 38 38 38
42213 - 14 14 14 2 2 6 2 2 6 2 2 6
42214 - 2 2 6 2 2 6 2 2 6 2 2 6
42215 - 2 2 6 6 6 6 80 54 7 167 114 7
42216 -213 154 11 236 178 12 246 190 14 246 190 14
42217 -246 190 14 246 190 14 246 190 14 246 190 14
42218 -246 190 14 242 186 14 239 182 13 239 182 13
42219 -230 174 11 210 150 10 174 135 50 124 112 88
42220 - 82 82 82 54 54 54 34 34 34 18 18 18
42221 - 6 6 6 0 0 0 0 0 0 0 0 0
42222 - 0 0 0 0 0 0 0 0 0 0 0 0
42223 - 0 0 0 0 0 0 0 0 0 0 0 0
42224 - 0 0 0 0 0 0 6 6 6 18 18 18
42225 - 50 50 50 158 118 36 192 133 9 200 144 11
42226 -216 158 10 219 162 10 224 166 10 226 170 11
42227 -230 174 11 236 178 12 239 182 13 239 182 13
42228 -242 186 14 246 186 14 246 190 14 246 190 14
42229 -246 190 14 246 190 14 246 190 14 246 190 14
42230 -246 186 14 230 174 11 210 150 10 163 110 8
42231 -104 69 6 10 10 10 2 2 6 2 2 6
42232 - 2 2 6 2 2 6 2 2 6 2 2 6
42233 - 2 2 6 2 2 6 2 2 6 2 2 6
42234 - 2 2 6 2 2 6 2 2 6 2 2 6
42235 - 2 2 6 6 6 6 91 60 6 167 114 7
42236 -206 145 10 230 174 11 242 186 14 246 190 14
42237 -246 190 14 246 190 14 246 186 14 242 186 14
42238 -239 182 13 230 174 11 224 166 10 213 154 11
42239 -180 133 36 124 112 88 86 86 86 58 58 58
42240 - 38 38 38 22 22 22 10 10 10 6 6 6
42241 - 0 0 0 0 0 0 0 0 0 0 0 0
42242 - 0 0 0 0 0 0 0 0 0 0 0 0
42243 - 0 0 0 0 0 0 0 0 0 0 0 0
42244 - 0 0 0 0 0 0 0 0 0 14 14 14
42245 - 34 34 34 70 70 70 138 110 50 158 118 36
42246 -167 114 7 180 123 7 192 133 9 197 138 11
42247 -200 144 11 206 145 10 213 154 11 219 162 10
42248 -224 166 10 230 174 11 239 182 13 242 186 14
42249 -246 186 14 246 186 14 246 186 14 246 186 14
42250 -239 182 13 216 158 10 185 133 11 152 99 6
42251 -104 69 6 18 14 6 2 2 6 2 2 6
42252 - 2 2 6 2 2 6 2 2 6 2 2 6
42253 - 2 2 6 2 2 6 2 2 6 2 2 6
42254 - 2 2 6 2 2 6 2 2 6 2 2 6
42255 - 2 2 6 6 6 6 80 54 7 152 99 6
42256 -192 133 9 219 162 10 236 178 12 239 182 13
42257 -246 186 14 242 186 14 239 182 13 236 178 12
42258 -224 166 10 206 145 10 192 133 9 154 121 60
42259 - 94 94 94 62 62 62 42 42 42 22 22 22
42260 - 14 14 14 6 6 6 0 0 0 0 0 0
42261 - 0 0 0 0 0 0 0 0 0 0 0 0
42262 - 0 0 0 0 0 0 0 0 0 0 0 0
42263 - 0 0 0 0 0 0 0 0 0 0 0 0
42264 - 0 0 0 0 0 0 0 0 0 6 6 6
42265 - 18 18 18 34 34 34 58 58 58 78 78 78
42266 -101 98 89 124 112 88 142 110 46 156 107 11
42267 -163 110 8 167 114 7 175 118 6 180 123 7
42268 -185 133 11 197 138 11 210 150 10 219 162 10
42269 -226 170 11 236 178 12 236 178 12 234 174 13
42270 -219 162 10 197 138 11 163 110 8 130 83 6
42271 - 91 60 6 10 10 10 2 2 6 2 2 6
42272 - 18 18 18 38 38 38 38 38 38 38 38 38
42273 - 38 38 38 38 38 38 38 38 38 38 38 38
42274 - 38 38 38 38 38 38 26 26 26 2 2 6
42275 - 2 2 6 6 6 6 70 47 6 137 92 6
42276 -175 118 6 200 144 11 219 162 10 230 174 11
42277 -234 174 13 230 174 11 219 162 10 210 150 10
42278 -192 133 9 163 110 8 124 112 88 82 82 82
42279 - 50 50 50 30 30 30 14 14 14 6 6 6
42280 - 0 0 0 0 0 0 0 0 0 0 0 0
42281 - 0 0 0 0 0 0 0 0 0 0 0 0
42282 - 0 0 0 0 0 0 0 0 0 0 0 0
42283 - 0 0 0 0 0 0 0 0 0 0 0 0
42284 - 0 0 0 0 0 0 0 0 0 0 0 0
42285 - 6 6 6 14 14 14 22 22 22 34 34 34
42286 - 42 42 42 58 58 58 74 74 74 86 86 86
42287 -101 98 89 122 102 70 130 98 46 121 87 25
42288 -137 92 6 152 99 6 163 110 8 180 123 7
42289 -185 133 11 197 138 11 206 145 10 200 144 11
42290 -180 123 7 156 107 11 130 83 6 104 69 6
42291 - 50 34 6 54 54 54 110 110 110 101 98 89
42292 - 86 86 86 82 82 82 78 78 78 78 78 78
42293 - 78 78 78 78 78 78 78 78 78 78 78 78
42294 - 78 78 78 82 82 82 86 86 86 94 94 94
42295 -106 106 106 101 101 101 86 66 34 124 80 6
42296 -156 107 11 180 123 7 192 133 9 200 144 11
42297 -206 145 10 200 144 11 192 133 9 175 118 6
42298 -139 102 15 109 106 95 70 70 70 42 42 42
42299 - 22 22 22 10 10 10 0 0 0 0 0 0
42300 - 0 0 0 0 0 0 0 0 0 0 0 0
42301 - 0 0 0 0 0 0 0 0 0 0 0 0
42302 - 0 0 0 0 0 0 0 0 0 0 0 0
42303 - 0 0 0 0 0 0 0 0 0 0 0 0
42304 - 0 0 0 0 0 0 0 0 0 0 0 0
42305 - 0 0 0 0 0 0 6 6 6 10 10 10
42306 - 14 14 14 22 22 22 30 30 30 38 38 38
42307 - 50 50 50 62 62 62 74 74 74 90 90 90
42308 -101 98 89 112 100 78 121 87 25 124 80 6
42309 -137 92 6 152 99 6 152 99 6 152 99 6
42310 -138 86 6 124 80 6 98 70 6 86 66 30
42311 -101 98 89 82 82 82 58 58 58 46 46 46
42312 - 38 38 38 34 34 34 34 34 34 34 34 34
42313 - 34 34 34 34 34 34 34 34 34 34 34 34
42314 - 34 34 34 34 34 34 38 38 38 42 42 42
42315 - 54 54 54 82 82 82 94 86 76 91 60 6
42316 -134 86 6 156 107 11 167 114 7 175 118 6
42317 -175 118 6 167 114 7 152 99 6 121 87 25
42318 -101 98 89 62 62 62 34 34 34 18 18 18
42319 - 6 6 6 0 0 0 0 0 0 0 0 0
42320 - 0 0 0 0 0 0 0 0 0 0 0 0
42321 - 0 0 0 0 0 0 0 0 0 0 0 0
42322 - 0 0 0 0 0 0 0 0 0 0 0 0
42323 - 0 0 0 0 0 0 0 0 0 0 0 0
42324 - 0 0 0 0 0 0 0 0 0 0 0 0
42325 - 0 0 0 0 0 0 0 0 0 0 0 0
42326 - 0 0 0 6 6 6 6 6 6 10 10 10
42327 - 18 18 18 22 22 22 30 30 30 42 42 42
42328 - 50 50 50 66 66 66 86 86 86 101 98 89
42329 -106 86 58 98 70 6 104 69 6 104 69 6
42330 -104 69 6 91 60 6 82 62 34 90 90 90
42331 - 62 62 62 38 38 38 22 22 22 14 14 14
42332 - 10 10 10 10 10 10 10 10 10 10 10 10
42333 - 10 10 10 10 10 10 6 6 6 10 10 10
42334 - 10 10 10 10 10 10 10 10 10 14 14 14
42335 - 22 22 22 42 42 42 70 70 70 89 81 66
42336 - 80 54 7 104 69 6 124 80 6 137 92 6
42337 -134 86 6 116 81 8 100 82 52 86 86 86
42338 - 58 58 58 30 30 30 14 14 14 6 6 6
42339 - 0 0 0 0 0 0 0 0 0 0 0 0
42340 - 0 0 0 0 0 0 0 0 0 0 0 0
42341 - 0 0 0 0 0 0 0 0 0 0 0 0
42342 - 0 0 0 0 0 0 0 0 0 0 0 0
42343 - 0 0 0 0 0 0 0 0 0 0 0 0
42344 - 0 0 0 0 0 0 0 0 0 0 0 0
42345 - 0 0 0 0 0 0 0 0 0 0 0 0
42346 - 0 0 0 0 0 0 0 0 0 0 0 0
42347 - 0 0 0 6 6 6 10 10 10 14 14 14
42348 - 18 18 18 26 26 26 38 38 38 54 54 54
42349 - 70 70 70 86 86 86 94 86 76 89 81 66
42350 - 89 81 66 86 86 86 74 74 74 50 50 50
42351 - 30 30 30 14 14 14 6 6 6 0 0 0
42352 - 0 0 0 0 0 0 0 0 0 0 0 0
42353 - 0 0 0 0 0 0 0 0 0 0 0 0
42354 - 0 0 0 0 0 0 0 0 0 0 0 0
42355 - 6 6 6 18 18 18 34 34 34 58 58 58
42356 - 82 82 82 89 81 66 89 81 66 89 81 66
42357 - 94 86 66 94 86 76 74 74 74 50 50 50
42358 - 26 26 26 14 14 14 6 6 6 0 0 0
42359 - 0 0 0 0 0 0 0 0 0 0 0 0
42360 - 0 0 0 0 0 0 0 0 0 0 0 0
42361 - 0 0 0 0 0 0 0 0 0 0 0 0
42362 - 0 0 0 0 0 0 0 0 0 0 0 0
42363 - 0 0 0 0 0 0 0 0 0 0 0 0
42364 - 0 0 0 0 0 0 0 0 0 0 0 0
42365 - 0 0 0 0 0 0 0 0 0 0 0 0
42366 - 0 0 0 0 0 0 0 0 0 0 0 0
42367 - 0 0 0 0 0 0 0 0 0 0 0 0
42368 - 6 6 6 6 6 6 14 14 14 18 18 18
42369 - 30 30 30 38 38 38 46 46 46 54 54 54
42370 - 50 50 50 42 42 42 30 30 30 18 18 18
42371 - 10 10 10 0 0 0 0 0 0 0 0 0
42372 - 0 0 0 0 0 0 0 0 0 0 0 0
42373 - 0 0 0 0 0 0 0 0 0 0 0 0
42374 - 0 0 0 0 0 0 0 0 0 0 0 0
42375 - 0 0 0 6 6 6 14 14 14 26 26 26
42376 - 38 38 38 50 50 50 58 58 58 58 58 58
42377 - 54 54 54 42 42 42 30 30 30 18 18 18
42378 - 10 10 10 0 0 0 0 0 0 0 0 0
42379 - 0 0 0 0 0 0 0 0 0 0 0 0
42380 - 0 0 0 0 0 0 0 0 0 0 0 0
42381 - 0 0 0 0 0 0 0 0 0 0 0 0
42382 - 0 0 0 0 0 0 0 0 0 0 0 0
42383 - 0 0 0 0 0 0 0 0 0 0 0 0
42384 - 0 0 0 0 0 0 0 0 0 0 0 0
42385 - 0 0 0 0 0 0 0 0 0 0 0 0
42386 - 0 0 0 0 0 0 0 0 0 0 0 0
42387 - 0 0 0 0 0 0 0 0 0 0 0 0
42388 - 0 0 0 0 0 0 0 0 0 6 6 6
42389 - 6 6 6 10 10 10 14 14 14 18 18 18
42390 - 18 18 18 14 14 14 10 10 10 6 6 6
42391 - 0 0 0 0 0 0 0 0 0 0 0 0
42392 - 0 0 0 0 0 0 0 0 0 0 0 0
42393 - 0 0 0 0 0 0 0 0 0 0 0 0
42394 - 0 0 0 0 0 0 0 0 0 0 0 0
42395 - 0 0 0 0 0 0 0 0 0 6 6 6
42396 - 14 14 14 18 18 18 22 22 22 22 22 22
42397 - 18 18 18 14 14 14 10 10 10 6 6 6
42398 - 0 0 0 0 0 0 0 0 0 0 0 0
42399 - 0 0 0 0 0 0 0 0 0 0 0 0
42400 - 0 0 0 0 0 0 0 0 0 0 0 0
42401 - 0 0 0 0 0 0 0 0 0 0 0 0
42402 - 0 0 0 0 0 0 0 0 0 0 0 0
42403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42416 +4 4 4 4 4 4
42417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42430 +4 4 4 4 4 4
42431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42444 +4 4 4 4 4 4
42445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42458 +4 4 4 4 4 4
42459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42472 +4 4 4 4 4 4
42473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42486 +4 4 4 4 4 4
42487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42491 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
42492 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
42493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42496 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
42497 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42498 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
42499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42500 +4 4 4 4 4 4
42501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42505 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
42506 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
42507 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42510 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
42511 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
42512 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
42513 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42514 +4 4 4 4 4 4
42515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42519 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
42520 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
42521 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42524 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
42525 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
42526 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
42527 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
42528 +4 4 4 4 4 4
42529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42532 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
42533 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
42534 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
42535 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
42536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42537 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42538 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
42539 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
42540 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
42541 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
42542 +4 4 4 4 4 4
42543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42546 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
42547 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
42548 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
42549 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
42550 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42551 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
42552 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
42553 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
42554 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
42555 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
42556 +4 4 4 4 4 4
42557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42560 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
42561 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
42562 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
42563 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
42564 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42565 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
42566 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
42567 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
42568 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
42569 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
42570 +4 4 4 4 4 4
42571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42573 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
42574 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
42575 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
42576 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
42577 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
42578 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
42579 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
42580 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
42581 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
42582 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
42583 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
42584 +4 4 4 4 4 4
42585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42587 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
42588 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
42589 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
42590 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
42591 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
42592 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
42593 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
42594 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
42595 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
42596 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
42597 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
42598 +4 4 4 4 4 4
42599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42601 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
42602 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
42603 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
42604 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
42605 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
42606 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
42607 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
42608 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
42609 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
42610 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
42611 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42612 +4 4 4 4 4 4
42613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42615 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
42616 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
42617 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
42618 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
42619 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
42620 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
42621 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
42622 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
42623 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
42624 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
42625 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
42626 +4 4 4 4 4 4
42627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42628 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
42629 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
42630 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
42631 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
42632 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
42633 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
42634 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
42635 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
42636 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
42637 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
42638 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
42639 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
42640 +4 4 4 4 4 4
42641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42642 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
42643 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
42644 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
42645 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42646 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
42647 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
42648 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
42649 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
42650 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
42651 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
42652 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
42653 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
42654 +0 0 0 4 4 4
42655 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42656 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
42657 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
42658 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
42659 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
42660 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
42661 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
42662 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
42663 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
42664 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
42665 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
42666 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
42667 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
42668 +2 0 0 0 0 0
42669 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
42670 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
42671 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
42672 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
42673 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
42674 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
42675 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
42676 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
42677 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
42678 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
42679 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
42680 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
42681 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
42682 +37 38 37 0 0 0
42683 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
42684 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
42685 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
42686 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
42687 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
42688 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
42689 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
42690 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
42691 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
42692 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
42693 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
42694 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
42695 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
42696 +85 115 134 4 0 0
42697 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
42698 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
42699 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
42700 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
42701 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
42702 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
42703 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
42704 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
42705 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
42706 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
42707 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
42708 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
42709 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
42710 +60 73 81 4 0 0
42711 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
42712 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
42713 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
42714 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
42715 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
42716 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
42717 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
42718 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
42719 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
42720 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
42721 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
42722 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
42723 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
42724 +16 19 21 4 0 0
42725 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
42726 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
42727 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
42728 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
42729 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
42730 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
42731 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
42732 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
42733 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
42734 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
42735 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
42736 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
42737 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
42738 +4 0 0 4 3 3
42739 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
42740 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
42741 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
42742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
42743 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
42744 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
42745 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
42746 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
42747 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
42748 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
42749 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
42750 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
42751 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
42752 +3 2 2 4 4 4
42753 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
42754 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
42755 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
42756 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
42757 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
42758 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
42759 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
42760 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
42761 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
42762 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
42763 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
42764 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
42765 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
42766 +4 4 4 4 4 4
42767 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
42768 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
42769 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
42770 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
42771 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
42772 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
42773 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
42774 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
42775 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
42776 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
42777 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
42778 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
42779 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
42780 +4 4 4 4 4 4
42781 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
42782 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
42783 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
42784 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
42785 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
42786 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
42787 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
42788 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
42789 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
42790 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
42791 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
42792 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
42793 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
42794 +5 5 5 5 5 5
42795 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
42796 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
42797 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
42798 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
42799 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
42800 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42801 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
42802 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
42803 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
42804 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
42805 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
42806 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
42807 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42808 +5 5 5 4 4 4
42809 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
42810 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
42811 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
42812 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
42813 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42814 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
42815 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
42816 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
42817 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
42818 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
42819 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
42820 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42822 +4 4 4 4 4 4
42823 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
42824 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
42825 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
42826 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
42827 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
42828 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42829 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42830 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
42831 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
42832 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
42833 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
42834 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
42835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42836 +4 4 4 4 4 4
42837 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
42838 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
42839 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
42840 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
42841 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42842 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
42843 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
42844 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
42845 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
42846 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
42847 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
42848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42850 +4 4 4 4 4 4
42851 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
42852 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
42853 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
42854 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
42855 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42856 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42857 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42858 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
42859 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
42860 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
42861 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
42862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42864 +4 4 4 4 4 4
42865 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
42866 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
42867 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
42868 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
42869 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42870 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
42871 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
42872 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
42873 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
42874 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
42875 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42878 +4 4 4 4 4 4
42879 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
42880 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
42881 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
42882 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
42883 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42884 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
42885 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
42886 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
42887 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
42888 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
42889 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
42890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42892 +4 4 4 4 4 4
42893 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
42894 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
42895 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
42896 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
42897 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42898 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
42899 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
42900 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
42901 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
42902 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
42903 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
42904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42906 +4 4 4 4 4 4
42907 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
42908 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
42909 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
42910 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42911 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
42912 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
42913 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
42914 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
42915 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
42916 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
42917 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42920 +4 4 4 4 4 4
42921 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
42922 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
42923 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
42924 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42925 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42926 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
42927 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
42928 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
42929 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
42930 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
42931 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42934 +4 4 4 4 4 4
42935 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
42936 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
42937 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42938 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42939 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42940 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
42941 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
42942 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
42943 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
42944 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
42945 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42948 +4 4 4 4 4 4
42949 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
42950 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
42951 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42952 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42953 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42954 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
42955 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
42956 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
42957 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42958 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42959 +0 0 0 3 3 3 5 5 5 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
42963 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42964 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
42965 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42966 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
42967 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
42968 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
42969 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
42970 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
42971 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42972 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42973 +0 0 0 3 3 3 5 5 5 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
42977 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42978 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
42979 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42980 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
42981 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42982 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
42983 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
42984 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
42985 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42986 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42987 +0 0 0 3 3 3 5 5 5 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
42991 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
42992 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
42993 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42994 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
42995 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
42996 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
42997 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
42998 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
42999 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43000 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43001 +0 0 0 3 3 3 5 5 5 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
43005 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43006 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43007 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43008 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43009 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43010 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43011 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43012 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43013 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43014 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43015 +0 0 0 3 3 3 5 5 5 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
43019 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43020 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43021 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43022 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43023 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43024 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43025 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43026 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43027 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43028 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43029 +0 0 0 3 3 3 5 5 5 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
43033 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43034 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43035 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43036 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43037 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43038 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43039 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43040 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43041 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43042 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43043 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43046 +4 4 4 4 4 4
43047 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43048 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43049 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43050 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43051 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43052 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43053 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43054 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43055 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43056 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43057 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43060 +4 4 4 4 4 4
43061 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43062 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43063 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43064 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43065 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43066 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43067 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43068 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43069 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43070 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43071 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43074 +4 4 4 4 4 4
43075 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43076 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43077 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43078 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43079 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43080 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43081 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43082 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43083 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43084 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43085 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43088 +4 4 4 4 4 4
43089 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43090 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43091 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43092 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43093 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43094 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43095 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43096 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43097 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43098 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43099 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43102 +4 4 4 4 4 4
43103 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43104 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43105 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43106 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43107 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43108 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43109 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43110 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43111 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43112 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43113 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43116 +4 4 4 4 4 4
43117 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43118 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43119 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43120 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43121 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43122 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43123 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43124 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43125 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43126 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43127 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43130 +4 4 4 4 4 4
43131 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43132 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43133 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43134 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43135 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43136 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43137 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43138 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43139 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43140 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43141 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43144 +4 4 4 4 4 4
43145 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43146 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43147 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43148 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43149 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43150 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43151 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43152 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43153 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43154 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43155 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43158 +4 4 4 4 4 4
43159 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43160 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43161 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43162 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43163 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43164 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43165 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43166 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43167 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43168 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43169 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43172 +4 4 4 4 4 4
43173 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43174 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43175 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43176 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43177 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43178 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43179 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43180 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43181 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43182 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43183 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43186 +4 4 4 4 4 4
43187 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43188 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43189 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43190 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43191 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43192 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43193 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43194 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43195 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43196 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43197 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43200 +4 4 4 4 4 4
43201 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43202 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43203 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43204 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43205 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43206 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43207 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43208 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43209 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43210 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43211 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43214 +4 4 4 4 4 4
43215 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43216 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43217 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43218 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43219 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43220 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43221 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43222 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43223 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43224 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
43225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43228 +4 4 4 4 4 4
43229 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43230 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43231 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43232 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43233 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43234 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43235 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43236 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43237 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43238 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43242 +4 4 4 4 4 4
43243 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43244 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43245 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43246 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43247 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43248 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43249 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43250 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43251 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43252 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43256 +4 4 4 4 4 4
43257 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43258 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43259 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43260 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43261 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43262 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43263 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43264 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43265 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43266 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43270 +4 4 4 4 4 4
43271 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43272 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43273 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43274 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43275 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43276 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43277 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43278 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43279 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
43280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43284 +4 4 4 4 4 4
43285 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43286 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43287 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43288 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43289 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43290 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43291 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43292 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43293 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
43294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43298 +4 4 4 4 4 4
43299 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43300 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43301 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43302 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43303 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43304 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43305 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43306 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43307 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43312 +4 4 4 4 4 4
43313 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43314 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43315 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43316 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43317 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43318 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43319 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43320 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
43321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43326 +4 4 4 4 4 4
43327 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43328 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43329 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43330 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43331 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43332 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43333 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43334 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43340 +4 4 4 4 4 4
43341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43342 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43343 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43344 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43345 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43346 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43347 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43348 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
43349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43354 +4 4 4 4 4 4
43355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43356 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43357 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43358 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43359 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43360 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43361 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43362 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
43363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43368 +4 4 4 4 4 4
43369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43370 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43371 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43372 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43373 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43374 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43375 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43376 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43382 +4 4 4 4 4 4
43383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43385 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43386 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43387 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43388 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43389 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
43390 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43396 +4 4 4 4 4 4
43397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43400 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43401 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
43402 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
43403 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
43404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43410 +4 4 4 4 4 4
43411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43414 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43415 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43416 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
43417 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
43418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43424 +4 4 4 4 4 4
43425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43428 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43429 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43430 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43431 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
43432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43438 +4 4 4 4 4 4
43439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43442 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
43443 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
43444 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
43445 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
43446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43452 +4 4 4 4 4 4
43453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43457 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
43458 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43459 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43466 +4 4 4 4 4 4
43467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43471 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
43472 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
43473 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43480 +4 4 4 4 4 4
43481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43485 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
43486 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
43487 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43494 +4 4 4 4 4 4
43495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43499 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
43500 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
43501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43508 +4 4 4 4 4 4
43509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43513 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43514 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
43515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43522 +4 4 4 4 4 4
43523 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
43524 index 86d449e..af6a7f7 100644
43525 --- a/drivers/video/udlfb.c
43526 +++ b/drivers/video/udlfb.c
43527 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
43528 dlfb_urb_completion(urb);
43529
43530 error:
43531 - atomic_add(bytes_sent, &dev->bytes_sent);
43532 - atomic_add(bytes_identical, &dev->bytes_identical);
43533 - atomic_add(width*height*2, &dev->bytes_rendered);
43534 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43535 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43536 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
43537 end_cycles = get_cycles();
43538 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
43539 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43540 >> 10)), /* Kcycles */
43541 &dev->cpu_kcycles_used);
43542
43543 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
43544 dlfb_urb_completion(urb);
43545
43546 error:
43547 - atomic_add(bytes_sent, &dev->bytes_sent);
43548 - atomic_add(bytes_identical, &dev->bytes_identical);
43549 - atomic_add(bytes_rendered, &dev->bytes_rendered);
43550 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43551 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43552 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
43553 end_cycles = get_cycles();
43554 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
43555 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43556 >> 10)), /* Kcycles */
43557 &dev->cpu_kcycles_used);
43558 }
43559 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
43560 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43561 struct dlfb_data *dev = fb_info->par;
43562 return snprintf(buf, PAGE_SIZE, "%u\n",
43563 - atomic_read(&dev->bytes_rendered));
43564 + atomic_read_unchecked(&dev->bytes_rendered));
43565 }
43566
43567 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43568 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43569 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43570 struct dlfb_data *dev = fb_info->par;
43571 return snprintf(buf, PAGE_SIZE, "%u\n",
43572 - atomic_read(&dev->bytes_identical));
43573 + atomic_read_unchecked(&dev->bytes_identical));
43574 }
43575
43576 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43577 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43578 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43579 struct dlfb_data *dev = fb_info->par;
43580 return snprintf(buf, PAGE_SIZE, "%u\n",
43581 - atomic_read(&dev->bytes_sent));
43582 + atomic_read_unchecked(&dev->bytes_sent));
43583 }
43584
43585 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43586 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43587 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43588 struct dlfb_data *dev = fb_info->par;
43589 return snprintf(buf, PAGE_SIZE, "%u\n",
43590 - atomic_read(&dev->cpu_kcycles_used));
43591 + atomic_read_unchecked(&dev->cpu_kcycles_used));
43592 }
43593
43594 static ssize_t edid_show(
43595 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
43596 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43597 struct dlfb_data *dev = fb_info->par;
43598
43599 - atomic_set(&dev->bytes_rendered, 0);
43600 - atomic_set(&dev->bytes_identical, 0);
43601 - atomic_set(&dev->bytes_sent, 0);
43602 - atomic_set(&dev->cpu_kcycles_used, 0);
43603 + atomic_set_unchecked(&dev->bytes_rendered, 0);
43604 + atomic_set_unchecked(&dev->bytes_identical, 0);
43605 + atomic_set_unchecked(&dev->bytes_sent, 0);
43606 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
43607
43608 return count;
43609 }
43610 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
43611 index 2f8f82d..191de37 100644
43612 --- a/drivers/video/uvesafb.c
43613 +++ b/drivers/video/uvesafb.c
43614 @@ -19,6 +19,7 @@
43615 #include <linux/io.h>
43616 #include <linux/mutex.h>
43617 #include <linux/slab.h>
43618 +#include <linux/moduleloader.h>
43619 #include <video/edid.h>
43620 #include <video/uvesafb.h>
43621 #ifdef CONFIG_X86
43622 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
43623 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
43624 par->pmi_setpal = par->ypan = 0;
43625 } else {
43626 +
43627 +#ifdef CONFIG_PAX_KERNEXEC
43628 +#ifdef CONFIG_MODULES
43629 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
43630 +#endif
43631 + if (!par->pmi_code) {
43632 + par->pmi_setpal = par->ypan = 0;
43633 + return 0;
43634 + }
43635 +#endif
43636 +
43637 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
43638 + task->t.regs.edi);
43639 +
43640 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43641 + pax_open_kernel();
43642 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
43643 + pax_close_kernel();
43644 +
43645 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
43646 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
43647 +#else
43648 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
43649 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
43650 +#endif
43651 +
43652 printk(KERN_INFO "uvesafb: protected mode interface info at "
43653 "%04x:%04x\n",
43654 (u16)task->t.regs.es, (u16)task->t.regs.edi);
43655 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
43656 par->ypan = ypan;
43657
43658 if (par->pmi_setpal || par->ypan) {
43659 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
43660 if (__supported_pte_mask & _PAGE_NX) {
43661 par->pmi_setpal = par->ypan = 0;
43662 printk(KERN_WARNING "uvesafb: NX protection is actively."
43663 "We have better not to use the PMI.\n");
43664 - } else {
43665 + } else
43666 +#endif
43667 uvesafb_vbe_getpmi(task, par);
43668 - }
43669 }
43670 #else
43671 /* The protected mode interface is not available on non-x86. */
43672 @@ -1838,6 +1862,11 @@ out:
43673 if (par->vbe_modes)
43674 kfree(par->vbe_modes);
43675
43676 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43677 + if (par->pmi_code)
43678 + module_free_exec(NULL, par->pmi_code);
43679 +#endif
43680 +
43681 framebuffer_release(info);
43682 return err;
43683 }
43684 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
43685 kfree(par->vbe_state_orig);
43686 if (par->vbe_state_saved)
43687 kfree(par->vbe_state_saved);
43688 +
43689 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43690 + if (par->pmi_code)
43691 + module_free_exec(NULL, par->pmi_code);
43692 +#endif
43693 +
43694 }
43695
43696 framebuffer_release(info);
43697 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
43698 index 501b340..86bd4cf 100644
43699 --- a/drivers/video/vesafb.c
43700 +++ b/drivers/video/vesafb.c
43701 @@ -9,6 +9,7 @@
43702 */
43703
43704 #include <linux/module.h>
43705 +#include <linux/moduleloader.h>
43706 #include <linux/kernel.h>
43707 #include <linux/errno.h>
43708 #include <linux/string.h>
43709 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
43710 static int vram_total __initdata; /* Set total amount of memory */
43711 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
43712 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
43713 -static void (*pmi_start)(void) __read_mostly;
43714 -static void (*pmi_pal) (void) __read_mostly;
43715 +static void (*pmi_start)(void) __read_only;
43716 +static void (*pmi_pal) (void) __read_only;
43717 static int depth __read_mostly;
43718 static int vga_compat __read_mostly;
43719 /* --------------------------------------------------------------------- */
43720 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
43721 unsigned int size_vmode;
43722 unsigned int size_remap;
43723 unsigned int size_total;
43724 + void *pmi_code = NULL;
43725
43726 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
43727 return -ENODEV;
43728 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
43729 size_remap = size_total;
43730 vesafb_fix.smem_len = size_remap;
43731
43732 -#ifndef __i386__
43733 - screen_info.vesapm_seg = 0;
43734 -#endif
43735 -
43736 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
43737 printk(KERN_WARNING
43738 "vesafb: cannot reserve video memory at 0x%lx\n",
43739 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
43740 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
43741 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
43742
43743 +#ifdef __i386__
43744 +
43745 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43746 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
43747 + if (!pmi_code)
43748 +#elif !defined(CONFIG_PAX_KERNEXEC)
43749 + if (0)
43750 +#endif
43751 +
43752 +#endif
43753 + screen_info.vesapm_seg = 0;
43754 +
43755 if (screen_info.vesapm_seg) {
43756 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
43757 - screen_info.vesapm_seg,screen_info.vesapm_off);
43758 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
43759 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
43760 }
43761
43762 if (screen_info.vesapm_seg < 0xc000)
43763 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
43764
43765 if (ypan || pmi_setpal) {
43766 unsigned short *pmi_base;
43767 +
43768 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43769 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
43770 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
43771 +
43772 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43773 + pax_open_kernel();
43774 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
43775 +#else
43776 + pmi_code = pmi_base;
43777 +#endif
43778 +
43779 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
43780 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
43781 +
43782 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43783 + pmi_start = ktva_ktla(pmi_start);
43784 + pmi_pal = ktva_ktla(pmi_pal);
43785 + pax_close_kernel();
43786 +#endif
43787 +
43788 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
43789 if (pmi_base[3]) {
43790 printk(KERN_INFO "vesafb: pmi: ports = ");
43791 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
43792 info->node, info->fix.id);
43793 return 0;
43794 err:
43795 +
43796 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43797 + module_free_exec(NULL, pmi_code);
43798 +#endif
43799 +
43800 if (info->screen_base)
43801 iounmap(info->screen_base);
43802 framebuffer_release(info);
43803 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
43804 index 88714ae..16c2e11 100644
43805 --- a/drivers/video/via/via_clock.h
43806 +++ b/drivers/video/via/via_clock.h
43807 @@ -56,7 +56,7 @@ struct via_clock {
43808
43809 void (*set_engine_pll_state)(u8 state);
43810 void (*set_engine_pll)(struct via_pll_config config);
43811 -};
43812 +} __no_const;
43813
43814
43815 static inline u32 get_pll_internal_frequency(u32 ref_freq,
43816 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
43817 index 6b1b7e1..b2fa4d5 100644
43818 --- a/drivers/virtio/virtio_mmio.c
43819 +++ b/drivers/virtio/virtio_mmio.c
43820 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
43821
43822 resources[0].end = memparse(device, &str) - 1;
43823
43824 - processed = sscanf(str, "@%lli:%u%n:%d%n",
43825 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
43826 &base, &resources[1].start, &consumed,
43827 &vm_cmdline_id, &consumed);
43828
43829 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
43830 index fef20db..d28b1ab 100644
43831 --- a/drivers/xen/xenfs/xenstored.c
43832 +++ b/drivers/xen/xenfs/xenstored.c
43833 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
43834 static int xsd_kva_open(struct inode *inode, struct file *file)
43835 {
43836 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
43837 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43838 + NULL);
43839 +#else
43840 xen_store_interface);
43841 +#endif
43842 +
43843 if (!file->private_data)
43844 return -ENOMEM;
43845 return 0;
43846 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
43847 index 890bed5..17ae73e 100644
43848 --- a/fs/9p/vfs_inode.c
43849 +++ b/fs/9p/vfs_inode.c
43850 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43851 void
43852 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43853 {
43854 - char *s = nd_get_link(nd);
43855 + const char *s = nd_get_link(nd);
43856
43857 p9_debug(P9_DEBUG_VFS, " %s %s\n",
43858 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
43859 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
43860 index 0efd152..b5802ad 100644
43861 --- a/fs/Kconfig.binfmt
43862 +++ b/fs/Kconfig.binfmt
43863 @@ -89,7 +89,7 @@ config HAVE_AOUT
43864
43865 config BINFMT_AOUT
43866 tristate "Kernel support for a.out and ECOFF binaries"
43867 - depends on HAVE_AOUT
43868 + depends on HAVE_AOUT && BROKEN
43869 ---help---
43870 A.out (Assembler.OUTput) is a set of formats for libraries and
43871 executables used in the earliest versions of UNIX. Linux used
43872 diff --git a/fs/aio.c b/fs/aio.c
43873 index 71f613c..9d01f1f 100644
43874 --- a/fs/aio.c
43875 +++ b/fs/aio.c
43876 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
43877 size += sizeof(struct io_event) * nr_events;
43878 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43879
43880 - if (nr_pages < 0)
43881 + if (nr_pages <= 0)
43882 return -EINVAL;
43883
43884 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43885 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
43886 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43887 {
43888 ssize_t ret;
43889 + struct iovec iovstack;
43890
43891 #ifdef CONFIG_COMPAT
43892 if (compat)
43893 ret = compat_rw_copy_check_uvector(type,
43894 (struct compat_iovec __user *)kiocb->ki_buf,
43895 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43896 + kiocb->ki_nbytes, 1, &iovstack,
43897 &kiocb->ki_iovec);
43898 else
43899 #endif
43900 ret = rw_copy_check_uvector(type,
43901 (struct iovec __user *)kiocb->ki_buf,
43902 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43903 + kiocb->ki_nbytes, 1, &iovstack,
43904 &kiocb->ki_iovec);
43905 if (ret < 0)
43906 goto out;
43907 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43908 if (ret < 0)
43909 goto out;
43910
43911 + if (kiocb->ki_iovec == &iovstack) {
43912 + kiocb->ki_inline_vec = iovstack;
43913 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
43914 + }
43915 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43916 kiocb->ki_cur_seg = 0;
43917 /* ki_nbytes/left now reflect bytes instead of segs */
43918 diff --git a/fs/attr.c b/fs/attr.c
43919 index cce7df5..eaa2731 100644
43920 --- a/fs/attr.c
43921 +++ b/fs/attr.c
43922 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
43923 unsigned long limit;
43924
43925 limit = rlimit(RLIMIT_FSIZE);
43926 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43927 if (limit != RLIM_INFINITY && offset > limit)
43928 goto out_sig;
43929 if (offset > inode->i_sb->s_maxbytes)
43930 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
43931 index dce436e..55e670d 100644
43932 --- a/fs/autofs4/waitq.c
43933 +++ b/fs/autofs4/waitq.c
43934 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
43935 {
43936 unsigned long sigpipe, flags;
43937 mm_segment_t fs;
43938 - const char *data = (const char *)addr;
43939 + const char __user *data = (const char __force_user *)addr;
43940 ssize_t wr = 0;
43941
43942 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
43943 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
43944 return 1;
43945 }
43946
43947 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43948 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
43949 +#endif
43950 +
43951 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43952 enum autofs_notify notify)
43953 {
43954 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43955
43956 /* If this is a direct mount request create a dummy name */
43957 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
43958 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43959 + /* this name does get written to userland via autofs4_write() */
43960 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
43961 +#else
43962 qstr.len = sprintf(name, "%p", dentry);
43963 +#endif
43964 else {
43965 qstr.len = autofs4_getpath(sbi, dentry, &name);
43966 if (!qstr.len) {
43967 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
43968 index 2b3bda8..6a2d4be 100644
43969 --- a/fs/befs/linuxvfs.c
43970 +++ b/fs/befs/linuxvfs.c
43971 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43972 {
43973 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43974 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43975 - char *link = nd_get_link(nd);
43976 + const char *link = nd_get_link(nd);
43977 if (!IS_ERR(link))
43978 kfree(link);
43979 }
43980 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
43981 index 0e7a6f8..332b1ca 100644
43982 --- a/fs/binfmt_aout.c
43983 +++ b/fs/binfmt_aout.c
43984 @@ -16,6 +16,7 @@
43985 #include <linux/string.h>
43986 #include <linux/fs.h>
43987 #include <linux/file.h>
43988 +#include <linux/security.h>
43989 #include <linux/stat.h>
43990 #include <linux/fcntl.h>
43991 #include <linux/ptrace.h>
43992 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
43993 #endif
43994 # define START_STACK(u) ((void __user *)u.start_stack)
43995
43996 + memset(&dump, 0, sizeof(dump));
43997 +
43998 fs = get_fs();
43999 set_fs(KERNEL_DS);
44000 has_dumped = 1;
44001 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44002
44003 /* If the size of the dump file exceeds the rlimit, then see what would happen
44004 if we wrote the stack, but not the data area. */
44005 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44006 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44007 dump.u_dsize = 0;
44008
44009 /* Make sure we have enough room to write the stack and data areas. */
44010 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44011 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44012 dump.u_ssize = 0;
44013
44014 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44015 rlim = rlimit(RLIMIT_DATA);
44016 if (rlim >= RLIM_INFINITY)
44017 rlim = ~0;
44018 +
44019 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44020 if (ex.a_data + ex.a_bss > rlim)
44021 return -ENOMEM;
44022
44023 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44024
44025 install_exec_creds(bprm);
44026
44027 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44028 + current->mm->pax_flags = 0UL;
44029 +#endif
44030 +
44031 +#ifdef CONFIG_PAX_PAGEEXEC
44032 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44033 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44034 +
44035 +#ifdef CONFIG_PAX_EMUTRAMP
44036 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44037 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44038 +#endif
44039 +
44040 +#ifdef CONFIG_PAX_MPROTECT
44041 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44042 + current->mm->pax_flags |= MF_PAX_MPROTECT;
44043 +#endif
44044 +
44045 + }
44046 +#endif
44047 +
44048 if (N_MAGIC(ex) == OMAGIC) {
44049 unsigned long text_addr, map_size;
44050 loff_t pos;
44051 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44052 }
44053
44054 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44055 - PROT_READ | PROT_WRITE | PROT_EXEC,
44056 + PROT_READ | PROT_WRITE,
44057 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44058 fd_offset + ex.a_text);
44059 if (error != N_DATADDR(ex)) {
44060 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44061 index fbd9f60..d4edac0 100644
44062 --- a/fs/binfmt_elf.c
44063 +++ b/fs/binfmt_elf.c
44064 @@ -33,6 +33,7 @@
44065 #include <linux/elf.h>
44066 #include <linux/utsname.h>
44067 #include <linux/coredump.h>
44068 +#include <linux/xattr.h>
44069 #include <asm/uaccess.h>
44070 #include <asm/param.h>
44071 #include <asm/page.h>
44072 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44073 #define elf_core_dump NULL
44074 #endif
44075
44076 +#ifdef CONFIG_PAX_MPROTECT
44077 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44078 +#endif
44079 +
44080 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44081 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44082 #else
44083 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44084 .load_binary = load_elf_binary,
44085 .load_shlib = load_elf_library,
44086 .core_dump = elf_core_dump,
44087 +
44088 +#ifdef CONFIG_PAX_MPROTECT
44089 + .handle_mprotect= elf_handle_mprotect,
44090 +#endif
44091 +
44092 .min_coredump = ELF_EXEC_PAGESIZE,
44093 };
44094
44095 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44096
44097 static int set_brk(unsigned long start, unsigned long end)
44098 {
44099 + unsigned long e = end;
44100 +
44101 start = ELF_PAGEALIGN(start);
44102 end = ELF_PAGEALIGN(end);
44103 if (end > start) {
44104 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44105 if (BAD_ADDR(addr))
44106 return addr;
44107 }
44108 - current->mm->start_brk = current->mm->brk = end;
44109 + current->mm->start_brk = current->mm->brk = e;
44110 return 0;
44111 }
44112
44113 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44114 elf_addr_t __user *u_rand_bytes;
44115 const char *k_platform = ELF_PLATFORM;
44116 const char *k_base_platform = ELF_BASE_PLATFORM;
44117 - unsigned char k_rand_bytes[16];
44118 + u32 k_rand_bytes[4];
44119 int items;
44120 elf_addr_t *elf_info;
44121 int ei_index = 0;
44122 const struct cred *cred = current_cred();
44123 struct vm_area_struct *vma;
44124 + unsigned long saved_auxv[AT_VECTOR_SIZE];
44125
44126 /*
44127 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44128 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44129 * Generate 16 random bytes for userspace PRNG seeding.
44130 */
44131 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44132 - u_rand_bytes = (elf_addr_t __user *)
44133 - STACK_ALLOC(p, sizeof(k_rand_bytes));
44134 + srandom32(k_rand_bytes[0] ^ random32());
44135 + srandom32(k_rand_bytes[1] ^ random32());
44136 + srandom32(k_rand_bytes[2] ^ random32());
44137 + srandom32(k_rand_bytes[3] ^ random32());
44138 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
44139 + u_rand_bytes = (elf_addr_t __user *) p;
44140 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44141 return -EFAULT;
44142
44143 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44144 return -EFAULT;
44145 current->mm->env_end = p;
44146
44147 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44148 +
44149 /* Put the elf_info on the stack in the right place. */
44150 sp = (elf_addr_t __user *)envp + 1;
44151 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44152 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44153 return -EFAULT;
44154 return 0;
44155 }
44156 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44157 an ELF header */
44158
44159 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44160 - struct file *interpreter, unsigned long *interp_map_addr,
44161 - unsigned long no_base)
44162 + struct file *interpreter, unsigned long no_base)
44163 {
44164 struct elf_phdr *elf_phdata;
44165 struct elf_phdr *eppnt;
44166 - unsigned long load_addr = 0;
44167 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44168 int load_addr_set = 0;
44169 unsigned long last_bss = 0, elf_bss = 0;
44170 - unsigned long error = ~0UL;
44171 + unsigned long error = -EINVAL;
44172 unsigned long total_size;
44173 int retval, i, size;
44174
44175 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44176 goto out_close;
44177 }
44178
44179 +#ifdef CONFIG_PAX_SEGMEXEC
44180 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44181 + pax_task_size = SEGMEXEC_TASK_SIZE;
44182 +#endif
44183 +
44184 eppnt = elf_phdata;
44185 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44186 if (eppnt->p_type == PT_LOAD) {
44187 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44188 map_addr = elf_map(interpreter, load_addr + vaddr,
44189 eppnt, elf_prot, elf_type, total_size);
44190 total_size = 0;
44191 - if (!*interp_map_addr)
44192 - *interp_map_addr = map_addr;
44193 error = map_addr;
44194 if (BAD_ADDR(map_addr))
44195 goto out_close;
44196 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44197 k = load_addr + eppnt->p_vaddr;
44198 if (BAD_ADDR(k) ||
44199 eppnt->p_filesz > eppnt->p_memsz ||
44200 - eppnt->p_memsz > TASK_SIZE ||
44201 - TASK_SIZE - eppnt->p_memsz < k) {
44202 + eppnt->p_memsz > pax_task_size ||
44203 + pax_task_size - eppnt->p_memsz < k) {
44204 error = -ENOMEM;
44205 goto out_close;
44206 }
44207 @@ -530,6 +551,315 @@ out:
44208 return error;
44209 }
44210
44211 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44212 +#ifdef CONFIG_PAX_SOFTMODE
44213 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44214 +{
44215 + unsigned long pax_flags = 0UL;
44216 +
44217 +#ifdef CONFIG_PAX_PAGEEXEC
44218 + if (elf_phdata->p_flags & PF_PAGEEXEC)
44219 + pax_flags |= MF_PAX_PAGEEXEC;
44220 +#endif
44221 +
44222 +#ifdef CONFIG_PAX_SEGMEXEC
44223 + if (elf_phdata->p_flags & PF_SEGMEXEC)
44224 + pax_flags |= MF_PAX_SEGMEXEC;
44225 +#endif
44226 +
44227 +#ifdef CONFIG_PAX_EMUTRAMP
44228 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44229 + pax_flags |= MF_PAX_EMUTRAMP;
44230 +#endif
44231 +
44232 +#ifdef CONFIG_PAX_MPROTECT
44233 + if (elf_phdata->p_flags & PF_MPROTECT)
44234 + pax_flags |= MF_PAX_MPROTECT;
44235 +#endif
44236 +
44237 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44238 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44239 + pax_flags |= MF_PAX_RANDMMAP;
44240 +#endif
44241 +
44242 + return pax_flags;
44243 +}
44244 +#endif
44245 +
44246 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44247 +{
44248 + unsigned long pax_flags = 0UL;
44249 +
44250 +#ifdef CONFIG_PAX_PAGEEXEC
44251 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44252 + pax_flags |= MF_PAX_PAGEEXEC;
44253 +#endif
44254 +
44255 +#ifdef CONFIG_PAX_SEGMEXEC
44256 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44257 + pax_flags |= MF_PAX_SEGMEXEC;
44258 +#endif
44259 +
44260 +#ifdef CONFIG_PAX_EMUTRAMP
44261 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44262 + pax_flags |= MF_PAX_EMUTRAMP;
44263 +#endif
44264 +
44265 +#ifdef CONFIG_PAX_MPROTECT
44266 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44267 + pax_flags |= MF_PAX_MPROTECT;
44268 +#endif
44269 +
44270 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44271 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44272 + pax_flags |= MF_PAX_RANDMMAP;
44273 +#endif
44274 +
44275 + return pax_flags;
44276 +}
44277 +#endif
44278 +
44279 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44280 +#ifdef CONFIG_PAX_SOFTMODE
44281 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44282 +{
44283 + unsigned long pax_flags = 0UL;
44284 +
44285 +#ifdef CONFIG_PAX_PAGEEXEC
44286 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44287 + pax_flags |= MF_PAX_PAGEEXEC;
44288 +#endif
44289 +
44290 +#ifdef CONFIG_PAX_SEGMEXEC
44291 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44292 + pax_flags |= MF_PAX_SEGMEXEC;
44293 +#endif
44294 +
44295 +#ifdef CONFIG_PAX_EMUTRAMP
44296 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44297 + pax_flags |= MF_PAX_EMUTRAMP;
44298 +#endif
44299 +
44300 +#ifdef CONFIG_PAX_MPROTECT
44301 + if (pax_flags_softmode & MF_PAX_MPROTECT)
44302 + pax_flags |= MF_PAX_MPROTECT;
44303 +#endif
44304 +
44305 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44306 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44307 + pax_flags |= MF_PAX_RANDMMAP;
44308 +#endif
44309 +
44310 + return pax_flags;
44311 +}
44312 +#endif
44313 +
44314 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44315 +{
44316 + unsigned long pax_flags = 0UL;
44317 +
44318 +#ifdef CONFIG_PAX_PAGEEXEC
44319 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44320 + pax_flags |= MF_PAX_PAGEEXEC;
44321 +#endif
44322 +
44323 +#ifdef CONFIG_PAX_SEGMEXEC
44324 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44325 + pax_flags |= MF_PAX_SEGMEXEC;
44326 +#endif
44327 +
44328 +#ifdef CONFIG_PAX_EMUTRAMP
44329 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44330 + pax_flags |= MF_PAX_EMUTRAMP;
44331 +#endif
44332 +
44333 +#ifdef CONFIG_PAX_MPROTECT
44334 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44335 + pax_flags |= MF_PAX_MPROTECT;
44336 +#endif
44337 +
44338 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44339 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44340 + pax_flags |= MF_PAX_RANDMMAP;
44341 +#endif
44342 +
44343 + return pax_flags;
44344 +}
44345 +#endif
44346 +
44347 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44348 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44349 +{
44350 + unsigned long pax_flags = 0UL;
44351 +
44352 +#ifdef CONFIG_PAX_EI_PAX
44353 +
44354 +#ifdef CONFIG_PAX_PAGEEXEC
44355 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44356 + pax_flags |= MF_PAX_PAGEEXEC;
44357 +#endif
44358 +
44359 +#ifdef CONFIG_PAX_SEGMEXEC
44360 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44361 + pax_flags |= MF_PAX_SEGMEXEC;
44362 +#endif
44363 +
44364 +#ifdef CONFIG_PAX_EMUTRAMP
44365 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44366 + pax_flags |= MF_PAX_EMUTRAMP;
44367 +#endif
44368 +
44369 +#ifdef CONFIG_PAX_MPROTECT
44370 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44371 + pax_flags |= MF_PAX_MPROTECT;
44372 +#endif
44373 +
44374 +#ifdef CONFIG_PAX_ASLR
44375 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44376 + pax_flags |= MF_PAX_RANDMMAP;
44377 +#endif
44378 +
44379 +#else
44380 +
44381 +#ifdef CONFIG_PAX_PAGEEXEC
44382 + pax_flags |= MF_PAX_PAGEEXEC;
44383 +#endif
44384 +
44385 +#ifdef CONFIG_PAX_SEGMEXEC
44386 + pax_flags |= MF_PAX_SEGMEXEC;
44387 +#endif
44388 +
44389 +#ifdef CONFIG_PAX_MPROTECT
44390 + pax_flags |= MF_PAX_MPROTECT;
44391 +#endif
44392 +
44393 +#ifdef CONFIG_PAX_RANDMMAP
44394 + if (randomize_va_space)
44395 + pax_flags |= MF_PAX_RANDMMAP;
44396 +#endif
44397 +
44398 +#endif
44399 +
44400 + return pax_flags;
44401 +}
44402 +
44403 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
44404 +{
44405 +
44406 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44407 + unsigned long i;
44408 +
44409 + for (i = 0UL; i < elf_ex->e_phnum; i++)
44410 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
44411 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
44412 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
44413 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
44414 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
44415 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
44416 + return ~0UL;
44417 +
44418 +#ifdef CONFIG_PAX_SOFTMODE
44419 + if (pax_softmode)
44420 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
44421 + else
44422 +#endif
44423 +
44424 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
44425 + break;
44426 + }
44427 +#endif
44428 +
44429 + return ~0UL;
44430 +}
44431 +
44432 +static unsigned long pax_parse_xattr_pax(struct file * const file)
44433 +{
44434 +
44435 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44436 + ssize_t xattr_size, i;
44437 + unsigned char xattr_value[5];
44438 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
44439 +
44440 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
44441 + if (xattr_size <= 0 || xattr_size > 5)
44442 + return ~0UL;
44443 +
44444 + for (i = 0; i < xattr_size; i++)
44445 + switch (xattr_value[i]) {
44446 + default:
44447 + return ~0UL;
44448 +
44449 +#define parse_flag(option1, option2, flag) \
44450 + case option1: \
44451 + if (pax_flags_hardmode & MF_PAX_##flag) \
44452 + return ~0UL; \
44453 + pax_flags_hardmode |= MF_PAX_##flag; \
44454 + break; \
44455 + case option2: \
44456 + if (pax_flags_softmode & MF_PAX_##flag) \
44457 + return ~0UL; \
44458 + pax_flags_softmode |= MF_PAX_##flag; \
44459 + break;
44460 +
44461 + parse_flag('p', 'P', PAGEEXEC);
44462 + parse_flag('e', 'E', EMUTRAMP);
44463 + parse_flag('m', 'M', MPROTECT);
44464 + parse_flag('r', 'R', RANDMMAP);
44465 + parse_flag('s', 'S', SEGMEXEC);
44466 +
44467 +#undef parse_flag
44468 + }
44469 +
44470 + if (pax_flags_hardmode & pax_flags_softmode)
44471 + return ~0UL;
44472 +
44473 +#ifdef CONFIG_PAX_SOFTMODE
44474 + if (pax_softmode)
44475 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
44476 + else
44477 +#endif
44478 +
44479 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
44480 +#else
44481 + return ~0UL;
44482 +#endif
44483 +
44484 +}
44485 +
44486 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
44487 +{
44488 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
44489 +
44490 + pax_flags = pax_parse_ei_pax(elf_ex);
44491 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
44492 + xattr_pax_flags = pax_parse_xattr_pax(file);
44493 +
44494 + if (pt_pax_flags == ~0UL)
44495 + pt_pax_flags = xattr_pax_flags;
44496 + else if (xattr_pax_flags == ~0UL)
44497 + xattr_pax_flags = pt_pax_flags;
44498 + if (pt_pax_flags != xattr_pax_flags)
44499 + return -EINVAL;
44500 + if (pt_pax_flags != ~0UL)
44501 + pax_flags = pt_pax_flags;
44502 +
44503 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
44504 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44505 + if ((__supported_pte_mask & _PAGE_NX))
44506 + pax_flags &= ~MF_PAX_SEGMEXEC;
44507 + else
44508 + pax_flags &= ~MF_PAX_PAGEEXEC;
44509 + }
44510 +#endif
44511 +
44512 + if (0 > pax_check_flags(&pax_flags))
44513 + return -EINVAL;
44514 +
44515 + current->mm->pax_flags = pax_flags;
44516 + return 0;
44517 +}
44518 +#endif
44519 +
44520 /*
44521 * These are the functions used to load ELF style executables and shared
44522 * libraries. There is no binary dependent code anywhere else.
44523 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
44524 {
44525 unsigned int random_variable = 0;
44526
44527 +#ifdef CONFIG_PAX_RANDUSTACK
44528 + if (randomize_va_space)
44529 + return stack_top - current->mm->delta_stack;
44530 +#endif
44531 +
44532 if ((current->flags & PF_RANDOMIZE) &&
44533 !(current->personality & ADDR_NO_RANDOMIZE)) {
44534 random_variable = get_random_int() & STACK_RND_MASK;
44535 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44536 unsigned long load_addr = 0, load_bias = 0;
44537 int load_addr_set = 0;
44538 char * elf_interpreter = NULL;
44539 - unsigned long error;
44540 + unsigned long error = 0;
44541 struct elf_phdr *elf_ppnt, *elf_phdata;
44542 unsigned long elf_bss, elf_brk;
44543 int retval, i;
44544 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44545 unsigned long start_code, end_code, start_data, end_data;
44546 unsigned long reloc_func_desc __maybe_unused = 0;
44547 int executable_stack = EXSTACK_DEFAULT;
44548 - unsigned long def_flags = 0;
44549 struct {
44550 struct elfhdr elf_ex;
44551 struct elfhdr interp_elf_ex;
44552 } *loc;
44553 + unsigned long pax_task_size = TASK_SIZE;
44554
44555 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
44556 if (!loc) {
44557 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44558 goto out_free_dentry;
44559
44560 /* OK, This is the point of no return */
44561 - current->mm->def_flags = def_flags;
44562 +
44563 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44564 + current->mm->pax_flags = 0UL;
44565 +#endif
44566 +
44567 +#ifdef CONFIG_PAX_DLRESOLVE
44568 + current->mm->call_dl_resolve = 0UL;
44569 +#endif
44570 +
44571 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
44572 + current->mm->call_syscall = 0UL;
44573 +#endif
44574 +
44575 +#ifdef CONFIG_PAX_ASLR
44576 + current->mm->delta_mmap = 0UL;
44577 + current->mm->delta_stack = 0UL;
44578 +#endif
44579 +
44580 + current->mm->def_flags = 0;
44581 +
44582 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44583 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
44584 + send_sig(SIGKILL, current, 0);
44585 + goto out_free_dentry;
44586 + }
44587 +#endif
44588 +
44589 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44590 + pax_set_initial_flags(bprm);
44591 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
44592 + if (pax_set_initial_flags_func)
44593 + (pax_set_initial_flags_func)(bprm);
44594 +#endif
44595 +
44596 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
44597 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
44598 + current->mm->context.user_cs_limit = PAGE_SIZE;
44599 + current->mm->def_flags |= VM_PAGEEXEC;
44600 + }
44601 +#endif
44602 +
44603 +#ifdef CONFIG_PAX_SEGMEXEC
44604 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
44605 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
44606 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
44607 + pax_task_size = SEGMEXEC_TASK_SIZE;
44608 + current->mm->def_flags |= VM_NOHUGEPAGE;
44609 + }
44610 +#endif
44611 +
44612 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
44613 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44614 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
44615 + put_cpu();
44616 + }
44617 +#endif
44618
44619 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
44620 may depend on the personality. */
44621 SET_PERSONALITY(loc->elf_ex);
44622 +
44623 +#ifdef CONFIG_PAX_ASLR
44624 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44625 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
44626 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
44627 + }
44628 +#endif
44629 +
44630 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44631 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44632 + executable_stack = EXSTACK_DISABLE_X;
44633 + current->personality &= ~READ_IMPLIES_EXEC;
44634 + } else
44635 +#endif
44636 +
44637 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
44638 current->personality |= READ_IMPLIES_EXEC;
44639
44640 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44641 #else
44642 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
44643 #endif
44644 +
44645 +#ifdef CONFIG_PAX_RANDMMAP
44646 + /* PaX: randomize base address at the default exe base if requested */
44647 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
44648 +#ifdef CONFIG_SPARC64
44649 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
44650 +#else
44651 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
44652 +#endif
44653 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
44654 + elf_flags |= MAP_FIXED;
44655 + }
44656 +#endif
44657 +
44658 }
44659
44660 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
44661 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44662 * allowed task size. Note that p_filesz must always be
44663 * <= p_memsz so it is only necessary to check p_memsz.
44664 */
44665 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44666 - elf_ppnt->p_memsz > TASK_SIZE ||
44667 - TASK_SIZE - elf_ppnt->p_memsz < k) {
44668 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44669 + elf_ppnt->p_memsz > pax_task_size ||
44670 + pax_task_size - elf_ppnt->p_memsz < k) {
44671 /* set_brk can never work. Avoid overflows. */
44672 send_sig(SIGKILL, current, 0);
44673 retval = -EINVAL;
44674 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44675 goto out_free_dentry;
44676 }
44677 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
44678 - send_sig(SIGSEGV, current, 0);
44679 - retval = -EFAULT; /* Nobody gets to see this, but.. */
44680 - goto out_free_dentry;
44681 + /*
44682 + * This bss-zeroing can fail if the ELF
44683 + * file specifies odd protections. So
44684 + * we don't check the return value
44685 + */
44686 }
44687
44688 +#ifdef CONFIG_PAX_RANDMMAP
44689 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44690 + unsigned long start, size;
44691 +
44692 + start = ELF_PAGEALIGN(elf_brk);
44693 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
44694 + down_read(&current->mm->mmap_sem);
44695 + retval = -ENOMEM;
44696 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
44697 + unsigned long prot = PROT_NONE;
44698 +
44699 + up_read(&current->mm->mmap_sem);
44700 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
44701 +// if (current->personality & ADDR_NO_RANDOMIZE)
44702 +// prot = PROT_READ;
44703 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
44704 + retval = IS_ERR_VALUE(start) ? start : 0;
44705 + } else
44706 + up_read(&current->mm->mmap_sem);
44707 + if (retval == 0)
44708 + retval = set_brk(start + size, start + size + PAGE_SIZE);
44709 + if (retval < 0) {
44710 + send_sig(SIGKILL, current, 0);
44711 + goto out_free_dentry;
44712 + }
44713 + }
44714 +#endif
44715 +
44716 if (elf_interpreter) {
44717 - unsigned long interp_map_addr = 0;
44718 -
44719 elf_entry = load_elf_interp(&loc->interp_elf_ex,
44720 interpreter,
44721 - &interp_map_addr,
44722 load_bias);
44723 if (!IS_ERR((void *)elf_entry)) {
44724 /*
44725 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
44726 * Decide what to dump of a segment, part, all or none.
44727 */
44728 static unsigned long vma_dump_size(struct vm_area_struct *vma,
44729 - unsigned long mm_flags)
44730 + unsigned long mm_flags, long signr)
44731 {
44732 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
44733
44734 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
44735 if (vma->vm_file == NULL)
44736 return 0;
44737
44738 - if (FILTER(MAPPED_PRIVATE))
44739 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
44740 goto whole;
44741
44742 /*
44743 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
44744 {
44745 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
44746 int i = 0;
44747 - do
44748 + do {
44749 i += 2;
44750 - while (auxv[i - 2] != AT_NULL);
44751 + } while (auxv[i - 2] != AT_NULL);
44752 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
44753 }
44754
44755 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
44756 }
44757
44758 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
44759 - unsigned long mm_flags)
44760 + struct coredump_params *cprm)
44761 {
44762 struct vm_area_struct *vma;
44763 size_t size = 0;
44764
44765 for (vma = first_vma(current, gate_vma); vma != NULL;
44766 vma = next_vma(vma, gate_vma))
44767 - size += vma_dump_size(vma, mm_flags);
44768 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
44769 return size;
44770 }
44771
44772 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44773
44774 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
44775
44776 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
44777 + offset += elf_core_vma_data_size(gate_vma, cprm);
44778 offset += elf_core_extra_data_size();
44779 e_shoff = offset;
44780
44781 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
44782 offset = dataoff;
44783
44784 size += sizeof(*elf);
44785 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44786 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
44787 goto end_coredump;
44788
44789 size += sizeof(*phdr4note);
44790 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44791 if (size > cprm->limit
44792 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
44793 goto end_coredump;
44794 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44795 phdr.p_offset = offset;
44796 phdr.p_vaddr = vma->vm_start;
44797 phdr.p_paddr = 0;
44798 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
44799 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
44800 phdr.p_memsz = vma->vm_end - vma->vm_start;
44801 offset += phdr.p_filesz;
44802 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
44803 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44804 phdr.p_align = ELF_EXEC_PAGESIZE;
44805
44806 size += sizeof(phdr);
44807 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44808 if (size > cprm->limit
44809 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
44810 goto end_coredump;
44811 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44812 unsigned long addr;
44813 unsigned long end;
44814
44815 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
44816 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
44817
44818 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
44819 struct page *page;
44820 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44821 page = get_dump_page(addr);
44822 if (page) {
44823 void *kaddr = kmap(page);
44824 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
44825 stop = ((size += PAGE_SIZE) > cprm->limit) ||
44826 !dump_write(cprm->file, kaddr,
44827 PAGE_SIZE);
44828 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44829
44830 if (e_phnum == PN_XNUM) {
44831 size += sizeof(*shdr4extnum);
44832 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44833 if (size > cprm->limit
44834 || !dump_write(cprm->file, shdr4extnum,
44835 sizeof(*shdr4extnum)))
44836 @@ -2216,6 +2667,97 @@ out:
44837
44838 #endif /* CONFIG_ELF_CORE */
44839
44840 +#ifdef CONFIG_PAX_MPROTECT
44841 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
44842 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
44843 + * we'll remove VM_MAYWRITE for good on RELRO segments.
44844 + *
44845 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
44846 + * basis because we want to allow the common case and not the special ones.
44847 + */
44848 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
44849 +{
44850 + struct elfhdr elf_h;
44851 + struct elf_phdr elf_p;
44852 + unsigned long i;
44853 + unsigned long oldflags;
44854 + bool is_textrel_rw, is_textrel_rx, is_relro;
44855 +
44856 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
44857 + return;
44858 +
44859 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44860 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44861 +
44862 +#ifdef CONFIG_PAX_ELFRELOCS
44863 + /* possible TEXTREL */
44864 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44865 + 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);
44866 +#else
44867 + is_textrel_rw = false;
44868 + is_textrel_rx = false;
44869 +#endif
44870 +
44871 + /* possible RELRO */
44872 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44873 +
44874 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44875 + return;
44876 +
44877 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44878 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44879 +
44880 +#ifdef CONFIG_PAX_ETEXECRELOCS
44881 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44882 +#else
44883 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44884 +#endif
44885 +
44886 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44887 + !elf_check_arch(&elf_h) ||
44888 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44889 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44890 + return;
44891 +
44892 + for (i = 0UL; i < elf_h.e_phnum; i++) {
44893 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44894 + return;
44895 + switch (elf_p.p_type) {
44896 + case PT_DYNAMIC:
44897 + if (!is_textrel_rw && !is_textrel_rx)
44898 + continue;
44899 + i = 0UL;
44900 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44901 + elf_dyn dyn;
44902 +
44903 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44904 + return;
44905 + if (dyn.d_tag == DT_NULL)
44906 + return;
44907 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44908 + gr_log_textrel(vma);
44909 + if (is_textrel_rw)
44910 + vma->vm_flags |= VM_MAYWRITE;
44911 + else
44912 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44913 + vma->vm_flags &= ~VM_MAYWRITE;
44914 + return;
44915 + }
44916 + i++;
44917 + }
44918 + return;
44919 +
44920 + case PT_GNU_RELRO:
44921 + if (!is_relro)
44922 + continue;
44923 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44924 + vma->vm_flags &= ~VM_MAYWRITE;
44925 + return;
44926 + }
44927 + }
44928 +}
44929 +#endif
44930 +
44931 static int __init init_elf_binfmt(void)
44932 {
44933 register_binfmt(&elf_format);
44934 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
44935 index e280352..7b2f231 100644
44936 --- a/fs/binfmt_flat.c
44937 +++ b/fs/binfmt_flat.c
44938 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
44939 realdatastart = (unsigned long) -ENOMEM;
44940 printk("Unable to allocate RAM for process data, errno %d\n",
44941 (int)-realdatastart);
44942 + down_write(&current->mm->mmap_sem);
44943 vm_munmap(textpos, text_len);
44944 + up_write(&current->mm->mmap_sem);
44945 ret = realdatastart;
44946 goto err;
44947 }
44948 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44949 }
44950 if (IS_ERR_VALUE(result)) {
44951 printk("Unable to read data+bss, errno %d\n", (int)-result);
44952 + down_write(&current->mm->mmap_sem);
44953 vm_munmap(textpos, text_len);
44954 vm_munmap(realdatastart, len);
44955 + up_write(&current->mm->mmap_sem);
44956 ret = result;
44957 goto err;
44958 }
44959 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44960 }
44961 if (IS_ERR_VALUE(result)) {
44962 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44963 + down_write(&current->mm->mmap_sem);
44964 vm_munmap(textpos, text_len + data_len + extra +
44965 MAX_SHARED_LIBS * sizeof(unsigned long));
44966 + up_write(&current->mm->mmap_sem);
44967 ret = result;
44968 goto err;
44969 }
44970 diff --git a/fs/bio.c b/fs/bio.c
44971 index b96fc6c..431d628 100644
44972 --- a/fs/bio.c
44973 +++ b/fs/bio.c
44974 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
44975 /*
44976 * Overflow, abort
44977 */
44978 - if (end < start)
44979 + if (end < start || end - start > INT_MAX - nr_pages)
44980 return ERR_PTR(-EINVAL);
44981
44982 nr_pages += end - start;
44983 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
44984 /*
44985 * Overflow, abort
44986 */
44987 - if (end < start)
44988 + if (end < start || end - start > INT_MAX - nr_pages)
44989 return ERR_PTR(-EINVAL);
44990
44991 nr_pages += end - start;
44992 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
44993 const int read = bio_data_dir(bio) == READ;
44994 struct bio_map_data *bmd = bio->bi_private;
44995 int i;
44996 - char *p = bmd->sgvecs[0].iov_base;
44997 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
44998
44999 __bio_for_each_segment(bvec, bio, i, 0) {
45000 char *addr = page_address(bvec->bv_page);
45001 diff --git a/fs/block_dev.c b/fs/block_dev.c
45002 index ab3a456..7da538b 100644
45003 --- a/fs/block_dev.c
45004 +++ b/fs/block_dev.c
45005 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45006 else if (bdev->bd_contains == bdev)
45007 return true; /* is a whole device which isn't held */
45008
45009 - else if (whole->bd_holder == bd_may_claim)
45010 + else if (whole->bd_holder == (void *)bd_may_claim)
45011 return true; /* is a partition of a device that is being partitioned */
45012 else if (whole->bd_holder != NULL)
45013 return false; /* is a partition of a held device */
45014 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45015 index cdfb4c4..da736d4 100644
45016 --- a/fs/btrfs/ctree.c
45017 +++ b/fs/btrfs/ctree.c
45018 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45019 free_extent_buffer(buf);
45020 add_root_to_dirty_list(root);
45021 } else {
45022 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45023 - parent_start = parent->start;
45024 - else
45025 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45026 + if (parent)
45027 + parent_start = parent->start;
45028 + else
45029 + parent_start = 0;
45030 + } else
45031 parent_start = 0;
45032
45033 WARN_ON(trans->transid != btrfs_header_generation(parent));
45034 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45035 index 95542a1..95a8727 100644
45036 --- a/fs/btrfs/inode.c
45037 +++ b/fs/btrfs/inode.c
45038 @@ -7243,7 +7243,7 @@ fail:
45039 return -ENOMEM;
45040 }
45041
45042 -static int btrfs_getattr(struct vfsmount *mnt,
45043 +int btrfs_getattr(struct vfsmount *mnt,
45044 struct dentry *dentry, struct kstat *stat)
45045 {
45046 struct inode *inode = dentry->d_inode;
45047 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45048 return 0;
45049 }
45050
45051 +EXPORT_SYMBOL(btrfs_getattr);
45052 +
45053 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
45054 +{
45055 + return BTRFS_I(inode)->root->anon_dev;
45056 +}
45057 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45058 +
45059 /*
45060 * If a file is moved, it will inherit the cow and compression flags of the new
45061 * directory.
45062 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45063 index 8fcf9a5..a200000 100644
45064 --- a/fs/btrfs/ioctl.c
45065 +++ b/fs/btrfs/ioctl.c
45066 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45067 for (i = 0; i < num_types; i++) {
45068 struct btrfs_space_info *tmp;
45069
45070 + /* Don't copy in more than we allocated */
45071 if (!slot_count)
45072 break;
45073
45074 + slot_count--;
45075 +
45076 info = NULL;
45077 rcu_read_lock();
45078 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45079 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45080 memcpy(dest, &space, sizeof(space));
45081 dest++;
45082 space_args.total_spaces++;
45083 - slot_count--;
45084 }
45085 - if (!slot_count)
45086 - break;
45087 }
45088 up_read(&info->groups_sem);
45089 }
45090 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45091 index 776f0aa..3aad281 100644
45092 --- a/fs/btrfs/relocation.c
45093 +++ b/fs/btrfs/relocation.c
45094 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45095 }
45096 spin_unlock(&rc->reloc_root_tree.lock);
45097
45098 - BUG_ON((struct btrfs_root *)node->data != root);
45099 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
45100
45101 if (!del) {
45102 spin_lock(&rc->reloc_root_tree.lock);
45103 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45104 index 622f469..e8d2d55 100644
45105 --- a/fs/cachefiles/bind.c
45106 +++ b/fs/cachefiles/bind.c
45107 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45108 args);
45109
45110 /* start by checking things over */
45111 - ASSERT(cache->fstop_percent >= 0 &&
45112 - cache->fstop_percent < cache->fcull_percent &&
45113 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
45114 cache->fcull_percent < cache->frun_percent &&
45115 cache->frun_percent < 100);
45116
45117 - ASSERT(cache->bstop_percent >= 0 &&
45118 - cache->bstop_percent < cache->bcull_percent &&
45119 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
45120 cache->bcull_percent < cache->brun_percent &&
45121 cache->brun_percent < 100);
45122
45123 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45124 index 0a1467b..6a53245 100644
45125 --- a/fs/cachefiles/daemon.c
45126 +++ b/fs/cachefiles/daemon.c
45127 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45128 if (n > buflen)
45129 return -EMSGSIZE;
45130
45131 - if (copy_to_user(_buffer, buffer, n) != 0)
45132 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45133 return -EFAULT;
45134
45135 return n;
45136 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45137 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45138 return -EIO;
45139
45140 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
45141 + if (datalen > PAGE_SIZE - 1)
45142 return -EOPNOTSUPP;
45143
45144 /* drag the command string into the kernel so we can parse it */
45145 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45146 if (args[0] != '%' || args[1] != '\0')
45147 return -EINVAL;
45148
45149 - if (fstop < 0 || fstop >= cache->fcull_percent)
45150 + if (fstop >= cache->fcull_percent)
45151 return cachefiles_daemon_range_error(cache, args);
45152
45153 cache->fstop_percent = fstop;
45154 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45155 if (args[0] != '%' || args[1] != '\0')
45156 return -EINVAL;
45157
45158 - if (bstop < 0 || bstop >= cache->bcull_percent)
45159 + if (bstop >= cache->bcull_percent)
45160 return cachefiles_daemon_range_error(cache, args);
45161
45162 cache->bstop_percent = bstop;
45163 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45164 index bd6bc1b..b627b53 100644
45165 --- a/fs/cachefiles/internal.h
45166 +++ b/fs/cachefiles/internal.h
45167 @@ -57,7 +57,7 @@ struct cachefiles_cache {
45168 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45169 struct rb_root active_nodes; /* active nodes (can't be culled) */
45170 rwlock_t active_lock; /* lock for active_nodes */
45171 - atomic_t gravecounter; /* graveyard uniquifier */
45172 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45173 unsigned frun_percent; /* when to stop culling (% files) */
45174 unsigned fcull_percent; /* when to start culling (% files) */
45175 unsigned fstop_percent; /* when to stop allocating (% files) */
45176 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45177 * proc.c
45178 */
45179 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45180 -extern atomic_t cachefiles_lookup_histogram[HZ];
45181 -extern atomic_t cachefiles_mkdir_histogram[HZ];
45182 -extern atomic_t cachefiles_create_histogram[HZ];
45183 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45184 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45185 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45186
45187 extern int __init cachefiles_proc_init(void);
45188 extern void cachefiles_proc_cleanup(void);
45189 static inline
45190 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45191 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45192 {
45193 unsigned long jif = jiffies - start_jif;
45194 if (jif >= HZ)
45195 jif = HZ - 1;
45196 - atomic_inc(&histogram[jif]);
45197 + atomic_inc_unchecked(&histogram[jif]);
45198 }
45199
45200 #else
45201 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45202 index b0b5f7c..039bb26 100644
45203 --- a/fs/cachefiles/namei.c
45204 +++ b/fs/cachefiles/namei.c
45205 @@ -318,7 +318,7 @@ try_again:
45206 /* first step is to make up a grave dentry in the graveyard */
45207 sprintf(nbuffer, "%08x%08x",
45208 (uint32_t) get_seconds(),
45209 - (uint32_t) atomic_inc_return(&cache->gravecounter));
45210 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45211
45212 /* do the multiway lock magic */
45213 trap = lock_rename(cache->graveyard, dir);
45214 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45215 index eccd339..4c1d995 100644
45216 --- a/fs/cachefiles/proc.c
45217 +++ b/fs/cachefiles/proc.c
45218 @@ -14,9 +14,9 @@
45219 #include <linux/seq_file.h>
45220 #include "internal.h"
45221
45222 -atomic_t cachefiles_lookup_histogram[HZ];
45223 -atomic_t cachefiles_mkdir_histogram[HZ];
45224 -atomic_t cachefiles_create_histogram[HZ];
45225 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45226 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45227 +atomic_unchecked_t cachefiles_create_histogram[HZ];
45228
45229 /*
45230 * display the latency histogram
45231 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45232 return 0;
45233 default:
45234 index = (unsigned long) v - 3;
45235 - x = atomic_read(&cachefiles_lookup_histogram[index]);
45236 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
45237 - z = atomic_read(&cachefiles_create_histogram[index]);
45238 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45239 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45240 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45241 if (x == 0 && y == 0 && z == 0)
45242 return 0;
45243
45244 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45245 index c994691..2a1537f 100644
45246 --- a/fs/cachefiles/rdwr.c
45247 +++ b/fs/cachefiles/rdwr.c
45248 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45249 old_fs = get_fs();
45250 set_fs(KERNEL_DS);
45251 ret = file->f_op->write(
45252 - file, (const void __user *) data, len, &pos);
45253 + file, (const void __force_user *) data, len, &pos);
45254 set_fs(old_fs);
45255 kunmap(page);
45256 if (ret != len)
45257 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45258 index e5b7731..b9c59fb 100644
45259 --- a/fs/ceph/dir.c
45260 +++ b/fs/ceph/dir.c
45261 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45262 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45263 struct ceph_mds_client *mdsc = fsc->mdsc;
45264 unsigned frag = fpos_frag(filp->f_pos);
45265 - int off = fpos_off(filp->f_pos);
45266 + unsigned int off = fpos_off(filp->f_pos);
45267 int err;
45268 u32 ftype;
45269 struct ceph_mds_reply_info_parsed *rinfo;
45270 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45271 index d9ea6ed..1e6c8ac 100644
45272 --- a/fs/cifs/cifs_debug.c
45273 +++ b/fs/cifs/cifs_debug.c
45274 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45275
45276 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45277 #ifdef CONFIG_CIFS_STATS2
45278 - atomic_set(&totBufAllocCount, 0);
45279 - atomic_set(&totSmBufAllocCount, 0);
45280 + atomic_set_unchecked(&totBufAllocCount, 0);
45281 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45282 #endif /* CONFIG_CIFS_STATS2 */
45283 spin_lock(&cifs_tcp_ses_lock);
45284 list_for_each(tmp1, &cifs_tcp_ses_list) {
45285 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45286 tcon = list_entry(tmp3,
45287 struct cifs_tcon,
45288 tcon_list);
45289 - atomic_set(&tcon->num_smbs_sent, 0);
45290 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45291 if (server->ops->clear_stats)
45292 server->ops->clear_stats(tcon);
45293 }
45294 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45295 smBufAllocCount.counter, cifs_min_small);
45296 #ifdef CONFIG_CIFS_STATS2
45297 seq_printf(m, "Total Large %d Small %d Allocations\n",
45298 - atomic_read(&totBufAllocCount),
45299 - atomic_read(&totSmBufAllocCount));
45300 + atomic_read_unchecked(&totBufAllocCount),
45301 + atomic_read_unchecked(&totSmBufAllocCount));
45302 #endif /* CONFIG_CIFS_STATS2 */
45303
45304 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45305 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45306 if (tcon->need_reconnect)
45307 seq_puts(m, "\tDISCONNECTED ");
45308 seq_printf(m, "\nSMBs: %d",
45309 - atomic_read(&tcon->num_smbs_sent));
45310 + atomic_read_unchecked(&tcon->num_smbs_sent));
45311 if (server->ops->print_stats)
45312 server->ops->print_stats(m, tcon);
45313 }
45314 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45315 index e7931cc..76a1ab9 100644
45316 --- a/fs/cifs/cifsfs.c
45317 +++ b/fs/cifs/cifsfs.c
45318 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45319 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45320 cifs_req_cachep = kmem_cache_create("cifs_request",
45321 CIFSMaxBufSize + max_hdr_size, 0,
45322 - SLAB_HWCACHE_ALIGN, NULL);
45323 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45324 if (cifs_req_cachep == NULL)
45325 return -ENOMEM;
45326
45327 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45328 efficient to alloc 1 per page off the slab compared to 17K (5page)
45329 alloc of large cifs buffers even when page debugging is on */
45330 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45331 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45332 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45333 NULL);
45334 if (cifs_sm_req_cachep == NULL) {
45335 mempool_destroy(cifs_req_poolp);
45336 @@ -1111,8 +1111,8 @@ init_cifs(void)
45337 atomic_set(&bufAllocCount, 0);
45338 atomic_set(&smBufAllocCount, 0);
45339 #ifdef CONFIG_CIFS_STATS2
45340 - atomic_set(&totBufAllocCount, 0);
45341 - atomic_set(&totSmBufAllocCount, 0);
45342 + atomic_set_unchecked(&totBufAllocCount, 0);
45343 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45344 #endif /* CONFIG_CIFS_STATS2 */
45345
45346 atomic_set(&midCount, 0);
45347 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45348 index f5af252..489b5f2 100644
45349 --- a/fs/cifs/cifsglob.h
45350 +++ b/fs/cifs/cifsglob.h
45351 @@ -751,35 +751,35 @@ struct cifs_tcon {
45352 __u16 Flags; /* optional support bits */
45353 enum statusEnum tidStatus;
45354 #ifdef CONFIG_CIFS_STATS
45355 - atomic_t num_smbs_sent;
45356 + atomic_unchecked_t num_smbs_sent;
45357 union {
45358 struct {
45359 - atomic_t num_writes;
45360 - atomic_t num_reads;
45361 - atomic_t num_flushes;
45362 - atomic_t num_oplock_brks;
45363 - atomic_t num_opens;
45364 - atomic_t num_closes;
45365 - atomic_t num_deletes;
45366 - atomic_t num_mkdirs;
45367 - atomic_t num_posixopens;
45368 - atomic_t num_posixmkdirs;
45369 - atomic_t num_rmdirs;
45370 - atomic_t num_renames;
45371 - atomic_t num_t2renames;
45372 - atomic_t num_ffirst;
45373 - atomic_t num_fnext;
45374 - atomic_t num_fclose;
45375 - atomic_t num_hardlinks;
45376 - atomic_t num_symlinks;
45377 - atomic_t num_locks;
45378 - atomic_t num_acl_get;
45379 - atomic_t num_acl_set;
45380 + atomic_unchecked_t num_writes;
45381 + atomic_unchecked_t num_reads;
45382 + atomic_unchecked_t num_flushes;
45383 + atomic_unchecked_t num_oplock_brks;
45384 + atomic_unchecked_t num_opens;
45385 + atomic_unchecked_t num_closes;
45386 + atomic_unchecked_t num_deletes;
45387 + atomic_unchecked_t num_mkdirs;
45388 + atomic_unchecked_t num_posixopens;
45389 + atomic_unchecked_t num_posixmkdirs;
45390 + atomic_unchecked_t num_rmdirs;
45391 + atomic_unchecked_t num_renames;
45392 + atomic_unchecked_t num_t2renames;
45393 + atomic_unchecked_t num_ffirst;
45394 + atomic_unchecked_t num_fnext;
45395 + atomic_unchecked_t num_fclose;
45396 + atomic_unchecked_t num_hardlinks;
45397 + atomic_unchecked_t num_symlinks;
45398 + atomic_unchecked_t num_locks;
45399 + atomic_unchecked_t num_acl_get;
45400 + atomic_unchecked_t num_acl_set;
45401 } cifs_stats;
45402 #ifdef CONFIG_CIFS_SMB2
45403 struct {
45404 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45405 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45406 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45407 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45408 } smb2_stats;
45409 #endif /* CONFIG_CIFS_SMB2 */
45410 } stats;
45411 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
45412 }
45413
45414 #ifdef CONFIG_CIFS_STATS
45415 -#define cifs_stats_inc atomic_inc
45416 +#define cifs_stats_inc atomic_inc_unchecked
45417
45418 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
45419 unsigned int bytes)
45420 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
45421 /* Various Debug counters */
45422 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
45423 #ifdef CONFIG_CIFS_STATS2
45424 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
45425 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
45426 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
45427 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
45428 #endif
45429 GLOBAL_EXTERN atomic_t smBufAllocCount;
45430 GLOBAL_EXTERN atomic_t midCount;
45431 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
45432 index 51dc2fb..1e12a33 100644
45433 --- a/fs/cifs/link.c
45434 +++ b/fs/cifs/link.c
45435 @@ -616,7 +616,7 @@ symlink_exit:
45436
45437 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
45438 {
45439 - char *p = nd_get_link(nd);
45440 + const char *p = nd_get_link(nd);
45441 if (!IS_ERR(p))
45442 kfree(p);
45443 }
45444 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
45445 index 3a00c0d..42d901c 100644
45446 --- a/fs/cifs/misc.c
45447 +++ b/fs/cifs/misc.c
45448 @@ -169,7 +169,7 @@ cifs_buf_get(void)
45449 memset(ret_buf, 0, buf_size + 3);
45450 atomic_inc(&bufAllocCount);
45451 #ifdef CONFIG_CIFS_STATS2
45452 - atomic_inc(&totBufAllocCount);
45453 + atomic_inc_unchecked(&totBufAllocCount);
45454 #endif /* CONFIG_CIFS_STATS2 */
45455 }
45456
45457 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
45458 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
45459 atomic_inc(&smBufAllocCount);
45460 #ifdef CONFIG_CIFS_STATS2
45461 - atomic_inc(&totSmBufAllocCount);
45462 + atomic_inc_unchecked(&totSmBufAllocCount);
45463 #endif /* CONFIG_CIFS_STATS2 */
45464
45465 }
45466 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
45467 index 591bf19..690d600 100644
45468 --- a/fs/cifs/smb1ops.c
45469 +++ b/fs/cifs/smb1ops.c
45470 @@ -617,27 +617,27 @@ static void
45471 cifs_clear_stats(struct cifs_tcon *tcon)
45472 {
45473 #ifdef CONFIG_CIFS_STATS
45474 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
45475 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
45476 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
45477 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45478 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
45479 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
45480 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45481 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
45482 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
45483 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
45484 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
45485 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
45486 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
45487 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
45488 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
45489 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
45490 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
45491 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
45492 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
45493 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
45494 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
45495 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
45496 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
45497 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
45498 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45499 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
45500 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
45501 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45502 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
45503 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
45504 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
45505 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
45506 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
45507 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
45508 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
45509 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
45510 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
45511 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
45512 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
45513 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
45514 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
45515 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
45516 #endif
45517 }
45518
45519 @@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45520 {
45521 #ifdef CONFIG_CIFS_STATS
45522 seq_printf(m, " Oplocks breaks: %d",
45523 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
45524 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
45525 seq_printf(m, "\nReads: %d Bytes: %llu",
45526 - atomic_read(&tcon->stats.cifs_stats.num_reads),
45527 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
45528 (long long)(tcon->bytes_read));
45529 seq_printf(m, "\nWrites: %d Bytes: %llu",
45530 - atomic_read(&tcon->stats.cifs_stats.num_writes),
45531 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
45532 (long long)(tcon->bytes_written));
45533 seq_printf(m, "\nFlushes: %d",
45534 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
45535 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
45536 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
45537 - atomic_read(&tcon->stats.cifs_stats.num_locks),
45538 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
45539 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
45540 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
45541 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
45542 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
45543 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
45544 - atomic_read(&tcon->stats.cifs_stats.num_opens),
45545 - atomic_read(&tcon->stats.cifs_stats.num_closes),
45546 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
45547 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
45548 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
45549 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
45550 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
45551 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
45552 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
45553 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
45554 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
45555 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
45556 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
45557 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
45558 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
45559 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
45560 seq_printf(m, "\nRenames: %d T2 Renames %d",
45561 - atomic_read(&tcon->stats.cifs_stats.num_renames),
45562 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
45563 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
45564 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
45565 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
45566 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
45567 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
45568 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
45569 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
45570 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
45571 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
45572 #endif
45573 }
45574
45575 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
45576 index 4d9dbe0..0af4601 100644
45577 --- a/fs/cifs/smb2ops.c
45578 +++ b/fs/cifs/smb2ops.c
45579 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
45580 #ifdef CONFIG_CIFS_STATS
45581 int i;
45582 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
45583 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45584 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45585 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45586 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45587 }
45588 #endif
45589 }
45590 @@ -301,66 +301,66 @@ static void
45591 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45592 {
45593 #ifdef CONFIG_CIFS_STATS
45594 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45595 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45596 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45597 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45598 seq_printf(m, "\nNegotiates: %d sent %d failed",
45599 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
45600 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
45601 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
45602 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
45603 seq_printf(m, "\nSessionSetups: %d sent %d failed",
45604 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
45605 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
45606 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
45607 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
45608 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
45609 seq_printf(m, "\nLogoffs: %d sent %d failed",
45610 - atomic_read(&sent[SMB2_LOGOFF_HE]),
45611 - atomic_read(&failed[SMB2_LOGOFF_HE]));
45612 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
45613 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
45614 seq_printf(m, "\nTreeConnects: %d sent %d failed",
45615 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
45616 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
45617 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
45618 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
45619 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
45620 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
45621 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
45622 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
45623 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
45624 seq_printf(m, "\nCreates: %d sent %d failed",
45625 - atomic_read(&sent[SMB2_CREATE_HE]),
45626 - atomic_read(&failed[SMB2_CREATE_HE]));
45627 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
45628 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
45629 seq_printf(m, "\nCloses: %d sent %d failed",
45630 - atomic_read(&sent[SMB2_CLOSE_HE]),
45631 - atomic_read(&failed[SMB2_CLOSE_HE]));
45632 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
45633 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
45634 seq_printf(m, "\nFlushes: %d sent %d failed",
45635 - atomic_read(&sent[SMB2_FLUSH_HE]),
45636 - atomic_read(&failed[SMB2_FLUSH_HE]));
45637 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
45638 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
45639 seq_printf(m, "\nReads: %d sent %d failed",
45640 - atomic_read(&sent[SMB2_READ_HE]),
45641 - atomic_read(&failed[SMB2_READ_HE]));
45642 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
45643 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
45644 seq_printf(m, "\nWrites: %d sent %d failed",
45645 - atomic_read(&sent[SMB2_WRITE_HE]),
45646 - atomic_read(&failed[SMB2_WRITE_HE]));
45647 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
45648 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
45649 seq_printf(m, "\nLocks: %d sent %d failed",
45650 - atomic_read(&sent[SMB2_LOCK_HE]),
45651 - atomic_read(&failed[SMB2_LOCK_HE]));
45652 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
45653 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
45654 seq_printf(m, "\nIOCTLs: %d sent %d failed",
45655 - atomic_read(&sent[SMB2_IOCTL_HE]),
45656 - atomic_read(&failed[SMB2_IOCTL_HE]));
45657 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
45658 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
45659 seq_printf(m, "\nCancels: %d sent %d failed",
45660 - atomic_read(&sent[SMB2_CANCEL_HE]),
45661 - atomic_read(&failed[SMB2_CANCEL_HE]));
45662 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
45663 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
45664 seq_printf(m, "\nEchos: %d sent %d failed",
45665 - atomic_read(&sent[SMB2_ECHO_HE]),
45666 - atomic_read(&failed[SMB2_ECHO_HE]));
45667 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
45668 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
45669 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
45670 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
45671 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
45672 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
45673 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
45674 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
45675 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
45676 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
45677 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
45678 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
45679 seq_printf(m, "\nQueryInfos: %d sent %d failed",
45680 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
45681 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
45682 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
45683 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
45684 seq_printf(m, "\nSetInfos: %d sent %d failed",
45685 - atomic_read(&sent[SMB2_SET_INFO_HE]),
45686 - atomic_read(&failed[SMB2_SET_INFO_HE]));
45687 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
45688 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
45689 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
45690 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
45691 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
45692 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
45693 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
45694 #endif
45695 }
45696
45697 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
45698 index 958ae0e..505c9d0 100644
45699 --- a/fs/coda/cache.c
45700 +++ b/fs/coda/cache.c
45701 @@ -24,7 +24,7 @@
45702 #include "coda_linux.h"
45703 #include "coda_cache.h"
45704
45705 -static atomic_t permission_epoch = ATOMIC_INIT(0);
45706 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
45707
45708 /* replace or extend an acl cache hit */
45709 void coda_cache_enter(struct inode *inode, int mask)
45710 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
45711 struct coda_inode_info *cii = ITOC(inode);
45712
45713 spin_lock(&cii->c_lock);
45714 - cii->c_cached_epoch = atomic_read(&permission_epoch);
45715 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
45716 if (cii->c_uid != current_fsuid()) {
45717 cii->c_uid = current_fsuid();
45718 cii->c_cached_perm = mask;
45719 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
45720 {
45721 struct coda_inode_info *cii = ITOC(inode);
45722 spin_lock(&cii->c_lock);
45723 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
45724 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
45725 spin_unlock(&cii->c_lock);
45726 }
45727
45728 /* remove all acl caches */
45729 void coda_cache_clear_all(struct super_block *sb)
45730 {
45731 - atomic_inc(&permission_epoch);
45732 + atomic_inc_unchecked(&permission_epoch);
45733 }
45734
45735
45736 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
45737 spin_lock(&cii->c_lock);
45738 hit = (mask & cii->c_cached_perm) == mask &&
45739 cii->c_uid == current_fsuid() &&
45740 - cii->c_cached_epoch == atomic_read(&permission_epoch);
45741 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
45742 spin_unlock(&cii->c_lock);
45743
45744 return hit;
45745 diff --git a/fs/compat.c b/fs/compat.c
45746 index 015e1e1..5ce8e54 100644
45747 --- a/fs/compat.c
45748 +++ b/fs/compat.c
45749 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
45750
45751 set_fs(KERNEL_DS);
45752 /* The __user pointer cast is valid because of the set_fs() */
45753 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
45754 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
45755 set_fs(oldfs);
45756 /* truncating is ok because it's a user address */
45757 if (!ret)
45758 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
45759 goto out;
45760
45761 ret = -EINVAL;
45762 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
45763 + if (nr_segs > UIO_MAXIOV)
45764 goto out;
45765 if (nr_segs > fast_segs) {
45766 ret = -ENOMEM;
45767 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
45768
45769 struct compat_readdir_callback {
45770 struct compat_old_linux_dirent __user *dirent;
45771 + struct file * file;
45772 int result;
45773 };
45774
45775 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
45776 buf->result = -EOVERFLOW;
45777 return -EOVERFLOW;
45778 }
45779 +
45780 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45781 + return 0;
45782 +
45783 buf->result++;
45784 dirent = buf->dirent;
45785 if (!access_ok(VERIFY_WRITE, dirent,
45786 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
45787
45788 buf.result = 0;
45789 buf.dirent = dirent;
45790 + buf.file = f.file;
45791
45792 error = vfs_readdir(f.file, compat_fillonedir, &buf);
45793 if (buf.result)
45794 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
45795 struct compat_getdents_callback {
45796 struct compat_linux_dirent __user *current_dir;
45797 struct compat_linux_dirent __user *previous;
45798 + struct file * file;
45799 int count;
45800 int error;
45801 };
45802 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
45803 buf->error = -EOVERFLOW;
45804 return -EOVERFLOW;
45805 }
45806 +
45807 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45808 + return 0;
45809 +
45810 dirent = buf->previous;
45811 if (dirent) {
45812 if (__put_user(offset, &dirent->d_off))
45813 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45814 buf.previous = NULL;
45815 buf.count = count;
45816 buf.error = 0;
45817 + buf.file = f.file;
45818
45819 error = vfs_readdir(f.file, compat_filldir, &buf);
45820 if (error >= 0)
45821 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45822 struct compat_getdents_callback64 {
45823 struct linux_dirent64 __user *current_dir;
45824 struct linux_dirent64 __user *previous;
45825 + struct file * file;
45826 int count;
45827 int error;
45828 };
45829 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
45830 buf->error = -EINVAL; /* only used if we fail.. */
45831 if (reclen > buf->count)
45832 return -EINVAL;
45833 +
45834 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45835 + return 0;
45836 +
45837 dirent = buf->previous;
45838
45839 if (dirent) {
45840 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
45841 buf.previous = NULL;
45842 buf.count = count;
45843 buf.error = 0;
45844 + buf.file = f.file;
45845
45846 error = vfs_readdir(f.file, compat_filldir64, &buf);
45847 if (error >= 0)
45848 error = buf.error;
45849 lastdirent = buf.previous;
45850 if (lastdirent) {
45851 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
45852 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
45853 if (__put_user_unaligned(d_off, &lastdirent->d_off))
45854 error = -EFAULT;
45855 else
45856 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
45857 index a81147e..20bf2b5 100644
45858 --- a/fs/compat_binfmt_elf.c
45859 +++ b/fs/compat_binfmt_elf.c
45860 @@ -30,11 +30,13 @@
45861 #undef elf_phdr
45862 #undef elf_shdr
45863 #undef elf_note
45864 +#undef elf_dyn
45865 #undef elf_addr_t
45866 #define elfhdr elf32_hdr
45867 #define elf_phdr elf32_phdr
45868 #define elf_shdr elf32_shdr
45869 #define elf_note elf32_note
45870 +#define elf_dyn Elf32_Dyn
45871 #define elf_addr_t Elf32_Addr
45872
45873 /*
45874 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
45875 index 4c6285f..b7a2411 100644
45876 --- a/fs/compat_ioctl.c
45877 +++ b/fs/compat_ioctl.c
45878 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
45879 return -EFAULT;
45880 if (__get_user(udata, &ss32->iomem_base))
45881 return -EFAULT;
45882 - ss.iomem_base = compat_ptr(udata);
45883 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
45884 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
45885 __get_user(ss.port_high, &ss32->port_high))
45886 return -EFAULT;
45887 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
45888 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
45889 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
45890 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
45891 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45892 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45893 return -EFAULT;
45894
45895 return ioctl_preallocate(file, p);
45896 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
45897 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45898 {
45899 unsigned int a, b;
45900 - a = *(unsigned int *)p;
45901 - b = *(unsigned int *)q;
45902 + a = *(const unsigned int *)p;
45903 + b = *(const unsigned int *)q;
45904 if (a > b)
45905 return 1;
45906 if (a < b)
45907 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
45908 index 7414ae2..d98ad6d 100644
45909 --- a/fs/configfs/dir.c
45910 +++ b/fs/configfs/dir.c
45911 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45912 }
45913 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45914 struct configfs_dirent *next;
45915 - const char * name;
45916 + const unsigned char * name;
45917 + char d_name[sizeof(next->s_dentry->d_iname)];
45918 int len;
45919 struct inode *inode = NULL;
45920
45921 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45922 continue;
45923
45924 name = configfs_get_name(next);
45925 - len = strlen(name);
45926 + if (next->s_dentry && name == next->s_dentry->d_iname) {
45927 + len = next->s_dentry->d_name.len;
45928 + memcpy(d_name, name, len);
45929 + name = d_name;
45930 + } else
45931 + len = strlen(name);
45932
45933 /*
45934 * We'll have a dentry and an inode for
45935 diff --git a/fs/coredump.c b/fs/coredump.c
45936 index ce47379..68c8e43 100644
45937 --- a/fs/coredump.c
45938 +++ b/fs/coredump.c
45939 @@ -52,7 +52,7 @@ struct core_name {
45940 char *corename;
45941 int used, size;
45942 };
45943 -static atomic_t call_count = ATOMIC_INIT(1);
45944 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45945
45946 /* The maximal length of core_pattern is also specified in sysctl.c */
45947
45948 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
45949 {
45950 char *old_corename = cn->corename;
45951
45952 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45953 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45954 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45955
45956 if (!cn->corename) {
45957 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
45958 int pid_in_pattern = 0;
45959 int err = 0;
45960
45961 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45962 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45963 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45964 cn->used = 0;
45965
45966 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
45967 pipe = file->f_path.dentry->d_inode->i_pipe;
45968
45969 pipe_lock(pipe);
45970 - pipe->readers++;
45971 - pipe->writers--;
45972 + atomic_inc(&pipe->readers);
45973 + atomic_dec(&pipe->writers);
45974
45975 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45976 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45977 wake_up_interruptible_sync(&pipe->wait);
45978 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45979 pipe_wait(pipe);
45980 }
45981
45982 - pipe->readers--;
45983 - pipe->writers++;
45984 + atomic_dec(&pipe->readers);
45985 + atomic_inc(&pipe->writers);
45986 pipe_unlock(pipe);
45987
45988 }
45989 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
45990 int ispipe;
45991 struct files_struct *displaced;
45992 bool need_nonrelative = false;
45993 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45994 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45995 + long signr = siginfo->si_signo;
45996 struct coredump_params cprm = {
45997 .siginfo = siginfo,
45998 .regs = regs,
45999 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46000 .mm_flags = mm->flags,
46001 };
46002
46003 - audit_core_dumps(siginfo->si_signo);
46004 + audit_core_dumps(signr);
46005 +
46006 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46007 + gr_handle_brute_attach(cprm.mm_flags);
46008
46009 binfmt = mm->binfmt;
46010 if (!binfmt || !binfmt->core_dump)
46011 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46012 need_nonrelative = true;
46013 }
46014
46015 - retval = coredump_wait(siginfo->si_signo, &core_state);
46016 + retval = coredump_wait(signr, &core_state);
46017 if (retval < 0)
46018 goto fail_creds;
46019
46020 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46021 }
46022 cprm.limit = RLIM_INFINITY;
46023
46024 - dump_count = atomic_inc_return(&core_dump_count);
46025 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46026 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46027 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46028 task_tgid_vnr(current), current->comm);
46029 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46030 } else {
46031 struct inode *inode;
46032
46033 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46034 +
46035 if (cprm.limit < binfmt->min_coredump)
46036 goto fail_unlock;
46037
46038 @@ -640,7 +646,7 @@ close_fail:
46039 filp_close(cprm.file, NULL);
46040 fail_dropcount:
46041 if (ispipe)
46042 - atomic_dec(&core_dump_count);
46043 + atomic_dec_unchecked(&core_dump_count);
46044 fail_unlock:
46045 kfree(cn.corename);
46046 fail_corename:
46047 @@ -659,7 +665,7 @@ fail:
46048 */
46049 int dump_write(struct file *file, const void *addr, int nr)
46050 {
46051 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46052 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46053 }
46054 EXPORT_SYMBOL(dump_write);
46055
46056 diff --git a/fs/dcache.c b/fs/dcache.c
46057 index 0d0adb6..f4646e9 100644
46058 --- a/fs/dcache.c
46059 +++ b/fs/dcache.c
46060 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46061 mempages -= reserve;
46062
46063 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46064 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46065 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46066
46067 dcache_init();
46068 inode_init();
46069 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46070 index b607d92..41fda09 100644
46071 --- a/fs/debugfs/inode.c
46072 +++ b/fs/debugfs/inode.c
46073 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46074 */
46075 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46076 {
46077 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46078 + return __create_file(name, S_IFDIR | S_IRWXU,
46079 +#else
46080 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46081 +#endif
46082 parent, NULL, NULL);
46083 }
46084 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46085 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46086 index cc7709e..7e7211f 100644
46087 --- a/fs/ecryptfs/inode.c
46088 +++ b/fs/ecryptfs/inode.c
46089 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46090 old_fs = get_fs();
46091 set_fs(get_ds());
46092 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46093 - (char __user *)lower_buf,
46094 + (char __force_user *)lower_buf,
46095 PATH_MAX);
46096 set_fs(old_fs);
46097 if (rc < 0)
46098 @@ -706,7 +706,7 @@ out:
46099 static void
46100 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46101 {
46102 - char *buf = nd_get_link(nd);
46103 + const char *buf = nd_get_link(nd);
46104 if (!IS_ERR(buf)) {
46105 /* Free the char* */
46106 kfree(buf);
46107 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46108 index 412e6ed..4292d22 100644
46109 --- a/fs/ecryptfs/miscdev.c
46110 +++ b/fs/ecryptfs/miscdev.c
46111 @@ -315,7 +315,7 @@ check_list:
46112 goto out_unlock_msg_ctx;
46113 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46114 if (msg_ctx->msg) {
46115 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
46116 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46117 goto out_unlock_msg_ctx;
46118 i += packet_length_size;
46119 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46120 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46121 index b2a34a1..162fa69 100644
46122 --- a/fs/ecryptfs/read_write.c
46123 +++ b/fs/ecryptfs/read_write.c
46124 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46125 return -EIO;
46126 fs_save = get_fs();
46127 set_fs(get_ds());
46128 - rc = vfs_write(lower_file, data, size, &offset);
46129 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46130 set_fs(fs_save);
46131 mark_inode_dirty_sync(ecryptfs_inode);
46132 return rc;
46133 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46134 return -EIO;
46135 fs_save = get_fs();
46136 set_fs(get_ds());
46137 - rc = vfs_read(lower_file, data, size, &offset);
46138 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46139 set_fs(fs_save);
46140 return rc;
46141 }
46142 diff --git a/fs/exec.c b/fs/exec.c
46143 index c6e6de4..de6841c 100644
46144 --- a/fs/exec.c
46145 +++ b/fs/exec.c
46146 @@ -55,6 +55,16 @@
46147 #include <linux/pipe_fs_i.h>
46148 #include <linux/oom.h>
46149 #include <linux/compat.h>
46150 +#include <linux/random.h>
46151 +#include <linux/seq_file.h>
46152 +#include <linux/coredump.h>
46153 +
46154 +#ifdef CONFIG_PAX_REFCOUNT
46155 +#include <linux/kallsyms.h>
46156 +#include <linux/kdebug.h>
46157 +#endif
46158 +
46159 +#include <trace/events/fs.h>
46160
46161 #include <asm/uaccess.h>
46162 #include <asm/mmu_context.h>
46163 @@ -66,6 +76,18 @@
46164
46165 #include <trace/events/sched.h>
46166
46167 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46168 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46169 +{
46170 + 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");
46171 +}
46172 +#endif
46173 +
46174 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46175 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46176 +EXPORT_SYMBOL(pax_set_initial_flags_func);
46177 +#endif
46178 +
46179 int suid_dumpable = 0;
46180
46181 static LIST_HEAD(formats);
46182 @@ -180,18 +202,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46183 int write)
46184 {
46185 struct page *page;
46186 - int ret;
46187
46188 -#ifdef CONFIG_STACK_GROWSUP
46189 - if (write) {
46190 - ret = expand_downwards(bprm->vma, pos);
46191 - if (ret < 0)
46192 - return NULL;
46193 - }
46194 -#endif
46195 - ret = get_user_pages(current, bprm->mm, pos,
46196 - 1, write, 1, &page, NULL);
46197 - if (ret <= 0)
46198 + if (0 > expand_downwards(bprm->vma, pos))
46199 + return NULL;
46200 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46201 return NULL;
46202
46203 if (write) {
46204 @@ -207,6 +221,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46205 if (size <= ARG_MAX)
46206 return page;
46207
46208 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46209 + // only allow 512KB for argv+env on suid/sgid binaries
46210 + // to prevent easy ASLR exhaustion
46211 + if (((bprm->cred->euid != current_euid()) ||
46212 + (bprm->cred->egid != current_egid())) &&
46213 + (size > (512 * 1024))) {
46214 + put_page(page);
46215 + return NULL;
46216 + }
46217 +#endif
46218 +
46219 /*
46220 * Limit to 1/4-th the stack size for the argv+env strings.
46221 * This ensures that:
46222 @@ -266,6 +291,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46223 vma->vm_end = STACK_TOP_MAX;
46224 vma->vm_start = vma->vm_end - PAGE_SIZE;
46225 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46226 +
46227 +#ifdef CONFIG_PAX_SEGMEXEC
46228 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46229 +#endif
46230 +
46231 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46232 INIT_LIST_HEAD(&vma->anon_vma_chain);
46233
46234 @@ -276,6 +306,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46235 mm->stack_vm = mm->total_vm = 1;
46236 up_write(&mm->mmap_sem);
46237 bprm->p = vma->vm_end - sizeof(void *);
46238 +
46239 +#ifdef CONFIG_PAX_RANDUSTACK
46240 + if (randomize_va_space)
46241 + bprm->p ^= random32() & ~PAGE_MASK;
46242 +#endif
46243 +
46244 return 0;
46245 err:
46246 up_write(&mm->mmap_sem);
46247 @@ -384,19 +420,7 @@ err:
46248 return err;
46249 }
46250
46251 -struct user_arg_ptr {
46252 -#ifdef CONFIG_COMPAT
46253 - bool is_compat;
46254 -#endif
46255 - union {
46256 - const char __user *const __user *native;
46257 -#ifdef CONFIG_COMPAT
46258 - const compat_uptr_t __user *compat;
46259 -#endif
46260 - } ptr;
46261 -};
46262 -
46263 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46264 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46265 {
46266 const char __user *native;
46267
46268 @@ -405,14 +429,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46269 compat_uptr_t compat;
46270
46271 if (get_user(compat, argv.ptr.compat + nr))
46272 - return ERR_PTR(-EFAULT);
46273 + return (const char __force_user *)ERR_PTR(-EFAULT);
46274
46275 return compat_ptr(compat);
46276 }
46277 #endif
46278
46279 if (get_user(native, argv.ptr.native + nr))
46280 - return ERR_PTR(-EFAULT);
46281 + return (const char __force_user *)ERR_PTR(-EFAULT);
46282
46283 return native;
46284 }
46285 @@ -431,11 +455,12 @@ static int count(struct user_arg_ptr argv, int max)
46286 if (!p)
46287 break;
46288
46289 - if (IS_ERR(p))
46290 + if (IS_ERR((const char __force_kernel *)p))
46291 return -EFAULT;
46292
46293 - if (i++ >= max)
46294 + if (i >= max)
46295 return -E2BIG;
46296 + ++i;
46297
46298 if (fatal_signal_pending(current))
46299 return -ERESTARTNOHAND;
46300 @@ -465,7 +490,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46301
46302 ret = -EFAULT;
46303 str = get_user_arg_ptr(argv, argc);
46304 - if (IS_ERR(str))
46305 + if (IS_ERR((const char __force_kernel *)str))
46306 goto out;
46307
46308 len = strnlen_user(str, MAX_ARG_STRLEN);
46309 @@ -547,7 +572,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46310 int r;
46311 mm_segment_t oldfs = get_fs();
46312 struct user_arg_ptr argv = {
46313 - .ptr.native = (const char __user *const __user *)__argv,
46314 + .ptr.native = (const char __force_user *const __force_user *)__argv,
46315 };
46316
46317 set_fs(KERNEL_DS);
46318 @@ -582,7 +607,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46319 unsigned long new_end = old_end - shift;
46320 struct mmu_gather tlb;
46321
46322 - BUG_ON(new_start > new_end);
46323 + if (new_start >= new_end || new_start < mmap_min_addr)
46324 + return -ENOMEM;
46325
46326 /*
46327 * ensure there are no vmas between where we want to go
46328 @@ -591,6 +617,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46329 if (vma != find_vma(mm, new_start))
46330 return -EFAULT;
46331
46332 +#ifdef CONFIG_PAX_SEGMEXEC
46333 + BUG_ON(pax_find_mirror_vma(vma));
46334 +#endif
46335 +
46336 /*
46337 * cover the whole range: [new_start, old_end)
46338 */
46339 @@ -671,10 +701,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46340 stack_top = arch_align_stack(stack_top);
46341 stack_top = PAGE_ALIGN(stack_top);
46342
46343 - if (unlikely(stack_top < mmap_min_addr) ||
46344 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46345 - return -ENOMEM;
46346 -
46347 stack_shift = vma->vm_end - stack_top;
46348
46349 bprm->p -= stack_shift;
46350 @@ -686,8 +712,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46351 bprm->exec -= stack_shift;
46352
46353 down_write(&mm->mmap_sem);
46354 +
46355 + /* Move stack pages down in memory. */
46356 + if (stack_shift) {
46357 + ret = shift_arg_pages(vma, stack_shift);
46358 + if (ret)
46359 + goto out_unlock;
46360 + }
46361 +
46362 vm_flags = VM_STACK_FLAGS;
46363
46364 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46365 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46366 + vm_flags &= ~VM_EXEC;
46367 +
46368 +#ifdef CONFIG_PAX_MPROTECT
46369 + if (mm->pax_flags & MF_PAX_MPROTECT)
46370 + vm_flags &= ~VM_MAYEXEC;
46371 +#endif
46372 +
46373 + }
46374 +#endif
46375 +
46376 /*
46377 * Adjust stack execute permissions; explicitly enable for
46378 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46379 @@ -706,13 +752,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46380 goto out_unlock;
46381 BUG_ON(prev != vma);
46382
46383 - /* Move stack pages down in memory. */
46384 - if (stack_shift) {
46385 - ret = shift_arg_pages(vma, stack_shift);
46386 - if (ret)
46387 - goto out_unlock;
46388 - }
46389 -
46390 /* mprotect_fixup is overkill to remove the temporary stack flags */
46391 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
46392
46393 @@ -771,6 +810,8 @@ struct file *open_exec(const char *name)
46394
46395 fsnotify_open(file);
46396
46397 + trace_open_exec(name);
46398 +
46399 err = deny_write_access(file);
46400 if (err)
46401 goto exit;
46402 @@ -794,7 +835,7 @@ int kernel_read(struct file *file, loff_t offset,
46403 old_fs = get_fs();
46404 set_fs(get_ds());
46405 /* The cast to a user pointer is valid due to the set_fs() */
46406 - result = vfs_read(file, (void __user *)addr, count, &pos);
46407 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
46408 set_fs(old_fs);
46409 return result;
46410 }
46411 @@ -1246,7 +1287,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
46412 }
46413 rcu_read_unlock();
46414
46415 - if (p->fs->users > n_fs) {
46416 + if (atomic_read(&p->fs->users) > n_fs) {
46417 bprm->unsafe |= LSM_UNSAFE_SHARE;
46418 } else {
46419 res = -EAGAIN;
46420 @@ -1449,6 +1490,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
46421
46422 EXPORT_SYMBOL(search_binary_handler);
46423
46424 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46425 +static DEFINE_PER_CPU(u64, exec_counter);
46426 +static int __init init_exec_counters(void)
46427 +{
46428 + unsigned int cpu;
46429 +
46430 + for_each_possible_cpu(cpu) {
46431 + per_cpu(exec_counter, cpu) = (u64)cpu;
46432 + }
46433 +
46434 + return 0;
46435 +}
46436 +early_initcall(init_exec_counters);
46437 +static inline void increment_exec_counter(void)
46438 +{
46439 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
46440 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
46441 +}
46442 +#else
46443 +static inline void increment_exec_counter(void) {}
46444 +#endif
46445 +
46446 /*
46447 * sys_execve() executes a new program.
46448 */
46449 @@ -1457,6 +1520,11 @@ static int do_execve_common(const char *filename,
46450 struct user_arg_ptr envp,
46451 struct pt_regs *regs)
46452 {
46453 +#ifdef CONFIG_GRKERNSEC
46454 + struct file *old_exec_file;
46455 + struct acl_subject_label *old_acl;
46456 + struct rlimit old_rlim[RLIM_NLIMITS];
46457 +#endif
46458 struct linux_binprm *bprm;
46459 struct file *file;
46460 struct files_struct *displaced;
46461 @@ -1464,6 +1532,8 @@ static int do_execve_common(const char *filename,
46462 int retval;
46463 const struct cred *cred = current_cred();
46464
46465 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
46466 +
46467 /*
46468 * We move the actual failure in case of RLIMIT_NPROC excess from
46469 * set*uid() to execve() because too many poorly written programs
46470 @@ -1504,12 +1574,27 @@ static int do_execve_common(const char *filename,
46471 if (IS_ERR(file))
46472 goto out_unmark;
46473
46474 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
46475 + retval = -EPERM;
46476 + goto out_file;
46477 + }
46478 +
46479 sched_exec();
46480
46481 bprm->file = file;
46482 bprm->filename = filename;
46483 bprm->interp = filename;
46484
46485 + if (gr_process_user_ban()) {
46486 + retval = -EPERM;
46487 + goto out_file;
46488 + }
46489 +
46490 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
46491 + retval = -EACCES;
46492 + goto out_file;
46493 + }
46494 +
46495 retval = bprm_mm_init(bprm);
46496 if (retval)
46497 goto out_file;
46498 @@ -1526,24 +1611,65 @@ static int do_execve_common(const char *filename,
46499 if (retval < 0)
46500 goto out;
46501
46502 +#ifdef CONFIG_GRKERNSEC
46503 + old_acl = current->acl;
46504 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
46505 + old_exec_file = current->exec_file;
46506 + get_file(file);
46507 + current->exec_file = file;
46508 +#endif
46509 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46510 + /* limit suid stack to 8MB
46511 + we saved the old limits above and will restore them if this exec fails
46512 + */
46513 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
46514 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
46515 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
46516 +#endif
46517 +
46518 + if (!gr_tpe_allow(file)) {
46519 + retval = -EACCES;
46520 + goto out_fail;
46521 + }
46522 +
46523 + if (gr_check_crash_exec(file)) {
46524 + retval = -EACCES;
46525 + goto out_fail;
46526 + }
46527 +
46528 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
46529 + bprm->unsafe);
46530 + if (retval < 0)
46531 + goto out_fail;
46532 +
46533 retval = copy_strings_kernel(1, &bprm->filename, bprm);
46534 if (retval < 0)
46535 - goto out;
46536 + goto out_fail;
46537
46538 bprm->exec = bprm->p;
46539 retval = copy_strings(bprm->envc, envp, bprm);
46540 if (retval < 0)
46541 - goto out;
46542 + goto out_fail;
46543
46544 retval = copy_strings(bprm->argc, argv, bprm);
46545 if (retval < 0)
46546 - goto out;
46547 + goto out_fail;
46548 +
46549 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
46550 +
46551 + gr_handle_exec_args(bprm, argv);
46552
46553 retval = search_binary_handler(bprm,regs);
46554 if (retval < 0)
46555 - goto out;
46556 + goto out_fail;
46557 +#ifdef CONFIG_GRKERNSEC
46558 + if (old_exec_file)
46559 + fput(old_exec_file);
46560 +#endif
46561
46562 /* execve succeeded */
46563 +
46564 + increment_exec_counter();
46565 current->fs->in_exec = 0;
46566 current->in_execve = 0;
46567 acct_update_integrals(current);
46568 @@ -1552,6 +1678,14 @@ static int do_execve_common(const char *filename,
46569 put_files_struct(displaced);
46570 return retval;
46571
46572 +out_fail:
46573 +#ifdef CONFIG_GRKERNSEC
46574 + current->acl = old_acl;
46575 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
46576 + fput(current->exec_file);
46577 + current->exec_file = old_exec_file;
46578 +#endif
46579 +
46580 out:
46581 if (bprm->mm) {
46582 acct_arg_size(bprm, 0);
46583 @@ -1727,3 +1861,253 @@ int kernel_execve(const char *filename,
46584 ret_from_kernel_execve(p);
46585 }
46586 #endif
46587 +
46588 +int pax_check_flags(unsigned long *flags)
46589 +{
46590 + int retval = 0;
46591 +
46592 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
46593 + if (*flags & MF_PAX_SEGMEXEC)
46594 + {
46595 + *flags &= ~MF_PAX_SEGMEXEC;
46596 + retval = -EINVAL;
46597 + }
46598 +#endif
46599 +
46600 + if ((*flags & MF_PAX_PAGEEXEC)
46601 +
46602 +#ifdef CONFIG_PAX_PAGEEXEC
46603 + && (*flags & MF_PAX_SEGMEXEC)
46604 +#endif
46605 +
46606 + )
46607 + {
46608 + *flags &= ~MF_PAX_PAGEEXEC;
46609 + retval = -EINVAL;
46610 + }
46611 +
46612 + if ((*flags & MF_PAX_MPROTECT)
46613 +
46614 +#ifdef CONFIG_PAX_MPROTECT
46615 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46616 +#endif
46617 +
46618 + )
46619 + {
46620 + *flags &= ~MF_PAX_MPROTECT;
46621 + retval = -EINVAL;
46622 + }
46623 +
46624 + if ((*flags & MF_PAX_EMUTRAMP)
46625 +
46626 +#ifdef CONFIG_PAX_EMUTRAMP
46627 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46628 +#endif
46629 +
46630 + )
46631 + {
46632 + *flags &= ~MF_PAX_EMUTRAMP;
46633 + retval = -EINVAL;
46634 + }
46635 +
46636 + return retval;
46637 +}
46638 +
46639 +EXPORT_SYMBOL(pax_check_flags);
46640 +
46641 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46642 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
46643 +{
46644 + struct task_struct *tsk = current;
46645 + struct mm_struct *mm = current->mm;
46646 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
46647 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
46648 + char *path_exec = NULL;
46649 + char *path_fault = NULL;
46650 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
46651 + siginfo_t info = { };
46652 +
46653 + if (buffer_exec && buffer_fault) {
46654 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
46655 +
46656 + down_read(&mm->mmap_sem);
46657 + vma = mm->mmap;
46658 + while (vma && (!vma_exec || !vma_fault)) {
46659 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
46660 + vma_exec = vma;
46661 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
46662 + vma_fault = vma;
46663 + vma = vma->vm_next;
46664 + }
46665 + if (vma_exec) {
46666 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
46667 + if (IS_ERR(path_exec))
46668 + path_exec = "<path too long>";
46669 + else {
46670 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
46671 + if (path_exec) {
46672 + *path_exec = 0;
46673 + path_exec = buffer_exec;
46674 + } else
46675 + path_exec = "<path too long>";
46676 + }
46677 + }
46678 + if (vma_fault) {
46679 + start = vma_fault->vm_start;
46680 + end = vma_fault->vm_end;
46681 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
46682 + if (vma_fault->vm_file) {
46683 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
46684 + if (IS_ERR(path_fault))
46685 + path_fault = "<path too long>";
46686 + else {
46687 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
46688 + if (path_fault) {
46689 + *path_fault = 0;
46690 + path_fault = buffer_fault;
46691 + } else
46692 + path_fault = "<path too long>";
46693 + }
46694 + } else
46695 + path_fault = "<anonymous mapping>";
46696 + }
46697 + up_read(&mm->mmap_sem);
46698 + }
46699 + if (tsk->signal->curr_ip)
46700 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
46701 + else
46702 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
46703 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
46704 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
46705 + task_uid(tsk), task_euid(tsk), pc, sp);
46706 + free_page((unsigned long)buffer_exec);
46707 + free_page((unsigned long)buffer_fault);
46708 + pax_report_insns(regs, pc, sp);
46709 + info.si_signo = SIGKILL;
46710 + info.si_errno = 0;
46711 + info.si_code = SI_KERNEL;
46712 + info.si_pid = 0;
46713 + info.si_uid = 0;
46714 + do_coredump(&info, regs);
46715 +}
46716 +#endif
46717 +
46718 +#ifdef CONFIG_PAX_REFCOUNT
46719 +void pax_report_refcount_overflow(struct pt_regs *regs)
46720 +{
46721 + if (current->signal->curr_ip)
46722 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
46723 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
46724 + else
46725 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
46726 + current->comm, task_pid_nr(current), current_uid(), current_euid());
46727 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
46728 + show_regs(regs);
46729 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
46730 +}
46731 +#endif
46732 +
46733 +#ifdef CONFIG_PAX_USERCOPY
46734 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
46735 +static noinline int check_stack_object(const void *obj, unsigned long len)
46736 +{
46737 + const void * const stack = task_stack_page(current);
46738 + const void * const stackend = stack + THREAD_SIZE;
46739 +
46740 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
46741 + const void *frame = NULL;
46742 + const void *oldframe;
46743 +#endif
46744 +
46745 + if (obj + len < obj)
46746 + return -1;
46747 +
46748 + if (obj + len <= stack || stackend <= obj)
46749 + return 0;
46750 +
46751 + if (obj < stack || stackend < obj + len)
46752 + return -1;
46753 +
46754 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
46755 + oldframe = __builtin_frame_address(1);
46756 + if (oldframe)
46757 + frame = __builtin_frame_address(2);
46758 + /*
46759 + low ----------------------------------------------> high
46760 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
46761 + ^----------------^
46762 + allow copies only within here
46763 + */
46764 + while (stack <= frame && frame < stackend) {
46765 + /* if obj + len extends past the last frame, this
46766 + check won't pass and the next frame will be 0,
46767 + causing us to bail out and correctly report
46768 + the copy as invalid
46769 + */
46770 + if (obj + len <= frame)
46771 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
46772 + oldframe = frame;
46773 + frame = *(const void * const *)frame;
46774 + }
46775 + return -1;
46776 +#else
46777 + return 1;
46778 +#endif
46779 +}
46780 +
46781 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
46782 +{
46783 + if (current->signal->curr_ip)
46784 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
46785 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
46786 + else
46787 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
46788 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
46789 + dump_stack();
46790 + gr_handle_kernel_exploit();
46791 + do_group_exit(SIGKILL);
46792 +}
46793 +#endif
46794 +
46795 +void check_object_size(const void *ptr, unsigned long n, bool to)
46796 +{
46797 +
46798 +#ifdef CONFIG_PAX_USERCOPY
46799 + const char *type;
46800 +
46801 + if (!n)
46802 + return;
46803 +
46804 + type = check_heap_object(ptr, n);
46805 + if (!type) {
46806 + if (check_stack_object(ptr, n) != -1)
46807 + return;
46808 + type = "<process stack>";
46809 + }
46810 +
46811 + pax_report_usercopy(ptr, n, to, type);
46812 +#endif
46813 +
46814 +}
46815 +EXPORT_SYMBOL(check_object_size);
46816 +
46817 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
46818 +void pax_track_stack(void)
46819 +{
46820 + unsigned long sp = (unsigned long)&sp;
46821 + if (sp < current_thread_info()->lowest_stack &&
46822 + sp > (unsigned long)task_stack_page(current))
46823 + current_thread_info()->lowest_stack = sp;
46824 +}
46825 +EXPORT_SYMBOL(pax_track_stack);
46826 +#endif
46827 +
46828 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
46829 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
46830 +{
46831 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
46832 + dump_stack();
46833 + do_group_exit(SIGKILL);
46834 +}
46835 +EXPORT_SYMBOL(report_size_overflow);
46836 +#endif
46837 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
46838 index 2616d0e..2ffdec9 100644
46839 --- a/fs/ext2/balloc.c
46840 +++ b/fs/ext2/balloc.c
46841 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
46842
46843 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46844 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46845 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46846 + if (free_blocks < root_blocks + 1 &&
46847 !uid_eq(sbi->s_resuid, current_fsuid()) &&
46848 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46849 - !in_group_p (sbi->s_resgid))) {
46850 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46851 return 0;
46852 }
46853 return 1;
46854 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
46855 index 22548f5..41521d8 100644
46856 --- a/fs/ext3/balloc.c
46857 +++ b/fs/ext3/balloc.c
46858 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
46859
46860 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46861 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46862 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46863 + if (free_blocks < root_blocks + 1 &&
46864 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
46865 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46866 - !in_group_p (sbi->s_resgid))) {
46867 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46868 return 0;
46869 }
46870 return 1;
46871 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
46872 index cf18217..8f6b9c3 100644
46873 --- a/fs/ext4/balloc.c
46874 +++ b/fs/ext4/balloc.c
46875 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
46876 /* Hm, nope. Are (enough) root reserved clusters available? */
46877 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
46878 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
46879 - capable(CAP_SYS_RESOURCE) ||
46880 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
46881 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
46882 + capable_nolog(CAP_SYS_RESOURCE)) {
46883
46884 if (free_clusters >= (nclusters + dirty_clusters))
46885 return 1;
46886 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
46887 index 3c20de1..6ff2460 100644
46888 --- a/fs/ext4/ext4.h
46889 +++ b/fs/ext4/ext4.h
46890 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
46891 unsigned long s_mb_last_start;
46892
46893 /* stats for buddy allocator */
46894 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
46895 - atomic_t s_bal_success; /* we found long enough chunks */
46896 - atomic_t s_bal_allocated; /* in blocks */
46897 - atomic_t s_bal_ex_scanned; /* total extents scanned */
46898 - atomic_t s_bal_goals; /* goal hits */
46899 - atomic_t s_bal_breaks; /* too long searches */
46900 - atomic_t s_bal_2orders; /* 2^order hits */
46901 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
46902 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
46903 + atomic_unchecked_t s_bal_allocated; /* in blocks */
46904 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
46905 + atomic_unchecked_t s_bal_goals; /* goal hits */
46906 + atomic_unchecked_t s_bal_breaks; /* too long searches */
46907 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
46908 spinlock_t s_bal_lock;
46909 unsigned long s_mb_buddies_generated;
46910 unsigned long long s_mb_generation_time;
46911 - atomic_t s_mb_lost_chunks;
46912 - atomic_t s_mb_preallocated;
46913 - atomic_t s_mb_discarded;
46914 + atomic_unchecked_t s_mb_lost_chunks;
46915 + atomic_unchecked_t s_mb_preallocated;
46916 + atomic_unchecked_t s_mb_discarded;
46917 atomic_t s_lock_busy;
46918
46919 /* locality groups */
46920 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
46921 index b3c243b..772c318 100644
46922 --- a/fs/ext4/inode.c
46923 +++ b/fs/ext4/inode.c
46924 @@ -1503,6 +1503,7 @@ static void ext4_da_block_invalidatepages(struct mpage_da_data *mpd)
46925
46926 index = mpd->first_page;
46927 end = mpd->next_page - 1;
46928 + pagevec_init(&pvec, 0);
46929 while (index <= end) {
46930 nr_pages = pagevec_lookup(&pvec, mapping, index, PAGEVEC_SIZE);
46931 if (nr_pages == 0)
46932 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
46933 index 526e553..3f2de85 100644
46934 --- a/fs/ext4/mballoc.c
46935 +++ b/fs/ext4/mballoc.c
46936 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
46937 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
46938
46939 if (EXT4_SB(sb)->s_mb_stats)
46940 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
46941 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
46942
46943 break;
46944 }
46945 @@ -2044,7 +2044,7 @@ repeat:
46946 ac->ac_status = AC_STATUS_CONTINUE;
46947 ac->ac_flags |= EXT4_MB_HINT_FIRST;
46948 cr = 3;
46949 - atomic_inc(&sbi->s_mb_lost_chunks);
46950 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
46951 goto repeat;
46952 }
46953 }
46954 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
46955 if (sbi->s_mb_stats) {
46956 ext4_msg(sb, KERN_INFO,
46957 "mballoc: %u blocks %u reqs (%u success)",
46958 - atomic_read(&sbi->s_bal_allocated),
46959 - atomic_read(&sbi->s_bal_reqs),
46960 - atomic_read(&sbi->s_bal_success));
46961 + atomic_read_unchecked(&sbi->s_bal_allocated),
46962 + atomic_read_unchecked(&sbi->s_bal_reqs),
46963 + atomic_read_unchecked(&sbi->s_bal_success));
46964 ext4_msg(sb, KERN_INFO,
46965 "mballoc: %u extents scanned, %u goal hits, "
46966 "%u 2^N hits, %u breaks, %u lost",
46967 - atomic_read(&sbi->s_bal_ex_scanned),
46968 - atomic_read(&sbi->s_bal_goals),
46969 - atomic_read(&sbi->s_bal_2orders),
46970 - atomic_read(&sbi->s_bal_breaks),
46971 - atomic_read(&sbi->s_mb_lost_chunks));
46972 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
46973 + atomic_read_unchecked(&sbi->s_bal_goals),
46974 + atomic_read_unchecked(&sbi->s_bal_2orders),
46975 + atomic_read_unchecked(&sbi->s_bal_breaks),
46976 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
46977 ext4_msg(sb, KERN_INFO,
46978 "mballoc: %lu generated and it took %Lu",
46979 sbi->s_mb_buddies_generated,
46980 sbi->s_mb_generation_time);
46981 ext4_msg(sb, KERN_INFO,
46982 "mballoc: %u preallocated, %u discarded",
46983 - atomic_read(&sbi->s_mb_preallocated),
46984 - atomic_read(&sbi->s_mb_discarded));
46985 + atomic_read_unchecked(&sbi->s_mb_preallocated),
46986 + atomic_read_unchecked(&sbi->s_mb_discarded));
46987 }
46988
46989 free_percpu(sbi->s_locality_groups);
46990 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
46991 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
46992
46993 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
46994 - atomic_inc(&sbi->s_bal_reqs);
46995 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46996 + atomic_inc_unchecked(&sbi->s_bal_reqs);
46997 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46998 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
46999 - atomic_inc(&sbi->s_bal_success);
47000 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47001 + atomic_inc_unchecked(&sbi->s_bal_success);
47002 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47003 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47004 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47005 - atomic_inc(&sbi->s_bal_goals);
47006 + atomic_inc_unchecked(&sbi->s_bal_goals);
47007 if (ac->ac_found > sbi->s_mb_max_to_scan)
47008 - atomic_inc(&sbi->s_bal_breaks);
47009 + atomic_inc_unchecked(&sbi->s_bal_breaks);
47010 }
47011
47012 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47013 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47014 trace_ext4_mb_new_inode_pa(ac, pa);
47015
47016 ext4_mb_use_inode_pa(ac, pa);
47017 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47018 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47019
47020 ei = EXT4_I(ac->ac_inode);
47021 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47022 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47023 trace_ext4_mb_new_group_pa(ac, pa);
47024
47025 ext4_mb_use_group_pa(ac, pa);
47026 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47027 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47028
47029 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47030 lg = ac->ac_lg;
47031 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47032 * from the bitmap and continue.
47033 */
47034 }
47035 - atomic_add(free, &sbi->s_mb_discarded);
47036 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
47037
47038 return err;
47039 }
47040 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47041 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47042 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47043 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47044 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47045 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47046 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47047
47048 return 0;
47049 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47050 index d59b351..775f8c8 100644
47051 --- a/fs/ext4/super.c
47052 +++ b/fs/ext4/super.c
47053 @@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47054 ext4_fsblk_t overhead = 0;
47055 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47056
47057 - memset(buf, 0, PAGE_SIZE);
47058 if (!buf)
47059 return -ENOMEM;
47060
47061 diff --git a/fs/fcntl.c b/fs/fcntl.c
47062 index 71a600a..20d87b1 100644
47063 --- a/fs/fcntl.c
47064 +++ b/fs/fcntl.c
47065 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47066 if (err)
47067 return err;
47068
47069 + if (gr_handle_chroot_fowner(pid, type))
47070 + return -ENOENT;
47071 + if (gr_check_protected_task_fowner(pid, type))
47072 + return -EACCES;
47073 +
47074 f_modown(filp, pid, type, force);
47075 return 0;
47076 }
47077 diff --git a/fs/fifo.c b/fs/fifo.c
47078 index cf6f434..3d7942c 100644
47079 --- a/fs/fifo.c
47080 +++ b/fs/fifo.c
47081 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47082 */
47083 filp->f_op = &read_pipefifo_fops;
47084 pipe->r_counter++;
47085 - if (pipe->readers++ == 0)
47086 + if (atomic_inc_return(&pipe->readers) == 1)
47087 wake_up_partner(inode);
47088
47089 - if (!pipe->writers) {
47090 + if (!atomic_read(&pipe->writers)) {
47091 if ((filp->f_flags & O_NONBLOCK)) {
47092 /* suppress POLLHUP until we have
47093 * seen a writer */
47094 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47095 * errno=ENXIO when there is no process reading the FIFO.
47096 */
47097 ret = -ENXIO;
47098 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47099 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47100 goto err;
47101
47102 filp->f_op = &write_pipefifo_fops;
47103 pipe->w_counter++;
47104 - if (!pipe->writers++)
47105 + if (atomic_inc_return(&pipe->writers) == 1)
47106 wake_up_partner(inode);
47107
47108 - if (!pipe->readers) {
47109 + if (!atomic_read(&pipe->readers)) {
47110 if (wait_for_partner(inode, &pipe->r_counter))
47111 goto err_wr;
47112 }
47113 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47114 */
47115 filp->f_op = &rdwr_pipefifo_fops;
47116
47117 - pipe->readers++;
47118 - pipe->writers++;
47119 + atomic_inc(&pipe->readers);
47120 + atomic_inc(&pipe->writers);
47121 pipe->r_counter++;
47122 pipe->w_counter++;
47123 - if (pipe->readers == 1 || pipe->writers == 1)
47124 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47125 wake_up_partner(inode);
47126 break;
47127
47128 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47129 return 0;
47130
47131 err_rd:
47132 - if (!--pipe->readers)
47133 + if (atomic_dec_and_test(&pipe->readers))
47134 wake_up_interruptible(&pipe->wait);
47135 ret = -ERESTARTSYS;
47136 goto err;
47137
47138 err_wr:
47139 - if (!--pipe->writers)
47140 + if (atomic_dec_and_test(&pipe->writers))
47141 wake_up_interruptible(&pipe->wait);
47142 ret = -ERESTARTSYS;
47143 goto err;
47144
47145 err:
47146 - if (!pipe->readers && !pipe->writers)
47147 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47148 free_pipe_info(inode);
47149
47150 err_nocleanup:
47151 diff --git a/fs/file.c b/fs/file.c
47152 index eff2316..8c8930c 100644
47153 --- a/fs/file.c
47154 +++ b/fs/file.c
47155 @@ -16,6 +16,7 @@
47156 #include <linux/slab.h>
47157 #include <linux/vmalloc.h>
47158 #include <linux/file.h>
47159 +#include <linux/security.h>
47160 #include <linux/fdtable.h>
47161 #include <linux/bitops.h>
47162 #include <linux/interrupt.h>
47163 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47164 if (!file)
47165 return __close_fd(files, fd);
47166
47167 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47168 if (fd >= rlimit(RLIMIT_NOFILE))
47169 return -EBADF;
47170
47171 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47172 if (unlikely(oldfd == newfd))
47173 return -EINVAL;
47174
47175 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47176 if (newfd >= rlimit(RLIMIT_NOFILE))
47177 return -EBADF;
47178
47179 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47180 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47181 {
47182 int err;
47183 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47184 if (from >= rlimit(RLIMIT_NOFILE))
47185 return -EINVAL;
47186 err = alloc_fd(from, flags);
47187 diff --git a/fs/filesystems.c b/fs/filesystems.c
47188 index da165f6..3671bdb 100644
47189 --- a/fs/filesystems.c
47190 +++ b/fs/filesystems.c
47191 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47192 int len = dot ? dot - name : strlen(name);
47193
47194 fs = __get_fs_type(name, len);
47195 +
47196 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
47197 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47198 +#else
47199 if (!fs && (request_module("%.*s", len, name) == 0))
47200 +#endif
47201 fs = __get_fs_type(name, len);
47202
47203 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47204 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47205 index 5df4775..9d9336f 100644
47206 --- a/fs/fs_struct.c
47207 +++ b/fs/fs_struct.c
47208 @@ -4,6 +4,7 @@
47209 #include <linux/path.h>
47210 #include <linux/slab.h>
47211 #include <linux/fs_struct.h>
47212 +#include <linux/grsecurity.h>
47213 #include "internal.h"
47214
47215 /*
47216 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47217 write_seqcount_begin(&fs->seq);
47218 old_root = fs->root;
47219 fs->root = *path;
47220 + gr_set_chroot_entries(current, path);
47221 write_seqcount_end(&fs->seq);
47222 spin_unlock(&fs->lock);
47223 if (old_root.dentry)
47224 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47225 return 1;
47226 }
47227
47228 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47229 +{
47230 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47231 + return 0;
47232 + *p = *new;
47233 +
47234 + /* This function is only called from pivot_root(). Leave our
47235 + gr_chroot_dentry and is_chrooted flags as-is, so that a
47236 + pivoted root isn't treated as a chroot
47237 + */
47238 + //gr_set_chroot_entries(task, new);
47239 +
47240 + return 1;
47241 +}
47242 +
47243 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47244 {
47245 struct task_struct *g, *p;
47246 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47247 int hits = 0;
47248 spin_lock(&fs->lock);
47249 write_seqcount_begin(&fs->seq);
47250 - hits += replace_path(&fs->root, old_root, new_root);
47251 + hits += replace_root_path(p, &fs->root, old_root, new_root);
47252 hits += replace_path(&fs->pwd, old_root, new_root);
47253 write_seqcount_end(&fs->seq);
47254 while (hits--) {
47255 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47256 task_lock(tsk);
47257 spin_lock(&fs->lock);
47258 tsk->fs = NULL;
47259 - kill = !--fs->users;
47260 + gr_clear_chroot_entries(tsk);
47261 + kill = !atomic_dec_return(&fs->users);
47262 spin_unlock(&fs->lock);
47263 task_unlock(tsk);
47264 if (kill)
47265 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47266 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47267 /* We don't need to lock fs - think why ;-) */
47268 if (fs) {
47269 - fs->users = 1;
47270 + atomic_set(&fs->users, 1);
47271 fs->in_exec = 0;
47272 spin_lock_init(&fs->lock);
47273 seqcount_init(&fs->seq);
47274 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47275 spin_lock(&old->lock);
47276 fs->root = old->root;
47277 path_get(&fs->root);
47278 + /* instead of calling gr_set_chroot_entries here,
47279 + we call it from every caller of this function
47280 + */
47281 fs->pwd = old->pwd;
47282 path_get(&fs->pwd);
47283 spin_unlock(&old->lock);
47284 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47285
47286 task_lock(current);
47287 spin_lock(&fs->lock);
47288 - kill = !--fs->users;
47289 + kill = !atomic_dec_return(&fs->users);
47290 current->fs = new_fs;
47291 + gr_set_chroot_entries(current, &new_fs->root);
47292 spin_unlock(&fs->lock);
47293 task_unlock(current);
47294
47295 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47296
47297 int current_umask(void)
47298 {
47299 - return current->fs->umask;
47300 + return current->fs->umask | gr_acl_umask();
47301 }
47302 EXPORT_SYMBOL(current_umask);
47303
47304 /* to be mentioned only in INIT_TASK */
47305 struct fs_struct init_fs = {
47306 - .users = 1,
47307 + .users = ATOMIC_INIT(1),
47308 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47309 .seq = SEQCNT_ZERO,
47310 .umask = 0022,
47311 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47312 task_lock(current);
47313
47314 spin_lock(&init_fs.lock);
47315 - init_fs.users++;
47316 + atomic_inc(&init_fs.users);
47317 spin_unlock(&init_fs.lock);
47318
47319 spin_lock(&fs->lock);
47320 current->fs = &init_fs;
47321 - kill = !--fs->users;
47322 + gr_set_chroot_entries(current, &current->fs->root);
47323 + kill = !atomic_dec_return(&fs->users);
47324 spin_unlock(&fs->lock);
47325
47326 task_unlock(current);
47327 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47328 index 9905350..02eaec4 100644
47329 --- a/fs/fscache/cookie.c
47330 +++ b/fs/fscache/cookie.c
47331 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47332 parent ? (char *) parent->def->name : "<no-parent>",
47333 def->name, netfs_data);
47334
47335 - fscache_stat(&fscache_n_acquires);
47336 + fscache_stat_unchecked(&fscache_n_acquires);
47337
47338 /* if there's no parent cookie, then we don't create one here either */
47339 if (!parent) {
47340 - fscache_stat(&fscache_n_acquires_null);
47341 + fscache_stat_unchecked(&fscache_n_acquires_null);
47342 _leave(" [no parent]");
47343 return NULL;
47344 }
47345 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47346 /* allocate and initialise a cookie */
47347 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47348 if (!cookie) {
47349 - fscache_stat(&fscache_n_acquires_oom);
47350 + fscache_stat_unchecked(&fscache_n_acquires_oom);
47351 _leave(" [ENOMEM]");
47352 return NULL;
47353 }
47354 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47355
47356 switch (cookie->def->type) {
47357 case FSCACHE_COOKIE_TYPE_INDEX:
47358 - fscache_stat(&fscache_n_cookie_index);
47359 + fscache_stat_unchecked(&fscache_n_cookie_index);
47360 break;
47361 case FSCACHE_COOKIE_TYPE_DATAFILE:
47362 - fscache_stat(&fscache_n_cookie_data);
47363 + fscache_stat_unchecked(&fscache_n_cookie_data);
47364 break;
47365 default:
47366 - fscache_stat(&fscache_n_cookie_special);
47367 + fscache_stat_unchecked(&fscache_n_cookie_special);
47368 break;
47369 }
47370
47371 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47372 if (fscache_acquire_non_index_cookie(cookie) < 0) {
47373 atomic_dec(&parent->n_children);
47374 __fscache_cookie_put(cookie);
47375 - fscache_stat(&fscache_n_acquires_nobufs);
47376 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
47377 _leave(" = NULL");
47378 return NULL;
47379 }
47380 }
47381
47382 - fscache_stat(&fscache_n_acquires_ok);
47383 + fscache_stat_unchecked(&fscache_n_acquires_ok);
47384 _leave(" = %p", cookie);
47385 return cookie;
47386 }
47387 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
47388 cache = fscache_select_cache_for_object(cookie->parent);
47389 if (!cache) {
47390 up_read(&fscache_addremove_sem);
47391 - fscache_stat(&fscache_n_acquires_no_cache);
47392 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
47393 _leave(" = -ENOMEDIUM [no cache]");
47394 return -ENOMEDIUM;
47395 }
47396 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
47397 object = cache->ops->alloc_object(cache, cookie);
47398 fscache_stat_d(&fscache_n_cop_alloc_object);
47399 if (IS_ERR(object)) {
47400 - fscache_stat(&fscache_n_object_no_alloc);
47401 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
47402 ret = PTR_ERR(object);
47403 goto error;
47404 }
47405
47406 - fscache_stat(&fscache_n_object_alloc);
47407 + fscache_stat_unchecked(&fscache_n_object_alloc);
47408
47409 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
47410
47411 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
47412 struct fscache_object *object;
47413 struct hlist_node *_p;
47414
47415 - fscache_stat(&fscache_n_updates);
47416 + fscache_stat_unchecked(&fscache_n_updates);
47417
47418 if (!cookie) {
47419 - fscache_stat(&fscache_n_updates_null);
47420 + fscache_stat_unchecked(&fscache_n_updates_null);
47421 _leave(" [no cookie]");
47422 return;
47423 }
47424 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47425 struct fscache_object *object;
47426 unsigned long event;
47427
47428 - fscache_stat(&fscache_n_relinquishes);
47429 + fscache_stat_unchecked(&fscache_n_relinquishes);
47430 if (retire)
47431 - fscache_stat(&fscache_n_relinquishes_retire);
47432 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
47433
47434 if (!cookie) {
47435 - fscache_stat(&fscache_n_relinquishes_null);
47436 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
47437 _leave(" [no cookie]");
47438 return;
47439 }
47440 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47441
47442 /* wait for the cookie to finish being instantiated (or to fail) */
47443 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
47444 - fscache_stat(&fscache_n_relinquishes_waitcrt);
47445 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
47446 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
47447 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
47448 }
47449 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
47450 index f6aad48..88dcf26 100644
47451 --- a/fs/fscache/internal.h
47452 +++ b/fs/fscache/internal.h
47453 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
47454 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
47455 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
47456
47457 -extern atomic_t fscache_n_op_pend;
47458 -extern atomic_t fscache_n_op_run;
47459 -extern atomic_t fscache_n_op_enqueue;
47460 -extern atomic_t fscache_n_op_deferred_release;
47461 -extern atomic_t fscache_n_op_release;
47462 -extern atomic_t fscache_n_op_gc;
47463 -extern atomic_t fscache_n_op_cancelled;
47464 -extern atomic_t fscache_n_op_rejected;
47465 +extern atomic_unchecked_t fscache_n_op_pend;
47466 +extern atomic_unchecked_t fscache_n_op_run;
47467 +extern atomic_unchecked_t fscache_n_op_enqueue;
47468 +extern atomic_unchecked_t fscache_n_op_deferred_release;
47469 +extern atomic_unchecked_t fscache_n_op_release;
47470 +extern atomic_unchecked_t fscache_n_op_gc;
47471 +extern atomic_unchecked_t fscache_n_op_cancelled;
47472 +extern atomic_unchecked_t fscache_n_op_rejected;
47473
47474 -extern atomic_t fscache_n_attr_changed;
47475 -extern atomic_t fscache_n_attr_changed_ok;
47476 -extern atomic_t fscache_n_attr_changed_nobufs;
47477 -extern atomic_t fscache_n_attr_changed_nomem;
47478 -extern atomic_t fscache_n_attr_changed_calls;
47479 +extern atomic_unchecked_t fscache_n_attr_changed;
47480 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
47481 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
47482 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
47483 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
47484
47485 -extern atomic_t fscache_n_allocs;
47486 -extern atomic_t fscache_n_allocs_ok;
47487 -extern atomic_t fscache_n_allocs_wait;
47488 -extern atomic_t fscache_n_allocs_nobufs;
47489 -extern atomic_t fscache_n_allocs_intr;
47490 -extern atomic_t fscache_n_allocs_object_dead;
47491 -extern atomic_t fscache_n_alloc_ops;
47492 -extern atomic_t fscache_n_alloc_op_waits;
47493 +extern atomic_unchecked_t fscache_n_allocs;
47494 +extern atomic_unchecked_t fscache_n_allocs_ok;
47495 +extern atomic_unchecked_t fscache_n_allocs_wait;
47496 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
47497 +extern atomic_unchecked_t fscache_n_allocs_intr;
47498 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
47499 +extern atomic_unchecked_t fscache_n_alloc_ops;
47500 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
47501
47502 -extern atomic_t fscache_n_retrievals;
47503 -extern atomic_t fscache_n_retrievals_ok;
47504 -extern atomic_t fscache_n_retrievals_wait;
47505 -extern atomic_t fscache_n_retrievals_nodata;
47506 -extern atomic_t fscache_n_retrievals_nobufs;
47507 -extern atomic_t fscache_n_retrievals_intr;
47508 -extern atomic_t fscache_n_retrievals_nomem;
47509 -extern atomic_t fscache_n_retrievals_object_dead;
47510 -extern atomic_t fscache_n_retrieval_ops;
47511 -extern atomic_t fscache_n_retrieval_op_waits;
47512 +extern atomic_unchecked_t fscache_n_retrievals;
47513 +extern atomic_unchecked_t fscache_n_retrievals_ok;
47514 +extern atomic_unchecked_t fscache_n_retrievals_wait;
47515 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
47516 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
47517 +extern atomic_unchecked_t fscache_n_retrievals_intr;
47518 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
47519 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
47520 +extern atomic_unchecked_t fscache_n_retrieval_ops;
47521 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
47522
47523 -extern atomic_t fscache_n_stores;
47524 -extern atomic_t fscache_n_stores_ok;
47525 -extern atomic_t fscache_n_stores_again;
47526 -extern atomic_t fscache_n_stores_nobufs;
47527 -extern atomic_t fscache_n_stores_oom;
47528 -extern atomic_t fscache_n_store_ops;
47529 -extern atomic_t fscache_n_store_calls;
47530 -extern atomic_t fscache_n_store_pages;
47531 -extern atomic_t fscache_n_store_radix_deletes;
47532 -extern atomic_t fscache_n_store_pages_over_limit;
47533 +extern atomic_unchecked_t fscache_n_stores;
47534 +extern atomic_unchecked_t fscache_n_stores_ok;
47535 +extern atomic_unchecked_t fscache_n_stores_again;
47536 +extern atomic_unchecked_t fscache_n_stores_nobufs;
47537 +extern atomic_unchecked_t fscache_n_stores_oom;
47538 +extern atomic_unchecked_t fscache_n_store_ops;
47539 +extern atomic_unchecked_t fscache_n_store_calls;
47540 +extern atomic_unchecked_t fscache_n_store_pages;
47541 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
47542 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
47543
47544 -extern atomic_t fscache_n_store_vmscan_not_storing;
47545 -extern atomic_t fscache_n_store_vmscan_gone;
47546 -extern atomic_t fscache_n_store_vmscan_busy;
47547 -extern atomic_t fscache_n_store_vmscan_cancelled;
47548 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47549 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
47550 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
47551 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47552
47553 -extern atomic_t fscache_n_marks;
47554 -extern atomic_t fscache_n_uncaches;
47555 +extern atomic_unchecked_t fscache_n_marks;
47556 +extern atomic_unchecked_t fscache_n_uncaches;
47557
47558 -extern atomic_t fscache_n_acquires;
47559 -extern atomic_t fscache_n_acquires_null;
47560 -extern atomic_t fscache_n_acquires_no_cache;
47561 -extern atomic_t fscache_n_acquires_ok;
47562 -extern atomic_t fscache_n_acquires_nobufs;
47563 -extern atomic_t fscache_n_acquires_oom;
47564 +extern atomic_unchecked_t fscache_n_acquires;
47565 +extern atomic_unchecked_t fscache_n_acquires_null;
47566 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
47567 +extern atomic_unchecked_t fscache_n_acquires_ok;
47568 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
47569 +extern atomic_unchecked_t fscache_n_acquires_oom;
47570
47571 -extern atomic_t fscache_n_updates;
47572 -extern atomic_t fscache_n_updates_null;
47573 -extern atomic_t fscache_n_updates_run;
47574 +extern atomic_unchecked_t fscache_n_updates;
47575 +extern atomic_unchecked_t fscache_n_updates_null;
47576 +extern atomic_unchecked_t fscache_n_updates_run;
47577
47578 -extern atomic_t fscache_n_relinquishes;
47579 -extern atomic_t fscache_n_relinquishes_null;
47580 -extern atomic_t fscache_n_relinquishes_waitcrt;
47581 -extern atomic_t fscache_n_relinquishes_retire;
47582 +extern atomic_unchecked_t fscache_n_relinquishes;
47583 +extern atomic_unchecked_t fscache_n_relinquishes_null;
47584 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47585 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
47586
47587 -extern atomic_t fscache_n_cookie_index;
47588 -extern atomic_t fscache_n_cookie_data;
47589 -extern atomic_t fscache_n_cookie_special;
47590 +extern atomic_unchecked_t fscache_n_cookie_index;
47591 +extern atomic_unchecked_t fscache_n_cookie_data;
47592 +extern atomic_unchecked_t fscache_n_cookie_special;
47593
47594 -extern atomic_t fscache_n_object_alloc;
47595 -extern atomic_t fscache_n_object_no_alloc;
47596 -extern atomic_t fscache_n_object_lookups;
47597 -extern atomic_t fscache_n_object_lookups_negative;
47598 -extern atomic_t fscache_n_object_lookups_positive;
47599 -extern atomic_t fscache_n_object_lookups_timed_out;
47600 -extern atomic_t fscache_n_object_created;
47601 -extern atomic_t fscache_n_object_avail;
47602 -extern atomic_t fscache_n_object_dead;
47603 +extern atomic_unchecked_t fscache_n_object_alloc;
47604 +extern atomic_unchecked_t fscache_n_object_no_alloc;
47605 +extern atomic_unchecked_t fscache_n_object_lookups;
47606 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
47607 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
47608 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
47609 +extern atomic_unchecked_t fscache_n_object_created;
47610 +extern atomic_unchecked_t fscache_n_object_avail;
47611 +extern atomic_unchecked_t fscache_n_object_dead;
47612
47613 -extern atomic_t fscache_n_checkaux_none;
47614 -extern atomic_t fscache_n_checkaux_okay;
47615 -extern atomic_t fscache_n_checkaux_update;
47616 -extern atomic_t fscache_n_checkaux_obsolete;
47617 +extern atomic_unchecked_t fscache_n_checkaux_none;
47618 +extern atomic_unchecked_t fscache_n_checkaux_okay;
47619 +extern atomic_unchecked_t fscache_n_checkaux_update;
47620 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
47621
47622 extern atomic_t fscache_n_cop_alloc_object;
47623 extern atomic_t fscache_n_cop_lookup_object;
47624 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
47625 atomic_inc(stat);
47626 }
47627
47628 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
47629 +{
47630 + atomic_inc_unchecked(stat);
47631 +}
47632 +
47633 static inline void fscache_stat_d(atomic_t *stat)
47634 {
47635 atomic_dec(stat);
47636 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
47637
47638 #define __fscache_stat(stat) (NULL)
47639 #define fscache_stat(stat) do {} while (0)
47640 +#define fscache_stat_unchecked(stat) do {} while (0)
47641 #define fscache_stat_d(stat) do {} while (0)
47642 #endif
47643
47644 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
47645 index b6b897c..0ffff9c 100644
47646 --- a/fs/fscache/object.c
47647 +++ b/fs/fscache/object.c
47648 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47649 /* update the object metadata on disk */
47650 case FSCACHE_OBJECT_UPDATING:
47651 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
47652 - fscache_stat(&fscache_n_updates_run);
47653 + fscache_stat_unchecked(&fscache_n_updates_run);
47654 fscache_stat(&fscache_n_cop_update_object);
47655 object->cache->ops->update_object(object);
47656 fscache_stat_d(&fscache_n_cop_update_object);
47657 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47658 spin_lock(&object->lock);
47659 object->state = FSCACHE_OBJECT_DEAD;
47660 spin_unlock(&object->lock);
47661 - fscache_stat(&fscache_n_object_dead);
47662 + fscache_stat_unchecked(&fscache_n_object_dead);
47663 goto terminal_transit;
47664
47665 /* handle the parent cache of this object being withdrawn from
47666 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47667 spin_lock(&object->lock);
47668 object->state = FSCACHE_OBJECT_DEAD;
47669 spin_unlock(&object->lock);
47670 - fscache_stat(&fscache_n_object_dead);
47671 + fscache_stat_unchecked(&fscache_n_object_dead);
47672 goto terminal_transit;
47673
47674 /* complain about the object being woken up once it is
47675 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
47676 parent->cookie->def->name, cookie->def->name,
47677 object->cache->tag->name);
47678
47679 - fscache_stat(&fscache_n_object_lookups);
47680 + fscache_stat_unchecked(&fscache_n_object_lookups);
47681 fscache_stat(&fscache_n_cop_lookup_object);
47682 ret = object->cache->ops->lookup_object(object);
47683 fscache_stat_d(&fscache_n_cop_lookup_object);
47684 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
47685 if (ret == -ETIMEDOUT) {
47686 /* probably stuck behind another object, so move this one to
47687 * the back of the queue */
47688 - fscache_stat(&fscache_n_object_lookups_timed_out);
47689 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
47690 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
47691 }
47692
47693 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
47694
47695 spin_lock(&object->lock);
47696 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
47697 - fscache_stat(&fscache_n_object_lookups_negative);
47698 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
47699
47700 /* transit here to allow write requests to begin stacking up
47701 * and read requests to begin returning ENODATA */
47702 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
47703 * result, in which case there may be data available */
47704 spin_lock(&object->lock);
47705 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
47706 - fscache_stat(&fscache_n_object_lookups_positive);
47707 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
47708
47709 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
47710
47711 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
47712 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
47713 } else {
47714 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
47715 - fscache_stat(&fscache_n_object_created);
47716 + fscache_stat_unchecked(&fscache_n_object_created);
47717
47718 object->state = FSCACHE_OBJECT_AVAILABLE;
47719 spin_unlock(&object->lock);
47720 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
47721 fscache_enqueue_dependents(object);
47722
47723 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
47724 - fscache_stat(&fscache_n_object_avail);
47725 + fscache_stat_unchecked(&fscache_n_object_avail);
47726
47727 _leave("");
47728 }
47729 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
47730 enum fscache_checkaux result;
47731
47732 if (!object->cookie->def->check_aux) {
47733 - fscache_stat(&fscache_n_checkaux_none);
47734 + fscache_stat_unchecked(&fscache_n_checkaux_none);
47735 return FSCACHE_CHECKAUX_OKAY;
47736 }
47737
47738 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
47739 switch (result) {
47740 /* entry okay as is */
47741 case FSCACHE_CHECKAUX_OKAY:
47742 - fscache_stat(&fscache_n_checkaux_okay);
47743 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
47744 break;
47745
47746 /* entry requires update */
47747 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
47748 - fscache_stat(&fscache_n_checkaux_update);
47749 + fscache_stat_unchecked(&fscache_n_checkaux_update);
47750 break;
47751
47752 /* entry requires deletion */
47753 case FSCACHE_CHECKAUX_OBSOLETE:
47754 - fscache_stat(&fscache_n_checkaux_obsolete);
47755 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
47756 break;
47757
47758 default:
47759 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
47760 index 30afdfa..2256596 100644
47761 --- a/fs/fscache/operation.c
47762 +++ b/fs/fscache/operation.c
47763 @@ -17,7 +17,7 @@
47764 #include <linux/slab.h>
47765 #include "internal.h"
47766
47767 -atomic_t fscache_op_debug_id;
47768 +atomic_unchecked_t fscache_op_debug_id;
47769 EXPORT_SYMBOL(fscache_op_debug_id);
47770
47771 /**
47772 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
47773 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
47774 ASSERTCMP(atomic_read(&op->usage), >, 0);
47775
47776 - fscache_stat(&fscache_n_op_enqueue);
47777 + fscache_stat_unchecked(&fscache_n_op_enqueue);
47778 switch (op->flags & FSCACHE_OP_TYPE) {
47779 case FSCACHE_OP_ASYNC:
47780 _debug("queue async");
47781 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
47782 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
47783 if (op->processor)
47784 fscache_enqueue_operation(op);
47785 - fscache_stat(&fscache_n_op_run);
47786 + fscache_stat_unchecked(&fscache_n_op_run);
47787 }
47788
47789 /*
47790 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
47791 if (object->n_ops > 1) {
47792 atomic_inc(&op->usage);
47793 list_add_tail(&op->pend_link, &object->pending_ops);
47794 - fscache_stat(&fscache_n_op_pend);
47795 + fscache_stat_unchecked(&fscache_n_op_pend);
47796 } else if (!list_empty(&object->pending_ops)) {
47797 atomic_inc(&op->usage);
47798 list_add_tail(&op->pend_link, &object->pending_ops);
47799 - fscache_stat(&fscache_n_op_pend);
47800 + fscache_stat_unchecked(&fscache_n_op_pend);
47801 fscache_start_operations(object);
47802 } else {
47803 ASSERTCMP(object->n_in_progress, ==, 0);
47804 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
47805 object->n_exclusive++; /* reads and writes must wait */
47806 atomic_inc(&op->usage);
47807 list_add_tail(&op->pend_link, &object->pending_ops);
47808 - fscache_stat(&fscache_n_op_pend);
47809 + fscache_stat_unchecked(&fscache_n_op_pend);
47810 ret = 0;
47811 } else {
47812 /* not allowed to submit ops in any other state */
47813 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
47814 if (object->n_exclusive > 0) {
47815 atomic_inc(&op->usage);
47816 list_add_tail(&op->pend_link, &object->pending_ops);
47817 - fscache_stat(&fscache_n_op_pend);
47818 + fscache_stat_unchecked(&fscache_n_op_pend);
47819 } else if (!list_empty(&object->pending_ops)) {
47820 atomic_inc(&op->usage);
47821 list_add_tail(&op->pend_link, &object->pending_ops);
47822 - fscache_stat(&fscache_n_op_pend);
47823 + fscache_stat_unchecked(&fscache_n_op_pend);
47824 fscache_start_operations(object);
47825 } else {
47826 ASSERTCMP(object->n_exclusive, ==, 0);
47827 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
47828 object->n_ops++;
47829 atomic_inc(&op->usage);
47830 list_add_tail(&op->pend_link, &object->pending_ops);
47831 - fscache_stat(&fscache_n_op_pend);
47832 + fscache_stat_unchecked(&fscache_n_op_pend);
47833 ret = 0;
47834 } else if (object->state == FSCACHE_OBJECT_DYING ||
47835 object->state == FSCACHE_OBJECT_LC_DYING ||
47836 object->state == FSCACHE_OBJECT_WITHDRAWING) {
47837 - fscache_stat(&fscache_n_op_rejected);
47838 + fscache_stat_unchecked(&fscache_n_op_rejected);
47839 ret = -ENOBUFS;
47840 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
47841 fscache_report_unexpected_submission(object, op, ostate);
47842 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
47843
47844 ret = -EBUSY;
47845 if (!list_empty(&op->pend_link)) {
47846 - fscache_stat(&fscache_n_op_cancelled);
47847 + fscache_stat_unchecked(&fscache_n_op_cancelled);
47848 list_del_init(&op->pend_link);
47849 object->n_ops--;
47850 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
47851 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
47852 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
47853 BUG();
47854
47855 - fscache_stat(&fscache_n_op_release);
47856 + fscache_stat_unchecked(&fscache_n_op_release);
47857
47858 if (op->release) {
47859 op->release(op);
47860 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
47861 * lock, and defer it otherwise */
47862 if (!spin_trylock(&object->lock)) {
47863 _debug("defer put");
47864 - fscache_stat(&fscache_n_op_deferred_release);
47865 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
47866
47867 cache = object->cache;
47868 spin_lock(&cache->op_gc_list_lock);
47869 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
47870
47871 _debug("GC DEFERRED REL OBJ%x OP%x",
47872 object->debug_id, op->debug_id);
47873 - fscache_stat(&fscache_n_op_gc);
47874 + fscache_stat_unchecked(&fscache_n_op_gc);
47875
47876 ASSERTCMP(atomic_read(&op->usage), ==, 0);
47877
47878 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
47879 index 3f7a59b..cf196cc 100644
47880 --- a/fs/fscache/page.c
47881 +++ b/fs/fscache/page.c
47882 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47883 val = radix_tree_lookup(&cookie->stores, page->index);
47884 if (!val) {
47885 rcu_read_unlock();
47886 - fscache_stat(&fscache_n_store_vmscan_not_storing);
47887 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
47888 __fscache_uncache_page(cookie, page);
47889 return true;
47890 }
47891 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47892 spin_unlock(&cookie->stores_lock);
47893
47894 if (xpage) {
47895 - fscache_stat(&fscache_n_store_vmscan_cancelled);
47896 - fscache_stat(&fscache_n_store_radix_deletes);
47897 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
47898 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47899 ASSERTCMP(xpage, ==, page);
47900 } else {
47901 - fscache_stat(&fscache_n_store_vmscan_gone);
47902 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
47903 }
47904
47905 wake_up_bit(&cookie->flags, 0);
47906 @@ -107,7 +107,7 @@ page_busy:
47907 /* we might want to wait here, but that could deadlock the allocator as
47908 * the work threads writing to the cache may all end up sleeping
47909 * on memory allocation */
47910 - fscache_stat(&fscache_n_store_vmscan_busy);
47911 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
47912 return false;
47913 }
47914 EXPORT_SYMBOL(__fscache_maybe_release_page);
47915 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
47916 FSCACHE_COOKIE_STORING_TAG);
47917 if (!radix_tree_tag_get(&cookie->stores, page->index,
47918 FSCACHE_COOKIE_PENDING_TAG)) {
47919 - fscache_stat(&fscache_n_store_radix_deletes);
47920 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47921 xpage = radix_tree_delete(&cookie->stores, page->index);
47922 }
47923 spin_unlock(&cookie->stores_lock);
47924 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
47925
47926 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
47927
47928 - fscache_stat(&fscache_n_attr_changed_calls);
47929 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
47930
47931 if (fscache_object_is_active(object)) {
47932 fscache_stat(&fscache_n_cop_attr_changed);
47933 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47934
47935 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47936
47937 - fscache_stat(&fscache_n_attr_changed);
47938 + fscache_stat_unchecked(&fscache_n_attr_changed);
47939
47940 op = kzalloc(sizeof(*op), GFP_KERNEL);
47941 if (!op) {
47942 - fscache_stat(&fscache_n_attr_changed_nomem);
47943 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
47944 _leave(" = -ENOMEM");
47945 return -ENOMEM;
47946 }
47947 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47948 if (fscache_submit_exclusive_op(object, op) < 0)
47949 goto nobufs;
47950 spin_unlock(&cookie->lock);
47951 - fscache_stat(&fscache_n_attr_changed_ok);
47952 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
47953 fscache_put_operation(op);
47954 _leave(" = 0");
47955 return 0;
47956 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47957 nobufs:
47958 spin_unlock(&cookie->lock);
47959 kfree(op);
47960 - fscache_stat(&fscache_n_attr_changed_nobufs);
47961 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
47962 _leave(" = %d", -ENOBUFS);
47963 return -ENOBUFS;
47964 }
47965 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
47966 /* allocate a retrieval operation and attempt to submit it */
47967 op = kzalloc(sizeof(*op), GFP_NOIO);
47968 if (!op) {
47969 - fscache_stat(&fscache_n_retrievals_nomem);
47970 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47971 return NULL;
47972 }
47973
47974 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47975 return 0;
47976 }
47977
47978 - fscache_stat(&fscache_n_retrievals_wait);
47979 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
47980
47981 jif = jiffies;
47982 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
47983 fscache_wait_bit_interruptible,
47984 TASK_INTERRUPTIBLE) != 0) {
47985 - fscache_stat(&fscache_n_retrievals_intr);
47986 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47987 _leave(" = -ERESTARTSYS");
47988 return -ERESTARTSYS;
47989 }
47990 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47991 */
47992 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47993 struct fscache_retrieval *op,
47994 - atomic_t *stat_op_waits,
47995 - atomic_t *stat_object_dead)
47996 + atomic_unchecked_t *stat_op_waits,
47997 + atomic_unchecked_t *stat_object_dead)
47998 {
47999 int ret;
48000
48001 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48002 goto check_if_dead;
48003
48004 _debug(">>> WT");
48005 - fscache_stat(stat_op_waits);
48006 + fscache_stat_unchecked(stat_op_waits);
48007 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48008 fscache_wait_bit_interruptible,
48009 TASK_INTERRUPTIBLE) < 0) {
48010 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48011
48012 check_if_dead:
48013 if (unlikely(fscache_object_is_dead(object))) {
48014 - fscache_stat(stat_object_dead);
48015 + fscache_stat_unchecked(stat_object_dead);
48016 return -ENOBUFS;
48017 }
48018 return 0;
48019 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48020
48021 _enter("%p,%p,,,", cookie, page);
48022
48023 - fscache_stat(&fscache_n_retrievals);
48024 + fscache_stat_unchecked(&fscache_n_retrievals);
48025
48026 if (hlist_empty(&cookie->backing_objects))
48027 goto nobufs;
48028 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48029 goto nobufs_unlock;
48030 spin_unlock(&cookie->lock);
48031
48032 - fscache_stat(&fscache_n_retrieval_ops);
48033 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48034
48035 /* pin the netfs read context in case we need to do the actual netfs
48036 * read because we've encountered a cache read failure */
48037 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48038
48039 error:
48040 if (ret == -ENOMEM)
48041 - fscache_stat(&fscache_n_retrievals_nomem);
48042 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48043 else if (ret == -ERESTARTSYS)
48044 - fscache_stat(&fscache_n_retrievals_intr);
48045 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48046 else if (ret == -ENODATA)
48047 - fscache_stat(&fscache_n_retrievals_nodata);
48048 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48049 else if (ret < 0)
48050 - fscache_stat(&fscache_n_retrievals_nobufs);
48051 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48052 else
48053 - fscache_stat(&fscache_n_retrievals_ok);
48054 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48055
48056 fscache_put_retrieval(op);
48057 _leave(" = %d", ret);
48058 @@ -429,7 +429,7 @@ nobufs_unlock:
48059 spin_unlock(&cookie->lock);
48060 kfree(op);
48061 nobufs:
48062 - fscache_stat(&fscache_n_retrievals_nobufs);
48063 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48064 _leave(" = -ENOBUFS");
48065 return -ENOBUFS;
48066 }
48067 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48068
48069 _enter("%p,,%d,,,", cookie, *nr_pages);
48070
48071 - fscache_stat(&fscache_n_retrievals);
48072 + fscache_stat_unchecked(&fscache_n_retrievals);
48073
48074 if (hlist_empty(&cookie->backing_objects))
48075 goto nobufs;
48076 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48077 goto nobufs_unlock;
48078 spin_unlock(&cookie->lock);
48079
48080 - fscache_stat(&fscache_n_retrieval_ops);
48081 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48082
48083 /* pin the netfs read context in case we need to do the actual netfs
48084 * read because we've encountered a cache read failure */
48085 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48086
48087 error:
48088 if (ret == -ENOMEM)
48089 - fscache_stat(&fscache_n_retrievals_nomem);
48090 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48091 else if (ret == -ERESTARTSYS)
48092 - fscache_stat(&fscache_n_retrievals_intr);
48093 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48094 else if (ret == -ENODATA)
48095 - fscache_stat(&fscache_n_retrievals_nodata);
48096 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48097 else if (ret < 0)
48098 - fscache_stat(&fscache_n_retrievals_nobufs);
48099 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48100 else
48101 - fscache_stat(&fscache_n_retrievals_ok);
48102 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48103
48104 fscache_put_retrieval(op);
48105 _leave(" = %d", ret);
48106 @@ -545,7 +545,7 @@ nobufs_unlock:
48107 spin_unlock(&cookie->lock);
48108 kfree(op);
48109 nobufs:
48110 - fscache_stat(&fscache_n_retrievals_nobufs);
48111 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48112 _leave(" = -ENOBUFS");
48113 return -ENOBUFS;
48114 }
48115 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48116
48117 _enter("%p,%p,,,", cookie, page);
48118
48119 - fscache_stat(&fscache_n_allocs);
48120 + fscache_stat_unchecked(&fscache_n_allocs);
48121
48122 if (hlist_empty(&cookie->backing_objects))
48123 goto nobufs;
48124 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48125 goto nobufs_unlock;
48126 spin_unlock(&cookie->lock);
48127
48128 - fscache_stat(&fscache_n_alloc_ops);
48129 + fscache_stat_unchecked(&fscache_n_alloc_ops);
48130
48131 ret = fscache_wait_for_retrieval_activation(
48132 object, op,
48133 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48134
48135 error:
48136 if (ret == -ERESTARTSYS)
48137 - fscache_stat(&fscache_n_allocs_intr);
48138 + fscache_stat_unchecked(&fscache_n_allocs_intr);
48139 else if (ret < 0)
48140 - fscache_stat(&fscache_n_allocs_nobufs);
48141 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48142 else
48143 - fscache_stat(&fscache_n_allocs_ok);
48144 + fscache_stat_unchecked(&fscache_n_allocs_ok);
48145
48146 fscache_put_retrieval(op);
48147 _leave(" = %d", ret);
48148 @@ -625,7 +625,7 @@ nobufs_unlock:
48149 spin_unlock(&cookie->lock);
48150 kfree(op);
48151 nobufs:
48152 - fscache_stat(&fscache_n_allocs_nobufs);
48153 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48154 _leave(" = -ENOBUFS");
48155 return -ENOBUFS;
48156 }
48157 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48158
48159 spin_lock(&cookie->stores_lock);
48160
48161 - fscache_stat(&fscache_n_store_calls);
48162 + fscache_stat_unchecked(&fscache_n_store_calls);
48163
48164 /* find a page to store */
48165 page = NULL;
48166 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48167 page = results[0];
48168 _debug("gang %d [%lx]", n, page->index);
48169 if (page->index > op->store_limit) {
48170 - fscache_stat(&fscache_n_store_pages_over_limit);
48171 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48172 goto superseded;
48173 }
48174
48175 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48176 spin_unlock(&cookie->stores_lock);
48177 spin_unlock(&object->lock);
48178
48179 - fscache_stat(&fscache_n_store_pages);
48180 + fscache_stat_unchecked(&fscache_n_store_pages);
48181 fscache_stat(&fscache_n_cop_write_page);
48182 ret = object->cache->ops->write_page(op, page);
48183 fscache_stat_d(&fscache_n_cop_write_page);
48184 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48185 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48186 ASSERT(PageFsCache(page));
48187
48188 - fscache_stat(&fscache_n_stores);
48189 + fscache_stat_unchecked(&fscache_n_stores);
48190
48191 op = kzalloc(sizeof(*op), GFP_NOIO);
48192 if (!op)
48193 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48194 spin_unlock(&cookie->stores_lock);
48195 spin_unlock(&object->lock);
48196
48197 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48198 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48199 op->store_limit = object->store_limit;
48200
48201 if (fscache_submit_op(object, &op->op) < 0)
48202 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48203
48204 spin_unlock(&cookie->lock);
48205 radix_tree_preload_end();
48206 - fscache_stat(&fscache_n_store_ops);
48207 - fscache_stat(&fscache_n_stores_ok);
48208 + fscache_stat_unchecked(&fscache_n_store_ops);
48209 + fscache_stat_unchecked(&fscache_n_stores_ok);
48210
48211 /* the work queue now carries its own ref on the object */
48212 fscache_put_operation(&op->op);
48213 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48214 return 0;
48215
48216 already_queued:
48217 - fscache_stat(&fscache_n_stores_again);
48218 + fscache_stat_unchecked(&fscache_n_stores_again);
48219 already_pending:
48220 spin_unlock(&cookie->stores_lock);
48221 spin_unlock(&object->lock);
48222 spin_unlock(&cookie->lock);
48223 radix_tree_preload_end();
48224 kfree(op);
48225 - fscache_stat(&fscache_n_stores_ok);
48226 + fscache_stat_unchecked(&fscache_n_stores_ok);
48227 _leave(" = 0");
48228 return 0;
48229
48230 @@ -851,14 +851,14 @@ nobufs:
48231 spin_unlock(&cookie->lock);
48232 radix_tree_preload_end();
48233 kfree(op);
48234 - fscache_stat(&fscache_n_stores_nobufs);
48235 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
48236 _leave(" = -ENOBUFS");
48237 return -ENOBUFS;
48238
48239 nomem_free:
48240 kfree(op);
48241 nomem:
48242 - fscache_stat(&fscache_n_stores_oom);
48243 + fscache_stat_unchecked(&fscache_n_stores_oom);
48244 _leave(" = -ENOMEM");
48245 return -ENOMEM;
48246 }
48247 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48248 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48249 ASSERTCMP(page, !=, NULL);
48250
48251 - fscache_stat(&fscache_n_uncaches);
48252 + fscache_stat_unchecked(&fscache_n_uncaches);
48253
48254 /* cache withdrawal may beat us to it */
48255 if (!PageFsCache(page))
48256 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48257 unsigned long loop;
48258
48259 #ifdef CONFIG_FSCACHE_STATS
48260 - atomic_add(pagevec->nr, &fscache_n_marks);
48261 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48262 #endif
48263
48264 for (loop = 0; loop < pagevec->nr; loop++) {
48265 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48266 index 4765190..2a067f2 100644
48267 --- a/fs/fscache/stats.c
48268 +++ b/fs/fscache/stats.c
48269 @@ -18,95 +18,95 @@
48270 /*
48271 * operation counters
48272 */
48273 -atomic_t fscache_n_op_pend;
48274 -atomic_t fscache_n_op_run;
48275 -atomic_t fscache_n_op_enqueue;
48276 -atomic_t fscache_n_op_requeue;
48277 -atomic_t fscache_n_op_deferred_release;
48278 -atomic_t fscache_n_op_release;
48279 -atomic_t fscache_n_op_gc;
48280 -atomic_t fscache_n_op_cancelled;
48281 -atomic_t fscache_n_op_rejected;
48282 +atomic_unchecked_t fscache_n_op_pend;
48283 +atomic_unchecked_t fscache_n_op_run;
48284 +atomic_unchecked_t fscache_n_op_enqueue;
48285 +atomic_unchecked_t fscache_n_op_requeue;
48286 +atomic_unchecked_t fscache_n_op_deferred_release;
48287 +atomic_unchecked_t fscache_n_op_release;
48288 +atomic_unchecked_t fscache_n_op_gc;
48289 +atomic_unchecked_t fscache_n_op_cancelled;
48290 +atomic_unchecked_t fscache_n_op_rejected;
48291
48292 -atomic_t fscache_n_attr_changed;
48293 -atomic_t fscache_n_attr_changed_ok;
48294 -atomic_t fscache_n_attr_changed_nobufs;
48295 -atomic_t fscache_n_attr_changed_nomem;
48296 -atomic_t fscache_n_attr_changed_calls;
48297 +atomic_unchecked_t fscache_n_attr_changed;
48298 +atomic_unchecked_t fscache_n_attr_changed_ok;
48299 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
48300 +atomic_unchecked_t fscache_n_attr_changed_nomem;
48301 +atomic_unchecked_t fscache_n_attr_changed_calls;
48302
48303 -atomic_t fscache_n_allocs;
48304 -atomic_t fscache_n_allocs_ok;
48305 -atomic_t fscache_n_allocs_wait;
48306 -atomic_t fscache_n_allocs_nobufs;
48307 -atomic_t fscache_n_allocs_intr;
48308 -atomic_t fscache_n_allocs_object_dead;
48309 -atomic_t fscache_n_alloc_ops;
48310 -atomic_t fscache_n_alloc_op_waits;
48311 +atomic_unchecked_t fscache_n_allocs;
48312 +atomic_unchecked_t fscache_n_allocs_ok;
48313 +atomic_unchecked_t fscache_n_allocs_wait;
48314 +atomic_unchecked_t fscache_n_allocs_nobufs;
48315 +atomic_unchecked_t fscache_n_allocs_intr;
48316 +atomic_unchecked_t fscache_n_allocs_object_dead;
48317 +atomic_unchecked_t fscache_n_alloc_ops;
48318 +atomic_unchecked_t fscache_n_alloc_op_waits;
48319
48320 -atomic_t fscache_n_retrievals;
48321 -atomic_t fscache_n_retrievals_ok;
48322 -atomic_t fscache_n_retrievals_wait;
48323 -atomic_t fscache_n_retrievals_nodata;
48324 -atomic_t fscache_n_retrievals_nobufs;
48325 -atomic_t fscache_n_retrievals_intr;
48326 -atomic_t fscache_n_retrievals_nomem;
48327 -atomic_t fscache_n_retrievals_object_dead;
48328 -atomic_t fscache_n_retrieval_ops;
48329 -atomic_t fscache_n_retrieval_op_waits;
48330 +atomic_unchecked_t fscache_n_retrievals;
48331 +atomic_unchecked_t fscache_n_retrievals_ok;
48332 +atomic_unchecked_t fscache_n_retrievals_wait;
48333 +atomic_unchecked_t fscache_n_retrievals_nodata;
48334 +atomic_unchecked_t fscache_n_retrievals_nobufs;
48335 +atomic_unchecked_t fscache_n_retrievals_intr;
48336 +atomic_unchecked_t fscache_n_retrievals_nomem;
48337 +atomic_unchecked_t fscache_n_retrievals_object_dead;
48338 +atomic_unchecked_t fscache_n_retrieval_ops;
48339 +atomic_unchecked_t fscache_n_retrieval_op_waits;
48340
48341 -atomic_t fscache_n_stores;
48342 -atomic_t fscache_n_stores_ok;
48343 -atomic_t fscache_n_stores_again;
48344 -atomic_t fscache_n_stores_nobufs;
48345 -atomic_t fscache_n_stores_oom;
48346 -atomic_t fscache_n_store_ops;
48347 -atomic_t fscache_n_store_calls;
48348 -atomic_t fscache_n_store_pages;
48349 -atomic_t fscache_n_store_radix_deletes;
48350 -atomic_t fscache_n_store_pages_over_limit;
48351 +atomic_unchecked_t fscache_n_stores;
48352 +atomic_unchecked_t fscache_n_stores_ok;
48353 +atomic_unchecked_t fscache_n_stores_again;
48354 +atomic_unchecked_t fscache_n_stores_nobufs;
48355 +atomic_unchecked_t fscache_n_stores_oom;
48356 +atomic_unchecked_t fscache_n_store_ops;
48357 +atomic_unchecked_t fscache_n_store_calls;
48358 +atomic_unchecked_t fscache_n_store_pages;
48359 +atomic_unchecked_t fscache_n_store_radix_deletes;
48360 +atomic_unchecked_t fscache_n_store_pages_over_limit;
48361
48362 -atomic_t fscache_n_store_vmscan_not_storing;
48363 -atomic_t fscache_n_store_vmscan_gone;
48364 -atomic_t fscache_n_store_vmscan_busy;
48365 -atomic_t fscache_n_store_vmscan_cancelled;
48366 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48367 +atomic_unchecked_t fscache_n_store_vmscan_gone;
48368 +atomic_unchecked_t fscache_n_store_vmscan_busy;
48369 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48370
48371 -atomic_t fscache_n_marks;
48372 -atomic_t fscache_n_uncaches;
48373 +atomic_unchecked_t fscache_n_marks;
48374 +atomic_unchecked_t fscache_n_uncaches;
48375
48376 -atomic_t fscache_n_acquires;
48377 -atomic_t fscache_n_acquires_null;
48378 -atomic_t fscache_n_acquires_no_cache;
48379 -atomic_t fscache_n_acquires_ok;
48380 -atomic_t fscache_n_acquires_nobufs;
48381 -atomic_t fscache_n_acquires_oom;
48382 +atomic_unchecked_t fscache_n_acquires;
48383 +atomic_unchecked_t fscache_n_acquires_null;
48384 +atomic_unchecked_t fscache_n_acquires_no_cache;
48385 +atomic_unchecked_t fscache_n_acquires_ok;
48386 +atomic_unchecked_t fscache_n_acquires_nobufs;
48387 +atomic_unchecked_t fscache_n_acquires_oom;
48388
48389 -atomic_t fscache_n_updates;
48390 -atomic_t fscache_n_updates_null;
48391 -atomic_t fscache_n_updates_run;
48392 +atomic_unchecked_t fscache_n_updates;
48393 +atomic_unchecked_t fscache_n_updates_null;
48394 +atomic_unchecked_t fscache_n_updates_run;
48395
48396 -atomic_t fscache_n_relinquishes;
48397 -atomic_t fscache_n_relinquishes_null;
48398 -atomic_t fscache_n_relinquishes_waitcrt;
48399 -atomic_t fscache_n_relinquishes_retire;
48400 +atomic_unchecked_t fscache_n_relinquishes;
48401 +atomic_unchecked_t fscache_n_relinquishes_null;
48402 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48403 +atomic_unchecked_t fscache_n_relinquishes_retire;
48404
48405 -atomic_t fscache_n_cookie_index;
48406 -atomic_t fscache_n_cookie_data;
48407 -atomic_t fscache_n_cookie_special;
48408 +atomic_unchecked_t fscache_n_cookie_index;
48409 +atomic_unchecked_t fscache_n_cookie_data;
48410 +atomic_unchecked_t fscache_n_cookie_special;
48411
48412 -atomic_t fscache_n_object_alloc;
48413 -atomic_t fscache_n_object_no_alloc;
48414 -atomic_t fscache_n_object_lookups;
48415 -atomic_t fscache_n_object_lookups_negative;
48416 -atomic_t fscache_n_object_lookups_positive;
48417 -atomic_t fscache_n_object_lookups_timed_out;
48418 -atomic_t fscache_n_object_created;
48419 -atomic_t fscache_n_object_avail;
48420 -atomic_t fscache_n_object_dead;
48421 +atomic_unchecked_t fscache_n_object_alloc;
48422 +atomic_unchecked_t fscache_n_object_no_alloc;
48423 +atomic_unchecked_t fscache_n_object_lookups;
48424 +atomic_unchecked_t fscache_n_object_lookups_negative;
48425 +atomic_unchecked_t fscache_n_object_lookups_positive;
48426 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
48427 +atomic_unchecked_t fscache_n_object_created;
48428 +atomic_unchecked_t fscache_n_object_avail;
48429 +atomic_unchecked_t fscache_n_object_dead;
48430
48431 -atomic_t fscache_n_checkaux_none;
48432 -atomic_t fscache_n_checkaux_okay;
48433 -atomic_t fscache_n_checkaux_update;
48434 -atomic_t fscache_n_checkaux_obsolete;
48435 +atomic_unchecked_t fscache_n_checkaux_none;
48436 +atomic_unchecked_t fscache_n_checkaux_okay;
48437 +atomic_unchecked_t fscache_n_checkaux_update;
48438 +atomic_unchecked_t fscache_n_checkaux_obsolete;
48439
48440 atomic_t fscache_n_cop_alloc_object;
48441 atomic_t fscache_n_cop_lookup_object;
48442 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
48443 seq_puts(m, "FS-Cache statistics\n");
48444
48445 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
48446 - atomic_read(&fscache_n_cookie_index),
48447 - atomic_read(&fscache_n_cookie_data),
48448 - atomic_read(&fscache_n_cookie_special));
48449 + atomic_read_unchecked(&fscache_n_cookie_index),
48450 + atomic_read_unchecked(&fscache_n_cookie_data),
48451 + atomic_read_unchecked(&fscache_n_cookie_special));
48452
48453 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
48454 - atomic_read(&fscache_n_object_alloc),
48455 - atomic_read(&fscache_n_object_no_alloc),
48456 - atomic_read(&fscache_n_object_avail),
48457 - atomic_read(&fscache_n_object_dead));
48458 + atomic_read_unchecked(&fscache_n_object_alloc),
48459 + atomic_read_unchecked(&fscache_n_object_no_alloc),
48460 + atomic_read_unchecked(&fscache_n_object_avail),
48461 + atomic_read_unchecked(&fscache_n_object_dead));
48462 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
48463 - atomic_read(&fscache_n_checkaux_none),
48464 - atomic_read(&fscache_n_checkaux_okay),
48465 - atomic_read(&fscache_n_checkaux_update),
48466 - atomic_read(&fscache_n_checkaux_obsolete));
48467 + atomic_read_unchecked(&fscache_n_checkaux_none),
48468 + atomic_read_unchecked(&fscache_n_checkaux_okay),
48469 + atomic_read_unchecked(&fscache_n_checkaux_update),
48470 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
48471
48472 seq_printf(m, "Pages : mrk=%u unc=%u\n",
48473 - atomic_read(&fscache_n_marks),
48474 - atomic_read(&fscache_n_uncaches));
48475 + atomic_read_unchecked(&fscache_n_marks),
48476 + atomic_read_unchecked(&fscache_n_uncaches));
48477
48478 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
48479 " oom=%u\n",
48480 - atomic_read(&fscache_n_acquires),
48481 - atomic_read(&fscache_n_acquires_null),
48482 - atomic_read(&fscache_n_acquires_no_cache),
48483 - atomic_read(&fscache_n_acquires_ok),
48484 - atomic_read(&fscache_n_acquires_nobufs),
48485 - atomic_read(&fscache_n_acquires_oom));
48486 + atomic_read_unchecked(&fscache_n_acquires),
48487 + atomic_read_unchecked(&fscache_n_acquires_null),
48488 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
48489 + atomic_read_unchecked(&fscache_n_acquires_ok),
48490 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
48491 + atomic_read_unchecked(&fscache_n_acquires_oom));
48492
48493 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
48494 - atomic_read(&fscache_n_object_lookups),
48495 - atomic_read(&fscache_n_object_lookups_negative),
48496 - atomic_read(&fscache_n_object_lookups_positive),
48497 - atomic_read(&fscache_n_object_created),
48498 - atomic_read(&fscache_n_object_lookups_timed_out));
48499 + atomic_read_unchecked(&fscache_n_object_lookups),
48500 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
48501 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
48502 + atomic_read_unchecked(&fscache_n_object_created),
48503 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
48504
48505 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
48506 - atomic_read(&fscache_n_updates),
48507 - atomic_read(&fscache_n_updates_null),
48508 - atomic_read(&fscache_n_updates_run));
48509 + atomic_read_unchecked(&fscache_n_updates),
48510 + atomic_read_unchecked(&fscache_n_updates_null),
48511 + atomic_read_unchecked(&fscache_n_updates_run));
48512
48513 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
48514 - atomic_read(&fscache_n_relinquishes),
48515 - atomic_read(&fscache_n_relinquishes_null),
48516 - atomic_read(&fscache_n_relinquishes_waitcrt),
48517 - atomic_read(&fscache_n_relinquishes_retire));
48518 + atomic_read_unchecked(&fscache_n_relinquishes),
48519 + atomic_read_unchecked(&fscache_n_relinquishes_null),
48520 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
48521 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
48522
48523 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
48524 - atomic_read(&fscache_n_attr_changed),
48525 - atomic_read(&fscache_n_attr_changed_ok),
48526 - atomic_read(&fscache_n_attr_changed_nobufs),
48527 - atomic_read(&fscache_n_attr_changed_nomem),
48528 - atomic_read(&fscache_n_attr_changed_calls));
48529 + atomic_read_unchecked(&fscache_n_attr_changed),
48530 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
48531 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
48532 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
48533 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
48534
48535 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
48536 - atomic_read(&fscache_n_allocs),
48537 - atomic_read(&fscache_n_allocs_ok),
48538 - atomic_read(&fscache_n_allocs_wait),
48539 - atomic_read(&fscache_n_allocs_nobufs),
48540 - atomic_read(&fscache_n_allocs_intr));
48541 + atomic_read_unchecked(&fscache_n_allocs),
48542 + atomic_read_unchecked(&fscache_n_allocs_ok),
48543 + atomic_read_unchecked(&fscache_n_allocs_wait),
48544 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
48545 + atomic_read_unchecked(&fscache_n_allocs_intr));
48546 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
48547 - atomic_read(&fscache_n_alloc_ops),
48548 - atomic_read(&fscache_n_alloc_op_waits),
48549 - atomic_read(&fscache_n_allocs_object_dead));
48550 + atomic_read_unchecked(&fscache_n_alloc_ops),
48551 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
48552 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
48553
48554 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
48555 " int=%u oom=%u\n",
48556 - atomic_read(&fscache_n_retrievals),
48557 - atomic_read(&fscache_n_retrievals_ok),
48558 - atomic_read(&fscache_n_retrievals_wait),
48559 - atomic_read(&fscache_n_retrievals_nodata),
48560 - atomic_read(&fscache_n_retrievals_nobufs),
48561 - atomic_read(&fscache_n_retrievals_intr),
48562 - atomic_read(&fscache_n_retrievals_nomem));
48563 + atomic_read_unchecked(&fscache_n_retrievals),
48564 + atomic_read_unchecked(&fscache_n_retrievals_ok),
48565 + atomic_read_unchecked(&fscache_n_retrievals_wait),
48566 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
48567 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
48568 + atomic_read_unchecked(&fscache_n_retrievals_intr),
48569 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
48570 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
48571 - atomic_read(&fscache_n_retrieval_ops),
48572 - atomic_read(&fscache_n_retrieval_op_waits),
48573 - atomic_read(&fscache_n_retrievals_object_dead));
48574 + atomic_read_unchecked(&fscache_n_retrieval_ops),
48575 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
48576 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
48577
48578 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
48579 - atomic_read(&fscache_n_stores),
48580 - atomic_read(&fscache_n_stores_ok),
48581 - atomic_read(&fscache_n_stores_again),
48582 - atomic_read(&fscache_n_stores_nobufs),
48583 - atomic_read(&fscache_n_stores_oom));
48584 + atomic_read_unchecked(&fscache_n_stores),
48585 + atomic_read_unchecked(&fscache_n_stores_ok),
48586 + atomic_read_unchecked(&fscache_n_stores_again),
48587 + atomic_read_unchecked(&fscache_n_stores_nobufs),
48588 + atomic_read_unchecked(&fscache_n_stores_oom));
48589 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
48590 - atomic_read(&fscache_n_store_ops),
48591 - atomic_read(&fscache_n_store_calls),
48592 - atomic_read(&fscache_n_store_pages),
48593 - atomic_read(&fscache_n_store_radix_deletes),
48594 - atomic_read(&fscache_n_store_pages_over_limit));
48595 + atomic_read_unchecked(&fscache_n_store_ops),
48596 + atomic_read_unchecked(&fscache_n_store_calls),
48597 + atomic_read_unchecked(&fscache_n_store_pages),
48598 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
48599 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
48600
48601 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
48602 - atomic_read(&fscache_n_store_vmscan_not_storing),
48603 - atomic_read(&fscache_n_store_vmscan_gone),
48604 - atomic_read(&fscache_n_store_vmscan_busy),
48605 - atomic_read(&fscache_n_store_vmscan_cancelled));
48606 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
48607 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
48608 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
48609 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
48610
48611 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
48612 - atomic_read(&fscache_n_op_pend),
48613 - atomic_read(&fscache_n_op_run),
48614 - atomic_read(&fscache_n_op_enqueue),
48615 - atomic_read(&fscache_n_op_cancelled),
48616 - atomic_read(&fscache_n_op_rejected));
48617 + atomic_read_unchecked(&fscache_n_op_pend),
48618 + atomic_read_unchecked(&fscache_n_op_run),
48619 + atomic_read_unchecked(&fscache_n_op_enqueue),
48620 + atomic_read_unchecked(&fscache_n_op_cancelled),
48621 + atomic_read_unchecked(&fscache_n_op_rejected));
48622 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
48623 - atomic_read(&fscache_n_op_deferred_release),
48624 - atomic_read(&fscache_n_op_release),
48625 - atomic_read(&fscache_n_op_gc));
48626 + atomic_read_unchecked(&fscache_n_op_deferred_release),
48627 + atomic_read_unchecked(&fscache_n_op_release),
48628 + atomic_read_unchecked(&fscache_n_op_gc));
48629
48630 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
48631 atomic_read(&fscache_n_cop_alloc_object),
48632 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
48633 index ee8d550..7189d8c 100644
48634 --- a/fs/fuse/cuse.c
48635 +++ b/fs/fuse/cuse.c
48636 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
48637 INIT_LIST_HEAD(&cuse_conntbl[i]);
48638
48639 /* inherit and extend fuse_dev_operations */
48640 - cuse_channel_fops = fuse_dev_operations;
48641 - cuse_channel_fops.owner = THIS_MODULE;
48642 - cuse_channel_fops.open = cuse_channel_open;
48643 - cuse_channel_fops.release = cuse_channel_release;
48644 + pax_open_kernel();
48645 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
48646 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
48647 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
48648 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
48649 + pax_close_kernel();
48650
48651 cuse_class = class_create(THIS_MODULE, "cuse");
48652 if (IS_ERR(cuse_class))
48653 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
48654 index 8c23fa7..0e3aac7 100644
48655 --- a/fs/fuse/dev.c
48656 +++ b/fs/fuse/dev.c
48657 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
48658 ret = 0;
48659 pipe_lock(pipe);
48660
48661 - if (!pipe->readers) {
48662 + if (!atomic_read(&pipe->readers)) {
48663 send_sig(SIGPIPE, current, 0);
48664 if (!ret)
48665 ret = -EPIPE;
48666 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
48667 index 324bc08..4fdd56e 100644
48668 --- a/fs/fuse/dir.c
48669 +++ b/fs/fuse/dir.c
48670 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
48671 return link;
48672 }
48673
48674 -static void free_link(char *link)
48675 +static void free_link(const char *link)
48676 {
48677 if (!IS_ERR(link))
48678 free_page((unsigned long) link);
48679 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
48680 index 381893c..3793318 100644
48681 --- a/fs/gfs2/inode.c
48682 +++ b/fs/gfs2/inode.c
48683 @@ -1490,7 +1490,7 @@ out:
48684
48685 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48686 {
48687 - char *s = nd_get_link(nd);
48688 + const char *s = nd_get_link(nd);
48689 if (!IS_ERR(s))
48690 kfree(s);
48691 }
48692 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
48693 index c5bc355..5a513bb 100644
48694 --- a/fs/hugetlbfs/inode.c
48695 +++ b/fs/hugetlbfs/inode.c
48696 @@ -923,7 +923,7 @@ static struct file_system_type hugetlbfs_fs_type = {
48697 .kill_sb = kill_litter_super,
48698 };
48699
48700 -static struct vfsmount *hugetlbfs_vfsmount;
48701 +struct vfsmount *hugetlbfs_vfsmount;
48702
48703 static int can_do_hugetlb_shm(void)
48704 {
48705 diff --git a/fs/inode.c b/fs/inode.c
48706 index 64999f1..8fad608 100644
48707 --- a/fs/inode.c
48708 +++ b/fs/inode.c
48709 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
48710
48711 #ifdef CONFIG_SMP
48712 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
48713 - static atomic_t shared_last_ino;
48714 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
48715 + static atomic_unchecked_t shared_last_ino;
48716 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
48717
48718 res = next - LAST_INO_BATCH;
48719 }
48720 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
48721 index 4a6cf28..d3a29d3 100644
48722 --- a/fs/jffs2/erase.c
48723 +++ b/fs/jffs2/erase.c
48724 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
48725 struct jffs2_unknown_node marker = {
48726 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
48727 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
48728 - .totlen = cpu_to_je32(c->cleanmarker_size)
48729 + .totlen = cpu_to_je32(c->cleanmarker_size),
48730 + .hdr_crc = cpu_to_je32(0)
48731 };
48732
48733 jffs2_prealloc_raw_node_refs(c, jeb, 1);
48734 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
48735 index a6597d6..41b30ec 100644
48736 --- a/fs/jffs2/wbuf.c
48737 +++ b/fs/jffs2/wbuf.c
48738 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
48739 {
48740 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
48741 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
48742 - .totlen = constant_cpu_to_je32(8)
48743 + .totlen = constant_cpu_to_je32(8),
48744 + .hdr_crc = constant_cpu_to_je32(0)
48745 };
48746
48747 /*
48748 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
48749 index 1a543be..d803c40 100644
48750 --- a/fs/jfs/super.c
48751 +++ b/fs/jfs/super.c
48752 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
48753
48754 jfs_inode_cachep =
48755 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
48756 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
48757 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
48758 init_once);
48759 if (jfs_inode_cachep == NULL)
48760 return -ENOMEM;
48761 diff --git a/fs/libfs.c b/fs/libfs.c
48762 index 7cc37ca..b3e3eec 100644
48763 --- a/fs/libfs.c
48764 +++ b/fs/libfs.c
48765 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
48766
48767 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
48768 struct dentry *next;
48769 + char d_name[sizeof(next->d_iname)];
48770 + const unsigned char *name;
48771 +
48772 next = list_entry(p, struct dentry, d_u.d_child);
48773 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
48774 if (!simple_positive(next)) {
48775 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
48776
48777 spin_unlock(&next->d_lock);
48778 spin_unlock(&dentry->d_lock);
48779 - if (filldir(dirent, next->d_name.name,
48780 + name = next->d_name.name;
48781 + if (name == next->d_iname) {
48782 + memcpy(d_name, name, next->d_name.len);
48783 + name = d_name;
48784 + }
48785 + if (filldir(dirent, name,
48786 next->d_name.len, filp->f_pos,
48787 next->d_inode->i_ino,
48788 dt_type(next->d_inode)) < 0)
48789 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
48790 index 05d2912..760abfa 100644
48791 --- a/fs/lockd/clntproc.c
48792 +++ b/fs/lockd/clntproc.c
48793 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
48794 /*
48795 * Cookie counter for NLM requests
48796 */
48797 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
48798 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
48799
48800 void nlmclnt_next_cookie(struct nlm_cookie *c)
48801 {
48802 - u32 cookie = atomic_inc_return(&nlm_cookie);
48803 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
48804
48805 memcpy(c->data, &cookie, 4);
48806 c->len=4;
48807 diff --git a/fs/locks.c b/fs/locks.c
48808 index a94e331..060bce3 100644
48809 --- a/fs/locks.c
48810 +++ b/fs/locks.c
48811 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
48812 return;
48813
48814 if (filp->f_op && filp->f_op->flock) {
48815 - struct file_lock fl = {
48816 + struct file_lock flock = {
48817 .fl_pid = current->tgid,
48818 .fl_file = filp,
48819 .fl_flags = FL_FLOCK,
48820 .fl_type = F_UNLCK,
48821 .fl_end = OFFSET_MAX,
48822 };
48823 - filp->f_op->flock(filp, F_SETLKW, &fl);
48824 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
48825 - fl.fl_ops->fl_release_private(&fl);
48826 + filp->f_op->flock(filp, F_SETLKW, &flock);
48827 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
48828 + flock.fl_ops->fl_release_private(&flock);
48829 }
48830
48831 lock_flocks();
48832 diff --git a/fs/namei.c b/fs/namei.c
48833 index 5f4cdf3..959a013 100644
48834 --- a/fs/namei.c
48835 +++ b/fs/namei.c
48836 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
48837 if (ret != -EACCES)
48838 return ret;
48839
48840 +#ifdef CONFIG_GRKERNSEC
48841 + /* we'll block if we have to log due to a denied capability use */
48842 + if (mask & MAY_NOT_BLOCK)
48843 + return -ECHILD;
48844 +#endif
48845 +
48846 if (S_ISDIR(inode->i_mode)) {
48847 /* DACs are overridable for directories */
48848 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
48849 - return 0;
48850 if (!(mask & MAY_WRITE))
48851 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48852 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48853 + inode_capable(inode, CAP_DAC_READ_SEARCH))
48854 return 0;
48855 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
48856 + return 0;
48857 return -EACCES;
48858 }
48859 /*
48860 + * Searching includes executable on directories, else just read.
48861 + */
48862 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48863 + if (mask == MAY_READ)
48864 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48865 + inode_capable(inode, CAP_DAC_READ_SEARCH))
48866 + return 0;
48867 +
48868 + /*
48869 * Read/write DACs are always overridable.
48870 * Executable DACs are overridable when there is
48871 * at least one exec bit set.
48872 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
48873 if (inode_capable(inode, CAP_DAC_OVERRIDE))
48874 return 0;
48875
48876 - /*
48877 - * Searching includes executable on directories, else just read.
48878 - */
48879 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48880 - if (mask == MAY_READ)
48881 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48882 - return 0;
48883 -
48884 return -EACCES;
48885 }
48886
48887 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48888 {
48889 struct dentry *dentry = link->dentry;
48890 int error;
48891 - char *s;
48892 + const char *s;
48893
48894 BUG_ON(nd->flags & LOOKUP_RCU);
48895
48896 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48897 if (error)
48898 goto out_put_nd_path;
48899
48900 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
48901 + dentry->d_inode, dentry, nd->path.mnt)) {
48902 + error = -EACCES;
48903 + goto out_put_nd_path;
48904 + }
48905 +
48906 nd->last_type = LAST_BIND;
48907 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48908 error = PTR_ERR(*p);
48909 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
48910 break;
48911 res = walk_component(nd, path, &nd->last,
48912 nd->last_type, LOOKUP_FOLLOW);
48913 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
48914 + res = -EACCES;
48915 put_link(nd, &link, cookie);
48916 } while (res > 0);
48917
48918 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
48919 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
48920 {
48921 unsigned long a, b, adata, bdata, mask, hash, len;
48922 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48923 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48924
48925 hash = a = 0;
48926 len = -sizeof(unsigned long);
48927 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
48928 if (err)
48929 break;
48930 err = lookup_last(nd, &path);
48931 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
48932 + err = -EACCES;
48933 put_link(nd, &link, cookie);
48934 }
48935 }
48936 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
48937 if (!err)
48938 err = complete_walk(nd);
48939
48940 + if (!(nd->flags & LOOKUP_PARENT)) {
48941 +#ifdef CONFIG_GRKERNSEC
48942 + if (flags & LOOKUP_RCU) {
48943 + if (!err)
48944 + path_put(&nd->path);
48945 + err = -ECHILD;
48946 + } else
48947 +#endif
48948 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48949 + if (!err)
48950 + path_put(&nd->path);
48951 + err = -ENOENT;
48952 + }
48953 + }
48954 +
48955 if (!err && nd->flags & LOOKUP_DIRECTORY) {
48956 if (!nd->inode->i_op->lookup) {
48957 path_put(&nd->path);
48958 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
48959 retval = path_lookupat(dfd, name->name,
48960 flags | LOOKUP_REVAL, nd);
48961
48962 - if (likely(!retval))
48963 + if (likely(!retval)) {
48964 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
48965 +#ifdef CONFIG_GRKERNSEC
48966 + if (flags & LOOKUP_RCU)
48967 + return -ECHILD;
48968 +#endif
48969 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48970 + return -ENOENT;
48971 + }
48972 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
48973 + }
48974 return retval;
48975 }
48976
48977 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
48978 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
48979 return -EPERM;
48980
48981 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
48982 + return -EPERM;
48983 + if (gr_handle_rawio(inode))
48984 + return -EPERM;
48985 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
48986 + return -EACCES;
48987 +
48988 return 0;
48989 }
48990
48991 @@ -2623,7 +2672,7 @@ looked_up:
48992 * cleared otherwise prior to returning.
48993 */
48994 static int lookup_open(struct nameidata *nd, struct path *path,
48995 - struct file *file,
48996 + struct path *link, struct file *file,
48997 const struct open_flags *op,
48998 bool got_write, int *opened)
48999 {
49000 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49001 /* Negative dentry, just create the file */
49002 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49003 umode_t mode = op->mode;
49004 +
49005 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49006 + error = -EACCES;
49007 + goto out_dput;
49008 + }
49009 +
49010 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49011 + error = -EACCES;
49012 + goto out_dput;
49013 + }
49014 +
49015 if (!IS_POSIXACL(dir->d_inode))
49016 mode &= ~current_umask();
49017 /*
49018 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49019 nd->flags & LOOKUP_EXCL);
49020 if (error)
49021 goto out_dput;
49022 + else
49023 + gr_handle_create(dentry, nd->path.mnt);
49024 }
49025 out_no_open:
49026 path->dentry = dentry;
49027 @@ -2693,7 +2755,7 @@ out_dput:
49028 /*
49029 * Handle the last step of open()
49030 */
49031 -static int do_last(struct nameidata *nd, struct path *path,
49032 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49033 struct file *file, const struct open_flags *op,
49034 int *opened, struct filename *name)
49035 {
49036 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49037 error = complete_walk(nd);
49038 if (error)
49039 return error;
49040 +#ifdef CONFIG_GRKERNSEC
49041 + if (nd->flags & LOOKUP_RCU) {
49042 + error = -ECHILD;
49043 + goto out;
49044 + }
49045 +#endif
49046 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49047 + error = -ENOENT;
49048 + goto out;
49049 + }
49050 audit_inode(name, nd->path.dentry, 0);
49051 if (open_flag & O_CREAT) {
49052 error = -EISDIR;
49053 goto out;
49054 }
49055 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49056 + error = -EACCES;
49057 + goto out;
49058 + }
49059 goto finish_open;
49060 case LAST_BIND:
49061 error = complete_walk(nd);
49062 if (error)
49063 return error;
49064 +#ifdef CONFIG_GRKERNSEC
49065 + if (nd->flags & LOOKUP_RCU) {
49066 + error = -ECHILD;
49067 + goto out;
49068 + }
49069 +#endif
49070 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49071 + error = -ENOENT;
49072 + goto out;
49073 + }
49074 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49075 + error = -EACCES;
49076 + goto out;
49077 + }
49078 audit_inode(name, dir, 0);
49079 goto finish_open;
49080 }
49081 @@ -2780,7 +2870,7 @@ retry_lookup:
49082 */
49083 }
49084 mutex_lock(&dir->d_inode->i_mutex);
49085 - error = lookup_open(nd, path, file, op, got_write, opened);
49086 + error = lookup_open(nd, path, link, file, op, got_write, opened);
49087 mutex_unlock(&dir->d_inode->i_mutex);
49088
49089 if (error <= 0) {
49090 @@ -2804,11 +2894,28 @@ retry_lookup:
49091 goto finish_open_created;
49092 }
49093
49094 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49095 + error = -ENOENT;
49096 + goto exit_dput;
49097 + }
49098 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49099 + error = -EACCES;
49100 + goto exit_dput;
49101 + }
49102 +
49103 /*
49104 * create/update audit record if it already exists.
49105 */
49106 - if (path->dentry->d_inode)
49107 + if (path->dentry->d_inode) {
49108 + /* only check if O_CREAT is specified, all other checks need to go
49109 + into may_open */
49110 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49111 + error = -EACCES;
49112 + goto exit_dput;
49113 + }
49114 +
49115 audit_inode(name, path->dentry, 0);
49116 + }
49117
49118 /*
49119 * If atomic_open() acquired write access it is dropped now due to
49120 @@ -2849,6 +2956,11 @@ finish_lookup:
49121 }
49122 }
49123 BUG_ON(inode != path->dentry->d_inode);
49124 + /* if we're resolving a symlink to another symlink */
49125 + if (link && gr_handle_symlink_owner(link, inode)) {
49126 + error = -EACCES;
49127 + goto out;
49128 + }
49129 return 1;
49130 }
49131
49132 @@ -2858,7 +2970,6 @@ finish_lookup:
49133 save_parent.dentry = nd->path.dentry;
49134 save_parent.mnt = mntget(path->mnt);
49135 nd->path.dentry = path->dentry;
49136 -
49137 }
49138 nd->inode = inode;
49139 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49140 @@ -2867,6 +2978,22 @@ finish_lookup:
49141 path_put(&save_parent);
49142 return error;
49143 }
49144 +
49145 +#ifdef CONFIG_GRKERNSEC
49146 + if (nd->flags & LOOKUP_RCU) {
49147 + error = -ECHILD;
49148 + goto out;
49149 + }
49150 +#endif
49151 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49152 + error = -ENOENT;
49153 + goto out;
49154 + }
49155 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49156 + error = -EACCES;
49157 + goto out;
49158 + }
49159 +
49160 error = -EISDIR;
49161 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49162 goto out;
49163 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49164 if (unlikely(error))
49165 goto out;
49166
49167 - error = do_last(nd, &path, file, op, &opened, pathname);
49168 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49169 while (unlikely(error > 0)) { /* trailing symlink */
49170 struct path link = path;
49171 void *cookie;
49172 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49173 error = follow_link(&link, nd, &cookie);
49174 if (unlikely(error))
49175 break;
49176 - error = do_last(nd, &path, file, op, &opened, pathname);
49177 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
49178 put_link(nd, &link, cookie);
49179 }
49180 out:
49181 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49182 goto unlock;
49183
49184 error = -EEXIST;
49185 - if (dentry->d_inode)
49186 + if (dentry->d_inode) {
49187 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49188 + error = -ENOENT;
49189 + }
49190 goto fail;
49191 + }
49192 /*
49193 * Special case - lookup gave negative, but... we had foo/bar/
49194 * From the vfs_mknod() POV we just have a negative dentry -
49195 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49196 }
49197 EXPORT_SYMBOL(user_path_create);
49198
49199 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49200 +{
49201 + struct filename *tmp = getname(pathname);
49202 + struct dentry *res;
49203 + if (IS_ERR(tmp))
49204 + return ERR_CAST(tmp);
49205 + res = kern_path_create(dfd, tmp->name, path, is_dir);
49206 + if (IS_ERR(res))
49207 + putname(tmp);
49208 + else
49209 + *to = tmp;
49210 + return res;
49211 +}
49212 +
49213 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49214 {
49215 int error = may_create(dir, dentry);
49216 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49217
49218 if (!IS_POSIXACL(path.dentry->d_inode))
49219 mode &= ~current_umask();
49220 +
49221 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49222 + error = -EPERM;
49223 + goto out;
49224 + }
49225 +
49226 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49227 + error = -EACCES;
49228 + goto out;
49229 + }
49230 +
49231 error = security_path_mknod(&path, dentry, mode, dev);
49232 if (error)
49233 goto out;
49234 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49235 break;
49236 }
49237 out:
49238 + if (!error)
49239 + gr_handle_create(dentry, path.mnt);
49240 done_path_create(&path, dentry);
49241 return error;
49242 }
49243 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49244
49245 if (!IS_POSIXACL(path.dentry->d_inode))
49246 mode &= ~current_umask();
49247 +
49248 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49249 + error = -EACCES;
49250 + goto out;
49251 + }
49252 +
49253 error = security_path_mkdir(&path, dentry, mode);
49254 if (!error)
49255 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49256 + if (!error)
49257 + gr_handle_create(dentry, path.mnt);
49258 +out:
49259 done_path_create(&path, dentry);
49260 return error;
49261 }
49262 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49263 struct filename *name;
49264 struct dentry *dentry;
49265 struct nameidata nd;
49266 + ino_t saved_ino = 0;
49267 + dev_t saved_dev = 0;
49268
49269 name = user_path_parent(dfd, pathname, &nd);
49270 if (IS_ERR(name))
49271 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49272 error = -ENOENT;
49273 goto exit3;
49274 }
49275 +
49276 + saved_ino = dentry->d_inode->i_ino;
49277 + saved_dev = gr_get_dev_from_dentry(dentry);
49278 +
49279 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49280 + error = -EACCES;
49281 + goto exit3;
49282 + }
49283 +
49284 error = security_path_rmdir(&nd.path, dentry);
49285 if (error)
49286 goto exit3;
49287 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49288 + if (!error && (saved_dev || saved_ino))
49289 + gr_handle_delete(saved_ino, saved_dev);
49290 exit3:
49291 dput(dentry);
49292 exit2:
49293 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49294 struct dentry *dentry;
49295 struct nameidata nd;
49296 struct inode *inode = NULL;
49297 + ino_t saved_ino = 0;
49298 + dev_t saved_dev = 0;
49299
49300 name = user_path_parent(dfd, pathname, &nd);
49301 if (IS_ERR(name))
49302 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49303 if (!inode)
49304 goto slashes;
49305 ihold(inode);
49306 +
49307 + if (inode->i_nlink <= 1) {
49308 + saved_ino = inode->i_ino;
49309 + saved_dev = gr_get_dev_from_dentry(dentry);
49310 + }
49311 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
49312 + error = -EACCES;
49313 + goto exit2;
49314 + }
49315 +
49316 error = security_path_unlink(&nd.path, dentry);
49317 if (error)
49318 goto exit2;
49319 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
49320 + if (!error && (saved_ino || saved_dev))
49321 + gr_handle_delete(saved_ino, saved_dev);
49322 exit2:
49323 dput(dentry);
49324 }
49325 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
49326 if (IS_ERR(dentry))
49327 goto out_putname;
49328
49329 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
49330 + error = -EACCES;
49331 + goto out;
49332 + }
49333 +
49334 error = security_path_symlink(&path, dentry, from->name);
49335 if (!error)
49336 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
49337 + if (!error)
49338 + gr_handle_create(dentry, path.mnt);
49339 +out:
49340 done_path_create(&path, dentry);
49341 out_putname:
49342 putname(from);
49343 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49344 {
49345 struct dentry *new_dentry;
49346 struct path old_path, new_path;
49347 + struct filename *to = NULL;
49348 int how = 0;
49349 int error;
49350
49351 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49352 if (error)
49353 return error;
49354
49355 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
49356 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
49357 error = PTR_ERR(new_dentry);
49358 if (IS_ERR(new_dentry))
49359 goto out;
49360 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49361 error = may_linkat(&old_path);
49362 if (unlikely(error))
49363 goto out_dput;
49364 +
49365 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
49366 + old_path.dentry->d_inode,
49367 + old_path.dentry->d_inode->i_mode, to)) {
49368 + error = -EACCES;
49369 + goto out_dput;
49370 + }
49371 +
49372 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
49373 + old_path.dentry, old_path.mnt, to)) {
49374 + error = -EACCES;
49375 + goto out_dput;
49376 + }
49377 +
49378 error = security_path_link(old_path.dentry, &new_path, new_dentry);
49379 if (error)
49380 goto out_dput;
49381 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
49382 + if (!error)
49383 + gr_handle_create(new_dentry, new_path.mnt);
49384 out_dput:
49385 + putname(to);
49386 done_path_create(&new_path, new_dentry);
49387 out:
49388 path_put(&old_path);
49389 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
49390 if (new_dentry == trap)
49391 goto exit5;
49392
49393 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
49394 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
49395 + to);
49396 + if (error)
49397 + goto exit5;
49398 +
49399 error = security_path_rename(&oldnd.path, old_dentry,
49400 &newnd.path, new_dentry);
49401 if (error)
49402 goto exit5;
49403 error = vfs_rename(old_dir->d_inode, old_dentry,
49404 new_dir->d_inode, new_dentry);
49405 + if (!error)
49406 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
49407 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
49408 exit5:
49409 dput(new_dentry);
49410 exit4:
49411 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
49412
49413 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
49414 {
49415 + char tmpbuf[64];
49416 + const char *newlink;
49417 int len;
49418
49419 len = PTR_ERR(link);
49420 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
49421 len = strlen(link);
49422 if (len > (unsigned) buflen)
49423 len = buflen;
49424 - if (copy_to_user(buffer, link, len))
49425 +
49426 + if (len < sizeof(tmpbuf)) {
49427 + memcpy(tmpbuf, link, len);
49428 + newlink = tmpbuf;
49429 + } else
49430 + newlink = link;
49431 +
49432 + if (copy_to_user(buffer, newlink, len))
49433 len = -EFAULT;
49434 out:
49435 return len;
49436 diff --git a/fs/namespace.c b/fs/namespace.c
49437 index 2496062..e26f6d6 100644
49438 --- a/fs/namespace.c
49439 +++ b/fs/namespace.c
49440 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
49441 if (!(sb->s_flags & MS_RDONLY))
49442 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
49443 up_write(&sb->s_umount);
49444 +
49445 + gr_log_remount(mnt->mnt_devname, retval);
49446 +
49447 return retval;
49448 }
49449
49450 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
49451 br_write_unlock(&vfsmount_lock);
49452 up_write(&namespace_sem);
49453 release_mounts(&umount_list);
49454 +
49455 + gr_log_unmount(mnt->mnt_devname, retval);
49456 +
49457 return retval;
49458 }
49459
49460 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
49461 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
49462 MS_STRICTATIME);
49463
49464 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
49465 + retval = -EPERM;
49466 + goto dput_out;
49467 + }
49468 +
49469 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
49470 + retval = -EPERM;
49471 + goto dput_out;
49472 + }
49473 +
49474 if (flags & MS_REMOUNT)
49475 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
49476 data_page);
49477 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
49478 dev_name, data_page);
49479 dput_out:
49480 path_put(&path);
49481 +
49482 + gr_log_mount(dev_name, dir_name, retval);
49483 +
49484 return retval;
49485 }
49486
49487 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
49488 if (error)
49489 goto out2;
49490
49491 + if (gr_handle_chroot_pivot()) {
49492 + error = -EPERM;
49493 + goto out2;
49494 + }
49495 +
49496 get_fs_root(current->fs, &root);
49497 error = lock_mount(&old);
49498 if (error)
49499 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
49500 index 6fa01ae..2790820 100644
49501 --- a/fs/nfs/inode.c
49502 +++ b/fs/nfs/inode.c
49503 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
49504 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
49505 }
49506
49507 -static atomic_long_t nfs_attr_generation_counter;
49508 +static atomic_long_unchecked_t nfs_attr_generation_counter;
49509
49510 static unsigned long nfs_read_attr_generation_counter(void)
49511 {
49512 - return atomic_long_read(&nfs_attr_generation_counter);
49513 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
49514 }
49515
49516 unsigned long nfs_inc_attr_generation_counter(void)
49517 {
49518 - return atomic_long_inc_return(&nfs_attr_generation_counter);
49519 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
49520 }
49521
49522 void nfs_fattr_init(struct nfs_fattr *fattr)
49523 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
49524 index f59169e..fd7d359 100644
49525 --- a/fs/nfsd/vfs.c
49526 +++ b/fs/nfsd/vfs.c
49527 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49528 } else {
49529 oldfs = get_fs();
49530 set_fs(KERNEL_DS);
49531 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
49532 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
49533 set_fs(oldfs);
49534 }
49535
49536 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49537
49538 /* Write the data. */
49539 oldfs = get_fs(); set_fs(KERNEL_DS);
49540 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
49541 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
49542 set_fs(oldfs);
49543 if (host_err < 0)
49544 goto out_nfserr;
49545 @@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
49546 */
49547
49548 oldfs = get_fs(); set_fs(KERNEL_DS);
49549 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
49550 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
49551 set_fs(oldfs);
49552
49553 if (host_err < 0)
49554 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
49555 index 6fcaeb8..9d16d04 100644
49556 --- a/fs/notify/fanotify/fanotify_user.c
49557 +++ b/fs/notify/fanotify/fanotify_user.c
49558 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
49559
49560 fd = fanotify_event_metadata.fd;
49561 ret = -EFAULT;
49562 - if (copy_to_user(buf, &fanotify_event_metadata,
49563 - fanotify_event_metadata.event_len))
49564 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
49565 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
49566 goto out_close_fd;
49567
49568 ret = prepare_for_access_response(group, event, fd);
49569 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
49570 index c887b13..0fdf472 100644
49571 --- a/fs/notify/notification.c
49572 +++ b/fs/notify/notification.c
49573 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
49574 * get set to 0 so it will never get 'freed'
49575 */
49576 static struct fsnotify_event *q_overflow_event;
49577 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49578 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49579
49580 /**
49581 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
49582 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49583 */
49584 u32 fsnotify_get_cookie(void)
49585 {
49586 - return atomic_inc_return(&fsnotify_sync_cookie);
49587 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
49588 }
49589 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
49590
49591 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
49592 index 99e3610..02c1068 100644
49593 --- a/fs/ntfs/dir.c
49594 +++ b/fs/ntfs/dir.c
49595 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
49596 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
49597 ~(s64)(ndir->itype.index.block_size - 1)));
49598 /* Bounds checks. */
49599 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49600 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49601 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
49602 "inode 0x%lx or driver bug.", vdir->i_ino);
49603 goto err_out;
49604 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
49605 index 1ecf464..e1ff8bf 100644
49606 --- a/fs/ntfs/file.c
49607 +++ b/fs/ntfs/file.c
49608 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
49609 #endif /* NTFS_RW */
49610 };
49611
49612 -const struct file_operations ntfs_empty_file_ops = {};
49613 +const struct file_operations ntfs_empty_file_ops __read_only;
49614
49615 -const struct inode_operations ntfs_empty_inode_ops = {};
49616 +const struct inode_operations ntfs_empty_inode_ops __read_only;
49617 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
49618 index a9f78c7..ed8a381 100644
49619 --- a/fs/ocfs2/localalloc.c
49620 +++ b/fs/ocfs2/localalloc.c
49621 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
49622 goto bail;
49623 }
49624
49625 - atomic_inc(&osb->alloc_stats.moves);
49626 + atomic_inc_unchecked(&osb->alloc_stats.moves);
49627
49628 bail:
49629 if (handle)
49630 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
49631 index d355e6e..578d905 100644
49632 --- a/fs/ocfs2/ocfs2.h
49633 +++ b/fs/ocfs2/ocfs2.h
49634 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
49635
49636 struct ocfs2_alloc_stats
49637 {
49638 - atomic_t moves;
49639 - atomic_t local_data;
49640 - atomic_t bitmap_data;
49641 - atomic_t bg_allocs;
49642 - atomic_t bg_extends;
49643 + atomic_unchecked_t moves;
49644 + atomic_unchecked_t local_data;
49645 + atomic_unchecked_t bitmap_data;
49646 + atomic_unchecked_t bg_allocs;
49647 + atomic_unchecked_t bg_extends;
49648 };
49649
49650 enum ocfs2_local_alloc_state
49651 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
49652 index f169da4..9112253 100644
49653 --- a/fs/ocfs2/suballoc.c
49654 +++ b/fs/ocfs2/suballoc.c
49655 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
49656 mlog_errno(status);
49657 goto bail;
49658 }
49659 - atomic_inc(&osb->alloc_stats.bg_extends);
49660 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
49661
49662 /* You should never ask for this much metadata */
49663 BUG_ON(bits_wanted >
49664 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
49665 mlog_errno(status);
49666 goto bail;
49667 }
49668 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49669 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49670
49671 *suballoc_loc = res.sr_bg_blkno;
49672 *suballoc_bit_start = res.sr_bit_offset;
49673 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
49674 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
49675 res->sr_bits);
49676
49677 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49678 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49679
49680 BUG_ON(res->sr_bits != 1);
49681
49682 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
49683 mlog_errno(status);
49684 goto bail;
49685 }
49686 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49687 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49688
49689 BUG_ON(res.sr_bits != 1);
49690
49691 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
49692 cluster_start,
49693 num_clusters);
49694 if (!status)
49695 - atomic_inc(&osb->alloc_stats.local_data);
49696 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
49697 } else {
49698 if (min_clusters > (osb->bitmap_cpg - 1)) {
49699 /* The only paths asking for contiguousness
49700 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
49701 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
49702 res.sr_bg_blkno,
49703 res.sr_bit_offset);
49704 - atomic_inc(&osb->alloc_stats.bitmap_data);
49705 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
49706 *num_clusters = res.sr_bits;
49707 }
49708 }
49709 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
49710 index 0e91ec2..f4b3fc6 100644
49711 --- a/fs/ocfs2/super.c
49712 +++ b/fs/ocfs2/super.c
49713 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
49714 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49715 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49716 "Stats",
49717 - atomic_read(&osb->alloc_stats.bitmap_data),
49718 - atomic_read(&osb->alloc_stats.local_data),
49719 - atomic_read(&osb->alloc_stats.bg_allocs),
49720 - atomic_read(&osb->alloc_stats.moves),
49721 - atomic_read(&osb->alloc_stats.bg_extends));
49722 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49723 + atomic_read_unchecked(&osb->alloc_stats.local_data),
49724 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49725 + atomic_read_unchecked(&osb->alloc_stats.moves),
49726 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49727
49728 out += snprintf(buf + out, len - out,
49729 "%10s => State: %u Descriptor: %llu Size: %u bits "
49730 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
49731 spin_lock_init(&osb->osb_xattr_lock);
49732 ocfs2_init_steal_slots(osb);
49733
49734 - atomic_set(&osb->alloc_stats.moves, 0);
49735 - atomic_set(&osb->alloc_stats.local_data, 0);
49736 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
49737 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
49738 - atomic_set(&osb->alloc_stats.bg_extends, 0);
49739 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49740 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49741 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49742 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49743 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49744
49745 /* Copy the blockcheck stats from the superblock probe */
49746 osb->osb_ecc_stats = *stats;
49747 diff --git a/fs/open.c b/fs/open.c
49748 index 59071f5..c6229a0 100644
49749 --- a/fs/open.c
49750 +++ b/fs/open.c
49751 @@ -31,6 +31,8 @@
49752 #include <linux/ima.h>
49753 #include <linux/dnotify.h>
49754
49755 +#define CREATE_TRACE_POINTS
49756 +#include <trace/events/fs.h>
49757 #include "internal.h"
49758
49759 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
49760 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
49761 error = locks_verify_truncate(inode, NULL, length);
49762 if (!error)
49763 error = security_path_truncate(&path);
49764 +
49765 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
49766 + error = -EACCES;
49767 +
49768 if (!error)
49769 error = do_truncate(path.dentry, length, 0, NULL);
49770
49771 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
49772 if (__mnt_is_readonly(path.mnt))
49773 res = -EROFS;
49774
49775 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
49776 + res = -EACCES;
49777 +
49778 out_path_release:
49779 path_put(&path);
49780 out:
49781 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
49782 if (error)
49783 goto dput_and_out;
49784
49785 + gr_log_chdir(path.dentry, path.mnt);
49786 +
49787 set_fs_pwd(current->fs, &path);
49788
49789 dput_and_out:
49790 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
49791 goto out_putf;
49792
49793 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49794 +
49795 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
49796 + error = -EPERM;
49797 +
49798 + if (!error)
49799 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
49800 +
49801 if (!error)
49802 set_fs_pwd(current->fs, &f.file->f_path);
49803 out_putf:
49804 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
49805 if (error)
49806 goto dput_and_out;
49807
49808 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49809 + goto dput_and_out;
49810 +
49811 set_fs_root(current->fs, &path);
49812 +
49813 + gr_handle_chroot_chdir(&path);
49814 +
49815 error = 0;
49816 dput_and_out:
49817 path_put(&path);
49818 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
49819 if (error)
49820 return error;
49821 mutex_lock(&inode->i_mutex);
49822 +
49823 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
49824 + error = -EACCES;
49825 + goto out_unlock;
49826 + }
49827 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
49828 + error = -EACCES;
49829 + goto out_unlock;
49830 + }
49831 +
49832 error = security_path_chmod(path, mode);
49833 if (error)
49834 goto out_unlock;
49835 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
49836 uid = make_kuid(current_user_ns(), user);
49837 gid = make_kgid(current_user_ns(), group);
49838
49839 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
49840 + return -EACCES;
49841 +
49842 newattrs.ia_valid = ATTR_CTIME;
49843 if (user != (uid_t) -1) {
49844 if (!uid_valid(uid))
49845 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
49846 } else {
49847 fsnotify_open(f);
49848 fd_install(fd, f);
49849 + trace_do_sys_open(tmp->name, flags, mode);
49850 }
49851 }
49852 putname(tmp);
49853 diff --git a/fs/pipe.c b/fs/pipe.c
49854 index bd3479d..fb92c4d 100644
49855 --- a/fs/pipe.c
49856 +++ b/fs/pipe.c
49857 @@ -438,9 +438,9 @@ redo:
49858 }
49859 if (bufs) /* More to do? */
49860 continue;
49861 - if (!pipe->writers)
49862 + if (!atomic_read(&pipe->writers))
49863 break;
49864 - if (!pipe->waiting_writers) {
49865 + if (!atomic_read(&pipe->waiting_writers)) {
49866 /* syscall merging: Usually we must not sleep
49867 * if O_NONBLOCK is set, or if we got some data.
49868 * But if a writer sleeps in kernel space, then
49869 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
49870 mutex_lock(&inode->i_mutex);
49871 pipe = inode->i_pipe;
49872
49873 - if (!pipe->readers) {
49874 + if (!atomic_read(&pipe->readers)) {
49875 send_sig(SIGPIPE, current, 0);
49876 ret = -EPIPE;
49877 goto out;
49878 @@ -553,7 +553,7 @@ redo1:
49879 for (;;) {
49880 int bufs;
49881
49882 - if (!pipe->readers) {
49883 + if (!atomic_read(&pipe->readers)) {
49884 send_sig(SIGPIPE, current, 0);
49885 if (!ret)
49886 ret = -EPIPE;
49887 @@ -644,9 +644,9 @@ redo2:
49888 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49889 do_wakeup = 0;
49890 }
49891 - pipe->waiting_writers++;
49892 + atomic_inc(&pipe->waiting_writers);
49893 pipe_wait(pipe);
49894 - pipe->waiting_writers--;
49895 + atomic_dec(&pipe->waiting_writers);
49896 }
49897 out:
49898 mutex_unlock(&inode->i_mutex);
49899 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49900 mask = 0;
49901 if (filp->f_mode & FMODE_READ) {
49902 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49903 - if (!pipe->writers && filp->f_version != pipe->w_counter)
49904 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49905 mask |= POLLHUP;
49906 }
49907
49908 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49909 * Most Unices do not set POLLERR for FIFOs but on Linux they
49910 * behave exactly like pipes for poll().
49911 */
49912 - if (!pipe->readers)
49913 + if (!atomic_read(&pipe->readers))
49914 mask |= POLLERR;
49915 }
49916
49917 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
49918
49919 mutex_lock(&inode->i_mutex);
49920 pipe = inode->i_pipe;
49921 - pipe->readers -= decr;
49922 - pipe->writers -= decw;
49923 + atomic_sub(decr, &pipe->readers);
49924 + atomic_sub(decw, &pipe->writers);
49925
49926 - if (!pipe->readers && !pipe->writers) {
49927 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49928 free_pipe_info(inode);
49929 } else {
49930 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49931 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
49932
49933 if (inode->i_pipe) {
49934 ret = 0;
49935 - inode->i_pipe->readers++;
49936 + atomic_inc(&inode->i_pipe->readers);
49937 }
49938
49939 mutex_unlock(&inode->i_mutex);
49940 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
49941
49942 if (inode->i_pipe) {
49943 ret = 0;
49944 - inode->i_pipe->writers++;
49945 + atomic_inc(&inode->i_pipe->writers);
49946 }
49947
49948 mutex_unlock(&inode->i_mutex);
49949 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
49950 if (inode->i_pipe) {
49951 ret = 0;
49952 if (filp->f_mode & FMODE_READ)
49953 - inode->i_pipe->readers++;
49954 + atomic_inc(&inode->i_pipe->readers);
49955 if (filp->f_mode & FMODE_WRITE)
49956 - inode->i_pipe->writers++;
49957 + atomic_inc(&inode->i_pipe->writers);
49958 }
49959
49960 mutex_unlock(&inode->i_mutex);
49961 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
49962 inode->i_pipe = NULL;
49963 }
49964
49965 -static struct vfsmount *pipe_mnt __read_mostly;
49966 +struct vfsmount *pipe_mnt __read_mostly;
49967
49968 /*
49969 * pipefs_dname() is called from d_path().
49970 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
49971 goto fail_iput;
49972 inode->i_pipe = pipe;
49973
49974 - pipe->readers = pipe->writers = 1;
49975 + atomic_set(&pipe->readers, 1);
49976 + atomic_set(&pipe->writers, 1);
49977 inode->i_fop = &rdwr_pipefifo_fops;
49978
49979 /*
49980 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
49981 index 15af622..0e9f4467 100644
49982 --- a/fs/proc/Kconfig
49983 +++ b/fs/proc/Kconfig
49984 @@ -30,12 +30,12 @@ config PROC_FS
49985
49986 config PROC_KCORE
49987 bool "/proc/kcore support" if !ARM
49988 - depends on PROC_FS && MMU
49989 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
49990
49991 config PROC_VMCORE
49992 bool "/proc/vmcore support"
49993 - depends on PROC_FS && CRASH_DUMP
49994 - default y
49995 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49996 + default n
49997 help
49998 Exports the dump image of crashed kernel in ELF format.
49999
50000 @@ -59,8 +59,8 @@ config PROC_SYSCTL
50001 limited in memory.
50002
50003 config PROC_PAGE_MONITOR
50004 - default y
50005 - depends on PROC_FS && MMU
50006 + default n
50007 + depends on PROC_FS && MMU && !GRKERNSEC
50008 bool "Enable /proc page monitoring" if EXPERT
50009 help
50010 Various /proc files exist to monitor process memory utilization:
50011 diff --git a/fs/proc/array.c b/fs/proc/array.c
50012 index bd31e02..15cae71 100644
50013 --- a/fs/proc/array.c
50014 +++ b/fs/proc/array.c
50015 @@ -60,6 +60,7 @@
50016 #include <linux/tty.h>
50017 #include <linux/string.h>
50018 #include <linux/mman.h>
50019 +#include <linux/grsecurity.h>
50020 #include <linux/proc_fs.h>
50021 #include <linux/ioport.h>
50022 #include <linux/uaccess.h>
50023 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50024 seq_putc(m, '\n');
50025 }
50026
50027 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50028 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
50029 +{
50030 + if (p->mm)
50031 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50032 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50033 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50034 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50035 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50036 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50037 + else
50038 + seq_printf(m, "PaX:\t-----\n");
50039 +}
50040 +#endif
50041 +
50042 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50043 struct pid *pid, struct task_struct *task)
50044 {
50045 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50046 task_cpus_allowed(m, task);
50047 cpuset_task_status_allowed(m, task);
50048 task_context_switch_counts(m, task);
50049 +
50050 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50051 + task_pax(m, task);
50052 +#endif
50053 +
50054 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50055 + task_grsec_rbac(m, task);
50056 +#endif
50057 +
50058 return 0;
50059 }
50060
50061 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50062 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50063 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50064 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50065 +#endif
50066 +
50067 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50068 struct pid *pid, struct task_struct *task, int whole)
50069 {
50070 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50071 char tcomm[sizeof(task->comm)];
50072 unsigned long flags;
50073
50074 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50075 + if (current->exec_id != m->exec_id) {
50076 + gr_log_badprocpid("stat");
50077 + return 0;
50078 + }
50079 +#endif
50080 +
50081 state = *get_task_state(task);
50082 vsize = eip = esp = 0;
50083 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50084 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50085 gtime = task->gtime;
50086 }
50087
50088 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50089 + if (PAX_RAND_FLAGS(mm)) {
50090 + eip = 0;
50091 + esp = 0;
50092 + wchan = 0;
50093 + }
50094 +#endif
50095 +#ifdef CONFIG_GRKERNSEC_HIDESYM
50096 + wchan = 0;
50097 + eip =0;
50098 + esp =0;
50099 +#endif
50100 +
50101 /* scale priority and nice values from timeslices to -20..20 */
50102 /* to make it look like a "normal" Unix priority/nice value */
50103 priority = task_prio(task);
50104 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50105 seq_put_decimal_ull(m, ' ', vsize);
50106 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50107 seq_put_decimal_ull(m, ' ', rsslim);
50108 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50109 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50110 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50111 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50112 +#else
50113 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50114 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50115 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50116 +#endif
50117 seq_put_decimal_ull(m, ' ', esp);
50118 seq_put_decimal_ull(m, ' ', eip);
50119 /* The signal information here is obsolete.
50120 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50121 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50122 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50123
50124 - if (mm && permitted) {
50125 + if (mm && permitted
50126 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50127 + && !PAX_RAND_FLAGS(mm)
50128 +#endif
50129 + ) {
50130 seq_put_decimal_ull(m, ' ', mm->start_data);
50131 seq_put_decimal_ull(m, ' ', mm->end_data);
50132 seq_put_decimal_ull(m, ' ', mm->start_brk);
50133 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50134 struct pid *pid, struct task_struct *task)
50135 {
50136 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50137 - struct mm_struct *mm = get_task_mm(task);
50138 + struct mm_struct *mm;
50139
50140 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50141 + if (current->exec_id != m->exec_id) {
50142 + gr_log_badprocpid("statm");
50143 + return 0;
50144 + }
50145 +#endif
50146 + mm = get_task_mm(task);
50147 if (mm) {
50148 size = task_statm(mm, &shared, &text, &data, &resident);
50149 mmput(mm);
50150 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50151 return 0;
50152 }
50153
50154 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50155 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50156 +{
50157 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50158 +}
50159 +#endif
50160 +
50161 #ifdef CONFIG_CHECKPOINT_RESTORE
50162 static struct pid *
50163 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50164 diff --git a/fs/proc/base.c b/fs/proc/base.c
50165 index 9e28356..c485b3c 100644
50166 --- a/fs/proc/base.c
50167 +++ b/fs/proc/base.c
50168 @@ -111,6 +111,14 @@ struct pid_entry {
50169 union proc_op op;
50170 };
50171
50172 +struct getdents_callback {
50173 + struct linux_dirent __user * current_dir;
50174 + struct linux_dirent __user * previous;
50175 + struct file * file;
50176 + int count;
50177 + int error;
50178 +};
50179 +
50180 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50181 .name = (NAME), \
50182 .len = sizeof(NAME) - 1, \
50183 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50184 if (!mm->arg_end)
50185 goto out_mm; /* Shh! No looking before we're done */
50186
50187 + if (gr_acl_handle_procpidmem(task))
50188 + goto out_mm;
50189 +
50190 len = mm->arg_end - mm->arg_start;
50191
50192 if (len > PAGE_SIZE)
50193 @@ -235,12 +246,28 @@ out:
50194 return res;
50195 }
50196
50197 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50198 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50199 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50200 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50201 +#endif
50202 +
50203 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50204 {
50205 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50206 int res = PTR_ERR(mm);
50207 if (mm && !IS_ERR(mm)) {
50208 unsigned int nwords = 0;
50209 +
50210 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50211 + /* allow if we're currently ptracing this task */
50212 + if (PAX_RAND_FLAGS(mm) &&
50213 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50214 + mmput(mm);
50215 + return 0;
50216 + }
50217 +#endif
50218 +
50219 do {
50220 nwords += 2;
50221 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50222 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50223 }
50224
50225
50226 -#ifdef CONFIG_KALLSYMS
50227 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50228 /*
50229 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50230 * Returns the resolved symbol. If that fails, simply return the address.
50231 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50232 mutex_unlock(&task->signal->cred_guard_mutex);
50233 }
50234
50235 -#ifdef CONFIG_STACKTRACE
50236 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50237
50238 #define MAX_STACK_TRACE_DEPTH 64
50239
50240 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50241 return count;
50242 }
50243
50244 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50245 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50246 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50247 {
50248 long nr;
50249 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50250 /************************************************************************/
50251
50252 /* permission checks */
50253 -static int proc_fd_access_allowed(struct inode *inode)
50254 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50255 {
50256 struct task_struct *task;
50257 int allowed = 0;
50258 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50259 */
50260 task = get_proc_task(inode);
50261 if (task) {
50262 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50263 + if (log)
50264 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50265 + else
50266 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50267 put_task_struct(task);
50268 }
50269 return allowed;
50270 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50271 struct task_struct *task,
50272 int hide_pid_min)
50273 {
50274 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50275 + return false;
50276 +
50277 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50278 + rcu_read_lock();
50279 + {
50280 + const struct cred *tmpcred = current_cred();
50281 + const struct cred *cred = __task_cred(task);
50282 +
50283 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50284 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50285 + || in_group_p(grsec_proc_gid)
50286 +#endif
50287 + ) {
50288 + rcu_read_unlock();
50289 + return true;
50290 + }
50291 + }
50292 + rcu_read_unlock();
50293 +
50294 + if (!pid->hide_pid)
50295 + return false;
50296 +#endif
50297 +
50298 if (pid->hide_pid < hide_pid_min)
50299 return true;
50300 if (in_group_p(pid->pid_gid))
50301 return true;
50302 +
50303 return ptrace_may_access(task, PTRACE_MODE_READ);
50304 }
50305
50306 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
50307 put_task_struct(task);
50308
50309 if (!has_perms) {
50310 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50311 + {
50312 +#else
50313 if (pid->hide_pid == 2) {
50314 +#endif
50315 /*
50316 * Let's make getdents(), stat(), and open()
50317 * consistent with each other. If a process
50318 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50319 if (!task)
50320 return -ESRCH;
50321
50322 + if (gr_acl_handle_procpidmem(task)) {
50323 + put_task_struct(task);
50324 + return -EPERM;
50325 + }
50326 +
50327 mm = mm_access(task, mode);
50328 put_task_struct(task);
50329
50330 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50331
50332 file->private_data = mm;
50333
50334 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50335 + file->f_version = current->exec_id;
50336 +#endif
50337 +
50338 return 0;
50339 }
50340
50341 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
50342 ssize_t copied;
50343 char *page;
50344
50345 +#ifdef CONFIG_GRKERNSEC
50346 + if (write)
50347 + return -EPERM;
50348 +#endif
50349 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50350 + if (file->f_version != current->exec_id) {
50351 + gr_log_badprocpid("mem");
50352 + return 0;
50353 + }
50354 +#endif
50355 +
50356 if (!mm)
50357 return 0;
50358
50359 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
50360 if (!mm)
50361 return 0;
50362
50363 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50364 + if (file->f_version != current->exec_id) {
50365 + gr_log_badprocpid("environ");
50366 + return 0;
50367 + }
50368 +#endif
50369 +
50370 page = (char *)__get_free_page(GFP_TEMPORARY);
50371 if (!page)
50372 return -ENOMEM;
50373 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
50374 int error = -EACCES;
50375
50376 /* Are we allowed to snoop on the tasks file descriptors? */
50377 - if (!proc_fd_access_allowed(inode))
50378 + if (!proc_fd_access_allowed(inode, 0))
50379 goto out;
50380
50381 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50382 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
50383 struct path path;
50384
50385 /* Are we allowed to snoop on the tasks file descriptors? */
50386 - if (!proc_fd_access_allowed(inode))
50387 - goto out;
50388 + /* logging this is needed for learning on chromium to work properly,
50389 + but we don't want to flood the logs from 'ps' which does a readlink
50390 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
50391 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
50392 + */
50393 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
50394 + if (!proc_fd_access_allowed(inode,0))
50395 + goto out;
50396 + } else {
50397 + if (!proc_fd_access_allowed(inode,1))
50398 + goto out;
50399 + }
50400
50401 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50402 if (error)
50403 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
50404 rcu_read_lock();
50405 cred = __task_cred(task);
50406 inode->i_uid = cred->euid;
50407 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50408 + inode->i_gid = grsec_proc_gid;
50409 +#else
50410 inode->i_gid = cred->egid;
50411 +#endif
50412 rcu_read_unlock();
50413 }
50414 security_task_to_inode(task, inode);
50415 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
50416 return -ENOENT;
50417 }
50418 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50419 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50420 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50421 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50422 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50423 +#endif
50424 task_dumpable(task)) {
50425 cred = __task_cred(task);
50426 stat->uid = cred->euid;
50427 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50428 + stat->gid = grsec_proc_gid;
50429 +#else
50430 stat->gid = cred->egid;
50431 +#endif
50432 }
50433 }
50434 rcu_read_unlock();
50435 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
50436
50437 if (task) {
50438 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50439 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50440 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50441 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50442 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50443 +#endif
50444 task_dumpable(task)) {
50445 rcu_read_lock();
50446 cred = __task_cred(task);
50447 inode->i_uid = cred->euid;
50448 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50449 + inode->i_gid = grsec_proc_gid;
50450 +#else
50451 inode->i_gid = cred->egid;
50452 +#endif
50453 rcu_read_unlock();
50454 } else {
50455 inode->i_uid = GLOBAL_ROOT_UID;
50456 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
50457 if (!task)
50458 goto out_no_task;
50459
50460 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50461 + goto out;
50462 +
50463 /*
50464 * Yes, it does not scale. And it should not. Don't add
50465 * new entries into /proc/<tgid>/ without very good reasons.
50466 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
50467 if (!task)
50468 goto out_no_task;
50469
50470 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50471 + goto out;
50472 +
50473 ret = 0;
50474 i = filp->f_pos;
50475 switch (i) {
50476 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
50477 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
50478 void *cookie)
50479 {
50480 - char *s = nd_get_link(nd);
50481 + const char *s = nd_get_link(nd);
50482 if (!IS_ERR(s))
50483 kfree(s);
50484 }
50485 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
50486 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
50487 #endif
50488 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50489 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50490 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50491 INF("syscall", S_IRUGO, proc_pid_syscall),
50492 #endif
50493 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50494 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
50495 #ifdef CONFIG_SECURITY
50496 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50497 #endif
50498 -#ifdef CONFIG_KALLSYMS
50499 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50500 INF("wchan", S_IRUGO, proc_pid_wchan),
50501 #endif
50502 -#ifdef CONFIG_STACKTRACE
50503 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50504 ONE("stack", S_IRUGO, proc_pid_stack),
50505 #endif
50506 #ifdef CONFIG_SCHEDSTATS
50507 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
50508 #ifdef CONFIG_HARDWALL
50509 INF("hardwall", S_IRUGO, proc_pid_hardwall),
50510 #endif
50511 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50512 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
50513 +#endif
50514 #ifdef CONFIG_USER_NS
50515 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
50516 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
50517 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
50518 if (!inode)
50519 goto out;
50520
50521 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50522 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
50523 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50524 + inode->i_gid = grsec_proc_gid;
50525 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
50526 +#else
50527 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
50528 +#endif
50529 inode->i_op = &proc_tgid_base_inode_operations;
50530 inode->i_fop = &proc_tgid_base_operations;
50531 inode->i_flags|=S_IMMUTABLE;
50532 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
50533 if (!task)
50534 goto out;
50535
50536 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50537 + goto out_put_task;
50538 +
50539 result = proc_pid_instantiate(dir, dentry, task, NULL);
50540 +out_put_task:
50541 put_task_struct(task);
50542 out:
50543 return result;
50544 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
50545 static int fake_filldir(void *buf, const char *name, int namelen,
50546 loff_t offset, u64 ino, unsigned d_type)
50547 {
50548 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
50549 + __buf->error = -EINVAL;
50550 return 0;
50551 }
50552
50553 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
50554 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
50555 #endif
50556 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50557 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50558 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50559 INF("syscall", S_IRUGO, proc_pid_syscall),
50560 #endif
50561 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50562 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
50563 #ifdef CONFIG_SECURITY
50564 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50565 #endif
50566 -#ifdef CONFIG_KALLSYMS
50567 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50568 INF("wchan", S_IRUGO, proc_pid_wchan),
50569 #endif
50570 -#ifdef CONFIG_STACKTRACE
50571 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50572 ONE("stack", S_IRUGO, proc_pid_stack),
50573 #endif
50574 #ifdef CONFIG_SCHEDSTATS
50575 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
50576 index 82676e3..5f8518a 100644
50577 --- a/fs/proc/cmdline.c
50578 +++ b/fs/proc/cmdline.c
50579 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
50580
50581 static int __init proc_cmdline_init(void)
50582 {
50583 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50584 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
50585 +#else
50586 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
50587 +#endif
50588 return 0;
50589 }
50590 module_init(proc_cmdline_init);
50591 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
50592 index b143471..bb105e5 100644
50593 --- a/fs/proc/devices.c
50594 +++ b/fs/proc/devices.c
50595 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
50596
50597 static int __init proc_devices_init(void)
50598 {
50599 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50600 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
50601 +#else
50602 proc_create("devices", 0, NULL, &proc_devinfo_operations);
50603 +#endif
50604 return 0;
50605 }
50606 module_init(proc_devices_init);
50607 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
50608 index f28a875..c467953 100644
50609 --- a/fs/proc/fd.c
50610 +++ b/fs/proc/fd.c
50611 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
50612 if (!task)
50613 return -ENOENT;
50614
50615 - files = get_files_struct(task);
50616 + if (!gr_acl_handle_procpidmem(task))
50617 + files = get_files_struct(task);
50618 put_task_struct(task);
50619
50620 if (files) {
50621 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
50622 */
50623 int proc_fd_permission(struct inode *inode, int mask)
50624 {
50625 + struct task_struct *task;
50626 int rv = generic_permission(inode, mask);
50627 - if (rv == 0)
50628 - return 0;
50629 +
50630 if (task_pid(current) == proc_pid(inode))
50631 rv = 0;
50632 +
50633 + task = get_proc_task(inode);
50634 + if (task == NULL)
50635 + return rv;
50636 +
50637 + if (gr_acl_handle_procpidmem(task))
50638 + rv = -EACCES;
50639 +
50640 + put_task_struct(task);
50641 +
50642 return rv;
50643 }
50644
50645 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
50646 index 3b22bbd..895b58c 100644
50647 --- a/fs/proc/inode.c
50648 +++ b/fs/proc/inode.c
50649 @@ -21,11 +21,17 @@
50650 #include <linux/seq_file.h>
50651 #include <linux/slab.h>
50652 #include <linux/mount.h>
50653 +#include <linux/grsecurity.h>
50654
50655 #include <asm/uaccess.h>
50656
50657 #include "internal.h"
50658
50659 +#ifdef CONFIG_PROC_SYSCTL
50660 +extern const struct inode_operations proc_sys_inode_operations;
50661 +extern const struct inode_operations proc_sys_dir_operations;
50662 +#endif
50663 +
50664 static void proc_evict_inode(struct inode *inode)
50665 {
50666 struct proc_dir_entry *de;
50667 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
50668 ns_ops = PROC_I(inode)->ns_ops;
50669 if (ns_ops && ns_ops->put)
50670 ns_ops->put(PROC_I(inode)->ns);
50671 +
50672 +#ifdef CONFIG_PROC_SYSCTL
50673 + if (inode->i_op == &proc_sys_inode_operations ||
50674 + inode->i_op == &proc_sys_dir_operations)
50675 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
50676 +#endif
50677 +
50678 }
50679
50680 static struct kmem_cache * proc_inode_cachep;
50681 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
50682 if (de->mode) {
50683 inode->i_mode = de->mode;
50684 inode->i_uid = de->uid;
50685 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50686 + inode->i_gid = grsec_proc_gid;
50687 +#else
50688 inode->i_gid = de->gid;
50689 +#endif
50690 }
50691 if (de->size)
50692 inode->i_size = de->size;
50693 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
50694 index 43973b0..a20e704 100644
50695 --- a/fs/proc/internal.h
50696 +++ b/fs/proc/internal.h
50697 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50698 struct pid *pid, struct task_struct *task);
50699 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50700 struct pid *pid, struct task_struct *task);
50701 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50702 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
50703 +#endif
50704 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
50705
50706 extern const struct file_operations proc_tid_children_operations;
50707 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
50708 index 86c67ee..cdca321 100644
50709 --- a/fs/proc/kcore.c
50710 +++ b/fs/proc/kcore.c
50711 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50712 * the addresses in the elf_phdr on our list.
50713 */
50714 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50715 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50716 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50717 + if (tsz > buflen)
50718 tsz = buflen;
50719 -
50720 +
50721 while (buflen) {
50722 struct kcore_list *m;
50723
50724 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50725 kfree(elf_buf);
50726 } else {
50727 if (kern_addr_valid(start)) {
50728 - unsigned long n;
50729 + char *elf_buf;
50730 + mm_segment_t oldfs;
50731
50732 - n = copy_to_user(buffer, (char *)start, tsz);
50733 - /*
50734 - * We cannot distinguish between fault on source
50735 - * and fault on destination. When this happens
50736 - * we clear too and hope it will trigger the
50737 - * EFAULT again.
50738 - */
50739 - if (n) {
50740 - if (clear_user(buffer + tsz - n,
50741 - n))
50742 + elf_buf = kmalloc(tsz, GFP_KERNEL);
50743 + if (!elf_buf)
50744 + return -ENOMEM;
50745 + oldfs = get_fs();
50746 + set_fs(KERNEL_DS);
50747 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50748 + set_fs(oldfs);
50749 + if (copy_to_user(buffer, elf_buf, tsz)) {
50750 + kfree(elf_buf);
50751 return -EFAULT;
50752 + }
50753 }
50754 + set_fs(oldfs);
50755 + kfree(elf_buf);
50756 } else {
50757 if (clear_user(buffer, tsz))
50758 return -EFAULT;
50759 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50760
50761 static int open_kcore(struct inode *inode, struct file *filp)
50762 {
50763 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
50764 + return -EPERM;
50765 +#endif
50766 if (!capable(CAP_SYS_RAWIO))
50767 return -EPERM;
50768 if (kcore_need_update)
50769 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
50770 index 80e4645..53e5fcf 100644
50771 --- a/fs/proc/meminfo.c
50772 +++ b/fs/proc/meminfo.c
50773 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
50774 vmi.used >> 10,
50775 vmi.largest_chunk >> 10
50776 #ifdef CONFIG_MEMORY_FAILURE
50777 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
50778 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
50779 #endif
50780 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
50781 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
50782 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
50783 index b1822dd..df622cb 100644
50784 --- a/fs/proc/nommu.c
50785 +++ b/fs/proc/nommu.c
50786 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
50787 if (len < 1)
50788 len = 1;
50789 seq_printf(m, "%*c", len, ' ');
50790 - seq_path(m, &file->f_path, "");
50791 + seq_path(m, &file->f_path, "\n\\");
50792 }
50793
50794 seq_putc(m, '\n');
50795 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
50796 index fe72cd0..cb9b67d 100644
50797 --- a/fs/proc/proc_net.c
50798 +++ b/fs/proc/proc_net.c
50799 @@ -23,6 +23,7 @@
50800 #include <linux/nsproxy.h>
50801 #include <net/net_namespace.h>
50802 #include <linux/seq_file.h>
50803 +#include <linux/grsecurity.h>
50804
50805 #include "internal.h"
50806
50807 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
50808 struct task_struct *task;
50809 struct nsproxy *ns;
50810 struct net *net = NULL;
50811 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50812 + const struct cred *cred = current_cred();
50813 +#endif
50814 +
50815 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50816 + if (cred->fsuid)
50817 + return net;
50818 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50819 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
50820 + return net;
50821 +#endif
50822
50823 rcu_read_lock();
50824 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50825 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
50826 index a781bdf..6665284 100644
50827 --- a/fs/proc/proc_sysctl.c
50828 +++ b/fs/proc/proc_sysctl.c
50829 @@ -12,11 +12,15 @@
50830 #include <linux/module.h>
50831 #include "internal.h"
50832
50833 +extern int gr_handle_chroot_sysctl(const int op);
50834 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
50835 + const int op);
50836 +
50837 static const struct dentry_operations proc_sys_dentry_operations;
50838 static const struct file_operations proc_sys_file_operations;
50839 -static const struct inode_operations proc_sys_inode_operations;
50840 +const struct inode_operations proc_sys_inode_operations;
50841 static const struct file_operations proc_sys_dir_file_operations;
50842 -static const struct inode_operations proc_sys_dir_operations;
50843 +const struct inode_operations proc_sys_dir_operations;
50844
50845 void proc_sys_poll_notify(struct ctl_table_poll *poll)
50846 {
50847 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
50848
50849 err = NULL;
50850 d_set_d_op(dentry, &proc_sys_dentry_operations);
50851 +
50852 + gr_handle_proc_create(dentry, inode);
50853 +
50854 d_add(dentry, inode);
50855
50856 out:
50857 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50858 struct inode *inode = filp->f_path.dentry->d_inode;
50859 struct ctl_table_header *head = grab_header(inode);
50860 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
50861 + int op = write ? MAY_WRITE : MAY_READ;
50862 ssize_t error;
50863 size_t res;
50864
50865 if (IS_ERR(head))
50866 return PTR_ERR(head);
50867
50868 +
50869 /*
50870 * At this point we know that the sysctl was not unregistered
50871 * and won't be until we finish.
50872 */
50873 error = -EPERM;
50874 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
50875 + if (sysctl_perm(head->root, table, op))
50876 goto out;
50877
50878 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
50879 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50880 if (!table->proc_handler)
50881 goto out;
50882
50883 +#ifdef CONFIG_GRKERNSEC
50884 + error = -EPERM;
50885 + if (gr_handle_chroot_sysctl(op))
50886 + goto out;
50887 + dget(filp->f_path.dentry);
50888 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
50889 + dput(filp->f_path.dentry);
50890 + goto out;
50891 + }
50892 + dput(filp->f_path.dentry);
50893 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
50894 + goto out;
50895 + if (write && !capable(CAP_SYS_ADMIN))
50896 + goto out;
50897 +#endif
50898 +
50899 /* careful: calling conventions are nasty here */
50900 res = count;
50901 error = table->proc_handler(table, write, buf, &res, ppos);
50902 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
50903 return -ENOMEM;
50904 } else {
50905 d_set_d_op(child, &proc_sys_dentry_operations);
50906 +
50907 + gr_handle_proc_create(child, inode);
50908 +
50909 d_add(child, inode);
50910 }
50911 } else {
50912 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
50913 if ((*pos)++ < file->f_pos)
50914 return 0;
50915
50916 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
50917 + return 0;
50918 +
50919 if (unlikely(S_ISLNK(table->mode)))
50920 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
50921 else
50922 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
50923 if (IS_ERR(head))
50924 return PTR_ERR(head);
50925
50926 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
50927 + return -ENOENT;
50928 +
50929 generic_fillattr(inode, stat);
50930 if (table)
50931 stat->mode = (stat->mode & S_IFMT) | table->mode;
50932 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
50933 .llseek = generic_file_llseek,
50934 };
50935
50936 -static const struct inode_operations proc_sys_inode_operations = {
50937 +const struct inode_operations proc_sys_inode_operations = {
50938 .permission = proc_sys_permission,
50939 .setattr = proc_sys_setattr,
50940 .getattr = proc_sys_getattr,
50941 };
50942
50943 -static const struct inode_operations proc_sys_dir_operations = {
50944 +const struct inode_operations proc_sys_dir_operations = {
50945 .lookup = proc_sys_lookup,
50946 .permission = proc_sys_permission,
50947 .setattr = proc_sys_setattr,
50948 diff --git a/fs/proc/root.c b/fs/proc/root.c
50949 index 9889a92..2613b48 100644
50950 --- a/fs/proc/root.c
50951 +++ b/fs/proc/root.c
50952 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
50953 #ifdef CONFIG_PROC_DEVICETREE
50954 proc_device_tree_init();
50955 #endif
50956 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50957 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50958 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50959 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50960 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50961 +#endif
50962 +#else
50963 proc_mkdir("bus", NULL);
50964 +#endif
50965 proc_sys_init();
50966 }
50967
50968 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
50969 index 90c63f9..e662cfc 100644
50970 --- a/fs/proc/task_mmu.c
50971 +++ b/fs/proc/task_mmu.c
50972 @@ -11,12 +11,19 @@
50973 #include <linux/rmap.h>
50974 #include <linux/swap.h>
50975 #include <linux/swapops.h>
50976 +#include <linux/grsecurity.h>
50977
50978 #include <asm/elf.h>
50979 #include <asm/uaccess.h>
50980 #include <asm/tlbflush.h>
50981 #include "internal.h"
50982
50983 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50984 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50985 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50986 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50987 +#endif
50988 +
50989 void task_mem(struct seq_file *m, struct mm_struct *mm)
50990 {
50991 unsigned long data, text, lib, swap;
50992 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50993 "VmExe:\t%8lu kB\n"
50994 "VmLib:\t%8lu kB\n"
50995 "VmPTE:\t%8lu kB\n"
50996 - "VmSwap:\t%8lu kB\n",
50997 - hiwater_vm << (PAGE_SHIFT-10),
50998 + "VmSwap:\t%8lu kB\n"
50999 +
51000 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51001 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51002 +#endif
51003 +
51004 + ,hiwater_vm << (PAGE_SHIFT-10),
51005 total_vm << (PAGE_SHIFT-10),
51006 mm->locked_vm << (PAGE_SHIFT-10),
51007 mm->pinned_vm << (PAGE_SHIFT-10),
51008 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51009 data << (PAGE_SHIFT-10),
51010 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51011 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51012 - swap << (PAGE_SHIFT-10));
51013 + swap << (PAGE_SHIFT-10)
51014 +
51015 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51016 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51017 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51018 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51019 +#else
51020 + , mm->context.user_cs_base
51021 + , mm->context.user_cs_limit
51022 +#endif
51023 +#endif
51024 +
51025 + );
51026 }
51027
51028 unsigned long task_vsize(struct mm_struct *mm)
51029 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51030 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51031 }
51032
51033 - /* We don't show the stack guard page in /proc/maps */
51034 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51035 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51036 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51037 +#else
51038 start = vma->vm_start;
51039 - if (stack_guard_page_start(vma, start))
51040 - start += PAGE_SIZE;
51041 end = vma->vm_end;
51042 - if (stack_guard_page_end(vma, end))
51043 - end -= PAGE_SIZE;
51044 +#endif
51045
51046 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51047 start,
51048 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51049 flags & VM_WRITE ? 'w' : '-',
51050 flags & VM_EXEC ? 'x' : '-',
51051 flags & VM_MAYSHARE ? 's' : 'p',
51052 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51053 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51054 +#else
51055 pgoff,
51056 +#endif
51057 MAJOR(dev), MINOR(dev), ino, &len);
51058
51059 /*
51060 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51061 */
51062 if (file) {
51063 pad_len_spaces(m, len);
51064 - seq_path(m, &file->f_path, "\n");
51065 + seq_path(m, &file->f_path, "\n\\");
51066 goto done;
51067 }
51068
51069 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51070 * Thread stack in /proc/PID/task/TID/maps or
51071 * the main process stack.
51072 */
51073 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
51074 - vma->vm_end >= mm->start_stack)) {
51075 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51076 + (vma->vm_start <= mm->start_stack &&
51077 + vma->vm_end >= mm->start_stack)) {
51078 name = "[stack]";
51079 } else {
51080 /* Thread stack in /proc/PID/maps */
51081 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51082 struct proc_maps_private *priv = m->private;
51083 struct task_struct *task = priv->task;
51084
51085 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51086 + if (current->exec_id != m->exec_id) {
51087 + gr_log_badprocpid("maps");
51088 + return 0;
51089 + }
51090 +#endif
51091 +
51092 show_map_vma(m, vma, is_pid);
51093
51094 if (m->count < m->size) /* vma is copied successfully */
51095 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51096 .private = &mss,
51097 };
51098
51099 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51100 + if (current->exec_id != m->exec_id) {
51101 + gr_log_badprocpid("smaps");
51102 + return 0;
51103 + }
51104 +#endif
51105 memset(&mss, 0, sizeof mss);
51106 - mss.vma = vma;
51107 - /* mmap_sem is held in m_start */
51108 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51109 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51110 -
51111 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51112 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51113 +#endif
51114 + mss.vma = vma;
51115 + /* mmap_sem is held in m_start */
51116 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51117 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51118 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51119 + }
51120 +#endif
51121 show_map_vma(m, vma, is_pid);
51122
51123 seq_printf(m,
51124 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51125 "KernelPageSize: %8lu kB\n"
51126 "MMUPageSize: %8lu kB\n"
51127 "Locked: %8lu kB\n",
51128 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51129 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51130 +#else
51131 (vma->vm_end - vma->vm_start) >> 10,
51132 +#endif
51133 mss.resident >> 10,
51134 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51135 mss.shared_clean >> 10,
51136 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51137 int n;
51138 char buffer[50];
51139
51140 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51141 + if (current->exec_id != m->exec_id) {
51142 + gr_log_badprocpid("numa_maps");
51143 + return 0;
51144 + }
51145 +#endif
51146 +
51147 if (!mm)
51148 return 0;
51149
51150 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51151 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51152 mpol_cond_put(pol);
51153
51154 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51155 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51156 +#else
51157 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51158 +#endif
51159
51160 if (file) {
51161 seq_printf(m, " file=");
51162 - seq_path(m, &file->f_path, "\n\t= ");
51163 + seq_path(m, &file->f_path, "\n\t\\= ");
51164 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51165 seq_printf(m, " heap");
51166 } else {
51167 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51168 index 1ccfa53..0848f95 100644
51169 --- a/fs/proc/task_nommu.c
51170 +++ b/fs/proc/task_nommu.c
51171 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51172 else
51173 bytes += kobjsize(mm);
51174
51175 - if (current->fs && current->fs->users > 1)
51176 + if (current->fs && atomic_read(&current->fs->users) > 1)
51177 sbytes += kobjsize(current->fs);
51178 else
51179 bytes += kobjsize(current->fs);
51180 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51181
51182 if (file) {
51183 pad_len_spaces(m, len);
51184 - seq_path(m, &file->f_path, "");
51185 + seq_path(m, &file->f_path, "\n\\");
51186 } else if (mm) {
51187 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51188
51189 diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51190 index 2d57e1a..43b1280 100644
51191 --- a/fs/pstore/ftrace.c
51192 +++ b/fs/pstore/ftrace.c
51193 @@ -28,7 +28,9 @@
51194 #include "internal.h"
51195
51196 static void notrace pstore_ftrace_call(unsigned long ip,
51197 - unsigned long parent_ip)
51198 + unsigned long parent_ip,
51199 + struct ftrace_ops *op,
51200 + struct pt_regs *regs)
51201 {
51202 unsigned long flags;
51203 struct pstore_ftrace_record rec = {};
51204 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51205 index 16e8abb..2dcf914 100644
51206 --- a/fs/quota/netlink.c
51207 +++ b/fs/quota/netlink.c
51208 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51209 void quota_send_warning(struct kqid qid, dev_t dev,
51210 const char warntype)
51211 {
51212 - static atomic_t seq;
51213 + static atomic_unchecked_t seq;
51214 struct sk_buff *skb;
51215 void *msg_head;
51216 int ret;
51217 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51218 "VFS: Not enough memory to send quota warning.\n");
51219 return;
51220 }
51221 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51222 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51223 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51224 if (!msg_head) {
51225 printk(KERN_ERR
51226 diff --git a/fs/read_write.c b/fs/read_write.c
51227 index d065348..8e2b43d 100644
51228 --- a/fs/read_write.c
51229 +++ b/fs/read_write.c
51230 @@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51231 if (retval > 0) {
51232 add_rchar(current, retval);
51233 add_wchar(current, retval);
51234 + fsnotify_access(in.file);
51235 + fsnotify_modify(out.file);
51236 }
51237
51238 inc_syscr(current);
51239 diff --git a/fs/readdir.c b/fs/readdir.c
51240 index 5e69ef5..e5d9099 100644
51241 --- a/fs/readdir.c
51242 +++ b/fs/readdir.c
51243 @@ -17,6 +17,7 @@
51244 #include <linux/security.h>
51245 #include <linux/syscalls.h>
51246 #include <linux/unistd.h>
51247 +#include <linux/namei.h>
51248
51249 #include <asm/uaccess.h>
51250
51251 @@ -67,6 +68,7 @@ struct old_linux_dirent {
51252
51253 struct readdir_callback {
51254 struct old_linux_dirent __user * dirent;
51255 + struct file * file;
51256 int result;
51257 };
51258
51259 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51260 buf->result = -EOVERFLOW;
51261 return -EOVERFLOW;
51262 }
51263 +
51264 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51265 + return 0;
51266 +
51267 buf->result++;
51268 dirent = buf->dirent;
51269 if (!access_ok(VERIFY_WRITE, dirent,
51270 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51271
51272 buf.result = 0;
51273 buf.dirent = dirent;
51274 + buf.file = f.file;
51275
51276 error = vfs_readdir(f.file, fillonedir, &buf);
51277 if (buf.result)
51278 @@ -139,6 +146,7 @@ struct linux_dirent {
51279 struct getdents_callback {
51280 struct linux_dirent __user * current_dir;
51281 struct linux_dirent __user * previous;
51282 + struct file * file;
51283 int count;
51284 int error;
51285 };
51286 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51287 buf->error = -EOVERFLOW;
51288 return -EOVERFLOW;
51289 }
51290 +
51291 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51292 + return 0;
51293 +
51294 dirent = buf->previous;
51295 if (dirent) {
51296 if (__put_user(offset, &dirent->d_off))
51297 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51298 buf.previous = NULL;
51299 buf.count = count;
51300 buf.error = 0;
51301 + buf.file = f.file;
51302
51303 error = vfs_readdir(f.file, filldir, &buf);
51304 if (error >= 0)
51305 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51306 struct getdents_callback64 {
51307 struct linux_dirent64 __user * current_dir;
51308 struct linux_dirent64 __user * previous;
51309 + struct file *file;
51310 int count;
51311 int error;
51312 };
51313 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
51314 buf->error = -EINVAL; /* only used if we fail.. */
51315 if (reclen > buf->count)
51316 return -EINVAL;
51317 +
51318 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51319 + return 0;
51320 +
51321 dirent = buf->previous;
51322 if (dirent) {
51323 if (__put_user(offset, &dirent->d_off))
51324 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51325
51326 buf.current_dir = dirent;
51327 buf.previous = NULL;
51328 + buf.file = f.file;
51329 buf.count = count;
51330 buf.error = 0;
51331
51332 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51333 error = buf.error;
51334 lastdirent = buf.previous;
51335 if (lastdirent) {
51336 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
51337 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
51338 if (__put_user(d_off, &lastdirent->d_off))
51339 error = -EFAULT;
51340 else
51341 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
51342 index 2b7882b..1c5ef48 100644
51343 --- a/fs/reiserfs/do_balan.c
51344 +++ b/fs/reiserfs/do_balan.c
51345 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
51346 return;
51347 }
51348
51349 - atomic_inc(&(fs_generation(tb->tb_sb)));
51350 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
51351 do_balance_starts(tb);
51352
51353 /* balance leaf returns 0 except if combining L R and S into
51354 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
51355 index e60e870..f40ac16 100644
51356 --- a/fs/reiserfs/procfs.c
51357 +++ b/fs/reiserfs/procfs.c
51358 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
51359 "SMALL_TAILS " : "NO_TAILS ",
51360 replay_only(sb) ? "REPLAY_ONLY " : "",
51361 convert_reiserfs(sb) ? "CONV " : "",
51362 - atomic_read(&r->s_generation_counter),
51363 + atomic_read_unchecked(&r->s_generation_counter),
51364 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
51365 SF(s_do_balance), SF(s_unneeded_left_neighbor),
51366 SF(s_good_search_by_key_reada), SF(s_bmaps),
51367 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
51368 index 33215f5..c5d427a 100644
51369 --- a/fs/reiserfs/reiserfs.h
51370 +++ b/fs/reiserfs/reiserfs.h
51371 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
51372 /* Comment? -Hans */
51373 wait_queue_head_t s_wait;
51374 /* To be obsoleted soon by per buffer seals.. -Hans */
51375 - atomic_t s_generation_counter; // increased by one every time the
51376 + atomic_unchecked_t s_generation_counter; // increased by one every time the
51377 // tree gets re-balanced
51378 unsigned long s_properties; /* File system properties. Currently holds
51379 on-disk FS format */
51380 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
51381 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
51382
51383 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
51384 -#define get_generation(s) atomic_read (&fs_generation(s))
51385 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
51386 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
51387 #define __fs_changed(gen,s) (gen != get_generation (s))
51388 #define fs_changed(gen,s) \
51389 diff --git a/fs/select.c b/fs/select.c
51390 index 2ef72d9..f213b17 100644
51391 --- a/fs/select.c
51392 +++ b/fs/select.c
51393 @@ -20,6 +20,7 @@
51394 #include <linux/export.h>
51395 #include <linux/slab.h>
51396 #include <linux/poll.h>
51397 +#include <linux/security.h>
51398 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
51399 #include <linux/file.h>
51400 #include <linux/fdtable.h>
51401 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
51402 struct poll_list *walk = head;
51403 unsigned long todo = nfds;
51404
51405 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
51406 if (nfds > rlimit(RLIMIT_NOFILE))
51407 return -EINVAL;
51408
51409 diff --git a/fs/seq_file.c b/fs/seq_file.c
51410 index 99dffab..e4fcb71 100644
51411 --- a/fs/seq_file.c
51412 +++ b/fs/seq_file.c
51413 @@ -10,6 +10,7 @@
51414 #include <linux/seq_file.h>
51415 #include <linux/slab.h>
51416 #include <linux/cred.h>
51417 +#include <linux/sched.h>
51418
51419 #include <asm/uaccess.h>
51420 #include <asm/page.h>
51421 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
51422 #ifdef CONFIG_USER_NS
51423 p->user_ns = file->f_cred->user_ns;
51424 #endif
51425 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51426 + p->exec_id = current->exec_id;
51427 +#endif
51428
51429 /*
51430 * Wrappers around seq_open(e.g. swaps_open) need to be
51431 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51432 return 0;
51433 }
51434 if (!m->buf) {
51435 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51436 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51437 if (!m->buf)
51438 return -ENOMEM;
51439 }
51440 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51441 Eoverflow:
51442 m->op->stop(m, p);
51443 kfree(m->buf);
51444 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51445 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51446 return !m->buf ? -ENOMEM : -EAGAIN;
51447 }
51448
51449 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51450
51451 /* grab buffer if we didn't have one */
51452 if (!m->buf) {
51453 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51454 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51455 if (!m->buf)
51456 goto Enomem;
51457 }
51458 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51459 goto Fill;
51460 m->op->stop(m, p);
51461 kfree(m->buf);
51462 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51463 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51464 if (!m->buf)
51465 goto Enomem;
51466 m->count = 0;
51467 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
51468 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
51469 void *data)
51470 {
51471 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
51472 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
51473 int res = -ENOMEM;
51474
51475 if (op) {
51476 diff --git a/fs/splice.c b/fs/splice.c
51477 index 48c7bd1..d0740e4 100644
51478 --- a/fs/splice.c
51479 +++ b/fs/splice.c
51480 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51481 pipe_lock(pipe);
51482
51483 for (;;) {
51484 - if (!pipe->readers) {
51485 + if (!atomic_read(&pipe->readers)) {
51486 send_sig(SIGPIPE, current, 0);
51487 if (!ret)
51488 ret = -EPIPE;
51489 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51490 do_wakeup = 0;
51491 }
51492
51493 - pipe->waiting_writers++;
51494 + atomic_inc(&pipe->waiting_writers);
51495 pipe_wait(pipe);
51496 - pipe->waiting_writers--;
51497 + atomic_dec(&pipe->waiting_writers);
51498 }
51499
51500 pipe_unlock(pipe);
51501 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
51502 old_fs = get_fs();
51503 set_fs(get_ds());
51504 /* The cast to a user pointer is valid due to the set_fs() */
51505 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
51506 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
51507 set_fs(old_fs);
51508
51509 return res;
51510 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
51511 old_fs = get_fs();
51512 set_fs(get_ds());
51513 /* The cast to a user pointer is valid due to the set_fs() */
51514 - res = vfs_write(file, (const char __user *)buf, count, &pos);
51515 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
51516 set_fs(old_fs);
51517
51518 return res;
51519 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
51520 goto err;
51521
51522 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
51523 - vec[i].iov_base = (void __user *) page_address(page);
51524 + vec[i].iov_base = (void __force_user *) page_address(page);
51525 vec[i].iov_len = this_len;
51526 spd.pages[i] = page;
51527 spd.nr_pages++;
51528 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
51529 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
51530 {
51531 while (!pipe->nrbufs) {
51532 - if (!pipe->writers)
51533 + if (!atomic_read(&pipe->writers))
51534 return 0;
51535
51536 - if (!pipe->waiting_writers && sd->num_spliced)
51537 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
51538 return 0;
51539
51540 if (sd->flags & SPLICE_F_NONBLOCK)
51541 @@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
51542 * out of the pipe right after the splice_to_pipe(). So set
51543 * PIPE_READERS appropriately.
51544 */
51545 - pipe->readers = 1;
51546 + atomic_set(&pipe->readers, 1);
51547
51548 current->splice_pipe = pipe;
51549 }
51550 @@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51551 ret = -ERESTARTSYS;
51552 break;
51553 }
51554 - if (!pipe->writers)
51555 + if (!atomic_read(&pipe->writers))
51556 break;
51557 - if (!pipe->waiting_writers) {
51558 + if (!atomic_read(&pipe->waiting_writers)) {
51559 if (flags & SPLICE_F_NONBLOCK) {
51560 ret = -EAGAIN;
51561 break;
51562 @@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51563 pipe_lock(pipe);
51564
51565 while (pipe->nrbufs >= pipe->buffers) {
51566 - if (!pipe->readers) {
51567 + if (!atomic_read(&pipe->readers)) {
51568 send_sig(SIGPIPE, current, 0);
51569 ret = -EPIPE;
51570 break;
51571 @@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51572 ret = -ERESTARTSYS;
51573 break;
51574 }
51575 - pipe->waiting_writers++;
51576 + atomic_inc(&pipe->waiting_writers);
51577 pipe_wait(pipe);
51578 - pipe->waiting_writers--;
51579 + atomic_dec(&pipe->waiting_writers);
51580 }
51581
51582 pipe_unlock(pipe);
51583 @@ -1826,14 +1826,14 @@ retry:
51584 pipe_double_lock(ipipe, opipe);
51585
51586 do {
51587 - if (!opipe->readers) {
51588 + if (!atomic_read(&opipe->readers)) {
51589 send_sig(SIGPIPE, current, 0);
51590 if (!ret)
51591 ret = -EPIPE;
51592 break;
51593 }
51594
51595 - if (!ipipe->nrbufs && !ipipe->writers)
51596 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
51597 break;
51598
51599 /*
51600 @@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51601 pipe_double_lock(ipipe, opipe);
51602
51603 do {
51604 - if (!opipe->readers) {
51605 + if (!atomic_read(&opipe->readers)) {
51606 send_sig(SIGPIPE, current, 0);
51607 if (!ret)
51608 ret = -EPIPE;
51609 @@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51610 * return EAGAIN if we have the potential of some data in the
51611 * future, otherwise just return 0
51612 */
51613 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
51614 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
51615 ret = -EAGAIN;
51616
51617 pipe_unlock(ipipe);
51618 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
51619 index 2fbdff6..5530a61 100644
51620 --- a/fs/sysfs/dir.c
51621 +++ b/fs/sysfs/dir.c
51622 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
51623 struct sysfs_dirent *sd;
51624 int rc;
51625
51626 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
51627 + const char *parent_name = parent_sd->s_name;
51628 +
51629 + mode = S_IFDIR | S_IRWXU;
51630 +
51631 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
51632 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
51633 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
51634 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
51635 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
51636 +#endif
51637 +
51638 /* allocate */
51639 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
51640 if (!sd)
51641 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
51642 index 00012e3..8392349 100644
51643 --- a/fs/sysfs/file.c
51644 +++ b/fs/sysfs/file.c
51645 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
51646
51647 struct sysfs_open_dirent {
51648 atomic_t refcnt;
51649 - atomic_t event;
51650 + atomic_unchecked_t event;
51651 wait_queue_head_t poll;
51652 struct list_head buffers; /* goes through sysfs_buffer.list */
51653 };
51654 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
51655 if (!sysfs_get_active(attr_sd))
51656 return -ENODEV;
51657
51658 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
51659 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
51660 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
51661
51662 sysfs_put_active(attr_sd);
51663 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
51664 return -ENOMEM;
51665
51666 atomic_set(&new_od->refcnt, 0);
51667 - atomic_set(&new_od->event, 1);
51668 + atomic_set_unchecked(&new_od->event, 1);
51669 init_waitqueue_head(&new_od->poll);
51670 INIT_LIST_HEAD(&new_od->buffers);
51671 goto retry;
51672 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
51673
51674 sysfs_put_active(attr_sd);
51675
51676 - if (buffer->event != atomic_read(&od->event))
51677 + if (buffer->event != atomic_read_unchecked(&od->event))
51678 goto trigger;
51679
51680 return DEFAULT_POLLMASK;
51681 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
51682
51683 od = sd->s_attr.open;
51684 if (od) {
51685 - atomic_inc(&od->event);
51686 + atomic_inc_unchecked(&od->event);
51687 wake_up_interruptible(&od->poll);
51688 }
51689
51690 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
51691 index 3c9eb56..9dea5be 100644
51692 --- a/fs/sysfs/symlink.c
51693 +++ b/fs/sysfs/symlink.c
51694 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
51695
51696 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
51697 {
51698 - char *page = nd_get_link(nd);
51699 + const char *page = nd_get_link(nd);
51700 if (!IS_ERR(page))
51701 free_page((unsigned long)page);
51702 }
51703 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
51704 index c175b4d..8f36a16 100644
51705 --- a/fs/udf/misc.c
51706 +++ b/fs/udf/misc.c
51707 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
51708
51709 u8 udf_tag_checksum(const struct tag *t)
51710 {
51711 - u8 *data = (u8 *)t;
51712 + const u8 *data = (const u8 *)t;
51713 u8 checksum = 0;
51714 int i;
51715 for (i = 0; i < sizeof(struct tag); ++i)
51716 diff --git a/fs/utimes.c b/fs/utimes.c
51717 index bb0696a..552054b 100644
51718 --- a/fs/utimes.c
51719 +++ b/fs/utimes.c
51720 @@ -1,6 +1,7 @@
51721 #include <linux/compiler.h>
51722 #include <linux/file.h>
51723 #include <linux/fs.h>
51724 +#include <linux/security.h>
51725 #include <linux/linkage.h>
51726 #include <linux/mount.h>
51727 #include <linux/namei.h>
51728 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
51729 goto mnt_drop_write_and_out;
51730 }
51731 }
51732 +
51733 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
51734 + error = -EACCES;
51735 + goto mnt_drop_write_and_out;
51736 + }
51737 +
51738 mutex_lock(&inode->i_mutex);
51739 error = notify_change(path->dentry, &newattrs);
51740 mutex_unlock(&inode->i_mutex);
51741 diff --git a/fs/xattr.c b/fs/xattr.c
51742 index e21c119..21dfc7c 100644
51743 --- a/fs/xattr.c
51744 +++ b/fs/xattr.c
51745 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
51746 * Extended attribute SET operations
51747 */
51748 static long
51749 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
51750 +setxattr(struct path *path, const char __user *name, const void __user *value,
51751 size_t size, int flags)
51752 {
51753 int error;
51754 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
51755 posix_acl_fix_xattr_from_user(kvalue, size);
51756 }
51757
51758 - error = vfs_setxattr(d, kname, kvalue, size, flags);
51759 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51760 + error = -EACCES;
51761 + goto out;
51762 + }
51763 +
51764 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
51765 out:
51766 if (vvalue)
51767 vfree(vvalue);
51768 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
51769 return error;
51770 error = mnt_want_write(path.mnt);
51771 if (!error) {
51772 - error = setxattr(path.dentry, name, value, size, flags);
51773 + error = setxattr(&path, name, value, size, flags);
51774 mnt_drop_write(path.mnt);
51775 }
51776 path_put(&path);
51777 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
51778 return error;
51779 error = mnt_want_write(path.mnt);
51780 if (!error) {
51781 - error = setxattr(path.dentry, name, value, size, flags);
51782 + error = setxattr(&path, name, value, size, flags);
51783 mnt_drop_write(path.mnt);
51784 }
51785 path_put(&path);
51786 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
51787 const void __user *,value, size_t, size, int, flags)
51788 {
51789 struct fd f = fdget(fd);
51790 - struct dentry *dentry;
51791 int error = -EBADF;
51792
51793 if (!f.file)
51794 return error;
51795 - dentry = f.file->f_path.dentry;
51796 - audit_inode(NULL, dentry, 0);
51797 + audit_inode(NULL, f.file->f_path.dentry, 0);
51798 error = mnt_want_write_file(f.file);
51799 if (!error) {
51800 - error = setxattr(dentry, name, value, size, flags);
51801 + error = setxattr(&f.file->f_path, name, value, size, flags);
51802 mnt_drop_write_file(f.file);
51803 }
51804 fdput(f);
51805 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
51806 index 9fbea87..6b19972 100644
51807 --- a/fs/xattr_acl.c
51808 +++ b/fs/xattr_acl.c
51809 @@ -76,8 +76,8 @@ struct posix_acl *
51810 posix_acl_from_xattr(struct user_namespace *user_ns,
51811 const void *value, size_t size)
51812 {
51813 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51814 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51815 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51816 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51817 int count;
51818 struct posix_acl *acl;
51819 struct posix_acl_entry *acl_e;
51820 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
51821 index 83d0cf3..2ef526b 100644
51822 --- a/fs/xfs/xfs_bmap.c
51823 +++ b/fs/xfs/xfs_bmap.c
51824 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
51825 int nmap,
51826 int ret_nmap);
51827 #else
51828 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51829 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51830 #endif /* DEBUG */
51831
51832 STATIC int
51833 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
51834 index 1b9fc3e..e1bdde0 100644
51835 --- a/fs/xfs/xfs_dir2_sf.c
51836 +++ b/fs/xfs/xfs_dir2_sf.c
51837 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
51838 }
51839
51840 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
51841 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51842 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51843 + char name[sfep->namelen];
51844 + memcpy(name, sfep->name, sfep->namelen);
51845 + if (filldir(dirent, name, sfep->namelen,
51846 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
51847 + *offset = off & 0x7fffffff;
51848 + return 0;
51849 + }
51850 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51851 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51852 *offset = off & 0x7fffffff;
51853 return 0;
51854 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
51855 index c1df3c6..f987db6 100644
51856 --- a/fs/xfs/xfs_ioctl.c
51857 +++ b/fs/xfs/xfs_ioctl.c
51858 @@ -126,7 +126,7 @@ xfs_find_handle(
51859 }
51860
51861 error = -EFAULT;
51862 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51863 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51864 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51865 goto out_put;
51866
51867 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
51868 index 4e00cf0..3374374 100644
51869 --- a/fs/xfs/xfs_iops.c
51870 +++ b/fs/xfs/xfs_iops.c
51871 @@ -394,7 +394,7 @@ xfs_vn_put_link(
51872 struct nameidata *nd,
51873 void *p)
51874 {
51875 - char *s = nd_get_link(nd);
51876 + const char *s = nd_get_link(nd);
51877
51878 if (!IS_ERR(s))
51879 kfree(s);
51880 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
51881 new file mode 100644
51882 index 0000000..ba93743
51883 --- /dev/null
51884 +++ b/grsecurity/Kconfig
51885 @@ -0,0 +1,982 @@
51886 +#
51887 +# grecurity configuration
51888 +#
51889 +menu "Memory Protections"
51890 +depends on GRKERNSEC
51891 +
51892 +config GRKERNSEC_KMEM
51893 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
51894 + default y if GRKERNSEC_CONFIG_AUTO
51895 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
51896 + help
51897 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
51898 + be written to or read from to modify or leak the contents of the running
51899 + kernel. /dev/port will also not be allowed to be opened. If you have module
51900 + support disabled, enabling this will close up four ways that are
51901 + currently used to insert malicious code into the running kernel.
51902 + Even with all these features enabled, we still highly recommend that
51903 + you use the RBAC system, as it is still possible for an attacker to
51904 + modify the running kernel through privileged I/O granted by ioperm/iopl.
51905 + If you are not using XFree86, you may be able to stop this additional
51906 + case by enabling the 'Disable privileged I/O' option. Though nothing
51907 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
51908 + but only to video memory, which is the only writing we allow in this
51909 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
51910 + not be allowed to mprotect it with PROT_WRITE later.
51911 + It is highly recommended that you say Y here if you meet all the
51912 + conditions above.
51913 +
51914 +config GRKERNSEC_VM86
51915 + bool "Restrict VM86 mode"
51916 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51917 + depends on X86_32
51918 +
51919 + help
51920 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
51921 + make use of a special execution mode on 32bit x86 processors called
51922 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
51923 + video cards and will still work with this option enabled. The purpose
51924 + of the option is to prevent exploitation of emulation errors in
51925 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
51926 + Nearly all users should be able to enable this option.
51927 +
51928 +config GRKERNSEC_IO
51929 + bool "Disable privileged I/O"
51930 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51931 + depends on X86
51932 + select RTC_CLASS
51933 + select RTC_INTF_DEV
51934 + select RTC_DRV_CMOS
51935 +
51936 + help
51937 + If you say Y here, all ioperm and iopl calls will return an error.
51938 + Ioperm and iopl can be used to modify the running kernel.
51939 + Unfortunately, some programs need this access to operate properly,
51940 + the most notable of which are XFree86 and hwclock. hwclock can be
51941 + remedied by having RTC support in the kernel, so real-time
51942 + clock support is enabled if this option is enabled, to ensure
51943 + that hwclock operates correctly. XFree86 still will not
51944 + operate correctly with this option enabled, so DO NOT CHOOSE Y
51945 + IF YOU USE XFree86. If you use XFree86 and you still want to
51946 + protect your kernel against modification, use the RBAC system.
51947 +
51948 +config GRKERNSEC_JIT_HARDEN
51949 + bool "Harden BPF JIT against spray attacks"
51950 + default y if GRKERNSEC_CONFIG_AUTO
51951 + depends on BPF_JIT
51952 + help
51953 + If you say Y here, the native code generated by the kernel's Berkeley
51954 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
51955 + attacks that attempt to fit attacker-beneficial instructions in
51956 + 32bit immediate fields of JIT-generated native instructions. The
51957 + attacker will generally aim to cause an unintended instruction sequence
51958 + of JIT-generated native code to execute by jumping into the middle of
51959 + a generated instruction. This feature effectively randomizes the 32bit
51960 + immediate constants present in the generated code to thwart such attacks.
51961 +
51962 + If you're using KERNEXEC, it's recommended that you enable this option
51963 + to supplement the hardening of the kernel.
51964 +
51965 +config GRKERNSEC_PROC_MEMMAP
51966 + bool "Harden ASLR against information leaks and entropy reduction"
51967 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
51968 + depends on PAX_NOEXEC || PAX_ASLR
51969 + help
51970 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
51971 + give no information about the addresses of its mappings if
51972 + PaX features that rely on random addresses are enabled on the task.
51973 + In addition to sanitizing this information and disabling other
51974 + dangerous sources of information, this option causes reads of sensitive
51975 + /proc/<pid> entries where the file descriptor was opened in a different
51976 + task than the one performing the read. Such attempts are logged.
51977 + This option also limits argv/env strings for suid/sgid binaries
51978 + to 512KB to prevent a complete exhaustion of the stack entropy provided
51979 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
51980 + binaries to prevent alternative mmap layouts from being abused.
51981 +
51982 + If you use PaX it is essential that you say Y here as it closes up
51983 + several holes that make full ASLR useless locally.
51984 +
51985 +config GRKERNSEC_BRUTE
51986 + bool "Deter exploit bruteforcing"
51987 + default y if GRKERNSEC_CONFIG_AUTO
51988 + help
51989 + If you say Y here, attempts to bruteforce exploits against forking
51990 + daemons such as apache or sshd, as well as against suid/sgid binaries
51991 + will be deterred. When a child of a forking daemon is killed by PaX
51992 + or crashes due to an illegal instruction or other suspicious signal,
51993 + the parent process will be delayed 30 seconds upon every subsequent
51994 + fork until the administrator is able to assess the situation and
51995 + restart the daemon.
51996 + In the suid/sgid case, the attempt is logged, the user has all their
51997 + processes terminated, and they are prevented from executing any further
51998 + processes for 15 minutes.
51999 + It is recommended that you also enable signal logging in the auditing
52000 + section so that logs are generated when a process triggers a suspicious
52001 + signal.
52002 + If the sysctl option is enabled, a sysctl option with name
52003 + "deter_bruteforce" is created.
52004 +
52005 +
52006 +config GRKERNSEC_MODHARDEN
52007 + bool "Harden module auto-loading"
52008 + default y if GRKERNSEC_CONFIG_AUTO
52009 + depends on MODULES
52010 + help
52011 + If you say Y here, module auto-loading in response to use of some
52012 + feature implemented by an unloaded module will be restricted to
52013 + root users. Enabling this option helps defend against attacks
52014 + by unprivileged users who abuse the auto-loading behavior to
52015 + cause a vulnerable module to load that is then exploited.
52016 +
52017 + If this option prevents a legitimate use of auto-loading for a
52018 + non-root user, the administrator can execute modprobe manually
52019 + with the exact name of the module mentioned in the alert log.
52020 + Alternatively, the administrator can add the module to the list
52021 + of modules loaded at boot by modifying init scripts.
52022 +
52023 + Modification of init scripts will most likely be needed on
52024 + Ubuntu servers with encrypted home directory support enabled,
52025 + as the first non-root user logging in will cause the ecb(aes),
52026 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52027 +
52028 +config GRKERNSEC_HIDESYM
52029 + bool "Hide kernel symbols"
52030 + default y if GRKERNSEC_CONFIG_AUTO
52031 + select PAX_USERCOPY_SLABS
52032 + help
52033 + If you say Y here, getting information on loaded modules, and
52034 + displaying all kernel symbols through a syscall will be restricted
52035 + to users with CAP_SYS_MODULE. For software compatibility reasons,
52036 + /proc/kallsyms will be restricted to the root user. The RBAC
52037 + system can hide that entry even from root.
52038 +
52039 + This option also prevents leaking of kernel addresses through
52040 + several /proc entries.
52041 +
52042 + Note that this option is only effective provided the following
52043 + conditions are met:
52044 + 1) The kernel using grsecurity is not precompiled by some distribution
52045 + 2) You have also enabled GRKERNSEC_DMESG
52046 + 3) You are using the RBAC system and hiding other files such as your
52047 + kernel image and System.map. Alternatively, enabling this option
52048 + causes the permissions on /boot, /lib/modules, and the kernel
52049 + source directory to change at compile time to prevent
52050 + reading by non-root users.
52051 + If the above conditions are met, this option will aid in providing a
52052 + useful protection against local kernel exploitation of overflows
52053 + and arbitrary read/write vulnerabilities.
52054 +
52055 +config GRKERNSEC_KERN_LOCKOUT
52056 + bool "Active kernel exploit response"
52057 + default y if GRKERNSEC_CONFIG_AUTO
52058 + depends on X86 || ARM || PPC || SPARC
52059 + help
52060 + If you say Y here, when a PaX alert is triggered due to suspicious
52061 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52062 + or an OOPS occurs due to bad memory accesses, instead of just
52063 + terminating the offending process (and potentially allowing
52064 + a subsequent exploit from the same user), we will take one of two
52065 + actions:
52066 + If the user was root, we will panic the system
52067 + If the user was non-root, we will log the attempt, terminate
52068 + all processes owned by the user, then prevent them from creating
52069 + any new processes until the system is restarted
52070 + This deters repeated kernel exploitation/bruteforcing attempts
52071 + and is useful for later forensics.
52072 +
52073 +endmenu
52074 +menu "Role Based Access Control Options"
52075 +depends on GRKERNSEC
52076 +
52077 +config GRKERNSEC_RBAC_DEBUG
52078 + bool
52079 +
52080 +config GRKERNSEC_NO_RBAC
52081 + bool "Disable RBAC system"
52082 + help
52083 + If you say Y here, the /dev/grsec device will be removed from the kernel,
52084 + preventing the RBAC system from being enabled. You should only say Y
52085 + here if you have no intention of using the RBAC system, so as to prevent
52086 + an attacker with root access from misusing the RBAC system to hide files
52087 + and processes when loadable module support and /dev/[k]mem have been
52088 + locked down.
52089 +
52090 +config GRKERNSEC_ACL_HIDEKERN
52091 + bool "Hide kernel processes"
52092 + help
52093 + If you say Y here, all kernel threads will be hidden to all
52094 + processes but those whose subject has the "view hidden processes"
52095 + flag.
52096 +
52097 +config GRKERNSEC_ACL_MAXTRIES
52098 + int "Maximum tries before password lockout"
52099 + default 3
52100 + help
52101 + This option enforces the maximum number of times a user can attempt
52102 + to authorize themselves with the grsecurity RBAC system before being
52103 + denied the ability to attempt authorization again for a specified time.
52104 + The lower the number, the harder it will be to brute-force a password.
52105 +
52106 +config GRKERNSEC_ACL_TIMEOUT
52107 + int "Time to wait after max password tries, in seconds"
52108 + default 30
52109 + help
52110 + This option specifies the time the user must wait after attempting to
52111 + authorize to the RBAC system with the maximum number of invalid
52112 + passwords. The higher the number, the harder it will be to brute-force
52113 + a password.
52114 +
52115 +endmenu
52116 +menu "Filesystem Protections"
52117 +depends on GRKERNSEC
52118 +
52119 +config GRKERNSEC_PROC
52120 + bool "Proc restrictions"
52121 + default y if GRKERNSEC_CONFIG_AUTO
52122 + help
52123 + If you say Y here, the permissions of the /proc filesystem
52124 + will be altered to enhance system security and privacy. You MUST
52125 + choose either a user only restriction or a user and group restriction.
52126 + Depending upon the option you choose, you can either restrict users to
52127 + see only the processes they themselves run, or choose a group that can
52128 + view all processes and files normally restricted to root if you choose
52129 + the "restrict to user only" option. NOTE: If you're running identd or
52130 + ntpd as a non-root user, you will have to run it as the group you
52131 + specify here.
52132 +
52133 +config GRKERNSEC_PROC_USER
52134 + bool "Restrict /proc to user only"
52135 + depends on GRKERNSEC_PROC
52136 + help
52137 + If you say Y here, non-root users will only be able to view their own
52138 + processes, and restricts them from viewing network-related information,
52139 + and viewing kernel symbol and module information.
52140 +
52141 +config GRKERNSEC_PROC_USERGROUP
52142 + bool "Allow special group"
52143 + default y if GRKERNSEC_CONFIG_AUTO
52144 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52145 + help
52146 + If you say Y here, you will be able to select a group that will be
52147 + able to view all processes and network-related information. If you've
52148 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52149 + remain hidden. This option is useful if you want to run identd as
52150 + a non-root user. The group you select may also be chosen at boot time
52151 + via "grsec_proc_gid=" on the kernel commandline.
52152 +
52153 +config GRKERNSEC_PROC_GID
52154 + int "GID for special group"
52155 + depends on GRKERNSEC_PROC_USERGROUP
52156 + default 1001
52157 +
52158 +config GRKERNSEC_PROC_ADD
52159 + bool "Additional restrictions"
52160 + default y if GRKERNSEC_CONFIG_AUTO
52161 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52162 + help
52163 + If you say Y here, additional restrictions will be placed on
52164 + /proc that keep normal users from viewing device information and
52165 + slabinfo information that could be useful for exploits.
52166 +
52167 +config GRKERNSEC_LINK
52168 + bool "Linking restrictions"
52169 + default y if GRKERNSEC_CONFIG_AUTO
52170 + help
52171 + If you say Y here, /tmp race exploits will be prevented, since users
52172 + will no longer be able to follow symlinks owned by other users in
52173 + world-writable +t directories (e.g. /tmp), unless the owner of the
52174 + symlink is the owner of the directory. users will also not be
52175 + able to hardlink to files they do not own. If the sysctl option is
52176 + enabled, a sysctl option with name "linking_restrictions" is created.
52177 +
52178 +config GRKERNSEC_SYMLINKOWN
52179 + bool "Kernel-enforced SymlinksIfOwnerMatch"
52180 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52181 + help
52182 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
52183 + that prevents it from being used as a security feature. As Apache
52184 + verifies the symlink by performing a stat() against the target of
52185 + the symlink before it is followed, an attacker can setup a symlink
52186 + to point to a same-owned file, then replace the symlink with one
52187 + that targets another user's file just after Apache "validates" the
52188 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
52189 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52190 + will be in place for the group you specify. If the sysctl option
52191 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
52192 + created.
52193 +
52194 +config GRKERNSEC_SYMLINKOWN_GID
52195 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52196 + depends on GRKERNSEC_SYMLINKOWN
52197 + default 1006
52198 + help
52199 + Setting this GID determines what group kernel-enforced
52200 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52201 + is enabled, a sysctl option with name "symlinkown_gid" is created.
52202 +
52203 +config GRKERNSEC_FIFO
52204 + bool "FIFO restrictions"
52205 + default y if GRKERNSEC_CONFIG_AUTO
52206 + help
52207 + If you say Y here, users will not be able to write to FIFOs they don't
52208 + own in world-writable +t directories (e.g. /tmp), unless the owner of
52209 + the FIFO is the same owner of the directory it's held in. If the sysctl
52210 + option is enabled, a sysctl option with name "fifo_restrictions" is
52211 + created.
52212 +
52213 +config GRKERNSEC_SYSFS_RESTRICT
52214 + bool "Sysfs/debugfs restriction"
52215 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52216 + depends on SYSFS
52217 + help
52218 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52219 + any filesystem normally mounted under it (e.g. debugfs) will be
52220 + mostly accessible only by root. These filesystems generally provide access
52221 + to hardware and debug information that isn't appropriate for unprivileged
52222 + users of the system. Sysfs and debugfs have also become a large source
52223 + of new vulnerabilities, ranging from infoleaks to local compromise.
52224 + There has been very little oversight with an eye toward security involved
52225 + in adding new exporters of information to these filesystems, so their
52226 + use is discouraged.
52227 + For reasons of compatibility, a few directories have been whitelisted
52228 + for access by non-root users:
52229 + /sys/fs/selinux
52230 + /sys/fs/fuse
52231 + /sys/devices/system/cpu
52232 +
52233 +config GRKERNSEC_ROFS
52234 + bool "Runtime read-only mount protection"
52235 + help
52236 + If you say Y here, a sysctl option with name "romount_protect" will
52237 + be created. By setting this option to 1 at runtime, filesystems
52238 + will be protected in the following ways:
52239 + * No new writable mounts will be allowed
52240 + * Existing read-only mounts won't be able to be remounted read/write
52241 + * Write operations will be denied on all block devices
52242 + This option acts independently of grsec_lock: once it is set to 1,
52243 + it cannot be turned off. Therefore, please be mindful of the resulting
52244 + behavior if this option is enabled in an init script on a read-only
52245 + filesystem. This feature is mainly intended for secure embedded systems.
52246 +
52247 +config GRKERNSEC_CHROOT
52248 + bool "Chroot jail restrictions"
52249 + default y if GRKERNSEC_CONFIG_AUTO
52250 + help
52251 + If you say Y here, you will be able to choose several options that will
52252 + make breaking out of a chrooted jail much more difficult. If you
52253 + encounter no software incompatibilities with the following options, it
52254 + is recommended that you enable each one.
52255 +
52256 +config GRKERNSEC_CHROOT_MOUNT
52257 + bool "Deny mounts"
52258 + default y if GRKERNSEC_CONFIG_AUTO
52259 + depends on GRKERNSEC_CHROOT
52260 + help
52261 + If you say Y here, processes inside a chroot will not be able to
52262 + mount or remount filesystems. If the sysctl option is enabled, a
52263 + sysctl option with name "chroot_deny_mount" is created.
52264 +
52265 +config GRKERNSEC_CHROOT_DOUBLE
52266 + bool "Deny double-chroots"
52267 + default y if GRKERNSEC_CONFIG_AUTO
52268 + depends on GRKERNSEC_CHROOT
52269 + help
52270 + If you say Y here, processes inside a chroot will not be able to chroot
52271 + again outside the chroot. This is a widely used method of breaking
52272 + out of a chroot jail and should not be allowed. If the sysctl
52273 + option is enabled, a sysctl option with name
52274 + "chroot_deny_chroot" is created.
52275 +
52276 +config GRKERNSEC_CHROOT_PIVOT
52277 + bool "Deny pivot_root in chroot"
52278 + default y if GRKERNSEC_CONFIG_AUTO
52279 + depends on GRKERNSEC_CHROOT
52280 + help
52281 + If you say Y here, processes inside a chroot will not be able to use
52282 + a function called pivot_root() that was introduced in Linux 2.3.41. It
52283 + works similar to chroot in that it changes the root filesystem. This
52284 + function could be misused in a chrooted process to attempt to break out
52285 + of the chroot, and therefore should not be allowed. If the sysctl
52286 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
52287 + created.
52288 +
52289 +config GRKERNSEC_CHROOT_CHDIR
52290 + bool "Enforce chdir(\"/\") on all chroots"
52291 + default y if GRKERNSEC_CONFIG_AUTO
52292 + depends on GRKERNSEC_CHROOT
52293 + help
52294 + If you say Y here, the current working directory of all newly-chrooted
52295 + applications will be set to the the root directory of the chroot.
52296 + The man page on chroot(2) states:
52297 + Note that this call does not change the current working
52298 + directory, so that `.' can be outside the tree rooted at
52299 + `/'. In particular, the super-user can escape from a
52300 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
52301 +
52302 + It is recommended that you say Y here, since it's not known to break
52303 + any software. If the sysctl option is enabled, a sysctl option with
52304 + name "chroot_enforce_chdir" is created.
52305 +
52306 +config GRKERNSEC_CHROOT_CHMOD
52307 + bool "Deny (f)chmod +s"
52308 + default y if GRKERNSEC_CONFIG_AUTO
52309 + depends on GRKERNSEC_CHROOT
52310 + help
52311 + If you say Y here, processes inside a chroot will not be able to chmod
52312 + or fchmod files to make them have suid or sgid bits. This protects
52313 + against another published method of breaking a chroot. If the sysctl
52314 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
52315 + created.
52316 +
52317 +config GRKERNSEC_CHROOT_FCHDIR
52318 + bool "Deny fchdir out of chroot"
52319 + default y if GRKERNSEC_CONFIG_AUTO
52320 + depends on GRKERNSEC_CHROOT
52321 + help
52322 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
52323 + to a file descriptor of the chrooting process that points to a directory
52324 + outside the filesystem will be stopped. If the sysctl option
52325 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
52326 +
52327 +config GRKERNSEC_CHROOT_MKNOD
52328 + bool "Deny mknod"
52329 + default y if GRKERNSEC_CONFIG_AUTO
52330 + depends on GRKERNSEC_CHROOT
52331 + help
52332 + If you say Y here, processes inside a chroot will not be allowed to
52333 + mknod. The problem with using mknod inside a chroot is that it
52334 + would allow an attacker to create a device entry that is the same
52335 + as one on the physical root of your system, which could range from
52336 + anything from the console device to a device for your harddrive (which
52337 + they could then use to wipe the drive or steal data). It is recommended
52338 + that you say Y here, unless you run into software incompatibilities.
52339 + If the sysctl option is enabled, a sysctl option with name
52340 + "chroot_deny_mknod" is created.
52341 +
52342 +config GRKERNSEC_CHROOT_SHMAT
52343 + bool "Deny shmat() out of chroot"
52344 + default y if GRKERNSEC_CONFIG_AUTO
52345 + depends on GRKERNSEC_CHROOT
52346 + help
52347 + If you say Y here, processes inside a chroot will not be able to attach
52348 + to shared memory segments that were created outside of the chroot jail.
52349 + It is recommended that you say Y here. If the sysctl option is enabled,
52350 + a sysctl option with name "chroot_deny_shmat" is created.
52351 +
52352 +config GRKERNSEC_CHROOT_UNIX
52353 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
52354 + default y if GRKERNSEC_CONFIG_AUTO
52355 + depends on GRKERNSEC_CHROOT
52356 + help
52357 + If you say Y here, processes inside a chroot will not be able to
52358 + connect to abstract (meaning not belonging to a filesystem) Unix
52359 + domain sockets that were bound outside of a chroot. It is recommended
52360 + that you say Y here. If the sysctl option is enabled, a sysctl option
52361 + with name "chroot_deny_unix" is created.
52362 +
52363 +config GRKERNSEC_CHROOT_FINDTASK
52364 + bool "Protect outside processes"
52365 + default y if GRKERNSEC_CONFIG_AUTO
52366 + depends on GRKERNSEC_CHROOT
52367 + help
52368 + If you say Y here, processes inside a chroot will not be able to
52369 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
52370 + getsid, or view any process outside of the chroot. If the sysctl
52371 + option is enabled, a sysctl option with name "chroot_findtask" is
52372 + created.
52373 +
52374 +config GRKERNSEC_CHROOT_NICE
52375 + bool "Restrict priority changes"
52376 + default y if GRKERNSEC_CONFIG_AUTO
52377 + depends on GRKERNSEC_CHROOT
52378 + help
52379 + If you say Y here, processes inside a chroot will not be able to raise
52380 + the priority of processes in the chroot, or alter the priority of
52381 + processes outside the chroot. This provides more security than simply
52382 + removing CAP_SYS_NICE from the process' capability set. If the
52383 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
52384 + is created.
52385 +
52386 +config GRKERNSEC_CHROOT_SYSCTL
52387 + bool "Deny sysctl writes"
52388 + default y if GRKERNSEC_CONFIG_AUTO
52389 + depends on GRKERNSEC_CHROOT
52390 + help
52391 + If you say Y here, an attacker in a chroot will not be able to
52392 + write to sysctl entries, either by sysctl(2) or through a /proc
52393 + interface. It is strongly recommended that you say Y here. If the
52394 + sysctl option is enabled, a sysctl option with name
52395 + "chroot_deny_sysctl" is created.
52396 +
52397 +config GRKERNSEC_CHROOT_CAPS
52398 + bool "Capability restrictions"
52399 + default y if GRKERNSEC_CONFIG_AUTO
52400 + depends on GRKERNSEC_CHROOT
52401 + help
52402 + If you say Y here, the capabilities on all processes within a
52403 + chroot jail will be lowered to stop module insertion, raw i/o,
52404 + system and net admin tasks, rebooting the system, modifying immutable
52405 + files, modifying IPC owned by another, and changing the system time.
52406 + This is left an option because it can break some apps. Disable this
52407 + if your chrooted apps are having problems performing those kinds of
52408 + tasks. If the sysctl option is enabled, a sysctl option with
52409 + name "chroot_caps" is created.
52410 +
52411 +endmenu
52412 +menu "Kernel Auditing"
52413 +depends on GRKERNSEC
52414 +
52415 +config GRKERNSEC_AUDIT_GROUP
52416 + bool "Single group for auditing"
52417 + help
52418 + If you say Y here, the exec, chdir, and (un)mount logging features
52419 + will only operate on a group you specify. This option is recommended
52420 + if you only want to watch certain users instead of having a large
52421 + amount of logs from the entire system. If the sysctl option is enabled,
52422 + a sysctl option with name "audit_group" is created.
52423 +
52424 +config GRKERNSEC_AUDIT_GID
52425 + int "GID for auditing"
52426 + depends on GRKERNSEC_AUDIT_GROUP
52427 + default 1007
52428 +
52429 +config GRKERNSEC_EXECLOG
52430 + bool "Exec logging"
52431 + help
52432 + If you say Y here, all execve() calls will be logged (since the
52433 + other exec*() calls are frontends to execve(), all execution
52434 + will be logged). Useful for shell-servers that like to keep track
52435 + of their users. If the sysctl option is enabled, a sysctl option with
52436 + name "exec_logging" is created.
52437 + WARNING: This option when enabled will produce a LOT of logs, especially
52438 + on an active system.
52439 +
52440 +config GRKERNSEC_RESLOG
52441 + bool "Resource logging"
52442 + default y if GRKERNSEC_CONFIG_AUTO
52443 + help
52444 + If you say Y here, all attempts to overstep resource limits will
52445 + be logged with the resource name, the requested size, and the current
52446 + limit. It is highly recommended that you say Y here. If the sysctl
52447 + option is enabled, a sysctl option with name "resource_logging" is
52448 + created. If the RBAC system is enabled, the sysctl value is ignored.
52449 +
52450 +config GRKERNSEC_CHROOT_EXECLOG
52451 + bool "Log execs within chroot"
52452 + help
52453 + If you say Y here, all executions inside a chroot jail will be logged
52454 + to syslog. This can cause a large amount of logs if certain
52455 + applications (eg. djb's daemontools) are installed on the system, and
52456 + is therefore left as an option. If the sysctl option is enabled, a
52457 + sysctl option with name "chroot_execlog" is created.
52458 +
52459 +config GRKERNSEC_AUDIT_PTRACE
52460 + bool "Ptrace logging"
52461 + help
52462 + If you say Y here, all attempts to attach to a process via ptrace
52463 + will be logged. If the sysctl option is enabled, a sysctl option
52464 + with name "audit_ptrace" is created.
52465 +
52466 +config GRKERNSEC_AUDIT_CHDIR
52467 + bool "Chdir logging"
52468 + help
52469 + If you say Y here, all chdir() calls will be logged. If the sysctl
52470 + option is enabled, a sysctl option with name "audit_chdir" is created.
52471 +
52472 +config GRKERNSEC_AUDIT_MOUNT
52473 + bool "(Un)Mount logging"
52474 + help
52475 + If you say Y here, all mounts and unmounts will be logged. If the
52476 + sysctl option is enabled, a sysctl option with name "audit_mount" is
52477 + created.
52478 +
52479 +config GRKERNSEC_SIGNAL
52480 + bool "Signal logging"
52481 + default y if GRKERNSEC_CONFIG_AUTO
52482 + help
52483 + If you say Y here, certain important signals will be logged, such as
52484 + SIGSEGV, which will as a result inform you of when a error in a program
52485 + occurred, which in some cases could mean a possible exploit attempt.
52486 + If the sysctl option is enabled, a sysctl option with name
52487 + "signal_logging" is created.
52488 +
52489 +config GRKERNSEC_FORKFAIL
52490 + bool "Fork failure logging"
52491 + help
52492 + If you say Y here, all failed fork() attempts will be logged.
52493 + This could suggest a fork bomb, or someone attempting to overstep
52494 + their process limit. If the sysctl option is enabled, a sysctl option
52495 + with name "forkfail_logging" is created.
52496 +
52497 +config GRKERNSEC_TIME
52498 + bool "Time change logging"
52499 + default y if GRKERNSEC_CONFIG_AUTO
52500 + help
52501 + If you say Y here, any changes of the system clock will be logged.
52502 + If the sysctl option is enabled, a sysctl option with name
52503 + "timechange_logging" is created.
52504 +
52505 +config GRKERNSEC_PROC_IPADDR
52506 + bool "/proc/<pid>/ipaddr support"
52507 + default y if GRKERNSEC_CONFIG_AUTO
52508 + help
52509 + If you say Y here, a new entry will be added to each /proc/<pid>
52510 + directory that contains the IP address of the person using the task.
52511 + The IP is carried across local TCP and AF_UNIX stream sockets.
52512 + This information can be useful for IDS/IPSes to perform remote response
52513 + to a local attack. The entry is readable by only the owner of the
52514 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
52515 + the RBAC system), and thus does not create privacy concerns.
52516 +
52517 +config GRKERNSEC_RWXMAP_LOG
52518 + bool 'Denied RWX mmap/mprotect logging'
52519 + default y if GRKERNSEC_CONFIG_AUTO
52520 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
52521 + help
52522 + If you say Y here, calls to mmap() and mprotect() with explicit
52523 + usage of PROT_WRITE and PROT_EXEC together will be logged when
52524 + denied by the PAX_MPROTECT feature. If the sysctl option is
52525 + enabled, a sysctl option with name "rwxmap_logging" is created.
52526 +
52527 +config GRKERNSEC_AUDIT_TEXTREL
52528 + bool 'ELF text relocations logging (READ HELP)'
52529 + depends on PAX_MPROTECT
52530 + help
52531 + If you say Y here, text relocations will be logged with the filename
52532 + of the offending library or binary. The purpose of the feature is
52533 + to help Linux distribution developers get rid of libraries and
52534 + binaries that need text relocations which hinder the future progress
52535 + of PaX. Only Linux distribution developers should say Y here, and
52536 + never on a production machine, as this option creates an information
52537 + leak that could aid an attacker in defeating the randomization of
52538 + a single memory region. If the sysctl option is enabled, a sysctl
52539 + option with name "audit_textrel" is created.
52540 +
52541 +endmenu
52542 +
52543 +menu "Executable Protections"
52544 +depends on GRKERNSEC
52545 +
52546 +config GRKERNSEC_DMESG
52547 + bool "Dmesg(8) restriction"
52548 + default y if GRKERNSEC_CONFIG_AUTO
52549 + help
52550 + If you say Y here, non-root users will not be able to use dmesg(8)
52551 + to view the contents of the kernel's circular log buffer.
52552 + The kernel's log buffer often contains kernel addresses and other
52553 + identifying information useful to an attacker in fingerprinting a
52554 + system for a targeted exploit.
52555 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
52556 + created.
52557 +
52558 +config GRKERNSEC_HARDEN_PTRACE
52559 + bool "Deter ptrace-based process snooping"
52560 + default y if GRKERNSEC_CONFIG_AUTO
52561 + help
52562 + If you say Y here, TTY sniffers and other malicious monitoring
52563 + programs implemented through ptrace will be defeated. If you
52564 + have been using the RBAC system, this option has already been
52565 + enabled for several years for all users, with the ability to make
52566 + fine-grained exceptions.
52567 +
52568 + This option only affects the ability of non-root users to ptrace
52569 + processes that are not a descendent of the ptracing process.
52570 + This means that strace ./binary and gdb ./binary will still work,
52571 + but attaching to arbitrary processes will not. If the sysctl
52572 + option is enabled, a sysctl option with name "harden_ptrace" is
52573 + created.
52574 +
52575 +config GRKERNSEC_PTRACE_READEXEC
52576 + bool "Require read access to ptrace sensitive binaries"
52577 + default y if GRKERNSEC_CONFIG_AUTO
52578 + help
52579 + If you say Y here, unprivileged users will not be able to ptrace unreadable
52580 + binaries. This option is useful in environments that
52581 + remove the read bits (e.g. file mode 4711) from suid binaries to
52582 + prevent infoleaking of their contents. This option adds
52583 + consistency to the use of that file mode, as the binary could normally
52584 + be read out when run without privileges while ptracing.
52585 +
52586 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
52587 + is created.
52588 +
52589 +config GRKERNSEC_SETXID
52590 + bool "Enforce consistent multithreaded privileges"
52591 + default y if GRKERNSEC_CONFIG_AUTO
52592 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
52593 + help
52594 + If you say Y here, a change from a root uid to a non-root uid
52595 + in a multithreaded application will cause the resulting uids,
52596 + gids, supplementary groups, and capabilities in that thread
52597 + to be propagated to the other threads of the process. In most
52598 + cases this is unnecessary, as glibc will emulate this behavior
52599 + on behalf of the application. Other libcs do not act in the
52600 + same way, allowing the other threads of the process to continue
52601 + running with root privileges. If the sysctl option is enabled,
52602 + a sysctl option with name "consistent_setxid" is created.
52603 +
52604 +config GRKERNSEC_TPE
52605 + bool "Trusted Path Execution (TPE)"
52606 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52607 + help
52608 + If you say Y here, you will be able to choose a gid to add to the
52609 + supplementary groups of users you want to mark as "untrusted."
52610 + These users will not be able to execute any files that are not in
52611 + root-owned directories writable only by root. If the sysctl option
52612 + is enabled, a sysctl option with name "tpe" is created.
52613 +
52614 +config GRKERNSEC_TPE_ALL
52615 + bool "Partially restrict all non-root users"
52616 + depends on GRKERNSEC_TPE
52617 + help
52618 + If you say Y here, all non-root users will be covered under
52619 + a weaker TPE restriction. This is separate from, and in addition to,
52620 + the main TPE options that you have selected elsewhere. Thus, if a
52621 + "trusted" GID is chosen, this restriction applies to even that GID.
52622 + Under this restriction, all non-root users will only be allowed to
52623 + execute files in directories they own that are not group or
52624 + world-writable, or in directories owned by root and writable only by
52625 + root. If the sysctl option is enabled, a sysctl option with name
52626 + "tpe_restrict_all" is created.
52627 +
52628 +config GRKERNSEC_TPE_INVERT
52629 + bool "Invert GID option"
52630 + depends on GRKERNSEC_TPE
52631 + help
52632 + If you say Y here, the group you specify in the TPE configuration will
52633 + decide what group TPE restrictions will be *disabled* for. This
52634 + option is useful if you want TPE restrictions to be applied to most
52635 + users on the system. If the sysctl option is enabled, a sysctl option
52636 + with name "tpe_invert" is created. Unlike other sysctl options, this
52637 + entry will default to on for backward-compatibility.
52638 +
52639 +config GRKERNSEC_TPE_GID
52640 + int
52641 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
52642 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
52643 +
52644 +config GRKERNSEC_TPE_UNTRUSTED_GID
52645 + int "GID for TPE-untrusted users"
52646 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
52647 + default 1005
52648 + help
52649 + Setting this GID determines what group TPE restrictions will be
52650 + *enabled* for. If the sysctl option is enabled, a sysctl option
52651 + with name "tpe_gid" is created.
52652 +
52653 +config GRKERNSEC_TPE_TRUSTED_GID
52654 + int "GID for TPE-trusted users"
52655 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
52656 + default 1005
52657 + help
52658 + Setting this GID determines what group TPE restrictions will be
52659 + *disabled* for. If the sysctl option is enabled, a sysctl option
52660 + with name "tpe_gid" is created.
52661 +
52662 +endmenu
52663 +menu "Network Protections"
52664 +depends on GRKERNSEC
52665 +
52666 +config GRKERNSEC_RANDNET
52667 + bool "Larger entropy pools"
52668 + default y if GRKERNSEC_CONFIG_AUTO
52669 + help
52670 + If you say Y here, the entropy pools used for many features of Linux
52671 + and grsecurity will be doubled in size. Since several grsecurity
52672 + features use additional randomness, it is recommended that you say Y
52673 + here. Saying Y here has a similar effect as modifying
52674 + /proc/sys/kernel/random/poolsize.
52675 +
52676 +config GRKERNSEC_BLACKHOLE
52677 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
52678 + default y if GRKERNSEC_CONFIG_AUTO
52679 + depends on NET
52680 + help
52681 + If you say Y here, neither TCP resets nor ICMP
52682 + destination-unreachable packets will be sent in response to packets
52683 + sent to ports for which no associated listening process exists.
52684 + This feature supports both IPV4 and IPV6 and exempts the
52685 + loopback interface from blackholing. Enabling this feature
52686 + makes a host more resilient to DoS attacks and reduces network
52687 + visibility against scanners.
52688 +
52689 + The blackhole feature as-implemented is equivalent to the FreeBSD
52690 + blackhole feature, as it prevents RST responses to all packets, not
52691 + just SYNs. Under most application behavior this causes no
52692 + problems, but applications (like haproxy) may not close certain
52693 + connections in a way that cleanly terminates them on the remote
52694 + end, leaving the remote host in LAST_ACK state. Because of this
52695 + side-effect and to prevent intentional LAST_ACK DoSes, this
52696 + feature also adds automatic mitigation against such attacks.
52697 + The mitigation drastically reduces the amount of time a socket
52698 + can spend in LAST_ACK state. If you're using haproxy and not
52699 + all servers it connects to have this option enabled, consider
52700 + disabling this feature on the haproxy host.
52701 +
52702 + If the sysctl option is enabled, two sysctl options with names
52703 + "ip_blackhole" and "lastack_retries" will be created.
52704 + While "ip_blackhole" takes the standard zero/non-zero on/off
52705 + toggle, "lastack_retries" uses the same kinds of values as
52706 + "tcp_retries1" and "tcp_retries2". The default value of 4
52707 + prevents a socket from lasting more than 45 seconds in LAST_ACK
52708 + state.
52709 +
52710 +config GRKERNSEC_NO_SIMULT_CONNECT
52711 + bool "Disable TCP Simultaneous Connect"
52712 + default y if GRKERNSEC_CONFIG_AUTO
52713 + depends on NET
52714 + help
52715 + If you say Y here, a feature by Willy Tarreau will be enabled that
52716 + removes a weakness in Linux's strict implementation of TCP that
52717 + allows two clients to connect to each other without either entering
52718 + a listening state. The weakness allows an attacker to easily prevent
52719 + a client from connecting to a known server provided the source port
52720 + for the connection is guessed correctly.
52721 +
52722 + As the weakness could be used to prevent an antivirus or IPS from
52723 + fetching updates, or prevent an SSL gateway from fetching a CRL,
52724 + it should be eliminated by enabling this option. Though Linux is
52725 + one of few operating systems supporting simultaneous connect, it
52726 + has no legitimate use in practice and is rarely supported by firewalls.
52727 +
52728 +config GRKERNSEC_SOCKET
52729 + bool "Socket restrictions"
52730 + depends on NET
52731 + help
52732 + If you say Y here, you will be able to choose from several options.
52733 + If you assign a GID on your system and add it to the supplementary
52734 + groups of users you want to restrict socket access to, this patch
52735 + will perform up to three things, based on the option(s) you choose.
52736 +
52737 +config GRKERNSEC_SOCKET_ALL
52738 + bool "Deny any sockets to group"
52739 + depends on GRKERNSEC_SOCKET
52740 + help
52741 + If you say Y here, you will be able to choose a GID of whose users will
52742 + be unable to connect to other hosts from your machine or run server
52743 + applications from your machine. If the sysctl option is enabled, a
52744 + sysctl option with name "socket_all" is created.
52745 +
52746 +config GRKERNSEC_SOCKET_ALL_GID
52747 + int "GID to deny all sockets for"
52748 + depends on GRKERNSEC_SOCKET_ALL
52749 + default 1004
52750 + help
52751 + Here you can choose the GID to disable socket access for. Remember to
52752 + add the users you want socket access disabled for to the GID
52753 + specified here. If the sysctl option is enabled, a sysctl option
52754 + with name "socket_all_gid" is created.
52755 +
52756 +config GRKERNSEC_SOCKET_CLIENT
52757 + bool "Deny client sockets to group"
52758 + depends on GRKERNSEC_SOCKET
52759 + help
52760 + If you say Y here, you will be able to choose a GID of whose users will
52761 + be unable to connect to other hosts from your machine, but will be
52762 + able to run servers. If this option is enabled, all users in the group
52763 + you specify will have to use passive mode when initiating ftp transfers
52764 + from the shell on your machine. If the sysctl option is enabled, a
52765 + sysctl option with name "socket_client" is created.
52766 +
52767 +config GRKERNSEC_SOCKET_CLIENT_GID
52768 + int "GID to deny client sockets for"
52769 + depends on GRKERNSEC_SOCKET_CLIENT
52770 + default 1003
52771 + help
52772 + Here you can choose the GID to disable client socket access for.
52773 + Remember to add the users you want client socket access disabled for to
52774 + the GID specified here. If the sysctl option is enabled, a sysctl
52775 + option with name "socket_client_gid" is created.
52776 +
52777 +config GRKERNSEC_SOCKET_SERVER
52778 + bool "Deny server sockets to group"
52779 + depends on GRKERNSEC_SOCKET
52780 + help
52781 + If you say Y here, you will be able to choose a GID of whose users will
52782 + be unable to run server applications from your machine. If the sysctl
52783 + option is enabled, a sysctl option with name "socket_server" is created.
52784 +
52785 +config GRKERNSEC_SOCKET_SERVER_GID
52786 + int "GID to deny server sockets for"
52787 + depends on GRKERNSEC_SOCKET_SERVER
52788 + default 1002
52789 + help
52790 + Here you can choose the GID to disable server socket access for.
52791 + Remember to add the users you want server socket access disabled for to
52792 + the GID specified here. If the sysctl option is enabled, a sysctl
52793 + option with name "socket_server_gid" is created.
52794 +
52795 +endmenu
52796 +menu "Sysctl Support"
52797 +depends on GRKERNSEC && SYSCTL
52798 +
52799 +config GRKERNSEC_SYSCTL
52800 + bool "Sysctl support"
52801 + default y if GRKERNSEC_CONFIG_AUTO
52802 + help
52803 + If you say Y here, you will be able to change the options that
52804 + grsecurity runs with at bootup, without having to recompile your
52805 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
52806 + to enable (1) or disable (0) various features. All the sysctl entries
52807 + are mutable until the "grsec_lock" entry is set to a non-zero value.
52808 + All features enabled in the kernel configuration are disabled at boot
52809 + if you do not say Y to the "Turn on features by default" option.
52810 + All options should be set at startup, and the grsec_lock entry should
52811 + be set to a non-zero value after all the options are set.
52812 + *THIS IS EXTREMELY IMPORTANT*
52813 +
52814 +config GRKERNSEC_SYSCTL_DISTRO
52815 + bool "Extra sysctl support for distro makers (READ HELP)"
52816 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
52817 + help
52818 + If you say Y here, additional sysctl options will be created
52819 + for features that affect processes running as root. Therefore,
52820 + it is critical when using this option that the grsec_lock entry be
52821 + enabled after boot. Only distros with prebuilt kernel packages
52822 + with this option enabled that can ensure grsec_lock is enabled
52823 + after boot should use this option.
52824 + *Failure to set grsec_lock after boot makes all grsec features
52825 + this option covers useless*
52826 +
52827 + Currently this option creates the following sysctl entries:
52828 + "Disable Privileged I/O": "disable_priv_io"
52829 +
52830 +config GRKERNSEC_SYSCTL_ON
52831 + bool "Turn on features by default"
52832 + default y if GRKERNSEC_CONFIG_AUTO
52833 + depends on GRKERNSEC_SYSCTL
52834 + help
52835 + If you say Y here, instead of having all features enabled in the
52836 + kernel configuration disabled at boot time, the features will be
52837 + enabled at boot time. It is recommended you say Y here unless
52838 + there is some reason you would want all sysctl-tunable features to
52839 + be disabled by default. As mentioned elsewhere, it is important
52840 + to enable the grsec_lock entry once you have finished modifying
52841 + the sysctl entries.
52842 +
52843 +endmenu
52844 +menu "Logging Options"
52845 +depends on GRKERNSEC
52846 +
52847 +config GRKERNSEC_FLOODTIME
52848 + int "Seconds in between log messages (minimum)"
52849 + default 10
52850 + help
52851 + This option allows you to enforce the number of seconds between
52852 + grsecurity log messages. The default should be suitable for most
52853 + people, however, if you choose to change it, choose a value small enough
52854 + to allow informative logs to be produced, but large enough to
52855 + prevent flooding.
52856 +
52857 +config GRKERNSEC_FLOODBURST
52858 + int "Number of messages in a burst (maximum)"
52859 + default 6
52860 + help
52861 + This option allows you to choose the maximum number of messages allowed
52862 + within the flood time interval you chose in a separate option. The
52863 + default should be suitable for most people, however if you find that
52864 + many of your logs are being interpreted as flooding, you may want to
52865 + raise this value.
52866 +
52867 +endmenu
52868 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
52869 new file mode 100644
52870 index 0000000..1b9afa9
52871 --- /dev/null
52872 +++ b/grsecurity/Makefile
52873 @@ -0,0 +1,38 @@
52874 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
52875 +# during 2001-2009 it has been completely redesigned by Brad Spengler
52876 +# into an RBAC system
52877 +#
52878 +# All code in this directory and various hooks inserted throughout the kernel
52879 +# are copyright Brad Spengler - Open Source Security, Inc., and released
52880 +# under the GPL v2 or higher
52881 +
52882 +KBUILD_CFLAGS += -Werror
52883 +
52884 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
52885 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
52886 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
52887 +
52888 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
52889 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
52890 + gracl_learn.o grsec_log.o
52891 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
52892 +
52893 +ifdef CONFIG_NET
52894 +obj-y += grsec_sock.o
52895 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
52896 +endif
52897 +
52898 +ifndef CONFIG_GRKERNSEC
52899 +obj-y += grsec_disabled.o
52900 +endif
52901 +
52902 +ifdef CONFIG_GRKERNSEC_HIDESYM
52903 +extra-y := grsec_hidesym.o
52904 +$(obj)/grsec_hidesym.o:
52905 + @-chmod -f 500 /boot
52906 + @-chmod -f 500 /lib/modules
52907 + @-chmod -f 500 /lib64/modules
52908 + @-chmod -f 500 /lib32/modules
52909 + @-chmod -f 700 .
52910 + @echo ' grsec: protected kernel image paths'
52911 +endif
52912 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
52913 new file mode 100644
52914 index 0000000..78353bd
52915 --- /dev/null
52916 +++ b/grsecurity/gracl.c
52917 @@ -0,0 +1,4039 @@
52918 +#include <linux/kernel.h>
52919 +#include <linux/module.h>
52920 +#include <linux/sched.h>
52921 +#include <linux/mm.h>
52922 +#include <linux/file.h>
52923 +#include <linux/fs.h>
52924 +#include <linux/namei.h>
52925 +#include <linux/mount.h>
52926 +#include <linux/tty.h>
52927 +#include <linux/proc_fs.h>
52928 +#include <linux/lglock.h>
52929 +#include <linux/slab.h>
52930 +#include <linux/vmalloc.h>
52931 +#include <linux/types.h>
52932 +#include <linux/sysctl.h>
52933 +#include <linux/netdevice.h>
52934 +#include <linux/ptrace.h>
52935 +#include <linux/gracl.h>
52936 +#include <linux/gralloc.h>
52937 +#include <linux/security.h>
52938 +#include <linux/grinternal.h>
52939 +#include <linux/pid_namespace.h>
52940 +#include <linux/stop_machine.h>
52941 +#include <linux/fdtable.h>
52942 +#include <linux/percpu.h>
52943 +#include <linux/lglock.h>
52944 +#include "../fs/mount.h"
52945 +
52946 +#include <asm/uaccess.h>
52947 +#include <asm/errno.h>
52948 +#include <asm/mman.h>
52949 +
52950 +extern struct lglock vfsmount_lock;
52951 +
52952 +static struct acl_role_db acl_role_set;
52953 +static struct name_db name_set;
52954 +static struct inodev_db inodev_set;
52955 +
52956 +/* for keeping track of userspace pointers used for subjects, so we
52957 + can share references in the kernel as well
52958 +*/
52959 +
52960 +static struct path real_root;
52961 +
52962 +static struct acl_subj_map_db subj_map_set;
52963 +
52964 +static struct acl_role_label *default_role;
52965 +
52966 +static struct acl_role_label *role_list;
52967 +
52968 +static u16 acl_sp_role_value;
52969 +
52970 +extern char *gr_shared_page[4];
52971 +static DEFINE_MUTEX(gr_dev_mutex);
52972 +DEFINE_RWLOCK(gr_inode_lock);
52973 +
52974 +struct gr_arg *gr_usermode;
52975 +
52976 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
52977 +
52978 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
52979 +extern void gr_clear_learn_entries(void);
52980 +
52981 +#ifdef CONFIG_GRKERNSEC_RESLOG
52982 +extern void gr_log_resource(const struct task_struct *task,
52983 + const int res, const unsigned long wanted, const int gt);
52984 +#endif
52985 +
52986 +unsigned char *gr_system_salt;
52987 +unsigned char *gr_system_sum;
52988 +
52989 +static struct sprole_pw **acl_special_roles = NULL;
52990 +static __u16 num_sprole_pws = 0;
52991 +
52992 +static struct acl_role_label *kernel_role = NULL;
52993 +
52994 +static unsigned int gr_auth_attempts = 0;
52995 +static unsigned long gr_auth_expires = 0UL;
52996 +
52997 +#ifdef CONFIG_NET
52998 +extern struct vfsmount *sock_mnt;
52999 +#endif
53000 +
53001 +extern struct vfsmount *pipe_mnt;
53002 +extern struct vfsmount *shm_mnt;
53003 +#ifdef CONFIG_HUGETLBFS
53004 +extern struct vfsmount *hugetlbfs_vfsmount;
53005 +#endif
53006 +
53007 +static struct acl_object_label *fakefs_obj_rw;
53008 +static struct acl_object_label *fakefs_obj_rwx;
53009 +
53010 +extern int gr_init_uidset(void);
53011 +extern void gr_free_uidset(void);
53012 +extern void gr_remove_uid(uid_t uid);
53013 +extern int gr_find_uid(uid_t uid);
53014 +
53015 +__inline__ int
53016 +gr_acl_is_enabled(void)
53017 +{
53018 + return (gr_status & GR_READY);
53019 +}
53020 +
53021 +#ifdef CONFIG_BTRFS_FS
53022 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53023 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53024 +#endif
53025 +
53026 +static inline dev_t __get_dev(const struct dentry *dentry)
53027 +{
53028 +#ifdef CONFIG_BTRFS_FS
53029 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53030 + return get_btrfs_dev_from_inode(dentry->d_inode);
53031 + else
53032 +#endif
53033 + return dentry->d_inode->i_sb->s_dev;
53034 +}
53035 +
53036 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53037 +{
53038 + return __get_dev(dentry);
53039 +}
53040 +
53041 +static char gr_task_roletype_to_char(struct task_struct *task)
53042 +{
53043 + switch (task->role->roletype &
53044 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53045 + GR_ROLE_SPECIAL)) {
53046 + case GR_ROLE_DEFAULT:
53047 + return 'D';
53048 + case GR_ROLE_USER:
53049 + return 'U';
53050 + case GR_ROLE_GROUP:
53051 + return 'G';
53052 + case GR_ROLE_SPECIAL:
53053 + return 'S';
53054 + }
53055 +
53056 + return 'X';
53057 +}
53058 +
53059 +char gr_roletype_to_char(void)
53060 +{
53061 + return gr_task_roletype_to_char(current);
53062 +}
53063 +
53064 +__inline__ int
53065 +gr_acl_tpe_check(void)
53066 +{
53067 + if (unlikely(!(gr_status & GR_READY)))
53068 + return 0;
53069 + if (current->role->roletype & GR_ROLE_TPE)
53070 + return 1;
53071 + else
53072 + return 0;
53073 +}
53074 +
53075 +int
53076 +gr_handle_rawio(const struct inode *inode)
53077 +{
53078 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53079 + if (inode && S_ISBLK(inode->i_mode) &&
53080 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53081 + !capable(CAP_SYS_RAWIO))
53082 + return 1;
53083 +#endif
53084 + return 0;
53085 +}
53086 +
53087 +static int
53088 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53089 +{
53090 + if (likely(lena != lenb))
53091 + return 0;
53092 +
53093 + return !memcmp(a, b, lena);
53094 +}
53095 +
53096 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53097 +{
53098 + *buflen -= namelen;
53099 + if (*buflen < 0)
53100 + return -ENAMETOOLONG;
53101 + *buffer -= namelen;
53102 + memcpy(*buffer, str, namelen);
53103 + return 0;
53104 +}
53105 +
53106 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53107 +{
53108 + return prepend(buffer, buflen, name->name, name->len);
53109 +}
53110 +
53111 +static int prepend_path(const struct path *path, struct path *root,
53112 + char **buffer, int *buflen)
53113 +{
53114 + struct dentry *dentry = path->dentry;
53115 + struct vfsmount *vfsmnt = path->mnt;
53116 + struct mount *mnt = real_mount(vfsmnt);
53117 + bool slash = false;
53118 + int error = 0;
53119 +
53120 + while (dentry != root->dentry || vfsmnt != root->mnt) {
53121 + struct dentry * parent;
53122 +
53123 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53124 + /* Global root? */
53125 + if (!mnt_has_parent(mnt)) {
53126 + goto out;
53127 + }
53128 + dentry = mnt->mnt_mountpoint;
53129 + mnt = mnt->mnt_parent;
53130 + vfsmnt = &mnt->mnt;
53131 + continue;
53132 + }
53133 + parent = dentry->d_parent;
53134 + prefetch(parent);
53135 + spin_lock(&dentry->d_lock);
53136 + error = prepend_name(buffer, buflen, &dentry->d_name);
53137 + spin_unlock(&dentry->d_lock);
53138 + if (!error)
53139 + error = prepend(buffer, buflen, "/", 1);
53140 + if (error)
53141 + break;
53142 +
53143 + slash = true;
53144 + dentry = parent;
53145 + }
53146 +
53147 +out:
53148 + if (!error && !slash)
53149 + error = prepend(buffer, buflen, "/", 1);
53150 +
53151 + return error;
53152 +}
53153 +
53154 +/* this must be called with vfsmount_lock and rename_lock held */
53155 +
53156 +static char *__our_d_path(const struct path *path, struct path *root,
53157 + char *buf, int buflen)
53158 +{
53159 + char *res = buf + buflen;
53160 + int error;
53161 +
53162 + prepend(&res, &buflen, "\0", 1);
53163 + error = prepend_path(path, root, &res, &buflen);
53164 + if (error)
53165 + return ERR_PTR(error);
53166 +
53167 + return res;
53168 +}
53169 +
53170 +static char *
53171 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53172 +{
53173 + char *retval;
53174 +
53175 + retval = __our_d_path(path, root, buf, buflen);
53176 + if (unlikely(IS_ERR(retval)))
53177 + retval = strcpy(buf, "<path too long>");
53178 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53179 + retval[1] = '\0';
53180 +
53181 + return retval;
53182 +}
53183 +
53184 +static char *
53185 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53186 + char *buf, int buflen)
53187 +{
53188 + struct path path;
53189 + char *res;
53190 +
53191 + path.dentry = (struct dentry *)dentry;
53192 + path.mnt = (struct vfsmount *)vfsmnt;
53193 +
53194 + /* we can use real_root.dentry, real_root.mnt, because this is only called
53195 + by the RBAC system */
53196 + res = gen_full_path(&path, &real_root, buf, buflen);
53197 +
53198 + return res;
53199 +}
53200 +
53201 +static char *
53202 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53203 + char *buf, int buflen)
53204 +{
53205 + char *res;
53206 + struct path path;
53207 + struct path root;
53208 + struct task_struct *reaper = init_pid_ns.child_reaper;
53209 +
53210 + path.dentry = (struct dentry *)dentry;
53211 + path.mnt = (struct vfsmount *)vfsmnt;
53212 +
53213 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53214 + get_fs_root(reaper->fs, &root);
53215 +
53216 + write_seqlock(&rename_lock);
53217 + br_read_lock(&vfsmount_lock);
53218 + res = gen_full_path(&path, &root, buf, buflen);
53219 + br_read_unlock(&vfsmount_lock);
53220 + write_sequnlock(&rename_lock);
53221 +
53222 + path_put(&root);
53223 + return res;
53224 +}
53225 +
53226 +static char *
53227 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53228 +{
53229 + char *ret;
53230 + write_seqlock(&rename_lock);
53231 + br_read_lock(&vfsmount_lock);
53232 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53233 + PAGE_SIZE);
53234 + br_read_unlock(&vfsmount_lock);
53235 + write_sequnlock(&rename_lock);
53236 + return ret;
53237 +}
53238 +
53239 +static char *
53240 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53241 +{
53242 + char *ret;
53243 + char *buf;
53244 + int buflen;
53245 +
53246 + write_seqlock(&rename_lock);
53247 + br_read_lock(&vfsmount_lock);
53248 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53249 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
53250 + buflen = (int)(ret - buf);
53251 + if (buflen >= 5)
53252 + prepend(&ret, &buflen, "/proc", 5);
53253 + else
53254 + ret = strcpy(buf, "<path too long>");
53255 + br_read_unlock(&vfsmount_lock);
53256 + write_sequnlock(&rename_lock);
53257 + return ret;
53258 +}
53259 +
53260 +char *
53261 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
53262 +{
53263 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53264 + PAGE_SIZE);
53265 +}
53266 +
53267 +char *
53268 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
53269 +{
53270 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53271 + PAGE_SIZE);
53272 +}
53273 +
53274 +char *
53275 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
53276 +{
53277 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
53278 + PAGE_SIZE);
53279 +}
53280 +
53281 +char *
53282 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
53283 +{
53284 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
53285 + PAGE_SIZE);
53286 +}
53287 +
53288 +char *
53289 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
53290 +{
53291 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
53292 + PAGE_SIZE);
53293 +}
53294 +
53295 +__inline__ __u32
53296 +to_gr_audit(const __u32 reqmode)
53297 +{
53298 + /* masks off auditable permission flags, then shifts them to create
53299 + auditing flags, and adds the special case of append auditing if
53300 + we're requesting write */
53301 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
53302 +}
53303 +
53304 +struct acl_subject_label *
53305 +lookup_subject_map(const struct acl_subject_label *userp)
53306 +{
53307 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
53308 + struct subject_map *match;
53309 +
53310 + match = subj_map_set.s_hash[index];
53311 +
53312 + while (match && match->user != userp)
53313 + match = match->next;
53314 +
53315 + if (match != NULL)
53316 + return match->kernel;
53317 + else
53318 + return NULL;
53319 +}
53320 +
53321 +static void
53322 +insert_subj_map_entry(struct subject_map *subjmap)
53323 +{
53324 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
53325 + struct subject_map **curr;
53326 +
53327 + subjmap->prev = NULL;
53328 +
53329 + curr = &subj_map_set.s_hash[index];
53330 + if (*curr != NULL)
53331 + (*curr)->prev = subjmap;
53332 +
53333 + subjmap->next = *curr;
53334 + *curr = subjmap;
53335 +
53336 + return;
53337 +}
53338 +
53339 +static struct acl_role_label *
53340 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
53341 + const gid_t gid)
53342 +{
53343 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
53344 + struct acl_role_label *match;
53345 + struct role_allowed_ip *ipp;
53346 + unsigned int x;
53347 + u32 curr_ip = task->signal->curr_ip;
53348 +
53349 + task->signal->saved_ip = curr_ip;
53350 +
53351 + match = acl_role_set.r_hash[index];
53352 +
53353 + while (match) {
53354 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
53355 + for (x = 0; x < match->domain_child_num; x++) {
53356 + if (match->domain_children[x] == uid)
53357 + goto found;
53358 + }
53359 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
53360 + break;
53361 + match = match->next;
53362 + }
53363 +found:
53364 + if (match == NULL) {
53365 + try_group:
53366 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
53367 + match = acl_role_set.r_hash[index];
53368 +
53369 + while (match) {
53370 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
53371 + for (x = 0; x < match->domain_child_num; x++) {
53372 + if (match->domain_children[x] == gid)
53373 + goto found2;
53374 + }
53375 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
53376 + break;
53377 + match = match->next;
53378 + }
53379 +found2:
53380 + if (match == NULL)
53381 + match = default_role;
53382 + if (match->allowed_ips == NULL)
53383 + return match;
53384 + else {
53385 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53386 + if (likely
53387 + ((ntohl(curr_ip) & ipp->netmask) ==
53388 + (ntohl(ipp->addr) & ipp->netmask)))
53389 + return match;
53390 + }
53391 + match = default_role;
53392 + }
53393 + } else if (match->allowed_ips == NULL) {
53394 + return match;
53395 + } else {
53396 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53397 + if (likely
53398 + ((ntohl(curr_ip) & ipp->netmask) ==
53399 + (ntohl(ipp->addr) & ipp->netmask)))
53400 + return match;
53401 + }
53402 + goto try_group;
53403 + }
53404 +
53405 + return match;
53406 +}
53407 +
53408 +struct acl_subject_label *
53409 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
53410 + const struct acl_role_label *role)
53411 +{
53412 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53413 + struct acl_subject_label *match;
53414 +
53415 + match = role->subj_hash[index];
53416 +
53417 + while (match && (match->inode != ino || match->device != dev ||
53418 + (match->mode & GR_DELETED))) {
53419 + match = match->next;
53420 + }
53421 +
53422 + if (match && !(match->mode & GR_DELETED))
53423 + return match;
53424 + else
53425 + return NULL;
53426 +}
53427 +
53428 +struct acl_subject_label *
53429 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
53430 + const struct acl_role_label *role)
53431 +{
53432 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53433 + struct acl_subject_label *match;
53434 +
53435 + match = role->subj_hash[index];
53436 +
53437 + while (match && (match->inode != ino || match->device != dev ||
53438 + !(match->mode & GR_DELETED))) {
53439 + match = match->next;
53440 + }
53441 +
53442 + if (match && (match->mode & GR_DELETED))
53443 + return match;
53444 + else
53445 + return NULL;
53446 +}
53447 +
53448 +static struct acl_object_label *
53449 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
53450 + const struct acl_subject_label *subj)
53451 +{
53452 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53453 + struct acl_object_label *match;
53454 +
53455 + match = subj->obj_hash[index];
53456 +
53457 + while (match && (match->inode != ino || match->device != dev ||
53458 + (match->mode & GR_DELETED))) {
53459 + match = match->next;
53460 + }
53461 +
53462 + if (match && !(match->mode & GR_DELETED))
53463 + return match;
53464 + else
53465 + return NULL;
53466 +}
53467 +
53468 +static struct acl_object_label *
53469 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
53470 + const struct acl_subject_label *subj)
53471 +{
53472 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53473 + struct acl_object_label *match;
53474 +
53475 + match = subj->obj_hash[index];
53476 +
53477 + while (match && (match->inode != ino || match->device != dev ||
53478 + !(match->mode & GR_DELETED))) {
53479 + match = match->next;
53480 + }
53481 +
53482 + if (match && (match->mode & GR_DELETED))
53483 + return match;
53484 +
53485 + match = subj->obj_hash[index];
53486 +
53487 + while (match && (match->inode != ino || match->device != dev ||
53488 + (match->mode & GR_DELETED))) {
53489 + match = match->next;
53490 + }
53491 +
53492 + if (match && !(match->mode & GR_DELETED))
53493 + return match;
53494 + else
53495 + return NULL;
53496 +}
53497 +
53498 +static struct name_entry *
53499 +lookup_name_entry(const char *name)
53500 +{
53501 + unsigned int len = strlen(name);
53502 + unsigned int key = full_name_hash(name, len);
53503 + unsigned int index = key % name_set.n_size;
53504 + struct name_entry *match;
53505 +
53506 + match = name_set.n_hash[index];
53507 +
53508 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
53509 + match = match->next;
53510 +
53511 + return match;
53512 +}
53513 +
53514 +static struct name_entry *
53515 +lookup_name_entry_create(const char *name)
53516 +{
53517 + unsigned int len = strlen(name);
53518 + unsigned int key = full_name_hash(name, len);
53519 + unsigned int index = key % name_set.n_size;
53520 + struct name_entry *match;
53521 +
53522 + match = name_set.n_hash[index];
53523 +
53524 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53525 + !match->deleted))
53526 + match = match->next;
53527 +
53528 + if (match && match->deleted)
53529 + return match;
53530 +
53531 + match = name_set.n_hash[index];
53532 +
53533 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53534 + match->deleted))
53535 + match = match->next;
53536 +
53537 + if (match && !match->deleted)
53538 + return match;
53539 + else
53540 + return NULL;
53541 +}
53542 +
53543 +static struct inodev_entry *
53544 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
53545 +{
53546 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
53547 + struct inodev_entry *match;
53548 +
53549 + match = inodev_set.i_hash[index];
53550 +
53551 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
53552 + match = match->next;
53553 +
53554 + return match;
53555 +}
53556 +
53557 +static void
53558 +insert_inodev_entry(struct inodev_entry *entry)
53559 +{
53560 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
53561 + inodev_set.i_size);
53562 + struct inodev_entry **curr;
53563 +
53564 + entry->prev = NULL;
53565 +
53566 + curr = &inodev_set.i_hash[index];
53567 + if (*curr != NULL)
53568 + (*curr)->prev = entry;
53569 +
53570 + entry->next = *curr;
53571 + *curr = entry;
53572 +
53573 + return;
53574 +}
53575 +
53576 +static void
53577 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
53578 +{
53579 + unsigned int index =
53580 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
53581 + struct acl_role_label **curr;
53582 + struct acl_role_label *tmp, *tmp2;
53583 +
53584 + curr = &acl_role_set.r_hash[index];
53585 +
53586 + /* simple case, slot is empty, just set it to our role */
53587 + if (*curr == NULL) {
53588 + *curr = role;
53589 + } else {
53590 + /* example:
53591 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
53592 + 2 -> 3
53593 + */
53594 + /* first check to see if we can already be reached via this slot */
53595 + tmp = *curr;
53596 + while (tmp && tmp != role)
53597 + tmp = tmp->next;
53598 + if (tmp == role) {
53599 + /* we don't need to add ourselves to this slot's chain */
53600 + return;
53601 + }
53602 + /* we need to add ourselves to this chain, two cases */
53603 + if (role->next == NULL) {
53604 + /* simple case, append the current chain to our role */
53605 + role->next = *curr;
53606 + *curr = role;
53607 + } else {
53608 + /* 1 -> 2 -> 3 -> 4
53609 + 2 -> 3 -> 4
53610 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
53611 + */
53612 + /* trickier case: walk our role's chain until we find
53613 + the role for the start of the current slot's chain */
53614 + tmp = role;
53615 + tmp2 = *curr;
53616 + while (tmp->next && tmp->next != tmp2)
53617 + tmp = tmp->next;
53618 + if (tmp->next == tmp2) {
53619 + /* from example above, we found 3, so just
53620 + replace this slot's chain with ours */
53621 + *curr = role;
53622 + } else {
53623 + /* we didn't find a subset of our role's chain
53624 + in the current slot's chain, so append their
53625 + chain to ours, and set us as the first role in
53626 + the slot's chain
53627 +
53628 + we could fold this case with the case above,
53629 + but making it explicit for clarity
53630 + */
53631 + tmp->next = tmp2;
53632 + *curr = role;
53633 + }
53634 + }
53635 + }
53636 +
53637 + return;
53638 +}
53639 +
53640 +static void
53641 +insert_acl_role_label(struct acl_role_label *role)
53642 +{
53643 + int i;
53644 +
53645 + if (role_list == NULL) {
53646 + role_list = role;
53647 + role->prev = NULL;
53648 + } else {
53649 + role->prev = role_list;
53650 + role_list = role;
53651 + }
53652 +
53653 + /* used for hash chains */
53654 + role->next = NULL;
53655 +
53656 + if (role->roletype & GR_ROLE_DOMAIN) {
53657 + for (i = 0; i < role->domain_child_num; i++)
53658 + __insert_acl_role_label(role, role->domain_children[i]);
53659 + } else
53660 + __insert_acl_role_label(role, role->uidgid);
53661 +}
53662 +
53663 +static int
53664 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
53665 +{
53666 + struct name_entry **curr, *nentry;
53667 + struct inodev_entry *ientry;
53668 + unsigned int len = strlen(name);
53669 + unsigned int key = full_name_hash(name, len);
53670 + unsigned int index = key % name_set.n_size;
53671 +
53672 + curr = &name_set.n_hash[index];
53673 +
53674 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
53675 + curr = &((*curr)->next);
53676 +
53677 + if (*curr != NULL)
53678 + return 1;
53679 +
53680 + nentry = acl_alloc(sizeof (struct name_entry));
53681 + if (nentry == NULL)
53682 + return 0;
53683 + ientry = acl_alloc(sizeof (struct inodev_entry));
53684 + if (ientry == NULL)
53685 + return 0;
53686 + ientry->nentry = nentry;
53687 +
53688 + nentry->key = key;
53689 + nentry->name = name;
53690 + nentry->inode = inode;
53691 + nentry->device = device;
53692 + nentry->len = len;
53693 + nentry->deleted = deleted;
53694 +
53695 + nentry->prev = NULL;
53696 + curr = &name_set.n_hash[index];
53697 + if (*curr != NULL)
53698 + (*curr)->prev = nentry;
53699 + nentry->next = *curr;
53700 + *curr = nentry;
53701 +
53702 + /* insert us into the table searchable by inode/dev */
53703 + insert_inodev_entry(ientry);
53704 +
53705 + return 1;
53706 +}
53707 +
53708 +static void
53709 +insert_acl_obj_label(struct acl_object_label *obj,
53710 + struct acl_subject_label *subj)
53711 +{
53712 + unsigned int index =
53713 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
53714 + struct acl_object_label **curr;
53715 +
53716 +
53717 + obj->prev = NULL;
53718 +
53719 + curr = &subj->obj_hash[index];
53720 + if (*curr != NULL)
53721 + (*curr)->prev = obj;
53722 +
53723 + obj->next = *curr;
53724 + *curr = obj;
53725 +
53726 + return;
53727 +}
53728 +
53729 +static void
53730 +insert_acl_subj_label(struct acl_subject_label *obj,
53731 + struct acl_role_label *role)
53732 +{
53733 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
53734 + struct acl_subject_label **curr;
53735 +
53736 + obj->prev = NULL;
53737 +
53738 + curr = &role->subj_hash[index];
53739 + if (*curr != NULL)
53740 + (*curr)->prev = obj;
53741 +
53742 + obj->next = *curr;
53743 + *curr = obj;
53744 +
53745 + return;
53746 +}
53747 +
53748 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
53749 +
53750 +static void *
53751 +create_table(__u32 * len, int elementsize)
53752 +{
53753 + unsigned int table_sizes[] = {
53754 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
53755 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
53756 + 4194301, 8388593, 16777213, 33554393, 67108859
53757 + };
53758 + void *newtable = NULL;
53759 + unsigned int pwr = 0;
53760 +
53761 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
53762 + table_sizes[pwr] <= *len)
53763 + pwr++;
53764 +
53765 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
53766 + return newtable;
53767 +
53768 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
53769 + newtable =
53770 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
53771 + else
53772 + newtable = vmalloc(table_sizes[pwr] * elementsize);
53773 +
53774 + *len = table_sizes[pwr];
53775 +
53776 + return newtable;
53777 +}
53778 +
53779 +static int
53780 +init_variables(const struct gr_arg *arg)
53781 +{
53782 + struct task_struct *reaper = init_pid_ns.child_reaper;
53783 + unsigned int stacksize;
53784 +
53785 + subj_map_set.s_size = arg->role_db.num_subjects;
53786 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
53787 + name_set.n_size = arg->role_db.num_objects;
53788 + inodev_set.i_size = arg->role_db.num_objects;
53789 +
53790 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
53791 + !name_set.n_size || !inodev_set.i_size)
53792 + return 1;
53793 +
53794 + if (!gr_init_uidset())
53795 + return 1;
53796 +
53797 + /* set up the stack that holds allocation info */
53798 +
53799 + stacksize = arg->role_db.num_pointers + 5;
53800 +
53801 + if (!acl_alloc_stack_init(stacksize))
53802 + return 1;
53803 +
53804 + /* grab reference for the real root dentry and vfsmount */
53805 + get_fs_root(reaper->fs, &real_root);
53806 +
53807 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53808 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
53809 +#endif
53810 +
53811 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
53812 + if (fakefs_obj_rw == NULL)
53813 + return 1;
53814 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
53815 +
53816 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
53817 + if (fakefs_obj_rwx == NULL)
53818 + return 1;
53819 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
53820 +
53821 + subj_map_set.s_hash =
53822 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
53823 + acl_role_set.r_hash =
53824 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
53825 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
53826 + inodev_set.i_hash =
53827 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
53828 +
53829 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
53830 + !name_set.n_hash || !inodev_set.i_hash)
53831 + return 1;
53832 +
53833 + memset(subj_map_set.s_hash, 0,
53834 + sizeof(struct subject_map *) * subj_map_set.s_size);
53835 + memset(acl_role_set.r_hash, 0,
53836 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
53837 + memset(name_set.n_hash, 0,
53838 + sizeof (struct name_entry *) * name_set.n_size);
53839 + memset(inodev_set.i_hash, 0,
53840 + sizeof (struct inodev_entry *) * inodev_set.i_size);
53841 +
53842 + return 0;
53843 +}
53844 +
53845 +/* free information not needed after startup
53846 + currently contains user->kernel pointer mappings for subjects
53847 +*/
53848 +
53849 +static void
53850 +free_init_variables(void)
53851 +{
53852 + __u32 i;
53853 +
53854 + if (subj_map_set.s_hash) {
53855 + for (i = 0; i < subj_map_set.s_size; i++) {
53856 + if (subj_map_set.s_hash[i]) {
53857 + kfree(subj_map_set.s_hash[i]);
53858 + subj_map_set.s_hash[i] = NULL;
53859 + }
53860 + }
53861 +
53862 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
53863 + PAGE_SIZE)
53864 + kfree(subj_map_set.s_hash);
53865 + else
53866 + vfree(subj_map_set.s_hash);
53867 + }
53868 +
53869 + return;
53870 +}
53871 +
53872 +static void
53873 +free_variables(void)
53874 +{
53875 + struct acl_subject_label *s;
53876 + struct acl_role_label *r;
53877 + struct task_struct *task, *task2;
53878 + unsigned int x;
53879 +
53880 + gr_clear_learn_entries();
53881 +
53882 + read_lock(&tasklist_lock);
53883 + do_each_thread(task2, task) {
53884 + task->acl_sp_role = 0;
53885 + task->acl_role_id = 0;
53886 + task->acl = NULL;
53887 + task->role = NULL;
53888 + } while_each_thread(task2, task);
53889 + read_unlock(&tasklist_lock);
53890 +
53891 + /* release the reference to the real root dentry and vfsmount */
53892 + path_put(&real_root);
53893 + memset(&real_root, 0, sizeof(real_root));
53894 +
53895 + /* free all object hash tables */
53896 +
53897 + FOR_EACH_ROLE_START(r)
53898 + if (r->subj_hash == NULL)
53899 + goto next_role;
53900 + FOR_EACH_SUBJECT_START(r, s, x)
53901 + if (s->obj_hash == NULL)
53902 + break;
53903 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53904 + kfree(s->obj_hash);
53905 + else
53906 + vfree(s->obj_hash);
53907 + FOR_EACH_SUBJECT_END(s, x)
53908 + FOR_EACH_NESTED_SUBJECT_START(r, s)
53909 + if (s->obj_hash == NULL)
53910 + break;
53911 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53912 + kfree(s->obj_hash);
53913 + else
53914 + vfree(s->obj_hash);
53915 + FOR_EACH_NESTED_SUBJECT_END(s)
53916 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
53917 + kfree(r->subj_hash);
53918 + else
53919 + vfree(r->subj_hash);
53920 + r->subj_hash = NULL;
53921 +next_role:
53922 + FOR_EACH_ROLE_END(r)
53923 +
53924 + acl_free_all();
53925 +
53926 + if (acl_role_set.r_hash) {
53927 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
53928 + PAGE_SIZE)
53929 + kfree(acl_role_set.r_hash);
53930 + else
53931 + vfree(acl_role_set.r_hash);
53932 + }
53933 + if (name_set.n_hash) {
53934 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
53935 + PAGE_SIZE)
53936 + kfree(name_set.n_hash);
53937 + else
53938 + vfree(name_set.n_hash);
53939 + }
53940 +
53941 + if (inodev_set.i_hash) {
53942 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
53943 + PAGE_SIZE)
53944 + kfree(inodev_set.i_hash);
53945 + else
53946 + vfree(inodev_set.i_hash);
53947 + }
53948 +
53949 + gr_free_uidset();
53950 +
53951 + memset(&name_set, 0, sizeof (struct name_db));
53952 + memset(&inodev_set, 0, sizeof (struct inodev_db));
53953 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
53954 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
53955 +
53956 + default_role = NULL;
53957 + kernel_role = NULL;
53958 + role_list = NULL;
53959 +
53960 + return;
53961 +}
53962 +
53963 +static __u32
53964 +count_user_objs(struct acl_object_label *userp)
53965 +{
53966 + struct acl_object_label o_tmp;
53967 + __u32 num = 0;
53968 +
53969 + while (userp) {
53970 + if (copy_from_user(&o_tmp, userp,
53971 + sizeof (struct acl_object_label)))
53972 + break;
53973 +
53974 + userp = o_tmp.prev;
53975 + num++;
53976 + }
53977 +
53978 + return num;
53979 +}
53980 +
53981 +static struct acl_subject_label *
53982 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
53983 +
53984 +static int
53985 +copy_user_glob(struct acl_object_label *obj)
53986 +{
53987 + struct acl_object_label *g_tmp, **guser;
53988 + unsigned int len;
53989 + char *tmp;
53990 +
53991 + if (obj->globbed == NULL)
53992 + return 0;
53993 +
53994 + guser = &obj->globbed;
53995 + while (*guser) {
53996 + g_tmp = (struct acl_object_label *)
53997 + acl_alloc(sizeof (struct acl_object_label));
53998 + if (g_tmp == NULL)
53999 + return -ENOMEM;
54000 +
54001 + if (copy_from_user(g_tmp, *guser,
54002 + sizeof (struct acl_object_label)))
54003 + return -EFAULT;
54004 +
54005 + len = strnlen_user(g_tmp->filename, PATH_MAX);
54006 +
54007 + if (!len || len >= PATH_MAX)
54008 + return -EINVAL;
54009 +
54010 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54011 + return -ENOMEM;
54012 +
54013 + if (copy_from_user(tmp, g_tmp->filename, len))
54014 + return -EFAULT;
54015 + tmp[len-1] = '\0';
54016 + g_tmp->filename = tmp;
54017 +
54018 + *guser = g_tmp;
54019 + guser = &(g_tmp->next);
54020 + }
54021 +
54022 + return 0;
54023 +}
54024 +
54025 +static int
54026 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54027 + struct acl_role_label *role)
54028 +{
54029 + struct acl_object_label *o_tmp;
54030 + unsigned int len;
54031 + int ret;
54032 + char *tmp;
54033 +
54034 + while (userp) {
54035 + if ((o_tmp = (struct acl_object_label *)
54036 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
54037 + return -ENOMEM;
54038 +
54039 + if (copy_from_user(o_tmp, userp,
54040 + sizeof (struct acl_object_label)))
54041 + return -EFAULT;
54042 +
54043 + userp = o_tmp->prev;
54044 +
54045 + len = strnlen_user(o_tmp->filename, PATH_MAX);
54046 +
54047 + if (!len || len >= PATH_MAX)
54048 + return -EINVAL;
54049 +
54050 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54051 + return -ENOMEM;
54052 +
54053 + if (copy_from_user(tmp, o_tmp->filename, len))
54054 + return -EFAULT;
54055 + tmp[len-1] = '\0';
54056 + o_tmp->filename = tmp;
54057 +
54058 + insert_acl_obj_label(o_tmp, subj);
54059 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54060 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54061 + return -ENOMEM;
54062 +
54063 + ret = copy_user_glob(o_tmp);
54064 + if (ret)
54065 + return ret;
54066 +
54067 + if (o_tmp->nested) {
54068 + int already_copied;
54069 +
54070 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54071 + if (IS_ERR(o_tmp->nested))
54072 + return PTR_ERR(o_tmp->nested);
54073 +
54074 + /* insert into nested subject list if we haven't copied this one yet
54075 + to prevent duplicate entries */
54076 + if (!already_copied) {
54077 + o_tmp->nested->next = role->hash->first;
54078 + role->hash->first = o_tmp->nested;
54079 + }
54080 + }
54081 + }
54082 +
54083 + return 0;
54084 +}
54085 +
54086 +static __u32
54087 +count_user_subjs(struct acl_subject_label *userp)
54088 +{
54089 + struct acl_subject_label s_tmp;
54090 + __u32 num = 0;
54091 +
54092 + while (userp) {
54093 + if (copy_from_user(&s_tmp, userp,
54094 + sizeof (struct acl_subject_label)))
54095 + break;
54096 +
54097 + userp = s_tmp.prev;
54098 + }
54099 +
54100 + return num;
54101 +}
54102 +
54103 +static int
54104 +copy_user_allowedips(struct acl_role_label *rolep)
54105 +{
54106 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54107 +
54108 + ruserip = rolep->allowed_ips;
54109 +
54110 + while (ruserip) {
54111 + rlast = rtmp;
54112 +
54113 + if ((rtmp = (struct role_allowed_ip *)
54114 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54115 + return -ENOMEM;
54116 +
54117 + if (copy_from_user(rtmp, ruserip,
54118 + sizeof (struct role_allowed_ip)))
54119 + return -EFAULT;
54120 +
54121 + ruserip = rtmp->prev;
54122 +
54123 + if (!rlast) {
54124 + rtmp->prev = NULL;
54125 + rolep->allowed_ips = rtmp;
54126 + } else {
54127 + rlast->next = rtmp;
54128 + rtmp->prev = rlast;
54129 + }
54130 +
54131 + if (!ruserip)
54132 + rtmp->next = NULL;
54133 + }
54134 +
54135 + return 0;
54136 +}
54137 +
54138 +static int
54139 +copy_user_transitions(struct acl_role_label *rolep)
54140 +{
54141 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
54142 +
54143 + unsigned int len;
54144 + char *tmp;
54145 +
54146 + rusertp = rolep->transitions;
54147 +
54148 + while (rusertp) {
54149 + rlast = rtmp;
54150 +
54151 + if ((rtmp = (struct role_transition *)
54152 + acl_alloc(sizeof (struct role_transition))) == NULL)
54153 + return -ENOMEM;
54154 +
54155 + if (copy_from_user(rtmp, rusertp,
54156 + sizeof (struct role_transition)))
54157 + return -EFAULT;
54158 +
54159 + rusertp = rtmp->prev;
54160 +
54161 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54162 +
54163 + if (!len || len >= GR_SPROLE_LEN)
54164 + return -EINVAL;
54165 +
54166 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54167 + return -ENOMEM;
54168 +
54169 + if (copy_from_user(tmp, rtmp->rolename, len))
54170 + return -EFAULT;
54171 + tmp[len-1] = '\0';
54172 + rtmp->rolename = tmp;
54173 +
54174 + if (!rlast) {
54175 + rtmp->prev = NULL;
54176 + rolep->transitions = rtmp;
54177 + } else {
54178 + rlast->next = rtmp;
54179 + rtmp->prev = rlast;
54180 + }
54181 +
54182 + if (!rusertp)
54183 + rtmp->next = NULL;
54184 + }
54185 +
54186 + return 0;
54187 +}
54188 +
54189 +static struct acl_subject_label *
54190 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54191 +{
54192 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54193 + unsigned int len;
54194 + char *tmp;
54195 + __u32 num_objs;
54196 + struct acl_ip_label **i_tmp, *i_utmp2;
54197 + struct gr_hash_struct ghash;
54198 + struct subject_map *subjmap;
54199 + unsigned int i_num;
54200 + int err;
54201 +
54202 + if (already_copied != NULL)
54203 + *already_copied = 0;
54204 +
54205 + s_tmp = lookup_subject_map(userp);
54206 +
54207 + /* we've already copied this subject into the kernel, just return
54208 + the reference to it, and don't copy it over again
54209 + */
54210 + if (s_tmp) {
54211 + if (already_copied != NULL)
54212 + *already_copied = 1;
54213 + return(s_tmp);
54214 + }
54215 +
54216 + if ((s_tmp = (struct acl_subject_label *)
54217 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54218 + return ERR_PTR(-ENOMEM);
54219 +
54220 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54221 + if (subjmap == NULL)
54222 + return ERR_PTR(-ENOMEM);
54223 +
54224 + subjmap->user = userp;
54225 + subjmap->kernel = s_tmp;
54226 + insert_subj_map_entry(subjmap);
54227 +
54228 + if (copy_from_user(s_tmp, userp,
54229 + sizeof (struct acl_subject_label)))
54230 + return ERR_PTR(-EFAULT);
54231 +
54232 + len = strnlen_user(s_tmp->filename, PATH_MAX);
54233 +
54234 + if (!len || len >= PATH_MAX)
54235 + return ERR_PTR(-EINVAL);
54236 +
54237 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54238 + return ERR_PTR(-ENOMEM);
54239 +
54240 + if (copy_from_user(tmp, s_tmp->filename, len))
54241 + return ERR_PTR(-EFAULT);
54242 + tmp[len-1] = '\0';
54243 + s_tmp->filename = tmp;
54244 +
54245 + if (!strcmp(s_tmp->filename, "/"))
54246 + role->root_label = s_tmp;
54247 +
54248 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
54249 + return ERR_PTR(-EFAULT);
54250 +
54251 + /* copy user and group transition tables */
54252 +
54253 + if (s_tmp->user_trans_num) {
54254 + uid_t *uidlist;
54255 +
54256 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
54257 + if (uidlist == NULL)
54258 + return ERR_PTR(-ENOMEM);
54259 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
54260 + return ERR_PTR(-EFAULT);
54261 +
54262 + s_tmp->user_transitions = uidlist;
54263 + }
54264 +
54265 + if (s_tmp->group_trans_num) {
54266 + gid_t *gidlist;
54267 +
54268 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
54269 + if (gidlist == NULL)
54270 + return ERR_PTR(-ENOMEM);
54271 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
54272 + return ERR_PTR(-EFAULT);
54273 +
54274 + s_tmp->group_transitions = gidlist;
54275 + }
54276 +
54277 + /* set up object hash table */
54278 + num_objs = count_user_objs(ghash.first);
54279 +
54280 + s_tmp->obj_hash_size = num_objs;
54281 + s_tmp->obj_hash =
54282 + (struct acl_object_label **)
54283 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
54284 +
54285 + if (!s_tmp->obj_hash)
54286 + return ERR_PTR(-ENOMEM);
54287 +
54288 + memset(s_tmp->obj_hash, 0,
54289 + s_tmp->obj_hash_size *
54290 + sizeof (struct acl_object_label *));
54291 +
54292 + /* add in objects */
54293 + err = copy_user_objs(ghash.first, s_tmp, role);
54294 +
54295 + if (err)
54296 + return ERR_PTR(err);
54297 +
54298 + /* set pointer for parent subject */
54299 + if (s_tmp->parent_subject) {
54300 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
54301 +
54302 + if (IS_ERR(s_tmp2))
54303 + return s_tmp2;
54304 +
54305 + s_tmp->parent_subject = s_tmp2;
54306 + }
54307 +
54308 + /* add in ip acls */
54309 +
54310 + if (!s_tmp->ip_num) {
54311 + s_tmp->ips = NULL;
54312 + goto insert;
54313 + }
54314 +
54315 + i_tmp =
54316 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
54317 + sizeof (struct acl_ip_label *));
54318 +
54319 + if (!i_tmp)
54320 + return ERR_PTR(-ENOMEM);
54321 +
54322 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
54323 + *(i_tmp + i_num) =
54324 + (struct acl_ip_label *)
54325 + acl_alloc(sizeof (struct acl_ip_label));
54326 + if (!*(i_tmp + i_num))
54327 + return ERR_PTR(-ENOMEM);
54328 +
54329 + if (copy_from_user
54330 + (&i_utmp2, s_tmp->ips + i_num,
54331 + sizeof (struct acl_ip_label *)))
54332 + return ERR_PTR(-EFAULT);
54333 +
54334 + if (copy_from_user
54335 + (*(i_tmp + i_num), i_utmp2,
54336 + sizeof (struct acl_ip_label)))
54337 + return ERR_PTR(-EFAULT);
54338 +
54339 + if ((*(i_tmp + i_num))->iface == NULL)
54340 + continue;
54341 +
54342 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
54343 + if (!len || len >= IFNAMSIZ)
54344 + return ERR_PTR(-EINVAL);
54345 + tmp = acl_alloc(len);
54346 + if (tmp == NULL)
54347 + return ERR_PTR(-ENOMEM);
54348 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
54349 + return ERR_PTR(-EFAULT);
54350 + (*(i_tmp + i_num))->iface = tmp;
54351 + }
54352 +
54353 + s_tmp->ips = i_tmp;
54354 +
54355 +insert:
54356 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
54357 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
54358 + return ERR_PTR(-ENOMEM);
54359 +
54360 + return s_tmp;
54361 +}
54362 +
54363 +static int
54364 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
54365 +{
54366 + struct acl_subject_label s_pre;
54367 + struct acl_subject_label * ret;
54368 + int err;
54369 +
54370 + while (userp) {
54371 + if (copy_from_user(&s_pre, userp,
54372 + sizeof (struct acl_subject_label)))
54373 + return -EFAULT;
54374 +
54375 + ret = do_copy_user_subj(userp, role, NULL);
54376 +
54377 + err = PTR_ERR(ret);
54378 + if (IS_ERR(ret))
54379 + return err;
54380 +
54381 + insert_acl_subj_label(ret, role);
54382 +
54383 + userp = s_pre.prev;
54384 + }
54385 +
54386 + return 0;
54387 +}
54388 +
54389 +static int
54390 +copy_user_acl(struct gr_arg *arg)
54391 +{
54392 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
54393 + struct acl_subject_label *subj_list;
54394 + struct sprole_pw *sptmp;
54395 + struct gr_hash_struct *ghash;
54396 + uid_t *domainlist;
54397 + unsigned int r_num;
54398 + unsigned int len;
54399 + char *tmp;
54400 + int err = 0;
54401 + __u16 i;
54402 + __u32 num_subjs;
54403 +
54404 + /* we need a default and kernel role */
54405 + if (arg->role_db.num_roles < 2)
54406 + return -EINVAL;
54407 +
54408 + /* copy special role authentication info from userspace */
54409 +
54410 + num_sprole_pws = arg->num_sprole_pws;
54411 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
54412 +
54413 + if (!acl_special_roles && num_sprole_pws)
54414 + return -ENOMEM;
54415 +
54416 + for (i = 0; i < num_sprole_pws; i++) {
54417 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
54418 + if (!sptmp)
54419 + return -ENOMEM;
54420 + if (copy_from_user(sptmp, arg->sprole_pws + i,
54421 + sizeof (struct sprole_pw)))
54422 + return -EFAULT;
54423 +
54424 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
54425 +
54426 + if (!len || len >= GR_SPROLE_LEN)
54427 + return -EINVAL;
54428 +
54429 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54430 + return -ENOMEM;
54431 +
54432 + if (copy_from_user(tmp, sptmp->rolename, len))
54433 + return -EFAULT;
54434 +
54435 + tmp[len-1] = '\0';
54436 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54437 + printk(KERN_ALERT "Copying special role %s\n", tmp);
54438 +#endif
54439 + sptmp->rolename = tmp;
54440 + acl_special_roles[i] = sptmp;
54441 + }
54442 +
54443 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
54444 +
54445 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
54446 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
54447 +
54448 + if (!r_tmp)
54449 + return -ENOMEM;
54450 +
54451 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
54452 + sizeof (struct acl_role_label *)))
54453 + return -EFAULT;
54454 +
54455 + if (copy_from_user(r_tmp, r_utmp2,
54456 + sizeof (struct acl_role_label)))
54457 + return -EFAULT;
54458 +
54459 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
54460 +
54461 + if (!len || len >= PATH_MAX)
54462 + return -EINVAL;
54463 +
54464 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54465 + return -ENOMEM;
54466 +
54467 + if (copy_from_user(tmp, r_tmp->rolename, len))
54468 + return -EFAULT;
54469 +
54470 + tmp[len-1] = '\0';
54471 + r_tmp->rolename = tmp;
54472 +
54473 + if (!strcmp(r_tmp->rolename, "default")
54474 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
54475 + default_role = r_tmp;
54476 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
54477 + kernel_role = r_tmp;
54478 + }
54479 +
54480 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
54481 + return -ENOMEM;
54482 +
54483 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
54484 + return -EFAULT;
54485 +
54486 + r_tmp->hash = ghash;
54487 +
54488 + num_subjs = count_user_subjs(r_tmp->hash->first);
54489 +
54490 + r_tmp->subj_hash_size = num_subjs;
54491 + r_tmp->subj_hash =
54492 + (struct acl_subject_label **)
54493 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
54494 +
54495 + if (!r_tmp->subj_hash)
54496 + return -ENOMEM;
54497 +
54498 + err = copy_user_allowedips(r_tmp);
54499 + if (err)
54500 + return err;
54501 +
54502 + /* copy domain info */
54503 + if (r_tmp->domain_children != NULL) {
54504 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
54505 + if (domainlist == NULL)
54506 + return -ENOMEM;
54507 +
54508 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
54509 + return -EFAULT;
54510 +
54511 + r_tmp->domain_children = domainlist;
54512 + }
54513 +
54514 + err = copy_user_transitions(r_tmp);
54515 + if (err)
54516 + return err;
54517 +
54518 + memset(r_tmp->subj_hash, 0,
54519 + r_tmp->subj_hash_size *
54520 + sizeof (struct acl_subject_label *));
54521 +
54522 + /* acquire the list of subjects, then NULL out
54523 + the list prior to parsing the subjects for this role,
54524 + as during this parsing the list is replaced with a list
54525 + of *nested* subjects for the role
54526 + */
54527 + subj_list = r_tmp->hash->first;
54528 +
54529 + /* set nested subject list to null */
54530 + r_tmp->hash->first = NULL;
54531 +
54532 + err = copy_user_subjs(subj_list, r_tmp);
54533 +
54534 + if (err)
54535 + return err;
54536 +
54537 + insert_acl_role_label(r_tmp);
54538 + }
54539 +
54540 + if (default_role == NULL || kernel_role == NULL)
54541 + return -EINVAL;
54542 +
54543 + return err;
54544 +}
54545 +
54546 +static int
54547 +gracl_init(struct gr_arg *args)
54548 +{
54549 + int error = 0;
54550 +
54551 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
54552 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
54553 +
54554 + if (init_variables(args)) {
54555 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
54556 + error = -ENOMEM;
54557 + free_variables();
54558 + goto out;
54559 + }
54560 +
54561 + error = copy_user_acl(args);
54562 + free_init_variables();
54563 + if (error) {
54564 + free_variables();
54565 + goto out;
54566 + }
54567 +
54568 + if ((error = gr_set_acls(0))) {
54569 + free_variables();
54570 + goto out;
54571 + }
54572 +
54573 + pax_open_kernel();
54574 + gr_status |= GR_READY;
54575 + pax_close_kernel();
54576 +
54577 + out:
54578 + return error;
54579 +}
54580 +
54581 +/* derived from glibc fnmatch() 0: match, 1: no match*/
54582 +
54583 +static int
54584 +glob_match(const char *p, const char *n)
54585 +{
54586 + char c;
54587 +
54588 + while ((c = *p++) != '\0') {
54589 + switch (c) {
54590 + case '?':
54591 + if (*n == '\0')
54592 + return 1;
54593 + else if (*n == '/')
54594 + return 1;
54595 + break;
54596 + case '\\':
54597 + if (*n != c)
54598 + return 1;
54599 + break;
54600 + case '*':
54601 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
54602 + if (*n == '/')
54603 + return 1;
54604 + else if (c == '?') {
54605 + if (*n == '\0')
54606 + return 1;
54607 + else
54608 + ++n;
54609 + }
54610 + }
54611 + if (c == '\0') {
54612 + return 0;
54613 + } else {
54614 + const char *endp;
54615 +
54616 + if ((endp = strchr(n, '/')) == NULL)
54617 + endp = n + strlen(n);
54618 +
54619 + if (c == '[') {
54620 + for (--p; n < endp; ++n)
54621 + if (!glob_match(p, n))
54622 + return 0;
54623 + } else if (c == '/') {
54624 + while (*n != '\0' && *n != '/')
54625 + ++n;
54626 + if (*n == '/' && !glob_match(p, n + 1))
54627 + return 0;
54628 + } else {
54629 + for (--p; n < endp; ++n)
54630 + if (*n == c && !glob_match(p, n))
54631 + return 0;
54632 + }
54633 +
54634 + return 1;
54635 + }
54636 + case '[':
54637 + {
54638 + int not;
54639 + char cold;
54640 +
54641 + if (*n == '\0' || *n == '/')
54642 + return 1;
54643 +
54644 + not = (*p == '!' || *p == '^');
54645 + if (not)
54646 + ++p;
54647 +
54648 + c = *p++;
54649 + for (;;) {
54650 + unsigned char fn = (unsigned char)*n;
54651 +
54652 + if (c == '\0')
54653 + return 1;
54654 + else {
54655 + if (c == fn)
54656 + goto matched;
54657 + cold = c;
54658 + c = *p++;
54659 +
54660 + if (c == '-' && *p != ']') {
54661 + unsigned char cend = *p++;
54662 +
54663 + if (cend == '\0')
54664 + return 1;
54665 +
54666 + if (cold <= fn && fn <= cend)
54667 + goto matched;
54668 +
54669 + c = *p++;
54670 + }
54671 + }
54672 +
54673 + if (c == ']')
54674 + break;
54675 + }
54676 + if (!not)
54677 + return 1;
54678 + break;
54679 + matched:
54680 + while (c != ']') {
54681 + if (c == '\0')
54682 + return 1;
54683 +
54684 + c = *p++;
54685 + }
54686 + if (not)
54687 + return 1;
54688 + }
54689 + break;
54690 + default:
54691 + if (c != *n)
54692 + return 1;
54693 + }
54694 +
54695 + ++n;
54696 + }
54697 +
54698 + if (*n == '\0')
54699 + return 0;
54700 +
54701 + if (*n == '/')
54702 + return 0;
54703 +
54704 + return 1;
54705 +}
54706 +
54707 +static struct acl_object_label *
54708 +chk_glob_label(struct acl_object_label *globbed,
54709 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
54710 +{
54711 + struct acl_object_label *tmp;
54712 +
54713 + if (*path == NULL)
54714 + *path = gr_to_filename_nolock(dentry, mnt);
54715 +
54716 + tmp = globbed;
54717 +
54718 + while (tmp) {
54719 + if (!glob_match(tmp->filename, *path))
54720 + return tmp;
54721 + tmp = tmp->next;
54722 + }
54723 +
54724 + return NULL;
54725 +}
54726 +
54727 +static struct acl_object_label *
54728 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
54729 + const ino_t curr_ino, const dev_t curr_dev,
54730 + const struct acl_subject_label *subj, char **path, const int checkglob)
54731 +{
54732 + struct acl_subject_label *tmpsubj;
54733 + struct acl_object_label *retval;
54734 + struct acl_object_label *retval2;
54735 +
54736 + tmpsubj = (struct acl_subject_label *) subj;
54737 + read_lock(&gr_inode_lock);
54738 + do {
54739 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
54740 + if (retval) {
54741 + if (checkglob && retval->globbed) {
54742 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
54743 + if (retval2)
54744 + retval = retval2;
54745 + }
54746 + break;
54747 + }
54748 + } while ((tmpsubj = tmpsubj->parent_subject));
54749 + read_unlock(&gr_inode_lock);
54750 +
54751 + return retval;
54752 +}
54753 +
54754 +static __inline__ struct acl_object_label *
54755 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
54756 + struct dentry *curr_dentry,
54757 + const struct acl_subject_label *subj, char **path, const int checkglob)
54758 +{
54759 + int newglob = checkglob;
54760 + ino_t inode;
54761 + dev_t device;
54762 +
54763 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
54764 + as we don't want a / * rule to match instead of the / object
54765 + don't do this for create lookups that call this function though, since they're looking up
54766 + on the parent and thus need globbing checks on all paths
54767 + */
54768 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
54769 + newglob = GR_NO_GLOB;
54770 +
54771 + spin_lock(&curr_dentry->d_lock);
54772 + inode = curr_dentry->d_inode->i_ino;
54773 + device = __get_dev(curr_dentry);
54774 + spin_unlock(&curr_dentry->d_lock);
54775 +
54776 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
54777 +}
54778 +
54779 +static struct acl_object_label *
54780 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54781 + const struct acl_subject_label *subj, char *path, const int checkglob)
54782 +{
54783 + struct dentry *dentry = (struct dentry *) l_dentry;
54784 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54785 + struct mount *real_mnt = real_mount(mnt);
54786 + struct acl_object_label *retval;
54787 + struct dentry *parent;
54788 +
54789 + write_seqlock(&rename_lock);
54790 + br_read_lock(&vfsmount_lock);
54791 +
54792 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
54793 +#ifdef CONFIG_NET
54794 + mnt == sock_mnt ||
54795 +#endif
54796 +#ifdef CONFIG_HUGETLBFS
54797 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
54798 +#endif
54799 + /* ignore Eric Biederman */
54800 + IS_PRIVATE(l_dentry->d_inode))) {
54801 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
54802 + goto out;
54803 + }
54804 +
54805 + for (;;) {
54806 + if (dentry == real_root.dentry && mnt == real_root.mnt)
54807 + break;
54808 +
54809 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54810 + if (!mnt_has_parent(real_mnt))
54811 + break;
54812 +
54813 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54814 + if (retval != NULL)
54815 + goto out;
54816 +
54817 + dentry = real_mnt->mnt_mountpoint;
54818 + real_mnt = real_mnt->mnt_parent;
54819 + mnt = &real_mnt->mnt;
54820 + continue;
54821 + }
54822 +
54823 + parent = dentry->d_parent;
54824 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54825 + if (retval != NULL)
54826 + goto out;
54827 +
54828 + dentry = parent;
54829 + }
54830 +
54831 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54832 +
54833 + /* real_root is pinned so we don't have to hold a reference */
54834 + if (retval == NULL)
54835 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
54836 +out:
54837 + br_read_unlock(&vfsmount_lock);
54838 + write_sequnlock(&rename_lock);
54839 +
54840 + BUG_ON(retval == NULL);
54841 +
54842 + return retval;
54843 +}
54844 +
54845 +static __inline__ struct acl_object_label *
54846 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54847 + const struct acl_subject_label *subj)
54848 +{
54849 + char *path = NULL;
54850 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
54851 +}
54852 +
54853 +static __inline__ struct acl_object_label *
54854 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54855 + const struct acl_subject_label *subj)
54856 +{
54857 + char *path = NULL;
54858 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
54859 +}
54860 +
54861 +static __inline__ struct acl_object_label *
54862 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54863 + const struct acl_subject_label *subj, char *path)
54864 +{
54865 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
54866 +}
54867 +
54868 +static struct acl_subject_label *
54869 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54870 + const struct acl_role_label *role)
54871 +{
54872 + struct dentry *dentry = (struct dentry *) l_dentry;
54873 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54874 + struct mount *real_mnt = real_mount(mnt);
54875 + struct acl_subject_label *retval;
54876 + struct dentry *parent;
54877 +
54878 + write_seqlock(&rename_lock);
54879 + br_read_lock(&vfsmount_lock);
54880 +
54881 + for (;;) {
54882 + if (dentry == real_root.dentry && mnt == real_root.mnt)
54883 + break;
54884 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54885 + if (!mnt_has_parent(real_mnt))
54886 + break;
54887 +
54888 + spin_lock(&dentry->d_lock);
54889 + read_lock(&gr_inode_lock);
54890 + retval =
54891 + lookup_acl_subj_label(dentry->d_inode->i_ino,
54892 + __get_dev(dentry), role);
54893 + read_unlock(&gr_inode_lock);
54894 + spin_unlock(&dentry->d_lock);
54895 + if (retval != NULL)
54896 + goto out;
54897 +
54898 + dentry = real_mnt->mnt_mountpoint;
54899 + real_mnt = real_mnt->mnt_parent;
54900 + mnt = &real_mnt->mnt;
54901 + continue;
54902 + }
54903 +
54904 + spin_lock(&dentry->d_lock);
54905 + read_lock(&gr_inode_lock);
54906 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54907 + __get_dev(dentry), role);
54908 + read_unlock(&gr_inode_lock);
54909 + parent = dentry->d_parent;
54910 + spin_unlock(&dentry->d_lock);
54911 +
54912 + if (retval != NULL)
54913 + goto out;
54914 +
54915 + dentry = parent;
54916 + }
54917 +
54918 + spin_lock(&dentry->d_lock);
54919 + read_lock(&gr_inode_lock);
54920 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54921 + __get_dev(dentry), role);
54922 + read_unlock(&gr_inode_lock);
54923 + spin_unlock(&dentry->d_lock);
54924 +
54925 + if (unlikely(retval == NULL)) {
54926 + /* real_root is pinned, we don't need to hold a reference */
54927 + read_lock(&gr_inode_lock);
54928 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
54929 + __get_dev(real_root.dentry), role);
54930 + read_unlock(&gr_inode_lock);
54931 + }
54932 +out:
54933 + br_read_unlock(&vfsmount_lock);
54934 + write_sequnlock(&rename_lock);
54935 +
54936 + BUG_ON(retval == NULL);
54937 +
54938 + return retval;
54939 +}
54940 +
54941 +static void
54942 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
54943 +{
54944 + struct task_struct *task = current;
54945 + const struct cred *cred = current_cred();
54946 +
54947 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
54948 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54949 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54950 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
54951 +
54952 + return;
54953 +}
54954 +
54955 +static void
54956 +gr_log_learn_id_change(const char type, const unsigned int real,
54957 + const unsigned int effective, const unsigned int fs)
54958 +{
54959 + struct task_struct *task = current;
54960 + const struct cred *cred = current_cred();
54961 +
54962 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
54963 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54964 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54965 + type, real, effective, fs, &task->signal->saved_ip);
54966 +
54967 + return;
54968 +}
54969 +
54970 +__u32
54971 +gr_search_file(const struct dentry * dentry, const __u32 mode,
54972 + const struct vfsmount * mnt)
54973 +{
54974 + __u32 retval = mode;
54975 + struct acl_subject_label *curracl;
54976 + struct acl_object_label *currobj;
54977 +
54978 + if (unlikely(!(gr_status & GR_READY)))
54979 + return (mode & ~GR_AUDITS);
54980 +
54981 + curracl = current->acl;
54982 +
54983 + currobj = chk_obj_label(dentry, mnt, curracl);
54984 + retval = currobj->mode & mode;
54985 +
54986 + /* if we're opening a specified transfer file for writing
54987 + (e.g. /dev/initctl), then transfer our role to init
54988 + */
54989 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
54990 + current->role->roletype & GR_ROLE_PERSIST)) {
54991 + struct task_struct *task = init_pid_ns.child_reaper;
54992 +
54993 + if (task->role != current->role) {
54994 + task->acl_sp_role = 0;
54995 + task->acl_role_id = current->acl_role_id;
54996 + task->role = current->role;
54997 + rcu_read_lock();
54998 + read_lock(&grsec_exec_file_lock);
54999 + gr_apply_subject_to_task(task);
55000 + read_unlock(&grsec_exec_file_lock);
55001 + rcu_read_unlock();
55002 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55003 + }
55004 + }
55005 +
55006 + if (unlikely
55007 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55008 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55009 + __u32 new_mode = mode;
55010 +
55011 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55012 +
55013 + retval = new_mode;
55014 +
55015 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55016 + new_mode |= GR_INHERIT;
55017 +
55018 + if (!(mode & GR_NOLEARN))
55019 + gr_log_learn(dentry, mnt, new_mode);
55020 + }
55021 +
55022 + return retval;
55023 +}
55024 +
55025 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55026 + const struct dentry *parent,
55027 + const struct vfsmount *mnt)
55028 +{
55029 + struct name_entry *match;
55030 + struct acl_object_label *matchpo;
55031 + struct acl_subject_label *curracl;
55032 + char *path;
55033 +
55034 + if (unlikely(!(gr_status & GR_READY)))
55035 + return NULL;
55036 +
55037 + preempt_disable();
55038 + path = gr_to_filename_rbac(new_dentry, mnt);
55039 + match = lookup_name_entry_create(path);
55040 +
55041 + curracl = current->acl;
55042 +
55043 + if (match) {
55044 + read_lock(&gr_inode_lock);
55045 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55046 + read_unlock(&gr_inode_lock);
55047 +
55048 + if (matchpo) {
55049 + preempt_enable();
55050 + return matchpo;
55051 + }
55052 + }
55053 +
55054 + // lookup parent
55055 +
55056 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55057 +
55058 + preempt_enable();
55059 + return matchpo;
55060 +}
55061 +
55062 +__u32
55063 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55064 + const struct vfsmount * mnt, const __u32 mode)
55065 +{
55066 + struct acl_object_label *matchpo;
55067 + __u32 retval;
55068 +
55069 + if (unlikely(!(gr_status & GR_READY)))
55070 + return (mode & ~GR_AUDITS);
55071 +
55072 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
55073 +
55074 + retval = matchpo->mode & mode;
55075 +
55076 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55077 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55078 + __u32 new_mode = mode;
55079 +
55080 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55081 +
55082 + gr_log_learn(new_dentry, mnt, new_mode);
55083 + return new_mode;
55084 + }
55085 +
55086 + return retval;
55087 +}
55088 +
55089 +__u32
55090 +gr_check_link(const struct dentry * new_dentry,
55091 + const struct dentry * parent_dentry,
55092 + const struct vfsmount * parent_mnt,
55093 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55094 +{
55095 + struct acl_object_label *obj;
55096 + __u32 oldmode, newmode;
55097 + __u32 needmode;
55098 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55099 + GR_DELETE | GR_INHERIT;
55100 +
55101 + if (unlikely(!(gr_status & GR_READY)))
55102 + return (GR_CREATE | GR_LINK);
55103 +
55104 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55105 + oldmode = obj->mode;
55106 +
55107 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55108 + newmode = obj->mode;
55109 +
55110 + needmode = newmode & checkmodes;
55111 +
55112 + // old name for hardlink must have at least the permissions of the new name
55113 + if ((oldmode & needmode) != needmode)
55114 + goto bad;
55115 +
55116 + // if old name had restrictions/auditing, make sure the new name does as well
55117 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55118 +
55119 + // don't allow hardlinking of suid/sgid/fcapped files without permission
55120 + if (is_privileged_binary(old_dentry))
55121 + needmode |= GR_SETID;
55122 +
55123 + if ((newmode & needmode) != needmode)
55124 + goto bad;
55125 +
55126 + // enforce minimum permissions
55127 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55128 + return newmode;
55129 +bad:
55130 + needmode = oldmode;
55131 + if (is_privileged_binary(old_dentry))
55132 + needmode |= GR_SETID;
55133 +
55134 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55135 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55136 + return (GR_CREATE | GR_LINK);
55137 + } else if (newmode & GR_SUPPRESS)
55138 + return GR_SUPPRESS;
55139 + else
55140 + return 0;
55141 +}
55142 +
55143 +int
55144 +gr_check_hidden_task(const struct task_struct *task)
55145 +{
55146 + if (unlikely(!(gr_status & GR_READY)))
55147 + return 0;
55148 +
55149 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55150 + return 1;
55151 +
55152 + return 0;
55153 +}
55154 +
55155 +int
55156 +gr_check_protected_task(const struct task_struct *task)
55157 +{
55158 + if (unlikely(!(gr_status & GR_READY) || !task))
55159 + return 0;
55160 +
55161 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55162 + task->acl != current->acl)
55163 + return 1;
55164 +
55165 + return 0;
55166 +}
55167 +
55168 +int
55169 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55170 +{
55171 + struct task_struct *p;
55172 + int ret = 0;
55173 +
55174 + if (unlikely(!(gr_status & GR_READY) || !pid))
55175 + return ret;
55176 +
55177 + read_lock(&tasklist_lock);
55178 + do_each_pid_task(pid, type, p) {
55179 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55180 + p->acl != current->acl) {
55181 + ret = 1;
55182 + goto out;
55183 + }
55184 + } while_each_pid_task(pid, type, p);
55185 +out:
55186 + read_unlock(&tasklist_lock);
55187 +
55188 + return ret;
55189 +}
55190 +
55191 +void
55192 +gr_copy_label(struct task_struct *tsk)
55193 +{
55194 + tsk->signal->used_accept = 0;
55195 + tsk->acl_sp_role = 0;
55196 + tsk->acl_role_id = current->acl_role_id;
55197 + tsk->acl = current->acl;
55198 + tsk->role = current->role;
55199 + tsk->signal->curr_ip = current->signal->curr_ip;
55200 + tsk->signal->saved_ip = current->signal->saved_ip;
55201 + if (current->exec_file)
55202 + get_file(current->exec_file);
55203 + tsk->exec_file = current->exec_file;
55204 + tsk->is_writable = current->is_writable;
55205 + if (unlikely(current->signal->used_accept)) {
55206 + current->signal->curr_ip = 0;
55207 + current->signal->saved_ip = 0;
55208 + }
55209 +
55210 + return;
55211 +}
55212 +
55213 +static void
55214 +gr_set_proc_res(struct task_struct *task)
55215 +{
55216 + struct acl_subject_label *proc;
55217 + unsigned short i;
55218 +
55219 + proc = task->acl;
55220 +
55221 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55222 + return;
55223 +
55224 + for (i = 0; i < RLIM_NLIMITS; i++) {
55225 + if (!(proc->resmask & (1 << i)))
55226 + continue;
55227 +
55228 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55229 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55230 + }
55231 +
55232 + return;
55233 +}
55234 +
55235 +extern int __gr_process_user_ban(struct user_struct *user);
55236 +
55237 +int
55238 +gr_check_user_change(int real, int effective, int fs)
55239 +{
55240 + unsigned int i;
55241 + __u16 num;
55242 + uid_t *uidlist;
55243 + int curuid;
55244 + int realok = 0;
55245 + int effectiveok = 0;
55246 + int fsok = 0;
55247 +
55248 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55249 + struct user_struct *user;
55250 +
55251 + if (real == -1)
55252 + goto skipit;
55253 +
55254 + user = find_user(real);
55255 + if (user == NULL)
55256 + goto skipit;
55257 +
55258 + if (__gr_process_user_ban(user)) {
55259 + /* for find_user */
55260 + free_uid(user);
55261 + return 1;
55262 + }
55263 +
55264 + /* for find_user */
55265 + free_uid(user);
55266 +
55267 +skipit:
55268 +#endif
55269 +
55270 + if (unlikely(!(gr_status & GR_READY)))
55271 + return 0;
55272 +
55273 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55274 + gr_log_learn_id_change('u', real, effective, fs);
55275 +
55276 + num = current->acl->user_trans_num;
55277 + uidlist = current->acl->user_transitions;
55278 +
55279 + if (uidlist == NULL)
55280 + return 0;
55281 +
55282 + if (real == -1)
55283 + realok = 1;
55284 + if (effective == -1)
55285 + effectiveok = 1;
55286 + if (fs == -1)
55287 + fsok = 1;
55288 +
55289 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
55290 + for (i = 0; i < num; i++) {
55291 + curuid = (int)uidlist[i];
55292 + if (real == curuid)
55293 + realok = 1;
55294 + if (effective == curuid)
55295 + effectiveok = 1;
55296 + if (fs == curuid)
55297 + fsok = 1;
55298 + }
55299 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
55300 + for (i = 0; i < num; i++) {
55301 + curuid = (int)uidlist[i];
55302 + if (real == curuid)
55303 + break;
55304 + if (effective == curuid)
55305 + break;
55306 + if (fs == curuid)
55307 + break;
55308 + }
55309 + /* not in deny list */
55310 + if (i == num) {
55311 + realok = 1;
55312 + effectiveok = 1;
55313 + fsok = 1;
55314 + }
55315 + }
55316 +
55317 + if (realok && effectiveok && fsok)
55318 + return 0;
55319 + else {
55320 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55321 + return 1;
55322 + }
55323 +}
55324 +
55325 +int
55326 +gr_check_group_change(int real, int effective, int fs)
55327 +{
55328 + unsigned int i;
55329 + __u16 num;
55330 + gid_t *gidlist;
55331 + int curgid;
55332 + int realok = 0;
55333 + int effectiveok = 0;
55334 + int fsok = 0;
55335 +
55336 + if (unlikely(!(gr_status & GR_READY)))
55337 + return 0;
55338 +
55339 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55340 + gr_log_learn_id_change('g', real, effective, fs);
55341 +
55342 + num = current->acl->group_trans_num;
55343 + gidlist = current->acl->group_transitions;
55344 +
55345 + if (gidlist == NULL)
55346 + return 0;
55347 +
55348 + if (real == -1)
55349 + realok = 1;
55350 + if (effective == -1)
55351 + effectiveok = 1;
55352 + if (fs == -1)
55353 + fsok = 1;
55354 +
55355 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
55356 + for (i = 0; i < num; i++) {
55357 + curgid = (int)gidlist[i];
55358 + if (real == curgid)
55359 + realok = 1;
55360 + if (effective == curgid)
55361 + effectiveok = 1;
55362 + if (fs == curgid)
55363 + fsok = 1;
55364 + }
55365 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
55366 + for (i = 0; i < num; i++) {
55367 + curgid = (int)gidlist[i];
55368 + if (real == curgid)
55369 + break;
55370 + if (effective == curgid)
55371 + break;
55372 + if (fs == curgid)
55373 + break;
55374 + }
55375 + /* not in deny list */
55376 + if (i == num) {
55377 + realok = 1;
55378 + effectiveok = 1;
55379 + fsok = 1;
55380 + }
55381 + }
55382 +
55383 + if (realok && effectiveok && fsok)
55384 + return 0;
55385 + else {
55386 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55387 + return 1;
55388 + }
55389 +}
55390 +
55391 +extern int gr_acl_is_capable(const int cap);
55392 +
55393 +void
55394 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
55395 +{
55396 + struct acl_role_label *role = task->role;
55397 + struct acl_subject_label *subj = NULL;
55398 + struct acl_object_label *obj;
55399 + struct file *filp;
55400 +
55401 + if (unlikely(!(gr_status & GR_READY)))
55402 + return;
55403 +
55404 + filp = task->exec_file;
55405 +
55406 + /* kernel process, we'll give them the kernel role */
55407 + if (unlikely(!filp)) {
55408 + task->role = kernel_role;
55409 + task->acl = kernel_role->root_label;
55410 + return;
55411 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
55412 + role = lookup_acl_role_label(task, uid, gid);
55413 +
55414 + /* don't change the role if we're not a privileged process */
55415 + if (role && task->role != role &&
55416 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
55417 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
55418 + return;
55419 +
55420 + /* perform subject lookup in possibly new role
55421 + we can use this result below in the case where role == task->role
55422 + */
55423 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
55424 +
55425 + /* if we changed uid/gid, but result in the same role
55426 + and are using inheritance, don't lose the inherited subject
55427 + if current subject is other than what normal lookup
55428 + would result in, we arrived via inheritance, don't
55429 + lose subject
55430 + */
55431 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
55432 + (subj == task->acl)))
55433 + task->acl = subj;
55434 +
55435 + task->role = role;
55436 +
55437 + task->is_writable = 0;
55438 +
55439 + /* ignore additional mmap checks for processes that are writable
55440 + by the default ACL */
55441 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55442 + if (unlikely(obj->mode & GR_WRITE))
55443 + task->is_writable = 1;
55444 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55445 + if (unlikely(obj->mode & GR_WRITE))
55446 + task->is_writable = 1;
55447 +
55448 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55449 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55450 +#endif
55451 +
55452 + gr_set_proc_res(task);
55453 +
55454 + return;
55455 +}
55456 +
55457 +int
55458 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
55459 + const int unsafe_flags)
55460 +{
55461 + struct task_struct *task = current;
55462 + struct acl_subject_label *newacl;
55463 + struct acl_object_label *obj;
55464 + __u32 retmode;
55465 +
55466 + if (unlikely(!(gr_status & GR_READY)))
55467 + return 0;
55468 +
55469 + newacl = chk_subj_label(dentry, mnt, task->role);
55470 +
55471 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
55472 + did an exec
55473 + */
55474 + rcu_read_lock();
55475 + read_lock(&tasklist_lock);
55476 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
55477 + (task->parent->acl->mode & GR_POVERRIDE))) {
55478 + read_unlock(&tasklist_lock);
55479 + rcu_read_unlock();
55480 + goto skip_check;
55481 + }
55482 + read_unlock(&tasklist_lock);
55483 + rcu_read_unlock();
55484 +
55485 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
55486 + !(task->role->roletype & GR_ROLE_GOD) &&
55487 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
55488 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55489 + if (unsafe_flags & LSM_UNSAFE_SHARE)
55490 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
55491 + else
55492 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
55493 + return -EACCES;
55494 + }
55495 +
55496 +skip_check:
55497 +
55498 + obj = chk_obj_label(dentry, mnt, task->acl);
55499 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
55500 +
55501 + if (!(task->acl->mode & GR_INHERITLEARN) &&
55502 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
55503 + if (obj->nested)
55504 + task->acl = obj->nested;
55505 + else
55506 + task->acl = newacl;
55507 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
55508 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
55509 +
55510 + task->is_writable = 0;
55511 +
55512 + /* ignore additional mmap checks for processes that are writable
55513 + by the default ACL */
55514 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
55515 + if (unlikely(obj->mode & GR_WRITE))
55516 + task->is_writable = 1;
55517 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
55518 + if (unlikely(obj->mode & GR_WRITE))
55519 + task->is_writable = 1;
55520 +
55521 + gr_set_proc_res(task);
55522 +
55523 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55524 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55525 +#endif
55526 + return 0;
55527 +}
55528 +
55529 +/* always called with valid inodev ptr */
55530 +static void
55531 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
55532 +{
55533 + struct acl_object_label *matchpo;
55534 + struct acl_subject_label *matchps;
55535 + struct acl_subject_label *subj;
55536 + struct acl_role_label *role;
55537 + unsigned int x;
55538 +
55539 + FOR_EACH_ROLE_START(role)
55540 + FOR_EACH_SUBJECT_START(role, subj, x)
55541 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55542 + matchpo->mode |= GR_DELETED;
55543 + FOR_EACH_SUBJECT_END(subj,x)
55544 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
55545 + /* nested subjects aren't in the role's subj_hash table */
55546 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55547 + matchpo->mode |= GR_DELETED;
55548 + FOR_EACH_NESTED_SUBJECT_END(subj)
55549 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
55550 + matchps->mode |= GR_DELETED;
55551 + FOR_EACH_ROLE_END(role)
55552 +
55553 + inodev->nentry->deleted = 1;
55554 +
55555 + return;
55556 +}
55557 +
55558 +void
55559 +gr_handle_delete(const ino_t ino, const dev_t dev)
55560 +{
55561 + struct inodev_entry *inodev;
55562 +
55563 + if (unlikely(!(gr_status & GR_READY)))
55564 + return;
55565 +
55566 + write_lock(&gr_inode_lock);
55567 + inodev = lookup_inodev_entry(ino, dev);
55568 + if (inodev != NULL)
55569 + do_handle_delete(inodev, ino, dev);
55570 + write_unlock(&gr_inode_lock);
55571 +
55572 + return;
55573 +}
55574 +
55575 +static void
55576 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
55577 + const ino_t newinode, const dev_t newdevice,
55578 + struct acl_subject_label *subj)
55579 +{
55580 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
55581 + struct acl_object_label *match;
55582 +
55583 + match = subj->obj_hash[index];
55584 +
55585 + while (match && (match->inode != oldinode ||
55586 + match->device != olddevice ||
55587 + !(match->mode & GR_DELETED)))
55588 + match = match->next;
55589 +
55590 + if (match && (match->inode == oldinode)
55591 + && (match->device == olddevice)
55592 + && (match->mode & GR_DELETED)) {
55593 + if (match->prev == NULL) {
55594 + subj->obj_hash[index] = match->next;
55595 + if (match->next != NULL)
55596 + match->next->prev = NULL;
55597 + } else {
55598 + match->prev->next = match->next;
55599 + if (match->next != NULL)
55600 + match->next->prev = match->prev;
55601 + }
55602 + match->prev = NULL;
55603 + match->next = NULL;
55604 + match->inode = newinode;
55605 + match->device = newdevice;
55606 + match->mode &= ~GR_DELETED;
55607 +
55608 + insert_acl_obj_label(match, subj);
55609 + }
55610 +
55611 + return;
55612 +}
55613 +
55614 +static void
55615 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
55616 + const ino_t newinode, const dev_t newdevice,
55617 + struct acl_role_label *role)
55618 +{
55619 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
55620 + struct acl_subject_label *match;
55621 +
55622 + match = role->subj_hash[index];
55623 +
55624 + while (match && (match->inode != oldinode ||
55625 + match->device != olddevice ||
55626 + !(match->mode & GR_DELETED)))
55627 + match = match->next;
55628 +
55629 + if (match && (match->inode == oldinode)
55630 + && (match->device == olddevice)
55631 + && (match->mode & GR_DELETED)) {
55632 + if (match->prev == NULL) {
55633 + role->subj_hash[index] = match->next;
55634 + if (match->next != NULL)
55635 + match->next->prev = NULL;
55636 + } else {
55637 + match->prev->next = match->next;
55638 + if (match->next != NULL)
55639 + match->next->prev = match->prev;
55640 + }
55641 + match->prev = NULL;
55642 + match->next = NULL;
55643 + match->inode = newinode;
55644 + match->device = newdevice;
55645 + match->mode &= ~GR_DELETED;
55646 +
55647 + insert_acl_subj_label(match, role);
55648 + }
55649 +
55650 + return;
55651 +}
55652 +
55653 +static void
55654 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
55655 + const ino_t newinode, const dev_t newdevice)
55656 +{
55657 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
55658 + struct inodev_entry *match;
55659 +
55660 + match = inodev_set.i_hash[index];
55661 +
55662 + while (match && (match->nentry->inode != oldinode ||
55663 + match->nentry->device != olddevice || !match->nentry->deleted))
55664 + match = match->next;
55665 +
55666 + if (match && (match->nentry->inode == oldinode)
55667 + && (match->nentry->device == olddevice) &&
55668 + match->nentry->deleted) {
55669 + if (match->prev == NULL) {
55670 + inodev_set.i_hash[index] = match->next;
55671 + if (match->next != NULL)
55672 + match->next->prev = NULL;
55673 + } else {
55674 + match->prev->next = match->next;
55675 + if (match->next != NULL)
55676 + match->next->prev = match->prev;
55677 + }
55678 + match->prev = NULL;
55679 + match->next = NULL;
55680 + match->nentry->inode = newinode;
55681 + match->nentry->device = newdevice;
55682 + match->nentry->deleted = 0;
55683 +
55684 + insert_inodev_entry(match);
55685 + }
55686 +
55687 + return;
55688 +}
55689 +
55690 +static void
55691 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
55692 +{
55693 + struct acl_subject_label *subj;
55694 + struct acl_role_label *role;
55695 + unsigned int x;
55696 +
55697 + FOR_EACH_ROLE_START(role)
55698 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
55699 +
55700 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
55701 + if ((subj->inode == ino) && (subj->device == dev)) {
55702 + subj->inode = ino;
55703 + subj->device = dev;
55704 + }
55705 + /* nested subjects aren't in the role's subj_hash table */
55706 + update_acl_obj_label(matchn->inode, matchn->device,
55707 + ino, dev, subj);
55708 + FOR_EACH_NESTED_SUBJECT_END(subj)
55709 + FOR_EACH_SUBJECT_START(role, subj, x)
55710 + update_acl_obj_label(matchn->inode, matchn->device,
55711 + ino, dev, subj);
55712 + FOR_EACH_SUBJECT_END(subj,x)
55713 + FOR_EACH_ROLE_END(role)
55714 +
55715 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
55716 +
55717 + return;
55718 +}
55719 +
55720 +static void
55721 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
55722 + const struct vfsmount *mnt)
55723 +{
55724 + ino_t ino = dentry->d_inode->i_ino;
55725 + dev_t dev = __get_dev(dentry);
55726 +
55727 + __do_handle_create(matchn, ino, dev);
55728 +
55729 + return;
55730 +}
55731 +
55732 +void
55733 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
55734 +{
55735 + struct name_entry *matchn;
55736 +
55737 + if (unlikely(!(gr_status & GR_READY)))
55738 + return;
55739 +
55740 + preempt_disable();
55741 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
55742 +
55743 + if (unlikely((unsigned long)matchn)) {
55744 + write_lock(&gr_inode_lock);
55745 + do_handle_create(matchn, dentry, mnt);
55746 + write_unlock(&gr_inode_lock);
55747 + }
55748 + preempt_enable();
55749 +
55750 + return;
55751 +}
55752 +
55753 +void
55754 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
55755 +{
55756 + struct name_entry *matchn;
55757 +
55758 + if (unlikely(!(gr_status & GR_READY)))
55759 + return;
55760 +
55761 + preempt_disable();
55762 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
55763 +
55764 + if (unlikely((unsigned long)matchn)) {
55765 + write_lock(&gr_inode_lock);
55766 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
55767 + write_unlock(&gr_inode_lock);
55768 + }
55769 + preempt_enable();
55770 +
55771 + return;
55772 +}
55773 +
55774 +void
55775 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55776 + struct dentry *old_dentry,
55777 + struct dentry *new_dentry,
55778 + struct vfsmount *mnt, const __u8 replace)
55779 +{
55780 + struct name_entry *matchn;
55781 + struct inodev_entry *inodev;
55782 + struct inode *inode = new_dentry->d_inode;
55783 + ino_t old_ino = old_dentry->d_inode->i_ino;
55784 + dev_t old_dev = __get_dev(old_dentry);
55785 +
55786 + /* vfs_rename swaps the name and parent link for old_dentry and
55787 + new_dentry
55788 + at this point, old_dentry has the new name, parent link, and inode
55789 + for the renamed file
55790 + if a file is being replaced by a rename, new_dentry has the inode
55791 + and name for the replaced file
55792 + */
55793 +
55794 + if (unlikely(!(gr_status & GR_READY)))
55795 + return;
55796 +
55797 + preempt_disable();
55798 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
55799 +
55800 + /* we wouldn't have to check d_inode if it weren't for
55801 + NFS silly-renaming
55802 + */
55803 +
55804 + write_lock(&gr_inode_lock);
55805 + if (unlikely(replace && inode)) {
55806 + ino_t new_ino = inode->i_ino;
55807 + dev_t new_dev = __get_dev(new_dentry);
55808 +
55809 + inodev = lookup_inodev_entry(new_ino, new_dev);
55810 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
55811 + do_handle_delete(inodev, new_ino, new_dev);
55812 + }
55813 +
55814 + inodev = lookup_inodev_entry(old_ino, old_dev);
55815 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
55816 + do_handle_delete(inodev, old_ino, old_dev);
55817 +
55818 + if (unlikely((unsigned long)matchn))
55819 + do_handle_create(matchn, old_dentry, mnt);
55820 +
55821 + write_unlock(&gr_inode_lock);
55822 + preempt_enable();
55823 +
55824 + return;
55825 +}
55826 +
55827 +static int
55828 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
55829 + unsigned char **sum)
55830 +{
55831 + struct acl_role_label *r;
55832 + struct role_allowed_ip *ipp;
55833 + struct role_transition *trans;
55834 + unsigned int i;
55835 + int found = 0;
55836 + u32 curr_ip = current->signal->curr_ip;
55837 +
55838 + current->signal->saved_ip = curr_ip;
55839 +
55840 + /* check transition table */
55841 +
55842 + for (trans = current->role->transitions; trans; trans = trans->next) {
55843 + if (!strcmp(rolename, trans->rolename)) {
55844 + found = 1;
55845 + break;
55846 + }
55847 + }
55848 +
55849 + if (!found)
55850 + return 0;
55851 +
55852 + /* handle special roles that do not require authentication
55853 + and check ip */
55854 +
55855 + FOR_EACH_ROLE_START(r)
55856 + if (!strcmp(rolename, r->rolename) &&
55857 + (r->roletype & GR_ROLE_SPECIAL)) {
55858 + found = 0;
55859 + if (r->allowed_ips != NULL) {
55860 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
55861 + if ((ntohl(curr_ip) & ipp->netmask) ==
55862 + (ntohl(ipp->addr) & ipp->netmask))
55863 + found = 1;
55864 + }
55865 + } else
55866 + found = 2;
55867 + if (!found)
55868 + return 0;
55869 +
55870 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
55871 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
55872 + *salt = NULL;
55873 + *sum = NULL;
55874 + return 1;
55875 + }
55876 + }
55877 + FOR_EACH_ROLE_END(r)
55878 +
55879 + for (i = 0; i < num_sprole_pws; i++) {
55880 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
55881 + *salt = acl_special_roles[i]->salt;
55882 + *sum = acl_special_roles[i]->sum;
55883 + return 1;
55884 + }
55885 + }
55886 +
55887 + return 0;
55888 +}
55889 +
55890 +static void
55891 +assign_special_role(char *rolename)
55892 +{
55893 + struct acl_object_label *obj;
55894 + struct acl_role_label *r;
55895 + struct acl_role_label *assigned = NULL;
55896 + struct task_struct *tsk;
55897 + struct file *filp;
55898 +
55899 + FOR_EACH_ROLE_START(r)
55900 + if (!strcmp(rolename, r->rolename) &&
55901 + (r->roletype & GR_ROLE_SPECIAL)) {
55902 + assigned = r;
55903 + break;
55904 + }
55905 + FOR_EACH_ROLE_END(r)
55906 +
55907 + if (!assigned)
55908 + return;
55909 +
55910 + read_lock(&tasklist_lock);
55911 + read_lock(&grsec_exec_file_lock);
55912 +
55913 + tsk = current->real_parent;
55914 + if (tsk == NULL)
55915 + goto out_unlock;
55916 +
55917 + filp = tsk->exec_file;
55918 + if (filp == NULL)
55919 + goto out_unlock;
55920 +
55921 + tsk->is_writable = 0;
55922 +
55923 + tsk->acl_sp_role = 1;
55924 + tsk->acl_role_id = ++acl_sp_role_value;
55925 + tsk->role = assigned;
55926 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
55927 +
55928 + /* ignore additional mmap checks for processes that are writable
55929 + by the default ACL */
55930 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55931 + if (unlikely(obj->mode & GR_WRITE))
55932 + tsk->is_writable = 1;
55933 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
55934 + if (unlikely(obj->mode & GR_WRITE))
55935 + tsk->is_writable = 1;
55936 +
55937 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55938 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
55939 +#endif
55940 +
55941 +out_unlock:
55942 + read_unlock(&grsec_exec_file_lock);
55943 + read_unlock(&tasklist_lock);
55944 + return;
55945 +}
55946 +
55947 +int gr_check_secure_terminal(struct task_struct *task)
55948 +{
55949 + struct task_struct *p, *p2, *p3;
55950 + struct files_struct *files;
55951 + struct fdtable *fdt;
55952 + struct file *our_file = NULL, *file;
55953 + int i;
55954 +
55955 + if (task->signal->tty == NULL)
55956 + return 1;
55957 +
55958 + files = get_files_struct(task);
55959 + if (files != NULL) {
55960 + rcu_read_lock();
55961 + fdt = files_fdtable(files);
55962 + for (i=0; i < fdt->max_fds; i++) {
55963 + file = fcheck_files(files, i);
55964 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
55965 + get_file(file);
55966 + our_file = file;
55967 + }
55968 + }
55969 + rcu_read_unlock();
55970 + put_files_struct(files);
55971 + }
55972 +
55973 + if (our_file == NULL)
55974 + return 1;
55975 +
55976 + read_lock(&tasklist_lock);
55977 + do_each_thread(p2, p) {
55978 + files = get_files_struct(p);
55979 + if (files == NULL ||
55980 + (p->signal && p->signal->tty == task->signal->tty)) {
55981 + if (files != NULL)
55982 + put_files_struct(files);
55983 + continue;
55984 + }
55985 + rcu_read_lock();
55986 + fdt = files_fdtable(files);
55987 + for (i=0; i < fdt->max_fds; i++) {
55988 + file = fcheck_files(files, i);
55989 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
55990 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
55991 + p3 = task;
55992 + while (p3->pid > 0) {
55993 + if (p3 == p)
55994 + break;
55995 + p3 = p3->real_parent;
55996 + }
55997 + if (p3 == p)
55998 + break;
55999 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56000 + gr_handle_alertkill(p);
56001 + rcu_read_unlock();
56002 + put_files_struct(files);
56003 + read_unlock(&tasklist_lock);
56004 + fput(our_file);
56005 + return 0;
56006 + }
56007 + }
56008 + rcu_read_unlock();
56009 + put_files_struct(files);
56010 + } while_each_thread(p2, p);
56011 + read_unlock(&tasklist_lock);
56012 +
56013 + fput(our_file);
56014 + return 1;
56015 +}
56016 +
56017 +static int gr_rbac_disable(void *unused)
56018 +{
56019 + pax_open_kernel();
56020 + gr_status &= ~GR_READY;
56021 + pax_close_kernel();
56022 +
56023 + return 0;
56024 +}
56025 +
56026 +ssize_t
56027 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56028 +{
56029 + struct gr_arg_wrapper uwrap;
56030 + unsigned char *sprole_salt = NULL;
56031 + unsigned char *sprole_sum = NULL;
56032 + int error = sizeof (struct gr_arg_wrapper);
56033 + int error2 = 0;
56034 +
56035 + mutex_lock(&gr_dev_mutex);
56036 +
56037 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56038 + error = -EPERM;
56039 + goto out;
56040 + }
56041 +
56042 + if (count != sizeof (struct gr_arg_wrapper)) {
56043 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56044 + error = -EINVAL;
56045 + goto out;
56046 + }
56047 +
56048 +
56049 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56050 + gr_auth_expires = 0;
56051 + gr_auth_attempts = 0;
56052 + }
56053 +
56054 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56055 + error = -EFAULT;
56056 + goto out;
56057 + }
56058 +
56059 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56060 + error = -EINVAL;
56061 + goto out;
56062 + }
56063 +
56064 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56065 + error = -EFAULT;
56066 + goto out;
56067 + }
56068 +
56069 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56070 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56071 + time_after(gr_auth_expires, get_seconds())) {
56072 + error = -EBUSY;
56073 + goto out;
56074 + }
56075 +
56076 + /* if non-root trying to do anything other than use a special role,
56077 + do not attempt authentication, do not count towards authentication
56078 + locking
56079 + */
56080 +
56081 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56082 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56083 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56084 + error = -EPERM;
56085 + goto out;
56086 + }
56087 +
56088 + /* ensure pw and special role name are null terminated */
56089 +
56090 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56091 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56092 +
56093 + /* Okay.
56094 + * We have our enough of the argument structure..(we have yet
56095 + * to copy_from_user the tables themselves) . Copy the tables
56096 + * only if we need them, i.e. for loading operations. */
56097 +
56098 + switch (gr_usermode->mode) {
56099 + case GR_STATUS:
56100 + if (gr_status & GR_READY) {
56101 + error = 1;
56102 + if (!gr_check_secure_terminal(current))
56103 + error = 3;
56104 + } else
56105 + error = 2;
56106 + goto out;
56107 + case GR_SHUTDOWN:
56108 + if ((gr_status & GR_READY)
56109 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56110 + stop_machine(gr_rbac_disable, NULL, NULL);
56111 + free_variables();
56112 + memset(gr_usermode, 0, sizeof (struct gr_arg));
56113 + memset(gr_system_salt, 0, GR_SALT_LEN);
56114 + memset(gr_system_sum, 0, GR_SHA_LEN);
56115 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56116 + } else if (gr_status & GR_READY) {
56117 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56118 + error = -EPERM;
56119 + } else {
56120 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56121 + error = -EAGAIN;
56122 + }
56123 + break;
56124 + case GR_ENABLE:
56125 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56126 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56127 + else {
56128 + if (gr_status & GR_READY)
56129 + error = -EAGAIN;
56130 + else
56131 + error = error2;
56132 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56133 + }
56134 + break;
56135 + case GR_RELOAD:
56136 + if (!(gr_status & GR_READY)) {
56137 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56138 + error = -EAGAIN;
56139 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56140 + stop_machine(gr_rbac_disable, NULL, NULL);
56141 + free_variables();
56142 + error2 = gracl_init(gr_usermode);
56143 + if (!error2)
56144 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56145 + else {
56146 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56147 + error = error2;
56148 + }
56149 + } else {
56150 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56151 + error = -EPERM;
56152 + }
56153 + break;
56154 + case GR_SEGVMOD:
56155 + if (unlikely(!(gr_status & GR_READY))) {
56156 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56157 + error = -EAGAIN;
56158 + break;
56159 + }
56160 +
56161 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56162 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56163 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56164 + struct acl_subject_label *segvacl;
56165 + segvacl =
56166 + lookup_acl_subj_label(gr_usermode->segv_inode,
56167 + gr_usermode->segv_device,
56168 + current->role);
56169 + if (segvacl) {
56170 + segvacl->crashes = 0;
56171 + segvacl->expires = 0;
56172 + }
56173 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56174 + gr_remove_uid(gr_usermode->segv_uid);
56175 + }
56176 + } else {
56177 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56178 + error = -EPERM;
56179 + }
56180 + break;
56181 + case GR_SPROLE:
56182 + case GR_SPROLEPAM:
56183 + if (unlikely(!(gr_status & GR_READY))) {
56184 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56185 + error = -EAGAIN;
56186 + break;
56187 + }
56188 +
56189 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56190 + current->role->expires = 0;
56191 + current->role->auth_attempts = 0;
56192 + }
56193 +
56194 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56195 + time_after(current->role->expires, get_seconds())) {
56196 + error = -EBUSY;
56197 + goto out;
56198 + }
56199 +
56200 + if (lookup_special_role_auth
56201 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56202 + && ((!sprole_salt && !sprole_sum)
56203 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56204 + char *p = "";
56205 + assign_special_role(gr_usermode->sp_role);
56206 + read_lock(&tasklist_lock);
56207 + if (current->real_parent)
56208 + p = current->real_parent->role->rolename;
56209 + read_unlock(&tasklist_lock);
56210 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56211 + p, acl_sp_role_value);
56212 + } else {
56213 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56214 + error = -EPERM;
56215 + if(!(current->role->auth_attempts++))
56216 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56217 +
56218 + goto out;
56219 + }
56220 + break;
56221 + case GR_UNSPROLE:
56222 + if (unlikely(!(gr_status & GR_READY))) {
56223 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56224 + error = -EAGAIN;
56225 + break;
56226 + }
56227 +
56228 + if (current->role->roletype & GR_ROLE_SPECIAL) {
56229 + char *p = "";
56230 + int i = 0;
56231 +
56232 + read_lock(&tasklist_lock);
56233 + if (current->real_parent) {
56234 + p = current->real_parent->role->rolename;
56235 + i = current->real_parent->acl_role_id;
56236 + }
56237 + read_unlock(&tasklist_lock);
56238 +
56239 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
56240 + gr_set_acls(1);
56241 + } else {
56242 + error = -EPERM;
56243 + goto out;
56244 + }
56245 + break;
56246 + default:
56247 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
56248 + error = -EINVAL;
56249 + break;
56250 + }
56251 +
56252 + if (error != -EPERM)
56253 + goto out;
56254 +
56255 + if(!(gr_auth_attempts++))
56256 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56257 +
56258 + out:
56259 + mutex_unlock(&gr_dev_mutex);
56260 + return error;
56261 +}
56262 +
56263 +/* must be called with
56264 + rcu_read_lock();
56265 + read_lock(&tasklist_lock);
56266 + read_lock(&grsec_exec_file_lock);
56267 +*/
56268 +int gr_apply_subject_to_task(struct task_struct *task)
56269 +{
56270 + struct acl_object_label *obj;
56271 + char *tmpname;
56272 + struct acl_subject_label *tmpsubj;
56273 + struct file *filp;
56274 + struct name_entry *nmatch;
56275 +
56276 + filp = task->exec_file;
56277 + if (filp == NULL)
56278 + return 0;
56279 +
56280 + /* the following is to apply the correct subject
56281 + on binaries running when the RBAC system
56282 + is enabled, when the binaries have been
56283 + replaced or deleted since their execution
56284 + -----
56285 + when the RBAC system starts, the inode/dev
56286 + from exec_file will be one the RBAC system
56287 + is unaware of. It only knows the inode/dev
56288 + of the present file on disk, or the absence
56289 + of it.
56290 + */
56291 + preempt_disable();
56292 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
56293 +
56294 + nmatch = lookup_name_entry(tmpname);
56295 + preempt_enable();
56296 + tmpsubj = NULL;
56297 + if (nmatch) {
56298 + if (nmatch->deleted)
56299 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
56300 + else
56301 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
56302 + if (tmpsubj != NULL)
56303 + task->acl = tmpsubj;
56304 + }
56305 + if (tmpsubj == NULL)
56306 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
56307 + task->role);
56308 + if (task->acl) {
56309 + task->is_writable = 0;
56310 + /* ignore additional mmap checks for processes that are writable
56311 + by the default ACL */
56312 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56313 + if (unlikely(obj->mode & GR_WRITE))
56314 + task->is_writable = 1;
56315 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56316 + if (unlikely(obj->mode & GR_WRITE))
56317 + task->is_writable = 1;
56318 +
56319 + gr_set_proc_res(task);
56320 +
56321 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56322 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56323 +#endif
56324 + } else {
56325 + return 1;
56326 + }
56327 +
56328 + return 0;
56329 +}
56330 +
56331 +int
56332 +gr_set_acls(const int type)
56333 +{
56334 + struct task_struct *task, *task2;
56335 + struct acl_role_label *role = current->role;
56336 + __u16 acl_role_id = current->acl_role_id;
56337 + const struct cred *cred;
56338 + int ret;
56339 +
56340 + rcu_read_lock();
56341 + read_lock(&tasklist_lock);
56342 + read_lock(&grsec_exec_file_lock);
56343 + do_each_thread(task2, task) {
56344 + /* check to see if we're called from the exit handler,
56345 + if so, only replace ACLs that have inherited the admin
56346 + ACL */
56347 +
56348 + if (type && (task->role != role ||
56349 + task->acl_role_id != acl_role_id))
56350 + continue;
56351 +
56352 + task->acl_role_id = 0;
56353 + task->acl_sp_role = 0;
56354 +
56355 + if (task->exec_file) {
56356 + cred = __task_cred(task);
56357 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
56358 + ret = gr_apply_subject_to_task(task);
56359 + if (ret) {
56360 + read_unlock(&grsec_exec_file_lock);
56361 + read_unlock(&tasklist_lock);
56362 + rcu_read_unlock();
56363 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
56364 + return ret;
56365 + }
56366 + } else {
56367 + // it's a kernel process
56368 + task->role = kernel_role;
56369 + task->acl = kernel_role->root_label;
56370 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
56371 + task->acl->mode &= ~GR_PROCFIND;
56372 +#endif
56373 + }
56374 + } while_each_thread(task2, task);
56375 + read_unlock(&grsec_exec_file_lock);
56376 + read_unlock(&tasklist_lock);
56377 + rcu_read_unlock();
56378 +
56379 + return 0;
56380 +}
56381 +
56382 +void
56383 +gr_learn_resource(const struct task_struct *task,
56384 + const int res, const unsigned long wanted, const int gt)
56385 +{
56386 + struct acl_subject_label *acl;
56387 + const struct cred *cred;
56388 +
56389 + if (unlikely((gr_status & GR_READY) &&
56390 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
56391 + goto skip_reslog;
56392 +
56393 +#ifdef CONFIG_GRKERNSEC_RESLOG
56394 + gr_log_resource(task, res, wanted, gt);
56395 +#endif
56396 + skip_reslog:
56397 +
56398 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
56399 + return;
56400 +
56401 + acl = task->acl;
56402 +
56403 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
56404 + !(acl->resmask & (1 << (unsigned short) res))))
56405 + return;
56406 +
56407 + if (wanted >= acl->res[res].rlim_cur) {
56408 + unsigned long res_add;
56409 +
56410 + res_add = wanted;
56411 + switch (res) {
56412 + case RLIMIT_CPU:
56413 + res_add += GR_RLIM_CPU_BUMP;
56414 + break;
56415 + case RLIMIT_FSIZE:
56416 + res_add += GR_RLIM_FSIZE_BUMP;
56417 + break;
56418 + case RLIMIT_DATA:
56419 + res_add += GR_RLIM_DATA_BUMP;
56420 + break;
56421 + case RLIMIT_STACK:
56422 + res_add += GR_RLIM_STACK_BUMP;
56423 + break;
56424 + case RLIMIT_CORE:
56425 + res_add += GR_RLIM_CORE_BUMP;
56426 + break;
56427 + case RLIMIT_RSS:
56428 + res_add += GR_RLIM_RSS_BUMP;
56429 + break;
56430 + case RLIMIT_NPROC:
56431 + res_add += GR_RLIM_NPROC_BUMP;
56432 + break;
56433 + case RLIMIT_NOFILE:
56434 + res_add += GR_RLIM_NOFILE_BUMP;
56435 + break;
56436 + case RLIMIT_MEMLOCK:
56437 + res_add += GR_RLIM_MEMLOCK_BUMP;
56438 + break;
56439 + case RLIMIT_AS:
56440 + res_add += GR_RLIM_AS_BUMP;
56441 + break;
56442 + case RLIMIT_LOCKS:
56443 + res_add += GR_RLIM_LOCKS_BUMP;
56444 + break;
56445 + case RLIMIT_SIGPENDING:
56446 + res_add += GR_RLIM_SIGPENDING_BUMP;
56447 + break;
56448 + case RLIMIT_MSGQUEUE:
56449 + res_add += GR_RLIM_MSGQUEUE_BUMP;
56450 + break;
56451 + case RLIMIT_NICE:
56452 + res_add += GR_RLIM_NICE_BUMP;
56453 + break;
56454 + case RLIMIT_RTPRIO:
56455 + res_add += GR_RLIM_RTPRIO_BUMP;
56456 + break;
56457 + case RLIMIT_RTTIME:
56458 + res_add += GR_RLIM_RTTIME_BUMP;
56459 + break;
56460 + }
56461 +
56462 + acl->res[res].rlim_cur = res_add;
56463 +
56464 + if (wanted > acl->res[res].rlim_max)
56465 + acl->res[res].rlim_max = res_add;
56466 +
56467 + /* only log the subject filename, since resource logging is supported for
56468 + single-subject learning only */
56469 + rcu_read_lock();
56470 + cred = __task_cred(task);
56471 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56472 + task->role->roletype, cred->uid, cred->gid, acl->filename,
56473 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
56474 + "", (unsigned long) res, &task->signal->saved_ip);
56475 + rcu_read_unlock();
56476 + }
56477 +
56478 + return;
56479 +}
56480 +
56481 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
56482 +void
56483 +pax_set_initial_flags(struct linux_binprm *bprm)
56484 +{
56485 + struct task_struct *task = current;
56486 + struct acl_subject_label *proc;
56487 + unsigned long flags;
56488 +
56489 + if (unlikely(!(gr_status & GR_READY)))
56490 + return;
56491 +
56492 + flags = pax_get_flags(task);
56493 +
56494 + proc = task->acl;
56495 +
56496 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
56497 + flags &= ~MF_PAX_PAGEEXEC;
56498 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
56499 + flags &= ~MF_PAX_SEGMEXEC;
56500 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
56501 + flags &= ~MF_PAX_RANDMMAP;
56502 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
56503 + flags &= ~MF_PAX_EMUTRAMP;
56504 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
56505 + flags &= ~MF_PAX_MPROTECT;
56506 +
56507 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
56508 + flags |= MF_PAX_PAGEEXEC;
56509 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
56510 + flags |= MF_PAX_SEGMEXEC;
56511 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
56512 + flags |= MF_PAX_RANDMMAP;
56513 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
56514 + flags |= MF_PAX_EMUTRAMP;
56515 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
56516 + flags |= MF_PAX_MPROTECT;
56517 +
56518 + pax_set_flags(task, flags);
56519 +
56520 + return;
56521 +}
56522 +#endif
56523 +
56524 +int
56525 +gr_handle_proc_ptrace(struct task_struct *task)
56526 +{
56527 + struct file *filp;
56528 + struct task_struct *tmp = task;
56529 + struct task_struct *curtemp = current;
56530 + __u32 retmode;
56531 +
56532 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
56533 + if (unlikely(!(gr_status & GR_READY)))
56534 + return 0;
56535 +#endif
56536 +
56537 + read_lock(&tasklist_lock);
56538 + read_lock(&grsec_exec_file_lock);
56539 + filp = task->exec_file;
56540 +
56541 + while (tmp->pid > 0) {
56542 + if (tmp == curtemp)
56543 + break;
56544 + tmp = tmp->real_parent;
56545 + }
56546 +
56547 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
56548 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
56549 + read_unlock(&grsec_exec_file_lock);
56550 + read_unlock(&tasklist_lock);
56551 + return 1;
56552 + }
56553 +
56554 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56555 + if (!(gr_status & GR_READY)) {
56556 + read_unlock(&grsec_exec_file_lock);
56557 + read_unlock(&tasklist_lock);
56558 + return 0;
56559 + }
56560 +#endif
56561 +
56562 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
56563 + read_unlock(&grsec_exec_file_lock);
56564 + read_unlock(&tasklist_lock);
56565 +
56566 + if (retmode & GR_NOPTRACE)
56567 + return 1;
56568 +
56569 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
56570 + && (current->acl != task->acl || (current->acl != current->role->root_label
56571 + && current->pid != task->pid)))
56572 + return 1;
56573 +
56574 + return 0;
56575 +}
56576 +
56577 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
56578 +{
56579 + if (unlikely(!(gr_status & GR_READY)))
56580 + return;
56581 +
56582 + if (!(current->role->roletype & GR_ROLE_GOD))
56583 + return;
56584 +
56585 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
56586 + p->role->rolename, gr_task_roletype_to_char(p),
56587 + p->acl->filename);
56588 +}
56589 +
56590 +int
56591 +gr_handle_ptrace(struct task_struct *task, const long request)
56592 +{
56593 + struct task_struct *tmp = task;
56594 + struct task_struct *curtemp = current;
56595 + __u32 retmode;
56596 +
56597 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
56598 + if (unlikely(!(gr_status & GR_READY)))
56599 + return 0;
56600 +#endif
56601 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
56602 + read_lock(&tasklist_lock);
56603 + while (tmp->pid > 0) {
56604 + if (tmp == curtemp)
56605 + break;
56606 + tmp = tmp->real_parent;
56607 + }
56608 +
56609 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
56610 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
56611 + read_unlock(&tasklist_lock);
56612 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56613 + return 1;
56614 + }
56615 + read_unlock(&tasklist_lock);
56616 + }
56617 +
56618 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56619 + if (!(gr_status & GR_READY))
56620 + return 0;
56621 +#endif
56622 +
56623 + read_lock(&grsec_exec_file_lock);
56624 + if (unlikely(!task->exec_file)) {
56625 + read_unlock(&grsec_exec_file_lock);
56626 + return 0;
56627 + }
56628 +
56629 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
56630 + read_unlock(&grsec_exec_file_lock);
56631 +
56632 + if (retmode & GR_NOPTRACE) {
56633 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56634 + return 1;
56635 + }
56636 +
56637 + if (retmode & GR_PTRACERD) {
56638 + switch (request) {
56639 + case PTRACE_SEIZE:
56640 + case PTRACE_POKETEXT:
56641 + case PTRACE_POKEDATA:
56642 + case PTRACE_POKEUSR:
56643 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
56644 + case PTRACE_SETREGS:
56645 + case PTRACE_SETFPREGS:
56646 +#endif
56647 +#ifdef CONFIG_X86
56648 + case PTRACE_SETFPXREGS:
56649 +#endif
56650 +#ifdef CONFIG_ALTIVEC
56651 + case PTRACE_SETVRREGS:
56652 +#endif
56653 + return 1;
56654 + default:
56655 + return 0;
56656 + }
56657 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
56658 + !(current->role->roletype & GR_ROLE_GOD) &&
56659 + (current->acl != task->acl)) {
56660 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56661 + return 1;
56662 + }
56663 +
56664 + return 0;
56665 +}
56666 +
56667 +static int is_writable_mmap(const struct file *filp)
56668 +{
56669 + struct task_struct *task = current;
56670 + struct acl_object_label *obj, *obj2;
56671 +
56672 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
56673 + !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))) {
56674 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56675 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
56676 + task->role->root_label);
56677 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
56678 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
56679 + return 1;
56680 + }
56681 + }
56682 + return 0;
56683 +}
56684 +
56685 +int
56686 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
56687 +{
56688 + __u32 mode;
56689 +
56690 + if (unlikely(!file || !(prot & PROT_EXEC)))
56691 + return 1;
56692 +
56693 + if (is_writable_mmap(file))
56694 + return 0;
56695 +
56696 + mode =
56697 + gr_search_file(file->f_path.dentry,
56698 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
56699 + file->f_path.mnt);
56700 +
56701 + if (!gr_tpe_allow(file))
56702 + return 0;
56703 +
56704 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
56705 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56706 + return 0;
56707 + } else if (unlikely(!(mode & GR_EXEC))) {
56708 + return 0;
56709 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
56710 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56711 + return 1;
56712 + }
56713 +
56714 + return 1;
56715 +}
56716 +
56717 +int
56718 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56719 +{
56720 + __u32 mode;
56721 +
56722 + if (unlikely(!file || !(prot & PROT_EXEC)))
56723 + return 1;
56724 +
56725 + if (is_writable_mmap(file))
56726 + return 0;
56727 +
56728 + mode =
56729 + gr_search_file(file->f_path.dentry,
56730 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
56731 + file->f_path.mnt);
56732 +
56733 + if (!gr_tpe_allow(file))
56734 + return 0;
56735 +
56736 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
56737 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56738 + return 0;
56739 + } else if (unlikely(!(mode & GR_EXEC))) {
56740 + return 0;
56741 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
56742 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56743 + return 1;
56744 + }
56745 +
56746 + return 1;
56747 +}
56748 +
56749 +void
56750 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56751 +{
56752 + unsigned long runtime;
56753 + unsigned long cputime;
56754 + unsigned int wday, cday;
56755 + __u8 whr, chr;
56756 + __u8 wmin, cmin;
56757 + __u8 wsec, csec;
56758 + struct timespec timeval;
56759 +
56760 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
56761 + !(task->acl->mode & GR_PROCACCT)))
56762 + return;
56763 +
56764 + do_posix_clock_monotonic_gettime(&timeval);
56765 + runtime = timeval.tv_sec - task->start_time.tv_sec;
56766 + wday = runtime / (3600 * 24);
56767 + runtime -= wday * (3600 * 24);
56768 + whr = runtime / 3600;
56769 + runtime -= whr * 3600;
56770 + wmin = runtime / 60;
56771 + runtime -= wmin * 60;
56772 + wsec = runtime;
56773 +
56774 + cputime = (task->utime + task->stime) / HZ;
56775 + cday = cputime / (3600 * 24);
56776 + cputime -= cday * (3600 * 24);
56777 + chr = cputime / 3600;
56778 + cputime -= chr * 3600;
56779 + cmin = cputime / 60;
56780 + cputime -= cmin * 60;
56781 + csec = cputime;
56782 +
56783 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
56784 +
56785 + return;
56786 +}
56787 +
56788 +void gr_set_kernel_label(struct task_struct *task)
56789 +{
56790 + if (gr_status & GR_READY) {
56791 + task->role = kernel_role;
56792 + task->acl = kernel_role->root_label;
56793 + }
56794 + return;
56795 +}
56796 +
56797 +#ifdef CONFIG_TASKSTATS
56798 +int gr_is_taskstats_denied(int pid)
56799 +{
56800 + struct task_struct *task;
56801 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56802 + const struct cred *cred;
56803 +#endif
56804 + int ret = 0;
56805 +
56806 + /* restrict taskstats viewing to un-chrooted root users
56807 + who have the 'view' subject flag if the RBAC system is enabled
56808 + */
56809 +
56810 + rcu_read_lock();
56811 + read_lock(&tasklist_lock);
56812 + task = find_task_by_vpid(pid);
56813 + if (task) {
56814 +#ifdef CONFIG_GRKERNSEC_CHROOT
56815 + if (proc_is_chrooted(task))
56816 + ret = -EACCES;
56817 +#endif
56818 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56819 + cred = __task_cred(task);
56820 +#ifdef CONFIG_GRKERNSEC_PROC_USER
56821 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
56822 + ret = -EACCES;
56823 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56824 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
56825 + ret = -EACCES;
56826 +#endif
56827 +#endif
56828 + if (gr_status & GR_READY) {
56829 + if (!(task->acl->mode & GR_VIEW))
56830 + ret = -EACCES;
56831 + }
56832 + } else
56833 + ret = -ENOENT;
56834 +
56835 + read_unlock(&tasklist_lock);
56836 + rcu_read_unlock();
56837 +
56838 + return ret;
56839 +}
56840 +#endif
56841 +
56842 +/* AUXV entries are filled via a descendant of search_binary_handler
56843 + after we've already applied the subject for the target
56844 +*/
56845 +int gr_acl_enable_at_secure(void)
56846 +{
56847 + if (unlikely(!(gr_status & GR_READY)))
56848 + return 0;
56849 +
56850 + if (current->acl->mode & GR_ATSECURE)
56851 + return 1;
56852 +
56853 + return 0;
56854 +}
56855 +
56856 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
56857 +{
56858 + struct task_struct *task = current;
56859 + struct dentry *dentry = file->f_path.dentry;
56860 + struct vfsmount *mnt = file->f_path.mnt;
56861 + struct acl_object_label *obj, *tmp;
56862 + struct acl_subject_label *subj;
56863 + unsigned int bufsize;
56864 + int is_not_root;
56865 + char *path;
56866 + dev_t dev = __get_dev(dentry);
56867 +
56868 + if (unlikely(!(gr_status & GR_READY)))
56869 + return 1;
56870 +
56871 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56872 + return 1;
56873 +
56874 + /* ignore Eric Biederman */
56875 + if (IS_PRIVATE(dentry->d_inode))
56876 + return 1;
56877 +
56878 + subj = task->acl;
56879 + read_lock(&gr_inode_lock);
56880 + do {
56881 + obj = lookup_acl_obj_label(ino, dev, subj);
56882 + if (obj != NULL) {
56883 + read_unlock(&gr_inode_lock);
56884 + return (obj->mode & GR_FIND) ? 1 : 0;
56885 + }
56886 + } while ((subj = subj->parent_subject));
56887 + read_unlock(&gr_inode_lock);
56888 +
56889 + /* this is purely an optimization since we're looking for an object
56890 + for the directory we're doing a readdir on
56891 + if it's possible for any globbed object to match the entry we're
56892 + filling into the directory, then the object we find here will be
56893 + an anchor point with attached globbed objects
56894 + */
56895 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
56896 + if (obj->globbed == NULL)
56897 + return (obj->mode & GR_FIND) ? 1 : 0;
56898 +
56899 + is_not_root = ((obj->filename[0] == '/') &&
56900 + (obj->filename[1] == '\0')) ? 0 : 1;
56901 + bufsize = PAGE_SIZE - namelen - is_not_root;
56902 +
56903 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
56904 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
56905 + return 1;
56906 +
56907 + preempt_disable();
56908 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
56909 + bufsize);
56910 +
56911 + bufsize = strlen(path);
56912 +
56913 + /* if base is "/", don't append an additional slash */
56914 + if (is_not_root)
56915 + *(path + bufsize) = '/';
56916 + memcpy(path + bufsize + is_not_root, name, namelen);
56917 + *(path + bufsize + namelen + is_not_root) = '\0';
56918 +
56919 + tmp = obj->globbed;
56920 + while (tmp) {
56921 + if (!glob_match(tmp->filename, path)) {
56922 + preempt_enable();
56923 + return (tmp->mode & GR_FIND) ? 1 : 0;
56924 + }
56925 + tmp = tmp->next;
56926 + }
56927 + preempt_enable();
56928 + return (obj->mode & GR_FIND) ? 1 : 0;
56929 +}
56930 +
56931 +void gr_put_exec_file(struct task_struct *task)
56932 +{
56933 + struct file *filp;
56934 +
56935 + write_lock(&grsec_exec_file_lock);
56936 + filp = task->exec_file;
56937 + task->exec_file = NULL;
56938 + write_unlock(&grsec_exec_file_lock);
56939 +
56940 + if (filp)
56941 + fput(filp);
56942 +
56943 + return;
56944 +}
56945 +
56946 +
56947 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
56948 +EXPORT_SYMBOL(gr_acl_is_enabled);
56949 +#endif
56950 +EXPORT_SYMBOL(gr_learn_resource);
56951 +EXPORT_SYMBOL(gr_set_kernel_label);
56952 +#ifdef CONFIG_SECURITY
56953 +EXPORT_SYMBOL(gr_check_user_change);
56954 +EXPORT_SYMBOL(gr_check_group_change);
56955 +#endif
56956 +
56957 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
56958 new file mode 100644
56959 index 0000000..34fefda
56960 --- /dev/null
56961 +++ b/grsecurity/gracl_alloc.c
56962 @@ -0,0 +1,105 @@
56963 +#include <linux/kernel.h>
56964 +#include <linux/mm.h>
56965 +#include <linux/slab.h>
56966 +#include <linux/vmalloc.h>
56967 +#include <linux/gracl.h>
56968 +#include <linux/grsecurity.h>
56969 +
56970 +static unsigned long alloc_stack_next = 1;
56971 +static unsigned long alloc_stack_size = 1;
56972 +static void **alloc_stack;
56973 +
56974 +static __inline__ int
56975 +alloc_pop(void)
56976 +{
56977 + if (alloc_stack_next == 1)
56978 + return 0;
56979 +
56980 + kfree(alloc_stack[alloc_stack_next - 2]);
56981 +
56982 + alloc_stack_next--;
56983 +
56984 + return 1;
56985 +}
56986 +
56987 +static __inline__ int
56988 +alloc_push(void *buf)
56989 +{
56990 + if (alloc_stack_next >= alloc_stack_size)
56991 + return 1;
56992 +
56993 + alloc_stack[alloc_stack_next - 1] = buf;
56994 +
56995 + alloc_stack_next++;
56996 +
56997 + return 0;
56998 +}
56999 +
57000 +void *
57001 +acl_alloc(unsigned long len)
57002 +{
57003 + void *ret = NULL;
57004 +
57005 + if (!len || len > PAGE_SIZE)
57006 + goto out;
57007 +
57008 + ret = kmalloc(len, GFP_KERNEL);
57009 +
57010 + if (ret) {
57011 + if (alloc_push(ret)) {
57012 + kfree(ret);
57013 + ret = NULL;
57014 + }
57015 + }
57016 +
57017 +out:
57018 + return ret;
57019 +}
57020 +
57021 +void *
57022 +acl_alloc_num(unsigned long num, unsigned long len)
57023 +{
57024 + if (!len || (num > (PAGE_SIZE / len)))
57025 + return NULL;
57026 +
57027 + return acl_alloc(num * len);
57028 +}
57029 +
57030 +void
57031 +acl_free_all(void)
57032 +{
57033 + if (gr_acl_is_enabled() || !alloc_stack)
57034 + return;
57035 +
57036 + while (alloc_pop()) ;
57037 +
57038 + if (alloc_stack) {
57039 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57040 + kfree(alloc_stack);
57041 + else
57042 + vfree(alloc_stack);
57043 + }
57044 +
57045 + alloc_stack = NULL;
57046 + alloc_stack_size = 1;
57047 + alloc_stack_next = 1;
57048 +
57049 + return;
57050 +}
57051 +
57052 +int
57053 +acl_alloc_stack_init(unsigned long size)
57054 +{
57055 + if ((size * sizeof (void *)) <= PAGE_SIZE)
57056 + alloc_stack =
57057 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57058 + else
57059 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
57060 +
57061 + alloc_stack_size = size;
57062 +
57063 + if (!alloc_stack)
57064 + return 0;
57065 + else
57066 + return 1;
57067 +}
57068 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57069 new file mode 100644
57070 index 0000000..6d21049
57071 --- /dev/null
57072 +++ b/grsecurity/gracl_cap.c
57073 @@ -0,0 +1,110 @@
57074 +#include <linux/kernel.h>
57075 +#include <linux/module.h>
57076 +#include <linux/sched.h>
57077 +#include <linux/gracl.h>
57078 +#include <linux/grsecurity.h>
57079 +#include <linux/grinternal.h>
57080 +
57081 +extern const char *captab_log[];
57082 +extern int captab_log_entries;
57083 +
57084 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57085 +{
57086 + struct acl_subject_label *curracl;
57087 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57088 + kernel_cap_t cap_audit = __cap_empty_set;
57089 +
57090 + if (!gr_acl_is_enabled())
57091 + return 1;
57092 +
57093 + curracl = task->acl;
57094 +
57095 + cap_drop = curracl->cap_lower;
57096 + cap_mask = curracl->cap_mask;
57097 + cap_audit = curracl->cap_invert_audit;
57098 +
57099 + while ((curracl = curracl->parent_subject)) {
57100 + /* if the cap isn't specified in the current computed mask but is specified in the
57101 + current level subject, and is lowered in the current level subject, then add
57102 + it to the set of dropped capabilities
57103 + otherwise, add the current level subject's mask to the current computed mask
57104 + */
57105 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57106 + cap_raise(cap_mask, cap);
57107 + if (cap_raised(curracl->cap_lower, cap))
57108 + cap_raise(cap_drop, cap);
57109 + if (cap_raised(curracl->cap_invert_audit, cap))
57110 + cap_raise(cap_audit, cap);
57111 + }
57112 + }
57113 +
57114 + if (!cap_raised(cap_drop, cap)) {
57115 + if (cap_raised(cap_audit, cap))
57116 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57117 + return 1;
57118 + }
57119 +
57120 + curracl = task->acl;
57121 +
57122 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57123 + && cap_raised(cred->cap_effective, cap)) {
57124 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57125 + task->role->roletype, cred->uid,
57126 + cred->gid, task->exec_file ?
57127 + gr_to_filename(task->exec_file->f_path.dentry,
57128 + task->exec_file->f_path.mnt) : curracl->filename,
57129 + curracl->filename, 0UL,
57130 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57131 + return 1;
57132 + }
57133 +
57134 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57135 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57136 +
57137 + return 0;
57138 +}
57139 +
57140 +int
57141 +gr_acl_is_capable(const int cap)
57142 +{
57143 + return gr_task_acl_is_capable(current, current_cred(), cap);
57144 +}
57145 +
57146 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57147 +{
57148 + struct acl_subject_label *curracl;
57149 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57150 +
57151 + if (!gr_acl_is_enabled())
57152 + return 1;
57153 +
57154 + curracl = task->acl;
57155 +
57156 + cap_drop = curracl->cap_lower;
57157 + cap_mask = curracl->cap_mask;
57158 +
57159 + while ((curracl = curracl->parent_subject)) {
57160 + /* if the cap isn't specified in the current computed mask but is specified in the
57161 + current level subject, and is lowered in the current level subject, then add
57162 + it to the set of dropped capabilities
57163 + otherwise, add the current level subject's mask to the current computed mask
57164 + */
57165 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57166 + cap_raise(cap_mask, cap);
57167 + if (cap_raised(curracl->cap_lower, cap))
57168 + cap_raise(cap_drop, cap);
57169 + }
57170 + }
57171 +
57172 + if (!cap_raised(cap_drop, cap))
57173 + return 1;
57174 +
57175 + return 0;
57176 +}
57177 +
57178 +int
57179 +gr_acl_is_capable_nolog(const int cap)
57180 +{
57181 + return gr_task_acl_is_capable_nolog(current, cap);
57182 +}
57183 +
57184 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57185 new file mode 100644
57186 index 0000000..a340c17
57187 --- /dev/null
57188 +++ b/grsecurity/gracl_fs.c
57189 @@ -0,0 +1,431 @@
57190 +#include <linux/kernel.h>
57191 +#include <linux/sched.h>
57192 +#include <linux/types.h>
57193 +#include <linux/fs.h>
57194 +#include <linux/file.h>
57195 +#include <linux/stat.h>
57196 +#include <linux/grsecurity.h>
57197 +#include <linux/grinternal.h>
57198 +#include <linux/gracl.h>
57199 +
57200 +umode_t
57201 +gr_acl_umask(void)
57202 +{
57203 + if (unlikely(!gr_acl_is_enabled()))
57204 + return 0;
57205 +
57206 + return current->role->umask;
57207 +}
57208 +
57209 +__u32
57210 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57211 + const struct vfsmount * mnt)
57212 +{
57213 + __u32 mode;
57214 +
57215 + if (unlikely(!dentry->d_inode))
57216 + return GR_FIND;
57217 +
57218 + mode =
57219 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57220 +
57221 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57222 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57223 + return mode;
57224 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57225 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57226 + return 0;
57227 + } else if (unlikely(!(mode & GR_FIND)))
57228 + return 0;
57229 +
57230 + return GR_FIND;
57231 +}
57232 +
57233 +__u32
57234 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57235 + int acc_mode)
57236 +{
57237 + __u32 reqmode = GR_FIND;
57238 + __u32 mode;
57239 +
57240 + if (unlikely(!dentry->d_inode))
57241 + return reqmode;
57242 +
57243 + if (acc_mode & MAY_APPEND)
57244 + reqmode |= GR_APPEND;
57245 + else if (acc_mode & MAY_WRITE)
57246 + reqmode |= GR_WRITE;
57247 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57248 + reqmode |= GR_READ;
57249 +
57250 + mode =
57251 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57252 + mnt);
57253 +
57254 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57255 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57256 + reqmode & GR_READ ? " reading" : "",
57257 + reqmode & GR_WRITE ? " writing" : reqmode &
57258 + GR_APPEND ? " appending" : "");
57259 + return reqmode;
57260 + } else
57261 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57262 + {
57263 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57264 + reqmode & GR_READ ? " reading" : "",
57265 + reqmode & GR_WRITE ? " writing" : reqmode &
57266 + GR_APPEND ? " appending" : "");
57267 + return 0;
57268 + } else if (unlikely((mode & reqmode) != reqmode))
57269 + return 0;
57270 +
57271 + return reqmode;
57272 +}
57273 +
57274 +__u32
57275 +gr_acl_handle_creat(const struct dentry * dentry,
57276 + const struct dentry * p_dentry,
57277 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57278 + const int imode)
57279 +{
57280 + __u32 reqmode = GR_WRITE | GR_CREATE;
57281 + __u32 mode;
57282 +
57283 + if (acc_mode & MAY_APPEND)
57284 + reqmode |= GR_APPEND;
57285 + // if a directory was required or the directory already exists, then
57286 + // don't count this open as a read
57287 + if ((acc_mode & MAY_READ) &&
57288 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
57289 + reqmode |= GR_READ;
57290 + if ((open_flags & O_CREAT) &&
57291 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57292 + reqmode |= GR_SETID;
57293 +
57294 + mode =
57295 + gr_check_create(dentry, p_dentry, p_mnt,
57296 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57297 +
57298 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57299 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57300 + reqmode & GR_READ ? " reading" : "",
57301 + reqmode & GR_WRITE ? " writing" : reqmode &
57302 + GR_APPEND ? " appending" : "");
57303 + return reqmode;
57304 + } else
57305 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57306 + {
57307 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57308 + reqmode & GR_READ ? " reading" : "",
57309 + reqmode & GR_WRITE ? " writing" : reqmode &
57310 + GR_APPEND ? " appending" : "");
57311 + return 0;
57312 + } else if (unlikely((mode & reqmode) != reqmode))
57313 + return 0;
57314 +
57315 + return reqmode;
57316 +}
57317 +
57318 +__u32
57319 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
57320 + const int fmode)
57321 +{
57322 + __u32 mode, reqmode = GR_FIND;
57323 +
57324 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
57325 + reqmode |= GR_EXEC;
57326 + if (fmode & S_IWOTH)
57327 + reqmode |= GR_WRITE;
57328 + if (fmode & S_IROTH)
57329 + reqmode |= GR_READ;
57330 +
57331 + mode =
57332 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57333 + mnt);
57334 +
57335 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57336 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57337 + reqmode & GR_READ ? " reading" : "",
57338 + reqmode & GR_WRITE ? " writing" : "",
57339 + reqmode & GR_EXEC ? " executing" : "");
57340 + return reqmode;
57341 + } else
57342 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57343 + {
57344 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57345 + reqmode & GR_READ ? " reading" : "",
57346 + reqmode & GR_WRITE ? " writing" : "",
57347 + reqmode & GR_EXEC ? " executing" : "");
57348 + return 0;
57349 + } else if (unlikely((mode & reqmode) != reqmode))
57350 + return 0;
57351 +
57352 + return reqmode;
57353 +}
57354 +
57355 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
57356 +{
57357 + __u32 mode;
57358 +
57359 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
57360 +
57361 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57362 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
57363 + return mode;
57364 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57365 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
57366 + return 0;
57367 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
57368 + return 0;
57369 +
57370 + return (reqmode);
57371 +}
57372 +
57373 +__u32
57374 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57375 +{
57376 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
57377 +}
57378 +
57379 +__u32
57380 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
57381 +{
57382 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
57383 +}
57384 +
57385 +__u32
57386 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
57387 +{
57388 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
57389 +}
57390 +
57391 +__u32
57392 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
57393 +{
57394 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
57395 +}
57396 +
57397 +__u32
57398 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
57399 + umode_t *modeptr)
57400 +{
57401 + umode_t mode;
57402 +
57403 + *modeptr &= ~gr_acl_umask();
57404 + mode = *modeptr;
57405 +
57406 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
57407 + return 1;
57408 +
57409 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
57410 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
57411 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
57412 + GR_CHMOD_ACL_MSG);
57413 + } else {
57414 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
57415 + }
57416 +}
57417 +
57418 +__u32
57419 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
57420 +{
57421 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
57422 +}
57423 +
57424 +__u32
57425 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
57426 +{
57427 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
57428 +}
57429 +
57430 +__u32
57431 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
57432 +{
57433 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
57434 +}
57435 +
57436 +__u32
57437 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
57438 +{
57439 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
57440 + GR_UNIXCONNECT_ACL_MSG);
57441 +}
57442 +
57443 +/* hardlinks require at minimum create and link permission,
57444 + any additional privilege required is based on the
57445 + privilege of the file being linked to
57446 +*/
57447 +__u32
57448 +gr_acl_handle_link(const struct dentry * new_dentry,
57449 + const struct dentry * parent_dentry,
57450 + const struct vfsmount * parent_mnt,
57451 + const struct dentry * old_dentry,
57452 + const struct vfsmount * old_mnt, const struct filename *to)
57453 +{
57454 + __u32 mode;
57455 + __u32 needmode = GR_CREATE | GR_LINK;
57456 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
57457 +
57458 + mode =
57459 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
57460 + old_mnt);
57461 +
57462 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
57463 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57464 + return mode;
57465 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57466 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57467 + return 0;
57468 + } else if (unlikely((mode & needmode) != needmode))
57469 + return 0;
57470 +
57471 + return 1;
57472 +}
57473 +
57474 +__u32
57475 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57476 + const struct dentry * parent_dentry,
57477 + const struct vfsmount * parent_mnt, const struct filename *from)
57478 +{
57479 + __u32 needmode = GR_WRITE | GR_CREATE;
57480 + __u32 mode;
57481 +
57482 + mode =
57483 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
57484 + GR_CREATE | GR_AUDIT_CREATE |
57485 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
57486 +
57487 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
57488 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57489 + return mode;
57490 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57491 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57492 + return 0;
57493 + } else if (unlikely((mode & needmode) != needmode))
57494 + return 0;
57495 +
57496 + return (GR_WRITE | GR_CREATE);
57497 +}
57498 +
57499 +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)
57500 +{
57501 + __u32 mode;
57502 +
57503 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57504 +
57505 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57506 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
57507 + return mode;
57508 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57509 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
57510 + return 0;
57511 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
57512 + return 0;
57513 +
57514 + return (reqmode);
57515 +}
57516 +
57517 +__u32
57518 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57519 + const struct dentry * parent_dentry,
57520 + const struct vfsmount * parent_mnt,
57521 + const int mode)
57522 +{
57523 + __u32 reqmode = GR_WRITE | GR_CREATE;
57524 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57525 + reqmode |= GR_SETID;
57526 +
57527 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57528 + reqmode, GR_MKNOD_ACL_MSG);
57529 +}
57530 +
57531 +__u32
57532 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
57533 + const struct dentry *parent_dentry,
57534 + const struct vfsmount *parent_mnt)
57535 +{
57536 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57537 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
57538 +}
57539 +
57540 +#define RENAME_CHECK_SUCCESS(old, new) \
57541 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
57542 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
57543 +
57544 +int
57545 +gr_acl_handle_rename(struct dentry *new_dentry,
57546 + struct dentry *parent_dentry,
57547 + const struct vfsmount *parent_mnt,
57548 + struct dentry *old_dentry,
57549 + struct inode *old_parent_inode,
57550 + struct vfsmount *old_mnt, const struct filename *newname)
57551 +{
57552 + __u32 comp1, comp2;
57553 + int error = 0;
57554 +
57555 + if (unlikely(!gr_acl_is_enabled()))
57556 + return 0;
57557 +
57558 + if (!new_dentry->d_inode) {
57559 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
57560 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
57561 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
57562 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
57563 + GR_DELETE | GR_AUDIT_DELETE |
57564 + GR_AUDIT_READ | GR_AUDIT_WRITE |
57565 + GR_SUPPRESS, old_mnt);
57566 + } else {
57567 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
57568 + GR_CREATE | GR_DELETE |
57569 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
57570 + GR_AUDIT_READ | GR_AUDIT_WRITE |
57571 + GR_SUPPRESS, parent_mnt);
57572 + comp2 =
57573 + gr_search_file(old_dentry,
57574 + GR_READ | GR_WRITE | GR_AUDIT_READ |
57575 + GR_DELETE | GR_AUDIT_DELETE |
57576 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
57577 + }
57578 +
57579 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
57580 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
57581 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57582 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
57583 + && !(comp2 & GR_SUPPRESS)) {
57584 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57585 + error = -EACCES;
57586 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
57587 + error = -EACCES;
57588 +
57589 + return error;
57590 +}
57591 +
57592 +void
57593 +gr_acl_handle_exit(void)
57594 +{
57595 + u16 id;
57596 + char *rolename;
57597 +
57598 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
57599 + !(current->role->roletype & GR_ROLE_PERSIST))) {
57600 + id = current->acl_role_id;
57601 + rolename = current->role->rolename;
57602 + gr_set_acls(1);
57603 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
57604 + }
57605 +
57606 + gr_put_exec_file(current);
57607 + return;
57608 +}
57609 +
57610 +int
57611 +gr_acl_handle_procpidmem(const struct task_struct *task)
57612 +{
57613 + if (unlikely(!gr_acl_is_enabled()))
57614 + return 0;
57615 +
57616 + if (task != current && task->acl->mode & GR_PROTPROCFD)
57617 + return -EACCES;
57618 +
57619 + return 0;
57620 +}
57621 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
57622 new file mode 100644
57623 index 0000000..58800a7
57624 --- /dev/null
57625 +++ b/grsecurity/gracl_ip.c
57626 @@ -0,0 +1,384 @@
57627 +#include <linux/kernel.h>
57628 +#include <asm/uaccess.h>
57629 +#include <asm/errno.h>
57630 +#include <net/sock.h>
57631 +#include <linux/file.h>
57632 +#include <linux/fs.h>
57633 +#include <linux/net.h>
57634 +#include <linux/in.h>
57635 +#include <linux/skbuff.h>
57636 +#include <linux/ip.h>
57637 +#include <linux/udp.h>
57638 +#include <linux/types.h>
57639 +#include <linux/sched.h>
57640 +#include <linux/netdevice.h>
57641 +#include <linux/inetdevice.h>
57642 +#include <linux/gracl.h>
57643 +#include <linux/grsecurity.h>
57644 +#include <linux/grinternal.h>
57645 +
57646 +#define GR_BIND 0x01
57647 +#define GR_CONNECT 0x02
57648 +#define GR_INVERT 0x04
57649 +#define GR_BINDOVERRIDE 0x08
57650 +#define GR_CONNECTOVERRIDE 0x10
57651 +#define GR_SOCK_FAMILY 0x20
57652 +
57653 +static const char * gr_protocols[IPPROTO_MAX] = {
57654 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
57655 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
57656 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
57657 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
57658 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
57659 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
57660 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
57661 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
57662 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
57663 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
57664 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
57665 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
57666 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
57667 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
57668 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
57669 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
57670 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
57671 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
57672 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
57673 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
57674 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
57675 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
57676 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
57677 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
57678 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
57679 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
57680 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
57681 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
57682 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
57683 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
57684 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
57685 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
57686 + };
57687 +
57688 +static const char * gr_socktypes[SOCK_MAX] = {
57689 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
57690 + "unknown:7", "unknown:8", "unknown:9", "packet"
57691 + };
57692 +
57693 +static const char * gr_sockfamilies[AF_MAX+1] = {
57694 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
57695 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
57696 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
57697 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
57698 + };
57699 +
57700 +const char *
57701 +gr_proto_to_name(unsigned char proto)
57702 +{
57703 + return gr_protocols[proto];
57704 +}
57705 +
57706 +const char *
57707 +gr_socktype_to_name(unsigned char type)
57708 +{
57709 + return gr_socktypes[type];
57710 +}
57711 +
57712 +const char *
57713 +gr_sockfamily_to_name(unsigned char family)
57714 +{
57715 + return gr_sockfamilies[family];
57716 +}
57717 +
57718 +int
57719 +gr_search_socket(const int domain, const int type, const int protocol)
57720 +{
57721 + struct acl_subject_label *curr;
57722 + const struct cred *cred = current_cred();
57723 +
57724 + if (unlikely(!gr_acl_is_enabled()))
57725 + goto exit;
57726 +
57727 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
57728 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
57729 + goto exit; // let the kernel handle it
57730 +
57731 + curr = current->acl;
57732 +
57733 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
57734 + /* the family is allowed, if this is PF_INET allow it only if
57735 + the extra sock type/protocol checks pass */
57736 + if (domain == PF_INET)
57737 + goto inet_check;
57738 + goto exit;
57739 + } else {
57740 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57741 + __u32 fakeip = 0;
57742 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57743 + current->role->roletype, cred->uid,
57744 + cred->gid, current->exec_file ?
57745 + gr_to_filename(current->exec_file->f_path.dentry,
57746 + current->exec_file->f_path.mnt) :
57747 + curr->filename, curr->filename,
57748 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
57749 + &current->signal->saved_ip);
57750 + goto exit;
57751 + }
57752 + goto exit_fail;
57753 + }
57754 +
57755 +inet_check:
57756 + /* the rest of this checking is for IPv4 only */
57757 + if (!curr->ips)
57758 + goto exit;
57759 +
57760 + if ((curr->ip_type & (1 << type)) &&
57761 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
57762 + goto exit;
57763 +
57764 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57765 + /* we don't place acls on raw sockets , and sometimes
57766 + dgram/ip sockets are opened for ioctl and not
57767 + bind/connect, so we'll fake a bind learn log */
57768 + if (type == SOCK_RAW || type == SOCK_PACKET) {
57769 + __u32 fakeip = 0;
57770 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57771 + current->role->roletype, cred->uid,
57772 + cred->gid, current->exec_file ?
57773 + gr_to_filename(current->exec_file->f_path.dentry,
57774 + current->exec_file->f_path.mnt) :
57775 + curr->filename, curr->filename,
57776 + &fakeip, 0, type,
57777 + protocol, GR_CONNECT, &current->signal->saved_ip);
57778 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
57779 + __u32 fakeip = 0;
57780 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57781 + current->role->roletype, cred->uid,
57782 + cred->gid, current->exec_file ?
57783 + gr_to_filename(current->exec_file->f_path.dentry,
57784 + current->exec_file->f_path.mnt) :
57785 + curr->filename, curr->filename,
57786 + &fakeip, 0, type,
57787 + protocol, GR_BIND, &current->signal->saved_ip);
57788 + }
57789 + /* we'll log when they use connect or bind */
57790 + goto exit;
57791 + }
57792 +
57793 +exit_fail:
57794 + if (domain == PF_INET)
57795 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
57796 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
57797 + else
57798 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
57799 + gr_socktype_to_name(type), protocol);
57800 +
57801 + return 0;
57802 +exit:
57803 + return 1;
57804 +}
57805 +
57806 +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)
57807 +{
57808 + if ((ip->mode & mode) &&
57809 + (ip_port >= ip->low) &&
57810 + (ip_port <= ip->high) &&
57811 + ((ntohl(ip_addr) & our_netmask) ==
57812 + (ntohl(our_addr) & our_netmask))
57813 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
57814 + && (ip->type & (1 << type))) {
57815 + if (ip->mode & GR_INVERT)
57816 + return 2; // specifically denied
57817 + else
57818 + return 1; // allowed
57819 + }
57820 +
57821 + return 0; // not specifically allowed, may continue parsing
57822 +}
57823 +
57824 +static int
57825 +gr_search_connectbind(const int full_mode, struct sock *sk,
57826 + struct sockaddr_in *addr, const int type)
57827 +{
57828 + char iface[IFNAMSIZ] = {0};
57829 + struct acl_subject_label *curr;
57830 + struct acl_ip_label *ip;
57831 + struct inet_sock *isk;
57832 + struct net_device *dev;
57833 + struct in_device *idev;
57834 + unsigned long i;
57835 + int ret;
57836 + int mode = full_mode & (GR_BIND | GR_CONNECT);
57837 + __u32 ip_addr = 0;
57838 + __u32 our_addr;
57839 + __u32 our_netmask;
57840 + char *p;
57841 + __u16 ip_port = 0;
57842 + const struct cred *cred = current_cred();
57843 +
57844 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
57845 + return 0;
57846 +
57847 + curr = current->acl;
57848 + isk = inet_sk(sk);
57849 +
57850 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
57851 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
57852 + addr->sin_addr.s_addr = curr->inaddr_any_override;
57853 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
57854 + struct sockaddr_in saddr;
57855 + int err;
57856 +
57857 + saddr.sin_family = AF_INET;
57858 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
57859 + saddr.sin_port = isk->inet_sport;
57860 +
57861 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57862 + if (err)
57863 + return err;
57864 +
57865 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57866 + if (err)
57867 + return err;
57868 + }
57869 +
57870 + if (!curr->ips)
57871 + return 0;
57872 +
57873 + ip_addr = addr->sin_addr.s_addr;
57874 + ip_port = ntohs(addr->sin_port);
57875 +
57876 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57877 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57878 + current->role->roletype, cred->uid,
57879 + cred->gid, current->exec_file ?
57880 + gr_to_filename(current->exec_file->f_path.dentry,
57881 + current->exec_file->f_path.mnt) :
57882 + curr->filename, curr->filename,
57883 + &ip_addr, ip_port, type,
57884 + sk->sk_protocol, mode, &current->signal->saved_ip);
57885 + return 0;
57886 + }
57887 +
57888 + for (i = 0; i < curr->ip_num; i++) {
57889 + ip = *(curr->ips + i);
57890 + if (ip->iface != NULL) {
57891 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
57892 + p = strchr(iface, ':');
57893 + if (p != NULL)
57894 + *p = '\0';
57895 + dev = dev_get_by_name(sock_net(sk), iface);
57896 + if (dev == NULL)
57897 + continue;
57898 + idev = in_dev_get(dev);
57899 + if (idev == NULL) {
57900 + dev_put(dev);
57901 + continue;
57902 + }
57903 + rcu_read_lock();
57904 + for_ifa(idev) {
57905 + if (!strcmp(ip->iface, ifa->ifa_label)) {
57906 + our_addr = ifa->ifa_address;
57907 + our_netmask = 0xffffffff;
57908 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57909 + if (ret == 1) {
57910 + rcu_read_unlock();
57911 + in_dev_put(idev);
57912 + dev_put(dev);
57913 + return 0;
57914 + } else if (ret == 2) {
57915 + rcu_read_unlock();
57916 + in_dev_put(idev);
57917 + dev_put(dev);
57918 + goto denied;
57919 + }
57920 + }
57921 + } endfor_ifa(idev);
57922 + rcu_read_unlock();
57923 + in_dev_put(idev);
57924 + dev_put(dev);
57925 + } else {
57926 + our_addr = ip->addr;
57927 + our_netmask = ip->netmask;
57928 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57929 + if (ret == 1)
57930 + return 0;
57931 + else if (ret == 2)
57932 + goto denied;
57933 + }
57934 + }
57935 +
57936 +denied:
57937 + if (mode == GR_BIND)
57938 + 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));
57939 + else if (mode == GR_CONNECT)
57940 + 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));
57941 +
57942 + return -EACCES;
57943 +}
57944 +
57945 +int
57946 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
57947 +{
57948 + /* always allow disconnection of dgram sockets with connect */
57949 + if (addr->sin_family == AF_UNSPEC)
57950 + return 0;
57951 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
57952 +}
57953 +
57954 +int
57955 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
57956 +{
57957 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
57958 +}
57959 +
57960 +int gr_search_listen(struct socket *sock)
57961 +{
57962 + struct sock *sk = sock->sk;
57963 + struct sockaddr_in addr;
57964 +
57965 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57966 + addr.sin_port = inet_sk(sk)->inet_sport;
57967 +
57968 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57969 +}
57970 +
57971 +int gr_search_accept(struct socket *sock)
57972 +{
57973 + struct sock *sk = sock->sk;
57974 + struct sockaddr_in addr;
57975 +
57976 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57977 + addr.sin_port = inet_sk(sk)->inet_sport;
57978 +
57979 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57980 +}
57981 +
57982 +int
57983 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
57984 +{
57985 + if (addr)
57986 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
57987 + else {
57988 + struct sockaddr_in sin;
57989 + const struct inet_sock *inet = inet_sk(sk);
57990 +
57991 + sin.sin_addr.s_addr = inet->inet_daddr;
57992 + sin.sin_port = inet->inet_dport;
57993 +
57994 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57995 + }
57996 +}
57997 +
57998 +int
57999 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58000 +{
58001 + struct sockaddr_in sin;
58002 +
58003 + if (unlikely(skb->len < sizeof (struct udphdr)))
58004 + return 0; // skip this packet
58005 +
58006 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58007 + sin.sin_port = udp_hdr(skb)->source;
58008 +
58009 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58010 +}
58011 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58012 new file mode 100644
58013 index 0000000..25f54ef
58014 --- /dev/null
58015 +++ b/grsecurity/gracl_learn.c
58016 @@ -0,0 +1,207 @@
58017 +#include <linux/kernel.h>
58018 +#include <linux/mm.h>
58019 +#include <linux/sched.h>
58020 +#include <linux/poll.h>
58021 +#include <linux/string.h>
58022 +#include <linux/file.h>
58023 +#include <linux/types.h>
58024 +#include <linux/vmalloc.h>
58025 +#include <linux/grinternal.h>
58026 +
58027 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58028 + size_t count, loff_t *ppos);
58029 +extern int gr_acl_is_enabled(void);
58030 +
58031 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58032 +static int gr_learn_attached;
58033 +
58034 +/* use a 512k buffer */
58035 +#define LEARN_BUFFER_SIZE (512 * 1024)
58036 +
58037 +static DEFINE_SPINLOCK(gr_learn_lock);
58038 +static DEFINE_MUTEX(gr_learn_user_mutex);
58039 +
58040 +/* we need to maintain two buffers, so that the kernel context of grlearn
58041 + uses a semaphore around the userspace copying, and the other kernel contexts
58042 + use a spinlock when copying into the buffer, since they cannot sleep
58043 +*/
58044 +static char *learn_buffer;
58045 +static char *learn_buffer_user;
58046 +static int learn_buffer_len;
58047 +static int learn_buffer_user_len;
58048 +
58049 +static ssize_t
58050 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58051 +{
58052 + DECLARE_WAITQUEUE(wait, current);
58053 + ssize_t retval = 0;
58054 +
58055 + add_wait_queue(&learn_wait, &wait);
58056 + set_current_state(TASK_INTERRUPTIBLE);
58057 + do {
58058 + mutex_lock(&gr_learn_user_mutex);
58059 + spin_lock(&gr_learn_lock);
58060 + if (learn_buffer_len)
58061 + break;
58062 + spin_unlock(&gr_learn_lock);
58063 + mutex_unlock(&gr_learn_user_mutex);
58064 + if (file->f_flags & O_NONBLOCK) {
58065 + retval = -EAGAIN;
58066 + goto out;
58067 + }
58068 + if (signal_pending(current)) {
58069 + retval = -ERESTARTSYS;
58070 + goto out;
58071 + }
58072 +
58073 + schedule();
58074 + } while (1);
58075 +
58076 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58077 + learn_buffer_user_len = learn_buffer_len;
58078 + retval = learn_buffer_len;
58079 + learn_buffer_len = 0;
58080 +
58081 + spin_unlock(&gr_learn_lock);
58082 +
58083 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58084 + retval = -EFAULT;
58085 +
58086 + mutex_unlock(&gr_learn_user_mutex);
58087 +out:
58088 + set_current_state(TASK_RUNNING);
58089 + remove_wait_queue(&learn_wait, &wait);
58090 + return retval;
58091 +}
58092 +
58093 +static unsigned int
58094 +poll_learn(struct file * file, poll_table * wait)
58095 +{
58096 + poll_wait(file, &learn_wait, wait);
58097 +
58098 + if (learn_buffer_len)
58099 + return (POLLIN | POLLRDNORM);
58100 +
58101 + return 0;
58102 +}
58103 +
58104 +void
58105 +gr_clear_learn_entries(void)
58106 +{
58107 + char *tmp;
58108 +
58109 + mutex_lock(&gr_learn_user_mutex);
58110 + spin_lock(&gr_learn_lock);
58111 + tmp = learn_buffer;
58112 + learn_buffer = NULL;
58113 + spin_unlock(&gr_learn_lock);
58114 + if (tmp)
58115 + vfree(tmp);
58116 + if (learn_buffer_user != NULL) {
58117 + vfree(learn_buffer_user);
58118 + learn_buffer_user = NULL;
58119 + }
58120 + learn_buffer_len = 0;
58121 + mutex_unlock(&gr_learn_user_mutex);
58122 +
58123 + return;
58124 +}
58125 +
58126 +void
58127 +gr_add_learn_entry(const char *fmt, ...)
58128 +{
58129 + va_list args;
58130 + unsigned int len;
58131 +
58132 + if (!gr_learn_attached)
58133 + return;
58134 +
58135 + spin_lock(&gr_learn_lock);
58136 +
58137 + /* leave a gap at the end so we know when it's "full" but don't have to
58138 + compute the exact length of the string we're trying to append
58139 + */
58140 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58141 + spin_unlock(&gr_learn_lock);
58142 + wake_up_interruptible(&learn_wait);
58143 + return;
58144 + }
58145 + if (learn_buffer == NULL) {
58146 + spin_unlock(&gr_learn_lock);
58147 + return;
58148 + }
58149 +
58150 + va_start(args, fmt);
58151 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58152 + va_end(args);
58153 +
58154 + learn_buffer_len += len + 1;
58155 +
58156 + spin_unlock(&gr_learn_lock);
58157 + wake_up_interruptible(&learn_wait);
58158 +
58159 + return;
58160 +}
58161 +
58162 +static int
58163 +open_learn(struct inode *inode, struct file *file)
58164 +{
58165 + if (file->f_mode & FMODE_READ && gr_learn_attached)
58166 + return -EBUSY;
58167 + if (file->f_mode & FMODE_READ) {
58168 + int retval = 0;
58169 + mutex_lock(&gr_learn_user_mutex);
58170 + if (learn_buffer == NULL)
58171 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58172 + if (learn_buffer_user == NULL)
58173 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58174 + if (learn_buffer == NULL) {
58175 + retval = -ENOMEM;
58176 + goto out_error;
58177 + }
58178 + if (learn_buffer_user == NULL) {
58179 + retval = -ENOMEM;
58180 + goto out_error;
58181 + }
58182 + learn_buffer_len = 0;
58183 + learn_buffer_user_len = 0;
58184 + gr_learn_attached = 1;
58185 +out_error:
58186 + mutex_unlock(&gr_learn_user_mutex);
58187 + return retval;
58188 + }
58189 + return 0;
58190 +}
58191 +
58192 +static int
58193 +close_learn(struct inode *inode, struct file *file)
58194 +{
58195 + if (file->f_mode & FMODE_READ) {
58196 + char *tmp = NULL;
58197 + mutex_lock(&gr_learn_user_mutex);
58198 + spin_lock(&gr_learn_lock);
58199 + tmp = learn_buffer;
58200 + learn_buffer = NULL;
58201 + spin_unlock(&gr_learn_lock);
58202 + if (tmp)
58203 + vfree(tmp);
58204 + if (learn_buffer_user != NULL) {
58205 + vfree(learn_buffer_user);
58206 + learn_buffer_user = NULL;
58207 + }
58208 + learn_buffer_len = 0;
58209 + learn_buffer_user_len = 0;
58210 + gr_learn_attached = 0;
58211 + mutex_unlock(&gr_learn_user_mutex);
58212 + }
58213 +
58214 + return 0;
58215 +}
58216 +
58217 +const struct file_operations grsec_fops = {
58218 + .read = read_learn,
58219 + .write = write_grsec_handler,
58220 + .open = open_learn,
58221 + .release = close_learn,
58222 + .poll = poll_learn,
58223 +};
58224 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58225 new file mode 100644
58226 index 0000000..39645c9
58227 --- /dev/null
58228 +++ b/grsecurity/gracl_res.c
58229 @@ -0,0 +1,68 @@
58230 +#include <linux/kernel.h>
58231 +#include <linux/sched.h>
58232 +#include <linux/gracl.h>
58233 +#include <linux/grinternal.h>
58234 +
58235 +static const char *restab_log[] = {
58236 + [RLIMIT_CPU] = "RLIMIT_CPU",
58237 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58238 + [RLIMIT_DATA] = "RLIMIT_DATA",
58239 + [RLIMIT_STACK] = "RLIMIT_STACK",
58240 + [RLIMIT_CORE] = "RLIMIT_CORE",
58241 + [RLIMIT_RSS] = "RLIMIT_RSS",
58242 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
58243 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58244 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58245 + [RLIMIT_AS] = "RLIMIT_AS",
58246 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58247 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58248 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58249 + [RLIMIT_NICE] = "RLIMIT_NICE",
58250 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58251 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58252 + [GR_CRASH_RES] = "RLIMIT_CRASH"
58253 +};
58254 +
58255 +void
58256 +gr_log_resource(const struct task_struct *task,
58257 + const int res, const unsigned long wanted, const int gt)
58258 +{
58259 + const struct cred *cred;
58260 + unsigned long rlim;
58261 +
58262 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
58263 + return;
58264 +
58265 + // not yet supported resource
58266 + if (unlikely(!restab_log[res]))
58267 + return;
58268 +
58269 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
58270 + rlim = task_rlimit_max(task, res);
58271 + else
58272 + rlim = task_rlimit(task, res);
58273 +
58274 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
58275 + return;
58276 +
58277 + rcu_read_lock();
58278 + cred = __task_cred(task);
58279 +
58280 + if (res == RLIMIT_NPROC &&
58281 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
58282 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
58283 + goto out_rcu_unlock;
58284 + else if (res == RLIMIT_MEMLOCK &&
58285 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
58286 + goto out_rcu_unlock;
58287 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
58288 + goto out_rcu_unlock;
58289 + rcu_read_unlock();
58290 +
58291 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
58292 +
58293 + return;
58294 +out_rcu_unlock:
58295 + rcu_read_unlock();
58296 + return;
58297 +}
58298 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
58299 new file mode 100644
58300 index 0000000..25197e9
58301 --- /dev/null
58302 +++ b/grsecurity/gracl_segv.c
58303 @@ -0,0 +1,299 @@
58304 +#include <linux/kernel.h>
58305 +#include <linux/mm.h>
58306 +#include <asm/uaccess.h>
58307 +#include <asm/errno.h>
58308 +#include <asm/mman.h>
58309 +#include <net/sock.h>
58310 +#include <linux/file.h>
58311 +#include <linux/fs.h>
58312 +#include <linux/net.h>
58313 +#include <linux/in.h>
58314 +#include <linux/slab.h>
58315 +#include <linux/types.h>
58316 +#include <linux/sched.h>
58317 +#include <linux/timer.h>
58318 +#include <linux/gracl.h>
58319 +#include <linux/grsecurity.h>
58320 +#include <linux/grinternal.h>
58321 +
58322 +static struct crash_uid *uid_set;
58323 +static unsigned short uid_used;
58324 +static DEFINE_SPINLOCK(gr_uid_lock);
58325 +extern rwlock_t gr_inode_lock;
58326 +extern struct acl_subject_label *
58327 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
58328 + struct acl_role_label *role);
58329 +
58330 +#ifdef CONFIG_BTRFS_FS
58331 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58332 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58333 +#endif
58334 +
58335 +static inline dev_t __get_dev(const struct dentry *dentry)
58336 +{
58337 +#ifdef CONFIG_BTRFS_FS
58338 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58339 + return get_btrfs_dev_from_inode(dentry->d_inode);
58340 + else
58341 +#endif
58342 + return dentry->d_inode->i_sb->s_dev;
58343 +}
58344 +
58345 +int
58346 +gr_init_uidset(void)
58347 +{
58348 + uid_set =
58349 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
58350 + uid_used = 0;
58351 +
58352 + return uid_set ? 1 : 0;
58353 +}
58354 +
58355 +void
58356 +gr_free_uidset(void)
58357 +{
58358 + if (uid_set)
58359 + kfree(uid_set);
58360 +
58361 + return;
58362 +}
58363 +
58364 +int
58365 +gr_find_uid(const uid_t uid)
58366 +{
58367 + struct crash_uid *tmp = uid_set;
58368 + uid_t buid;
58369 + int low = 0, high = uid_used - 1, mid;
58370 +
58371 + while (high >= low) {
58372 + mid = (low + high) >> 1;
58373 + buid = tmp[mid].uid;
58374 + if (buid == uid)
58375 + return mid;
58376 + if (buid > uid)
58377 + high = mid - 1;
58378 + if (buid < uid)
58379 + low = mid + 1;
58380 + }
58381 +
58382 + return -1;
58383 +}
58384 +
58385 +static __inline__ void
58386 +gr_insertsort(void)
58387 +{
58388 + unsigned short i, j;
58389 + struct crash_uid index;
58390 +
58391 + for (i = 1; i < uid_used; i++) {
58392 + index = uid_set[i];
58393 + j = i;
58394 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
58395 + uid_set[j] = uid_set[j - 1];
58396 + j--;
58397 + }
58398 + uid_set[j] = index;
58399 + }
58400 +
58401 + return;
58402 +}
58403 +
58404 +static __inline__ void
58405 +gr_insert_uid(const uid_t uid, const unsigned long expires)
58406 +{
58407 + int loc;
58408 +
58409 + if (uid_used == GR_UIDTABLE_MAX)
58410 + return;
58411 +
58412 + loc = gr_find_uid(uid);
58413 +
58414 + if (loc >= 0) {
58415 + uid_set[loc].expires = expires;
58416 + return;
58417 + }
58418 +
58419 + uid_set[uid_used].uid = uid;
58420 + uid_set[uid_used].expires = expires;
58421 + uid_used++;
58422 +
58423 + gr_insertsort();
58424 +
58425 + return;
58426 +}
58427 +
58428 +void
58429 +gr_remove_uid(const unsigned short loc)
58430 +{
58431 + unsigned short i;
58432 +
58433 + for (i = loc + 1; i < uid_used; i++)
58434 + uid_set[i - 1] = uid_set[i];
58435 +
58436 + uid_used--;
58437 +
58438 + return;
58439 +}
58440 +
58441 +int
58442 +gr_check_crash_uid(const uid_t uid)
58443 +{
58444 + int loc;
58445 + int ret = 0;
58446 +
58447 + if (unlikely(!gr_acl_is_enabled()))
58448 + return 0;
58449 +
58450 + spin_lock(&gr_uid_lock);
58451 + loc = gr_find_uid(uid);
58452 +
58453 + if (loc < 0)
58454 + goto out_unlock;
58455 +
58456 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
58457 + gr_remove_uid(loc);
58458 + else
58459 + ret = 1;
58460 +
58461 +out_unlock:
58462 + spin_unlock(&gr_uid_lock);
58463 + return ret;
58464 +}
58465 +
58466 +static __inline__ int
58467 +proc_is_setxid(const struct cred *cred)
58468 +{
58469 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
58470 + !uid_eq(cred->uid, cred->fsuid))
58471 + return 1;
58472 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
58473 + !uid_eq(cred->gid, cred->fsgid))
58474 + return 1;
58475 +
58476 + return 0;
58477 +}
58478 +
58479 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
58480 +
58481 +void
58482 +gr_handle_crash(struct task_struct *task, const int sig)
58483 +{
58484 + struct acl_subject_label *curr;
58485 + struct task_struct *tsk, *tsk2;
58486 + const struct cred *cred;
58487 + const struct cred *cred2;
58488 +
58489 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
58490 + return;
58491 +
58492 + if (unlikely(!gr_acl_is_enabled()))
58493 + return;
58494 +
58495 + curr = task->acl;
58496 +
58497 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
58498 + return;
58499 +
58500 + if (time_before_eq(curr->expires, get_seconds())) {
58501 + curr->expires = 0;
58502 + curr->crashes = 0;
58503 + }
58504 +
58505 + curr->crashes++;
58506 +
58507 + if (!curr->expires)
58508 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
58509 +
58510 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58511 + time_after(curr->expires, get_seconds())) {
58512 + rcu_read_lock();
58513 + cred = __task_cred(task);
58514 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
58515 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58516 + spin_lock(&gr_uid_lock);
58517 + gr_insert_uid(cred->uid, curr->expires);
58518 + spin_unlock(&gr_uid_lock);
58519 + curr->expires = 0;
58520 + curr->crashes = 0;
58521 + read_lock(&tasklist_lock);
58522 + do_each_thread(tsk2, tsk) {
58523 + cred2 = __task_cred(tsk);
58524 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
58525 + gr_fake_force_sig(SIGKILL, tsk);
58526 + } while_each_thread(tsk2, tsk);
58527 + read_unlock(&tasklist_lock);
58528 + } else {
58529 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58530 + read_lock(&tasklist_lock);
58531 + read_lock(&grsec_exec_file_lock);
58532 + do_each_thread(tsk2, tsk) {
58533 + if (likely(tsk != task)) {
58534 + // if this thread has the same subject as the one that triggered
58535 + // RES_CRASH and it's the same binary, kill it
58536 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
58537 + gr_fake_force_sig(SIGKILL, tsk);
58538 + }
58539 + } while_each_thread(tsk2, tsk);
58540 + read_unlock(&grsec_exec_file_lock);
58541 + read_unlock(&tasklist_lock);
58542 + }
58543 + rcu_read_unlock();
58544 + }
58545 +
58546 + return;
58547 +}
58548 +
58549 +int
58550 +gr_check_crash_exec(const struct file *filp)
58551 +{
58552 + struct acl_subject_label *curr;
58553 +
58554 + if (unlikely(!gr_acl_is_enabled()))
58555 + return 0;
58556 +
58557 + read_lock(&gr_inode_lock);
58558 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
58559 + __get_dev(filp->f_path.dentry),
58560 + current->role);
58561 + read_unlock(&gr_inode_lock);
58562 +
58563 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
58564 + (!curr->crashes && !curr->expires))
58565 + return 0;
58566 +
58567 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58568 + time_after(curr->expires, get_seconds()))
58569 + return 1;
58570 + else if (time_before_eq(curr->expires, get_seconds())) {
58571 + curr->crashes = 0;
58572 + curr->expires = 0;
58573 + }
58574 +
58575 + return 0;
58576 +}
58577 +
58578 +void
58579 +gr_handle_alertkill(struct task_struct *task)
58580 +{
58581 + struct acl_subject_label *curracl;
58582 + __u32 curr_ip;
58583 + struct task_struct *p, *p2;
58584 +
58585 + if (unlikely(!gr_acl_is_enabled()))
58586 + return;
58587 +
58588 + curracl = task->acl;
58589 + curr_ip = task->signal->curr_ip;
58590 +
58591 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
58592 + read_lock(&tasklist_lock);
58593 + do_each_thread(p2, p) {
58594 + if (p->signal->curr_ip == curr_ip)
58595 + gr_fake_force_sig(SIGKILL, p);
58596 + } while_each_thread(p2, p);
58597 + read_unlock(&tasklist_lock);
58598 + } else if (curracl->mode & GR_KILLPROC)
58599 + gr_fake_force_sig(SIGKILL, task);
58600 +
58601 + return;
58602 +}
58603 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
58604 new file mode 100644
58605 index 0000000..9d83a69
58606 --- /dev/null
58607 +++ b/grsecurity/gracl_shm.c
58608 @@ -0,0 +1,40 @@
58609 +#include <linux/kernel.h>
58610 +#include <linux/mm.h>
58611 +#include <linux/sched.h>
58612 +#include <linux/file.h>
58613 +#include <linux/ipc.h>
58614 +#include <linux/gracl.h>
58615 +#include <linux/grsecurity.h>
58616 +#include <linux/grinternal.h>
58617 +
58618 +int
58619 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58620 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58621 +{
58622 + struct task_struct *task;
58623 +
58624 + if (!gr_acl_is_enabled())
58625 + return 1;
58626 +
58627 + rcu_read_lock();
58628 + read_lock(&tasklist_lock);
58629 +
58630 + task = find_task_by_vpid(shm_cprid);
58631 +
58632 + if (unlikely(!task))
58633 + task = find_task_by_vpid(shm_lapid);
58634 +
58635 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
58636 + (task->pid == shm_lapid)) &&
58637 + (task->acl->mode & GR_PROTSHM) &&
58638 + (task->acl != current->acl))) {
58639 + read_unlock(&tasklist_lock);
58640 + rcu_read_unlock();
58641 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
58642 + return 0;
58643 + }
58644 + read_unlock(&tasklist_lock);
58645 + rcu_read_unlock();
58646 +
58647 + return 1;
58648 +}
58649 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
58650 new file mode 100644
58651 index 0000000..bc0be01
58652 --- /dev/null
58653 +++ b/grsecurity/grsec_chdir.c
58654 @@ -0,0 +1,19 @@
58655 +#include <linux/kernel.h>
58656 +#include <linux/sched.h>
58657 +#include <linux/fs.h>
58658 +#include <linux/file.h>
58659 +#include <linux/grsecurity.h>
58660 +#include <linux/grinternal.h>
58661 +
58662 +void
58663 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
58664 +{
58665 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58666 + if ((grsec_enable_chdir && grsec_enable_group &&
58667 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
58668 + !grsec_enable_group)) {
58669 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
58670 + }
58671 +#endif
58672 + return;
58673 +}
58674 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
58675 new file mode 100644
58676 index 0000000..9807ee2
58677 --- /dev/null
58678 +++ b/grsecurity/grsec_chroot.c
58679 @@ -0,0 +1,368 @@
58680 +#include <linux/kernel.h>
58681 +#include <linux/module.h>
58682 +#include <linux/sched.h>
58683 +#include <linux/file.h>
58684 +#include <linux/fs.h>
58685 +#include <linux/mount.h>
58686 +#include <linux/types.h>
58687 +#include "../fs/mount.h"
58688 +#include <linux/grsecurity.h>
58689 +#include <linux/grinternal.h>
58690 +
58691 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
58692 +{
58693 +#ifdef CONFIG_GRKERNSEC
58694 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
58695 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
58696 + task->gr_is_chrooted = 1;
58697 + else
58698 + task->gr_is_chrooted = 0;
58699 +
58700 + task->gr_chroot_dentry = path->dentry;
58701 +#endif
58702 + return;
58703 +}
58704 +
58705 +void gr_clear_chroot_entries(struct task_struct *task)
58706 +{
58707 +#ifdef CONFIG_GRKERNSEC
58708 + task->gr_is_chrooted = 0;
58709 + task->gr_chroot_dentry = NULL;
58710 +#endif
58711 + return;
58712 +}
58713 +
58714 +int
58715 +gr_handle_chroot_unix(const pid_t pid)
58716 +{
58717 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58718 + struct task_struct *p;
58719 +
58720 + if (unlikely(!grsec_enable_chroot_unix))
58721 + return 1;
58722 +
58723 + if (likely(!proc_is_chrooted(current)))
58724 + return 1;
58725 +
58726 + rcu_read_lock();
58727 + read_lock(&tasklist_lock);
58728 + p = find_task_by_vpid_unrestricted(pid);
58729 + if (unlikely(p && !have_same_root(current, p))) {
58730 + read_unlock(&tasklist_lock);
58731 + rcu_read_unlock();
58732 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
58733 + return 0;
58734 + }
58735 + read_unlock(&tasklist_lock);
58736 + rcu_read_unlock();
58737 +#endif
58738 + return 1;
58739 +}
58740 +
58741 +int
58742 +gr_handle_chroot_nice(void)
58743 +{
58744 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58745 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
58746 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
58747 + return -EPERM;
58748 + }
58749 +#endif
58750 + return 0;
58751 +}
58752 +
58753 +int
58754 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
58755 +{
58756 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58757 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
58758 + && proc_is_chrooted(current)) {
58759 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
58760 + return -EACCES;
58761 + }
58762 +#endif
58763 + return 0;
58764 +}
58765 +
58766 +int
58767 +gr_handle_chroot_rawio(const struct inode *inode)
58768 +{
58769 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58770 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58771 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
58772 + return 1;
58773 +#endif
58774 + return 0;
58775 +}
58776 +
58777 +int
58778 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
58779 +{
58780 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58781 + struct task_struct *p;
58782 + int ret = 0;
58783 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
58784 + return ret;
58785 +
58786 + read_lock(&tasklist_lock);
58787 + do_each_pid_task(pid, type, p) {
58788 + if (!have_same_root(current, p)) {
58789 + ret = 1;
58790 + goto out;
58791 + }
58792 + } while_each_pid_task(pid, type, p);
58793 +out:
58794 + read_unlock(&tasklist_lock);
58795 + return ret;
58796 +#endif
58797 + return 0;
58798 +}
58799 +
58800 +int
58801 +gr_pid_is_chrooted(struct task_struct *p)
58802 +{
58803 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58804 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
58805 + return 0;
58806 +
58807 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
58808 + !have_same_root(current, p)) {
58809 + return 1;
58810 + }
58811 +#endif
58812 + return 0;
58813 +}
58814 +
58815 +EXPORT_SYMBOL(gr_pid_is_chrooted);
58816 +
58817 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
58818 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
58819 +{
58820 + struct path path, currentroot;
58821 + int ret = 0;
58822 +
58823 + path.dentry = (struct dentry *)u_dentry;
58824 + path.mnt = (struct vfsmount *)u_mnt;
58825 + get_fs_root(current->fs, &currentroot);
58826 + if (path_is_under(&path, &currentroot))
58827 + ret = 1;
58828 + path_put(&currentroot);
58829 +
58830 + return ret;
58831 +}
58832 +#endif
58833 +
58834 +int
58835 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
58836 +{
58837 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58838 + if (!grsec_enable_chroot_fchdir)
58839 + return 1;
58840 +
58841 + if (!proc_is_chrooted(current))
58842 + return 1;
58843 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
58844 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
58845 + return 0;
58846 + }
58847 +#endif
58848 + return 1;
58849 +}
58850 +
58851 +int
58852 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58853 + const time_t shm_createtime)
58854 +{
58855 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58856 + struct task_struct *p;
58857 + time_t starttime;
58858 +
58859 + if (unlikely(!grsec_enable_chroot_shmat))
58860 + return 1;
58861 +
58862 + if (likely(!proc_is_chrooted(current)))
58863 + return 1;
58864 +
58865 + rcu_read_lock();
58866 + read_lock(&tasklist_lock);
58867 +
58868 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
58869 + starttime = p->start_time.tv_sec;
58870 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
58871 + if (have_same_root(current, p)) {
58872 + goto allow;
58873 + } else {
58874 + read_unlock(&tasklist_lock);
58875 + rcu_read_unlock();
58876 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58877 + return 0;
58878 + }
58879 + }
58880 + /* creator exited, pid reuse, fall through to next check */
58881 + }
58882 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
58883 + if (unlikely(!have_same_root(current, p))) {
58884 + read_unlock(&tasklist_lock);
58885 + rcu_read_unlock();
58886 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58887 + return 0;
58888 + }
58889 + }
58890 +
58891 +allow:
58892 + read_unlock(&tasklist_lock);
58893 + rcu_read_unlock();
58894 +#endif
58895 + return 1;
58896 +}
58897 +
58898 +void
58899 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
58900 +{
58901 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58902 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
58903 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
58904 +#endif
58905 + return;
58906 +}
58907 +
58908 +int
58909 +gr_handle_chroot_mknod(const struct dentry *dentry,
58910 + const struct vfsmount *mnt, const int mode)
58911 +{
58912 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58913 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
58914 + proc_is_chrooted(current)) {
58915 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
58916 + return -EPERM;
58917 + }
58918 +#endif
58919 + return 0;
58920 +}
58921 +
58922 +int
58923 +gr_handle_chroot_mount(const struct dentry *dentry,
58924 + const struct vfsmount *mnt, const char *dev_name)
58925 +{
58926 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58927 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
58928 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
58929 + return -EPERM;
58930 + }
58931 +#endif
58932 + return 0;
58933 +}
58934 +
58935 +int
58936 +gr_handle_chroot_pivot(void)
58937 +{
58938 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58939 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
58940 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
58941 + return -EPERM;
58942 + }
58943 +#endif
58944 + return 0;
58945 +}
58946 +
58947 +int
58948 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
58949 +{
58950 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58951 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
58952 + !gr_is_outside_chroot(dentry, mnt)) {
58953 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
58954 + return -EPERM;
58955 + }
58956 +#endif
58957 + return 0;
58958 +}
58959 +
58960 +extern const char *captab_log[];
58961 +extern int captab_log_entries;
58962 +
58963 +int
58964 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58965 +{
58966 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58967 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58968 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58969 + if (cap_raised(chroot_caps, cap)) {
58970 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
58971 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
58972 + }
58973 + return 0;
58974 + }
58975 + }
58976 +#endif
58977 + return 1;
58978 +}
58979 +
58980 +int
58981 +gr_chroot_is_capable(const int cap)
58982 +{
58983 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58984 + return gr_task_chroot_is_capable(current, current_cred(), cap);
58985 +#endif
58986 + return 1;
58987 +}
58988 +
58989 +int
58990 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
58991 +{
58992 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58993 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58994 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58995 + if (cap_raised(chroot_caps, cap)) {
58996 + return 0;
58997 + }
58998 + }
58999 +#endif
59000 + return 1;
59001 +}
59002 +
59003 +int
59004 +gr_chroot_is_capable_nolog(const int cap)
59005 +{
59006 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59007 + return gr_task_chroot_is_capable_nolog(current, cap);
59008 +#endif
59009 + return 1;
59010 +}
59011 +
59012 +int
59013 +gr_handle_chroot_sysctl(const int op)
59014 +{
59015 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59016 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59017 + proc_is_chrooted(current))
59018 + return -EACCES;
59019 +#endif
59020 + return 0;
59021 +}
59022 +
59023 +void
59024 +gr_handle_chroot_chdir(struct path *path)
59025 +{
59026 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59027 + if (grsec_enable_chroot_chdir)
59028 + set_fs_pwd(current->fs, path);
59029 +#endif
59030 + return;
59031 +}
59032 +
59033 +int
59034 +gr_handle_chroot_chmod(const struct dentry *dentry,
59035 + const struct vfsmount *mnt, const int mode)
59036 +{
59037 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59038 + /* allow chmod +s on directories, but not files */
59039 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59040 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59041 + proc_is_chrooted(current)) {
59042 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59043 + return -EPERM;
59044 + }
59045 +#endif
59046 + return 0;
59047 +}
59048 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59049 new file mode 100644
59050 index 0000000..7de2055
59051 --- /dev/null
59052 +++ b/grsecurity/grsec_disabled.c
59053 @@ -0,0 +1,442 @@
59054 +#include <linux/kernel.h>
59055 +#include <linux/module.h>
59056 +#include <linux/sched.h>
59057 +#include <linux/file.h>
59058 +#include <linux/fs.h>
59059 +#include <linux/kdev_t.h>
59060 +#include <linux/net.h>
59061 +#include <linux/in.h>
59062 +#include <linux/ip.h>
59063 +#include <linux/skbuff.h>
59064 +#include <linux/sysctl.h>
59065 +
59066 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59067 +void
59068 +pax_set_initial_flags(struct linux_binprm *bprm)
59069 +{
59070 + return;
59071 +}
59072 +#endif
59073 +
59074 +#ifdef CONFIG_SYSCTL
59075 +__u32
59076 +gr_handle_sysctl(const struct ctl_table * table, const int op)
59077 +{
59078 + return 0;
59079 +}
59080 +#endif
59081 +
59082 +#ifdef CONFIG_TASKSTATS
59083 +int gr_is_taskstats_denied(int pid)
59084 +{
59085 + return 0;
59086 +}
59087 +#endif
59088 +
59089 +int
59090 +gr_acl_is_enabled(void)
59091 +{
59092 + return 0;
59093 +}
59094 +
59095 +void
59096 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59097 +{
59098 + return;
59099 +}
59100 +
59101 +int
59102 +gr_handle_rawio(const struct inode *inode)
59103 +{
59104 + return 0;
59105 +}
59106 +
59107 +void
59108 +gr_acl_handle_psacct(struct task_struct *task, const long code)
59109 +{
59110 + return;
59111 +}
59112 +
59113 +int
59114 +gr_handle_ptrace(struct task_struct *task, const long request)
59115 +{
59116 + return 0;
59117 +}
59118 +
59119 +int
59120 +gr_handle_proc_ptrace(struct task_struct *task)
59121 +{
59122 + return 0;
59123 +}
59124 +
59125 +void
59126 +gr_learn_resource(const struct task_struct *task,
59127 + const int res, const unsigned long wanted, const int gt)
59128 +{
59129 + return;
59130 +}
59131 +
59132 +int
59133 +gr_set_acls(const int type)
59134 +{
59135 + return 0;
59136 +}
59137 +
59138 +int
59139 +gr_check_hidden_task(const struct task_struct *tsk)
59140 +{
59141 + return 0;
59142 +}
59143 +
59144 +int
59145 +gr_check_protected_task(const struct task_struct *task)
59146 +{
59147 + return 0;
59148 +}
59149 +
59150 +int
59151 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59152 +{
59153 + return 0;
59154 +}
59155 +
59156 +void
59157 +gr_copy_label(struct task_struct *tsk)
59158 +{
59159 + return;
59160 +}
59161 +
59162 +void
59163 +gr_set_pax_flags(struct task_struct *task)
59164 +{
59165 + return;
59166 +}
59167 +
59168 +int
59169 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59170 + const int unsafe_share)
59171 +{
59172 + return 0;
59173 +}
59174 +
59175 +void
59176 +gr_handle_delete(const ino_t ino, const dev_t dev)
59177 +{
59178 + return;
59179 +}
59180 +
59181 +void
59182 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59183 +{
59184 + return;
59185 +}
59186 +
59187 +void
59188 +gr_handle_crash(struct task_struct *task, const int sig)
59189 +{
59190 + return;
59191 +}
59192 +
59193 +int
59194 +gr_check_crash_exec(const struct file *filp)
59195 +{
59196 + return 0;
59197 +}
59198 +
59199 +int
59200 +gr_check_crash_uid(const uid_t uid)
59201 +{
59202 + return 0;
59203 +}
59204 +
59205 +void
59206 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59207 + struct dentry *old_dentry,
59208 + struct dentry *new_dentry,
59209 + struct vfsmount *mnt, const __u8 replace)
59210 +{
59211 + return;
59212 +}
59213 +
59214 +int
59215 +gr_search_socket(const int family, const int type, const int protocol)
59216 +{
59217 + return 1;
59218 +}
59219 +
59220 +int
59221 +gr_search_connectbind(const int mode, const struct socket *sock,
59222 + const struct sockaddr_in *addr)
59223 +{
59224 + return 0;
59225 +}
59226 +
59227 +void
59228 +gr_handle_alertkill(struct task_struct *task)
59229 +{
59230 + return;
59231 +}
59232 +
59233 +__u32
59234 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59235 +{
59236 + return 1;
59237 +}
59238 +
59239 +__u32
59240 +gr_acl_handle_hidden_file(const struct dentry * dentry,
59241 + const struct vfsmount * mnt)
59242 +{
59243 + return 1;
59244 +}
59245 +
59246 +__u32
59247 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59248 + int acc_mode)
59249 +{
59250 + return 1;
59251 +}
59252 +
59253 +__u32
59254 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59255 +{
59256 + return 1;
59257 +}
59258 +
59259 +__u32
59260 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59261 +{
59262 + return 1;
59263 +}
59264 +
59265 +int
59266 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59267 + unsigned int *vm_flags)
59268 +{
59269 + return 1;
59270 +}
59271 +
59272 +__u32
59273 +gr_acl_handle_truncate(const struct dentry * dentry,
59274 + const struct vfsmount * mnt)
59275 +{
59276 + return 1;
59277 +}
59278 +
59279 +__u32
59280 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59281 +{
59282 + return 1;
59283 +}
59284 +
59285 +__u32
59286 +gr_acl_handle_access(const struct dentry * dentry,
59287 + const struct vfsmount * mnt, const int fmode)
59288 +{
59289 + return 1;
59290 +}
59291 +
59292 +__u32
59293 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
59294 + umode_t *mode)
59295 +{
59296 + return 1;
59297 +}
59298 +
59299 +__u32
59300 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
59301 +{
59302 + return 1;
59303 +}
59304 +
59305 +__u32
59306 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
59307 +{
59308 + return 1;
59309 +}
59310 +
59311 +void
59312 +grsecurity_init(void)
59313 +{
59314 + return;
59315 +}
59316 +
59317 +umode_t gr_acl_umask(void)
59318 +{
59319 + return 0;
59320 +}
59321 +
59322 +__u32
59323 +gr_acl_handle_mknod(const struct dentry * new_dentry,
59324 + const struct dentry * parent_dentry,
59325 + const struct vfsmount * parent_mnt,
59326 + const int mode)
59327 +{
59328 + return 1;
59329 +}
59330 +
59331 +__u32
59332 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
59333 + const struct dentry * parent_dentry,
59334 + const struct vfsmount * parent_mnt)
59335 +{
59336 + return 1;
59337 +}
59338 +
59339 +__u32
59340 +gr_acl_handle_symlink(const struct dentry * new_dentry,
59341 + const struct dentry * parent_dentry,
59342 + const struct vfsmount * parent_mnt, const struct filename *from)
59343 +{
59344 + return 1;
59345 +}
59346 +
59347 +__u32
59348 +gr_acl_handle_link(const struct dentry * new_dentry,
59349 + const struct dentry * parent_dentry,
59350 + const struct vfsmount * parent_mnt,
59351 + const struct dentry * old_dentry,
59352 + const struct vfsmount * old_mnt, const struct filename *to)
59353 +{
59354 + return 1;
59355 +}
59356 +
59357 +int
59358 +gr_acl_handle_rename(const struct dentry *new_dentry,
59359 + const struct dentry *parent_dentry,
59360 + const struct vfsmount *parent_mnt,
59361 + const struct dentry *old_dentry,
59362 + const struct inode *old_parent_inode,
59363 + const struct vfsmount *old_mnt, const struct filename *newname)
59364 +{
59365 + return 0;
59366 +}
59367 +
59368 +int
59369 +gr_acl_handle_filldir(const struct file *file, const char *name,
59370 + const int namelen, const ino_t ino)
59371 +{
59372 + return 1;
59373 +}
59374 +
59375 +int
59376 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59377 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59378 +{
59379 + return 1;
59380 +}
59381 +
59382 +int
59383 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
59384 +{
59385 + return 0;
59386 +}
59387 +
59388 +int
59389 +gr_search_accept(const struct socket *sock)
59390 +{
59391 + return 0;
59392 +}
59393 +
59394 +int
59395 +gr_search_listen(const struct socket *sock)
59396 +{
59397 + return 0;
59398 +}
59399 +
59400 +int
59401 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
59402 +{
59403 + return 0;
59404 +}
59405 +
59406 +__u32
59407 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
59408 +{
59409 + return 1;
59410 +}
59411 +
59412 +__u32
59413 +gr_acl_handle_creat(const struct dentry * dentry,
59414 + const struct dentry * p_dentry,
59415 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
59416 + const int imode)
59417 +{
59418 + return 1;
59419 +}
59420 +
59421 +void
59422 +gr_acl_handle_exit(void)
59423 +{
59424 + return;
59425 +}
59426 +
59427 +int
59428 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59429 +{
59430 + return 1;
59431 +}
59432 +
59433 +void
59434 +gr_set_role_label(const uid_t uid, const gid_t gid)
59435 +{
59436 + return;
59437 +}
59438 +
59439 +int
59440 +gr_acl_handle_procpidmem(const struct task_struct *task)
59441 +{
59442 + return 0;
59443 +}
59444 +
59445 +int
59446 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
59447 +{
59448 + return 0;
59449 +}
59450 +
59451 +int
59452 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
59453 +{
59454 + return 0;
59455 +}
59456 +
59457 +void
59458 +gr_set_kernel_label(struct task_struct *task)
59459 +{
59460 + return;
59461 +}
59462 +
59463 +int
59464 +gr_check_user_change(int real, int effective, int fs)
59465 +{
59466 + return 0;
59467 +}
59468 +
59469 +int
59470 +gr_check_group_change(int real, int effective, int fs)
59471 +{
59472 + return 0;
59473 +}
59474 +
59475 +int gr_acl_enable_at_secure(void)
59476 +{
59477 + return 0;
59478 +}
59479 +
59480 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
59481 +{
59482 + return dentry->d_inode->i_sb->s_dev;
59483 +}
59484 +
59485 +void gr_put_exec_file(struct task_struct *task)
59486 +{
59487 + return;
59488 +}
59489 +
59490 +EXPORT_SYMBOL(gr_learn_resource);
59491 +EXPORT_SYMBOL(gr_set_kernel_label);
59492 +#ifdef CONFIG_SECURITY
59493 +EXPORT_SYMBOL(gr_check_user_change);
59494 +EXPORT_SYMBOL(gr_check_group_change);
59495 +#endif
59496 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
59497 new file mode 100644
59498 index 0000000..abfa971
59499 --- /dev/null
59500 +++ b/grsecurity/grsec_exec.c
59501 @@ -0,0 +1,174 @@
59502 +#include <linux/kernel.h>
59503 +#include <linux/sched.h>
59504 +#include <linux/file.h>
59505 +#include <linux/binfmts.h>
59506 +#include <linux/fs.h>
59507 +#include <linux/types.h>
59508 +#include <linux/grdefs.h>
59509 +#include <linux/grsecurity.h>
59510 +#include <linux/grinternal.h>
59511 +#include <linux/capability.h>
59512 +#include <linux/module.h>
59513 +
59514 +#include <asm/uaccess.h>
59515 +
59516 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59517 +static char gr_exec_arg_buf[132];
59518 +static DEFINE_MUTEX(gr_exec_arg_mutex);
59519 +#endif
59520 +
59521 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
59522 +
59523 +void
59524 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
59525 +{
59526 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59527 + char *grarg = gr_exec_arg_buf;
59528 + unsigned int i, x, execlen = 0;
59529 + char c;
59530 +
59531 + if (!((grsec_enable_execlog && grsec_enable_group &&
59532 + in_group_p(grsec_audit_gid))
59533 + || (grsec_enable_execlog && !grsec_enable_group)))
59534 + return;
59535 +
59536 + mutex_lock(&gr_exec_arg_mutex);
59537 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
59538 +
59539 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
59540 + const char __user *p;
59541 + unsigned int len;
59542 +
59543 + p = get_user_arg_ptr(argv, i);
59544 + if (IS_ERR(p))
59545 + goto log;
59546 +
59547 + len = strnlen_user(p, 128 - execlen);
59548 + if (len > 128 - execlen)
59549 + len = 128 - execlen;
59550 + else if (len > 0)
59551 + len--;
59552 + if (copy_from_user(grarg + execlen, p, len))
59553 + goto log;
59554 +
59555 + /* rewrite unprintable characters */
59556 + for (x = 0; x < len; x++) {
59557 + c = *(grarg + execlen + x);
59558 + if (c < 32 || c > 126)
59559 + *(grarg + execlen + x) = ' ';
59560 + }
59561 +
59562 + execlen += len;
59563 + *(grarg + execlen) = ' ';
59564 + *(grarg + execlen + 1) = '\0';
59565 + execlen++;
59566 + }
59567 +
59568 + log:
59569 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
59570 + bprm->file->f_path.mnt, grarg);
59571 + mutex_unlock(&gr_exec_arg_mutex);
59572 +#endif
59573 + return;
59574 +}
59575 +
59576 +#ifdef CONFIG_GRKERNSEC
59577 +extern int gr_acl_is_capable(const int cap);
59578 +extern int gr_acl_is_capable_nolog(const int cap);
59579 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59580 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
59581 +extern int gr_chroot_is_capable(const int cap);
59582 +extern int gr_chroot_is_capable_nolog(const int cap);
59583 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59584 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
59585 +#endif
59586 +
59587 +const char *captab_log[] = {
59588 + "CAP_CHOWN",
59589 + "CAP_DAC_OVERRIDE",
59590 + "CAP_DAC_READ_SEARCH",
59591 + "CAP_FOWNER",
59592 + "CAP_FSETID",
59593 + "CAP_KILL",
59594 + "CAP_SETGID",
59595 + "CAP_SETUID",
59596 + "CAP_SETPCAP",
59597 + "CAP_LINUX_IMMUTABLE",
59598 + "CAP_NET_BIND_SERVICE",
59599 + "CAP_NET_BROADCAST",
59600 + "CAP_NET_ADMIN",
59601 + "CAP_NET_RAW",
59602 + "CAP_IPC_LOCK",
59603 + "CAP_IPC_OWNER",
59604 + "CAP_SYS_MODULE",
59605 + "CAP_SYS_RAWIO",
59606 + "CAP_SYS_CHROOT",
59607 + "CAP_SYS_PTRACE",
59608 + "CAP_SYS_PACCT",
59609 + "CAP_SYS_ADMIN",
59610 + "CAP_SYS_BOOT",
59611 + "CAP_SYS_NICE",
59612 + "CAP_SYS_RESOURCE",
59613 + "CAP_SYS_TIME",
59614 + "CAP_SYS_TTY_CONFIG",
59615 + "CAP_MKNOD",
59616 + "CAP_LEASE",
59617 + "CAP_AUDIT_WRITE",
59618 + "CAP_AUDIT_CONTROL",
59619 + "CAP_SETFCAP",
59620 + "CAP_MAC_OVERRIDE",
59621 + "CAP_MAC_ADMIN",
59622 + "CAP_SYSLOG",
59623 + "CAP_WAKE_ALARM"
59624 +};
59625 +
59626 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
59627 +
59628 +int gr_is_capable(const int cap)
59629 +{
59630 +#ifdef CONFIG_GRKERNSEC
59631 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
59632 + return 1;
59633 + return 0;
59634 +#else
59635 + return 1;
59636 +#endif
59637 +}
59638 +
59639 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59640 +{
59641 +#ifdef CONFIG_GRKERNSEC
59642 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
59643 + return 1;
59644 + return 0;
59645 +#else
59646 + return 1;
59647 +#endif
59648 +}
59649 +
59650 +int gr_is_capable_nolog(const int cap)
59651 +{
59652 +#ifdef CONFIG_GRKERNSEC
59653 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
59654 + return 1;
59655 + return 0;
59656 +#else
59657 + return 1;
59658 +#endif
59659 +}
59660 +
59661 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
59662 +{
59663 +#ifdef CONFIG_GRKERNSEC
59664 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
59665 + return 1;
59666 + return 0;
59667 +#else
59668 + return 1;
59669 +#endif
59670 +}
59671 +
59672 +EXPORT_SYMBOL(gr_is_capable);
59673 +EXPORT_SYMBOL(gr_is_capable_nolog);
59674 +EXPORT_SYMBOL(gr_task_is_capable);
59675 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
59676 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
59677 new file mode 100644
59678 index 0000000..d3ee748
59679 --- /dev/null
59680 +++ b/grsecurity/grsec_fifo.c
59681 @@ -0,0 +1,24 @@
59682 +#include <linux/kernel.h>
59683 +#include <linux/sched.h>
59684 +#include <linux/fs.h>
59685 +#include <linux/file.h>
59686 +#include <linux/grinternal.h>
59687 +
59688 +int
59689 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
59690 + const struct dentry *dir, const int flag, const int acc_mode)
59691 +{
59692 +#ifdef CONFIG_GRKERNSEC_FIFO
59693 + const struct cred *cred = current_cred();
59694 +
59695 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
59696 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
59697 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
59698 + (cred->fsuid != dentry->d_inode->i_uid)) {
59699 + if (!inode_permission(dentry->d_inode, acc_mode))
59700 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
59701 + return -EACCES;
59702 + }
59703 +#endif
59704 + return 0;
59705 +}
59706 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
59707 new file mode 100644
59708 index 0000000..8ca18bf
59709 --- /dev/null
59710 +++ b/grsecurity/grsec_fork.c
59711 @@ -0,0 +1,23 @@
59712 +#include <linux/kernel.h>
59713 +#include <linux/sched.h>
59714 +#include <linux/grsecurity.h>
59715 +#include <linux/grinternal.h>
59716 +#include <linux/errno.h>
59717 +
59718 +void
59719 +gr_log_forkfail(const int retval)
59720 +{
59721 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59722 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
59723 + switch (retval) {
59724 + case -EAGAIN:
59725 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
59726 + break;
59727 + case -ENOMEM:
59728 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
59729 + break;
59730 + }
59731 + }
59732 +#endif
59733 + return;
59734 +}
59735 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
59736 new file mode 100644
59737 index 0000000..05a6015
59738 --- /dev/null
59739 +++ b/grsecurity/grsec_init.c
59740 @@ -0,0 +1,283 @@
59741 +#include <linux/kernel.h>
59742 +#include <linux/sched.h>
59743 +#include <linux/mm.h>
59744 +#include <linux/gracl.h>
59745 +#include <linux/slab.h>
59746 +#include <linux/vmalloc.h>
59747 +#include <linux/percpu.h>
59748 +#include <linux/module.h>
59749 +
59750 +int grsec_enable_ptrace_readexec;
59751 +int grsec_enable_setxid;
59752 +int grsec_enable_symlinkown;
59753 +int grsec_symlinkown_gid;
59754 +int grsec_enable_brute;
59755 +int grsec_enable_link;
59756 +int grsec_enable_dmesg;
59757 +int grsec_enable_harden_ptrace;
59758 +int grsec_enable_fifo;
59759 +int grsec_enable_execlog;
59760 +int grsec_enable_signal;
59761 +int grsec_enable_forkfail;
59762 +int grsec_enable_audit_ptrace;
59763 +int grsec_enable_time;
59764 +int grsec_enable_audit_textrel;
59765 +int grsec_enable_group;
59766 +int grsec_audit_gid;
59767 +int grsec_enable_chdir;
59768 +int grsec_enable_mount;
59769 +int grsec_enable_rofs;
59770 +int grsec_enable_chroot_findtask;
59771 +int grsec_enable_chroot_mount;
59772 +int grsec_enable_chroot_shmat;
59773 +int grsec_enable_chroot_fchdir;
59774 +int grsec_enable_chroot_double;
59775 +int grsec_enable_chroot_pivot;
59776 +int grsec_enable_chroot_chdir;
59777 +int grsec_enable_chroot_chmod;
59778 +int grsec_enable_chroot_mknod;
59779 +int grsec_enable_chroot_nice;
59780 +int grsec_enable_chroot_execlog;
59781 +int grsec_enable_chroot_caps;
59782 +int grsec_enable_chroot_sysctl;
59783 +int grsec_enable_chroot_unix;
59784 +int grsec_enable_tpe;
59785 +int grsec_tpe_gid;
59786 +int grsec_enable_blackhole;
59787 +#ifdef CONFIG_IPV6_MODULE
59788 +EXPORT_SYMBOL(grsec_enable_blackhole);
59789 +#endif
59790 +int grsec_lastack_retries;
59791 +int grsec_enable_tpe_all;
59792 +int grsec_enable_tpe_invert;
59793 +int grsec_enable_socket_all;
59794 +int grsec_socket_all_gid;
59795 +int grsec_enable_socket_client;
59796 +int grsec_socket_client_gid;
59797 +int grsec_enable_socket_server;
59798 +int grsec_socket_server_gid;
59799 +int grsec_resource_logging;
59800 +int grsec_disable_privio;
59801 +int grsec_enable_log_rwxmaps;
59802 +int grsec_lock;
59803 +
59804 +DEFINE_SPINLOCK(grsec_alert_lock);
59805 +unsigned long grsec_alert_wtime = 0;
59806 +unsigned long grsec_alert_fyet = 0;
59807 +
59808 +DEFINE_SPINLOCK(grsec_audit_lock);
59809 +
59810 +DEFINE_RWLOCK(grsec_exec_file_lock);
59811 +
59812 +char *gr_shared_page[4];
59813 +
59814 +char *gr_alert_log_fmt;
59815 +char *gr_audit_log_fmt;
59816 +char *gr_alert_log_buf;
59817 +char *gr_audit_log_buf;
59818 +
59819 +extern struct gr_arg *gr_usermode;
59820 +extern unsigned char *gr_system_salt;
59821 +extern unsigned char *gr_system_sum;
59822 +
59823 +void __init
59824 +grsecurity_init(void)
59825 +{
59826 + int j;
59827 + /* create the per-cpu shared pages */
59828 +
59829 +#ifdef CONFIG_X86
59830 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
59831 +#endif
59832 +
59833 + for (j = 0; j < 4; j++) {
59834 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
59835 + if (gr_shared_page[j] == NULL) {
59836 + panic("Unable to allocate grsecurity shared page");
59837 + return;
59838 + }
59839 + }
59840 +
59841 + /* allocate log buffers */
59842 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
59843 + if (!gr_alert_log_fmt) {
59844 + panic("Unable to allocate grsecurity alert log format buffer");
59845 + return;
59846 + }
59847 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
59848 + if (!gr_audit_log_fmt) {
59849 + panic("Unable to allocate grsecurity audit log format buffer");
59850 + return;
59851 + }
59852 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59853 + if (!gr_alert_log_buf) {
59854 + panic("Unable to allocate grsecurity alert log buffer");
59855 + return;
59856 + }
59857 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59858 + if (!gr_audit_log_buf) {
59859 + panic("Unable to allocate grsecurity audit log buffer");
59860 + return;
59861 + }
59862 +
59863 + /* allocate memory for authentication structure */
59864 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
59865 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
59866 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
59867 +
59868 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
59869 + panic("Unable to allocate grsecurity authentication structure");
59870 + return;
59871 + }
59872 +
59873 +
59874 +#ifdef CONFIG_GRKERNSEC_IO
59875 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
59876 + grsec_disable_privio = 1;
59877 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59878 + grsec_disable_privio = 1;
59879 +#else
59880 + grsec_disable_privio = 0;
59881 +#endif
59882 +#endif
59883 +
59884 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59885 + /* for backward compatibility, tpe_invert always defaults to on if
59886 + enabled in the kernel
59887 + */
59888 + grsec_enable_tpe_invert = 1;
59889 +#endif
59890 +
59891 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59892 +#ifndef CONFIG_GRKERNSEC_SYSCTL
59893 + grsec_lock = 1;
59894 +#endif
59895 +
59896 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59897 + grsec_enable_audit_textrel = 1;
59898 +#endif
59899 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59900 + grsec_enable_log_rwxmaps = 1;
59901 +#endif
59902 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59903 + grsec_enable_group = 1;
59904 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
59905 +#endif
59906 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59907 + grsec_enable_ptrace_readexec = 1;
59908 +#endif
59909 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59910 + grsec_enable_chdir = 1;
59911 +#endif
59912 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59913 + grsec_enable_harden_ptrace = 1;
59914 +#endif
59915 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59916 + grsec_enable_mount = 1;
59917 +#endif
59918 +#ifdef CONFIG_GRKERNSEC_LINK
59919 + grsec_enable_link = 1;
59920 +#endif
59921 +#ifdef CONFIG_GRKERNSEC_BRUTE
59922 + grsec_enable_brute = 1;
59923 +#endif
59924 +#ifdef CONFIG_GRKERNSEC_DMESG
59925 + grsec_enable_dmesg = 1;
59926 +#endif
59927 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59928 + grsec_enable_blackhole = 1;
59929 + grsec_lastack_retries = 4;
59930 +#endif
59931 +#ifdef CONFIG_GRKERNSEC_FIFO
59932 + grsec_enable_fifo = 1;
59933 +#endif
59934 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59935 + grsec_enable_execlog = 1;
59936 +#endif
59937 +#ifdef CONFIG_GRKERNSEC_SETXID
59938 + grsec_enable_setxid = 1;
59939 +#endif
59940 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59941 + grsec_enable_signal = 1;
59942 +#endif
59943 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59944 + grsec_enable_forkfail = 1;
59945 +#endif
59946 +#ifdef CONFIG_GRKERNSEC_TIME
59947 + grsec_enable_time = 1;
59948 +#endif
59949 +#ifdef CONFIG_GRKERNSEC_RESLOG
59950 + grsec_resource_logging = 1;
59951 +#endif
59952 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59953 + grsec_enable_chroot_findtask = 1;
59954 +#endif
59955 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59956 + grsec_enable_chroot_unix = 1;
59957 +#endif
59958 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59959 + grsec_enable_chroot_mount = 1;
59960 +#endif
59961 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59962 + grsec_enable_chroot_fchdir = 1;
59963 +#endif
59964 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59965 + grsec_enable_chroot_shmat = 1;
59966 +#endif
59967 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59968 + grsec_enable_audit_ptrace = 1;
59969 +#endif
59970 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59971 + grsec_enable_chroot_double = 1;
59972 +#endif
59973 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59974 + grsec_enable_chroot_pivot = 1;
59975 +#endif
59976 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59977 + grsec_enable_chroot_chdir = 1;
59978 +#endif
59979 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59980 + grsec_enable_chroot_chmod = 1;
59981 +#endif
59982 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59983 + grsec_enable_chroot_mknod = 1;
59984 +#endif
59985 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59986 + grsec_enable_chroot_nice = 1;
59987 +#endif
59988 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59989 + grsec_enable_chroot_execlog = 1;
59990 +#endif
59991 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59992 + grsec_enable_chroot_caps = 1;
59993 +#endif
59994 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59995 + grsec_enable_chroot_sysctl = 1;
59996 +#endif
59997 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59998 + grsec_enable_symlinkown = 1;
59999 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60000 +#endif
60001 +#ifdef CONFIG_GRKERNSEC_TPE
60002 + grsec_enable_tpe = 1;
60003 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60004 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60005 + grsec_enable_tpe_all = 1;
60006 +#endif
60007 +#endif
60008 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60009 + grsec_enable_socket_all = 1;
60010 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60011 +#endif
60012 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60013 + grsec_enable_socket_client = 1;
60014 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60015 +#endif
60016 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60017 + grsec_enable_socket_server = 1;
60018 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60019 +#endif
60020 +#endif
60021 +
60022 + return;
60023 +}
60024 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60025 new file mode 100644
60026 index 0000000..6095407
60027 --- /dev/null
60028 +++ b/grsecurity/grsec_link.c
60029 @@ -0,0 +1,58 @@
60030 +#include <linux/kernel.h>
60031 +#include <linux/sched.h>
60032 +#include <linux/fs.h>
60033 +#include <linux/file.h>
60034 +#include <linux/grinternal.h>
60035 +
60036 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60037 +{
60038 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60039 + const struct inode *link_inode = link->dentry->d_inode;
60040 +
60041 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60042 + /* ignore root-owned links, e.g. /proc/self */
60043 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60044 + !uid_eq(link_inode->i_uid, target->i_uid)) {
60045 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60046 + return 1;
60047 + }
60048 +#endif
60049 + return 0;
60050 +}
60051 +
60052 +int
60053 +gr_handle_follow_link(const struct inode *parent,
60054 + const struct inode *inode,
60055 + const struct dentry *dentry, const struct vfsmount *mnt)
60056 +{
60057 +#ifdef CONFIG_GRKERNSEC_LINK
60058 + const struct cred *cred = current_cred();
60059 +
60060 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60061 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60062 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60063 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60064 + return -EACCES;
60065 + }
60066 +#endif
60067 + return 0;
60068 +}
60069 +
60070 +int
60071 +gr_handle_hardlink(const struct dentry *dentry,
60072 + const struct vfsmount *mnt,
60073 + struct inode *inode, const int mode, const struct filename *to)
60074 +{
60075 +#ifdef CONFIG_GRKERNSEC_LINK
60076 + const struct cred *cred = current_cred();
60077 +
60078 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60079 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60080 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60081 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60082 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60083 + return -EPERM;
60084 + }
60085 +#endif
60086 + return 0;
60087 +}
60088 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60089 new file mode 100644
60090 index 0000000..a45d2e9
60091 --- /dev/null
60092 +++ b/grsecurity/grsec_log.c
60093 @@ -0,0 +1,322 @@
60094 +#include <linux/kernel.h>
60095 +#include <linux/sched.h>
60096 +#include <linux/file.h>
60097 +#include <linux/tty.h>
60098 +#include <linux/fs.h>
60099 +#include <linux/grinternal.h>
60100 +
60101 +#ifdef CONFIG_TREE_PREEMPT_RCU
60102 +#define DISABLE_PREEMPT() preempt_disable()
60103 +#define ENABLE_PREEMPT() preempt_enable()
60104 +#else
60105 +#define DISABLE_PREEMPT()
60106 +#define ENABLE_PREEMPT()
60107 +#endif
60108 +
60109 +#define BEGIN_LOCKS(x) \
60110 + DISABLE_PREEMPT(); \
60111 + rcu_read_lock(); \
60112 + read_lock(&tasklist_lock); \
60113 + read_lock(&grsec_exec_file_lock); \
60114 + if (x != GR_DO_AUDIT) \
60115 + spin_lock(&grsec_alert_lock); \
60116 + else \
60117 + spin_lock(&grsec_audit_lock)
60118 +
60119 +#define END_LOCKS(x) \
60120 + if (x != GR_DO_AUDIT) \
60121 + spin_unlock(&grsec_alert_lock); \
60122 + else \
60123 + spin_unlock(&grsec_audit_lock); \
60124 + read_unlock(&grsec_exec_file_lock); \
60125 + read_unlock(&tasklist_lock); \
60126 + rcu_read_unlock(); \
60127 + ENABLE_PREEMPT(); \
60128 + if (x == GR_DONT_AUDIT) \
60129 + gr_handle_alertkill(current)
60130 +
60131 +enum {
60132 + FLOODING,
60133 + NO_FLOODING
60134 +};
60135 +
60136 +extern char *gr_alert_log_fmt;
60137 +extern char *gr_audit_log_fmt;
60138 +extern char *gr_alert_log_buf;
60139 +extern char *gr_audit_log_buf;
60140 +
60141 +static int gr_log_start(int audit)
60142 +{
60143 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60144 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60145 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60146 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60147 + unsigned long curr_secs = get_seconds();
60148 +
60149 + if (audit == GR_DO_AUDIT)
60150 + goto set_fmt;
60151 +
60152 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60153 + grsec_alert_wtime = curr_secs;
60154 + grsec_alert_fyet = 0;
60155 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60156 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60157 + grsec_alert_fyet++;
60158 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60159 + grsec_alert_wtime = curr_secs;
60160 + grsec_alert_fyet++;
60161 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60162 + return FLOODING;
60163 + }
60164 + else return FLOODING;
60165 +
60166 +set_fmt:
60167 +#endif
60168 + memset(buf, 0, PAGE_SIZE);
60169 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
60170 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60171 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60172 + } else if (current->signal->curr_ip) {
60173 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60174 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60175 + } else if (gr_acl_is_enabled()) {
60176 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60177 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60178 + } else {
60179 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
60180 + strcpy(buf, fmt);
60181 + }
60182 +
60183 + return NO_FLOODING;
60184 +}
60185 +
60186 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60187 + __attribute__ ((format (printf, 2, 0)));
60188 +
60189 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60190 +{
60191 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60192 + unsigned int len = strlen(buf);
60193 +
60194 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60195 +
60196 + return;
60197 +}
60198 +
60199 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60200 + __attribute__ ((format (printf, 2, 3)));
60201 +
60202 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60203 +{
60204 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60205 + unsigned int len = strlen(buf);
60206 + va_list ap;
60207 +
60208 + va_start(ap, msg);
60209 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60210 + va_end(ap);
60211 +
60212 + return;
60213 +}
60214 +
60215 +static void gr_log_end(int audit, int append_default)
60216 +{
60217 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60218 +
60219 + if (append_default) {
60220 + unsigned int len = strlen(buf);
60221 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
60222 + }
60223 +
60224 + printk("%s\n", buf);
60225 +
60226 + return;
60227 +}
60228 +
60229 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60230 +{
60231 + int logtype;
60232 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60233 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60234 + void *voidptr = NULL;
60235 + int num1 = 0, num2 = 0;
60236 + unsigned long ulong1 = 0, ulong2 = 0;
60237 + struct dentry *dentry = NULL;
60238 + struct vfsmount *mnt = NULL;
60239 + struct file *file = NULL;
60240 + struct task_struct *task = NULL;
60241 + const struct cred *cred, *pcred;
60242 + va_list ap;
60243 +
60244 + BEGIN_LOCKS(audit);
60245 + logtype = gr_log_start(audit);
60246 + if (logtype == FLOODING) {
60247 + END_LOCKS(audit);
60248 + return;
60249 + }
60250 + va_start(ap, argtypes);
60251 + switch (argtypes) {
60252 + case GR_TTYSNIFF:
60253 + task = va_arg(ap, struct task_struct *);
60254 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
60255 + break;
60256 + case GR_SYSCTL_HIDDEN:
60257 + str1 = va_arg(ap, char *);
60258 + gr_log_middle_varargs(audit, msg, result, str1);
60259 + break;
60260 + case GR_RBAC:
60261 + dentry = va_arg(ap, struct dentry *);
60262 + mnt = va_arg(ap, struct vfsmount *);
60263 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60264 + break;
60265 + case GR_RBAC_STR:
60266 + dentry = va_arg(ap, struct dentry *);
60267 + mnt = va_arg(ap, struct vfsmount *);
60268 + str1 = va_arg(ap, char *);
60269 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60270 + break;
60271 + case GR_STR_RBAC:
60272 + str1 = va_arg(ap, char *);
60273 + dentry = va_arg(ap, struct dentry *);
60274 + mnt = va_arg(ap, struct vfsmount *);
60275 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60276 + break;
60277 + case GR_RBAC_MODE2:
60278 + dentry = va_arg(ap, struct dentry *);
60279 + mnt = va_arg(ap, struct vfsmount *);
60280 + str1 = va_arg(ap, char *);
60281 + str2 = va_arg(ap, char *);
60282 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
60283 + break;
60284 + case GR_RBAC_MODE3:
60285 + dentry = va_arg(ap, struct dentry *);
60286 + mnt = va_arg(ap, struct vfsmount *);
60287 + str1 = va_arg(ap, char *);
60288 + str2 = va_arg(ap, char *);
60289 + str3 = va_arg(ap, char *);
60290 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
60291 + break;
60292 + case GR_FILENAME:
60293 + dentry = va_arg(ap, struct dentry *);
60294 + mnt = va_arg(ap, struct vfsmount *);
60295 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
60296 + break;
60297 + case GR_STR_FILENAME:
60298 + str1 = va_arg(ap, char *);
60299 + dentry = va_arg(ap, struct dentry *);
60300 + mnt = va_arg(ap, struct vfsmount *);
60301 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
60302 + break;
60303 + case GR_FILENAME_STR:
60304 + dentry = va_arg(ap, struct dentry *);
60305 + mnt = va_arg(ap, struct vfsmount *);
60306 + str1 = va_arg(ap, char *);
60307 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
60308 + break;
60309 + case GR_FILENAME_TWO_INT:
60310 + dentry = va_arg(ap, struct dentry *);
60311 + mnt = va_arg(ap, struct vfsmount *);
60312 + num1 = va_arg(ap, int);
60313 + num2 = va_arg(ap, int);
60314 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
60315 + break;
60316 + case GR_FILENAME_TWO_INT_STR:
60317 + dentry = va_arg(ap, struct dentry *);
60318 + mnt = va_arg(ap, struct vfsmount *);
60319 + num1 = va_arg(ap, int);
60320 + num2 = va_arg(ap, int);
60321 + str1 = va_arg(ap, char *);
60322 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
60323 + break;
60324 + case GR_TEXTREL:
60325 + file = va_arg(ap, struct file *);
60326 + ulong1 = va_arg(ap, unsigned long);
60327 + ulong2 = va_arg(ap, unsigned long);
60328 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
60329 + break;
60330 + case GR_PTRACE:
60331 + task = va_arg(ap, struct task_struct *);
60332 + 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);
60333 + break;
60334 + case GR_RESOURCE:
60335 + task = va_arg(ap, struct task_struct *);
60336 + cred = __task_cred(task);
60337 + pcred = __task_cred(task->real_parent);
60338 + ulong1 = va_arg(ap, unsigned long);
60339 + str1 = va_arg(ap, char *);
60340 + ulong2 = va_arg(ap, unsigned long);
60341 + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60342 + break;
60343 + case GR_CAP:
60344 + task = va_arg(ap, struct task_struct *);
60345 + cred = __task_cred(task);
60346 + pcred = __task_cred(task->real_parent);
60347 + str1 = va_arg(ap, char *);
60348 + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60349 + break;
60350 + case GR_SIG:
60351 + str1 = va_arg(ap, char *);
60352 + voidptr = va_arg(ap, void *);
60353 + gr_log_middle_varargs(audit, msg, str1, voidptr);
60354 + break;
60355 + case GR_SIG2:
60356 + task = va_arg(ap, struct task_struct *);
60357 + cred = __task_cred(task);
60358 + pcred = __task_cred(task->real_parent);
60359 + num1 = va_arg(ap, int);
60360 + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60361 + break;
60362 + case GR_CRASH1:
60363 + task = va_arg(ap, struct task_struct *);
60364 + cred = __task_cred(task);
60365 + pcred = __task_cred(task->real_parent);
60366 + ulong1 = va_arg(ap, unsigned long);
60367 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
60368 + break;
60369 + case GR_CRASH2:
60370 + task = va_arg(ap, struct task_struct *);
60371 + cred = __task_cred(task);
60372 + pcred = __task_cred(task->real_parent);
60373 + ulong1 = va_arg(ap, unsigned long);
60374 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
60375 + break;
60376 + case GR_RWXMAP:
60377 + file = va_arg(ap, struct file *);
60378 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
60379 + break;
60380 + case GR_PSACCT:
60381 + {
60382 + unsigned int wday, cday;
60383 + __u8 whr, chr;
60384 + __u8 wmin, cmin;
60385 + __u8 wsec, csec;
60386 + char cur_tty[64] = { 0 };
60387 + char parent_tty[64] = { 0 };
60388 +
60389 + task = va_arg(ap, struct task_struct *);
60390 + wday = va_arg(ap, unsigned int);
60391 + cday = va_arg(ap, unsigned int);
60392 + whr = va_arg(ap, int);
60393 + chr = va_arg(ap, int);
60394 + wmin = va_arg(ap, int);
60395 + cmin = va_arg(ap, int);
60396 + wsec = va_arg(ap, int);
60397 + csec = va_arg(ap, int);
60398 + ulong1 = va_arg(ap, unsigned long);
60399 + cred = __task_cred(task);
60400 + pcred = __task_cred(task->real_parent);
60401 +
60402 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->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->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60403 + }
60404 + break;
60405 + default:
60406 + gr_log_middle(audit, msg, ap);
60407 + }
60408 + va_end(ap);
60409 + // these don't need DEFAULTSECARGS printed on the end
60410 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
60411 + gr_log_end(audit, 0);
60412 + else
60413 + gr_log_end(audit, 1);
60414 + END_LOCKS(audit);
60415 +}
60416 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
60417 new file mode 100644
60418 index 0000000..f536303
60419 --- /dev/null
60420 +++ b/grsecurity/grsec_mem.c
60421 @@ -0,0 +1,40 @@
60422 +#include <linux/kernel.h>
60423 +#include <linux/sched.h>
60424 +#include <linux/mm.h>
60425 +#include <linux/mman.h>
60426 +#include <linux/grinternal.h>
60427 +
60428 +void
60429 +gr_handle_ioperm(void)
60430 +{
60431 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
60432 + return;
60433 +}
60434 +
60435 +void
60436 +gr_handle_iopl(void)
60437 +{
60438 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
60439 + return;
60440 +}
60441 +
60442 +void
60443 +gr_handle_mem_readwrite(u64 from, u64 to)
60444 +{
60445 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
60446 + return;
60447 +}
60448 +
60449 +void
60450 +gr_handle_vm86(void)
60451 +{
60452 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
60453 + return;
60454 +}
60455 +
60456 +void
60457 +gr_log_badprocpid(const char *entry)
60458 +{
60459 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
60460 + return;
60461 +}
60462 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
60463 new file mode 100644
60464 index 0000000..2131422
60465 --- /dev/null
60466 +++ b/grsecurity/grsec_mount.c
60467 @@ -0,0 +1,62 @@
60468 +#include <linux/kernel.h>
60469 +#include <linux/sched.h>
60470 +#include <linux/mount.h>
60471 +#include <linux/grsecurity.h>
60472 +#include <linux/grinternal.h>
60473 +
60474 +void
60475 +gr_log_remount(const char *devname, const int retval)
60476 +{
60477 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60478 + if (grsec_enable_mount && (retval >= 0))
60479 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
60480 +#endif
60481 + return;
60482 +}
60483 +
60484 +void
60485 +gr_log_unmount(const char *devname, const int retval)
60486 +{
60487 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60488 + if (grsec_enable_mount && (retval >= 0))
60489 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
60490 +#endif
60491 + return;
60492 +}
60493 +
60494 +void
60495 +gr_log_mount(const char *from, const char *to, const int retval)
60496 +{
60497 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60498 + if (grsec_enable_mount && (retval >= 0))
60499 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
60500 +#endif
60501 + return;
60502 +}
60503 +
60504 +int
60505 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
60506 +{
60507 +#ifdef CONFIG_GRKERNSEC_ROFS
60508 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
60509 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
60510 + return -EPERM;
60511 + } else
60512 + return 0;
60513 +#endif
60514 + return 0;
60515 +}
60516 +
60517 +int
60518 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
60519 +{
60520 +#ifdef CONFIG_GRKERNSEC_ROFS
60521 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
60522 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
60523 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
60524 + return -EPERM;
60525 + } else
60526 + return 0;
60527 +#endif
60528 + return 0;
60529 +}
60530 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
60531 new file mode 100644
60532 index 0000000..a3b12a0
60533 --- /dev/null
60534 +++ b/grsecurity/grsec_pax.c
60535 @@ -0,0 +1,36 @@
60536 +#include <linux/kernel.h>
60537 +#include <linux/sched.h>
60538 +#include <linux/mm.h>
60539 +#include <linux/file.h>
60540 +#include <linux/grinternal.h>
60541 +#include <linux/grsecurity.h>
60542 +
60543 +void
60544 +gr_log_textrel(struct vm_area_struct * vma)
60545 +{
60546 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60547 + if (grsec_enable_audit_textrel)
60548 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
60549 +#endif
60550 + return;
60551 +}
60552 +
60553 +void
60554 +gr_log_rwxmmap(struct file *file)
60555 +{
60556 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60557 + if (grsec_enable_log_rwxmaps)
60558 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
60559 +#endif
60560 + return;
60561 +}
60562 +
60563 +void
60564 +gr_log_rwxmprotect(struct file *file)
60565 +{
60566 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60567 + if (grsec_enable_log_rwxmaps)
60568 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
60569 +#endif
60570 + return;
60571 +}
60572 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
60573 new file mode 100644
60574 index 0000000..f7f29aa
60575 --- /dev/null
60576 +++ b/grsecurity/grsec_ptrace.c
60577 @@ -0,0 +1,30 @@
60578 +#include <linux/kernel.h>
60579 +#include <linux/sched.h>
60580 +#include <linux/grinternal.h>
60581 +#include <linux/security.h>
60582 +
60583 +void
60584 +gr_audit_ptrace(struct task_struct *task)
60585 +{
60586 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60587 + if (grsec_enable_audit_ptrace)
60588 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
60589 +#endif
60590 + return;
60591 +}
60592 +
60593 +int
60594 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
60595 +{
60596 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60597 + const struct dentry *dentry = file->f_path.dentry;
60598 + const struct vfsmount *mnt = file->f_path.mnt;
60599 +
60600 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
60601 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
60602 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
60603 + return -EACCES;
60604 + }
60605 +#endif
60606 + return 0;
60607 +}
60608 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
60609 new file mode 100644
60610 index 0000000..5c00416
60611 --- /dev/null
60612 +++ b/grsecurity/grsec_sig.c
60613 @@ -0,0 +1,222 @@
60614 +#include <linux/kernel.h>
60615 +#include <linux/sched.h>
60616 +#include <linux/delay.h>
60617 +#include <linux/grsecurity.h>
60618 +#include <linux/grinternal.h>
60619 +#include <linux/hardirq.h>
60620 +
60621 +char *signames[] = {
60622 + [SIGSEGV] = "Segmentation fault",
60623 + [SIGILL] = "Illegal instruction",
60624 + [SIGABRT] = "Abort",
60625 + [SIGBUS] = "Invalid alignment/Bus error"
60626 +};
60627 +
60628 +void
60629 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
60630 +{
60631 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60632 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
60633 + (sig == SIGABRT) || (sig == SIGBUS))) {
60634 + if (t->pid == current->pid) {
60635 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
60636 + } else {
60637 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
60638 + }
60639 + }
60640 +#endif
60641 + return;
60642 +}
60643 +
60644 +int
60645 +gr_handle_signal(const struct task_struct *p, const int sig)
60646 +{
60647 +#ifdef CONFIG_GRKERNSEC
60648 + /* ignore the 0 signal for protected task checks */
60649 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
60650 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
60651 + return -EPERM;
60652 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
60653 + return -EPERM;
60654 + }
60655 +#endif
60656 + return 0;
60657 +}
60658 +
60659 +#ifdef CONFIG_GRKERNSEC
60660 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
60661 +
60662 +int gr_fake_force_sig(int sig, struct task_struct *t)
60663 +{
60664 + unsigned long int flags;
60665 + int ret, blocked, ignored;
60666 + struct k_sigaction *action;
60667 +
60668 + spin_lock_irqsave(&t->sighand->siglock, flags);
60669 + action = &t->sighand->action[sig-1];
60670 + ignored = action->sa.sa_handler == SIG_IGN;
60671 + blocked = sigismember(&t->blocked, sig);
60672 + if (blocked || ignored) {
60673 + action->sa.sa_handler = SIG_DFL;
60674 + if (blocked) {
60675 + sigdelset(&t->blocked, sig);
60676 + recalc_sigpending_and_wake(t);
60677 + }
60678 + }
60679 + if (action->sa.sa_handler == SIG_DFL)
60680 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
60681 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
60682 +
60683 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
60684 +
60685 + return ret;
60686 +}
60687 +#endif
60688 +
60689 +#ifdef CONFIG_GRKERNSEC_BRUTE
60690 +#define GR_USER_BAN_TIME (15 * 60)
60691 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
60692 +
60693 +static int __get_dumpable(unsigned long mm_flags)
60694 +{
60695 + int ret;
60696 +
60697 + ret = mm_flags & MMF_DUMPABLE_MASK;
60698 + return (ret >= 2) ? 2 : ret;
60699 +}
60700 +#endif
60701 +
60702 +void gr_handle_brute_attach(unsigned long mm_flags)
60703 +{
60704 +#ifdef CONFIG_GRKERNSEC_BRUTE
60705 + struct task_struct *p = current;
60706 + kuid_t uid = GLOBAL_ROOT_UID;
60707 + int daemon = 0;
60708 +
60709 + if (!grsec_enable_brute)
60710 + return;
60711 +
60712 + rcu_read_lock();
60713 + read_lock(&tasklist_lock);
60714 + read_lock(&grsec_exec_file_lock);
60715 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
60716 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
60717 + p->real_parent->brute = 1;
60718 + daemon = 1;
60719 + } else {
60720 + const struct cred *cred = __task_cred(p), *cred2;
60721 + struct task_struct *tsk, *tsk2;
60722 +
60723 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60724 + struct user_struct *user;
60725 +
60726 + uid = cred->uid;
60727 +
60728 + /* this is put upon execution past expiration */
60729 + user = find_user(uid);
60730 + if (user == NULL)
60731 + goto unlock;
60732 + user->banned = 1;
60733 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
60734 + if (user->ban_expires == ~0UL)
60735 + user->ban_expires--;
60736 +
60737 + do_each_thread(tsk2, tsk) {
60738 + cred2 = __task_cred(tsk);
60739 + if (tsk != p && uid_eq(cred2->uid, uid))
60740 + gr_fake_force_sig(SIGKILL, tsk);
60741 + } while_each_thread(tsk2, tsk);
60742 + }
60743 + }
60744 +unlock:
60745 + read_unlock(&grsec_exec_file_lock);
60746 + read_unlock(&tasklist_lock);
60747 + rcu_read_unlock();
60748 +
60749 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
60750 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
60751 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
60752 + else if (daemon)
60753 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
60754 +
60755 +#endif
60756 + return;
60757 +}
60758 +
60759 +void gr_handle_brute_check(void)
60760 +{
60761 +#ifdef CONFIG_GRKERNSEC_BRUTE
60762 + struct task_struct *p = current;
60763 +
60764 + if (unlikely(p->brute)) {
60765 + if (!grsec_enable_brute)
60766 + p->brute = 0;
60767 + else if (time_before(get_seconds(), p->brute_expires))
60768 + msleep(30 * 1000);
60769 + }
60770 +#endif
60771 + return;
60772 +}
60773 +
60774 +void gr_handle_kernel_exploit(void)
60775 +{
60776 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
60777 + const struct cred *cred;
60778 + struct task_struct *tsk, *tsk2;
60779 + struct user_struct *user;
60780 + kuid_t uid;
60781 +
60782 + if (in_irq() || in_serving_softirq() || in_nmi())
60783 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
60784 +
60785 + uid = current_uid();
60786 +
60787 + if (uid_eq(uid, GLOBAL_ROOT_UID))
60788 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
60789 + else {
60790 + /* kill all the processes of this user, hold a reference
60791 + to their creds struct, and prevent them from creating
60792 + another process until system reset
60793 + */
60794 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
60795 + from_kuid_munged(&init_user_ns, uid));
60796 + /* we intentionally leak this ref */
60797 + user = get_uid(current->cred->user);
60798 + if (user) {
60799 + user->banned = 1;
60800 + user->ban_expires = ~0UL;
60801 + }
60802 +
60803 + read_lock(&tasklist_lock);
60804 + do_each_thread(tsk2, tsk) {
60805 + cred = __task_cred(tsk);
60806 + if (uid_eq(cred->uid, uid))
60807 + gr_fake_force_sig(SIGKILL, tsk);
60808 + } while_each_thread(tsk2, tsk);
60809 + read_unlock(&tasklist_lock);
60810 + }
60811 +#endif
60812 +}
60813 +
60814 +int __gr_process_user_ban(struct user_struct *user)
60815 +{
60816 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60817 + if (unlikely(user->banned)) {
60818 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
60819 + user->banned = 0;
60820 + user->ban_expires = 0;
60821 + free_uid(user);
60822 + } else
60823 + return -EPERM;
60824 + }
60825 +#endif
60826 + return 0;
60827 +}
60828 +
60829 +int gr_process_user_ban(void)
60830 +{
60831 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60832 + return __gr_process_user_ban(current->cred->user);
60833 +#endif
60834 + return 0;
60835 +}
60836 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
60837 new file mode 100644
60838 index 0000000..4030d57
60839 --- /dev/null
60840 +++ b/grsecurity/grsec_sock.c
60841 @@ -0,0 +1,244 @@
60842 +#include <linux/kernel.h>
60843 +#include <linux/module.h>
60844 +#include <linux/sched.h>
60845 +#include <linux/file.h>
60846 +#include <linux/net.h>
60847 +#include <linux/in.h>
60848 +#include <linux/ip.h>
60849 +#include <net/sock.h>
60850 +#include <net/inet_sock.h>
60851 +#include <linux/grsecurity.h>
60852 +#include <linux/grinternal.h>
60853 +#include <linux/gracl.h>
60854 +
60855 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
60856 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
60857 +
60858 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
60859 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
60860 +
60861 +#ifdef CONFIG_UNIX_MODULE
60862 +EXPORT_SYMBOL(gr_acl_handle_unix);
60863 +EXPORT_SYMBOL(gr_acl_handle_mknod);
60864 +EXPORT_SYMBOL(gr_handle_chroot_unix);
60865 +EXPORT_SYMBOL(gr_handle_create);
60866 +#endif
60867 +
60868 +#ifdef CONFIG_GRKERNSEC
60869 +#define gr_conn_table_size 32749
60870 +struct conn_table_entry {
60871 + struct conn_table_entry *next;
60872 + struct signal_struct *sig;
60873 +};
60874 +
60875 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
60876 +DEFINE_SPINLOCK(gr_conn_table_lock);
60877 +
60878 +extern const char * gr_socktype_to_name(unsigned char type);
60879 +extern const char * gr_proto_to_name(unsigned char proto);
60880 +extern const char * gr_sockfamily_to_name(unsigned char family);
60881 +
60882 +static __inline__ int
60883 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
60884 +{
60885 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
60886 +}
60887 +
60888 +static __inline__ int
60889 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
60890 + __u16 sport, __u16 dport)
60891 +{
60892 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
60893 + sig->gr_sport == sport && sig->gr_dport == dport))
60894 + return 1;
60895 + else
60896 + return 0;
60897 +}
60898 +
60899 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
60900 +{
60901 + struct conn_table_entry **match;
60902 + unsigned int index;
60903 +
60904 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60905 + sig->gr_sport, sig->gr_dport,
60906 + gr_conn_table_size);
60907 +
60908 + newent->sig = sig;
60909 +
60910 + match = &gr_conn_table[index];
60911 + newent->next = *match;
60912 + *match = newent;
60913 +
60914 + return;
60915 +}
60916 +
60917 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
60918 +{
60919 + struct conn_table_entry *match, *last = NULL;
60920 + unsigned int index;
60921 +
60922 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60923 + sig->gr_sport, sig->gr_dport,
60924 + gr_conn_table_size);
60925 +
60926 + match = gr_conn_table[index];
60927 + while (match && !conn_match(match->sig,
60928 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
60929 + sig->gr_dport)) {
60930 + last = match;
60931 + match = match->next;
60932 + }
60933 +
60934 + if (match) {
60935 + if (last)
60936 + last->next = match->next;
60937 + else
60938 + gr_conn_table[index] = NULL;
60939 + kfree(match);
60940 + }
60941 +
60942 + return;
60943 +}
60944 +
60945 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
60946 + __u16 sport, __u16 dport)
60947 +{
60948 + struct conn_table_entry *match;
60949 + unsigned int index;
60950 +
60951 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
60952 +
60953 + match = gr_conn_table[index];
60954 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
60955 + match = match->next;
60956 +
60957 + if (match)
60958 + return match->sig;
60959 + else
60960 + return NULL;
60961 +}
60962 +
60963 +#endif
60964 +
60965 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
60966 +{
60967 +#ifdef CONFIG_GRKERNSEC
60968 + struct signal_struct *sig = task->signal;
60969 + struct conn_table_entry *newent;
60970 +
60971 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
60972 + if (newent == NULL)
60973 + return;
60974 + /* no bh lock needed since we are called with bh disabled */
60975 + spin_lock(&gr_conn_table_lock);
60976 + gr_del_task_from_ip_table_nolock(sig);
60977 + sig->gr_saddr = inet->inet_rcv_saddr;
60978 + sig->gr_daddr = inet->inet_daddr;
60979 + sig->gr_sport = inet->inet_sport;
60980 + sig->gr_dport = inet->inet_dport;
60981 + gr_add_to_task_ip_table_nolock(sig, newent);
60982 + spin_unlock(&gr_conn_table_lock);
60983 +#endif
60984 + return;
60985 +}
60986 +
60987 +void gr_del_task_from_ip_table(struct task_struct *task)
60988 +{
60989 +#ifdef CONFIG_GRKERNSEC
60990 + spin_lock_bh(&gr_conn_table_lock);
60991 + gr_del_task_from_ip_table_nolock(task->signal);
60992 + spin_unlock_bh(&gr_conn_table_lock);
60993 +#endif
60994 + return;
60995 +}
60996 +
60997 +void
60998 +gr_attach_curr_ip(const struct sock *sk)
60999 +{
61000 +#ifdef CONFIG_GRKERNSEC
61001 + struct signal_struct *p, *set;
61002 + const struct inet_sock *inet = inet_sk(sk);
61003 +
61004 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61005 + return;
61006 +
61007 + set = current->signal;
61008 +
61009 + spin_lock_bh(&gr_conn_table_lock);
61010 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61011 + inet->inet_dport, inet->inet_sport);
61012 + if (unlikely(p != NULL)) {
61013 + set->curr_ip = p->curr_ip;
61014 + set->used_accept = 1;
61015 + gr_del_task_from_ip_table_nolock(p);
61016 + spin_unlock_bh(&gr_conn_table_lock);
61017 + return;
61018 + }
61019 + spin_unlock_bh(&gr_conn_table_lock);
61020 +
61021 + set->curr_ip = inet->inet_daddr;
61022 + set->used_accept = 1;
61023 +#endif
61024 + return;
61025 +}
61026 +
61027 +int
61028 +gr_handle_sock_all(const int family, const int type, const int protocol)
61029 +{
61030 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61031 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61032 + (family != AF_UNIX)) {
61033 + if (family == AF_INET)
61034 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61035 + else
61036 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61037 + return -EACCES;
61038 + }
61039 +#endif
61040 + return 0;
61041 +}
61042 +
61043 +int
61044 +gr_handle_sock_server(const struct sockaddr *sck)
61045 +{
61046 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61047 + if (grsec_enable_socket_server &&
61048 + in_group_p(grsec_socket_server_gid) &&
61049 + sck && (sck->sa_family != AF_UNIX) &&
61050 + (sck->sa_family != AF_LOCAL)) {
61051 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61052 + return -EACCES;
61053 + }
61054 +#endif
61055 + return 0;
61056 +}
61057 +
61058 +int
61059 +gr_handle_sock_server_other(const struct sock *sck)
61060 +{
61061 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61062 + if (grsec_enable_socket_server &&
61063 + in_group_p(grsec_socket_server_gid) &&
61064 + sck && (sck->sk_family != AF_UNIX) &&
61065 + (sck->sk_family != AF_LOCAL)) {
61066 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61067 + return -EACCES;
61068 + }
61069 +#endif
61070 + return 0;
61071 +}
61072 +
61073 +int
61074 +gr_handle_sock_client(const struct sockaddr *sck)
61075 +{
61076 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61077 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61078 + sck && (sck->sa_family != AF_UNIX) &&
61079 + (sck->sa_family != AF_LOCAL)) {
61080 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61081 + return -EACCES;
61082 + }
61083 +#endif
61084 + return 0;
61085 +}
61086 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61087 new file mode 100644
61088 index 0000000..f55ef0f
61089 --- /dev/null
61090 +++ b/grsecurity/grsec_sysctl.c
61091 @@ -0,0 +1,469 @@
61092 +#include <linux/kernel.h>
61093 +#include <linux/sched.h>
61094 +#include <linux/sysctl.h>
61095 +#include <linux/grsecurity.h>
61096 +#include <linux/grinternal.h>
61097 +
61098 +int
61099 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61100 +{
61101 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61102 + if (dirname == NULL || name == NULL)
61103 + return 0;
61104 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61105 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61106 + return -EACCES;
61107 + }
61108 +#endif
61109 + return 0;
61110 +}
61111 +
61112 +#ifdef CONFIG_GRKERNSEC_ROFS
61113 +static int __maybe_unused one = 1;
61114 +#endif
61115 +
61116 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61117 +struct ctl_table grsecurity_table[] = {
61118 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61119 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61120 +#ifdef CONFIG_GRKERNSEC_IO
61121 + {
61122 + .procname = "disable_priv_io",
61123 + .data = &grsec_disable_privio,
61124 + .maxlen = sizeof(int),
61125 + .mode = 0600,
61126 + .proc_handler = &proc_dointvec,
61127 + },
61128 +#endif
61129 +#endif
61130 +#ifdef CONFIG_GRKERNSEC_LINK
61131 + {
61132 + .procname = "linking_restrictions",
61133 + .data = &grsec_enable_link,
61134 + .maxlen = sizeof(int),
61135 + .mode = 0600,
61136 + .proc_handler = &proc_dointvec,
61137 + },
61138 +#endif
61139 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61140 + {
61141 + .procname = "enforce_symlinksifowner",
61142 + .data = &grsec_enable_symlinkown,
61143 + .maxlen = sizeof(int),
61144 + .mode = 0600,
61145 + .proc_handler = &proc_dointvec,
61146 + },
61147 + {
61148 + .procname = "symlinkown_gid",
61149 + .data = &grsec_symlinkown_gid,
61150 + .maxlen = sizeof(int),
61151 + .mode = 0600,
61152 + .proc_handler = &proc_dointvec,
61153 + },
61154 +#endif
61155 +#ifdef CONFIG_GRKERNSEC_BRUTE
61156 + {
61157 + .procname = "deter_bruteforce",
61158 + .data = &grsec_enable_brute,
61159 + .maxlen = sizeof(int),
61160 + .mode = 0600,
61161 + .proc_handler = &proc_dointvec,
61162 + },
61163 +#endif
61164 +#ifdef CONFIG_GRKERNSEC_FIFO
61165 + {
61166 + .procname = "fifo_restrictions",
61167 + .data = &grsec_enable_fifo,
61168 + .maxlen = sizeof(int),
61169 + .mode = 0600,
61170 + .proc_handler = &proc_dointvec,
61171 + },
61172 +#endif
61173 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61174 + {
61175 + .procname = "ptrace_readexec",
61176 + .data = &grsec_enable_ptrace_readexec,
61177 + .maxlen = sizeof(int),
61178 + .mode = 0600,
61179 + .proc_handler = &proc_dointvec,
61180 + },
61181 +#endif
61182 +#ifdef CONFIG_GRKERNSEC_SETXID
61183 + {
61184 + .procname = "consistent_setxid",
61185 + .data = &grsec_enable_setxid,
61186 + .maxlen = sizeof(int),
61187 + .mode = 0600,
61188 + .proc_handler = &proc_dointvec,
61189 + },
61190 +#endif
61191 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61192 + {
61193 + .procname = "ip_blackhole",
61194 + .data = &grsec_enable_blackhole,
61195 + .maxlen = sizeof(int),
61196 + .mode = 0600,
61197 + .proc_handler = &proc_dointvec,
61198 + },
61199 + {
61200 + .procname = "lastack_retries",
61201 + .data = &grsec_lastack_retries,
61202 + .maxlen = sizeof(int),
61203 + .mode = 0600,
61204 + .proc_handler = &proc_dointvec,
61205 + },
61206 +#endif
61207 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61208 + {
61209 + .procname = "exec_logging",
61210 + .data = &grsec_enable_execlog,
61211 + .maxlen = sizeof(int),
61212 + .mode = 0600,
61213 + .proc_handler = &proc_dointvec,
61214 + },
61215 +#endif
61216 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61217 + {
61218 + .procname = "rwxmap_logging",
61219 + .data = &grsec_enable_log_rwxmaps,
61220 + .maxlen = sizeof(int),
61221 + .mode = 0600,
61222 + .proc_handler = &proc_dointvec,
61223 + },
61224 +#endif
61225 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61226 + {
61227 + .procname = "signal_logging",
61228 + .data = &grsec_enable_signal,
61229 + .maxlen = sizeof(int),
61230 + .mode = 0600,
61231 + .proc_handler = &proc_dointvec,
61232 + },
61233 +#endif
61234 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61235 + {
61236 + .procname = "forkfail_logging",
61237 + .data = &grsec_enable_forkfail,
61238 + .maxlen = sizeof(int),
61239 + .mode = 0600,
61240 + .proc_handler = &proc_dointvec,
61241 + },
61242 +#endif
61243 +#ifdef CONFIG_GRKERNSEC_TIME
61244 + {
61245 + .procname = "timechange_logging",
61246 + .data = &grsec_enable_time,
61247 + .maxlen = sizeof(int),
61248 + .mode = 0600,
61249 + .proc_handler = &proc_dointvec,
61250 + },
61251 +#endif
61252 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61253 + {
61254 + .procname = "chroot_deny_shmat",
61255 + .data = &grsec_enable_chroot_shmat,
61256 + .maxlen = sizeof(int),
61257 + .mode = 0600,
61258 + .proc_handler = &proc_dointvec,
61259 + },
61260 +#endif
61261 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61262 + {
61263 + .procname = "chroot_deny_unix",
61264 + .data = &grsec_enable_chroot_unix,
61265 + .maxlen = sizeof(int),
61266 + .mode = 0600,
61267 + .proc_handler = &proc_dointvec,
61268 + },
61269 +#endif
61270 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61271 + {
61272 + .procname = "chroot_deny_mount",
61273 + .data = &grsec_enable_chroot_mount,
61274 + .maxlen = sizeof(int),
61275 + .mode = 0600,
61276 + .proc_handler = &proc_dointvec,
61277 + },
61278 +#endif
61279 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61280 + {
61281 + .procname = "chroot_deny_fchdir",
61282 + .data = &grsec_enable_chroot_fchdir,
61283 + .maxlen = sizeof(int),
61284 + .mode = 0600,
61285 + .proc_handler = &proc_dointvec,
61286 + },
61287 +#endif
61288 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61289 + {
61290 + .procname = "chroot_deny_chroot",
61291 + .data = &grsec_enable_chroot_double,
61292 + .maxlen = sizeof(int),
61293 + .mode = 0600,
61294 + .proc_handler = &proc_dointvec,
61295 + },
61296 +#endif
61297 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61298 + {
61299 + .procname = "chroot_deny_pivot",
61300 + .data = &grsec_enable_chroot_pivot,
61301 + .maxlen = sizeof(int),
61302 + .mode = 0600,
61303 + .proc_handler = &proc_dointvec,
61304 + },
61305 +#endif
61306 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61307 + {
61308 + .procname = "chroot_enforce_chdir",
61309 + .data = &grsec_enable_chroot_chdir,
61310 + .maxlen = sizeof(int),
61311 + .mode = 0600,
61312 + .proc_handler = &proc_dointvec,
61313 + },
61314 +#endif
61315 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61316 + {
61317 + .procname = "chroot_deny_chmod",
61318 + .data = &grsec_enable_chroot_chmod,
61319 + .maxlen = sizeof(int),
61320 + .mode = 0600,
61321 + .proc_handler = &proc_dointvec,
61322 + },
61323 +#endif
61324 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61325 + {
61326 + .procname = "chroot_deny_mknod",
61327 + .data = &grsec_enable_chroot_mknod,
61328 + .maxlen = sizeof(int),
61329 + .mode = 0600,
61330 + .proc_handler = &proc_dointvec,
61331 + },
61332 +#endif
61333 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61334 + {
61335 + .procname = "chroot_restrict_nice",
61336 + .data = &grsec_enable_chroot_nice,
61337 + .maxlen = sizeof(int),
61338 + .mode = 0600,
61339 + .proc_handler = &proc_dointvec,
61340 + },
61341 +#endif
61342 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61343 + {
61344 + .procname = "chroot_execlog",
61345 + .data = &grsec_enable_chroot_execlog,
61346 + .maxlen = sizeof(int),
61347 + .mode = 0600,
61348 + .proc_handler = &proc_dointvec,
61349 + },
61350 +#endif
61351 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61352 + {
61353 + .procname = "chroot_caps",
61354 + .data = &grsec_enable_chroot_caps,
61355 + .maxlen = sizeof(int),
61356 + .mode = 0600,
61357 + .proc_handler = &proc_dointvec,
61358 + },
61359 +#endif
61360 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61361 + {
61362 + .procname = "chroot_deny_sysctl",
61363 + .data = &grsec_enable_chroot_sysctl,
61364 + .maxlen = sizeof(int),
61365 + .mode = 0600,
61366 + .proc_handler = &proc_dointvec,
61367 + },
61368 +#endif
61369 +#ifdef CONFIG_GRKERNSEC_TPE
61370 + {
61371 + .procname = "tpe",
61372 + .data = &grsec_enable_tpe,
61373 + .maxlen = sizeof(int),
61374 + .mode = 0600,
61375 + .proc_handler = &proc_dointvec,
61376 + },
61377 + {
61378 + .procname = "tpe_gid",
61379 + .data = &grsec_tpe_gid,
61380 + .maxlen = sizeof(int),
61381 + .mode = 0600,
61382 + .proc_handler = &proc_dointvec,
61383 + },
61384 +#endif
61385 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61386 + {
61387 + .procname = "tpe_invert",
61388 + .data = &grsec_enable_tpe_invert,
61389 + .maxlen = sizeof(int),
61390 + .mode = 0600,
61391 + .proc_handler = &proc_dointvec,
61392 + },
61393 +#endif
61394 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
61395 + {
61396 + .procname = "tpe_restrict_all",
61397 + .data = &grsec_enable_tpe_all,
61398 + .maxlen = sizeof(int),
61399 + .mode = 0600,
61400 + .proc_handler = &proc_dointvec,
61401 + },
61402 +#endif
61403 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61404 + {
61405 + .procname = "socket_all",
61406 + .data = &grsec_enable_socket_all,
61407 + .maxlen = sizeof(int),
61408 + .mode = 0600,
61409 + .proc_handler = &proc_dointvec,
61410 + },
61411 + {
61412 + .procname = "socket_all_gid",
61413 + .data = &grsec_socket_all_gid,
61414 + .maxlen = sizeof(int),
61415 + .mode = 0600,
61416 + .proc_handler = &proc_dointvec,
61417 + },
61418 +#endif
61419 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61420 + {
61421 + .procname = "socket_client",
61422 + .data = &grsec_enable_socket_client,
61423 + .maxlen = sizeof(int),
61424 + .mode = 0600,
61425 + .proc_handler = &proc_dointvec,
61426 + },
61427 + {
61428 + .procname = "socket_client_gid",
61429 + .data = &grsec_socket_client_gid,
61430 + .maxlen = sizeof(int),
61431 + .mode = 0600,
61432 + .proc_handler = &proc_dointvec,
61433 + },
61434 +#endif
61435 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61436 + {
61437 + .procname = "socket_server",
61438 + .data = &grsec_enable_socket_server,
61439 + .maxlen = sizeof(int),
61440 + .mode = 0600,
61441 + .proc_handler = &proc_dointvec,
61442 + },
61443 + {
61444 + .procname = "socket_server_gid",
61445 + .data = &grsec_socket_server_gid,
61446 + .maxlen = sizeof(int),
61447 + .mode = 0600,
61448 + .proc_handler = &proc_dointvec,
61449 + },
61450 +#endif
61451 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61452 + {
61453 + .procname = "audit_group",
61454 + .data = &grsec_enable_group,
61455 + .maxlen = sizeof(int),
61456 + .mode = 0600,
61457 + .proc_handler = &proc_dointvec,
61458 + },
61459 + {
61460 + .procname = "audit_gid",
61461 + .data = &grsec_audit_gid,
61462 + .maxlen = sizeof(int),
61463 + .mode = 0600,
61464 + .proc_handler = &proc_dointvec,
61465 + },
61466 +#endif
61467 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61468 + {
61469 + .procname = "audit_chdir",
61470 + .data = &grsec_enable_chdir,
61471 + .maxlen = sizeof(int),
61472 + .mode = 0600,
61473 + .proc_handler = &proc_dointvec,
61474 + },
61475 +#endif
61476 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61477 + {
61478 + .procname = "audit_mount",
61479 + .data = &grsec_enable_mount,
61480 + .maxlen = sizeof(int),
61481 + .mode = 0600,
61482 + .proc_handler = &proc_dointvec,
61483 + },
61484 +#endif
61485 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61486 + {
61487 + .procname = "audit_textrel",
61488 + .data = &grsec_enable_audit_textrel,
61489 + .maxlen = sizeof(int),
61490 + .mode = 0600,
61491 + .proc_handler = &proc_dointvec,
61492 + },
61493 +#endif
61494 +#ifdef CONFIG_GRKERNSEC_DMESG
61495 + {
61496 + .procname = "dmesg",
61497 + .data = &grsec_enable_dmesg,
61498 + .maxlen = sizeof(int),
61499 + .mode = 0600,
61500 + .proc_handler = &proc_dointvec,
61501 + },
61502 +#endif
61503 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61504 + {
61505 + .procname = "chroot_findtask",
61506 + .data = &grsec_enable_chroot_findtask,
61507 + .maxlen = sizeof(int),
61508 + .mode = 0600,
61509 + .proc_handler = &proc_dointvec,
61510 + },
61511 +#endif
61512 +#ifdef CONFIG_GRKERNSEC_RESLOG
61513 + {
61514 + .procname = "resource_logging",
61515 + .data = &grsec_resource_logging,
61516 + .maxlen = sizeof(int),
61517 + .mode = 0600,
61518 + .proc_handler = &proc_dointvec,
61519 + },
61520 +#endif
61521 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61522 + {
61523 + .procname = "audit_ptrace",
61524 + .data = &grsec_enable_audit_ptrace,
61525 + .maxlen = sizeof(int),
61526 + .mode = 0600,
61527 + .proc_handler = &proc_dointvec,
61528 + },
61529 +#endif
61530 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61531 + {
61532 + .procname = "harden_ptrace",
61533 + .data = &grsec_enable_harden_ptrace,
61534 + .maxlen = sizeof(int),
61535 + .mode = 0600,
61536 + .proc_handler = &proc_dointvec,
61537 + },
61538 +#endif
61539 + {
61540 + .procname = "grsec_lock",
61541 + .data = &grsec_lock,
61542 + .maxlen = sizeof(int),
61543 + .mode = 0600,
61544 + .proc_handler = &proc_dointvec,
61545 + },
61546 +#endif
61547 +#ifdef CONFIG_GRKERNSEC_ROFS
61548 + {
61549 + .procname = "romount_protect",
61550 + .data = &grsec_enable_rofs,
61551 + .maxlen = sizeof(int),
61552 + .mode = 0600,
61553 + .proc_handler = &proc_dointvec_minmax,
61554 + .extra1 = &one,
61555 + .extra2 = &one,
61556 + },
61557 +#endif
61558 + { }
61559 +};
61560 +#endif
61561 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
61562 new file mode 100644
61563 index 0000000..0dc13c3
61564 --- /dev/null
61565 +++ b/grsecurity/grsec_time.c
61566 @@ -0,0 +1,16 @@
61567 +#include <linux/kernel.h>
61568 +#include <linux/sched.h>
61569 +#include <linux/grinternal.h>
61570 +#include <linux/module.h>
61571 +
61572 +void
61573 +gr_log_timechange(void)
61574 +{
61575 +#ifdef CONFIG_GRKERNSEC_TIME
61576 + if (grsec_enable_time)
61577 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
61578 +#endif
61579 + return;
61580 +}
61581 +
61582 +EXPORT_SYMBOL(gr_log_timechange);
61583 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
61584 new file mode 100644
61585 index 0000000..07e0dc0
61586 --- /dev/null
61587 +++ b/grsecurity/grsec_tpe.c
61588 @@ -0,0 +1,73 @@
61589 +#include <linux/kernel.h>
61590 +#include <linux/sched.h>
61591 +#include <linux/file.h>
61592 +#include <linux/fs.h>
61593 +#include <linux/grinternal.h>
61594 +
61595 +extern int gr_acl_tpe_check(void);
61596 +
61597 +int
61598 +gr_tpe_allow(const struct file *file)
61599 +{
61600 +#ifdef CONFIG_GRKERNSEC
61601 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
61602 + const struct cred *cred = current_cred();
61603 + char *msg = NULL;
61604 + char *msg2 = NULL;
61605 +
61606 + // never restrict root
61607 + if (!cred->uid)
61608 + return 1;
61609 +
61610 + if (grsec_enable_tpe) {
61611 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61612 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
61613 + msg = "not being in trusted group";
61614 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
61615 + msg = "being in untrusted group";
61616 +#else
61617 + if (in_group_p(grsec_tpe_gid))
61618 + msg = "being in untrusted group";
61619 +#endif
61620 + }
61621 + if (!msg && gr_acl_tpe_check())
61622 + msg = "being in untrusted role";
61623 +
61624 + // not in any affected group/role
61625 + if (!msg)
61626 + goto next_check;
61627 +
61628 + if (inode->i_uid)
61629 + msg2 = "file in non-root-owned directory";
61630 + else if (inode->i_mode & S_IWOTH)
61631 + msg2 = "file in world-writable directory";
61632 + else if (inode->i_mode & S_IWGRP)
61633 + msg2 = "file in group-writable directory";
61634 +
61635 + if (msg && msg2) {
61636 + char fullmsg[70] = {0};
61637 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
61638 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
61639 + return 0;
61640 + }
61641 + msg = NULL;
61642 +next_check:
61643 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
61644 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
61645 + return 1;
61646 +
61647 + if (inode->i_uid && (inode->i_uid != cred->uid))
61648 + msg = "directory not owned by user";
61649 + else if (inode->i_mode & S_IWOTH)
61650 + msg = "file in world-writable directory";
61651 + else if (inode->i_mode & S_IWGRP)
61652 + msg = "file in group-writable directory";
61653 +
61654 + if (msg) {
61655 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
61656 + return 0;
61657 + }
61658 +#endif
61659 +#endif
61660 + return 1;
61661 +}
61662 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
61663 new file mode 100644
61664 index 0000000..9f7b1ac
61665 --- /dev/null
61666 +++ b/grsecurity/grsum.c
61667 @@ -0,0 +1,61 @@
61668 +#include <linux/err.h>
61669 +#include <linux/kernel.h>
61670 +#include <linux/sched.h>
61671 +#include <linux/mm.h>
61672 +#include <linux/scatterlist.h>
61673 +#include <linux/crypto.h>
61674 +#include <linux/gracl.h>
61675 +
61676 +
61677 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
61678 +#error "crypto and sha256 must be built into the kernel"
61679 +#endif
61680 +
61681 +int
61682 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
61683 +{
61684 + char *p;
61685 + struct crypto_hash *tfm;
61686 + struct hash_desc desc;
61687 + struct scatterlist sg;
61688 + unsigned char temp_sum[GR_SHA_LEN];
61689 + volatile int retval = 0;
61690 + volatile int dummy = 0;
61691 + unsigned int i;
61692 +
61693 + sg_init_table(&sg, 1);
61694 +
61695 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
61696 + if (IS_ERR(tfm)) {
61697 + /* should never happen, since sha256 should be built in */
61698 + return 1;
61699 + }
61700 +
61701 + desc.tfm = tfm;
61702 + desc.flags = 0;
61703 +
61704 + crypto_hash_init(&desc);
61705 +
61706 + p = salt;
61707 + sg_set_buf(&sg, p, GR_SALT_LEN);
61708 + crypto_hash_update(&desc, &sg, sg.length);
61709 +
61710 + p = entry->pw;
61711 + sg_set_buf(&sg, p, strlen(p));
61712 +
61713 + crypto_hash_update(&desc, &sg, sg.length);
61714 +
61715 + crypto_hash_final(&desc, temp_sum);
61716 +
61717 + memset(entry->pw, 0, GR_PW_LEN);
61718 +
61719 + for (i = 0; i < GR_SHA_LEN; i++)
61720 + if (sum[i] != temp_sum[i])
61721 + retval = 1;
61722 + else
61723 + dummy = 1; // waste a cycle
61724 +
61725 + crypto_free_hash(tfm);
61726 +
61727 + return retval;
61728 +}
61729 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
61730 index 77ff547..181834f 100644
61731 --- a/include/asm-generic/4level-fixup.h
61732 +++ b/include/asm-generic/4level-fixup.h
61733 @@ -13,8 +13,10 @@
61734 #define pmd_alloc(mm, pud, address) \
61735 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
61736 NULL: pmd_offset(pud, address))
61737 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
61738
61739 #define pud_alloc(mm, pgd, address) (pgd)
61740 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
61741 #define pud_offset(pgd, start) (pgd)
61742 #define pud_none(pud) 0
61743 #define pud_bad(pud) 0
61744 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
61745 index b7babf0..04ad282 100644
61746 --- a/include/asm-generic/atomic-long.h
61747 +++ b/include/asm-generic/atomic-long.h
61748 @@ -22,6 +22,12 @@
61749
61750 typedef atomic64_t atomic_long_t;
61751
61752 +#ifdef CONFIG_PAX_REFCOUNT
61753 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
61754 +#else
61755 +typedef atomic64_t atomic_long_unchecked_t;
61756 +#endif
61757 +
61758 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
61759
61760 static inline long atomic_long_read(atomic_long_t *l)
61761 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61762 return (long)atomic64_read(v);
61763 }
61764
61765 +#ifdef CONFIG_PAX_REFCOUNT
61766 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61767 +{
61768 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61769 +
61770 + return (long)atomic64_read_unchecked(v);
61771 +}
61772 +#endif
61773 +
61774 static inline void atomic_long_set(atomic_long_t *l, long i)
61775 {
61776 atomic64_t *v = (atomic64_t *)l;
61777 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61778 atomic64_set(v, i);
61779 }
61780
61781 +#ifdef CONFIG_PAX_REFCOUNT
61782 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61783 +{
61784 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61785 +
61786 + atomic64_set_unchecked(v, i);
61787 +}
61788 +#endif
61789 +
61790 static inline void atomic_long_inc(atomic_long_t *l)
61791 {
61792 atomic64_t *v = (atomic64_t *)l;
61793 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61794 atomic64_inc(v);
61795 }
61796
61797 +#ifdef CONFIG_PAX_REFCOUNT
61798 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61799 +{
61800 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61801 +
61802 + atomic64_inc_unchecked(v);
61803 +}
61804 +#endif
61805 +
61806 static inline void atomic_long_dec(atomic_long_t *l)
61807 {
61808 atomic64_t *v = (atomic64_t *)l;
61809 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61810 atomic64_dec(v);
61811 }
61812
61813 +#ifdef CONFIG_PAX_REFCOUNT
61814 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61815 +{
61816 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61817 +
61818 + atomic64_dec_unchecked(v);
61819 +}
61820 +#endif
61821 +
61822 static inline void atomic_long_add(long i, atomic_long_t *l)
61823 {
61824 atomic64_t *v = (atomic64_t *)l;
61825 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61826 atomic64_add(i, v);
61827 }
61828
61829 +#ifdef CONFIG_PAX_REFCOUNT
61830 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61831 +{
61832 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61833 +
61834 + atomic64_add_unchecked(i, v);
61835 +}
61836 +#endif
61837 +
61838 static inline void atomic_long_sub(long i, atomic_long_t *l)
61839 {
61840 atomic64_t *v = (atomic64_t *)l;
61841 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61842 atomic64_sub(i, v);
61843 }
61844
61845 +#ifdef CONFIG_PAX_REFCOUNT
61846 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61847 +{
61848 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61849 +
61850 + atomic64_sub_unchecked(i, v);
61851 +}
61852 +#endif
61853 +
61854 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61855 {
61856 atomic64_t *v = (atomic64_t *)l;
61857 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
61858 return (long)atomic64_add_return(i, v);
61859 }
61860
61861 +#ifdef CONFIG_PAX_REFCOUNT
61862 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
61863 +{
61864 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61865 +
61866 + return (long)atomic64_add_return_unchecked(i, v);
61867 +}
61868 +#endif
61869 +
61870 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
61871 {
61872 atomic64_t *v = (atomic64_t *)l;
61873 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61874 return (long)atomic64_inc_return(v);
61875 }
61876
61877 +#ifdef CONFIG_PAX_REFCOUNT
61878 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61879 +{
61880 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61881 +
61882 + return (long)atomic64_inc_return_unchecked(v);
61883 +}
61884 +#endif
61885 +
61886 static inline long atomic_long_dec_return(atomic_long_t *l)
61887 {
61888 atomic64_t *v = (atomic64_t *)l;
61889 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61890
61891 typedef atomic_t atomic_long_t;
61892
61893 +#ifdef CONFIG_PAX_REFCOUNT
61894 +typedef atomic_unchecked_t atomic_long_unchecked_t;
61895 +#else
61896 +typedef atomic_t atomic_long_unchecked_t;
61897 +#endif
61898 +
61899 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61900 static inline long atomic_long_read(atomic_long_t *l)
61901 {
61902 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61903 return (long)atomic_read(v);
61904 }
61905
61906 +#ifdef CONFIG_PAX_REFCOUNT
61907 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61908 +{
61909 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61910 +
61911 + return (long)atomic_read_unchecked(v);
61912 +}
61913 +#endif
61914 +
61915 static inline void atomic_long_set(atomic_long_t *l, long i)
61916 {
61917 atomic_t *v = (atomic_t *)l;
61918 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61919 atomic_set(v, i);
61920 }
61921
61922 +#ifdef CONFIG_PAX_REFCOUNT
61923 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61924 +{
61925 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61926 +
61927 + atomic_set_unchecked(v, i);
61928 +}
61929 +#endif
61930 +
61931 static inline void atomic_long_inc(atomic_long_t *l)
61932 {
61933 atomic_t *v = (atomic_t *)l;
61934 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61935 atomic_inc(v);
61936 }
61937
61938 +#ifdef CONFIG_PAX_REFCOUNT
61939 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61940 +{
61941 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61942 +
61943 + atomic_inc_unchecked(v);
61944 +}
61945 +#endif
61946 +
61947 static inline void atomic_long_dec(atomic_long_t *l)
61948 {
61949 atomic_t *v = (atomic_t *)l;
61950 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61951 atomic_dec(v);
61952 }
61953
61954 +#ifdef CONFIG_PAX_REFCOUNT
61955 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61956 +{
61957 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61958 +
61959 + atomic_dec_unchecked(v);
61960 +}
61961 +#endif
61962 +
61963 static inline void atomic_long_add(long i, atomic_long_t *l)
61964 {
61965 atomic_t *v = (atomic_t *)l;
61966 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61967 atomic_add(i, v);
61968 }
61969
61970 +#ifdef CONFIG_PAX_REFCOUNT
61971 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61972 +{
61973 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61974 +
61975 + atomic_add_unchecked(i, v);
61976 +}
61977 +#endif
61978 +
61979 static inline void atomic_long_sub(long i, atomic_long_t *l)
61980 {
61981 atomic_t *v = (atomic_t *)l;
61982 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61983 atomic_sub(i, v);
61984 }
61985
61986 +#ifdef CONFIG_PAX_REFCOUNT
61987 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61988 +{
61989 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61990 +
61991 + atomic_sub_unchecked(i, v);
61992 +}
61993 +#endif
61994 +
61995 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61996 {
61997 atomic_t *v = (atomic_t *)l;
61998 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
61999 return (long)atomic_add_return(i, v);
62000 }
62001
62002 +#ifdef CONFIG_PAX_REFCOUNT
62003 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62004 +{
62005 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62006 +
62007 + return (long)atomic_add_return_unchecked(i, v);
62008 +}
62009 +
62010 +#endif
62011 +
62012 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62013 {
62014 atomic_t *v = (atomic_t *)l;
62015 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62016 return (long)atomic_inc_return(v);
62017 }
62018
62019 +#ifdef CONFIG_PAX_REFCOUNT
62020 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62021 +{
62022 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62023 +
62024 + return (long)atomic_inc_return_unchecked(v);
62025 +}
62026 +#endif
62027 +
62028 static inline long atomic_long_dec_return(atomic_long_t *l)
62029 {
62030 atomic_t *v = (atomic_t *)l;
62031 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62032
62033 #endif /* BITS_PER_LONG == 64 */
62034
62035 +#ifdef CONFIG_PAX_REFCOUNT
62036 +static inline void pax_refcount_needs_these_functions(void)
62037 +{
62038 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
62039 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62040 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62041 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62042 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62043 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62044 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62045 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62046 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62047 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62048 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62049 +#ifdef CONFIG_X86
62050 + atomic_clear_mask_unchecked(0, NULL);
62051 + atomic_set_mask_unchecked(0, NULL);
62052 +#endif
62053 +
62054 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62055 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62056 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62057 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62058 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62059 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62060 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62061 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62062 +}
62063 +#else
62064 +#define atomic_read_unchecked(v) atomic_read(v)
62065 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62066 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62067 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62068 +#define atomic_inc_unchecked(v) atomic_inc(v)
62069 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62070 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62071 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62072 +#define atomic_dec_unchecked(v) atomic_dec(v)
62073 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62074 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62075 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62076 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62077 +
62078 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
62079 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62080 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62081 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62082 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62083 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62084 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62085 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62086 +#endif
62087 +
62088 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62089 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62090 index 1ced641..c896ee8 100644
62091 --- a/include/asm-generic/atomic.h
62092 +++ b/include/asm-generic/atomic.h
62093 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62094 * Atomically clears the bits set in @mask from @v
62095 */
62096 #ifndef atomic_clear_mask
62097 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62098 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62099 {
62100 unsigned long flags;
62101
62102 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62103 index b18ce4f..2ee2843 100644
62104 --- a/include/asm-generic/atomic64.h
62105 +++ b/include/asm-generic/atomic64.h
62106 @@ -16,6 +16,8 @@ typedef struct {
62107 long long counter;
62108 } atomic64_t;
62109
62110 +typedef atomic64_t atomic64_unchecked_t;
62111 +
62112 #define ATOMIC64_INIT(i) { (i) }
62113
62114 extern long long atomic64_read(const atomic64_t *v);
62115 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62116 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62117 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62118
62119 +#define atomic64_read_unchecked(v) atomic64_read(v)
62120 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62121 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62122 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62123 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62124 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
62125 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62126 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
62127 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62128 +
62129 #endif /* _ASM_GENERIC_ATOMIC64_H */
62130 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62131 index 1bfcfe5..e04c5c9 100644
62132 --- a/include/asm-generic/cache.h
62133 +++ b/include/asm-generic/cache.h
62134 @@ -6,7 +6,7 @@
62135 * cache lines need to provide their own cache.h.
62136 */
62137
62138 -#define L1_CACHE_SHIFT 5
62139 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62140 +#define L1_CACHE_SHIFT 5UL
62141 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62142
62143 #endif /* __ASM_GENERIC_CACHE_H */
62144 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62145 index 0d68a1e..b74a761 100644
62146 --- a/include/asm-generic/emergency-restart.h
62147 +++ b/include/asm-generic/emergency-restart.h
62148 @@ -1,7 +1,7 @@
62149 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62150 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62151
62152 -static inline void machine_emergency_restart(void)
62153 +static inline __noreturn void machine_emergency_restart(void)
62154 {
62155 machine_restart(NULL);
62156 }
62157 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62158 index 90f99c7..00ce236 100644
62159 --- a/include/asm-generic/kmap_types.h
62160 +++ b/include/asm-generic/kmap_types.h
62161 @@ -2,9 +2,9 @@
62162 #define _ASM_GENERIC_KMAP_TYPES_H
62163
62164 #ifdef __WITH_KM_FENCE
62165 -# define KM_TYPE_NR 41
62166 +# define KM_TYPE_NR 42
62167 #else
62168 -# define KM_TYPE_NR 20
62169 +# define KM_TYPE_NR 21
62170 #endif
62171
62172 #endif
62173 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62174 index 9ceb03b..62b0b8f 100644
62175 --- a/include/asm-generic/local.h
62176 +++ b/include/asm-generic/local.h
62177 @@ -23,24 +23,37 @@ typedef struct
62178 atomic_long_t a;
62179 } local_t;
62180
62181 +typedef struct {
62182 + atomic_long_unchecked_t a;
62183 +} local_unchecked_t;
62184 +
62185 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62186
62187 #define local_read(l) atomic_long_read(&(l)->a)
62188 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62189 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62190 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62191 #define local_inc(l) atomic_long_inc(&(l)->a)
62192 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62193 #define local_dec(l) atomic_long_dec(&(l)->a)
62194 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62195 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62196 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62197 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62198 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62199
62200 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62201 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62202 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62203 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62204 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62205 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62206 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62207 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62208 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62209
62210 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62211 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62212 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62213 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62214 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62215 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62216 index 725612b..9cc513a 100644
62217 --- a/include/asm-generic/pgtable-nopmd.h
62218 +++ b/include/asm-generic/pgtable-nopmd.h
62219 @@ -1,14 +1,19 @@
62220 #ifndef _PGTABLE_NOPMD_H
62221 #define _PGTABLE_NOPMD_H
62222
62223 -#ifndef __ASSEMBLY__
62224 -
62225 #include <asm-generic/pgtable-nopud.h>
62226
62227 -struct mm_struct;
62228 -
62229 #define __PAGETABLE_PMD_FOLDED
62230
62231 +#define PMD_SHIFT PUD_SHIFT
62232 +#define PTRS_PER_PMD 1
62233 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62234 +#define PMD_MASK (~(PMD_SIZE-1))
62235 +
62236 +#ifndef __ASSEMBLY__
62237 +
62238 +struct mm_struct;
62239 +
62240 /*
62241 * Having the pmd type consist of a pud gets the size right, and allows
62242 * us to conceptually access the pud entry that this pmd is folded into
62243 @@ -16,11 +21,6 @@ struct mm_struct;
62244 */
62245 typedef struct { pud_t pud; } pmd_t;
62246
62247 -#define PMD_SHIFT PUD_SHIFT
62248 -#define PTRS_PER_PMD 1
62249 -#define PMD_SIZE (1UL << PMD_SHIFT)
62250 -#define PMD_MASK (~(PMD_SIZE-1))
62251 -
62252 /*
62253 * The "pud_xxx()" functions here are trivial for a folded two-level
62254 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62255 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62256 index 810431d..0ec4804f 100644
62257 --- a/include/asm-generic/pgtable-nopud.h
62258 +++ b/include/asm-generic/pgtable-nopud.h
62259 @@ -1,10 +1,15 @@
62260 #ifndef _PGTABLE_NOPUD_H
62261 #define _PGTABLE_NOPUD_H
62262
62263 -#ifndef __ASSEMBLY__
62264 -
62265 #define __PAGETABLE_PUD_FOLDED
62266
62267 +#define PUD_SHIFT PGDIR_SHIFT
62268 +#define PTRS_PER_PUD 1
62269 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62270 +#define PUD_MASK (~(PUD_SIZE-1))
62271 +
62272 +#ifndef __ASSEMBLY__
62273 +
62274 /*
62275 * Having the pud type consist of a pgd gets the size right, and allows
62276 * us to conceptually access the pgd entry that this pud is folded into
62277 @@ -12,11 +17,6 @@
62278 */
62279 typedef struct { pgd_t pgd; } pud_t;
62280
62281 -#define PUD_SHIFT PGDIR_SHIFT
62282 -#define PTRS_PER_PUD 1
62283 -#define PUD_SIZE (1UL << PUD_SHIFT)
62284 -#define PUD_MASK (~(PUD_SIZE-1))
62285 -
62286 /*
62287 * The "pgd_xxx()" functions here are trivial for a folded two-level
62288 * setup: the pud is never bad, and a pud always exists (as it's folded
62289 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
62290 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
62291
62292 #define pgd_populate(mm, pgd, pud) do { } while (0)
62293 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
62294 /*
62295 * (puds are folded into pgds so this doesn't get actually called,
62296 * but the define is needed for a generic inline function.)
62297 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
62298 index b36ce40..019426d 100644
62299 --- a/include/asm-generic/pgtable.h
62300 +++ b/include/asm-generic/pgtable.h
62301 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
62302 #endif
62303 }
62304
62305 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
62306 +static inline unsigned long pax_open_kernel(void) { return 0; }
62307 +#endif
62308 +
62309 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
62310 +static inline unsigned long pax_close_kernel(void) { return 0; }
62311 +#endif
62312 +
62313 #endif /* CONFIG_MMU */
62314
62315 #endif /* !__ASSEMBLY__ */
62316 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62317 index d1ea7ce..b1ebf2a 100644
62318 --- a/include/asm-generic/vmlinux.lds.h
62319 +++ b/include/asm-generic/vmlinux.lds.h
62320 @@ -218,6 +218,7 @@
62321 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
62322 VMLINUX_SYMBOL(__start_rodata) = .; \
62323 *(.rodata) *(.rodata.*) \
62324 + *(.data..read_only) \
62325 *(__vermagic) /* Kernel version magic */ \
62326 . = ALIGN(8); \
62327 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
62328 @@ -725,17 +726,18 @@
62329 * section in the linker script will go there too. @phdr should have
62330 * a leading colon.
62331 *
62332 - * Note that this macros defines __per_cpu_load as an absolute symbol.
62333 + * Note that this macros defines per_cpu_load as an absolute symbol.
62334 * If there is no need to put the percpu section at a predetermined
62335 * address, use PERCPU_SECTION.
62336 */
62337 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
62338 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
62339 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
62340 + per_cpu_load = .; \
62341 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
62342 - LOAD_OFFSET) { \
62343 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
62344 PERCPU_INPUT(cacheline) \
62345 } phdr \
62346 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
62347 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
62348
62349 /**
62350 * PERCPU_SECTION - define output section for percpu area, simple version
62351 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
62352 index 418d270..bfd2794 100644
62353 --- a/include/crypto/algapi.h
62354 +++ b/include/crypto/algapi.h
62355 @@ -34,7 +34,7 @@ struct crypto_type {
62356 unsigned int maskclear;
62357 unsigned int maskset;
62358 unsigned int tfmsize;
62359 -};
62360 +} __do_const;
62361
62362 struct crypto_instance {
62363 struct crypto_alg alg;
62364 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
62365 index 3fd8280..2b3c415 100644
62366 --- a/include/drm/drmP.h
62367 +++ b/include/drm/drmP.h
62368 @@ -72,6 +72,7 @@
62369 #include <linux/workqueue.h>
62370 #include <linux/poll.h>
62371 #include <asm/pgalloc.h>
62372 +#include <asm/local.h>
62373 #include <drm/drm.h>
62374 #include <drm/drm_sarea.h>
62375
62376 @@ -1068,7 +1069,7 @@ struct drm_device {
62377
62378 /** \name Usage Counters */
62379 /*@{ */
62380 - int open_count; /**< Outstanding files open */
62381 + local_t open_count; /**< Outstanding files open */
62382 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
62383 atomic_t vma_count; /**< Outstanding vma areas open */
62384 int buf_use; /**< Buffers in use -- cannot alloc */
62385 @@ -1079,7 +1080,7 @@ struct drm_device {
62386 /*@{ */
62387 unsigned long counters;
62388 enum drm_stat_type types[15];
62389 - atomic_t counts[15];
62390 + atomic_unchecked_t counts[15];
62391 /*@} */
62392
62393 struct list_head filelist;
62394 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
62395 index e01cc80..6fb6f25 100644
62396 --- a/include/drm/drm_crtc_helper.h
62397 +++ b/include/drm/drm_crtc_helper.h
62398 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
62399 struct drm_connector *connector);
62400 /* disable encoder when not in use - more explicit than dpms off */
62401 void (*disable)(struct drm_encoder *encoder);
62402 -};
62403 +} __no_const;
62404
62405 /**
62406 * drm_connector_helper_funcs - helper operations for connectors
62407 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
62408 index d6d1da4..fdd1ac5 100644
62409 --- a/include/drm/ttm/ttm_memory.h
62410 +++ b/include/drm/ttm/ttm_memory.h
62411 @@ -48,7 +48,7 @@
62412
62413 struct ttm_mem_shrink {
62414 int (*do_shrink) (struct ttm_mem_shrink *);
62415 -};
62416 +} __no_const;
62417
62418 /**
62419 * struct ttm_mem_global - Global memory accounting structure.
62420 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
62421 index 22ef21c..75904ba 100644
62422 --- a/include/linux/atmdev.h
62423 +++ b/include/linux/atmdev.h
62424 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
62425 #endif
62426
62427 struct k_atm_aal_stats {
62428 -#define __HANDLE_ITEM(i) atomic_t i
62429 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
62430 __AAL_STAT_ITEMS
62431 #undef __HANDLE_ITEM
62432 };
62433 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
62434 index de0628e..38f42eb 100644
62435 --- a/include/linux/binfmts.h
62436 +++ b/include/linux/binfmts.h
62437 @@ -75,6 +75,7 @@ struct linux_binfmt {
62438 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
62439 int (*load_shlib)(struct file *);
62440 int (*core_dump)(struct coredump_params *cprm);
62441 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
62442 unsigned long min_coredump; /* minimal dump size */
62443 };
62444
62445 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
62446 index 1756001..ab117ec 100644
62447 --- a/include/linux/blkdev.h
62448 +++ b/include/linux/blkdev.h
62449 @@ -1478,7 +1478,7 @@ struct block_device_operations {
62450 /* this callback is with swap_lock and sometimes page table lock held */
62451 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
62452 struct module *owner;
62453 -};
62454 +} __do_const;
62455
62456 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
62457 unsigned long);
62458 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
62459 index 7c2e030..b72475d 100644
62460 --- a/include/linux/blktrace_api.h
62461 +++ b/include/linux/blktrace_api.h
62462 @@ -23,7 +23,7 @@ struct blk_trace {
62463 struct dentry *dir;
62464 struct dentry *dropped_file;
62465 struct dentry *msg_file;
62466 - atomic_t dropped;
62467 + atomic_unchecked_t dropped;
62468 };
62469
62470 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
62471 diff --git a/include/linux/cache.h b/include/linux/cache.h
62472 index 4c57065..4307975 100644
62473 --- a/include/linux/cache.h
62474 +++ b/include/linux/cache.h
62475 @@ -16,6 +16,10 @@
62476 #define __read_mostly
62477 #endif
62478
62479 +#ifndef __read_only
62480 +#define __read_only __read_mostly
62481 +#endif
62482 +
62483 #ifndef ____cacheline_aligned
62484 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
62485 #endif
62486 diff --git a/include/linux/capability.h b/include/linux/capability.h
62487 index 98503b7..cc36d18 100644
62488 --- a/include/linux/capability.h
62489 +++ b/include/linux/capability.h
62490 @@ -211,8 +211,13 @@ extern bool capable(int cap);
62491 extern bool ns_capable(struct user_namespace *ns, int cap);
62492 extern bool nsown_capable(int cap);
62493 extern bool inode_capable(const struct inode *inode, int cap);
62494 +extern bool capable_nolog(int cap);
62495 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
62496 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
62497
62498 /* audit system wants to get cap info from files as well */
62499 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
62500
62501 +extern int is_privileged_binary(const struct dentry *dentry);
62502 +
62503 #endif /* !_LINUX_CAPABILITY_H */
62504 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
62505 index 8609d57..86e4d79 100644
62506 --- a/include/linux/cdrom.h
62507 +++ b/include/linux/cdrom.h
62508 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
62509
62510 /* driver specifications */
62511 const int capability; /* capability flags */
62512 - int n_minors; /* number of active minor devices */
62513 /* handle uniform packets for scsi type devices (scsi,atapi) */
62514 int (*generic_packet) (struct cdrom_device_info *,
62515 struct packet_command *);
62516 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
62517 index 42e55de..1cd0e66 100644
62518 --- a/include/linux/cleancache.h
62519 +++ b/include/linux/cleancache.h
62520 @@ -31,7 +31,7 @@ struct cleancache_ops {
62521 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
62522 void (*invalidate_inode)(int, struct cleancache_filekey);
62523 void (*invalidate_fs)(int);
62524 -};
62525 +} __no_const;
62526
62527 extern struct cleancache_ops
62528 cleancache_register_ops(struct cleancache_ops *ops);
62529 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
62530 index 412bc6c..c31666e 100644
62531 --- a/include/linux/compiler-gcc4.h
62532 +++ b/include/linux/compiler-gcc4.h
62533 @@ -32,6 +32,21 @@
62534 #define __linktime_error(message) __attribute__((__error__(message)))
62535
62536 #if __GNUC_MINOR__ >= 5
62537 +
62538 +#ifdef CONSTIFY_PLUGIN
62539 +#define __no_const __attribute__((no_const))
62540 +#define __do_const __attribute__((do_const))
62541 +#endif
62542 +
62543 +#ifdef SIZE_OVERFLOW_PLUGIN
62544 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
62545 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
62546 +#endif
62547 +
62548 +#ifdef LATENT_ENTROPY_PLUGIN
62549 +#define __latent_entropy __attribute__((latent_entropy))
62550 +#endif
62551 +
62552 /*
62553 * Mark a position in code as unreachable. This can be used to
62554 * suppress control flow warnings after asm blocks that transfer
62555 @@ -47,6 +62,11 @@
62556 #define __noclone __attribute__((__noclone__))
62557
62558 #endif
62559 +
62560 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
62561 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
62562 +#define __bos0(ptr) __bos((ptr), 0)
62563 +#define __bos1(ptr) __bos((ptr), 1)
62564 #endif
62565
62566 #if __GNUC_MINOR__ >= 6
62567 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
62568 index f430e41..38be90f 100644
62569 --- a/include/linux/compiler.h
62570 +++ b/include/linux/compiler.h
62571 @@ -5,31 +5,62 @@
62572
62573 #ifdef __CHECKER__
62574 # define __user __attribute__((noderef, address_space(1)))
62575 +# define __force_user __force __user
62576 # define __kernel __attribute__((address_space(0)))
62577 +# define __force_kernel __force __kernel
62578 # define __safe __attribute__((safe))
62579 # define __force __attribute__((force))
62580 # define __nocast __attribute__((nocast))
62581 # define __iomem __attribute__((noderef, address_space(2)))
62582 +# define __force_iomem __force __iomem
62583 # define __acquires(x) __attribute__((context(x,0,1)))
62584 # define __releases(x) __attribute__((context(x,1,0)))
62585 # define __acquire(x) __context__(x,1)
62586 # define __release(x) __context__(x,-1)
62587 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
62588 # define __percpu __attribute__((noderef, address_space(3)))
62589 +# define __force_percpu __force __percpu
62590 #ifdef CONFIG_SPARSE_RCU_POINTER
62591 # define __rcu __attribute__((noderef, address_space(4)))
62592 +# define __force_rcu __force __rcu
62593 #else
62594 # define __rcu
62595 +# define __force_rcu
62596 #endif
62597 extern void __chk_user_ptr(const volatile void __user *);
62598 extern void __chk_io_ptr(const volatile void __iomem *);
62599 +#elif defined(CHECKER_PLUGIN)
62600 +//# define __user
62601 +//# define __force_user
62602 +//# define __kernel
62603 +//# define __force_kernel
62604 +# define __safe
62605 +# define __force
62606 +# define __nocast
62607 +# define __iomem
62608 +# define __force_iomem
62609 +# define __chk_user_ptr(x) (void)0
62610 +# define __chk_io_ptr(x) (void)0
62611 +# define __builtin_warning(x, y...) (1)
62612 +# define __acquires(x)
62613 +# define __releases(x)
62614 +# define __acquire(x) (void)0
62615 +# define __release(x) (void)0
62616 +# define __cond_lock(x,c) (c)
62617 +# define __percpu
62618 +# define __force_percpu
62619 +# define __rcu
62620 +# define __force_rcu
62621 #else
62622 # define __user
62623 +# define __force_user
62624 # define __kernel
62625 +# define __force_kernel
62626 # define __safe
62627 # define __force
62628 # define __nocast
62629 # define __iomem
62630 +# define __force_iomem
62631 # define __chk_user_ptr(x) (void)0
62632 # define __chk_io_ptr(x) (void)0
62633 # define __builtin_warning(x, y...) (1)
62634 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
62635 # define __release(x) (void)0
62636 # define __cond_lock(x,c) (c)
62637 # define __percpu
62638 +# define __force_percpu
62639 # define __rcu
62640 +# define __force_rcu
62641 #endif
62642
62643 #ifdef __KERNEL__
62644 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
62645 # define __attribute_const__ /* unimplemented */
62646 #endif
62647
62648 +#ifndef __no_const
62649 +# define __no_const
62650 +#endif
62651 +
62652 +#ifndef __do_const
62653 +# define __do_const
62654 +#endif
62655 +
62656 +#ifndef __size_overflow
62657 +# define __size_overflow(...)
62658 +#endif
62659 +
62660 +#ifndef __intentional_overflow
62661 +# define __intentional_overflow(...)
62662 +#endif
62663 +
62664 +#ifndef __latent_entropy
62665 +# define __latent_entropy
62666 +#endif
62667 +
62668 /*
62669 * Tell gcc if a function is cold. The compiler will assume any path
62670 * directly leading to the call is unlikely.
62671 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
62672 #define __cold
62673 #endif
62674
62675 +#ifndef __alloc_size
62676 +#define __alloc_size(...)
62677 +#endif
62678 +
62679 +#ifndef __bos
62680 +#define __bos(ptr, arg)
62681 +#endif
62682 +
62683 +#ifndef __bos0
62684 +#define __bos0(ptr)
62685 +#endif
62686 +
62687 +#ifndef __bos1
62688 +#define __bos1(ptr)
62689 +#endif
62690 +
62691 /* Simple shorthand for a section definition */
62692 #ifndef __section
62693 # define __section(S) __attribute__ ((__section__(#S)))
62694 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
62695 * use is to mediate communication between process-level code and irq/NMI
62696 * handlers, all running on the same CPU.
62697 */
62698 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
62699 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
62700 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
62701
62702 #endif /* __LINUX_COMPILER_H */
62703 diff --git a/include/linux/cred.h b/include/linux/cred.h
62704 index ebbed2c..908cc2c 100644
62705 --- a/include/linux/cred.h
62706 +++ b/include/linux/cred.h
62707 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
62708 static inline void validate_process_creds(void)
62709 {
62710 }
62711 +static inline void validate_task_creds(struct task_struct *task)
62712 +{
62713 +}
62714 #endif
62715
62716 /**
62717 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
62718 index b92eadf..b4ecdc1 100644
62719 --- a/include/linux/crypto.h
62720 +++ b/include/linux/crypto.h
62721 @@ -373,7 +373,7 @@ struct cipher_tfm {
62722 const u8 *key, unsigned int keylen);
62723 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
62724 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
62725 -};
62726 +} __no_const;
62727
62728 struct hash_tfm {
62729 int (*init)(struct hash_desc *desc);
62730 @@ -394,13 +394,13 @@ struct compress_tfm {
62731 int (*cot_decompress)(struct crypto_tfm *tfm,
62732 const u8 *src, unsigned int slen,
62733 u8 *dst, unsigned int *dlen);
62734 -};
62735 +} __no_const;
62736
62737 struct rng_tfm {
62738 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
62739 unsigned int dlen);
62740 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
62741 -};
62742 +} __no_const;
62743
62744 #define crt_ablkcipher crt_u.ablkcipher
62745 #define crt_aead crt_u.aead
62746 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
62747 index 7925bf0..d5143d2 100644
62748 --- a/include/linux/decompress/mm.h
62749 +++ b/include/linux/decompress/mm.h
62750 @@ -77,7 +77,7 @@ static void free(void *where)
62751 * warnings when not needed (indeed large_malloc / large_free are not
62752 * needed by inflate */
62753
62754 -#define malloc(a) kmalloc(a, GFP_KERNEL)
62755 +#define malloc(a) kmalloc((a), GFP_KERNEL)
62756 #define free(a) kfree(a)
62757
62758 #define large_malloc(a) vmalloc(a)
62759 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
62760 index 94af418..b1ca7a2 100644
62761 --- a/include/linux/dma-mapping.h
62762 +++ b/include/linux/dma-mapping.h
62763 @@ -54,7 +54,7 @@ struct dma_map_ops {
62764 u64 (*get_required_mask)(struct device *dev);
62765 #endif
62766 int is_phys;
62767 -};
62768 +} __do_const;
62769
62770 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
62771
62772 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
62773 index d3201e4..8281e63 100644
62774 --- a/include/linux/dmaengine.h
62775 +++ b/include/linux/dmaengine.h
62776 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
62777 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
62778 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
62779
62780 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62781 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62782 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
62783 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62784 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62785 struct dma_pinned_list *pinned_list, struct page *page,
62786 unsigned int offset, size_t len);
62787
62788 diff --git a/include/linux/elf.h b/include/linux/elf.h
62789 index 8c9048e..16a4665 100644
62790 --- a/include/linux/elf.h
62791 +++ b/include/linux/elf.h
62792 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
62793 #define elf_note elf32_note
62794 #define elf_addr_t Elf32_Off
62795 #define Elf_Half Elf32_Half
62796 +#define elf_dyn Elf32_Dyn
62797
62798 #else
62799
62800 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
62801 #define elf_note elf64_note
62802 #define elf_addr_t Elf64_Off
62803 #define Elf_Half Elf64_Half
62804 +#define elf_dyn Elf64_Dyn
62805
62806 #endif
62807
62808 diff --git a/include/linux/filter.h b/include/linux/filter.h
62809 index 24d251f..7afb83d 100644
62810 --- a/include/linux/filter.h
62811 +++ b/include/linux/filter.h
62812 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
62813
62814 struct sk_buff;
62815 struct sock;
62816 +struct bpf_jit_work;
62817
62818 struct sk_filter
62819 {
62820 @@ -27,6 +28,9 @@ struct sk_filter
62821 unsigned int len; /* Number of filter blocks */
62822 unsigned int (*bpf_func)(const struct sk_buff *skb,
62823 const struct sock_filter *filter);
62824 +#ifdef CONFIG_BPF_JIT
62825 + struct bpf_jit_work *work;
62826 +#endif
62827 struct rcu_head rcu;
62828 struct sock_filter insns[0];
62829 };
62830 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
62831 index 3044254..9767f41 100644
62832 --- a/include/linux/frontswap.h
62833 +++ b/include/linux/frontswap.h
62834 @@ -11,7 +11,7 @@ struct frontswap_ops {
62835 int (*load)(unsigned, pgoff_t, struct page *);
62836 void (*invalidate_page)(unsigned, pgoff_t);
62837 void (*invalidate_area)(unsigned);
62838 -};
62839 +} __no_const;
62840
62841 extern bool frontswap_enabled;
62842 extern struct frontswap_ops
62843 diff --git a/include/linux/fs.h b/include/linux/fs.h
62844 index 75fe9a1..72a4a6b 100644
62845 --- a/include/linux/fs.h
62846 +++ b/include/linux/fs.h
62847 @@ -1543,7 +1543,8 @@ struct file_operations {
62848 int (*setlease)(struct file *, long, struct file_lock **);
62849 long (*fallocate)(struct file *file, int mode, loff_t offset,
62850 loff_t len);
62851 -};
62852 +} __do_const;
62853 +typedef struct file_operations __no_const file_operations_no_const;
62854
62855 struct inode_operations {
62856 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
62857 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
62858 index 003dc0f..3c4ea97 100644
62859 --- a/include/linux/fs_struct.h
62860 +++ b/include/linux/fs_struct.h
62861 @@ -6,7 +6,7 @@
62862 #include <linux/seqlock.h>
62863
62864 struct fs_struct {
62865 - int users;
62866 + atomic_t users;
62867 spinlock_t lock;
62868 seqcount_t seq;
62869 int umask;
62870 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
62871 index ce31408..b1ad003 100644
62872 --- a/include/linux/fscache-cache.h
62873 +++ b/include/linux/fscache-cache.h
62874 @@ -102,7 +102,7 @@ struct fscache_operation {
62875 fscache_operation_release_t release;
62876 };
62877
62878 -extern atomic_t fscache_op_debug_id;
62879 +extern atomic_unchecked_t fscache_op_debug_id;
62880 extern void fscache_op_work_func(struct work_struct *work);
62881
62882 extern void fscache_enqueue_operation(struct fscache_operation *);
62883 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
62884 {
62885 INIT_WORK(&op->work, fscache_op_work_func);
62886 atomic_set(&op->usage, 1);
62887 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62888 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62889 op->processor = processor;
62890 op->release = release;
62891 INIT_LIST_HEAD(&op->pend_link);
62892 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
62893 index 0fbfb46..52a6556 100644
62894 --- a/include/linux/fsnotify.h
62895 +++ b/include/linux/fsnotify.h
62896 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
62897 */
62898 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
62899 {
62900 - return kstrdup(name, GFP_KERNEL);
62901 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
62902 }
62903
62904 /*
62905 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
62906 index 642928c..93afe6a 100644
62907 --- a/include/linux/ftrace_event.h
62908 +++ b/include/linux/ftrace_event.h
62909 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
62910 extern int trace_add_event_call(struct ftrace_event_call *call);
62911 extern void trace_remove_event_call(struct ftrace_event_call *call);
62912
62913 -#define is_signed_type(type) (((type)(-1)) < 0)
62914 +#define is_signed_type(type) (((type)(-1)) < (type)1)
62915
62916 int trace_set_clr_event(const char *system, const char *event, int set);
62917
62918 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
62919 index 4f440b3..342233a 100644
62920 --- a/include/linux/genhd.h
62921 +++ b/include/linux/genhd.h
62922 @@ -190,7 +190,7 @@ struct gendisk {
62923 struct kobject *slave_dir;
62924
62925 struct timer_rand_state *random;
62926 - atomic_t sync_io; /* RAID */
62927 + atomic_unchecked_t sync_io; /* RAID */
62928 struct disk_events *ev;
62929 #ifdef CONFIG_BLK_DEV_INTEGRITY
62930 struct blk_integrity *integrity;
62931 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
62932 index d0a7967..63c4c47 100644
62933 --- a/include/linux/gfp.h
62934 +++ b/include/linux/gfp.h
62935 @@ -35,6 +35,12 @@ struct vm_area_struct;
62936 #define ___GFP_OTHER_NODE 0x800000u
62937 #define ___GFP_WRITE 0x1000000u
62938
62939 +#ifdef CONFIG_PAX_USERCOPY_SLABS
62940 +#define ___GFP_USERCOPY 0x2000000u
62941 +#else
62942 +#define ___GFP_USERCOPY 0
62943 +#endif
62944 +
62945 /*
62946 * GFP bitmasks..
62947 *
62948 @@ -89,6 +95,7 @@ struct vm_area_struct;
62949 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
62950 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
62951 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
62952 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
62953
62954 /*
62955 * This may seem redundant, but it's a way of annotating false positives vs.
62956 @@ -96,7 +103,7 @@ struct vm_area_struct;
62957 */
62958 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
62959
62960 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
62961 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
62962 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
62963
62964 /* This equals 0, but use constants in case they ever change */
62965 @@ -150,6 +157,8 @@ struct vm_area_struct;
62966 /* 4GB DMA on some platforms */
62967 #define GFP_DMA32 __GFP_DMA32
62968
62969 +#define GFP_USERCOPY __GFP_USERCOPY
62970 +
62971 /* Convert GFP flags to their corresponding migrate type */
62972 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
62973 {
62974 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
62975 new file mode 100644
62976 index 0000000..ebe6d72
62977 --- /dev/null
62978 +++ b/include/linux/gracl.h
62979 @@ -0,0 +1,319 @@
62980 +#ifndef GR_ACL_H
62981 +#define GR_ACL_H
62982 +
62983 +#include <linux/grdefs.h>
62984 +#include <linux/resource.h>
62985 +#include <linux/capability.h>
62986 +#include <linux/dcache.h>
62987 +#include <asm/resource.h>
62988 +
62989 +/* Major status information */
62990 +
62991 +#define GR_VERSION "grsecurity 2.9.1"
62992 +#define GRSECURITY_VERSION 0x2901
62993 +
62994 +enum {
62995 + GR_SHUTDOWN = 0,
62996 + GR_ENABLE = 1,
62997 + GR_SPROLE = 2,
62998 + GR_RELOAD = 3,
62999 + GR_SEGVMOD = 4,
63000 + GR_STATUS = 5,
63001 + GR_UNSPROLE = 6,
63002 + GR_PASSSET = 7,
63003 + GR_SPROLEPAM = 8,
63004 +};
63005 +
63006 +/* Password setup definitions
63007 + * kernel/grhash.c */
63008 +enum {
63009 + GR_PW_LEN = 128,
63010 + GR_SALT_LEN = 16,
63011 + GR_SHA_LEN = 32,
63012 +};
63013 +
63014 +enum {
63015 + GR_SPROLE_LEN = 64,
63016 +};
63017 +
63018 +enum {
63019 + GR_NO_GLOB = 0,
63020 + GR_REG_GLOB,
63021 + GR_CREATE_GLOB
63022 +};
63023 +
63024 +#define GR_NLIMITS 32
63025 +
63026 +/* Begin Data Structures */
63027 +
63028 +struct sprole_pw {
63029 + unsigned char *rolename;
63030 + unsigned char salt[GR_SALT_LEN];
63031 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63032 +};
63033 +
63034 +struct name_entry {
63035 + __u32 key;
63036 + ino_t inode;
63037 + dev_t device;
63038 + char *name;
63039 + __u16 len;
63040 + __u8 deleted;
63041 + struct name_entry *prev;
63042 + struct name_entry *next;
63043 +};
63044 +
63045 +struct inodev_entry {
63046 + struct name_entry *nentry;
63047 + struct inodev_entry *prev;
63048 + struct inodev_entry *next;
63049 +};
63050 +
63051 +struct acl_role_db {
63052 + struct acl_role_label **r_hash;
63053 + __u32 r_size;
63054 +};
63055 +
63056 +struct inodev_db {
63057 + struct inodev_entry **i_hash;
63058 + __u32 i_size;
63059 +};
63060 +
63061 +struct name_db {
63062 + struct name_entry **n_hash;
63063 + __u32 n_size;
63064 +};
63065 +
63066 +struct crash_uid {
63067 + uid_t uid;
63068 + unsigned long expires;
63069 +};
63070 +
63071 +struct gr_hash_struct {
63072 + void **table;
63073 + void **nametable;
63074 + void *first;
63075 + __u32 table_size;
63076 + __u32 used_size;
63077 + int type;
63078 +};
63079 +
63080 +/* Userspace Grsecurity ACL data structures */
63081 +
63082 +struct acl_subject_label {
63083 + char *filename;
63084 + ino_t inode;
63085 + dev_t device;
63086 + __u32 mode;
63087 + kernel_cap_t cap_mask;
63088 + kernel_cap_t cap_lower;
63089 + kernel_cap_t cap_invert_audit;
63090 +
63091 + struct rlimit res[GR_NLIMITS];
63092 + __u32 resmask;
63093 +
63094 + __u8 user_trans_type;
63095 + __u8 group_trans_type;
63096 + uid_t *user_transitions;
63097 + gid_t *group_transitions;
63098 + __u16 user_trans_num;
63099 + __u16 group_trans_num;
63100 +
63101 + __u32 sock_families[2];
63102 + __u32 ip_proto[8];
63103 + __u32 ip_type;
63104 + struct acl_ip_label **ips;
63105 + __u32 ip_num;
63106 + __u32 inaddr_any_override;
63107 +
63108 + __u32 crashes;
63109 + unsigned long expires;
63110 +
63111 + struct acl_subject_label *parent_subject;
63112 + struct gr_hash_struct *hash;
63113 + struct acl_subject_label *prev;
63114 + struct acl_subject_label *next;
63115 +
63116 + struct acl_object_label **obj_hash;
63117 + __u32 obj_hash_size;
63118 + __u16 pax_flags;
63119 +};
63120 +
63121 +struct role_allowed_ip {
63122 + __u32 addr;
63123 + __u32 netmask;
63124 +
63125 + struct role_allowed_ip *prev;
63126 + struct role_allowed_ip *next;
63127 +};
63128 +
63129 +struct role_transition {
63130 + char *rolename;
63131 +
63132 + struct role_transition *prev;
63133 + struct role_transition *next;
63134 +};
63135 +
63136 +struct acl_role_label {
63137 + char *rolename;
63138 + uid_t uidgid;
63139 + __u16 roletype;
63140 +
63141 + __u16 auth_attempts;
63142 + unsigned long expires;
63143 +
63144 + struct acl_subject_label *root_label;
63145 + struct gr_hash_struct *hash;
63146 +
63147 + struct acl_role_label *prev;
63148 + struct acl_role_label *next;
63149 +
63150 + struct role_transition *transitions;
63151 + struct role_allowed_ip *allowed_ips;
63152 + uid_t *domain_children;
63153 + __u16 domain_child_num;
63154 +
63155 + umode_t umask;
63156 +
63157 + struct acl_subject_label **subj_hash;
63158 + __u32 subj_hash_size;
63159 +};
63160 +
63161 +struct user_acl_role_db {
63162 + struct acl_role_label **r_table;
63163 + __u32 num_pointers; /* Number of allocations to track */
63164 + __u32 num_roles; /* Number of roles */
63165 + __u32 num_domain_children; /* Number of domain children */
63166 + __u32 num_subjects; /* Number of subjects */
63167 + __u32 num_objects; /* Number of objects */
63168 +};
63169 +
63170 +struct acl_object_label {
63171 + char *filename;
63172 + ino_t inode;
63173 + dev_t device;
63174 + __u32 mode;
63175 +
63176 + struct acl_subject_label *nested;
63177 + struct acl_object_label *globbed;
63178 +
63179 + /* next two structures not used */
63180 +
63181 + struct acl_object_label *prev;
63182 + struct acl_object_label *next;
63183 +};
63184 +
63185 +struct acl_ip_label {
63186 + char *iface;
63187 + __u32 addr;
63188 + __u32 netmask;
63189 + __u16 low, high;
63190 + __u8 mode;
63191 + __u32 type;
63192 + __u32 proto[8];
63193 +
63194 + /* next two structures not used */
63195 +
63196 + struct acl_ip_label *prev;
63197 + struct acl_ip_label *next;
63198 +};
63199 +
63200 +struct gr_arg {
63201 + struct user_acl_role_db role_db;
63202 + unsigned char pw[GR_PW_LEN];
63203 + unsigned char salt[GR_SALT_LEN];
63204 + unsigned char sum[GR_SHA_LEN];
63205 + unsigned char sp_role[GR_SPROLE_LEN];
63206 + struct sprole_pw *sprole_pws;
63207 + dev_t segv_device;
63208 + ino_t segv_inode;
63209 + uid_t segv_uid;
63210 + __u16 num_sprole_pws;
63211 + __u16 mode;
63212 +};
63213 +
63214 +struct gr_arg_wrapper {
63215 + struct gr_arg *arg;
63216 + __u32 version;
63217 + __u32 size;
63218 +};
63219 +
63220 +struct subject_map {
63221 + struct acl_subject_label *user;
63222 + struct acl_subject_label *kernel;
63223 + struct subject_map *prev;
63224 + struct subject_map *next;
63225 +};
63226 +
63227 +struct acl_subj_map_db {
63228 + struct subject_map **s_hash;
63229 + __u32 s_size;
63230 +};
63231 +
63232 +/* End Data Structures Section */
63233 +
63234 +/* Hash functions generated by empirical testing by Brad Spengler
63235 + Makes good use of the low bits of the inode. Generally 0-1 times
63236 + in loop for successful match. 0-3 for unsuccessful match.
63237 + Shift/add algorithm with modulus of table size and an XOR*/
63238 +
63239 +static __inline__ unsigned int
63240 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63241 +{
63242 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
63243 +}
63244 +
63245 + static __inline__ unsigned int
63246 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
63247 +{
63248 + return ((const unsigned long)userp % sz);
63249 +}
63250 +
63251 +static __inline__ unsigned int
63252 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
63253 +{
63254 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
63255 +}
63256 +
63257 +static __inline__ unsigned int
63258 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
63259 +{
63260 + return full_name_hash((const unsigned char *)name, len) % sz;
63261 +}
63262 +
63263 +#define FOR_EACH_ROLE_START(role) \
63264 + role = role_list; \
63265 + while (role) {
63266 +
63267 +#define FOR_EACH_ROLE_END(role) \
63268 + role = role->prev; \
63269 + }
63270 +
63271 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
63272 + subj = NULL; \
63273 + iter = 0; \
63274 + while (iter < role->subj_hash_size) { \
63275 + if (subj == NULL) \
63276 + subj = role->subj_hash[iter]; \
63277 + if (subj == NULL) { \
63278 + iter++; \
63279 + continue; \
63280 + }
63281 +
63282 +#define FOR_EACH_SUBJECT_END(subj,iter) \
63283 + subj = subj->next; \
63284 + if (subj == NULL) \
63285 + iter++; \
63286 + }
63287 +
63288 +
63289 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
63290 + subj = role->hash->first; \
63291 + while (subj != NULL) {
63292 +
63293 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
63294 + subj = subj->next; \
63295 + }
63296 +
63297 +#endif
63298 +
63299 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
63300 new file mode 100644
63301 index 0000000..323ecf2
63302 --- /dev/null
63303 +++ b/include/linux/gralloc.h
63304 @@ -0,0 +1,9 @@
63305 +#ifndef __GRALLOC_H
63306 +#define __GRALLOC_H
63307 +
63308 +void acl_free_all(void);
63309 +int acl_alloc_stack_init(unsigned long size);
63310 +void *acl_alloc(unsigned long len);
63311 +void *acl_alloc_num(unsigned long num, unsigned long len);
63312 +
63313 +#endif
63314 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
63315 new file mode 100644
63316 index 0000000..be66033
63317 --- /dev/null
63318 +++ b/include/linux/grdefs.h
63319 @@ -0,0 +1,140 @@
63320 +#ifndef GRDEFS_H
63321 +#define GRDEFS_H
63322 +
63323 +/* Begin grsecurity status declarations */
63324 +
63325 +enum {
63326 + GR_READY = 0x01,
63327 + GR_STATUS_INIT = 0x00 // disabled state
63328 +};
63329 +
63330 +/* Begin ACL declarations */
63331 +
63332 +/* Role flags */
63333 +
63334 +enum {
63335 + GR_ROLE_USER = 0x0001,
63336 + GR_ROLE_GROUP = 0x0002,
63337 + GR_ROLE_DEFAULT = 0x0004,
63338 + GR_ROLE_SPECIAL = 0x0008,
63339 + GR_ROLE_AUTH = 0x0010,
63340 + GR_ROLE_NOPW = 0x0020,
63341 + GR_ROLE_GOD = 0x0040,
63342 + GR_ROLE_LEARN = 0x0080,
63343 + GR_ROLE_TPE = 0x0100,
63344 + GR_ROLE_DOMAIN = 0x0200,
63345 + GR_ROLE_PAM = 0x0400,
63346 + GR_ROLE_PERSIST = 0x0800
63347 +};
63348 +
63349 +/* ACL Subject and Object mode flags */
63350 +enum {
63351 + GR_DELETED = 0x80000000
63352 +};
63353 +
63354 +/* ACL Object-only mode flags */
63355 +enum {
63356 + GR_READ = 0x00000001,
63357 + GR_APPEND = 0x00000002,
63358 + GR_WRITE = 0x00000004,
63359 + GR_EXEC = 0x00000008,
63360 + GR_FIND = 0x00000010,
63361 + GR_INHERIT = 0x00000020,
63362 + GR_SETID = 0x00000040,
63363 + GR_CREATE = 0x00000080,
63364 + GR_DELETE = 0x00000100,
63365 + GR_LINK = 0x00000200,
63366 + GR_AUDIT_READ = 0x00000400,
63367 + GR_AUDIT_APPEND = 0x00000800,
63368 + GR_AUDIT_WRITE = 0x00001000,
63369 + GR_AUDIT_EXEC = 0x00002000,
63370 + GR_AUDIT_FIND = 0x00004000,
63371 + GR_AUDIT_INHERIT= 0x00008000,
63372 + GR_AUDIT_SETID = 0x00010000,
63373 + GR_AUDIT_CREATE = 0x00020000,
63374 + GR_AUDIT_DELETE = 0x00040000,
63375 + GR_AUDIT_LINK = 0x00080000,
63376 + GR_PTRACERD = 0x00100000,
63377 + GR_NOPTRACE = 0x00200000,
63378 + GR_SUPPRESS = 0x00400000,
63379 + GR_NOLEARN = 0x00800000,
63380 + GR_INIT_TRANSFER= 0x01000000
63381 +};
63382 +
63383 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
63384 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
63385 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
63386 +
63387 +/* ACL subject-only mode flags */
63388 +enum {
63389 + GR_KILL = 0x00000001,
63390 + GR_VIEW = 0x00000002,
63391 + GR_PROTECTED = 0x00000004,
63392 + GR_LEARN = 0x00000008,
63393 + GR_OVERRIDE = 0x00000010,
63394 + /* just a placeholder, this mode is only used in userspace */
63395 + GR_DUMMY = 0x00000020,
63396 + GR_PROTSHM = 0x00000040,
63397 + GR_KILLPROC = 0x00000080,
63398 + GR_KILLIPPROC = 0x00000100,
63399 + /* just a placeholder, this mode is only used in userspace */
63400 + GR_NOTROJAN = 0x00000200,
63401 + GR_PROTPROCFD = 0x00000400,
63402 + GR_PROCACCT = 0x00000800,
63403 + GR_RELAXPTRACE = 0x00001000,
63404 + //GR_NESTED = 0x00002000,
63405 + GR_INHERITLEARN = 0x00004000,
63406 + GR_PROCFIND = 0x00008000,
63407 + GR_POVERRIDE = 0x00010000,
63408 + GR_KERNELAUTH = 0x00020000,
63409 + GR_ATSECURE = 0x00040000,
63410 + GR_SHMEXEC = 0x00080000
63411 +};
63412 +
63413 +enum {
63414 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
63415 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
63416 + GR_PAX_ENABLE_MPROTECT = 0x0004,
63417 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
63418 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
63419 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
63420 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
63421 + GR_PAX_DISABLE_MPROTECT = 0x0400,
63422 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
63423 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
63424 +};
63425 +
63426 +enum {
63427 + GR_ID_USER = 0x01,
63428 + GR_ID_GROUP = 0x02,
63429 +};
63430 +
63431 +enum {
63432 + GR_ID_ALLOW = 0x01,
63433 + GR_ID_DENY = 0x02,
63434 +};
63435 +
63436 +#define GR_CRASH_RES 31
63437 +#define GR_UIDTABLE_MAX 500
63438 +
63439 +/* begin resource learning section */
63440 +enum {
63441 + GR_RLIM_CPU_BUMP = 60,
63442 + GR_RLIM_FSIZE_BUMP = 50000,
63443 + GR_RLIM_DATA_BUMP = 10000,
63444 + GR_RLIM_STACK_BUMP = 1000,
63445 + GR_RLIM_CORE_BUMP = 10000,
63446 + GR_RLIM_RSS_BUMP = 500000,
63447 + GR_RLIM_NPROC_BUMP = 1,
63448 + GR_RLIM_NOFILE_BUMP = 5,
63449 + GR_RLIM_MEMLOCK_BUMP = 50000,
63450 + GR_RLIM_AS_BUMP = 500000,
63451 + GR_RLIM_LOCKS_BUMP = 2,
63452 + GR_RLIM_SIGPENDING_BUMP = 5,
63453 + GR_RLIM_MSGQUEUE_BUMP = 10000,
63454 + GR_RLIM_NICE_BUMP = 1,
63455 + GR_RLIM_RTPRIO_BUMP = 1,
63456 + GR_RLIM_RTTIME_BUMP = 1000000
63457 +};
63458 +
63459 +#endif
63460 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
63461 new file mode 100644
63462 index 0000000..c9292f7
63463 --- /dev/null
63464 +++ b/include/linux/grinternal.h
63465 @@ -0,0 +1,223 @@
63466 +#ifndef __GRINTERNAL_H
63467 +#define __GRINTERNAL_H
63468 +
63469 +#ifdef CONFIG_GRKERNSEC
63470 +
63471 +#include <linux/fs.h>
63472 +#include <linux/mnt_namespace.h>
63473 +#include <linux/nsproxy.h>
63474 +#include <linux/gracl.h>
63475 +#include <linux/grdefs.h>
63476 +#include <linux/grmsg.h>
63477 +
63478 +void gr_add_learn_entry(const char *fmt, ...)
63479 + __attribute__ ((format (printf, 1, 2)));
63480 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
63481 + const struct vfsmount *mnt);
63482 +__u32 gr_check_create(const struct dentry *new_dentry,
63483 + const struct dentry *parent,
63484 + const struct vfsmount *mnt, const __u32 mode);
63485 +int gr_check_protected_task(const struct task_struct *task);
63486 +__u32 to_gr_audit(const __u32 reqmode);
63487 +int gr_set_acls(const int type);
63488 +int gr_apply_subject_to_task(struct task_struct *task);
63489 +int gr_acl_is_enabled(void);
63490 +char gr_roletype_to_char(void);
63491 +
63492 +void gr_handle_alertkill(struct task_struct *task);
63493 +char *gr_to_filename(const struct dentry *dentry,
63494 + const struct vfsmount *mnt);
63495 +char *gr_to_filename1(const struct dentry *dentry,
63496 + const struct vfsmount *mnt);
63497 +char *gr_to_filename2(const struct dentry *dentry,
63498 + const struct vfsmount *mnt);
63499 +char *gr_to_filename3(const struct dentry *dentry,
63500 + const struct vfsmount *mnt);
63501 +
63502 +extern int grsec_enable_ptrace_readexec;
63503 +extern int grsec_enable_harden_ptrace;
63504 +extern int grsec_enable_link;
63505 +extern int grsec_enable_fifo;
63506 +extern int grsec_enable_execve;
63507 +extern int grsec_enable_shm;
63508 +extern int grsec_enable_execlog;
63509 +extern int grsec_enable_signal;
63510 +extern int grsec_enable_audit_ptrace;
63511 +extern int grsec_enable_forkfail;
63512 +extern int grsec_enable_time;
63513 +extern int grsec_enable_rofs;
63514 +extern int grsec_enable_chroot_shmat;
63515 +extern int grsec_enable_chroot_mount;
63516 +extern int grsec_enable_chroot_double;
63517 +extern int grsec_enable_chroot_pivot;
63518 +extern int grsec_enable_chroot_chdir;
63519 +extern int grsec_enable_chroot_chmod;
63520 +extern int grsec_enable_chroot_mknod;
63521 +extern int grsec_enable_chroot_fchdir;
63522 +extern int grsec_enable_chroot_nice;
63523 +extern int grsec_enable_chroot_execlog;
63524 +extern int grsec_enable_chroot_caps;
63525 +extern int grsec_enable_chroot_sysctl;
63526 +extern int grsec_enable_chroot_unix;
63527 +extern int grsec_enable_symlinkown;
63528 +extern int grsec_symlinkown_gid;
63529 +extern int grsec_enable_tpe;
63530 +extern int grsec_tpe_gid;
63531 +extern int grsec_enable_tpe_all;
63532 +extern int grsec_enable_tpe_invert;
63533 +extern int grsec_enable_socket_all;
63534 +extern int grsec_socket_all_gid;
63535 +extern int grsec_enable_socket_client;
63536 +extern int grsec_socket_client_gid;
63537 +extern int grsec_enable_socket_server;
63538 +extern int grsec_socket_server_gid;
63539 +extern int grsec_audit_gid;
63540 +extern int grsec_enable_group;
63541 +extern int grsec_enable_audit_textrel;
63542 +extern int grsec_enable_log_rwxmaps;
63543 +extern int grsec_enable_mount;
63544 +extern int grsec_enable_chdir;
63545 +extern int grsec_resource_logging;
63546 +extern int grsec_enable_blackhole;
63547 +extern int grsec_lastack_retries;
63548 +extern int grsec_enable_brute;
63549 +extern int grsec_lock;
63550 +
63551 +extern spinlock_t grsec_alert_lock;
63552 +extern unsigned long grsec_alert_wtime;
63553 +extern unsigned long grsec_alert_fyet;
63554 +
63555 +extern spinlock_t grsec_audit_lock;
63556 +
63557 +extern rwlock_t grsec_exec_file_lock;
63558 +
63559 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
63560 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
63561 + (tsk)->exec_file->f_vfsmnt) : "/")
63562 +
63563 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
63564 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
63565 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
63566 +
63567 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
63568 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
63569 + (tsk)->exec_file->f_vfsmnt) : "/")
63570 +
63571 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
63572 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
63573 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
63574 +
63575 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
63576 +
63577 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
63578 +
63579 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
63580 + (task)->pid, (cred)->uid, \
63581 + (cred)->euid, (cred)->gid, (cred)->egid, \
63582 + gr_parent_task_fullpath(task), \
63583 + (task)->real_parent->comm, (task)->real_parent->pid, \
63584 + (pcred)->uid, (pcred)->euid, \
63585 + (pcred)->gid, (pcred)->egid
63586 +
63587 +#define GR_CHROOT_CAPS {{ \
63588 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
63589 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
63590 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
63591 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
63592 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
63593 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
63594 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
63595 +
63596 +#define security_learn(normal_msg,args...) \
63597 +({ \
63598 + read_lock(&grsec_exec_file_lock); \
63599 + gr_add_learn_entry(normal_msg "\n", ## args); \
63600 + read_unlock(&grsec_exec_file_lock); \
63601 +})
63602 +
63603 +enum {
63604 + GR_DO_AUDIT,
63605 + GR_DONT_AUDIT,
63606 + /* used for non-audit messages that we shouldn't kill the task on */
63607 + GR_DONT_AUDIT_GOOD
63608 +};
63609 +
63610 +enum {
63611 + GR_TTYSNIFF,
63612 + GR_RBAC,
63613 + GR_RBAC_STR,
63614 + GR_STR_RBAC,
63615 + GR_RBAC_MODE2,
63616 + GR_RBAC_MODE3,
63617 + GR_FILENAME,
63618 + GR_SYSCTL_HIDDEN,
63619 + GR_NOARGS,
63620 + GR_ONE_INT,
63621 + GR_ONE_INT_TWO_STR,
63622 + GR_ONE_STR,
63623 + GR_STR_INT,
63624 + GR_TWO_STR_INT,
63625 + GR_TWO_INT,
63626 + GR_TWO_U64,
63627 + GR_THREE_INT,
63628 + GR_FIVE_INT_TWO_STR,
63629 + GR_TWO_STR,
63630 + GR_THREE_STR,
63631 + GR_FOUR_STR,
63632 + GR_STR_FILENAME,
63633 + GR_FILENAME_STR,
63634 + GR_FILENAME_TWO_INT,
63635 + GR_FILENAME_TWO_INT_STR,
63636 + GR_TEXTREL,
63637 + GR_PTRACE,
63638 + GR_RESOURCE,
63639 + GR_CAP,
63640 + GR_SIG,
63641 + GR_SIG2,
63642 + GR_CRASH1,
63643 + GR_CRASH2,
63644 + GR_PSACCT,
63645 + GR_RWXMAP
63646 +};
63647 +
63648 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
63649 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
63650 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
63651 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
63652 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
63653 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
63654 +#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)
63655 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
63656 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
63657 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
63658 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
63659 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
63660 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
63661 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
63662 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
63663 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
63664 +#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)
63665 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
63666 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
63667 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
63668 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
63669 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
63670 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
63671 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
63672 +#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)
63673 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
63674 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
63675 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
63676 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
63677 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
63678 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
63679 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
63680 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
63681 +#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)
63682 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
63683 +
63684 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
63685 +
63686 +#endif
63687 +
63688 +#endif
63689 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
63690 new file mode 100644
63691 index 0000000..2bd4c8d
63692 --- /dev/null
63693 +++ b/include/linux/grmsg.h
63694 @@ -0,0 +1,111 @@
63695 +#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"
63696 +#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"
63697 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
63698 +#define GR_STOPMOD_MSG "denied modification of module state by "
63699 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
63700 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
63701 +#define GR_IOPERM_MSG "denied use of ioperm() by "
63702 +#define GR_IOPL_MSG "denied use of iopl() by "
63703 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
63704 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
63705 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
63706 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
63707 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
63708 +#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"
63709 +#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"
63710 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
63711 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
63712 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
63713 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
63714 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
63715 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
63716 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
63717 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
63718 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
63719 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
63720 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
63721 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
63722 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
63723 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
63724 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
63725 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
63726 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
63727 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63728 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63729 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
63730 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63731 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63732 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63733 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63734 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63735 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63736 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63737 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63738 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63739 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63740 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63741 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63742 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63743 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63744 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63745 +#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"
63746 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
63747 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63748 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63749 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63750 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63751 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63752 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63753 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63754 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63755 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63756 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63757 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63758 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63759 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63760 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63761 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63762 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63763 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63764 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63765 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63766 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
63767 +#define GR_NICE_CHROOT_MSG "denied priority change by "
63768 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63769 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63770 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63771 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63772 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63773 +#define GR_TIME_MSG "time set by "
63774 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63775 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63776 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63777 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63778 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63779 +#define GR_BIND_MSG "denied bind() by "
63780 +#define GR_CONNECT_MSG "denied connect() by "
63781 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63782 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63783 +#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"
63784 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63785 +#define GR_CAP_ACL_MSG "use of %s denied for "
63786 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
63787 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63788 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63789 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63790 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63791 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63792 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63793 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63794 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63795 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63796 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63797 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63798 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63799 +#define GR_VM86_MSG "denied use of vm86 by "
63800 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63801 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
63802 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63803 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
63804 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
63805 +#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 "
63806 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
63807 new file mode 100644
63808 index 0000000..f2f5d5b
63809 --- /dev/null
63810 +++ b/include/linux/grsecurity.h
63811 @@ -0,0 +1,239 @@
63812 +#ifndef GR_SECURITY_H
63813 +#define GR_SECURITY_H
63814 +#include <linux/fs.h>
63815 +#include <linux/fs_struct.h>
63816 +#include <linux/binfmts.h>
63817 +#include <linux/gracl.h>
63818 +
63819 +/* notify of brain-dead configs */
63820 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63821 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
63822 +#endif
63823 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63824 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63825 +#endif
63826 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63827 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63828 +#endif
63829 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63830 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
63831 +#endif
63832 +
63833 +#include <linux/compat.h>
63834 +
63835 +struct user_arg_ptr {
63836 +#ifdef CONFIG_COMPAT
63837 + bool is_compat;
63838 +#endif
63839 + union {
63840 + const char __user *const __user *native;
63841 +#ifdef CONFIG_COMPAT
63842 + const compat_uptr_t __user *compat;
63843 +#endif
63844 + } ptr;
63845 +};
63846 +
63847 +void gr_handle_brute_attach(unsigned long mm_flags);
63848 +void gr_handle_brute_check(void);
63849 +void gr_handle_kernel_exploit(void);
63850 +int gr_process_user_ban(void);
63851 +
63852 +char gr_roletype_to_char(void);
63853 +
63854 +int gr_acl_enable_at_secure(void);
63855 +
63856 +int gr_check_user_change(int real, int effective, int fs);
63857 +int gr_check_group_change(int real, int effective, int fs);
63858 +
63859 +void gr_del_task_from_ip_table(struct task_struct *p);
63860 +
63861 +int gr_pid_is_chrooted(struct task_struct *p);
63862 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63863 +int gr_handle_chroot_nice(void);
63864 +int gr_handle_chroot_sysctl(const int op);
63865 +int gr_handle_chroot_setpriority(struct task_struct *p,
63866 + const int niceval);
63867 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63868 +int gr_handle_chroot_chroot(const struct dentry *dentry,
63869 + const struct vfsmount *mnt);
63870 +void gr_handle_chroot_chdir(struct path *path);
63871 +int gr_handle_chroot_chmod(const struct dentry *dentry,
63872 + const struct vfsmount *mnt, const int mode);
63873 +int gr_handle_chroot_mknod(const struct dentry *dentry,
63874 + const struct vfsmount *mnt, const int mode);
63875 +int gr_handle_chroot_mount(const struct dentry *dentry,
63876 + const struct vfsmount *mnt,
63877 + const char *dev_name);
63878 +int gr_handle_chroot_pivot(void);
63879 +int gr_handle_chroot_unix(const pid_t pid);
63880 +
63881 +int gr_handle_rawio(const struct inode *inode);
63882 +
63883 +void gr_handle_ioperm(void);
63884 +void gr_handle_iopl(void);
63885 +
63886 +umode_t gr_acl_umask(void);
63887 +
63888 +int gr_tpe_allow(const struct file *file);
63889 +
63890 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63891 +void gr_clear_chroot_entries(struct task_struct *task);
63892 +
63893 +void gr_log_forkfail(const int retval);
63894 +void gr_log_timechange(void);
63895 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63896 +void gr_log_chdir(const struct dentry *dentry,
63897 + const struct vfsmount *mnt);
63898 +void gr_log_chroot_exec(const struct dentry *dentry,
63899 + const struct vfsmount *mnt);
63900 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
63901 +void gr_log_remount(const char *devname, const int retval);
63902 +void gr_log_unmount(const char *devname, const int retval);
63903 +void gr_log_mount(const char *from, const char *to, const int retval);
63904 +void gr_log_textrel(struct vm_area_struct *vma);
63905 +void gr_log_rwxmmap(struct file *file);
63906 +void gr_log_rwxmprotect(struct file *file);
63907 +
63908 +int gr_handle_follow_link(const struct inode *parent,
63909 + const struct inode *inode,
63910 + const struct dentry *dentry,
63911 + const struct vfsmount *mnt);
63912 +int gr_handle_fifo(const struct dentry *dentry,
63913 + const struct vfsmount *mnt,
63914 + const struct dentry *dir, const int flag,
63915 + const int acc_mode);
63916 +int gr_handle_hardlink(const struct dentry *dentry,
63917 + const struct vfsmount *mnt,
63918 + struct inode *inode,
63919 + const int mode, const struct filename *to);
63920 +
63921 +int gr_is_capable(const int cap);
63922 +int gr_is_capable_nolog(const int cap);
63923 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63924 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
63925 +
63926 +void gr_learn_resource(const struct task_struct *task, const int limit,
63927 + const unsigned long wanted, const int gt);
63928 +void gr_copy_label(struct task_struct *tsk);
63929 +void gr_handle_crash(struct task_struct *task, const int sig);
63930 +int gr_handle_signal(const struct task_struct *p, const int sig);
63931 +int gr_check_crash_uid(const uid_t uid);
63932 +int gr_check_protected_task(const struct task_struct *task);
63933 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63934 +int gr_acl_handle_mmap(const struct file *file,
63935 + const unsigned long prot);
63936 +int gr_acl_handle_mprotect(const struct file *file,
63937 + const unsigned long prot);
63938 +int gr_check_hidden_task(const struct task_struct *tsk);
63939 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63940 + const struct vfsmount *mnt);
63941 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63942 + const struct vfsmount *mnt);
63943 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63944 + const struct vfsmount *mnt, const int fmode);
63945 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63946 + const struct vfsmount *mnt, umode_t *mode);
63947 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63948 + const struct vfsmount *mnt);
63949 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63950 + const struct vfsmount *mnt);
63951 +int gr_handle_ptrace(struct task_struct *task, const long request);
63952 +int gr_handle_proc_ptrace(struct task_struct *task);
63953 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63954 + const struct vfsmount *mnt);
63955 +int gr_check_crash_exec(const struct file *filp);
63956 +int gr_acl_is_enabled(void);
63957 +void gr_set_kernel_label(struct task_struct *task);
63958 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63959 + const gid_t gid);
63960 +int gr_set_proc_label(const struct dentry *dentry,
63961 + const struct vfsmount *mnt,
63962 + const int unsafe_flags);
63963 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63964 + const struct vfsmount *mnt);
63965 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63966 + const struct vfsmount *mnt, int acc_mode);
63967 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63968 + const struct dentry *p_dentry,
63969 + const struct vfsmount *p_mnt,
63970 + int open_flags, int acc_mode, const int imode);
63971 +void gr_handle_create(const struct dentry *dentry,
63972 + const struct vfsmount *mnt);
63973 +void gr_handle_proc_create(const struct dentry *dentry,
63974 + const struct inode *inode);
63975 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63976 + const struct dentry *parent_dentry,
63977 + const struct vfsmount *parent_mnt,
63978 + const int mode);
63979 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63980 + const struct dentry *parent_dentry,
63981 + const struct vfsmount *parent_mnt);
63982 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63983 + const struct vfsmount *mnt);
63984 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63985 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63986 + const struct vfsmount *mnt);
63987 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63988 + const struct dentry *parent_dentry,
63989 + const struct vfsmount *parent_mnt,
63990 + const struct filename *from);
63991 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63992 + const struct dentry *parent_dentry,
63993 + const struct vfsmount *parent_mnt,
63994 + const struct dentry *old_dentry,
63995 + const struct vfsmount *old_mnt, const struct filename *to);
63996 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
63997 +int gr_acl_handle_rename(struct dentry *new_dentry,
63998 + struct dentry *parent_dentry,
63999 + const struct vfsmount *parent_mnt,
64000 + struct dentry *old_dentry,
64001 + struct inode *old_parent_inode,
64002 + struct vfsmount *old_mnt, const struct filename *newname);
64003 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64004 + struct dentry *old_dentry,
64005 + struct dentry *new_dentry,
64006 + struct vfsmount *mnt, const __u8 replace);
64007 +__u32 gr_check_link(const struct dentry *new_dentry,
64008 + const struct dentry *parent_dentry,
64009 + const struct vfsmount *parent_mnt,
64010 + const struct dentry *old_dentry,
64011 + const struct vfsmount *old_mnt);
64012 +int gr_acl_handle_filldir(const struct file *file, const char *name,
64013 + const unsigned int namelen, const ino_t ino);
64014 +
64015 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
64016 + const struct vfsmount *mnt);
64017 +void gr_acl_handle_exit(void);
64018 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
64019 +int gr_acl_handle_procpidmem(const struct task_struct *task);
64020 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64021 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64022 +void gr_audit_ptrace(struct task_struct *task);
64023 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64024 +void gr_put_exec_file(struct task_struct *task);
64025 +
64026 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64027 +
64028 +#ifdef CONFIG_GRKERNSEC
64029 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64030 +void gr_handle_vm86(void);
64031 +void gr_handle_mem_readwrite(u64 from, u64 to);
64032 +
64033 +void gr_log_badprocpid(const char *entry);
64034 +
64035 +extern int grsec_enable_dmesg;
64036 +extern int grsec_disable_privio;
64037 +
64038 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64039 +extern int grsec_proc_gid;
64040 +#endif
64041 +
64042 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64043 +extern int grsec_enable_chroot_findtask;
64044 +#endif
64045 +#ifdef CONFIG_GRKERNSEC_SETXID
64046 +extern int grsec_enable_setxid;
64047 +#endif
64048 +#endif
64049 +
64050 +#endif
64051 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64052 new file mode 100644
64053 index 0000000..e7ffaaf
64054 --- /dev/null
64055 +++ b/include/linux/grsock.h
64056 @@ -0,0 +1,19 @@
64057 +#ifndef __GRSOCK_H
64058 +#define __GRSOCK_H
64059 +
64060 +extern void gr_attach_curr_ip(const struct sock *sk);
64061 +extern int gr_handle_sock_all(const int family, const int type,
64062 + const int protocol);
64063 +extern int gr_handle_sock_server(const struct sockaddr *sck);
64064 +extern int gr_handle_sock_server_other(const struct sock *sck);
64065 +extern int gr_handle_sock_client(const struct sockaddr *sck);
64066 +extern int gr_search_connect(struct socket * sock,
64067 + struct sockaddr_in * addr);
64068 +extern int gr_search_bind(struct socket * sock,
64069 + struct sockaddr_in * addr);
64070 +extern int gr_search_listen(struct socket * sock);
64071 +extern int gr_search_accept(struct socket * sock);
64072 +extern int gr_search_socket(const int domain, const int type,
64073 + const int protocol);
64074 +
64075 +#endif
64076 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64077 index ef788b5..ac41b7b 100644
64078 --- a/include/linux/highmem.h
64079 +++ b/include/linux/highmem.h
64080 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64081 kunmap_atomic(kaddr);
64082 }
64083
64084 +static inline void sanitize_highpage(struct page *page)
64085 +{
64086 + void *kaddr;
64087 + unsigned long flags;
64088 +
64089 + local_irq_save(flags);
64090 + kaddr = kmap_atomic(page);
64091 + clear_page(kaddr);
64092 + kunmap_atomic(kaddr);
64093 + local_irq_restore(flags);
64094 +}
64095 +
64096 static inline void zero_user_segments(struct page *page,
64097 unsigned start1, unsigned end1,
64098 unsigned start2, unsigned end2)
64099 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64100 index 800de22..7a2fa46 100644
64101 --- a/include/linux/i2c.h
64102 +++ b/include/linux/i2c.h
64103 @@ -367,6 +367,7 @@ struct i2c_algorithm {
64104 /* To determine what the adapter supports */
64105 u32 (*functionality) (struct i2c_adapter *);
64106 };
64107 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64108
64109 /*
64110 * i2c_adapter is the structure used to identify a physical i2c bus along
64111 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64112 index d23c3c2..eb63c81 100644
64113 --- a/include/linux/i2o.h
64114 +++ b/include/linux/i2o.h
64115 @@ -565,7 +565,7 @@ struct i2o_controller {
64116 struct i2o_device *exec; /* Executive */
64117 #if BITS_PER_LONG == 64
64118 spinlock_t context_list_lock; /* lock for context_list */
64119 - atomic_t context_list_counter; /* needed for unique contexts */
64120 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64121 struct list_head context_list; /* list of context id's
64122 and pointers */
64123 #endif
64124 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64125 index aff7ad8..3942bbd 100644
64126 --- a/include/linux/if_pppox.h
64127 +++ b/include/linux/if_pppox.h
64128 @@ -76,7 +76,7 @@ struct pppox_proto {
64129 int (*ioctl)(struct socket *sock, unsigned int cmd,
64130 unsigned long arg);
64131 struct module *owner;
64132 -};
64133 +} __do_const;
64134
64135 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64136 extern void unregister_pppox_proto(int proto_num);
64137 diff --git a/include/linux/init.h b/include/linux/init.h
64138 index e59041e..df0a975 100644
64139 --- a/include/linux/init.h
64140 +++ b/include/linux/init.h
64141 @@ -39,9 +39,36 @@
64142 * Also note, that this data cannot be "const".
64143 */
64144
64145 +#ifdef MODULE
64146 +#define add_init_latent_entropy
64147 +#define add_devinit_latent_entropy
64148 +#define add_cpuinit_latent_entropy
64149 +#define add_meminit_latent_entropy
64150 +#else
64151 +#define add_init_latent_entropy __latent_entropy
64152 +
64153 +#ifdef CONFIG_HOTPLUG
64154 +#define add_devinit_latent_entropy
64155 +#else
64156 +#define add_devinit_latent_entropy __latent_entropy
64157 +#endif
64158 +
64159 +#ifdef CONFIG_HOTPLUG_CPU
64160 +#define add_cpuinit_latent_entropy
64161 +#else
64162 +#define add_cpuinit_latent_entropy __latent_entropy
64163 +#endif
64164 +
64165 +#ifdef CONFIG_MEMORY_HOTPLUG
64166 +#define add_meminit_latent_entropy
64167 +#else
64168 +#define add_meminit_latent_entropy __latent_entropy
64169 +#endif
64170 +#endif
64171 +
64172 /* These are for everybody (although not all archs will actually
64173 discard it in modules) */
64174 -#define __init __section(.init.text) __cold notrace
64175 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64176 #define __initdata __section(.init.data)
64177 #define __initconst __constsection(.init.rodata)
64178 #define __exitdata __section(.exit.data)
64179 @@ -94,7 +121,7 @@
64180 #define __exit __section(.exit.text) __exitused __cold notrace
64181
64182 /* Used for HOTPLUG */
64183 -#define __devinit __section(.devinit.text) __cold notrace
64184 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64185 #define __devinitdata __section(.devinit.data)
64186 #define __devinitconst __constsection(.devinit.rodata)
64187 #define __devexit __section(.devexit.text) __exitused __cold notrace
64188 @@ -102,7 +129,7 @@
64189 #define __devexitconst __constsection(.devexit.rodata)
64190
64191 /* Used for HOTPLUG_CPU */
64192 -#define __cpuinit __section(.cpuinit.text) __cold notrace
64193 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64194 #define __cpuinitdata __section(.cpuinit.data)
64195 #define __cpuinitconst __constsection(.cpuinit.rodata)
64196 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64197 @@ -110,7 +137,7 @@
64198 #define __cpuexitconst __constsection(.cpuexit.rodata)
64199
64200 /* Used for MEMORY_HOTPLUG */
64201 -#define __meminit __section(.meminit.text) __cold notrace
64202 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64203 #define __meminitdata __section(.meminit.data)
64204 #define __meminitconst __constsection(.meminit.rodata)
64205 #define __memexit __section(.memexit.text) __exitused __cold notrace
64206 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64207 index 6d087c5..401cab8 100644
64208 --- a/include/linux/init_task.h
64209 +++ b/include/linux/init_task.h
64210 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64211
64212 #define INIT_TASK_COMM "swapper"
64213
64214 +#ifdef CONFIG_X86
64215 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64216 +#else
64217 +#define INIT_TASK_THREAD_INFO
64218 +#endif
64219 +
64220 /*
64221 * INIT_TASK is used to set up the first task table, touch at
64222 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64223 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64224 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64225 .comm = INIT_TASK_COMM, \
64226 .thread = INIT_THREAD, \
64227 + INIT_TASK_THREAD_INFO \
64228 .fs = &init_fs, \
64229 .files = &init_files, \
64230 .signal = &init_signals, \
64231 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64232 index 5e4e617..eee383d 100644
64233 --- a/include/linux/interrupt.h
64234 +++ b/include/linux/interrupt.h
64235 @@ -435,7 +435,7 @@ enum
64236 /* map softirq index to softirq name. update 'softirq_to_name' in
64237 * kernel/softirq.c when adding a new softirq.
64238 */
64239 -extern char *softirq_to_name[NR_SOFTIRQS];
64240 +extern const char * const softirq_to_name[NR_SOFTIRQS];
64241
64242 /* softirq mask and active fields moved to irq_cpustat_t in
64243 * asm/hardirq.h to get better cache usage. KAO
64244 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
64245
64246 struct softirq_action
64247 {
64248 - void (*action)(struct softirq_action *);
64249 + void (*action)(void);
64250 };
64251
64252 asmlinkage void do_softirq(void);
64253 asmlinkage void __do_softirq(void);
64254 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
64255 +extern void open_softirq(int nr, void (*action)(void));
64256 extern void softirq_init(void);
64257 extern void __raise_softirq_irqoff(unsigned int nr);
64258
64259 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
64260 index 6883e19..06992b1 100644
64261 --- a/include/linux/kallsyms.h
64262 +++ b/include/linux/kallsyms.h
64263 @@ -15,7 +15,8 @@
64264
64265 struct module;
64266
64267 -#ifdef CONFIG_KALLSYMS
64268 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
64269 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64270 /* Lookup the address for a symbol. Returns 0 if not found. */
64271 unsigned long kallsyms_lookup_name(const char *name);
64272
64273 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
64274 /* Stupid that this does nothing, but I didn't create this mess. */
64275 #define __print_symbol(fmt, addr)
64276 #endif /*CONFIG_KALLSYMS*/
64277 +#else /* when included by kallsyms.c, vsnprintf.c, or
64278 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
64279 +extern void __print_symbol(const char *fmt, unsigned long address);
64280 +extern int sprint_backtrace(char *buffer, unsigned long address);
64281 +extern int sprint_symbol(char *buffer, unsigned long address);
64282 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
64283 +const char *kallsyms_lookup(unsigned long addr,
64284 + unsigned long *symbolsize,
64285 + unsigned long *offset,
64286 + char **modname, char *namebuf);
64287 +#endif
64288
64289 /* This macro allows us to keep printk typechecking */
64290 static __printf(1, 2)
64291 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
64292 index 4dff0c6..1ca9b72 100644
64293 --- a/include/linux/kgdb.h
64294 +++ b/include/linux/kgdb.h
64295 @@ -53,7 +53,7 @@ extern int kgdb_connected;
64296 extern int kgdb_io_module_registered;
64297
64298 extern atomic_t kgdb_setting_breakpoint;
64299 -extern atomic_t kgdb_cpu_doing_single_step;
64300 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
64301
64302 extern struct task_struct *kgdb_usethread;
64303 extern struct task_struct *kgdb_contthread;
64304 @@ -255,7 +255,7 @@ struct kgdb_arch {
64305 void (*correct_hw_break)(void);
64306
64307 void (*enable_nmi)(bool on);
64308 -};
64309 +} __do_const;
64310
64311 /**
64312 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
64313 @@ -280,7 +280,7 @@ struct kgdb_io {
64314 void (*pre_exception) (void);
64315 void (*post_exception) (void);
64316 int is_console;
64317 -};
64318 +} __do_const;
64319
64320 extern struct kgdb_arch arch_kgdb_ops;
64321
64322 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
64323 index 5398d58..5883a34 100644
64324 --- a/include/linux/kmod.h
64325 +++ b/include/linux/kmod.h
64326 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
64327 * usually useless though. */
64328 extern __printf(2, 3)
64329 int __request_module(bool wait, const char *name, ...);
64330 +extern __printf(3, 4)
64331 +int ___request_module(bool wait, char *param_name, const char *name, ...);
64332 #define request_module(mod...) __request_module(true, mod)
64333 #define request_module_nowait(mod...) __request_module(false, mod)
64334 #define try_then_request_module(x, mod...) \
64335 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
64336 index 1e57449..4fede7b 100644
64337 --- a/include/linux/kobject.h
64338 +++ b/include/linux/kobject.h
64339 @@ -111,7 +111,7 @@ struct kobj_type {
64340 struct attribute **default_attrs;
64341 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
64342 const void *(*namespace)(struct kobject *kobj);
64343 -};
64344 +} __do_const;
64345
64346 struct kobj_uevent_env {
64347 char *envp[UEVENT_NUM_ENVP];
64348 diff --git a/include/linux/kref.h b/include/linux/kref.h
64349 index 65af688..0592677 100644
64350 --- a/include/linux/kref.h
64351 +++ b/include/linux/kref.h
64352 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
64353 static inline int kref_sub(struct kref *kref, unsigned int count,
64354 void (*release)(struct kref *kref))
64355 {
64356 - WARN_ON(release == NULL);
64357 + BUG_ON(release == NULL);
64358
64359 if (atomic_sub_and_test((int) count, &kref->refcount)) {
64360 release(kref);
64361 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
64362 index ecc5543..0e96bcc 100644
64363 --- a/include/linux/kvm_host.h
64364 +++ b/include/linux/kvm_host.h
64365 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
64366 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
64367 void vcpu_put(struct kvm_vcpu *vcpu);
64368
64369 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64370 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64371 struct module *module);
64372 void kvm_exit(void);
64373
64374 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
64375 struct kvm_guest_debug *dbg);
64376 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
64377
64378 -int kvm_arch_init(void *opaque);
64379 +int kvm_arch_init(const void *opaque);
64380 void kvm_arch_exit(void);
64381
64382 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
64383 diff --git a/include/linux/libata.h b/include/linux/libata.h
64384 index e931c9a..7aa8f6f 100644
64385 --- a/include/linux/libata.h
64386 +++ b/include/linux/libata.h
64387 @@ -915,7 +915,7 @@ struct ata_port_operations {
64388 * fields must be pointers.
64389 */
64390 const struct ata_port_operations *inherits;
64391 -};
64392 +} __do_const;
64393
64394 struct ata_port_info {
64395 unsigned long flags;
64396 diff --git a/include/linux/list.h b/include/linux/list.h
64397 index cc6d2aa..71febca 100644
64398 --- a/include/linux/list.h
64399 +++ b/include/linux/list.h
64400 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
64401 extern void list_del(struct list_head *entry);
64402 #endif
64403
64404 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
64405 +extern void pax_list_del(struct list_head *entry);
64406 +
64407 /**
64408 * list_replace - replace old entry by new one
64409 * @old : the element to be replaced
64410 diff --git a/include/linux/mm.h b/include/linux/mm.h
64411 index 280dae5..39046ec 100644
64412 --- a/include/linux/mm.h
64413 +++ b/include/linux/mm.h
64414 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
64415 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
64416 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
64417 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
64418 +
64419 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64420 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
64421 +#endif
64422 +
64423 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
64424
64425 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
64426 @@ -1039,34 +1044,6 @@ int set_page_dirty(struct page *page);
64427 int set_page_dirty_lock(struct page *page);
64428 int clear_page_dirty_for_io(struct page *page);
64429
64430 -/* Is the vma a continuation of the stack vma above it? */
64431 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
64432 -{
64433 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
64434 -}
64435 -
64436 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
64437 - unsigned long addr)
64438 -{
64439 - return (vma->vm_flags & VM_GROWSDOWN) &&
64440 - (vma->vm_start == addr) &&
64441 - !vma_growsdown(vma->vm_prev, addr);
64442 -}
64443 -
64444 -/* Is the vma a continuation of the stack vma below it? */
64445 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
64446 -{
64447 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
64448 -}
64449 -
64450 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
64451 - unsigned long addr)
64452 -{
64453 - return (vma->vm_flags & VM_GROWSUP) &&
64454 - (vma->vm_end == addr) &&
64455 - !vma_growsup(vma->vm_next, addr);
64456 -}
64457 -
64458 extern pid_t
64459 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
64460
64461 @@ -1166,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
64462 }
64463 #endif
64464
64465 +#ifdef CONFIG_MMU
64466 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
64467 +#else
64468 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
64469 +{
64470 + return __pgprot(0);
64471 +}
64472 +#endif
64473 +
64474 int vma_wants_writenotify(struct vm_area_struct *vma);
64475
64476 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
64477 @@ -1184,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
64478 {
64479 return 0;
64480 }
64481 +
64482 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
64483 + unsigned long address)
64484 +{
64485 + return 0;
64486 +}
64487 #else
64488 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64489 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64490 #endif
64491
64492 #ifdef __PAGETABLE_PMD_FOLDED
64493 @@ -1194,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
64494 {
64495 return 0;
64496 }
64497 +
64498 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
64499 + unsigned long address)
64500 +{
64501 + return 0;
64502 +}
64503 #else
64504 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
64505 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
64506 #endif
64507
64508 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
64509 @@ -1213,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
64510 NULL: pud_offset(pgd, address);
64511 }
64512
64513 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
64514 +{
64515 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
64516 + NULL: pud_offset(pgd, address);
64517 +}
64518 +
64519 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
64520 {
64521 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
64522 NULL: pmd_offset(pud, address);
64523 }
64524 +
64525 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
64526 +{
64527 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
64528 + NULL: pmd_offset(pud, address);
64529 +}
64530 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
64531
64532 #if USE_SPLIT_PTLOCKS
64533 @@ -1447,6 +1459,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
64534 unsigned long, unsigned long,
64535 unsigned long, unsigned long);
64536 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
64537 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
64538
64539 /* These take the mm semaphore themselves */
64540 extern unsigned long vm_brk(unsigned long, unsigned long);
64541 @@ -1510,6 +1523,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
64542 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
64543 struct vm_area_struct **pprev);
64544
64545 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
64546 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
64547 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
64548 +
64549 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
64550 NULL if none. Assume start_addr < end_addr. */
64551 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
64552 @@ -1538,15 +1555,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
64553 return vma;
64554 }
64555
64556 -#ifdef CONFIG_MMU
64557 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
64558 -#else
64559 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
64560 -{
64561 - return __pgprot(0);
64562 -}
64563 -#endif
64564 -
64565 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
64566 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
64567 unsigned long pfn, unsigned long size, pgprot_t);
64568 @@ -1652,7 +1660,7 @@ extern int unpoison_memory(unsigned long pfn);
64569 extern int sysctl_memory_failure_early_kill;
64570 extern int sysctl_memory_failure_recovery;
64571 extern void shake_page(struct page *p, int access);
64572 -extern atomic_long_t mce_bad_pages;
64573 +extern atomic_long_unchecked_t mce_bad_pages;
64574 extern int soft_offline_page(struct page *page, int flags);
64575
64576 extern void dump_page(struct page *page);
64577 @@ -1683,5 +1691,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
64578 static inline bool page_is_guard(struct page *page) { return false; }
64579 #endif /* CONFIG_DEBUG_PAGEALLOC */
64580
64581 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64582 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
64583 +#else
64584 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
64585 +#endif
64586 +
64587 #endif /* __KERNEL__ */
64588 #endif /* _LINUX_MM_H */
64589 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
64590 index 31f8a3a..499f1db 100644
64591 --- a/include/linux/mm_types.h
64592 +++ b/include/linux/mm_types.h
64593 @@ -275,6 +275,8 @@ struct vm_area_struct {
64594 #ifdef CONFIG_NUMA
64595 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
64596 #endif
64597 +
64598 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
64599 };
64600
64601 struct core_thread {
64602 @@ -348,7 +350,7 @@ struct mm_struct {
64603 unsigned long def_flags;
64604 unsigned long nr_ptes; /* Page table pages */
64605 unsigned long start_code, end_code, start_data, end_data;
64606 - unsigned long start_brk, brk, start_stack;
64607 + unsigned long brk_gap, start_brk, brk, start_stack;
64608 unsigned long arg_start, arg_end, env_start, env_end;
64609
64610 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
64611 @@ -399,6 +401,24 @@ struct mm_struct {
64612 struct cpumask cpumask_allocation;
64613 #endif
64614 struct uprobes_state uprobes_state;
64615 +
64616 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64617 + unsigned long pax_flags;
64618 +#endif
64619 +
64620 +#ifdef CONFIG_PAX_DLRESOLVE
64621 + unsigned long call_dl_resolve;
64622 +#endif
64623 +
64624 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
64625 + unsigned long call_syscall;
64626 +#endif
64627 +
64628 +#ifdef CONFIG_PAX_ASLR
64629 + unsigned long delta_mmap; /* randomized offset */
64630 + unsigned long delta_stack; /* randomized offset */
64631 +#endif
64632 +
64633 };
64634
64635 static inline void mm_init_cpumask(struct mm_struct *mm)
64636 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
64637 index c5d5278..f0b68c8 100644
64638 --- a/include/linux/mmiotrace.h
64639 +++ b/include/linux/mmiotrace.h
64640 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
64641 /* Called from ioremap.c */
64642 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
64643 void __iomem *addr);
64644 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
64645 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
64646
64647 /* For anyone to insert markers. Remember trailing newline. */
64648 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
64649 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
64650 {
64651 }
64652
64653 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
64654 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
64655 {
64656 }
64657
64658 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
64659 index a23923b..073fee4 100644
64660 --- a/include/linux/mmzone.h
64661 +++ b/include/linux/mmzone.h
64662 @@ -421,7 +421,7 @@ struct zone {
64663 unsigned long flags; /* zone flags, see below */
64664
64665 /* Zone statistics */
64666 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64667 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64668
64669 /*
64670 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
64671 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
64672 index fed3def..7cc3f93 100644
64673 --- a/include/linux/mod_devicetable.h
64674 +++ b/include/linux/mod_devicetable.h
64675 @@ -12,7 +12,7 @@
64676 typedef unsigned long kernel_ulong_t;
64677 #endif
64678
64679 -#define PCI_ANY_ID (~0)
64680 +#define PCI_ANY_ID ((__u16)~0)
64681
64682 struct pci_device_id {
64683 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
64684 @@ -139,7 +139,7 @@ struct usb_device_id {
64685 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
64686 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
64687
64688 -#define HID_ANY_ID (~0)
64689 +#define HID_ANY_ID (~0U)
64690 #define HID_BUS_ANY 0xffff
64691 #define HID_GROUP_ANY 0x0000
64692
64693 diff --git a/include/linux/module.h b/include/linux/module.h
64694 index 7760c6d..983ee18 100644
64695 --- a/include/linux/module.h
64696 +++ b/include/linux/module.h
64697 @@ -17,9 +17,11 @@
64698 #include <linux/moduleparam.h>
64699 #include <linux/tracepoint.h>
64700 #include <linux/export.h>
64701 +#include <linux/fs.h>
64702
64703 #include <linux/percpu.h>
64704 #include <asm/module.h>
64705 +#include <asm/pgtable.h>
64706
64707 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
64708 #define MODULE_SIG_STRING "~Module signature appended~\n"
64709 @@ -281,19 +283,16 @@ struct module
64710 int (*init)(void);
64711
64712 /* If this is non-NULL, vfree after init() returns */
64713 - void *module_init;
64714 + void *module_init_rx, *module_init_rw;
64715
64716 /* Here is the actual code + data, vfree'd on unload. */
64717 - void *module_core;
64718 + void *module_core_rx, *module_core_rw;
64719
64720 /* Here are the sizes of the init and core sections */
64721 - unsigned int init_size, core_size;
64722 + unsigned int init_size_rw, core_size_rw;
64723
64724 /* The size of the executable code in each section. */
64725 - unsigned int init_text_size, core_text_size;
64726 -
64727 - /* Size of RO sections of the module (text+rodata) */
64728 - unsigned int init_ro_size, core_ro_size;
64729 + unsigned int init_size_rx, core_size_rx;
64730
64731 /* Arch-specific module values */
64732 struct mod_arch_specific arch;
64733 @@ -349,6 +348,10 @@ struct module
64734 #ifdef CONFIG_EVENT_TRACING
64735 struct ftrace_event_call **trace_events;
64736 unsigned int num_trace_events;
64737 + struct file_operations trace_id;
64738 + struct file_operations trace_enable;
64739 + struct file_operations trace_format;
64740 + struct file_operations trace_filter;
64741 #endif
64742 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
64743 unsigned int num_ftrace_callsites;
64744 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
64745 bool is_module_percpu_address(unsigned long addr);
64746 bool is_module_text_address(unsigned long addr);
64747
64748 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
64749 +{
64750 +
64751 +#ifdef CONFIG_PAX_KERNEXEC
64752 + if (ktla_ktva(addr) >= (unsigned long)start &&
64753 + ktla_ktva(addr) < (unsigned long)start + size)
64754 + return 1;
64755 +#endif
64756 +
64757 + return ((void *)addr >= start && (void *)addr < start + size);
64758 +}
64759 +
64760 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
64761 +{
64762 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
64763 +}
64764 +
64765 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
64766 +{
64767 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
64768 +}
64769 +
64770 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
64771 +{
64772 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
64773 +}
64774 +
64775 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
64776 +{
64777 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
64778 +}
64779 +
64780 static inline int within_module_core(unsigned long addr, struct module *mod)
64781 {
64782 - return (unsigned long)mod->module_core <= addr &&
64783 - addr < (unsigned long)mod->module_core + mod->core_size;
64784 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
64785 }
64786
64787 static inline int within_module_init(unsigned long addr, struct module *mod)
64788 {
64789 - return (unsigned long)mod->module_init <= addr &&
64790 - addr < (unsigned long)mod->module_init + mod->init_size;
64791 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
64792 }
64793
64794 /* Search for module by name: must hold module_mutex. */
64795 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
64796 index 560ca53..5ee8d73 100644
64797 --- a/include/linux/moduleloader.h
64798 +++ b/include/linux/moduleloader.h
64799 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
64800
64801 /* Allocator used for allocating struct module, core sections and init
64802 sections. Returns NULL on failure. */
64803 -void *module_alloc(unsigned long size);
64804 +void *module_alloc(unsigned long size) __size_overflow(1);
64805 +
64806 +#ifdef CONFIG_PAX_KERNEXEC
64807 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
64808 +#else
64809 +#define module_alloc_exec(x) module_alloc(x)
64810 +#endif
64811
64812 /* Free memory returned from module_alloc. */
64813 void module_free(struct module *mod, void *module_region);
64814
64815 +#ifdef CONFIG_PAX_KERNEXEC
64816 +void module_free_exec(struct module *mod, void *module_region);
64817 +#else
64818 +#define module_free_exec(x, y) module_free((x), (y))
64819 +#endif
64820 +
64821 /*
64822 * Apply the given relocation to the (simplified) ELF. Return -error
64823 * or 0.
64824 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
64825 unsigned int relsec,
64826 struct module *me)
64827 {
64828 +#ifdef CONFIG_MODULES
64829 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
64830 +#endif
64831 return -ENOEXEC;
64832 }
64833 #endif
64834 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
64835 unsigned int relsec,
64836 struct module *me)
64837 {
64838 +#ifdef CONFIG_MODULES
64839 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
64840 +#endif
64841 return -ENOEXEC;
64842 }
64843 #endif
64844 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
64845 index d6a5806..7c13347 100644
64846 --- a/include/linux/moduleparam.h
64847 +++ b/include/linux/moduleparam.h
64848 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
64849 * @len is usually just sizeof(string).
64850 */
64851 #define module_param_string(name, string, len, perm) \
64852 - static const struct kparam_string __param_string_##name \
64853 + static const struct kparam_string __param_string_##name __used \
64854 = { len, string }; \
64855 __module_param_call(MODULE_PARAM_PREFIX, name, \
64856 &param_ops_string, \
64857 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
64858 */
64859 #define module_param_array_named(name, array, type, nump, perm) \
64860 param_check_##type(name, &(array)[0]); \
64861 - static const struct kparam_array __param_arr_##name \
64862 + static const struct kparam_array __param_arr_##name __used \
64863 = { .max = ARRAY_SIZE(array), .num = nump, \
64864 .ops = &param_ops_##type, \
64865 .elemsize = sizeof(array[0]), .elem = array }; \
64866 diff --git a/include/linux/namei.h b/include/linux/namei.h
64867 index 4bf19d8..5268cea 100644
64868 --- a/include/linux/namei.h
64869 +++ b/include/linux/namei.h
64870 @@ -18,7 +18,7 @@ struct nameidata {
64871 unsigned seq;
64872 int last_type;
64873 unsigned depth;
64874 - char *saved_names[MAX_NESTED_LINKS + 1];
64875 + const char *saved_names[MAX_NESTED_LINKS + 1];
64876 };
64877
64878 /*
64879 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
64880
64881 extern void nd_jump_link(struct nameidata *nd, struct path *path);
64882
64883 -static inline void nd_set_link(struct nameidata *nd, char *path)
64884 +static inline void nd_set_link(struct nameidata *nd, const char *path)
64885 {
64886 nd->saved_names[nd->depth] = path;
64887 }
64888
64889 -static inline char *nd_get_link(struct nameidata *nd)
64890 +static inline const char *nd_get_link(const struct nameidata *nd)
64891 {
64892 return nd->saved_names[nd->depth];
64893 }
64894 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
64895 index a848ffc..3bbbaee 100644
64896 --- a/include/linux/netdevice.h
64897 +++ b/include/linux/netdevice.h
64898 @@ -999,6 +999,7 @@ struct net_device_ops {
64899 struct net_device *dev,
64900 int idx);
64901 };
64902 +typedef struct net_device_ops __no_const net_device_ops_no_const;
64903
64904 /*
64905 * The DEVICE structure.
64906 @@ -1059,7 +1060,7 @@ struct net_device {
64907 int iflink;
64908
64909 struct net_device_stats stats;
64910 - atomic_long_t rx_dropped; /* dropped packets by core network
64911 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
64912 * Do not use this in drivers.
64913 */
64914
64915 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
64916 index 7958e84..ed74d7a 100644
64917 --- a/include/linux/netfilter/ipset/ip_set.h
64918 +++ b/include/linux/netfilter/ipset/ip_set.h
64919 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
64920 /* Return true if "b" set is the same as "a"
64921 * according to the create set parameters */
64922 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
64923 -};
64924 +} __do_const;
64925
64926 /* The core set type structure */
64927 struct ip_set_type {
64928 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
64929 index 4966dde..7d8ce06 100644
64930 --- a/include/linux/netfilter/nfnetlink.h
64931 +++ b/include/linux/netfilter/nfnetlink.h
64932 @@ -16,7 +16,7 @@ struct nfnl_callback {
64933 const struct nlattr * const cda[]);
64934 const struct nla_policy *policy; /* netlink attribute policy */
64935 const u_int16_t attr_count; /* number of nlattr's */
64936 -};
64937 +} __do_const;
64938
64939 struct nfnetlink_subsystem {
64940 const char *name;
64941 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
64942 new file mode 100644
64943 index 0000000..33f4af8
64944 --- /dev/null
64945 +++ b/include/linux/netfilter/xt_gradm.h
64946 @@ -0,0 +1,9 @@
64947 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
64948 +#define _LINUX_NETFILTER_XT_GRADM_H 1
64949 +
64950 +struct xt_gradm_mtinfo {
64951 + __u16 flags;
64952 + __u16 invflags;
64953 +};
64954 +
64955 +#endif
64956 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
64957 index d65746e..62e72c2 100644
64958 --- a/include/linux/notifier.h
64959 +++ b/include/linux/notifier.h
64960 @@ -51,7 +51,8 @@ struct notifier_block {
64961 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
64962 struct notifier_block __rcu *next;
64963 int priority;
64964 -};
64965 +} __do_const;
64966 +typedef struct notifier_block __no_const notifier_block_no_const;
64967
64968 struct atomic_notifier_head {
64969 spinlock_t lock;
64970 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
64971 index a4c5624..79d6d88 100644
64972 --- a/include/linux/oprofile.h
64973 +++ b/include/linux/oprofile.h
64974 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
64975 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64976 char const * name, ulong * val);
64977
64978 -/** Create a file for read-only access to an atomic_t. */
64979 +/** Create a file for read-only access to an atomic_unchecked_t. */
64980 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64981 - char const * name, atomic_t * val);
64982 + char const * name, atomic_unchecked_t * val);
64983
64984 /** create a directory */
64985 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64986 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
64987 index 6bfb2faa..1204767 100644
64988 --- a/include/linux/perf_event.h
64989 +++ b/include/linux/perf_event.h
64990 @@ -328,8 +328,8 @@ struct perf_event {
64991
64992 enum perf_event_active_state state;
64993 unsigned int attach_state;
64994 - local64_t count;
64995 - atomic64_t child_count;
64996 + local64_t count; /* PaX: fix it one day */
64997 + atomic64_unchecked_t child_count;
64998
64999 /*
65000 * These are the total time in nanoseconds that the event
65001 @@ -380,8 +380,8 @@ struct perf_event {
65002 * These accumulate total time (in nanoseconds) that children
65003 * events have been enabled and running, respectively.
65004 */
65005 - atomic64_t child_total_time_enabled;
65006 - atomic64_t child_total_time_running;
65007 + atomic64_unchecked_t child_total_time_enabled;
65008 + atomic64_unchecked_t child_total_time_running;
65009
65010 /*
65011 * Protect attach/detach and child_list:
65012 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65013 index ad1a427..6419649 100644
65014 --- a/include/linux/pipe_fs_i.h
65015 +++ b/include/linux/pipe_fs_i.h
65016 @@ -45,9 +45,9 @@ struct pipe_buffer {
65017 struct pipe_inode_info {
65018 wait_queue_head_t wait;
65019 unsigned int nrbufs, curbuf, buffers;
65020 - unsigned int readers;
65021 - unsigned int writers;
65022 - unsigned int waiting_writers;
65023 + atomic_t readers;
65024 + atomic_t writers;
65025 + atomic_t waiting_writers;
65026 unsigned int r_counter;
65027 unsigned int w_counter;
65028 struct page *tmp_page;
65029 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65030 index 5f28cae..3d23723 100644
65031 --- a/include/linux/platform_data/usb-ehci-s5p.h
65032 +++ b/include/linux/platform_data/usb-ehci-s5p.h
65033 @@ -14,7 +14,7 @@
65034 struct s5p_ehci_platdata {
65035 int (*phy_init)(struct platform_device *pdev, int type);
65036 int (*phy_exit)(struct platform_device *pdev, int type);
65037 -};
65038 +} __no_const;
65039
65040 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65041
65042 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65043 index f271860..6b3bec5 100644
65044 --- a/include/linux/pm_runtime.h
65045 +++ b/include/linux/pm_runtime.h
65046 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65047
65048 static inline void pm_runtime_mark_last_busy(struct device *dev)
65049 {
65050 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
65051 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65052 }
65053
65054 #else /* !CONFIG_PM_RUNTIME */
65055 diff --git a/include/linux/poison.h b/include/linux/poison.h
65056 index 2110a81..13a11bb 100644
65057 --- a/include/linux/poison.h
65058 +++ b/include/linux/poison.h
65059 @@ -19,8 +19,8 @@
65060 * under normal circumstances, used to verify that nobody uses
65061 * non-initialized list entries.
65062 */
65063 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65064 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65065 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65066 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65067
65068 /********** include/linux/timer.h **********/
65069 /*
65070 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65071 index 4a496eb..d9c5659 100644
65072 --- a/include/linux/power/smartreflex.h
65073 +++ b/include/linux/power/smartreflex.h
65074 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
65075 int (*notify)(struct omap_sr *sr, u32 status);
65076 u8 notify_flags;
65077 u8 class_type;
65078 -};
65079 +} __do_const;
65080
65081 /**
65082 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65083 diff --git a/include/linux/printk.h b/include/linux/printk.h
65084 index 9afc01e..92c32e8 100644
65085 --- a/include/linux/printk.h
65086 +++ b/include/linux/printk.h
65087 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65088 extern int printk_needs_cpu(int cpu);
65089 extern void printk_tick(void);
65090
65091 +extern int kptr_restrict;
65092 +
65093 #ifdef CONFIG_PRINTK
65094 asmlinkage __printf(5, 0)
65095 int vprintk_emit(int facility, int level,
65096 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65097
65098 extern int printk_delay_msec;
65099 extern int dmesg_restrict;
65100 -extern int kptr_restrict;
65101
65102 void log_buf_kexec_setup(void);
65103 void __init setup_log_buf(int early);
65104 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65105 index 3fd2e87..75db910 100644
65106 --- a/include/linux/proc_fs.h
65107 +++ b/include/linux/proc_fs.h
65108 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65109 return proc_create_data(name, mode, parent, proc_fops, NULL);
65110 }
65111
65112 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65113 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65114 +{
65115 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65116 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65117 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65118 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65119 +#else
65120 + return proc_create_data(name, mode, parent, proc_fops, NULL);
65121 +#endif
65122 +}
65123 +
65124 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65125 umode_t mode, struct proc_dir_entry *base,
65126 read_proc_t *read_proc, void * data)
65127 diff --git a/include/linux/random.h b/include/linux/random.h
65128 index 6330ed4..419c6c3 100644
65129 --- a/include/linux/random.h
65130 +++ b/include/linux/random.h
65131 @@ -30,12 +30,17 @@ void srandom32(u32 seed);
65132
65133 u32 prandom32(struct rnd_state *);
65134
65135 +static inline unsigned long pax_get_random_long(void)
65136 +{
65137 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65138 +}
65139 +
65140 /*
65141 * Handle minimum values for seeds
65142 */
65143 static inline u32 __seed(u32 x, u32 m)
65144 {
65145 - return (x < m) ? x + m : x;
65146 + return (x <= m) ? x + m + 1 : x;
65147 }
65148
65149 /**
65150 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65151 index 23b3630..e1bc12b 100644
65152 --- a/include/linux/reboot.h
65153 +++ b/include/linux/reboot.h
65154 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65155 * Architecture-specific implementations of sys_reboot commands.
65156 */
65157
65158 -extern void machine_restart(char *cmd);
65159 -extern void machine_halt(void);
65160 -extern void machine_power_off(void);
65161 +extern void machine_restart(char *cmd) __noreturn;
65162 +extern void machine_halt(void) __noreturn;
65163 +extern void machine_power_off(void) __noreturn;
65164
65165 extern void machine_shutdown(void);
65166 struct pt_regs;
65167 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65168 */
65169
65170 extern void kernel_restart_prepare(char *cmd);
65171 -extern void kernel_restart(char *cmd);
65172 -extern void kernel_halt(void);
65173 -extern void kernel_power_off(void);
65174 +extern void kernel_restart(char *cmd) __noreturn;
65175 +extern void kernel_halt(void) __noreturn;
65176 +extern void kernel_power_off(void) __noreturn;
65177
65178 extern int C_A_D; /* for sysctl */
65179 void ctrl_alt_del(void);
65180 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65181 * Emergency restart, callable from an interrupt handler.
65182 */
65183
65184 -extern void emergency_restart(void);
65185 +extern void emergency_restart(void) __noreturn;
65186 #include <asm/emergency-restart.h>
65187
65188 #endif /* _LINUX_REBOOT_H */
65189 diff --git a/include/linux/regset.h b/include/linux/regset.h
65190 index 8e0c9fe..fdb64bc 100644
65191 --- a/include/linux/regset.h
65192 +++ b/include/linux/regset.h
65193 @@ -161,7 +161,7 @@ struct user_regset {
65194 unsigned int align;
65195 unsigned int bias;
65196 unsigned int core_note_type;
65197 -};
65198 +} __do_const;
65199
65200 /**
65201 * struct user_regset_view - available regsets
65202 diff --git a/include/linux/relay.h b/include/linux/relay.h
65203 index 91cacc3..b55ff74 100644
65204 --- a/include/linux/relay.h
65205 +++ b/include/linux/relay.h
65206 @@ -160,7 +160,7 @@ struct rchan_callbacks
65207 * The callback should return 0 if successful, negative if not.
65208 */
65209 int (*remove_buf_file)(struct dentry *dentry);
65210 -};
65211 +} __no_const;
65212
65213 /*
65214 * CONFIG_RELAY kernel API, kernel/relay.c
65215 diff --git a/include/linux/rio.h b/include/linux/rio.h
65216 index a3e7842..d973ca6 100644
65217 --- a/include/linux/rio.h
65218 +++ b/include/linux/rio.h
65219 @@ -339,7 +339,7 @@ struct rio_ops {
65220 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65221 u64 rstart, u32 size, u32 flags);
65222 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65223 -};
65224 +} __no_const;
65225
65226 #define RIO_RESOURCE_MEM 0x00000100
65227 #define RIO_RESOURCE_DOORBELL 0x00000200
65228 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65229 index bfe1f47..6a33ee3 100644
65230 --- a/include/linux/rmap.h
65231 +++ b/include/linux/rmap.h
65232 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65233 void anon_vma_init(void); /* create anon_vma_cachep */
65234 int anon_vma_prepare(struct vm_area_struct *);
65235 void unlink_anon_vmas(struct vm_area_struct *);
65236 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
65237 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
65238 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
65239 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
65240
65241 static inline void anon_vma_merge(struct vm_area_struct *vma,
65242 struct vm_area_struct *next)
65243 diff --git a/include/linux/sched.h b/include/linux/sched.h
65244 index 0dd42a0..cc9bffb 100644
65245 --- a/include/linux/sched.h
65246 +++ b/include/linux/sched.h
65247 @@ -61,6 +61,7 @@ struct bio_list;
65248 struct fs_struct;
65249 struct perf_event_context;
65250 struct blk_plug;
65251 +struct linux_binprm;
65252
65253 /*
65254 * List of flags we want to share for kernel threads,
65255 @@ -344,10 +345,13 @@ struct user_namespace;
65256 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
65257
65258 extern int sysctl_max_map_count;
65259 +extern unsigned long sysctl_heap_stack_gap;
65260
65261 #include <linux/aio.h>
65262
65263 #ifdef CONFIG_MMU
65264 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
65265 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
65266 extern void arch_pick_mmap_layout(struct mm_struct *mm);
65267 extern unsigned long
65268 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
65269 @@ -614,6 +618,17 @@ struct signal_struct {
65270 #ifdef CONFIG_TASKSTATS
65271 struct taskstats *stats;
65272 #endif
65273 +
65274 +#ifdef CONFIG_GRKERNSEC
65275 + u32 curr_ip;
65276 + u32 saved_ip;
65277 + u32 gr_saddr;
65278 + u32 gr_daddr;
65279 + u16 gr_sport;
65280 + u16 gr_dport;
65281 + u8 used_accept:1;
65282 +#endif
65283 +
65284 #ifdef CONFIG_AUDIT
65285 unsigned audit_tty;
65286 struct tty_audit_buf *tty_audit_buf;
65287 @@ -691,6 +706,11 @@ struct user_struct {
65288 struct key *session_keyring; /* UID's default session keyring */
65289 #endif
65290
65291 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65292 + unsigned int banned;
65293 + unsigned long ban_expires;
65294 +#endif
65295 +
65296 /* Hash table maintenance information */
65297 struct hlist_node uidhash_node;
65298 kuid_t uid;
65299 @@ -1312,8 +1332,8 @@ struct task_struct {
65300 struct list_head thread_group;
65301
65302 struct completion *vfork_done; /* for vfork() */
65303 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
65304 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65305 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
65306 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65307
65308 cputime_t utime, stime, utimescaled, stimescaled;
65309 cputime_t gtime;
65310 @@ -1329,11 +1349,6 @@ struct task_struct {
65311 struct task_cputime cputime_expires;
65312 struct list_head cpu_timers[3];
65313
65314 -/* process credentials */
65315 - const struct cred __rcu *real_cred; /* objective and real subjective task
65316 - * credentials (COW) */
65317 - const struct cred __rcu *cred; /* effective (overridable) subjective task
65318 - * credentials (COW) */
65319 char comm[TASK_COMM_LEN]; /* executable name excluding path
65320 - access with [gs]et_task_comm (which lock
65321 it with task_lock())
65322 @@ -1350,6 +1365,10 @@ struct task_struct {
65323 #endif
65324 /* CPU-specific state of this task */
65325 struct thread_struct thread;
65326 +/* thread_info moved to task_struct */
65327 +#ifdef CONFIG_X86
65328 + struct thread_info tinfo;
65329 +#endif
65330 /* filesystem information */
65331 struct fs_struct *fs;
65332 /* open file information */
65333 @@ -1423,6 +1442,10 @@ struct task_struct {
65334 gfp_t lockdep_reclaim_gfp;
65335 #endif
65336
65337 +/* process credentials */
65338 + const struct cred __rcu *real_cred; /* objective and real subjective task
65339 + * credentials (COW) */
65340 +
65341 /* journalling filesystem info */
65342 void *journal_info;
65343
65344 @@ -1461,6 +1484,10 @@ struct task_struct {
65345 /* cg_list protected by css_set_lock and tsk->alloc_lock */
65346 struct list_head cg_list;
65347 #endif
65348 +
65349 + const struct cred __rcu *cred; /* effective (overridable) subjective task
65350 + * credentials (COW) */
65351 +
65352 #ifdef CONFIG_FUTEX
65353 struct robust_list_head __user *robust_list;
65354 #ifdef CONFIG_COMPAT
65355 @@ -1548,8 +1575,75 @@ struct task_struct {
65356 #ifdef CONFIG_UPROBES
65357 struct uprobe_task *utask;
65358 #endif
65359 +
65360 +#ifdef CONFIG_GRKERNSEC
65361 + /* grsecurity */
65362 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65363 + u64 exec_id;
65364 +#endif
65365 +#ifdef CONFIG_GRKERNSEC_SETXID
65366 + const struct cred *delayed_cred;
65367 +#endif
65368 + struct dentry *gr_chroot_dentry;
65369 + struct acl_subject_label *acl;
65370 + struct acl_role_label *role;
65371 + struct file *exec_file;
65372 + unsigned long brute_expires;
65373 + u16 acl_role_id;
65374 + /* is this the task that authenticated to the special role */
65375 + u8 acl_sp_role;
65376 + u8 is_writable;
65377 + u8 brute;
65378 + u8 gr_is_chrooted;
65379 +#endif
65380 +
65381 };
65382
65383 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
65384 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
65385 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
65386 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
65387 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
65388 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
65389 +
65390 +#ifdef CONFIG_PAX_SOFTMODE
65391 +extern int pax_softmode;
65392 +#endif
65393 +
65394 +extern int pax_check_flags(unsigned long *);
65395 +
65396 +/* if tsk != current then task_lock must be held on it */
65397 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65398 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
65399 +{
65400 + if (likely(tsk->mm))
65401 + return tsk->mm->pax_flags;
65402 + else
65403 + return 0UL;
65404 +}
65405 +
65406 +/* if tsk != current then task_lock must be held on it */
65407 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
65408 +{
65409 + if (likely(tsk->mm)) {
65410 + tsk->mm->pax_flags = flags;
65411 + return 0;
65412 + }
65413 + return -EINVAL;
65414 +}
65415 +#endif
65416 +
65417 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
65418 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
65419 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
65420 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
65421 +#endif
65422 +
65423 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
65424 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
65425 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
65426 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
65427 +
65428 /* Future-safe accessor for struct task_struct's cpus_allowed. */
65429 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
65430
65431 @@ -2092,7 +2186,9 @@ void yield(void);
65432 extern struct exec_domain default_exec_domain;
65433
65434 union thread_union {
65435 +#ifndef CONFIG_X86
65436 struct thread_info thread_info;
65437 +#endif
65438 unsigned long stack[THREAD_SIZE/sizeof(long)];
65439 };
65440
65441 @@ -2125,6 +2221,7 @@ extern struct pid_namespace init_pid_ns;
65442 */
65443
65444 extern struct task_struct *find_task_by_vpid(pid_t nr);
65445 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
65446 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
65447 struct pid_namespace *ns);
65448
65449 @@ -2281,7 +2378,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
65450 extern void exit_itimers(struct signal_struct *);
65451 extern void flush_itimer_signals(void);
65452
65453 -extern void do_group_exit(int);
65454 +extern __noreturn void do_group_exit(int);
65455
65456 extern void daemonize(const char *, ...);
65457 extern int allow_signal(int);
65458 @@ -2485,9 +2582,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
65459
65460 #endif
65461
65462 -static inline int object_is_on_stack(void *obj)
65463 +static inline int object_starts_on_stack(void *obj)
65464 {
65465 - void *stack = task_stack_page(current);
65466 + const void *stack = task_stack_page(current);
65467
65468 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
65469 }
65470 diff --git a/include/linux/security.h b/include/linux/security.h
65471 index 05e88bd..5cda002 100644
65472 --- a/include/linux/security.h
65473 +++ b/include/linux/security.h
65474 @@ -26,6 +26,7 @@
65475 #include <linux/capability.h>
65476 #include <linux/slab.h>
65477 #include <linux/err.h>
65478 +#include <linux/grsecurity.h>
65479
65480 struct linux_binprm;
65481 struct cred;
65482 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
65483 index 68a04a3..866e6a1 100644
65484 --- a/include/linux/seq_file.h
65485 +++ b/include/linux/seq_file.h
65486 @@ -26,6 +26,9 @@ struct seq_file {
65487 struct mutex lock;
65488 const struct seq_operations *op;
65489 int poll_event;
65490 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65491 + u64 exec_id;
65492 +#endif
65493 #ifdef CONFIG_USER_NS
65494 struct user_namespace *user_ns;
65495 #endif
65496 @@ -38,6 +41,7 @@ struct seq_operations {
65497 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
65498 int (*show) (struct seq_file *m, void *v);
65499 };
65500 +typedef struct seq_operations __no_const seq_operations_no_const;
65501
65502 #define SEQ_SKIP 1
65503
65504 diff --git a/include/linux/shm.h b/include/linux/shm.h
65505 index bcf8a6a..4d0af77 100644
65506 --- a/include/linux/shm.h
65507 +++ b/include/linux/shm.h
65508 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
65509
65510 /* The task created the shm object. NULL if the task is dead. */
65511 struct task_struct *shm_creator;
65512 +#ifdef CONFIG_GRKERNSEC
65513 + time_t shm_createtime;
65514 + pid_t shm_lapid;
65515 +#endif
65516 };
65517
65518 /* shm_mode upper byte flags */
65519 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
65520 index 6a2c34e..a1f320f 100644
65521 --- a/include/linux/skbuff.h
65522 +++ b/include/linux/skbuff.h
65523 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
65524 extern struct sk_buff *__alloc_skb(unsigned int size,
65525 gfp_t priority, int flags, int node);
65526 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
65527 -static inline struct sk_buff *alloc_skb(unsigned int size,
65528 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
65529 gfp_t priority)
65530 {
65531 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
65532 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
65533 */
65534 static inline int skb_queue_empty(const struct sk_buff_head *list)
65535 {
65536 - return list->next == (struct sk_buff *)list;
65537 + return list->next == (const struct sk_buff *)list;
65538 }
65539
65540 /**
65541 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
65542 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
65543 const struct sk_buff *skb)
65544 {
65545 - return skb->next == (struct sk_buff *)list;
65546 + return skb->next == (const struct sk_buff *)list;
65547 }
65548
65549 /**
65550 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
65551 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
65552 const struct sk_buff *skb)
65553 {
65554 - return skb->prev == (struct sk_buff *)list;
65555 + return skb->prev == (const struct sk_buff *)list;
65556 }
65557
65558 /**
65559 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
65560 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
65561 */
65562 #ifndef NET_SKB_PAD
65563 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
65564 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
65565 #endif
65566
65567 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
65568 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
65569 int noblock, int *err);
65570 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
65571 struct poll_table_struct *wait);
65572 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
65573 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
65574 int offset, struct iovec *to,
65575 int size);
65576 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
65577 diff --git a/include/linux/slab.h b/include/linux/slab.h
65578 index 83d1a14..209e1a6 100644
65579 --- a/include/linux/slab.h
65580 +++ b/include/linux/slab.h
65581 @@ -11,12 +11,20 @@
65582
65583 #include <linux/gfp.h>
65584 #include <linux/types.h>
65585 +#include <linux/err.h>
65586
65587 /*
65588 * Flags to pass to kmem_cache_create().
65589 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
65590 */
65591 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
65592 +
65593 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65594 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
65595 +#else
65596 +#define SLAB_USERCOPY 0x00000000UL
65597 +#endif
65598 +
65599 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
65600 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
65601 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
65602 @@ -87,10 +95,13 @@
65603 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
65604 * Both make kfree a no-op.
65605 */
65606 -#define ZERO_SIZE_PTR ((void *)16)
65607 +#define ZERO_SIZE_PTR \
65608 +({ \
65609 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
65610 + (void *)(-MAX_ERRNO-1L); \
65611 +})
65612
65613 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
65614 - (unsigned long)ZERO_SIZE_PTR)
65615 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
65616
65617 /*
65618 * Common fields provided in kmem_cache by all slab allocators
65619 @@ -110,7 +121,7 @@ struct kmem_cache {
65620 unsigned int align; /* Alignment as calculated */
65621 unsigned long flags; /* Active flags on the slab */
65622 const char *name; /* Slab name for sysfs */
65623 - int refcount; /* Use counter */
65624 + atomic_t refcount; /* Use counter */
65625 void (*ctor)(void *); /* Called on object slot creation */
65626 struct list_head list; /* List of all slab caches on the system */
65627 };
65628 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
65629 void kfree(const void *);
65630 void kzfree(const void *);
65631 size_t ksize(const void *);
65632 +const char *check_heap_object(const void *ptr, unsigned long n);
65633 +bool is_usercopy_object(const void *ptr);
65634
65635 /*
65636 * Allocator specific definitions. These are mainly used to establish optimized
65637 @@ -323,7 +336,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
65638 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
65639 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
65640 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
65641 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
65642 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
65643 #define kmalloc_track_caller(size, flags) \
65644 __kmalloc_track_caller(size, flags, _RET_IP_)
65645 #else
65646 @@ -343,7 +356,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
65647 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
65648 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
65649 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
65650 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
65651 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
65652 #define kmalloc_node_track_caller(size, flags, node) \
65653 __kmalloc_node_track_caller(size, flags, node, \
65654 _RET_IP_)
65655 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
65656 index cc290f0..0ba60931 100644
65657 --- a/include/linux/slab_def.h
65658 +++ b/include/linux/slab_def.h
65659 @@ -52,7 +52,7 @@ struct kmem_cache {
65660 /* 4) cache creation/removal */
65661 const char *name;
65662 struct list_head list;
65663 - int refcount;
65664 + atomic_t refcount;
65665 int object_size;
65666 int align;
65667
65668 @@ -68,10 +68,10 @@ struct kmem_cache {
65669 unsigned long node_allocs;
65670 unsigned long node_frees;
65671 unsigned long node_overflow;
65672 - atomic_t allochit;
65673 - atomic_t allocmiss;
65674 - atomic_t freehit;
65675 - atomic_t freemiss;
65676 + atomic_unchecked_t allochit;
65677 + atomic_unchecked_t allocmiss;
65678 + atomic_unchecked_t freehit;
65679 + atomic_unchecked_t freemiss;
65680
65681 /*
65682 * If debugging is enabled, then the allocator can add additional
65683 @@ -104,11 +104,16 @@ struct cache_sizes {
65684 #ifdef CONFIG_ZONE_DMA
65685 struct kmem_cache *cs_dmacachep;
65686 #endif
65687 +
65688 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65689 + struct kmem_cache *cs_usercopycachep;
65690 +#endif
65691 +
65692 };
65693 extern struct cache_sizes malloc_sizes[];
65694
65695 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65696 -void *__kmalloc(size_t size, gfp_t flags);
65697 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
65698
65699 #ifdef CONFIG_TRACING
65700 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
65701 @@ -145,6 +150,13 @@ found:
65702 cachep = malloc_sizes[i].cs_dmacachep;
65703 else
65704 #endif
65705 +
65706 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65707 + if (flags & GFP_USERCOPY)
65708 + cachep = malloc_sizes[i].cs_usercopycachep;
65709 + else
65710 +#endif
65711 +
65712 cachep = malloc_sizes[i].cs_cachep;
65713
65714 ret = kmem_cache_alloc_trace(cachep, flags, size);
65715 @@ -155,7 +167,7 @@ found:
65716 }
65717
65718 #ifdef CONFIG_NUMA
65719 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
65720 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65721 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65722
65723 #ifdef CONFIG_TRACING
65724 @@ -198,6 +210,13 @@ found:
65725 cachep = malloc_sizes[i].cs_dmacachep;
65726 else
65727 #endif
65728 +
65729 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65730 + if (flags & GFP_USERCOPY)
65731 + cachep = malloc_sizes[i].cs_usercopycachep;
65732 + else
65733 +#endif
65734 +
65735 cachep = malloc_sizes[i].cs_cachep;
65736
65737 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
65738 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
65739 index f28e14a..7831211 100644
65740 --- a/include/linux/slob_def.h
65741 +++ b/include/linux/slob_def.h
65742 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
65743 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
65744 }
65745
65746 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
65747 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65748
65749 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
65750 {
65751 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65752 return __kmalloc_node(size, flags, NUMA_NO_NODE);
65753 }
65754
65755 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
65756 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
65757 {
65758 return kmalloc(size, flags);
65759 }
65760 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
65761 index df448ad..b99e7f6 100644
65762 --- a/include/linux/slub_def.h
65763 +++ b/include/linux/slub_def.h
65764 @@ -91,7 +91,7 @@ struct kmem_cache {
65765 struct kmem_cache_order_objects max;
65766 struct kmem_cache_order_objects min;
65767 gfp_t allocflags; /* gfp flags to use on each alloc */
65768 - int refcount; /* Refcount for slab cache destroy */
65769 + atomic_t refcount; /* Refcount for slab cache destroy */
65770 void (*ctor)(void *);
65771 int inuse; /* Offset to metadata */
65772 int align; /* Alignment */
65773 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
65774 * Sorry that the following has to be that ugly but some versions of GCC
65775 * have trouble with constant propagation and loops.
65776 */
65777 -static __always_inline int kmalloc_index(size_t size)
65778 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
65779 {
65780 if (!size)
65781 return 0;
65782 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
65783 }
65784
65785 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65786 -void *__kmalloc(size_t size, gfp_t flags);
65787 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
65788
65789 static __always_inline void *
65790 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
65791 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
65792 }
65793 #endif
65794
65795 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
65796 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
65797 {
65798 unsigned int order = get_order(size);
65799 return kmalloc_order_trace(size, flags, order);
65800 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65801 }
65802
65803 #ifdef CONFIG_NUMA
65804 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
65805 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65806 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65807
65808 #ifdef CONFIG_TRACING
65809 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
65810 index 680f9a3..f13aeb0 100644
65811 --- a/include/linux/sonet.h
65812 +++ b/include/linux/sonet.h
65813 @@ -7,7 +7,7 @@
65814 #include <uapi/linux/sonet.h>
65815
65816 struct k_sonet_stats {
65817 -#define __HANDLE_ITEM(i) atomic_t i
65818 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
65819 __SONET_ITEMS
65820 #undef __HANDLE_ITEM
65821 };
65822 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
65823 index 34206b8..f019e06 100644
65824 --- a/include/linux/sunrpc/clnt.h
65825 +++ b/include/linux/sunrpc/clnt.h
65826 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
65827 {
65828 switch (sap->sa_family) {
65829 case AF_INET:
65830 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
65831 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65832 case AF_INET6:
65833 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65834 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65835 }
65836 return 0;
65837 }
65838 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
65839 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65840 const struct sockaddr *src)
65841 {
65842 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65843 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65844 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65845
65846 dsin->sin_family = ssin->sin_family;
65847 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
65848 if (sa->sa_family != AF_INET6)
65849 return 0;
65850
65851 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65852 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65853 }
65854
65855 #endif /* __KERNEL__ */
65856 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
65857 index 0b8e3e6..33e0a01 100644
65858 --- a/include/linux/sunrpc/svc_rdma.h
65859 +++ b/include/linux/sunrpc/svc_rdma.h
65860 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65861 extern unsigned int svcrdma_max_requests;
65862 extern unsigned int svcrdma_max_req_size;
65863
65864 -extern atomic_t rdma_stat_recv;
65865 -extern atomic_t rdma_stat_read;
65866 -extern atomic_t rdma_stat_write;
65867 -extern atomic_t rdma_stat_sq_starve;
65868 -extern atomic_t rdma_stat_rq_starve;
65869 -extern atomic_t rdma_stat_rq_poll;
65870 -extern atomic_t rdma_stat_rq_prod;
65871 -extern atomic_t rdma_stat_sq_poll;
65872 -extern atomic_t rdma_stat_sq_prod;
65873 +extern atomic_unchecked_t rdma_stat_recv;
65874 +extern atomic_unchecked_t rdma_stat_read;
65875 +extern atomic_unchecked_t rdma_stat_write;
65876 +extern atomic_unchecked_t rdma_stat_sq_starve;
65877 +extern atomic_unchecked_t rdma_stat_rq_starve;
65878 +extern atomic_unchecked_t rdma_stat_rq_poll;
65879 +extern atomic_unchecked_t rdma_stat_rq_prod;
65880 +extern atomic_unchecked_t rdma_stat_sq_poll;
65881 +extern atomic_unchecked_t rdma_stat_sq_prod;
65882
65883 #define RPCRDMA_VERSION 1
65884
65885 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
65886 index cd844a6..3ca3592 100644
65887 --- a/include/linux/sysctl.h
65888 +++ b/include/linux/sysctl.h
65889 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
65890
65891 extern int proc_dostring(struct ctl_table *, int,
65892 void __user *, size_t *, loff_t *);
65893 +extern int proc_dostring_modpriv(struct ctl_table *, int,
65894 + void __user *, size_t *, loff_t *);
65895 extern int proc_dointvec(struct ctl_table *, int,
65896 void __user *, size_t *, loff_t *);
65897 extern int proc_dointvec_minmax(struct ctl_table *, int,
65898 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
65899 index 7faf933..eb6f5e3 100644
65900 --- a/include/linux/sysrq.h
65901 +++ b/include/linux/sysrq.h
65902 @@ -36,7 +36,7 @@ struct sysrq_key_op {
65903 char *help_msg;
65904 char *action_msg;
65905 int enable_mask;
65906 -};
65907 +} __do_const;
65908
65909 #ifdef CONFIG_MAGIC_SYSRQ
65910
65911 diff --git a/include/linux/tty.h b/include/linux/tty.h
65912 index f0b4eb4..1c4854e 100644
65913 --- a/include/linux/tty.h
65914 +++ b/include/linux/tty.h
65915 @@ -192,7 +192,7 @@ struct tty_port {
65916 const struct tty_port_operations *ops; /* Port operations */
65917 spinlock_t lock; /* Lock protecting tty field */
65918 int blocked_open; /* Waiting to open */
65919 - int count; /* Usage count */
65920 + atomic_t count; /* Usage count */
65921 wait_queue_head_t open_wait; /* Open waiters */
65922 wait_queue_head_t close_wait; /* Close waiters */
65923 wait_queue_head_t delta_msr_wait; /* Modem status change */
65924 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
65925 struct tty_struct *tty, struct file *filp);
65926 static inline int tty_port_users(struct tty_port *port)
65927 {
65928 - return port->count + port->blocked_open;
65929 + return atomic_read(&port->count) + port->blocked_open;
65930 }
65931
65932 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
65933 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
65934 index dd976cf..e272742 100644
65935 --- a/include/linux/tty_driver.h
65936 +++ b/include/linux/tty_driver.h
65937 @@ -284,7 +284,7 @@ struct tty_operations {
65938 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
65939 #endif
65940 const struct file_operations *proc_fops;
65941 -};
65942 +} __do_const;
65943
65944 struct tty_driver {
65945 int magic; /* magic number for this structure */
65946 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
65947 index fb79dd8d..07d4773 100644
65948 --- a/include/linux/tty_ldisc.h
65949 +++ b/include/linux/tty_ldisc.h
65950 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
65951
65952 struct module *owner;
65953
65954 - int refcount;
65955 + atomic_t refcount;
65956 };
65957
65958 struct tty_ldisc {
65959 diff --git a/include/linux/types.h b/include/linux/types.h
65960 index 1cc0e4b..0d50edf 100644
65961 --- a/include/linux/types.h
65962 +++ b/include/linux/types.h
65963 @@ -175,10 +175,26 @@ typedef struct {
65964 int counter;
65965 } atomic_t;
65966
65967 +#ifdef CONFIG_PAX_REFCOUNT
65968 +typedef struct {
65969 + int counter;
65970 +} atomic_unchecked_t;
65971 +#else
65972 +typedef atomic_t atomic_unchecked_t;
65973 +#endif
65974 +
65975 #ifdef CONFIG_64BIT
65976 typedef struct {
65977 long counter;
65978 } atomic64_t;
65979 +
65980 +#ifdef CONFIG_PAX_REFCOUNT
65981 +typedef struct {
65982 + long counter;
65983 +} atomic64_unchecked_t;
65984 +#else
65985 +typedef atomic64_t atomic64_unchecked_t;
65986 +#endif
65987 #endif
65988
65989 struct list_head {
65990 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
65991 index 5ca0951..ab496a5 100644
65992 --- a/include/linux/uaccess.h
65993 +++ b/include/linux/uaccess.h
65994 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
65995 long ret; \
65996 mm_segment_t old_fs = get_fs(); \
65997 \
65998 - set_fs(KERNEL_DS); \
65999 pagefault_disable(); \
66000 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66001 - pagefault_enable(); \
66002 + set_fs(KERNEL_DS); \
66003 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66004 set_fs(old_fs); \
66005 + pagefault_enable(); \
66006 ret; \
66007 })
66008
66009 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66010 index 99c1b4d..bb94261 100644
66011 --- a/include/linux/unaligned/access_ok.h
66012 +++ b/include/linux/unaligned/access_ok.h
66013 @@ -6,32 +6,32 @@
66014
66015 static inline u16 get_unaligned_le16(const void *p)
66016 {
66017 - return le16_to_cpup((__le16 *)p);
66018 + return le16_to_cpup((const __le16 *)p);
66019 }
66020
66021 static inline u32 get_unaligned_le32(const void *p)
66022 {
66023 - return le32_to_cpup((__le32 *)p);
66024 + return le32_to_cpup((const __le32 *)p);
66025 }
66026
66027 static inline u64 get_unaligned_le64(const void *p)
66028 {
66029 - return le64_to_cpup((__le64 *)p);
66030 + return le64_to_cpup((const __le64 *)p);
66031 }
66032
66033 static inline u16 get_unaligned_be16(const void *p)
66034 {
66035 - return be16_to_cpup((__be16 *)p);
66036 + return be16_to_cpup((const __be16 *)p);
66037 }
66038
66039 static inline u32 get_unaligned_be32(const void *p)
66040 {
66041 - return be32_to_cpup((__be32 *)p);
66042 + return be32_to_cpup((const __be32 *)p);
66043 }
66044
66045 static inline u64 get_unaligned_be64(const void *p)
66046 {
66047 - return be64_to_cpup((__be64 *)p);
66048 + return be64_to_cpup((const __be64 *)p);
66049 }
66050
66051 static inline void put_unaligned_le16(u16 val, void *p)
66052 diff --git a/include/linux/usb.h b/include/linux/usb.h
66053 index 10278d1..e21ec3c 100644
66054 --- a/include/linux/usb.h
66055 +++ b/include/linux/usb.h
66056 @@ -551,7 +551,7 @@ struct usb_device {
66057 int maxchild;
66058
66059 u32 quirks;
66060 - atomic_t urbnum;
66061 + atomic_unchecked_t urbnum;
66062
66063 unsigned long active_duration;
66064
66065 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66066 index c5d36c6..108f4f9 100644
66067 --- a/include/linux/usb/renesas_usbhs.h
66068 +++ b/include/linux/usb/renesas_usbhs.h
66069 @@ -39,7 +39,7 @@ enum {
66070 */
66071 struct renesas_usbhs_driver_callback {
66072 int (*notify_hotplug)(struct platform_device *pdev);
66073 -};
66074 +} __no_const;
66075
66076 /*
66077 * callback functions for platform
66078 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66079 index 6f8fbcf..8259001 100644
66080 --- a/include/linux/vermagic.h
66081 +++ b/include/linux/vermagic.h
66082 @@ -25,9 +25,35 @@
66083 #define MODULE_ARCH_VERMAGIC ""
66084 #endif
66085
66086 +#ifdef CONFIG_PAX_REFCOUNT
66087 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
66088 +#else
66089 +#define MODULE_PAX_REFCOUNT ""
66090 +#endif
66091 +
66092 +#ifdef CONSTIFY_PLUGIN
66093 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66094 +#else
66095 +#define MODULE_CONSTIFY_PLUGIN ""
66096 +#endif
66097 +
66098 +#ifdef STACKLEAK_PLUGIN
66099 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66100 +#else
66101 +#define MODULE_STACKLEAK_PLUGIN ""
66102 +#endif
66103 +
66104 +#ifdef CONFIG_GRKERNSEC
66105 +#define MODULE_GRSEC "GRSEC "
66106 +#else
66107 +#define MODULE_GRSEC ""
66108 +#endif
66109 +
66110 #define VERMAGIC_STRING \
66111 UTS_RELEASE " " \
66112 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66113 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66114 - MODULE_ARCH_VERMAGIC
66115 + MODULE_ARCH_VERMAGIC \
66116 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66117 + MODULE_GRSEC
66118
66119 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66120 index 6071e91..ca6a489 100644
66121 --- a/include/linux/vmalloc.h
66122 +++ b/include/linux/vmalloc.h
66123 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66124 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66125 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66126 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66127 +
66128 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66129 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66130 +#endif
66131 +
66132 /* bits [20..32] reserved for arch specific ioremap internals */
66133
66134 /*
66135 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66136 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66137 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66138 unsigned long start, unsigned long end, gfp_t gfp_mask,
66139 - pgprot_t prot, int node, const void *caller);
66140 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
66141 extern void vfree(const void *addr);
66142
66143 extern void *vmap(struct page **pages, unsigned int count,
66144 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66145 extern void free_vm_area(struct vm_struct *area);
66146
66147 /* for /dev/kmem */
66148 -extern long vread(char *buf, char *addr, unsigned long count);
66149 -extern long vwrite(char *buf, char *addr, unsigned long count);
66150 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66151 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66152
66153 /*
66154 * Internals. Dont't use..
66155 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66156 index 92a86b2..1d9eb3c 100644
66157 --- a/include/linux/vmstat.h
66158 +++ b/include/linux/vmstat.h
66159 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66160 /*
66161 * Zone based page accounting with per cpu differentials.
66162 */
66163 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66164 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66165
66166 static inline void zone_page_state_add(long x, struct zone *zone,
66167 enum zone_stat_item item)
66168 {
66169 - atomic_long_add(x, &zone->vm_stat[item]);
66170 - atomic_long_add(x, &vm_stat[item]);
66171 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
66172 + atomic_long_add_unchecked(x, &vm_stat[item]);
66173 }
66174
66175 static inline unsigned long global_page_state(enum zone_stat_item item)
66176 {
66177 - long x = atomic_long_read(&vm_stat[item]);
66178 + long x = atomic_long_read_unchecked(&vm_stat[item]);
66179 #ifdef CONFIG_SMP
66180 if (x < 0)
66181 x = 0;
66182 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
66183 static inline unsigned long zone_page_state(struct zone *zone,
66184 enum zone_stat_item item)
66185 {
66186 - long x = atomic_long_read(&zone->vm_stat[item]);
66187 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66188 #ifdef CONFIG_SMP
66189 if (x < 0)
66190 x = 0;
66191 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
66192 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
66193 enum zone_stat_item item)
66194 {
66195 - long x = atomic_long_read(&zone->vm_stat[item]);
66196 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66197
66198 #ifdef CONFIG_SMP
66199 int cpu;
66200 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
66201
66202 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
66203 {
66204 - atomic_long_inc(&zone->vm_stat[item]);
66205 - atomic_long_inc(&vm_stat[item]);
66206 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
66207 + atomic_long_inc_unchecked(&vm_stat[item]);
66208 }
66209
66210 static inline void __inc_zone_page_state(struct page *page,
66211 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
66212
66213 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
66214 {
66215 - atomic_long_dec(&zone->vm_stat[item]);
66216 - atomic_long_dec(&vm_stat[item]);
66217 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
66218 + atomic_long_dec_unchecked(&vm_stat[item]);
66219 }
66220
66221 static inline void __dec_zone_page_state(struct page *page,
66222 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
66223 index 95d1c91..6798cca 100644
66224 --- a/include/media/v4l2-dev.h
66225 +++ b/include/media/v4l2-dev.h
66226 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
66227 int (*mmap) (struct file *, struct vm_area_struct *);
66228 int (*open) (struct file *);
66229 int (*release) (struct file *);
66230 -};
66231 +} __do_const;
66232
66233 /*
66234 * Newer version of video_device, handled by videodev2.c
66235 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
66236 index e48b571..7e40de4 100644
66237 --- a/include/media/v4l2-ioctl.h
66238 +++ b/include/media/v4l2-ioctl.h
66239 @@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
66240 bool valid_prio, int cmd, void *arg);
66241 };
66242
66243 -
66244 /* v4l debugging and diagnostics */
66245
66246 /* Debug bitmask flags to be used on V4L2 */
66247 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
66248 index 9e5425b..8136ffc 100644
66249 --- a/include/net/caif/cfctrl.h
66250 +++ b/include/net/caif/cfctrl.h
66251 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
66252 void (*radioset_rsp)(void);
66253 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
66254 struct cflayer *client_layer);
66255 -};
66256 +} __no_const;
66257
66258 /* Link Setup Parameters for CAIF-Links. */
66259 struct cfctrl_link_param {
66260 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
66261 struct cfctrl {
66262 struct cfsrvl serv;
66263 struct cfctrl_rsp res;
66264 - atomic_t req_seq_no;
66265 - atomic_t rsp_seq_no;
66266 + atomic_unchecked_t req_seq_no;
66267 + atomic_unchecked_t rsp_seq_no;
66268 struct list_head list;
66269 /* Protects from simultaneous access to first_req list */
66270 spinlock_t info_list_lock;
66271 diff --git a/include/net/flow.h b/include/net/flow.h
66272 index 628e11b..4c475df 100644
66273 --- a/include/net/flow.h
66274 +++ b/include/net/flow.h
66275 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
66276
66277 extern void flow_cache_flush(void);
66278 extern void flow_cache_flush_deferred(void);
66279 -extern atomic_t flow_cache_genid;
66280 +extern atomic_unchecked_t flow_cache_genid;
66281
66282 #endif
66283 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
66284 index e5062c9..e709988 100644
66285 --- a/include/net/gro_cells.h
66286 +++ b/include/net/gro_cells.h
66287 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
66288 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
66289
66290 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
66291 - atomic_long_inc(&dev->rx_dropped);
66292 + atomic_long_inc_unchecked(&dev->rx_dropped);
66293 kfree_skb(skb);
66294 return;
66295 }
66296 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
66297 index 1832927..ce39aea 100644
66298 --- a/include/net/inet_connection_sock.h
66299 +++ b/include/net/inet_connection_sock.h
66300 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
66301 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
66302 int (*bind_conflict)(const struct sock *sk,
66303 const struct inet_bind_bucket *tb, bool relax);
66304 -};
66305 +} __do_const;
66306
66307 /** inet_connection_sock - INET connection oriented sock
66308 *
66309 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
66310 index 53f464d..ba76aaa 100644
66311 --- a/include/net/inetpeer.h
66312 +++ b/include/net/inetpeer.h
66313 @@ -47,8 +47,8 @@ struct inet_peer {
66314 */
66315 union {
66316 struct {
66317 - atomic_t rid; /* Frag reception counter */
66318 - atomic_t ip_id_count; /* IP ID for the next packet */
66319 + atomic_unchecked_t rid; /* Frag reception counter */
66320 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
66321 };
66322 struct rcu_head rcu;
66323 struct inet_peer *gc_next;
66324 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
66325 more++;
66326 inet_peer_refcheck(p);
66327 do {
66328 - old = atomic_read(&p->ip_id_count);
66329 + old = atomic_read_unchecked(&p->ip_id_count);
66330 new = old + more;
66331 if (!new)
66332 new = 1;
66333 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
66334 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
66335 return new;
66336 }
66337
66338 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
66339 index 9497be1..5a4fafe 100644
66340 --- a/include/net/ip_fib.h
66341 +++ b/include/net/ip_fib.h
66342 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
66343
66344 #define FIB_RES_SADDR(net, res) \
66345 ((FIB_RES_NH(res).nh_saddr_genid == \
66346 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
66347 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
66348 FIB_RES_NH(res).nh_saddr : \
66349 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
66350 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
66351 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
66352 index ee75ccd..2cc2b95 100644
66353 --- a/include/net/ip_vs.h
66354 +++ b/include/net/ip_vs.h
66355 @@ -510,7 +510,7 @@ struct ip_vs_conn {
66356 struct ip_vs_conn *control; /* Master control connection */
66357 atomic_t n_control; /* Number of controlled ones */
66358 struct ip_vs_dest *dest; /* real server */
66359 - atomic_t in_pkts; /* incoming packet counter */
66360 + atomic_unchecked_t in_pkts; /* incoming packet counter */
66361
66362 /* packet transmitter for different forwarding methods. If it
66363 mangles the packet, it must return NF_DROP or better NF_STOLEN,
66364 @@ -648,7 +648,7 @@ struct ip_vs_dest {
66365 __be16 port; /* port number of the server */
66366 union nf_inet_addr addr; /* IP address of the server */
66367 volatile unsigned int flags; /* dest status flags */
66368 - atomic_t conn_flags; /* flags to copy to conn */
66369 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
66370 atomic_t weight; /* server weight */
66371
66372 atomic_t refcnt; /* reference counter */
66373 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
66374 index 80ffde3..968b0f4 100644
66375 --- a/include/net/irda/ircomm_tty.h
66376 +++ b/include/net/irda/ircomm_tty.h
66377 @@ -35,6 +35,7 @@
66378 #include <linux/termios.h>
66379 #include <linux/timer.h>
66380 #include <linux/tty.h> /* struct tty_struct */
66381 +#include <asm/local.h>
66382
66383 #include <net/irda/irias_object.h>
66384 #include <net/irda/ircomm_core.h>
66385 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
66386 index cc7c197..9f2da2a 100644
66387 --- a/include/net/iucv/af_iucv.h
66388 +++ b/include/net/iucv/af_iucv.h
66389 @@ -141,7 +141,7 @@ struct iucv_sock {
66390 struct iucv_sock_list {
66391 struct hlist_head head;
66392 rwlock_t lock;
66393 - atomic_t autobind_name;
66394 + atomic_unchecked_t autobind_name;
66395 };
66396
66397 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
66398 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
66399 index 0dab173..1b76af0 100644
66400 --- a/include/net/neighbour.h
66401 +++ b/include/net/neighbour.h
66402 @@ -123,7 +123,7 @@ struct neigh_ops {
66403 void (*error_report)(struct neighbour *, struct sk_buff *);
66404 int (*output)(struct neighbour *, struct sk_buff *);
66405 int (*connected_output)(struct neighbour *, struct sk_buff *);
66406 -};
66407 +} __do_const;
66408
66409 struct pneigh_entry {
66410 struct pneigh_entry *next;
66411 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
66412 index 95e6466..251016d 100644
66413 --- a/include/net/net_namespace.h
66414 +++ b/include/net/net_namespace.h
66415 @@ -110,7 +110,7 @@ struct net {
66416 #endif
66417 struct netns_ipvs *ipvs;
66418 struct sock *diag_nlsk;
66419 - atomic_t rt_genid;
66420 + atomic_unchecked_t rt_genid;
66421 };
66422
66423 /*
66424 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
66425
66426 static inline int rt_genid(struct net *net)
66427 {
66428 - return atomic_read(&net->rt_genid);
66429 + return atomic_read_unchecked(&net->rt_genid);
66430 }
66431
66432 static inline void rt_genid_bump(struct net *net)
66433 {
66434 - atomic_inc(&net->rt_genid);
66435 + atomic_inc_unchecked(&net->rt_genid);
66436 }
66437
66438 #endif /* __NET_NET_NAMESPACE_H */
66439 diff --git a/include/net/netdma.h b/include/net/netdma.h
66440 index 8ba8ce2..99b7fff 100644
66441 --- a/include/net/netdma.h
66442 +++ b/include/net/netdma.h
66443 @@ -24,7 +24,7 @@
66444 #include <linux/dmaengine.h>
66445 #include <linux/skbuff.h>
66446
66447 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
66448 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
66449 struct sk_buff *skb, int offset, struct iovec *to,
66450 size_t len, struct dma_pinned_list *pinned_list);
66451
66452 diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
66453 index 252fd10..aa1421f 100644
66454 --- a/include/net/netfilter/nf_queue.h
66455 +++ b/include/net/netfilter/nf_queue.h
66456 @@ -22,7 +22,7 @@ struct nf_queue_handler {
66457 int (*outfn)(struct nf_queue_entry *entry,
66458 unsigned int queuenum);
66459 char *name;
66460 -};
66461 +} __do_const;
66462
66463 extern int nf_register_queue_handler(u_int8_t pf,
66464 const struct nf_queue_handler *qh);
66465 diff --git a/include/net/netlink.h b/include/net/netlink.h
66466 index 9690b0f..87aded7 100644
66467 --- a/include/net/netlink.h
66468 +++ b/include/net/netlink.h
66469 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
66470 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
66471 {
66472 if (mark)
66473 - skb_trim(skb, (unsigned char *) mark - skb->data);
66474 + skb_trim(skb, (const unsigned char *) mark - skb->data);
66475 }
66476
66477 /**
66478 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
66479 index 2ae2b83..dbdc85e 100644
66480 --- a/include/net/netns/ipv4.h
66481 +++ b/include/net/netns/ipv4.h
66482 @@ -64,7 +64,7 @@ struct netns_ipv4 {
66483 kgid_t sysctl_ping_group_range[2];
66484 long sysctl_tcp_mem[3];
66485
66486 - atomic_t dev_addr_genid;
66487 + atomic_unchecked_t dev_addr_genid;
66488
66489 #ifdef CONFIG_IP_MROUTE
66490 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
66491 diff --git a/include/net/protocol.h b/include/net/protocol.h
66492 index 929528c..c84d4f6 100644
66493 --- a/include/net/protocol.h
66494 +++ b/include/net/protocol.h
66495 @@ -48,7 +48,7 @@ struct net_protocol {
66496 int (*gro_complete)(struct sk_buff *skb);
66497 unsigned int no_policy:1,
66498 netns_ok:1;
66499 -};
66500 +} __do_const;
66501
66502 #if IS_ENABLED(CONFIG_IPV6)
66503 struct inet6_protocol {
66504 @@ -69,7 +69,7 @@ struct inet6_protocol {
66505 int (*gro_complete)(struct sk_buff *skb);
66506
66507 unsigned int flags; /* INET6_PROTO_xxx */
66508 -};
66509 +} __do_const;
66510
66511 #define INET6_PROTO_NOPOLICY 0x1
66512 #define INET6_PROTO_FINAL 0x2
66513 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
66514 index 9c6414f..fbd0524 100644
66515 --- a/include/net/sctp/sctp.h
66516 +++ b/include/net/sctp/sctp.h
66517 @@ -318,9 +318,9 @@ do { \
66518
66519 #else /* SCTP_DEBUG */
66520
66521 -#define SCTP_DEBUG_PRINTK(whatever...)
66522 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
66523 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
66524 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
66525 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
66526 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
66527 #define SCTP_ENABLE_DEBUG
66528 #define SCTP_DISABLE_DEBUG
66529 #define SCTP_ASSERT(expr, str, func)
66530 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
66531 index 64158aa..b65533c 100644
66532 --- a/include/net/sctp/structs.h
66533 +++ b/include/net/sctp/structs.h
66534 @@ -496,7 +496,7 @@ struct sctp_af {
66535 int sockaddr_len;
66536 sa_family_t sa_family;
66537 struct list_head list;
66538 -};
66539 +} __do_const;
66540
66541 struct sctp_af *sctp_get_af_specific(sa_family_t);
66542 int sctp_register_af(struct sctp_af *);
66543 @@ -516,7 +516,7 @@ struct sctp_pf {
66544 struct sctp_association *asoc);
66545 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
66546 struct sctp_af *af;
66547 -};
66548 +} __do_const;
66549
66550
66551 /* Structure to track chunk fragments that have been acked, but peer
66552 diff --git a/include/net/sock.h b/include/net/sock.h
66553 index c945fba..e162e56 100644
66554 --- a/include/net/sock.h
66555 +++ b/include/net/sock.h
66556 @@ -304,7 +304,7 @@ struct sock {
66557 #ifdef CONFIG_RPS
66558 __u32 sk_rxhash;
66559 #endif
66560 - atomic_t sk_drops;
66561 + atomic_unchecked_t sk_drops;
66562 int sk_rcvbuf;
66563
66564 struct sk_filter __rcu *sk_filter;
66565 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
66566 }
66567
66568 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
66569 - char __user *from, char *to,
66570 + char __user *from, unsigned char *to,
66571 int copy, int offset)
66572 {
66573 if (skb->ip_summed == CHECKSUM_NONE) {
66574 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
66575 }
66576 }
66577
66578 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
66579 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
66580
66581 /**
66582 * sk_page_frag - return an appropriate page_frag
66583 diff --git a/include/net/tcp.h b/include/net/tcp.h
66584 index 4af45e3..af97861 100644
66585 --- a/include/net/tcp.h
66586 +++ b/include/net/tcp.h
66587 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
66588 extern void tcp_xmit_retransmit_queue(struct sock *);
66589 extern void tcp_simple_retransmit(struct sock *);
66590 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
66591 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
66592 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
66593
66594 extern void tcp_send_probe0(struct sock *);
66595 extern void tcp_send_partial(struct sock *);
66596 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
66597 struct inet6_skb_parm h6;
66598 #endif
66599 } header; /* For incoming frames */
66600 - __u32 seq; /* Starting sequence number */
66601 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
66602 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
66603 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
66604 __u32 when; /* used to compute rtt's */
66605 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
66606
66607 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
66608
66609 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
66610 /* 1 byte hole */
66611 - __u32 ack_seq; /* Sequence number ACK'd */
66612 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
66613 };
66614
66615 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
66616 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
66617 index 63445ed..74ef61d 100644
66618 --- a/include/net/xfrm.h
66619 +++ b/include/net/xfrm.h
66620 @@ -423,7 +423,7 @@ struct xfrm_mode {
66621 struct module *owner;
66622 unsigned int encap;
66623 int flags;
66624 -};
66625 +} __do_const;
66626
66627 /* Flags for xfrm_mode. */
66628 enum {
66629 @@ -514,7 +514,7 @@ struct xfrm_policy {
66630 struct timer_list timer;
66631
66632 struct flow_cache_object flo;
66633 - atomic_t genid;
66634 + atomic_unchecked_t genid;
66635 u32 priority;
66636 u32 index;
66637 struct xfrm_mark mark;
66638 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
66639 index 1a046b1..ee0bef0 100644
66640 --- a/include/rdma/iw_cm.h
66641 +++ b/include/rdma/iw_cm.h
66642 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
66643 int backlog);
66644
66645 int (*destroy_listen)(struct iw_cm_id *cm_id);
66646 -};
66647 +} __no_const;
66648
66649 /**
66650 * iw_create_cm_id - Create an IW CM identifier.
66651 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
66652 index 399162b..b337f1a 100644
66653 --- a/include/scsi/libfc.h
66654 +++ b/include/scsi/libfc.h
66655 @@ -762,6 +762,7 @@ struct libfc_function_template {
66656 */
66657 void (*disc_stop_final) (struct fc_lport *);
66658 };
66659 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
66660
66661 /**
66662 * struct fc_disc - Discovery context
66663 @@ -866,7 +867,7 @@ struct fc_lport {
66664 struct fc_vport *vport;
66665
66666 /* Operational Information */
66667 - struct libfc_function_template tt;
66668 + libfc_function_template_no_const tt;
66669 u8 link_up;
66670 u8 qfull;
66671 enum fc_lport_state state;
66672 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
66673 index 55367b0..d97bd2a 100644
66674 --- a/include/scsi/scsi_device.h
66675 +++ b/include/scsi/scsi_device.h
66676 @@ -169,9 +169,9 @@ struct scsi_device {
66677 unsigned int max_device_blocked; /* what device_blocked counts down from */
66678 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
66679
66680 - atomic_t iorequest_cnt;
66681 - atomic_t iodone_cnt;
66682 - atomic_t ioerr_cnt;
66683 + atomic_unchecked_t iorequest_cnt;
66684 + atomic_unchecked_t iodone_cnt;
66685 + atomic_unchecked_t ioerr_cnt;
66686
66687 struct device sdev_gendev,
66688 sdev_dev;
66689 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
66690 index b797e8f..8e2c3aa 100644
66691 --- a/include/scsi/scsi_transport_fc.h
66692 +++ b/include/scsi/scsi_transport_fc.h
66693 @@ -751,7 +751,8 @@ struct fc_function_template {
66694 unsigned long show_host_system_hostname:1;
66695
66696 unsigned long disable_target_scan:1;
66697 -};
66698 +} __do_const;
66699 +typedef struct fc_function_template __no_const fc_function_template_no_const;
66700
66701
66702 /**
66703 diff --git a/include/sound/soc.h b/include/sound/soc.h
66704 index 91244a0..89ca1a7 100644
66705 --- a/include/sound/soc.h
66706 +++ b/include/sound/soc.h
66707 @@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
66708 /* probe ordering - for components with runtime dependencies */
66709 int probe_order;
66710 int remove_order;
66711 -};
66712 +} __do_const;
66713
66714 /* SoC platform interface */
66715 struct snd_soc_platform_driver {
66716 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
66717 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
66718 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
66719 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
66720 -};
66721 +} __do_const;
66722
66723 struct snd_soc_platform {
66724 const char *name;
66725 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
66726 index 5be8937..cefbdd5 100644
66727 --- a/include/target/target_core_base.h
66728 +++ b/include/target/target_core_base.h
66729 @@ -758,7 +758,7 @@ struct se_device {
66730 spinlock_t stats_lock;
66731 /* Active commands on this virtual SE device */
66732 atomic_t simple_cmds;
66733 - atomic_t dev_ordered_id;
66734 + atomic_unchecked_t dev_ordered_id;
66735 atomic_t dev_ordered_sync;
66736 atomic_t dev_qf_count;
66737 struct se_obj dev_obj;
66738 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
66739 new file mode 100644
66740 index 0000000..fb634b7
66741 --- /dev/null
66742 +++ b/include/trace/events/fs.h
66743 @@ -0,0 +1,53 @@
66744 +#undef TRACE_SYSTEM
66745 +#define TRACE_SYSTEM fs
66746 +
66747 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
66748 +#define _TRACE_FS_H
66749 +
66750 +#include <linux/fs.h>
66751 +#include <linux/tracepoint.h>
66752 +
66753 +TRACE_EVENT(do_sys_open,
66754 +
66755 + TP_PROTO(const char *filename, int flags, int mode),
66756 +
66757 + TP_ARGS(filename, flags, mode),
66758 +
66759 + TP_STRUCT__entry(
66760 + __string( filename, filename )
66761 + __field( int, flags )
66762 + __field( int, mode )
66763 + ),
66764 +
66765 + TP_fast_assign(
66766 + __assign_str(filename, filename);
66767 + __entry->flags = flags;
66768 + __entry->mode = mode;
66769 + ),
66770 +
66771 + TP_printk("\"%s\" %x %o",
66772 + __get_str(filename), __entry->flags, __entry->mode)
66773 +);
66774 +
66775 +TRACE_EVENT(open_exec,
66776 +
66777 + TP_PROTO(const char *filename),
66778 +
66779 + TP_ARGS(filename),
66780 +
66781 + TP_STRUCT__entry(
66782 + __string( filename, filename )
66783 + ),
66784 +
66785 + TP_fast_assign(
66786 + __assign_str(filename, filename);
66787 + ),
66788 +
66789 + TP_printk("\"%s\"",
66790 + __get_str(filename))
66791 +);
66792 +
66793 +#endif /* _TRACE_FS_H */
66794 +
66795 +/* This part must be outside protection */
66796 +#include <trace/define_trace.h>
66797 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
66798 index 1c09820..7f5ec79 100644
66799 --- a/include/trace/events/irq.h
66800 +++ b/include/trace/events/irq.h
66801 @@ -36,7 +36,7 @@ struct softirq_action;
66802 */
66803 TRACE_EVENT(irq_handler_entry,
66804
66805 - TP_PROTO(int irq, struct irqaction *action),
66806 + TP_PROTO(int irq, const struct irqaction *action),
66807
66808 TP_ARGS(irq, action),
66809
66810 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66811 */
66812 TRACE_EVENT(irq_handler_exit,
66813
66814 - TP_PROTO(int irq, struct irqaction *action, int ret),
66815 + TP_PROTO(int irq, const struct irqaction *action, int ret),
66816
66817 TP_ARGS(irq, action, ret),
66818
66819 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
66820 index 7caf44c..23c6f27 100644
66821 --- a/include/uapi/linux/a.out.h
66822 +++ b/include/uapi/linux/a.out.h
66823 @@ -39,6 +39,14 @@ enum machine_type {
66824 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
66825 };
66826
66827 +/* Constants for the N_FLAGS field */
66828 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
66829 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
66830 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
66831 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
66832 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
66833 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
66834 +
66835 #if !defined (N_MAGIC)
66836 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
66837 #endif
66838 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
66839 index d876736..b36014e 100644
66840 --- a/include/uapi/linux/byteorder/little_endian.h
66841 +++ b/include/uapi/linux/byteorder/little_endian.h
66842 @@ -42,51 +42,51 @@
66843
66844 static inline __le64 __cpu_to_le64p(const __u64 *p)
66845 {
66846 - return (__force __le64)*p;
66847 + return (__force const __le64)*p;
66848 }
66849 static inline __u64 __le64_to_cpup(const __le64 *p)
66850 {
66851 - return (__force __u64)*p;
66852 + return (__force const __u64)*p;
66853 }
66854 static inline __le32 __cpu_to_le32p(const __u32 *p)
66855 {
66856 - return (__force __le32)*p;
66857 + return (__force const __le32)*p;
66858 }
66859 static inline __u32 __le32_to_cpup(const __le32 *p)
66860 {
66861 - return (__force __u32)*p;
66862 + return (__force const __u32)*p;
66863 }
66864 static inline __le16 __cpu_to_le16p(const __u16 *p)
66865 {
66866 - return (__force __le16)*p;
66867 + return (__force const __le16)*p;
66868 }
66869 static inline __u16 __le16_to_cpup(const __le16 *p)
66870 {
66871 - return (__force __u16)*p;
66872 + return (__force const __u16)*p;
66873 }
66874 static inline __be64 __cpu_to_be64p(const __u64 *p)
66875 {
66876 - return (__force __be64)__swab64p(p);
66877 + return (__force const __be64)__swab64p(p);
66878 }
66879 static inline __u64 __be64_to_cpup(const __be64 *p)
66880 {
66881 - return __swab64p((__u64 *)p);
66882 + return __swab64p((const __u64 *)p);
66883 }
66884 static inline __be32 __cpu_to_be32p(const __u32 *p)
66885 {
66886 - return (__force __be32)__swab32p(p);
66887 + return (__force const __be32)__swab32p(p);
66888 }
66889 static inline __u32 __be32_to_cpup(const __be32 *p)
66890 {
66891 - return __swab32p((__u32 *)p);
66892 + return __swab32p((const __u32 *)p);
66893 }
66894 static inline __be16 __cpu_to_be16p(const __u16 *p)
66895 {
66896 - return (__force __be16)__swab16p(p);
66897 + return (__force const __be16)__swab16p(p);
66898 }
66899 static inline __u16 __be16_to_cpup(const __be16 *p)
66900 {
66901 - return __swab16p((__u16 *)p);
66902 + return __swab16p((const __u16 *)p);
66903 }
66904 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
66905 #define __le64_to_cpus(x) do { (void)(x); } while (0)
66906 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
66907 index 126a817..d522bd1 100644
66908 --- a/include/uapi/linux/elf.h
66909 +++ b/include/uapi/linux/elf.h
66910 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
66911 #define PT_GNU_EH_FRAME 0x6474e550
66912
66913 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
66914 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
66915 +
66916 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
66917 +
66918 +/* Constants for the e_flags field */
66919 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
66920 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
66921 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
66922 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
66923 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
66924 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
66925
66926 /*
66927 * Extended Numbering
66928 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
66929 #define DT_DEBUG 21
66930 #define DT_TEXTREL 22
66931 #define DT_JMPREL 23
66932 +#define DT_FLAGS 30
66933 + #define DF_TEXTREL 0x00000004
66934 #define DT_ENCODING 32
66935 #define OLD_DT_LOOS 0x60000000
66936 #define DT_LOOS 0x6000000d
66937 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
66938 #define PF_W 0x2
66939 #define PF_X 0x1
66940
66941 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
66942 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
66943 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
66944 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
66945 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
66946 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
66947 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
66948 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
66949 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
66950 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
66951 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
66952 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
66953 +
66954 typedef struct elf32_phdr{
66955 Elf32_Word p_type;
66956 Elf32_Off p_offset;
66957 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
66958 #define EI_OSABI 7
66959 #define EI_PAD 8
66960
66961 +#define EI_PAX 14
66962 +
66963 #define ELFMAG0 0x7f /* EI_MAG */
66964 #define ELFMAG1 'E'
66965 #define ELFMAG2 'L'
66966 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
66967 index aa169c4..6a2771d 100644
66968 --- a/include/uapi/linux/personality.h
66969 +++ b/include/uapi/linux/personality.h
66970 @@ -30,6 +30,7 @@ enum {
66971 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
66972 ADDR_NO_RANDOMIZE | \
66973 ADDR_COMPAT_LAYOUT | \
66974 + ADDR_LIMIT_3GB | \
66975 MMAP_PAGE_ZERO)
66976
66977 /*
66978 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
66979 index 7530e74..e714828 100644
66980 --- a/include/uapi/linux/screen_info.h
66981 +++ b/include/uapi/linux/screen_info.h
66982 @@ -43,7 +43,8 @@ struct screen_info {
66983 __u16 pages; /* 0x32 */
66984 __u16 vesa_attributes; /* 0x34 */
66985 __u32 capabilities; /* 0x36 */
66986 - __u8 _reserved[6]; /* 0x3a */
66987 + __u16 vesapm_size; /* 0x3a */
66988 + __u8 _reserved[4]; /* 0x3c */
66989 } __attribute__((packed));
66990
66991 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
66992 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
66993 index 6d67213..8dab561 100644
66994 --- a/include/uapi/linux/sysctl.h
66995 +++ b/include/uapi/linux/sysctl.h
66996 @@ -155,7 +155,11 @@ enum
66997 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
66998 };
66999
67000 -
67001 +#ifdef CONFIG_PAX_SOFTMODE
67002 +enum {
67003 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67004 +};
67005 +#endif
67006
67007 /* CTL_VM names: */
67008 enum
67009 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67010 index 26607bd..588b65f 100644
67011 --- a/include/uapi/linux/xattr.h
67012 +++ b/include/uapi/linux/xattr.h
67013 @@ -60,5 +60,9 @@
67014 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67015 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67016
67017 +/* User namespace */
67018 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67019 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
67020 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67021
67022 #endif /* _UAPI_LINUX_XATTR_H */
67023 diff --git a/include/video/omapdss.h b/include/video/omapdss.h
67024 index 3729173..7b2df7e 100644
67025 --- a/include/video/omapdss.h
67026 +++ b/include/video/omapdss.h
67027 @@ -323,7 +323,7 @@ struct omap_dss_board_info {
67028 int (*dsi_enable_pads)(int dsi_id, unsigned lane_mask);
67029 void (*dsi_disable_pads)(int dsi_id, unsigned lane_mask);
67030 int (*set_min_bus_tput)(struct device *dev, unsigned long r);
67031 -};
67032 +} __do_const;
67033
67034 /* Init with the board info */
67035 extern int omap_display_init(struct omap_dss_board_info *board_data);
67036 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67037 index f9466fa..f4e2b81 100644
67038 --- a/include/video/udlfb.h
67039 +++ b/include/video/udlfb.h
67040 @@ -53,10 +53,10 @@ struct dlfb_data {
67041 u32 pseudo_palette[256];
67042 int blank_mode; /*one of FB_BLANK_ */
67043 /* blit-only rendering path metrics, exposed through sysfs */
67044 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67045 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67046 - atomic_t bytes_sent; /* to usb, after compression including overhead */
67047 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67048 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67049 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67050 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67051 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67052 };
67053
67054 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67055 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67056 index 0993a22..32ba2fe 100644
67057 --- a/include/video/uvesafb.h
67058 +++ b/include/video/uvesafb.h
67059 @@ -177,6 +177,7 @@ struct uvesafb_par {
67060 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67061 u8 pmi_setpal; /* PMI for palette changes */
67062 u16 *pmi_base; /* protected mode interface location */
67063 + u8 *pmi_code; /* protected mode code location */
67064 void *pmi_start;
67065 void *pmi_pal;
67066 u8 *vbe_state_orig; /*
67067 diff --git a/init/Kconfig b/init/Kconfig
67068 index 6fdd6e3..5b01610 100644
67069 --- a/init/Kconfig
67070 +++ b/init/Kconfig
67071 @@ -925,6 +925,7 @@ endif # CGROUPS
67072
67073 config CHECKPOINT_RESTORE
67074 bool "Checkpoint/restore support" if EXPERT
67075 + depends on !GRKERNSEC
67076 default n
67077 help
67078 Enables additional kernel features in a sake of checkpoint/restore.
67079 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67080 depends on OCFS2_FS = n
67081 depends on XFS_FS = n
67082
67083 + depends on GRKERNSEC = n
67084 +
67085 config UIDGID_STRICT_TYPE_CHECKS
67086 bool "Require conversions between uid/gids and their internal representation"
67087 depends on UIDGID_CONVERTED
67088 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67089
67090 config COMPAT_BRK
67091 bool "Disable heap randomization"
67092 - default y
67093 + default n
67094 help
67095 Randomizing heap placement makes heap exploits harder, but it
67096 also breaks ancient binaries (including anything libc5 based).
67097 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67098 config STOP_MACHINE
67099 bool
67100 default y
67101 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67102 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67103 help
67104 Need stop_machine() primitive.
67105
67106 diff --git a/init/Makefile b/init/Makefile
67107 index 7bc47ee..6da2dc7 100644
67108 --- a/init/Makefile
67109 +++ b/init/Makefile
67110 @@ -2,6 +2,9 @@
67111 # Makefile for the linux kernel.
67112 #
67113
67114 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
67115 +asflags-y := $(GCC_PLUGINS_AFLAGS)
67116 +
67117 obj-y := main.o version.o mounts.o
67118 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67119 obj-y += noinitramfs.o
67120 diff --git a/init/do_mounts.c b/init/do_mounts.c
67121 index f8a6642..4e5ee1b 100644
67122 --- a/init/do_mounts.c
67123 +++ b/init/do_mounts.c
67124 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67125 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67126 {
67127 struct super_block *s;
67128 - int err = sys_mount(name, "/root", fs, flags, data);
67129 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67130 if (err)
67131 return err;
67132
67133 - sys_chdir("/root");
67134 + sys_chdir((const char __force_user *)"/root");
67135 s = current->fs->pwd.dentry->d_sb;
67136 ROOT_DEV = s->s_dev;
67137 printk(KERN_INFO
67138 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67139 va_start(args, fmt);
67140 vsprintf(buf, fmt, args);
67141 va_end(args);
67142 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67143 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67144 if (fd >= 0) {
67145 sys_ioctl(fd, FDEJECT, 0);
67146 sys_close(fd);
67147 }
67148 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67149 - fd = sys_open("/dev/console", O_RDWR, 0);
67150 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67151 if (fd >= 0) {
67152 sys_ioctl(fd, TCGETS, (long)&termios);
67153 termios.c_lflag &= ~ICANON;
67154 sys_ioctl(fd, TCSETSF, (long)&termios);
67155 - sys_read(fd, &c, 1);
67156 + sys_read(fd, (char __user *)&c, 1);
67157 termios.c_lflag |= ICANON;
67158 sys_ioctl(fd, TCSETSF, (long)&termios);
67159 sys_close(fd);
67160 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67161 mount_root();
67162 out:
67163 devtmpfs_mount("dev");
67164 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
67165 - sys_chroot(".");
67166 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
67167 + sys_chroot((const char __force_user *)".");
67168 }
67169 diff --git a/init/do_mounts.h b/init/do_mounts.h
67170 index f5b978a..69dbfe8 100644
67171 --- a/init/do_mounts.h
67172 +++ b/init/do_mounts.h
67173 @@ -15,15 +15,15 @@ extern int root_mountflags;
67174
67175 static inline int create_dev(char *name, dev_t dev)
67176 {
67177 - sys_unlink(name);
67178 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
67179 + sys_unlink((char __force_user *)name);
67180 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
67181 }
67182
67183 #if BITS_PER_LONG == 32
67184 static inline u32 bstat(char *name)
67185 {
67186 struct stat64 stat;
67187 - if (sys_stat64(name, &stat) != 0)
67188 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
67189 return 0;
67190 if (!S_ISBLK(stat.st_mode))
67191 return 0;
67192 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
67193 static inline u32 bstat(char *name)
67194 {
67195 struct stat stat;
67196 - if (sys_newstat(name, &stat) != 0)
67197 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
67198 return 0;
67199 if (!S_ISBLK(stat.st_mode))
67200 return 0;
67201 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
67202 index 5e4ded5..aa3cd7e 100644
67203 --- a/init/do_mounts_initrd.c
67204 +++ b/init/do_mounts_initrd.c
67205 @@ -54,8 +54,8 @@ static void __init handle_initrd(void)
67206 create_dev("/dev/root.old", Root_RAM0);
67207 /* mount initrd on rootfs' /root */
67208 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
67209 - sys_mkdir("/old", 0700);
67210 - sys_chdir("/old");
67211 + sys_mkdir((const char __force_user *)"/old", 0700);
67212 + sys_chdir((const char __force_user *)"/old");
67213
67214 /*
67215 * In case that a resume from disk is carried out by linuxrc or one of
67216 @@ -69,31 +69,31 @@ static void __init handle_initrd(void)
67217 current->flags &= ~PF_FREEZER_SKIP;
67218
67219 /* move initrd to rootfs' /old */
67220 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
67221 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
67222 /* switch root and cwd back to / of rootfs */
67223 - sys_chroot("..");
67224 + sys_chroot((const char __force_user *)"..");
67225
67226 if (new_decode_dev(real_root_dev) == Root_RAM0) {
67227 - sys_chdir("/old");
67228 + sys_chdir((const char __force_user *)"/old");
67229 return;
67230 }
67231
67232 - sys_chdir("/");
67233 + sys_chdir((const char __force_user *)"/");
67234 ROOT_DEV = new_decode_dev(real_root_dev);
67235 mount_root();
67236
67237 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
67238 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
67239 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
67240 if (!error)
67241 printk("okay\n");
67242 else {
67243 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
67244 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
67245 if (error == -ENOENT)
67246 printk("/initrd does not exist. Ignored.\n");
67247 else
67248 printk("failed\n");
67249 printk(KERN_NOTICE "Unmounting old root\n");
67250 - sys_umount("/old", MNT_DETACH);
67251 + sys_umount((char __force_user *)"/old", MNT_DETACH);
67252 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
67253 if (fd < 0) {
67254 error = fd;
67255 @@ -116,11 +116,11 @@ int __init initrd_load(void)
67256 * mounted in the normal path.
67257 */
67258 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
67259 - sys_unlink("/initrd.image");
67260 + sys_unlink((const char __force_user *)"/initrd.image");
67261 handle_initrd();
67262 return 1;
67263 }
67264 }
67265 - sys_unlink("/initrd.image");
67266 + sys_unlink((const char __force_user *)"/initrd.image");
67267 return 0;
67268 }
67269 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
67270 index 8cb6db5..d729f50 100644
67271 --- a/init/do_mounts_md.c
67272 +++ b/init/do_mounts_md.c
67273 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
67274 partitioned ? "_d" : "", minor,
67275 md_setup_args[ent].device_names);
67276
67277 - fd = sys_open(name, 0, 0);
67278 + fd = sys_open((char __force_user *)name, 0, 0);
67279 if (fd < 0) {
67280 printk(KERN_ERR "md: open failed - cannot start "
67281 "array %s\n", name);
67282 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
67283 * array without it
67284 */
67285 sys_close(fd);
67286 - fd = sys_open(name, 0, 0);
67287 + fd = sys_open((char __force_user *)name, 0, 0);
67288 sys_ioctl(fd, BLKRRPART, 0);
67289 }
67290 sys_close(fd);
67291 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
67292
67293 wait_for_device_probe();
67294
67295 - fd = sys_open("/dev/md0", 0, 0);
67296 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
67297 if (fd >= 0) {
67298 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
67299 sys_close(fd);
67300 diff --git a/init/init_task.c b/init/init_task.c
67301 index 8b2f399..f0797c9 100644
67302 --- a/init/init_task.c
67303 +++ b/init/init_task.c
67304 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
67305 * Initial thread structure. Alignment of this is handled by a special
67306 * linker map entry.
67307 */
67308 +#ifdef CONFIG_X86
67309 +union thread_union init_thread_union __init_task_data;
67310 +#else
67311 union thread_union init_thread_union __init_task_data =
67312 { INIT_THREAD_INFO(init_task) };
67313 +#endif
67314 diff --git a/init/initramfs.c b/init/initramfs.c
67315 index 84c6bf1..8899338 100644
67316 --- a/init/initramfs.c
67317 +++ b/init/initramfs.c
67318 @@ -84,7 +84,7 @@ static void __init free_hash(void)
67319 }
67320 }
67321
67322 -static long __init do_utime(char *filename, time_t mtime)
67323 +static long __init do_utime(char __force_user *filename, time_t mtime)
67324 {
67325 struct timespec t[2];
67326
67327 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
67328 struct dir_entry *de, *tmp;
67329 list_for_each_entry_safe(de, tmp, &dir_list, list) {
67330 list_del(&de->list);
67331 - do_utime(de->name, de->mtime);
67332 + do_utime((char __force_user *)de->name, de->mtime);
67333 kfree(de->name);
67334 kfree(de);
67335 }
67336 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
67337 if (nlink >= 2) {
67338 char *old = find_link(major, minor, ino, mode, collected);
67339 if (old)
67340 - return (sys_link(old, collected) < 0) ? -1 : 1;
67341 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
67342 }
67343 return 0;
67344 }
67345 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
67346 {
67347 struct stat st;
67348
67349 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
67350 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
67351 if (S_ISDIR(st.st_mode))
67352 - sys_rmdir(path);
67353 + sys_rmdir((char __force_user *)path);
67354 else
67355 - sys_unlink(path);
67356 + sys_unlink((char __force_user *)path);
67357 }
67358 }
67359
67360 @@ -315,7 +315,7 @@ static int __init do_name(void)
67361 int openflags = O_WRONLY|O_CREAT;
67362 if (ml != 1)
67363 openflags |= O_TRUNC;
67364 - wfd = sys_open(collected, openflags, mode);
67365 + wfd = sys_open((char __force_user *)collected, openflags, mode);
67366
67367 if (wfd >= 0) {
67368 sys_fchown(wfd, uid, gid);
67369 @@ -327,17 +327,17 @@ static int __init do_name(void)
67370 }
67371 }
67372 } else if (S_ISDIR(mode)) {
67373 - sys_mkdir(collected, mode);
67374 - sys_chown(collected, uid, gid);
67375 - sys_chmod(collected, mode);
67376 + sys_mkdir((char __force_user *)collected, mode);
67377 + sys_chown((char __force_user *)collected, uid, gid);
67378 + sys_chmod((char __force_user *)collected, mode);
67379 dir_add(collected, mtime);
67380 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
67381 S_ISFIFO(mode) || S_ISSOCK(mode)) {
67382 if (maybe_link() == 0) {
67383 - sys_mknod(collected, mode, rdev);
67384 - sys_chown(collected, uid, gid);
67385 - sys_chmod(collected, mode);
67386 - do_utime(collected, mtime);
67387 + sys_mknod((char __force_user *)collected, mode, rdev);
67388 + sys_chown((char __force_user *)collected, uid, gid);
67389 + sys_chmod((char __force_user *)collected, mode);
67390 + do_utime((char __force_user *)collected, mtime);
67391 }
67392 }
67393 return 0;
67394 @@ -346,15 +346,15 @@ static int __init do_name(void)
67395 static int __init do_copy(void)
67396 {
67397 if (count >= body_len) {
67398 - sys_write(wfd, victim, body_len);
67399 + sys_write(wfd, (char __force_user *)victim, body_len);
67400 sys_close(wfd);
67401 - do_utime(vcollected, mtime);
67402 + do_utime((char __force_user *)vcollected, mtime);
67403 kfree(vcollected);
67404 eat(body_len);
67405 state = SkipIt;
67406 return 0;
67407 } else {
67408 - sys_write(wfd, victim, count);
67409 + sys_write(wfd, (char __force_user *)victim, count);
67410 body_len -= count;
67411 eat(count);
67412 return 1;
67413 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
67414 {
67415 collected[N_ALIGN(name_len) + body_len] = '\0';
67416 clean_path(collected, 0);
67417 - sys_symlink(collected + N_ALIGN(name_len), collected);
67418 - sys_lchown(collected, uid, gid);
67419 - do_utime(collected, mtime);
67420 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
67421 + sys_lchown((char __force_user *)collected, uid, gid);
67422 + do_utime((char __force_user *)collected, mtime);
67423 state = SkipIt;
67424 next_state = Reset;
67425 return 0;
67426 diff --git a/init/main.c b/init/main.c
67427 index e33e09d..b699703 100644
67428 --- a/init/main.c
67429 +++ b/init/main.c
67430 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
67431 extern void tc_init(void);
67432 #endif
67433
67434 +extern void grsecurity_init(void);
67435 +
67436 /*
67437 * Debug helper: via this flag we know that we are in 'early bootup code'
67438 * where only the boot processor is running with IRQ disabled. This means
67439 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
67440
67441 __setup("reset_devices", set_reset_devices);
67442
67443 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67444 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
67445 +static int __init setup_grsec_proc_gid(char *str)
67446 +{
67447 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
67448 + return 1;
67449 +}
67450 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
67451 +#endif
67452 +
67453 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
67454 +extern char pax_enter_kernel_user[];
67455 +extern char pax_exit_kernel_user[];
67456 +extern pgdval_t clone_pgd_mask;
67457 +#endif
67458 +
67459 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
67460 +static int __init setup_pax_nouderef(char *str)
67461 +{
67462 +#ifdef CONFIG_X86_32
67463 + unsigned int cpu;
67464 + struct desc_struct *gdt;
67465 +
67466 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
67467 + gdt = get_cpu_gdt_table(cpu);
67468 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
67469 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
67470 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
67471 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
67472 + }
67473 + loadsegment(ds, __KERNEL_DS);
67474 + loadsegment(es, __KERNEL_DS);
67475 + loadsegment(ss, __KERNEL_DS);
67476 +#else
67477 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
67478 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
67479 + clone_pgd_mask = ~(pgdval_t)0UL;
67480 +#endif
67481 +
67482 + return 0;
67483 +}
67484 +early_param("pax_nouderef", setup_pax_nouderef);
67485 +#endif
67486 +
67487 +#ifdef CONFIG_PAX_SOFTMODE
67488 +int pax_softmode;
67489 +
67490 +static int __init setup_pax_softmode(char *str)
67491 +{
67492 + get_option(&str, &pax_softmode);
67493 + return 1;
67494 +}
67495 +__setup("pax_softmode=", setup_pax_softmode);
67496 +#endif
67497 +
67498 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
67499 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
67500 static const char *panic_later, *panic_param;
67501 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
67502 {
67503 int count = preempt_count();
67504 int ret;
67505 + const char *msg1 = "", *msg2 = "";
67506
67507 if (initcall_debug)
67508 ret = do_one_initcall_debug(fn);
67509 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
67510 sprintf(msgbuf, "error code %d ", ret);
67511
67512 if (preempt_count() != count) {
67513 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
67514 + msg1 = " preemption imbalance";
67515 preempt_count() = count;
67516 }
67517 if (irqs_disabled()) {
67518 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
67519 + msg2 = " disabled interrupts";
67520 local_irq_enable();
67521 }
67522 - if (msgbuf[0]) {
67523 - printk("initcall %pF returned with %s\n", fn, msgbuf);
67524 + if (msgbuf[0] || *msg1 || *msg2) {
67525 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
67526 }
67527
67528 return ret;
67529 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
67530 "late",
67531 };
67532
67533 +#ifdef CONFIG_PAX_LATENT_ENTROPY
67534 +u64 latent_entropy;
67535 +#endif
67536 +
67537 static void __init do_initcall_level(int level)
67538 {
67539 extern const struct kernel_param __start___param[], __stop___param[];
67540 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
67541 level, level,
67542 &repair_env_string);
67543
67544 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
67545 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
67546 do_one_initcall(*fn);
67547 +
67548 +#ifdef CONFIG_PAX_LATENT_ENTROPY
67549 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
67550 +#endif
67551 +
67552 + }
67553 }
67554
67555 static void __init do_initcalls(void)
67556 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
67557 {
67558 initcall_t *fn;
67559
67560 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
67561 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
67562 do_one_initcall(*fn);
67563 +
67564 +#ifdef CONFIG_PAX_LATENT_ENTROPY
67565 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
67566 +#endif
67567 +
67568 + }
67569 }
67570
67571 static int run_init_process(const char *init_filename)
67572 @@ -876,7 +950,7 @@ static void __init kernel_init_freeable(void)
67573 do_basic_setup();
67574
67575 /* Open the /dev/console on the rootfs, this should never fail */
67576 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
67577 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
67578 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
67579
67580 (void) sys_dup(0);
67581 @@ -889,11 +963,13 @@ static void __init kernel_init_freeable(void)
67582 if (!ramdisk_execute_command)
67583 ramdisk_execute_command = "/init";
67584
67585 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
67586 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
67587 ramdisk_execute_command = NULL;
67588 prepare_namespace();
67589 }
67590
67591 + grsecurity_init();
67592 +
67593 /*
67594 * Ok, we have completed the initial bootup, and
67595 * we're essentially up and running. Get rid of the
67596 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
67597 index 71a3ca1..cc330ee 100644
67598 --- a/ipc/mqueue.c
67599 +++ b/ipc/mqueue.c
67600 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
67601 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
67602 info->attr.mq_msgsize);
67603
67604 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
67605 spin_lock(&mq_lock);
67606 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
67607 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
67608 diff --git a/ipc/msg.c b/ipc/msg.c
67609 index a71af5a..a90a110 100644
67610 --- a/ipc/msg.c
67611 +++ b/ipc/msg.c
67612 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
67613 return security_msg_queue_associate(msq, msgflg);
67614 }
67615
67616 +static struct ipc_ops msg_ops = {
67617 + .getnew = newque,
67618 + .associate = msg_security,
67619 + .more_checks = NULL
67620 +};
67621 +
67622 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
67623 {
67624 struct ipc_namespace *ns;
67625 - struct ipc_ops msg_ops;
67626 struct ipc_params msg_params;
67627
67628 ns = current->nsproxy->ipc_ns;
67629
67630 - msg_ops.getnew = newque;
67631 - msg_ops.associate = msg_security;
67632 - msg_ops.more_checks = NULL;
67633 -
67634 msg_params.key = key;
67635 msg_params.flg = msgflg;
67636
67637 diff --git a/ipc/sem.c b/ipc/sem.c
67638 index 58d31f1..cce7a55 100644
67639 --- a/ipc/sem.c
67640 +++ b/ipc/sem.c
67641 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
67642 return 0;
67643 }
67644
67645 +static struct ipc_ops sem_ops = {
67646 + .getnew = newary,
67647 + .associate = sem_security,
67648 + .more_checks = sem_more_checks
67649 +};
67650 +
67651 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
67652 {
67653 struct ipc_namespace *ns;
67654 - struct ipc_ops sem_ops;
67655 struct ipc_params sem_params;
67656
67657 ns = current->nsproxy->ipc_ns;
67658 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
67659 if (nsems < 0 || nsems > ns->sc_semmsl)
67660 return -EINVAL;
67661
67662 - sem_ops.getnew = newary;
67663 - sem_ops.associate = sem_security;
67664 - sem_ops.more_checks = sem_more_checks;
67665 -
67666 sem_params.key = key;
67667 sem_params.flg = semflg;
67668 sem_params.u.nsems = nsems;
67669 diff --git a/ipc/shm.c b/ipc/shm.c
67670 index dff40c9..9450e27 100644
67671 --- a/ipc/shm.c
67672 +++ b/ipc/shm.c
67673 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
67674 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
67675 #endif
67676
67677 +#ifdef CONFIG_GRKERNSEC
67678 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
67679 + const time_t shm_createtime, const uid_t cuid,
67680 + const int shmid);
67681 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
67682 + const time_t shm_createtime);
67683 +#endif
67684 +
67685 void shm_init_ns(struct ipc_namespace *ns)
67686 {
67687 ns->shm_ctlmax = SHMMAX;
67688 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
67689 shp->shm_lprid = 0;
67690 shp->shm_atim = shp->shm_dtim = 0;
67691 shp->shm_ctim = get_seconds();
67692 +#ifdef CONFIG_GRKERNSEC
67693 + {
67694 + struct timespec timeval;
67695 + do_posix_clock_monotonic_gettime(&timeval);
67696 +
67697 + shp->shm_createtime = timeval.tv_sec;
67698 + }
67699 +#endif
67700 shp->shm_segsz = size;
67701 shp->shm_nattch = 0;
67702 shp->shm_file = file;
67703 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
67704 return 0;
67705 }
67706
67707 +static struct ipc_ops shm_ops = {
67708 + .getnew = newseg,
67709 + .associate = shm_security,
67710 + .more_checks = shm_more_checks
67711 +};
67712 +
67713 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
67714 {
67715 struct ipc_namespace *ns;
67716 - struct ipc_ops shm_ops;
67717 struct ipc_params shm_params;
67718
67719 ns = current->nsproxy->ipc_ns;
67720
67721 - shm_ops.getnew = newseg;
67722 - shm_ops.associate = shm_security;
67723 - shm_ops.more_checks = shm_more_checks;
67724 -
67725 shm_params.key = key;
67726 shm_params.flg = shmflg;
67727 shm_params.u.size = size;
67728 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
67729 f_mode = FMODE_READ | FMODE_WRITE;
67730 }
67731 if (shmflg & SHM_EXEC) {
67732 +
67733 +#ifdef CONFIG_PAX_MPROTECT
67734 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
67735 + goto out;
67736 +#endif
67737 +
67738 prot |= PROT_EXEC;
67739 acc_mode |= S_IXUGO;
67740 }
67741 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
67742 if (err)
67743 goto out_unlock;
67744
67745 +#ifdef CONFIG_GRKERNSEC
67746 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
67747 + shp->shm_perm.cuid, shmid) ||
67748 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
67749 + err = -EACCES;
67750 + goto out_unlock;
67751 + }
67752 +#endif
67753 +
67754 path = shp->shm_file->f_path;
67755 path_get(&path);
67756 shp->shm_nattch++;
67757 +#ifdef CONFIG_GRKERNSEC
67758 + shp->shm_lapid = current->pid;
67759 +#endif
67760 size = i_size_read(path.dentry->d_inode);
67761 shm_unlock(shp);
67762
67763 diff --git a/kernel/acct.c b/kernel/acct.c
67764 index 051e071..15e0920 100644
67765 --- a/kernel/acct.c
67766 +++ b/kernel/acct.c
67767 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
67768 */
67769 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
67770 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
67771 - file->f_op->write(file, (char *)&ac,
67772 + file->f_op->write(file, (char __force_user *)&ac,
67773 sizeof(acct_t), &file->f_pos);
67774 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
67775 set_fs(fs);
67776 diff --git a/kernel/audit.c b/kernel/audit.c
67777 index 40414e9..c920b72 100644
67778 --- a/kernel/audit.c
67779 +++ b/kernel/audit.c
67780 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
67781 3) suppressed due to audit_rate_limit
67782 4) suppressed due to audit_backlog_limit
67783 */
67784 -static atomic_t audit_lost = ATOMIC_INIT(0);
67785 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
67786
67787 /* The netlink socket. */
67788 static struct sock *audit_sock;
67789 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
67790 unsigned long now;
67791 int print;
67792
67793 - atomic_inc(&audit_lost);
67794 + atomic_inc_unchecked(&audit_lost);
67795
67796 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
67797
67798 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
67799 printk(KERN_WARNING
67800 "audit: audit_lost=%d audit_rate_limit=%d "
67801 "audit_backlog_limit=%d\n",
67802 - atomic_read(&audit_lost),
67803 + atomic_read_unchecked(&audit_lost),
67804 audit_rate_limit,
67805 audit_backlog_limit);
67806 audit_panic(message);
67807 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
67808 status_set.pid = audit_pid;
67809 status_set.rate_limit = audit_rate_limit;
67810 status_set.backlog_limit = audit_backlog_limit;
67811 - status_set.lost = atomic_read(&audit_lost);
67812 + status_set.lost = atomic_read_unchecked(&audit_lost);
67813 status_set.backlog = skb_queue_len(&audit_skb_queue);
67814 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
67815 &status_set, sizeof(status_set));
67816 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
67817 index 157e989..b28b365 100644
67818 --- a/kernel/auditsc.c
67819 +++ b/kernel/auditsc.c
67820 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
67821 }
67822
67823 /* global counter which is incremented every time something logs in */
67824 -static atomic_t session_id = ATOMIC_INIT(0);
67825 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
67826
67827 /**
67828 * audit_set_loginuid - set current task's audit_context loginuid
67829 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
67830 return -EPERM;
67831 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
67832
67833 - sessionid = atomic_inc_return(&session_id);
67834 + sessionid = atomic_inc_return_unchecked(&session_id);
67835 if (context && context->in_syscall) {
67836 struct audit_buffer *ab;
67837
67838 diff --git a/kernel/capability.c b/kernel/capability.c
67839 index 493d972..ea17248 100644
67840 --- a/kernel/capability.c
67841 +++ b/kernel/capability.c
67842 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
67843 * before modification is attempted and the application
67844 * fails.
67845 */
67846 + if (tocopy > ARRAY_SIZE(kdata))
67847 + return -EFAULT;
67848 +
67849 if (copy_to_user(dataptr, kdata, tocopy
67850 * sizeof(struct __user_cap_data_struct))) {
67851 return -EFAULT;
67852 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
67853 int ret;
67854
67855 rcu_read_lock();
67856 - ret = security_capable(__task_cred(t), ns, cap);
67857 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
67858 + gr_task_is_capable(t, __task_cred(t), cap);
67859 rcu_read_unlock();
67860
67861 - return (ret == 0);
67862 + return ret;
67863 }
67864
67865 /**
67866 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
67867 int ret;
67868
67869 rcu_read_lock();
67870 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
67871 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
67872 rcu_read_unlock();
67873
67874 - return (ret == 0);
67875 + return ret;
67876 }
67877
67878 /**
67879 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
67880 BUG();
67881 }
67882
67883 - if (security_capable(current_cred(), ns, cap) == 0) {
67884 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
67885 current->flags |= PF_SUPERPRIV;
67886 return true;
67887 }
67888 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
67889 }
67890 EXPORT_SYMBOL(ns_capable);
67891
67892 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
67893 +{
67894 + if (unlikely(!cap_valid(cap))) {
67895 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
67896 + BUG();
67897 + }
67898 +
67899 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
67900 + current->flags |= PF_SUPERPRIV;
67901 + return true;
67902 + }
67903 + return false;
67904 +}
67905 +EXPORT_SYMBOL(ns_capable_nolog);
67906 +
67907 /**
67908 * capable - Determine if the current task has a superior capability in effect
67909 * @cap: The capability to be tested for
67910 @@ -408,6 +427,12 @@ bool capable(int cap)
67911 }
67912 EXPORT_SYMBOL(capable);
67913
67914 +bool capable_nolog(int cap)
67915 +{
67916 + return ns_capable_nolog(&init_user_ns, cap);
67917 +}
67918 +EXPORT_SYMBOL(capable_nolog);
67919 +
67920 /**
67921 * nsown_capable - Check superior capability to one's own user_ns
67922 * @cap: The capability in question
67923 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
67924
67925 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67926 }
67927 +
67928 +bool inode_capable_nolog(const struct inode *inode, int cap)
67929 +{
67930 + struct user_namespace *ns = current_user_ns();
67931 +
67932 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67933 +}
67934 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
67935 index ad99830..992d8a7 100644
67936 --- a/kernel/cgroup.c
67937 +++ b/kernel/cgroup.c
67938 @@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
67939 struct css_set *cg = link->cg;
67940 struct task_struct *task;
67941 int count = 0;
67942 - seq_printf(seq, "css_set %p\n", cg);
67943 + seq_printf(seq, "css_set %pK\n", cg);
67944 list_for_each_entry(task, &cg->tasks, cg_list) {
67945 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
67946 seq_puts(seq, " ...\n");
67947 diff --git a/kernel/compat.c b/kernel/compat.c
67948 index c28a306..b4d0cf3 100644
67949 --- a/kernel/compat.c
67950 +++ b/kernel/compat.c
67951 @@ -13,6 +13,7 @@
67952
67953 #include <linux/linkage.h>
67954 #include <linux/compat.h>
67955 +#include <linux/module.h>
67956 #include <linux/errno.h>
67957 #include <linux/time.h>
67958 #include <linux/signal.h>
67959 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
67960 mm_segment_t oldfs;
67961 long ret;
67962
67963 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
67964 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
67965 oldfs = get_fs();
67966 set_fs(KERNEL_DS);
67967 ret = hrtimer_nanosleep_restart(restart);
67968 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
67969 oldfs = get_fs();
67970 set_fs(KERNEL_DS);
67971 ret = hrtimer_nanosleep(&tu,
67972 - rmtp ? (struct timespec __user *)&rmt : NULL,
67973 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
67974 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
67975 set_fs(oldfs);
67976
67977 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
67978 mm_segment_t old_fs = get_fs();
67979
67980 set_fs(KERNEL_DS);
67981 - ret = sys_sigpending((old_sigset_t __user *) &s);
67982 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
67983 set_fs(old_fs);
67984 if (ret == 0)
67985 ret = put_user(s, set);
67986 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
67987 mm_segment_t old_fs = get_fs();
67988
67989 set_fs(KERNEL_DS);
67990 - ret = sys_old_getrlimit(resource, &r);
67991 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
67992 set_fs(old_fs);
67993
67994 if (!ret) {
67995 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
67996 mm_segment_t old_fs = get_fs();
67997
67998 set_fs(KERNEL_DS);
67999 - ret = sys_getrusage(who, (struct rusage __user *) &r);
68000 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68001 set_fs(old_fs);
68002
68003 if (ret)
68004 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68005 set_fs (KERNEL_DS);
68006 ret = sys_wait4(pid,
68007 (stat_addr ?
68008 - (unsigned int __user *) &status : NULL),
68009 - options, (struct rusage __user *) &r);
68010 + (unsigned int __force_user *) &status : NULL),
68011 + options, (struct rusage __force_user *) &r);
68012 set_fs (old_fs);
68013
68014 if (ret > 0) {
68015 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68016 memset(&info, 0, sizeof(info));
68017
68018 set_fs(KERNEL_DS);
68019 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68020 - uru ? (struct rusage __user *)&ru : NULL);
68021 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68022 + uru ? (struct rusage __force_user *)&ru : NULL);
68023 set_fs(old_fs);
68024
68025 if ((ret < 0) || (info.si_signo == 0))
68026 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68027 oldfs = get_fs();
68028 set_fs(KERNEL_DS);
68029 err = sys_timer_settime(timer_id, flags,
68030 - (struct itimerspec __user *) &newts,
68031 - (struct itimerspec __user *) &oldts);
68032 + (struct itimerspec __force_user *) &newts,
68033 + (struct itimerspec __force_user *) &oldts);
68034 set_fs(oldfs);
68035 if (!err && old && put_compat_itimerspec(old, &oldts))
68036 return -EFAULT;
68037 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68038 oldfs = get_fs();
68039 set_fs(KERNEL_DS);
68040 err = sys_timer_gettime(timer_id,
68041 - (struct itimerspec __user *) &ts);
68042 + (struct itimerspec __force_user *) &ts);
68043 set_fs(oldfs);
68044 if (!err && put_compat_itimerspec(setting, &ts))
68045 return -EFAULT;
68046 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68047 oldfs = get_fs();
68048 set_fs(KERNEL_DS);
68049 err = sys_clock_settime(which_clock,
68050 - (struct timespec __user *) &ts);
68051 + (struct timespec __force_user *) &ts);
68052 set_fs(oldfs);
68053 return err;
68054 }
68055 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68056 oldfs = get_fs();
68057 set_fs(KERNEL_DS);
68058 err = sys_clock_gettime(which_clock,
68059 - (struct timespec __user *) &ts);
68060 + (struct timespec __force_user *) &ts);
68061 set_fs(oldfs);
68062 if (!err && put_compat_timespec(&ts, tp))
68063 return -EFAULT;
68064 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68065
68066 oldfs = get_fs();
68067 set_fs(KERNEL_DS);
68068 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68069 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68070 set_fs(oldfs);
68071
68072 err = compat_put_timex(utp, &txc);
68073 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68074 oldfs = get_fs();
68075 set_fs(KERNEL_DS);
68076 err = sys_clock_getres(which_clock,
68077 - (struct timespec __user *) &ts);
68078 + (struct timespec __force_user *) &ts);
68079 set_fs(oldfs);
68080 if (!err && tp && put_compat_timespec(&ts, tp))
68081 return -EFAULT;
68082 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68083 long err;
68084 mm_segment_t oldfs;
68085 struct timespec tu;
68086 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68087 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68088
68089 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68090 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68091 oldfs = get_fs();
68092 set_fs(KERNEL_DS);
68093 err = clock_nanosleep_restart(restart);
68094 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68095 oldfs = get_fs();
68096 set_fs(KERNEL_DS);
68097 err = sys_clock_nanosleep(which_clock, flags,
68098 - (struct timespec __user *) &in,
68099 - (struct timespec __user *) &out);
68100 + (struct timespec __force_user *) &in,
68101 + (struct timespec __force_user *) &out);
68102 set_fs(oldfs);
68103
68104 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68105 diff --git a/kernel/configs.c b/kernel/configs.c
68106 index 42e8fa0..9e7406b 100644
68107 --- a/kernel/configs.c
68108 +++ b/kernel/configs.c
68109 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68110 struct proc_dir_entry *entry;
68111
68112 /* create the current config file */
68113 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68114 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68115 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68116 + &ikconfig_file_ops);
68117 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68118 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68119 + &ikconfig_file_ops);
68120 +#endif
68121 +#else
68122 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68123 &ikconfig_file_ops);
68124 +#endif
68125 +
68126 if (!entry)
68127 return -ENOMEM;
68128
68129 diff --git a/kernel/cred.c b/kernel/cred.c
68130 index 48cea3d..3476734 100644
68131 --- a/kernel/cred.c
68132 +++ b/kernel/cred.c
68133 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68134 validate_creds(cred);
68135 alter_cred_subscribers(cred, -1);
68136 put_cred(cred);
68137 +
68138 +#ifdef CONFIG_GRKERNSEC_SETXID
68139 + cred = (struct cred *) tsk->delayed_cred;
68140 + if (cred != NULL) {
68141 + tsk->delayed_cred = NULL;
68142 + validate_creds(cred);
68143 + alter_cred_subscribers(cred, -1);
68144 + put_cred(cred);
68145 + }
68146 +#endif
68147 }
68148
68149 /**
68150 @@ -469,7 +479,7 @@ error_put:
68151 * Always returns 0 thus allowing this function to be tail-called at the end
68152 * of, say, sys_setgid().
68153 */
68154 -int commit_creds(struct cred *new)
68155 +static int __commit_creds(struct cred *new)
68156 {
68157 struct task_struct *task = current;
68158 const struct cred *old = task->real_cred;
68159 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68160
68161 get_cred(new); /* we will require a ref for the subj creds too */
68162
68163 + gr_set_role_label(task, new->uid, new->gid);
68164 +
68165 /* dumpability changes */
68166 if (!uid_eq(old->euid, new->euid) ||
68167 !gid_eq(old->egid, new->egid) ||
68168 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
68169 put_cred(old);
68170 return 0;
68171 }
68172 +#ifdef CONFIG_GRKERNSEC_SETXID
68173 +extern int set_user(struct cred *new);
68174 +
68175 +void gr_delayed_cred_worker(void)
68176 +{
68177 + const struct cred *new = current->delayed_cred;
68178 + struct cred *ncred;
68179 +
68180 + current->delayed_cred = NULL;
68181 +
68182 + if (current_uid() && new != NULL) {
68183 + // from doing get_cred on it when queueing this
68184 + put_cred(new);
68185 + return;
68186 + } else if (new == NULL)
68187 + return;
68188 +
68189 + ncred = prepare_creds();
68190 + if (!ncred)
68191 + goto die;
68192 + // uids
68193 + ncred->uid = new->uid;
68194 + ncred->euid = new->euid;
68195 + ncred->suid = new->suid;
68196 + ncred->fsuid = new->fsuid;
68197 + // gids
68198 + ncred->gid = new->gid;
68199 + ncred->egid = new->egid;
68200 + ncred->sgid = new->sgid;
68201 + ncred->fsgid = new->fsgid;
68202 + // groups
68203 + if (set_groups(ncred, new->group_info) < 0) {
68204 + abort_creds(ncred);
68205 + goto die;
68206 + }
68207 + // caps
68208 + ncred->securebits = new->securebits;
68209 + ncred->cap_inheritable = new->cap_inheritable;
68210 + ncred->cap_permitted = new->cap_permitted;
68211 + ncred->cap_effective = new->cap_effective;
68212 + ncred->cap_bset = new->cap_bset;
68213 +
68214 + if (set_user(ncred)) {
68215 + abort_creds(ncred);
68216 + goto die;
68217 + }
68218 +
68219 + // from doing get_cred on it when queueing this
68220 + put_cred(new);
68221 +
68222 + __commit_creds(ncred);
68223 + return;
68224 +die:
68225 + // from doing get_cred on it when queueing this
68226 + put_cred(new);
68227 + do_group_exit(SIGKILL);
68228 +}
68229 +#endif
68230 +
68231 +int commit_creds(struct cred *new)
68232 +{
68233 +#ifdef CONFIG_GRKERNSEC_SETXID
68234 + int ret;
68235 + int schedule_it = 0;
68236 + struct task_struct *t;
68237 +
68238 + /* we won't get called with tasklist_lock held for writing
68239 + and interrupts disabled as the cred struct in that case is
68240 + init_cred
68241 + */
68242 + if (grsec_enable_setxid && !current_is_single_threaded() &&
68243 + !current_uid() && new->uid) {
68244 + schedule_it = 1;
68245 + }
68246 + ret = __commit_creds(new);
68247 + if (schedule_it) {
68248 + rcu_read_lock();
68249 + read_lock(&tasklist_lock);
68250 + for (t = next_thread(current); t != current;
68251 + t = next_thread(t)) {
68252 + if (t->delayed_cred == NULL) {
68253 + t->delayed_cred = get_cred(new);
68254 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
68255 + set_tsk_need_resched(t);
68256 + }
68257 + }
68258 + read_unlock(&tasklist_lock);
68259 + rcu_read_unlock();
68260 + }
68261 + return ret;
68262 +#else
68263 + return __commit_creds(new);
68264 +#endif
68265 +}
68266 +
68267 EXPORT_SYMBOL(commit_creds);
68268
68269 /**
68270 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
68271 index 9a61738..c5c8f3a 100644
68272 --- a/kernel/debug/debug_core.c
68273 +++ b/kernel/debug/debug_core.c
68274 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
68275 */
68276 static atomic_t masters_in_kgdb;
68277 static atomic_t slaves_in_kgdb;
68278 -static atomic_t kgdb_break_tasklet_var;
68279 +static atomic_unchecked_t kgdb_break_tasklet_var;
68280 atomic_t kgdb_setting_breakpoint;
68281
68282 struct task_struct *kgdb_usethread;
68283 @@ -132,7 +132,7 @@ int kgdb_single_step;
68284 static pid_t kgdb_sstep_pid;
68285
68286 /* to keep track of the CPU which is doing the single stepping*/
68287 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68288 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68289
68290 /*
68291 * If you are debugging a problem where roundup (the collection of
68292 @@ -540,7 +540,7 @@ return_normal:
68293 * kernel will only try for the value of sstep_tries before
68294 * giving up and continuing on.
68295 */
68296 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
68297 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
68298 (kgdb_info[cpu].task &&
68299 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
68300 atomic_set(&kgdb_active, -1);
68301 @@ -634,8 +634,8 @@ cpu_master_loop:
68302 }
68303
68304 kgdb_restore:
68305 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
68306 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
68307 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
68308 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
68309 if (kgdb_info[sstep_cpu].task)
68310 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
68311 else
68312 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
68313 static void kgdb_tasklet_bpt(unsigned long ing)
68314 {
68315 kgdb_breakpoint();
68316 - atomic_set(&kgdb_break_tasklet_var, 0);
68317 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
68318 }
68319
68320 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
68321
68322 void kgdb_schedule_breakpoint(void)
68323 {
68324 - if (atomic_read(&kgdb_break_tasklet_var) ||
68325 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
68326 atomic_read(&kgdb_active) != -1 ||
68327 atomic_read(&kgdb_setting_breakpoint))
68328 return;
68329 - atomic_inc(&kgdb_break_tasklet_var);
68330 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
68331 tasklet_schedule(&kgdb_tasklet_breakpoint);
68332 }
68333 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
68334 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
68335 index 4d5f8d5..4743f33 100644
68336 --- a/kernel/debug/kdb/kdb_main.c
68337 +++ b/kernel/debug/kdb/kdb_main.c
68338 @@ -1972,7 +1972,7 @@ static int kdb_lsmod(int argc, const char **argv)
68339 list_for_each_entry(mod, kdb_modules, list) {
68340
68341 kdb_printf("%-20s%8u 0x%p ", mod->name,
68342 - mod->core_size, (void *)mod);
68343 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
68344 #ifdef CONFIG_MODULE_UNLOAD
68345 kdb_printf("%4ld ", module_refcount(mod));
68346 #endif
68347 @@ -1982,7 +1982,7 @@ static int kdb_lsmod(int argc, const char **argv)
68348 kdb_printf(" (Loading)");
68349 else
68350 kdb_printf(" (Live)");
68351 - kdb_printf(" 0x%p", mod->module_core);
68352 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
68353
68354 #ifdef CONFIG_MODULE_UNLOAD
68355 {
68356 diff --git a/kernel/events/core.c b/kernel/events/core.c
68357 index dbccf83..8c66482 100644
68358 --- a/kernel/events/core.c
68359 +++ b/kernel/events/core.c
68360 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
68361 return 0;
68362 }
68363
68364 -static atomic64_t perf_event_id;
68365 +static atomic64_unchecked_t perf_event_id;
68366
68367 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
68368 enum event_type_t event_type);
68369 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
68370
68371 static inline u64 perf_event_count(struct perf_event *event)
68372 {
68373 - return local64_read(&event->count) + atomic64_read(&event->child_count);
68374 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
68375 }
68376
68377 static u64 perf_event_read(struct perf_event *event)
68378 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
68379 mutex_lock(&event->child_mutex);
68380 total += perf_event_read(event);
68381 *enabled += event->total_time_enabled +
68382 - atomic64_read(&event->child_total_time_enabled);
68383 + atomic64_read_unchecked(&event->child_total_time_enabled);
68384 *running += event->total_time_running +
68385 - atomic64_read(&event->child_total_time_running);
68386 + atomic64_read_unchecked(&event->child_total_time_running);
68387
68388 list_for_each_entry(child, &event->child_list, child_list) {
68389 total += perf_event_read(child);
68390 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
68391 userpg->offset -= local64_read(&event->hw.prev_count);
68392
68393 userpg->time_enabled = enabled +
68394 - atomic64_read(&event->child_total_time_enabled);
68395 + atomic64_read_unchecked(&event->child_total_time_enabled);
68396
68397 userpg->time_running = running +
68398 - atomic64_read(&event->child_total_time_running);
68399 + atomic64_read_unchecked(&event->child_total_time_running);
68400
68401 arch_perf_update_userpage(userpg, now);
68402
68403 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
68404 values[n++] = perf_event_count(event);
68405 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
68406 values[n++] = enabled +
68407 - atomic64_read(&event->child_total_time_enabled);
68408 + atomic64_read_unchecked(&event->child_total_time_enabled);
68409 }
68410 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
68411 values[n++] = running +
68412 - atomic64_read(&event->child_total_time_running);
68413 + atomic64_read_unchecked(&event->child_total_time_running);
68414 }
68415 if (read_format & PERF_FORMAT_ID)
68416 values[n++] = primary_event_id(event);
68417 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
68418 * need to add enough zero bytes after the string to handle
68419 * the 64bit alignment we do later.
68420 */
68421 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
68422 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
68423 if (!buf) {
68424 name = strncpy(tmp, "//enomem", sizeof(tmp));
68425 goto got_name;
68426 }
68427 - name = d_path(&file->f_path, buf, PATH_MAX);
68428 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
68429 if (IS_ERR(name)) {
68430 name = strncpy(tmp, "//toolong", sizeof(tmp));
68431 goto got_name;
68432 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
68433 event->parent = parent_event;
68434
68435 event->ns = get_pid_ns(current->nsproxy->pid_ns);
68436 - event->id = atomic64_inc_return(&perf_event_id);
68437 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
68438
68439 event->state = PERF_EVENT_STATE_INACTIVE;
68440
68441 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
68442 /*
68443 * Add back the child's count to the parent's count:
68444 */
68445 - atomic64_add(child_val, &parent_event->child_count);
68446 - atomic64_add(child_event->total_time_enabled,
68447 + atomic64_add_unchecked(child_val, &parent_event->child_count);
68448 + atomic64_add_unchecked(child_event->total_time_enabled,
68449 &parent_event->child_total_time_enabled);
68450 - atomic64_add(child_event->total_time_running,
68451 + atomic64_add_unchecked(child_event->total_time_running,
68452 &parent_event->child_total_time_running);
68453
68454 /*
68455 diff --git a/kernel/exit.c b/kernel/exit.c
68456 index 346616c..f103b28 100644
68457 --- a/kernel/exit.c
68458 +++ b/kernel/exit.c
68459 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
68460 struct task_struct *leader;
68461 int zap_leader;
68462 repeat:
68463 +#ifdef CONFIG_NET
68464 + gr_del_task_from_ip_table(p);
68465 +#endif
68466 +
68467 /* don't need to get the RCU readlock here - the process is dead and
68468 * can't be modifying its own credentials. But shut RCU-lockdep up */
68469 rcu_read_lock();
68470 @@ -394,7 +398,7 @@ int allow_signal(int sig)
68471 * know it'll be handled, so that they don't get converted to
68472 * SIGKILL or just silently dropped.
68473 */
68474 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
68475 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
68476 recalc_sigpending();
68477 spin_unlock_irq(&current->sighand->siglock);
68478 return 0;
68479 @@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
68480 vsnprintf(current->comm, sizeof(current->comm), name, args);
68481 va_end(args);
68482
68483 + gr_put_exec_file(current);
68484 + gr_set_kernel_label(current);
68485 +
68486 /*
68487 * If we were started as result of loading a module, close all of the
68488 * user space pages. We don't need them, and if we didn't close them
68489 @@ -812,6 +819,8 @@ void do_exit(long code)
68490 struct task_struct *tsk = current;
68491 int group_dead;
68492
68493 + set_fs(USER_DS);
68494 +
68495 profile_task_exit(tsk);
68496
68497 WARN_ON(blk_needs_flush_plug(tsk));
68498 @@ -828,7 +837,6 @@ void do_exit(long code)
68499 * mm_release()->clear_child_tid() from writing to a user-controlled
68500 * kernel address.
68501 */
68502 - set_fs(USER_DS);
68503
68504 ptrace_event(PTRACE_EVENT_EXIT, code);
68505
68506 @@ -887,6 +895,9 @@ void do_exit(long code)
68507 tsk->exit_code = code;
68508 taskstats_exit(tsk, group_dead);
68509
68510 + gr_acl_handle_psacct(tsk, code);
68511 + gr_acl_handle_exit();
68512 +
68513 exit_mm(tsk);
68514
68515 if (group_dead)
68516 @@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
68517 * Take down every thread in the group. This is called by fatal signals
68518 * as well as by sys_exit_group (below).
68519 */
68520 -void
68521 +__noreturn void
68522 do_group_exit(int exit_code)
68523 {
68524 struct signal_struct *sig = current->signal;
68525 diff --git a/kernel/fork.c b/kernel/fork.c
68526 index acc4cb6..b524cb5 100644
68527 --- a/kernel/fork.c
68528 +++ b/kernel/fork.c
68529 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
68530 *stackend = STACK_END_MAGIC; /* for overflow detection */
68531
68532 #ifdef CONFIG_CC_STACKPROTECTOR
68533 - tsk->stack_canary = get_random_int();
68534 + tsk->stack_canary = pax_get_random_long();
68535 #endif
68536
68537 /*
68538 @@ -344,13 +344,81 @@ free_tsk:
68539 }
68540
68541 #ifdef CONFIG_MMU
68542 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
68543 +{
68544 + struct vm_area_struct *tmp;
68545 + unsigned long charge;
68546 + struct mempolicy *pol;
68547 + struct file *file;
68548 +
68549 + charge = 0;
68550 + if (mpnt->vm_flags & VM_ACCOUNT) {
68551 + unsigned long len = vma_pages(mpnt);
68552 +
68553 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
68554 + goto fail_nomem;
68555 + charge = len;
68556 + }
68557 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
68558 + if (!tmp)
68559 + goto fail_nomem;
68560 + *tmp = *mpnt;
68561 + tmp->vm_mm = mm;
68562 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
68563 + pol = mpol_dup(vma_policy(mpnt));
68564 + if (IS_ERR(pol))
68565 + goto fail_nomem_policy;
68566 + vma_set_policy(tmp, pol);
68567 + if (anon_vma_fork(tmp, mpnt))
68568 + goto fail_nomem_anon_vma_fork;
68569 + tmp->vm_flags &= ~VM_LOCKED;
68570 + tmp->vm_next = tmp->vm_prev = NULL;
68571 + tmp->vm_mirror = NULL;
68572 + file = tmp->vm_file;
68573 + if (file) {
68574 + struct inode *inode = file->f_path.dentry->d_inode;
68575 + struct address_space *mapping = file->f_mapping;
68576 +
68577 + get_file(file);
68578 + if (tmp->vm_flags & VM_DENYWRITE)
68579 + atomic_dec(&inode->i_writecount);
68580 + mutex_lock(&mapping->i_mmap_mutex);
68581 + if (tmp->vm_flags & VM_SHARED)
68582 + mapping->i_mmap_writable++;
68583 + flush_dcache_mmap_lock(mapping);
68584 + /* insert tmp into the share list, just after mpnt */
68585 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
68586 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
68587 + else
68588 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
68589 + flush_dcache_mmap_unlock(mapping);
68590 + mutex_unlock(&mapping->i_mmap_mutex);
68591 + }
68592 +
68593 + /*
68594 + * Clear hugetlb-related page reserves for children. This only
68595 + * affects MAP_PRIVATE mappings. Faults generated by the child
68596 + * are not guaranteed to succeed, even if read-only
68597 + */
68598 + if (is_vm_hugetlb_page(tmp))
68599 + reset_vma_resv_huge_pages(tmp);
68600 +
68601 + return tmp;
68602 +
68603 +fail_nomem_anon_vma_fork:
68604 + mpol_put(pol);
68605 +fail_nomem_policy:
68606 + kmem_cache_free(vm_area_cachep, tmp);
68607 +fail_nomem:
68608 + vm_unacct_memory(charge);
68609 + return NULL;
68610 +}
68611 +
68612 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
68613 {
68614 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
68615 struct rb_node **rb_link, *rb_parent;
68616 int retval;
68617 - unsigned long charge;
68618 - struct mempolicy *pol;
68619
68620 down_write(&oldmm->mmap_sem);
68621 flush_cache_dup_mm(oldmm);
68622 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
68623 mm->locked_vm = 0;
68624 mm->mmap = NULL;
68625 mm->mmap_cache = NULL;
68626 - mm->free_area_cache = oldmm->mmap_base;
68627 - mm->cached_hole_size = ~0UL;
68628 + mm->free_area_cache = oldmm->free_area_cache;
68629 + mm->cached_hole_size = oldmm->cached_hole_size;
68630 mm->map_count = 0;
68631 cpumask_clear(mm_cpumask(mm));
68632 mm->mm_rb = RB_ROOT;
68633 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
68634
68635 prev = NULL;
68636 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
68637 - struct file *file;
68638 -
68639 if (mpnt->vm_flags & VM_DONTCOPY) {
68640 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
68641 -vma_pages(mpnt));
68642 continue;
68643 }
68644 - charge = 0;
68645 - if (mpnt->vm_flags & VM_ACCOUNT) {
68646 - unsigned long len = vma_pages(mpnt);
68647 -
68648 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
68649 - goto fail_nomem;
68650 - charge = len;
68651 - }
68652 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
68653 - if (!tmp)
68654 - goto fail_nomem;
68655 - *tmp = *mpnt;
68656 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
68657 - pol = mpol_dup(vma_policy(mpnt));
68658 - retval = PTR_ERR(pol);
68659 - if (IS_ERR(pol))
68660 - goto fail_nomem_policy;
68661 - vma_set_policy(tmp, pol);
68662 - tmp->vm_mm = mm;
68663 - if (anon_vma_fork(tmp, mpnt))
68664 - goto fail_nomem_anon_vma_fork;
68665 - tmp->vm_flags &= ~VM_LOCKED;
68666 - tmp->vm_next = tmp->vm_prev = NULL;
68667 - file = tmp->vm_file;
68668 - if (file) {
68669 - struct inode *inode = file->f_path.dentry->d_inode;
68670 - struct address_space *mapping = file->f_mapping;
68671 -
68672 - get_file(file);
68673 - if (tmp->vm_flags & VM_DENYWRITE)
68674 - atomic_dec(&inode->i_writecount);
68675 - mutex_lock(&mapping->i_mmap_mutex);
68676 - if (tmp->vm_flags & VM_SHARED)
68677 - mapping->i_mmap_writable++;
68678 - flush_dcache_mmap_lock(mapping);
68679 - /* insert tmp into the share list, just after mpnt */
68680 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
68681 - vma_nonlinear_insert(tmp,
68682 - &mapping->i_mmap_nonlinear);
68683 - else
68684 - vma_interval_tree_insert_after(tmp, mpnt,
68685 - &mapping->i_mmap);
68686 - flush_dcache_mmap_unlock(mapping);
68687 - mutex_unlock(&mapping->i_mmap_mutex);
68688 + tmp = dup_vma(mm, oldmm, mpnt);
68689 + if (!tmp) {
68690 + retval = -ENOMEM;
68691 + goto out;
68692 }
68693
68694 /*
68695 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
68696 if (retval)
68697 goto out;
68698 }
68699 +
68700 +#ifdef CONFIG_PAX_SEGMEXEC
68701 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
68702 + struct vm_area_struct *mpnt_m;
68703 +
68704 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
68705 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
68706 +
68707 + if (!mpnt->vm_mirror)
68708 + continue;
68709 +
68710 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
68711 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
68712 + mpnt->vm_mirror = mpnt_m;
68713 + } else {
68714 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
68715 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
68716 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
68717 + mpnt->vm_mirror->vm_mirror = mpnt;
68718 + }
68719 + }
68720 + BUG_ON(mpnt_m);
68721 + }
68722 +#endif
68723 +
68724 /* a new mm has just been created */
68725 arch_dup_mmap(oldmm, mm);
68726 retval = 0;
68727 @@ -470,14 +521,6 @@ out:
68728 flush_tlb_mm(oldmm);
68729 up_write(&oldmm->mmap_sem);
68730 return retval;
68731 -fail_nomem_anon_vma_fork:
68732 - mpol_put(pol);
68733 -fail_nomem_policy:
68734 - kmem_cache_free(vm_area_cachep, tmp);
68735 -fail_nomem:
68736 - retval = -ENOMEM;
68737 - vm_unacct_memory(charge);
68738 - goto out;
68739 }
68740
68741 static inline int mm_alloc_pgd(struct mm_struct *mm)
68742 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
68743 return ERR_PTR(err);
68744
68745 mm = get_task_mm(task);
68746 - if (mm && mm != current->mm &&
68747 - !ptrace_may_access(task, mode)) {
68748 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
68749 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
68750 mmput(mm);
68751 mm = ERR_PTR(-EACCES);
68752 }
68753 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
68754 spin_unlock(&fs->lock);
68755 return -EAGAIN;
68756 }
68757 - fs->users++;
68758 + atomic_inc(&fs->users);
68759 spin_unlock(&fs->lock);
68760 return 0;
68761 }
68762 tsk->fs = copy_fs_struct(fs);
68763 if (!tsk->fs)
68764 return -ENOMEM;
68765 + /* Carry through gr_chroot_dentry and is_chrooted instead
68766 + of recomputing it here. Already copied when the task struct
68767 + is duplicated. This allows pivot_root to not be treated as
68768 + a chroot
68769 + */
68770 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
68771 +
68772 return 0;
68773 }
68774
68775 @@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
68776 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
68777 #endif
68778 retval = -EAGAIN;
68779 +
68780 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
68781 +
68782 if (atomic_read(&p->real_cred->user->processes) >=
68783 task_rlimit(p, RLIMIT_NPROC)) {
68784 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
68785 @@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
68786 goto bad_fork_free_pid;
68787 }
68788
68789 + /* synchronizes with gr_set_acls()
68790 + we need to call this past the point of no return for fork()
68791 + */
68792 + gr_copy_label(p);
68793 +
68794 if (clone_flags & CLONE_THREAD) {
68795 current->signal->nr_threads++;
68796 atomic_inc(&current->signal->live);
68797 @@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
68798 bad_fork_free:
68799 free_task(p);
68800 fork_out:
68801 + gr_log_forkfail(retval);
68802 +
68803 return ERR_PTR(retval);
68804 }
68805
68806 @@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
68807 if (clone_flags & CLONE_PARENT_SETTID)
68808 put_user(nr, parent_tidptr);
68809
68810 + gr_handle_brute_check();
68811 +
68812 if (clone_flags & CLONE_VFORK) {
68813 p->vfork_done = &vfork;
68814 init_completion(&vfork);
68815 @@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
68816 return 0;
68817
68818 /* don't need lock here; in the worst case we'll do useless copy */
68819 - if (fs->users == 1)
68820 + if (atomic_read(&fs->users) == 1)
68821 return 0;
68822
68823 *new_fsp = copy_fs_struct(fs);
68824 @@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
68825 fs = current->fs;
68826 spin_lock(&fs->lock);
68827 current->fs = new_fs;
68828 - if (--fs->users)
68829 + gr_set_chroot_entries(current, &current->fs->root);
68830 + if (atomic_dec_return(&fs->users))
68831 new_fs = NULL;
68832 else
68833 new_fs = fs;
68834 diff --git a/kernel/futex.c b/kernel/futex.c
68835 index 19eb089..b8c65ea 100644
68836 --- a/kernel/futex.c
68837 +++ b/kernel/futex.c
68838 @@ -54,6 +54,7 @@
68839 #include <linux/mount.h>
68840 #include <linux/pagemap.h>
68841 #include <linux/syscalls.h>
68842 +#include <linux/ptrace.h>
68843 #include <linux/signal.h>
68844 #include <linux/export.h>
68845 #include <linux/magic.h>
68846 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
68847 struct page *page, *page_head;
68848 int err, ro = 0;
68849
68850 +#ifdef CONFIG_PAX_SEGMEXEC
68851 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
68852 + return -EFAULT;
68853 +#endif
68854 +
68855 /*
68856 * The futex address must be "naturally" aligned.
68857 */
68858 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
68859 {
68860 u32 curval;
68861 int i;
68862 + mm_segment_t oldfs;
68863
68864 /*
68865 * This will fail and we want it. Some arch implementations do
68866 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
68867 * implementation, the non-functional ones will return
68868 * -ENOSYS.
68869 */
68870 + oldfs = get_fs();
68871 + set_fs(USER_DS);
68872 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
68873 futex_cmpxchg_enabled = 1;
68874 + set_fs(oldfs);
68875
68876 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
68877 plist_head_init(&futex_queues[i].chain);
68878 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
68879 index 9b22d03..6295b62 100644
68880 --- a/kernel/gcov/base.c
68881 +++ b/kernel/gcov/base.c
68882 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
68883 }
68884
68885 #ifdef CONFIG_MODULES
68886 -static inline int within(void *addr, void *start, unsigned long size)
68887 -{
68888 - return ((addr >= start) && (addr < start + size));
68889 -}
68890 -
68891 /* Update list and generate events when modules are unloaded. */
68892 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68893 void *data)
68894 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68895 prev = NULL;
68896 /* Remove entries located in module from linked list. */
68897 for (info = gcov_info_head; info; info = info->next) {
68898 - if (within(info, mod->module_core, mod->core_size)) {
68899 + if (within_module_core_rw((unsigned long)info, mod)) {
68900 if (prev)
68901 prev->next = info->next;
68902 else
68903 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
68904 index 6db7a5e..25b6648 100644
68905 --- a/kernel/hrtimer.c
68906 +++ b/kernel/hrtimer.c
68907 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
68908 local_irq_restore(flags);
68909 }
68910
68911 -static void run_hrtimer_softirq(struct softirq_action *h)
68912 +static void run_hrtimer_softirq(void)
68913 {
68914 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
68915
68916 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
68917 index 60f48fa..7f3a770 100644
68918 --- a/kernel/jump_label.c
68919 +++ b/kernel/jump_label.c
68920 @@ -13,6 +13,7 @@
68921 #include <linux/sort.h>
68922 #include <linux/err.h>
68923 #include <linux/static_key.h>
68924 +#include <linux/mm.h>
68925
68926 #ifdef HAVE_JUMP_LABEL
68927
68928 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
68929
68930 size = (((unsigned long)stop - (unsigned long)start)
68931 / sizeof(struct jump_entry));
68932 + pax_open_kernel();
68933 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
68934 + pax_close_kernel();
68935 }
68936
68937 static void jump_label_update(struct static_key *key, int enable);
68938 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
68939 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
68940 struct jump_entry *iter;
68941
68942 + pax_open_kernel();
68943 for (iter = iter_start; iter < iter_stop; iter++) {
68944 if (within_module_init(iter->code, mod))
68945 iter->code = 0;
68946 }
68947 + pax_close_kernel();
68948 }
68949
68950 static int
68951 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
68952 index 2169fee..45c017a 100644
68953 --- a/kernel/kallsyms.c
68954 +++ b/kernel/kallsyms.c
68955 @@ -11,6 +11,9 @@
68956 * Changed the compression method from stem compression to "table lookup"
68957 * compression (see scripts/kallsyms.c for a more complete description)
68958 */
68959 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68960 +#define __INCLUDED_BY_HIDESYM 1
68961 +#endif
68962 #include <linux/kallsyms.h>
68963 #include <linux/module.h>
68964 #include <linux/init.h>
68965 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
68966
68967 static inline int is_kernel_inittext(unsigned long addr)
68968 {
68969 + if (system_state != SYSTEM_BOOTING)
68970 + return 0;
68971 +
68972 if (addr >= (unsigned long)_sinittext
68973 && addr <= (unsigned long)_einittext)
68974 return 1;
68975 return 0;
68976 }
68977
68978 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68979 +#ifdef CONFIG_MODULES
68980 +static inline int is_module_text(unsigned long addr)
68981 +{
68982 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
68983 + return 1;
68984 +
68985 + addr = ktla_ktva(addr);
68986 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
68987 +}
68988 +#else
68989 +static inline int is_module_text(unsigned long addr)
68990 +{
68991 + return 0;
68992 +}
68993 +#endif
68994 +#endif
68995 +
68996 static inline int is_kernel_text(unsigned long addr)
68997 {
68998 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
68999 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69000
69001 static inline int is_kernel(unsigned long addr)
69002 {
69003 +
69004 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69005 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
69006 + return 1;
69007 +
69008 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69009 +#else
69010 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69011 +#endif
69012 +
69013 return 1;
69014 return in_gate_area_no_mm(addr);
69015 }
69016
69017 static int is_ksym_addr(unsigned long addr)
69018 {
69019 +
69020 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69021 + if (is_module_text(addr))
69022 + return 0;
69023 +#endif
69024 +
69025 if (all_var)
69026 return is_kernel(addr);
69027
69028 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69029
69030 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69031 {
69032 - iter->name[0] = '\0';
69033 iter->nameoff = get_symbol_offset(new_pos);
69034 iter->pos = new_pos;
69035 }
69036 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69037 {
69038 struct kallsym_iter *iter = m->private;
69039
69040 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69041 + if (current_uid())
69042 + return 0;
69043 +#endif
69044 +
69045 /* Some debugging symbols have no name. Ignore them. */
69046 if (!iter->name[0])
69047 return 0;
69048 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69049 */
69050 type = iter->exported ? toupper(iter->type) :
69051 tolower(iter->type);
69052 +
69053 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69054 type, iter->name, iter->module_name);
69055 } else
69056 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69057 struct kallsym_iter *iter;
69058 int ret;
69059
69060 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69061 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69062 if (!iter)
69063 return -ENOMEM;
69064 reset_iter(iter, 0);
69065 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69066 index 30b7b22..c726387 100644
69067 --- a/kernel/kcmp.c
69068 +++ b/kernel/kcmp.c
69069 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69070 struct task_struct *task1, *task2;
69071 int ret;
69072
69073 +#ifdef CONFIG_GRKERNSEC
69074 + return -ENOSYS;
69075 +#endif
69076 +
69077 rcu_read_lock();
69078
69079 /*
69080 diff --git a/kernel/kexec.c b/kernel/kexec.c
69081 index 5e4bd78..00c5b91 100644
69082 --- a/kernel/kexec.c
69083 +++ b/kernel/kexec.c
69084 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69085 unsigned long flags)
69086 {
69087 struct compat_kexec_segment in;
69088 - struct kexec_segment out, __user *ksegments;
69089 + struct kexec_segment out;
69090 + struct kexec_segment __user *ksegments;
69091 unsigned long i, result;
69092
69093 /* Don't allow clients that don't understand the native
69094 diff --git a/kernel/kmod.c b/kernel/kmod.c
69095 index 1c317e3..4a92a55 100644
69096 --- a/kernel/kmod.c
69097 +++ b/kernel/kmod.c
69098 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69099 kfree(info->argv);
69100 }
69101
69102 -static int call_modprobe(char *module_name, int wait)
69103 +static int call_modprobe(char *module_name, char *module_param, int wait)
69104 {
69105 static char *envp[] = {
69106 "HOME=/",
69107 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69108 NULL
69109 };
69110
69111 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69112 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69113 if (!argv)
69114 goto out;
69115
69116 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69117 argv[1] = "-q";
69118 argv[2] = "--";
69119 argv[3] = module_name; /* check free_modprobe_argv() */
69120 - argv[4] = NULL;
69121 + argv[4] = module_param;
69122 + argv[5] = NULL;
69123
69124 return call_usermodehelper_fns(modprobe_path, argv, envp,
69125 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69126 @@ -120,9 +121,8 @@ out:
69127 * If module auto-loading support is disabled then this function
69128 * becomes a no-operation.
69129 */
69130 -int __request_module(bool wait, const char *fmt, ...)
69131 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69132 {
69133 - va_list args;
69134 char module_name[MODULE_NAME_LEN];
69135 unsigned int max_modprobes;
69136 int ret;
69137 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69138 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69139 static int kmod_loop_msg;
69140
69141 - va_start(args, fmt);
69142 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69143 - va_end(args);
69144 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69145 if (ret >= MODULE_NAME_LEN)
69146 return -ENAMETOOLONG;
69147
69148 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69149 if (ret)
69150 return ret;
69151
69152 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69153 + if (!current_uid()) {
69154 + /* hack to workaround consolekit/udisks stupidity */
69155 + read_lock(&tasklist_lock);
69156 + if (!strcmp(current->comm, "mount") &&
69157 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69158 + read_unlock(&tasklist_lock);
69159 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69160 + return -EPERM;
69161 + }
69162 + read_unlock(&tasklist_lock);
69163 + }
69164 +#endif
69165 +
69166 /* If modprobe needs a service that is in a module, we get a recursive
69167 * loop. Limit the number of running kmod threads to max_threads/2 or
69168 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
69169 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
69170
69171 trace_module_request(module_name, wait, _RET_IP_);
69172
69173 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69174 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69175
69176 atomic_dec(&kmod_concurrent);
69177 return ret;
69178 }
69179 +
69180 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
69181 +{
69182 + va_list args;
69183 + int ret;
69184 +
69185 + va_start(args, fmt);
69186 + ret = ____request_module(wait, module_param, fmt, args);
69187 + va_end(args);
69188 +
69189 + return ret;
69190 +}
69191 +
69192 +int __request_module(bool wait, const char *fmt, ...)
69193 +{
69194 + va_list args;
69195 + int ret;
69196 +
69197 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69198 + if (current_uid()) {
69199 + char module_param[MODULE_NAME_LEN];
69200 +
69201 + memset(module_param, 0, sizeof(module_param));
69202 +
69203 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
69204 +
69205 + va_start(args, fmt);
69206 + ret = ____request_module(wait, module_param, fmt, args);
69207 + va_end(args);
69208 +
69209 + return ret;
69210 + }
69211 +#endif
69212 +
69213 + va_start(args, fmt);
69214 + ret = ____request_module(wait, NULL, fmt, args);
69215 + va_end(args);
69216 +
69217 + return ret;
69218 +}
69219 +
69220 EXPORT_SYMBOL(__request_module);
69221 #endif /* CONFIG_MODULES */
69222
69223 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
69224 *
69225 * Thus the __user pointer cast is valid here.
69226 */
69227 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
69228 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
69229
69230 /*
69231 * If ret is 0, either ____call_usermodehelper failed and the
69232 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
69233 index 098f396..fe85ff1 100644
69234 --- a/kernel/kprobes.c
69235 +++ b/kernel/kprobes.c
69236 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
69237 * kernel image and loaded module images reside. This is required
69238 * so x86_64 can correctly handle the %rip-relative fixups.
69239 */
69240 - kip->insns = module_alloc(PAGE_SIZE);
69241 + kip->insns = module_alloc_exec(PAGE_SIZE);
69242 if (!kip->insns) {
69243 kfree(kip);
69244 return NULL;
69245 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
69246 */
69247 if (!list_is_singular(&kip->list)) {
69248 list_del(&kip->list);
69249 - module_free(NULL, kip->insns);
69250 + module_free_exec(NULL, kip->insns);
69251 kfree(kip);
69252 }
69253 return 1;
69254 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
69255 {
69256 int i, err = 0;
69257 unsigned long offset = 0, size = 0;
69258 - char *modname, namebuf[128];
69259 + char *modname, namebuf[KSYM_NAME_LEN];
69260 const char *symbol_name;
69261 void *addr;
69262 struct kprobe_blackpoint *kb;
69263 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
69264 kprobe_type = "k";
69265
69266 if (sym)
69267 - seq_printf(pi, "%p %s %s+0x%x %s ",
69268 + seq_printf(pi, "%pK %s %s+0x%x %s ",
69269 p->addr, kprobe_type, sym, offset,
69270 (modname ? modname : " "));
69271 else
69272 - seq_printf(pi, "%p %s %p ",
69273 + seq_printf(pi, "%pK %s %pK ",
69274 p->addr, kprobe_type, p->addr);
69275
69276 if (!pp)
69277 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
69278 const char *sym = NULL;
69279 unsigned int i = *(loff_t *) v;
69280 unsigned long offset = 0;
69281 - char *modname, namebuf[128];
69282 + char *modname, namebuf[KSYM_NAME_LEN];
69283
69284 head = &kprobe_table[i];
69285 preempt_disable();
69286 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
69287 index 4e316e1..5501eef 100644
69288 --- a/kernel/ksysfs.c
69289 +++ b/kernel/ksysfs.c
69290 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
69291 {
69292 if (count+1 > UEVENT_HELPER_PATH_LEN)
69293 return -ENOENT;
69294 + if (!capable(CAP_SYS_ADMIN))
69295 + return -EPERM;
69296 memcpy(uevent_helper, buf, count);
69297 uevent_helper[count] = '\0';
69298 if (count && uevent_helper[count-1] == '\n')
69299 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
69300 index 7981e5b..7f2105c 100644
69301 --- a/kernel/lockdep.c
69302 +++ b/kernel/lockdep.c
69303 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
69304 end = (unsigned long) &_end,
69305 addr = (unsigned long) obj;
69306
69307 +#ifdef CONFIG_PAX_KERNEXEC
69308 + start = ktla_ktva(start);
69309 +#endif
69310 +
69311 /*
69312 * static variable?
69313 */
69314 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
69315 if (!static_obj(lock->key)) {
69316 debug_locks_off();
69317 printk("INFO: trying to register non-static key.\n");
69318 + printk("lock:%pS key:%pS.\n", lock, lock->key);
69319 printk("the code is fine but needs lockdep annotation.\n");
69320 printk("turning off the locking correctness validator.\n");
69321 dump_stack();
69322 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
69323 if (!class)
69324 return 0;
69325 }
69326 - atomic_inc((atomic_t *)&class->ops);
69327 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
69328 if (very_verbose(class)) {
69329 printk("\nacquire class [%p] %s", class->key, class->name);
69330 if (class->name_version > 1)
69331 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
69332 index 91c32a0..7b88d63 100644
69333 --- a/kernel/lockdep_proc.c
69334 +++ b/kernel/lockdep_proc.c
69335 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
69336
69337 static void print_name(struct seq_file *m, struct lock_class *class)
69338 {
69339 - char str[128];
69340 + char str[KSYM_NAME_LEN];
69341 const char *name = class->name;
69342
69343 if (!name) {
69344 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
69345 return 0;
69346 }
69347
69348 - seq_printf(m, "%p", class->key);
69349 + seq_printf(m, "%pK", class->key);
69350 #ifdef CONFIG_DEBUG_LOCKDEP
69351 seq_printf(m, " OPS:%8ld", class->ops);
69352 #endif
69353 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
69354
69355 list_for_each_entry(entry, &class->locks_after, entry) {
69356 if (entry->distance == 1) {
69357 - seq_printf(m, " -> [%p] ", entry->class->key);
69358 + seq_printf(m, " -> [%pK] ", entry->class->key);
69359 print_name(m, entry->class);
69360 seq_puts(m, "\n");
69361 }
69362 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
69363 if (!class->key)
69364 continue;
69365
69366 - seq_printf(m, "[%p] ", class->key);
69367 + seq_printf(m, "[%pK] ", class->key);
69368 print_name(m, class);
69369 seq_puts(m, "\n");
69370 }
69371 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
69372 if (!i)
69373 seq_line(m, '-', 40-namelen, namelen);
69374
69375 - snprintf(ip, sizeof(ip), "[<%p>]",
69376 + snprintf(ip, sizeof(ip), "[<%pK>]",
69377 (void *)class->contention_point[i]);
69378 seq_printf(m, "%40s %14lu %29s %pS\n",
69379 name, stats->contention_point[i],
69380 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
69381 if (!i)
69382 seq_line(m, '-', 40-namelen, namelen);
69383
69384 - snprintf(ip, sizeof(ip), "[<%p>]",
69385 + snprintf(ip, sizeof(ip), "[<%pK>]",
69386 (void *)class->contending_point[i]);
69387 seq_printf(m, "%40s %14lu %29s %pS\n",
69388 name, stats->contending_point[i],
69389 diff --git a/kernel/module.c b/kernel/module.c
69390 index 6e48c3a..ac2ef5b 100644
69391 --- a/kernel/module.c
69392 +++ b/kernel/module.c
69393 @@ -59,6 +59,7 @@
69394 #include <linux/pfn.h>
69395 #include <linux/bsearch.h>
69396 #include <linux/fips.h>
69397 +#include <linux/grsecurity.h>
69398 #include "module-internal.h"
69399
69400 #define CREATE_TRACE_POINTS
69401 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
69402
69403 /* Bounds of module allocation, for speeding __module_address.
69404 * Protected by module_mutex. */
69405 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
69406 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
69407 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
69408
69409 int register_module_notifier(struct notifier_block * nb)
69410 {
69411 @@ -318,7 +320,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
69412 return true;
69413
69414 list_for_each_entry_rcu(mod, &modules, list) {
69415 - struct symsearch arr[] = {
69416 + struct symsearch modarr[] = {
69417 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
69418 NOT_GPL_ONLY, false },
69419 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
69420 @@ -340,7 +342,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
69421 #endif
69422 };
69423
69424 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
69425 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
69426 return true;
69427 }
69428 return false;
69429 @@ -472,7 +474,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
69430 static int percpu_modalloc(struct module *mod,
69431 unsigned long size, unsigned long align)
69432 {
69433 - if (align > PAGE_SIZE) {
69434 + if (align-1 >= PAGE_SIZE) {
69435 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
69436 mod->name, align, PAGE_SIZE);
69437 align = PAGE_SIZE;
69438 @@ -1072,7 +1074,7 @@ struct module_attribute module_uevent =
69439 static ssize_t show_coresize(struct module_attribute *mattr,
69440 struct module_kobject *mk, char *buffer)
69441 {
69442 - return sprintf(buffer, "%u\n", mk->mod->core_size);
69443 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
69444 }
69445
69446 static struct module_attribute modinfo_coresize =
69447 @@ -1081,7 +1083,7 @@ static struct module_attribute modinfo_coresize =
69448 static ssize_t show_initsize(struct module_attribute *mattr,
69449 struct module_kobject *mk, char *buffer)
69450 {
69451 - return sprintf(buffer, "%u\n", mk->mod->init_size);
69452 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
69453 }
69454
69455 static struct module_attribute modinfo_initsize =
69456 @@ -1295,7 +1297,7 @@ resolve_symbol_wait(struct module *mod,
69457 */
69458 #ifdef CONFIG_SYSFS
69459
69460 -#ifdef CONFIG_KALLSYMS
69461 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69462 static inline bool sect_empty(const Elf_Shdr *sect)
69463 {
69464 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
69465 @@ -1761,21 +1763,21 @@ static void set_section_ro_nx(void *base,
69466
69467 static void unset_module_core_ro_nx(struct module *mod)
69468 {
69469 - set_page_attributes(mod->module_core + mod->core_text_size,
69470 - mod->module_core + mod->core_size,
69471 + set_page_attributes(mod->module_core_rw,
69472 + mod->module_core_rw + mod->core_size_rw,
69473 set_memory_x);
69474 - set_page_attributes(mod->module_core,
69475 - mod->module_core + mod->core_ro_size,
69476 + set_page_attributes(mod->module_core_rx,
69477 + mod->module_core_rx + mod->core_size_rx,
69478 set_memory_rw);
69479 }
69480
69481 static void unset_module_init_ro_nx(struct module *mod)
69482 {
69483 - set_page_attributes(mod->module_init + mod->init_text_size,
69484 - mod->module_init + mod->init_size,
69485 + set_page_attributes(mod->module_init_rw,
69486 + mod->module_init_rw + mod->init_size_rw,
69487 set_memory_x);
69488 - set_page_attributes(mod->module_init,
69489 - mod->module_init + mod->init_ro_size,
69490 + set_page_attributes(mod->module_init_rx,
69491 + mod->module_init_rx + mod->init_size_rx,
69492 set_memory_rw);
69493 }
69494
69495 @@ -1786,14 +1788,14 @@ void set_all_modules_text_rw(void)
69496
69497 mutex_lock(&module_mutex);
69498 list_for_each_entry_rcu(mod, &modules, list) {
69499 - if ((mod->module_core) && (mod->core_text_size)) {
69500 - set_page_attributes(mod->module_core,
69501 - mod->module_core + mod->core_text_size,
69502 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
69503 + set_page_attributes(mod->module_core_rx,
69504 + mod->module_core_rx + mod->core_size_rx,
69505 set_memory_rw);
69506 }
69507 - if ((mod->module_init) && (mod->init_text_size)) {
69508 - set_page_attributes(mod->module_init,
69509 - mod->module_init + mod->init_text_size,
69510 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
69511 + set_page_attributes(mod->module_init_rx,
69512 + mod->module_init_rx + mod->init_size_rx,
69513 set_memory_rw);
69514 }
69515 }
69516 @@ -1807,14 +1809,14 @@ void set_all_modules_text_ro(void)
69517
69518 mutex_lock(&module_mutex);
69519 list_for_each_entry_rcu(mod, &modules, list) {
69520 - if ((mod->module_core) && (mod->core_text_size)) {
69521 - set_page_attributes(mod->module_core,
69522 - mod->module_core + mod->core_text_size,
69523 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
69524 + set_page_attributes(mod->module_core_rx,
69525 + mod->module_core_rx + mod->core_size_rx,
69526 set_memory_ro);
69527 }
69528 - if ((mod->module_init) && (mod->init_text_size)) {
69529 - set_page_attributes(mod->module_init,
69530 - mod->module_init + mod->init_text_size,
69531 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
69532 + set_page_attributes(mod->module_init_rx,
69533 + mod->module_init_rx + mod->init_size_rx,
69534 set_memory_ro);
69535 }
69536 }
69537 @@ -1860,16 +1862,19 @@ static void free_module(struct module *mod)
69538
69539 /* This may be NULL, but that's OK */
69540 unset_module_init_ro_nx(mod);
69541 - module_free(mod, mod->module_init);
69542 + module_free(mod, mod->module_init_rw);
69543 + module_free_exec(mod, mod->module_init_rx);
69544 kfree(mod->args);
69545 percpu_modfree(mod);
69546
69547 /* Free lock-classes: */
69548 - lockdep_free_key_range(mod->module_core, mod->core_size);
69549 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
69550 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
69551
69552 /* Finally, free the core (containing the module structure) */
69553 unset_module_core_ro_nx(mod);
69554 - module_free(mod, mod->module_core);
69555 + module_free_exec(mod, mod->module_core_rx);
69556 + module_free(mod, mod->module_core_rw);
69557
69558 #ifdef CONFIG_MPU
69559 update_protections(current->mm);
69560 @@ -1939,9 +1944,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
69561 int ret = 0;
69562 const struct kernel_symbol *ksym;
69563
69564 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69565 + int is_fs_load = 0;
69566 + int register_filesystem_found = 0;
69567 + char *p;
69568 +
69569 + p = strstr(mod->args, "grsec_modharden_fs");
69570 + if (p) {
69571 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
69572 + /* copy \0 as well */
69573 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
69574 + is_fs_load = 1;
69575 + }
69576 +#endif
69577 +
69578 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
69579 const char *name = info->strtab + sym[i].st_name;
69580
69581 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69582 + /* it's a real shame this will never get ripped and copied
69583 + upstream! ;(
69584 + */
69585 + if (is_fs_load && !strcmp(name, "register_filesystem"))
69586 + register_filesystem_found = 1;
69587 +#endif
69588 +
69589 switch (sym[i].st_shndx) {
69590 case SHN_COMMON:
69591 /* We compiled with -fno-common. These are not
69592 @@ -1962,7 +1989,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
69593 ksym = resolve_symbol_wait(mod, info, name);
69594 /* Ok if resolved. */
69595 if (ksym && !IS_ERR(ksym)) {
69596 + pax_open_kernel();
69597 sym[i].st_value = ksym->value;
69598 + pax_close_kernel();
69599 break;
69600 }
69601
69602 @@ -1981,11 +2010,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
69603 secbase = (unsigned long)mod_percpu(mod);
69604 else
69605 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
69606 + pax_open_kernel();
69607 sym[i].st_value += secbase;
69608 + pax_close_kernel();
69609 break;
69610 }
69611 }
69612
69613 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69614 + if (is_fs_load && !register_filesystem_found) {
69615 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
69616 + ret = -EPERM;
69617 + }
69618 +#endif
69619 +
69620 return ret;
69621 }
69622
69623 @@ -2069,22 +2107,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
69624 || s->sh_entsize != ~0UL
69625 || strstarts(sname, ".init"))
69626 continue;
69627 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
69628 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
69629 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
69630 + else
69631 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
69632 pr_debug("\t%s\n", sname);
69633 }
69634 - switch (m) {
69635 - case 0: /* executable */
69636 - mod->core_size = debug_align(mod->core_size);
69637 - mod->core_text_size = mod->core_size;
69638 - break;
69639 - case 1: /* RO: text and ro-data */
69640 - mod->core_size = debug_align(mod->core_size);
69641 - mod->core_ro_size = mod->core_size;
69642 - break;
69643 - case 3: /* whole core */
69644 - mod->core_size = debug_align(mod->core_size);
69645 - break;
69646 - }
69647 }
69648
69649 pr_debug("Init section allocation order:\n");
69650 @@ -2098,23 +2126,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
69651 || s->sh_entsize != ~0UL
69652 || !strstarts(sname, ".init"))
69653 continue;
69654 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
69655 - | INIT_OFFSET_MASK);
69656 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
69657 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
69658 + else
69659 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
69660 + s->sh_entsize |= INIT_OFFSET_MASK;
69661 pr_debug("\t%s\n", sname);
69662 }
69663 - switch (m) {
69664 - case 0: /* executable */
69665 - mod->init_size = debug_align(mod->init_size);
69666 - mod->init_text_size = mod->init_size;
69667 - break;
69668 - case 1: /* RO: text and ro-data */
69669 - mod->init_size = debug_align(mod->init_size);
69670 - mod->init_ro_size = mod->init_size;
69671 - break;
69672 - case 3: /* whole init */
69673 - mod->init_size = debug_align(mod->init_size);
69674 - break;
69675 - }
69676 }
69677 }
69678
69679 @@ -2286,7 +2304,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
69680
69681 /* Put symbol section at end of init part of module. */
69682 symsect->sh_flags |= SHF_ALLOC;
69683 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
69684 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
69685 info->index.sym) | INIT_OFFSET_MASK;
69686 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
69687
69688 @@ -2306,13 +2324,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
69689 }
69690
69691 /* Append room for core symbols at end of core part. */
69692 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
69693 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
69694 - mod->core_size += strtab_size;
69695 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
69696 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
69697 + mod->core_size_rx += strtab_size;
69698
69699 /* Put string table section at end of init part of module. */
69700 strsect->sh_flags |= SHF_ALLOC;
69701 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
69702 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
69703 info->index.str) | INIT_OFFSET_MASK;
69704 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
69705 }
69706 @@ -2330,12 +2348,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
69707 /* Make sure we get permanent strtab: don't use info->strtab. */
69708 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
69709
69710 + pax_open_kernel();
69711 +
69712 /* Set types up while we still have access to sections. */
69713 for (i = 0; i < mod->num_symtab; i++)
69714 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
69715
69716 - mod->core_symtab = dst = mod->module_core + info->symoffs;
69717 - mod->core_strtab = s = mod->module_core + info->stroffs;
69718 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
69719 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
69720 src = mod->symtab;
69721 *s++ = 0;
69722 for (ndst = i = 0; i < mod->num_symtab; i++) {
69723 @@ -2348,6 +2368,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
69724 }
69725 }
69726 mod->core_num_syms = ndst;
69727 +
69728 + pax_close_kernel();
69729 }
69730 #else
69731 static inline void layout_symtab(struct module *mod, struct load_info *info)
69732 @@ -2381,17 +2403,33 @@ void * __weak module_alloc(unsigned long size)
69733 return size == 0 ? NULL : vmalloc_exec(size);
69734 }
69735
69736 -static void *module_alloc_update_bounds(unsigned long size)
69737 +static void *module_alloc_update_bounds_rw(unsigned long size)
69738 {
69739 void *ret = module_alloc(size);
69740
69741 if (ret) {
69742 mutex_lock(&module_mutex);
69743 /* Update module bounds. */
69744 - if ((unsigned long)ret < module_addr_min)
69745 - module_addr_min = (unsigned long)ret;
69746 - if ((unsigned long)ret + size > module_addr_max)
69747 - module_addr_max = (unsigned long)ret + size;
69748 + if ((unsigned long)ret < module_addr_min_rw)
69749 + module_addr_min_rw = (unsigned long)ret;
69750 + if ((unsigned long)ret + size > module_addr_max_rw)
69751 + module_addr_max_rw = (unsigned long)ret + size;
69752 + mutex_unlock(&module_mutex);
69753 + }
69754 + return ret;
69755 +}
69756 +
69757 +static void *module_alloc_update_bounds_rx(unsigned long size)
69758 +{
69759 + void *ret = module_alloc_exec(size);
69760 +
69761 + if (ret) {
69762 + mutex_lock(&module_mutex);
69763 + /* Update module bounds. */
69764 + if ((unsigned long)ret < module_addr_min_rx)
69765 + module_addr_min_rx = (unsigned long)ret;
69766 + if ((unsigned long)ret + size > module_addr_max_rx)
69767 + module_addr_max_rx = (unsigned long)ret + size;
69768 mutex_unlock(&module_mutex);
69769 }
69770 return ret;
69771 @@ -2610,8 +2648,14 @@ static struct module *setup_load_info(struct load_info *info)
69772 static int check_modinfo(struct module *mod, struct load_info *info)
69773 {
69774 const char *modmagic = get_modinfo(info, "vermagic");
69775 + const char *license = get_modinfo(info, "license");
69776 int err;
69777
69778 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
69779 + if (!license || !license_is_gpl_compatible(license))
69780 + return -ENOEXEC;
69781 +#endif
69782 +
69783 /* This is allowed: modprobe --force will invalidate it. */
69784 if (!modmagic) {
69785 err = try_to_force_load(mod, "bad vermagic");
69786 @@ -2634,7 +2678,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
69787 }
69788
69789 /* Set up license info based on the info section */
69790 - set_license(mod, get_modinfo(info, "license"));
69791 + set_license(mod, license);
69792
69793 return 0;
69794 }
69795 @@ -2728,7 +2772,7 @@ static int move_module(struct module *mod, struct load_info *info)
69796 void *ptr;
69797
69798 /* Do the allocs. */
69799 - ptr = module_alloc_update_bounds(mod->core_size);
69800 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
69801 /*
69802 * The pointer to this block is stored in the module structure
69803 * which is inside the block. Just mark it as not being a
69804 @@ -2738,23 +2782,50 @@ static int move_module(struct module *mod, struct load_info *info)
69805 if (!ptr)
69806 return -ENOMEM;
69807
69808 - memset(ptr, 0, mod->core_size);
69809 - mod->module_core = ptr;
69810 + memset(ptr, 0, mod->core_size_rw);
69811 + mod->module_core_rw = ptr;
69812
69813 - ptr = module_alloc_update_bounds(mod->init_size);
69814 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
69815 /*
69816 * The pointer to this block is stored in the module structure
69817 * which is inside the block. This block doesn't need to be
69818 * scanned as it contains data and code that will be freed
69819 * after the module is initialized.
69820 */
69821 - kmemleak_ignore(ptr);
69822 - if (!ptr && mod->init_size) {
69823 - module_free(mod, mod->module_core);
69824 + kmemleak_not_leak(ptr);
69825 + if (!ptr && mod->init_size_rw) {
69826 + module_free(mod, mod->module_core_rw);
69827 return -ENOMEM;
69828 }
69829 - memset(ptr, 0, mod->init_size);
69830 - mod->module_init = ptr;
69831 + memset(ptr, 0, mod->init_size_rw);
69832 + mod->module_init_rw = ptr;
69833 +
69834 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
69835 + kmemleak_not_leak(ptr);
69836 + if (!ptr) {
69837 + module_free(mod, mod->module_init_rw);
69838 + module_free(mod, mod->module_core_rw);
69839 + return -ENOMEM;
69840 + }
69841 +
69842 + pax_open_kernel();
69843 + memset(ptr, 0, mod->core_size_rx);
69844 + pax_close_kernel();
69845 + mod->module_core_rx = ptr;
69846 +
69847 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
69848 + kmemleak_not_leak(ptr);
69849 + if (!ptr && mod->init_size_rx) {
69850 + module_free_exec(mod, mod->module_core_rx);
69851 + module_free(mod, mod->module_init_rw);
69852 + module_free(mod, mod->module_core_rw);
69853 + return -ENOMEM;
69854 + }
69855 +
69856 + pax_open_kernel();
69857 + memset(ptr, 0, mod->init_size_rx);
69858 + pax_close_kernel();
69859 + mod->module_init_rx = ptr;
69860
69861 /* Transfer each section which specifies SHF_ALLOC */
69862 pr_debug("final section addresses:\n");
69863 @@ -2765,16 +2836,45 @@ static int move_module(struct module *mod, struct load_info *info)
69864 if (!(shdr->sh_flags & SHF_ALLOC))
69865 continue;
69866
69867 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
69868 - dest = mod->module_init
69869 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69870 - else
69871 - dest = mod->module_core + shdr->sh_entsize;
69872 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
69873 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69874 + dest = mod->module_init_rw
69875 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69876 + else
69877 + dest = mod->module_init_rx
69878 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69879 + } else {
69880 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69881 + dest = mod->module_core_rw + shdr->sh_entsize;
69882 + else
69883 + dest = mod->module_core_rx + shdr->sh_entsize;
69884 + }
69885 +
69886 + if (shdr->sh_type != SHT_NOBITS) {
69887 +
69888 +#ifdef CONFIG_PAX_KERNEXEC
69889 +#ifdef CONFIG_X86_64
69890 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
69891 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
69892 +#endif
69893 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
69894 + pax_open_kernel();
69895 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69896 + pax_close_kernel();
69897 + } else
69898 +#endif
69899
69900 - if (shdr->sh_type != SHT_NOBITS)
69901 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69902 + }
69903 /* Update sh_addr to point to copy in image. */
69904 - shdr->sh_addr = (unsigned long)dest;
69905 +
69906 +#ifdef CONFIG_PAX_KERNEXEC
69907 + if (shdr->sh_flags & SHF_EXECINSTR)
69908 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
69909 + else
69910 +#endif
69911 +
69912 + shdr->sh_addr = (unsigned long)dest;
69913 pr_debug("\t0x%lx %s\n",
69914 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
69915 }
69916 @@ -2829,12 +2929,12 @@ static void flush_module_icache(const struct module *mod)
69917 * Do it before processing of module parameters, so the module
69918 * can provide parameter accessor functions of its own.
69919 */
69920 - if (mod->module_init)
69921 - flush_icache_range((unsigned long)mod->module_init,
69922 - (unsigned long)mod->module_init
69923 - + mod->init_size);
69924 - flush_icache_range((unsigned long)mod->module_core,
69925 - (unsigned long)mod->module_core + mod->core_size);
69926 + if (mod->module_init_rx)
69927 + flush_icache_range((unsigned long)mod->module_init_rx,
69928 + (unsigned long)mod->module_init_rx
69929 + + mod->init_size_rx);
69930 + flush_icache_range((unsigned long)mod->module_core_rx,
69931 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
69932
69933 set_fs(old_fs);
69934 }
69935 @@ -2904,8 +3004,10 @@ out:
69936 static void module_deallocate(struct module *mod, struct load_info *info)
69937 {
69938 percpu_modfree(mod);
69939 - module_free(mod, mod->module_init);
69940 - module_free(mod, mod->module_core);
69941 + module_free_exec(mod, mod->module_init_rx);
69942 + module_free_exec(mod, mod->module_core_rx);
69943 + module_free(mod, mod->module_init_rw);
69944 + module_free(mod, mod->module_core_rw);
69945 }
69946
69947 int __weak module_finalize(const Elf_Ehdr *hdr,
69948 @@ -2918,7 +3020,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
69949 static int post_relocation(struct module *mod, const struct load_info *info)
69950 {
69951 /* Sort exception table now relocations are done. */
69952 + pax_open_kernel();
69953 sort_extable(mod->extable, mod->extable + mod->num_exentries);
69954 + pax_close_kernel();
69955
69956 /* Copy relocated percpu area over. */
69957 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
69958 @@ -2989,9 +3093,38 @@ static struct module *load_module(void __user *umod,
69959 if (err)
69960 goto free_unload;
69961
69962 + /* Now copy in args */
69963 + mod->args = strndup_user(uargs, ~0UL >> 1);
69964 + if (IS_ERR(mod->args)) {
69965 + err = PTR_ERR(mod->args);
69966 + goto free_unload;
69967 + }
69968 +
69969 /* Set up MODINFO_ATTR fields */
69970 setup_modinfo(mod, &info);
69971
69972 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69973 + {
69974 + char *p, *p2;
69975 +
69976 + if (strstr(mod->args, "grsec_modharden_netdev")) {
69977 + 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);
69978 + err = -EPERM;
69979 + goto free_modinfo;
69980 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
69981 + p += sizeof("grsec_modharden_normal") - 1;
69982 + p2 = strstr(p, "_");
69983 + if (p2) {
69984 + *p2 = '\0';
69985 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
69986 + *p2 = '_';
69987 + }
69988 + err = -EPERM;
69989 + goto free_modinfo;
69990 + }
69991 + }
69992 +#endif
69993 +
69994 /* Fix up syms, so that st_value is a pointer to location. */
69995 err = simplify_symbols(mod, &info);
69996 if (err < 0)
69997 @@ -3007,13 +3140,6 @@ static struct module *load_module(void __user *umod,
69998
69999 flush_module_icache(mod);
70000
70001 - /* Now copy in args */
70002 - mod->args = strndup_user(uargs, ~0UL >> 1);
70003 - if (IS_ERR(mod->args)) {
70004 - err = PTR_ERR(mod->args);
70005 - goto free_arch_cleanup;
70006 - }
70007 -
70008 /* Mark state as coming so strong_try_module_get() ignores us. */
70009 mod->state = MODULE_STATE_COMING;
70010
70011 @@ -3081,11 +3207,11 @@ again:
70012 unlock:
70013 mutex_unlock(&module_mutex);
70014 synchronize_sched();
70015 - kfree(mod->args);
70016 free_arch_cleanup:
70017 module_arch_cleanup(mod);
70018 free_modinfo:
70019 free_modinfo(mod);
70020 + kfree(mod->args);
70021 free_unload:
70022 module_unload_free(mod);
70023 free_module:
70024 @@ -3126,16 +3252,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70025 MODULE_STATE_COMING, mod);
70026
70027 /* Set RO and NX regions for core */
70028 - set_section_ro_nx(mod->module_core,
70029 - mod->core_text_size,
70030 - mod->core_ro_size,
70031 - mod->core_size);
70032 + set_section_ro_nx(mod->module_core_rx,
70033 + mod->core_size_rx,
70034 + mod->core_size_rx,
70035 + mod->core_size_rx);
70036
70037 /* Set RO and NX regions for init */
70038 - set_section_ro_nx(mod->module_init,
70039 - mod->init_text_size,
70040 - mod->init_ro_size,
70041 - mod->init_size);
70042 + set_section_ro_nx(mod->module_init_rx,
70043 + mod->init_size_rx,
70044 + mod->init_size_rx,
70045 + mod->init_size_rx);
70046
70047 do_mod_ctors(mod);
70048 /* Start the module */
70049 @@ -3180,11 +3306,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70050 mod->strtab = mod->core_strtab;
70051 #endif
70052 unset_module_init_ro_nx(mod);
70053 - module_free(mod, mod->module_init);
70054 - mod->module_init = NULL;
70055 - mod->init_size = 0;
70056 - mod->init_ro_size = 0;
70057 - mod->init_text_size = 0;
70058 + module_free(mod, mod->module_init_rw);
70059 + module_free_exec(mod, mod->module_init_rx);
70060 + mod->module_init_rw = NULL;
70061 + mod->module_init_rx = NULL;
70062 + mod->init_size_rw = 0;
70063 + mod->init_size_rx = 0;
70064 mutex_unlock(&module_mutex);
70065 wake_up_all(&module_wq);
70066
70067 @@ -3216,10 +3343,16 @@ static const char *get_ksymbol(struct module *mod,
70068 unsigned long nextval;
70069
70070 /* At worse, next value is at end of module */
70071 - if (within_module_init(addr, mod))
70072 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
70073 + if (within_module_init_rx(addr, mod))
70074 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70075 + else if (within_module_init_rw(addr, mod))
70076 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70077 + else if (within_module_core_rx(addr, mod))
70078 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70079 + else if (within_module_core_rw(addr, mod))
70080 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70081 else
70082 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
70083 + return NULL;
70084
70085 /* Scan for closest preceding symbol, and next symbol. (ELF
70086 starts real symbols at 1). */
70087 @@ -3454,7 +3587,7 @@ static int m_show(struct seq_file *m, void *p)
70088 char buf[8];
70089
70090 seq_printf(m, "%s %u",
70091 - mod->name, mod->init_size + mod->core_size);
70092 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70093 print_unload_info(m, mod);
70094
70095 /* Informative for users. */
70096 @@ -3463,7 +3596,7 @@ static int m_show(struct seq_file *m, void *p)
70097 mod->state == MODULE_STATE_COMING ? "Loading":
70098 "Live");
70099 /* Used by oprofile and other similar tools. */
70100 - seq_printf(m, " 0x%pK", mod->module_core);
70101 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70102
70103 /* Taints info */
70104 if (mod->taints)
70105 @@ -3499,7 +3632,17 @@ static const struct file_operations proc_modules_operations = {
70106
70107 static int __init proc_modules_init(void)
70108 {
70109 +#ifndef CONFIG_GRKERNSEC_HIDESYM
70110 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70111 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70112 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70113 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70114 +#else
70115 proc_create("modules", 0, NULL, &proc_modules_operations);
70116 +#endif
70117 +#else
70118 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70119 +#endif
70120 return 0;
70121 }
70122 module_init(proc_modules_init);
70123 @@ -3558,12 +3701,12 @@ struct module *__module_address(unsigned long addr)
70124 {
70125 struct module *mod;
70126
70127 - if (addr < module_addr_min || addr > module_addr_max)
70128 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70129 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
70130 return NULL;
70131
70132 list_for_each_entry_rcu(mod, &modules, list)
70133 - if (within_module_core(addr, mod)
70134 - || within_module_init(addr, mod))
70135 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
70136 return mod;
70137 return NULL;
70138 }
70139 @@ -3597,11 +3740,20 @@ bool is_module_text_address(unsigned long addr)
70140 */
70141 struct module *__module_text_address(unsigned long addr)
70142 {
70143 - struct module *mod = __module_address(addr);
70144 + struct module *mod;
70145 +
70146 +#ifdef CONFIG_X86_32
70147 + addr = ktla_ktva(addr);
70148 +#endif
70149 +
70150 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70151 + return NULL;
70152 +
70153 + mod = __module_address(addr);
70154 +
70155 if (mod) {
70156 /* Make sure it's within the text section. */
70157 - if (!within(addr, mod->module_init, mod->init_text_size)
70158 - && !within(addr, mod->module_core, mod->core_text_size))
70159 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70160 mod = NULL;
70161 }
70162 return mod;
70163 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70164 index 7e3443f..b2a1e6b 100644
70165 --- a/kernel/mutex-debug.c
70166 +++ b/kernel/mutex-debug.c
70167 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70168 }
70169
70170 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70171 - struct thread_info *ti)
70172 + struct task_struct *task)
70173 {
70174 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70175
70176 /* Mark the current thread as blocked on the lock: */
70177 - ti->task->blocked_on = waiter;
70178 + task->blocked_on = waiter;
70179 }
70180
70181 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70182 - struct thread_info *ti)
70183 + struct task_struct *task)
70184 {
70185 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
70186 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
70187 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
70188 - ti->task->blocked_on = NULL;
70189 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
70190 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
70191 + task->blocked_on = NULL;
70192
70193 list_del_init(&waiter->list);
70194 waiter->task = NULL;
70195 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
70196 index 0799fd3..d06ae3b 100644
70197 --- a/kernel/mutex-debug.h
70198 +++ b/kernel/mutex-debug.h
70199 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
70200 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
70201 extern void debug_mutex_add_waiter(struct mutex *lock,
70202 struct mutex_waiter *waiter,
70203 - struct thread_info *ti);
70204 + struct task_struct *task);
70205 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70206 - struct thread_info *ti);
70207 + struct task_struct *task);
70208 extern void debug_mutex_unlock(struct mutex *lock);
70209 extern void debug_mutex_init(struct mutex *lock, const char *name,
70210 struct lock_class_key *key);
70211 diff --git a/kernel/mutex.c b/kernel/mutex.c
70212 index a307cc9..27fd2e9 100644
70213 --- a/kernel/mutex.c
70214 +++ b/kernel/mutex.c
70215 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70216 spin_lock_mutex(&lock->wait_lock, flags);
70217
70218 debug_mutex_lock_common(lock, &waiter);
70219 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
70220 + debug_mutex_add_waiter(lock, &waiter, task);
70221
70222 /* add waiting tasks to the end of the waitqueue (FIFO): */
70223 list_add_tail(&waiter.list, &lock->wait_list);
70224 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70225 * TASK_UNINTERRUPTIBLE case.)
70226 */
70227 if (unlikely(signal_pending_state(state, task))) {
70228 - mutex_remove_waiter(lock, &waiter,
70229 - task_thread_info(task));
70230 + mutex_remove_waiter(lock, &waiter, task);
70231 mutex_release(&lock->dep_map, 1, ip);
70232 spin_unlock_mutex(&lock->wait_lock, flags);
70233
70234 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70235 done:
70236 lock_acquired(&lock->dep_map, ip);
70237 /* got the lock - rejoice! */
70238 - mutex_remove_waiter(lock, &waiter, current_thread_info());
70239 + mutex_remove_waiter(lock, &waiter, task);
70240 mutex_set_owner(lock);
70241
70242 /* set it to 0 if there are no waiters left: */
70243 diff --git a/kernel/notifier.c b/kernel/notifier.c
70244 index 2d5cc4c..d9ea600 100644
70245 --- a/kernel/notifier.c
70246 +++ b/kernel/notifier.c
70247 @@ -5,6 +5,7 @@
70248 #include <linux/rcupdate.h>
70249 #include <linux/vmalloc.h>
70250 #include <linux/reboot.h>
70251 +#include <linux/mm.h>
70252
70253 /*
70254 * Notifier list for kernel code which wants to be called
70255 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
70256 while ((*nl) != NULL) {
70257 if (n->priority > (*nl)->priority)
70258 break;
70259 - nl = &((*nl)->next);
70260 + nl = (struct notifier_block **)&((*nl)->next);
70261 }
70262 - n->next = *nl;
70263 + pax_open_kernel();
70264 + *(const void **)&n->next = *nl;
70265 rcu_assign_pointer(*nl, n);
70266 + pax_close_kernel();
70267 return 0;
70268 }
70269
70270 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
70271 return 0;
70272 if (n->priority > (*nl)->priority)
70273 break;
70274 - nl = &((*nl)->next);
70275 + nl = (struct notifier_block **)&((*nl)->next);
70276 }
70277 - n->next = *nl;
70278 + pax_open_kernel();
70279 + *(const void **)&n->next = *nl;
70280 rcu_assign_pointer(*nl, n);
70281 + pax_close_kernel();
70282 return 0;
70283 }
70284
70285 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
70286 {
70287 while ((*nl) != NULL) {
70288 if ((*nl) == n) {
70289 + pax_open_kernel();
70290 rcu_assign_pointer(*nl, n->next);
70291 + pax_close_kernel();
70292 return 0;
70293 }
70294 - nl = &((*nl)->next);
70295 + nl = (struct notifier_block **)&((*nl)->next);
70296 }
70297 return -ENOENT;
70298 }
70299 diff --git a/kernel/panic.c b/kernel/panic.c
70300 index e1b2822..5edc1d9 100644
70301 --- a/kernel/panic.c
70302 +++ b/kernel/panic.c
70303 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
70304 const char *board;
70305
70306 printk(KERN_WARNING "------------[ cut here ]------------\n");
70307 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
70308 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
70309 board = dmi_get_system_info(DMI_PRODUCT_NAME);
70310 if (board)
70311 printk(KERN_WARNING "Hardware name: %s\n", board);
70312 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
70313 */
70314 void __stack_chk_fail(void)
70315 {
70316 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
70317 + dump_stack();
70318 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
70319 __builtin_return_address(0));
70320 }
70321 EXPORT_SYMBOL(__stack_chk_fail);
70322 diff --git a/kernel/pid.c b/kernel/pid.c
70323 index aebd4f5..1693c13 100644
70324 --- a/kernel/pid.c
70325 +++ b/kernel/pid.c
70326 @@ -33,6 +33,7 @@
70327 #include <linux/rculist.h>
70328 #include <linux/bootmem.h>
70329 #include <linux/hash.h>
70330 +#include <linux/security.h>
70331 #include <linux/pid_namespace.h>
70332 #include <linux/init_task.h>
70333 #include <linux/syscalls.h>
70334 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
70335
70336 int pid_max = PID_MAX_DEFAULT;
70337
70338 -#define RESERVED_PIDS 300
70339 +#define RESERVED_PIDS 500
70340
70341 int pid_max_min = RESERVED_PIDS + 1;
70342 int pid_max_max = PID_MAX_LIMIT;
70343 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
70344 */
70345 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
70346 {
70347 + struct task_struct *task;
70348 +
70349 rcu_lockdep_assert(rcu_read_lock_held(),
70350 "find_task_by_pid_ns() needs rcu_read_lock()"
70351 " protection");
70352 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70353 +
70354 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70355 +
70356 + if (gr_pid_is_chrooted(task))
70357 + return NULL;
70358 +
70359 + return task;
70360 }
70361
70362 struct task_struct *find_task_by_vpid(pid_t vnr)
70363 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
70364 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
70365 }
70366
70367 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
70368 +{
70369 + rcu_lockdep_assert(rcu_read_lock_held(),
70370 + "find_task_by_pid_ns() needs rcu_read_lock()"
70371 + " protection");
70372 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
70373 +}
70374 +
70375 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
70376 {
70377 struct pid *pid;
70378 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
70379 index 125cb67..2e5c8ad 100644
70380 --- a/kernel/posix-cpu-timers.c
70381 +++ b/kernel/posix-cpu-timers.c
70382 @@ -6,9 +6,11 @@
70383 #include <linux/posix-timers.h>
70384 #include <linux/errno.h>
70385 #include <linux/math64.h>
70386 +#include <linux/security.h>
70387 #include <asm/uaccess.h>
70388 #include <linux/kernel_stat.h>
70389 #include <trace/events/timer.h>
70390 +#include <linux/random.h>
70391
70392 /*
70393 * Called after updating RLIMIT_CPU to run cpu timer and update
70394 @@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
70395 */
70396 void posix_cpu_timers_exit(struct task_struct *tsk)
70397 {
70398 + add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
70399 + sizeof(unsigned long long));
70400 cleanup_timers(tsk->cpu_timers,
70401 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
70402
70403 @@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
70404
70405 static __init int init_posix_cpu_timers(void)
70406 {
70407 - struct k_clock process = {
70408 + static struct k_clock process = {
70409 .clock_getres = process_cpu_clock_getres,
70410 .clock_get = process_cpu_clock_get,
70411 .timer_create = process_cpu_timer_create,
70412 .nsleep = process_cpu_nsleep,
70413 .nsleep_restart = process_cpu_nsleep_restart,
70414 };
70415 - struct k_clock thread = {
70416 + static struct k_clock thread = {
70417 .clock_getres = thread_cpu_clock_getres,
70418 .clock_get = thread_cpu_clock_get,
70419 .timer_create = thread_cpu_timer_create,
70420 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
70421 index 69185ae..cc2847a 100644
70422 --- a/kernel/posix-timers.c
70423 +++ b/kernel/posix-timers.c
70424 @@ -43,6 +43,7 @@
70425 #include <linux/idr.h>
70426 #include <linux/posix-clock.h>
70427 #include <linux/posix-timers.h>
70428 +#include <linux/grsecurity.h>
70429 #include <linux/syscalls.h>
70430 #include <linux/wait.h>
70431 #include <linux/workqueue.h>
70432 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
70433 * which we beg off on and pass to do_sys_settimeofday().
70434 */
70435
70436 -static struct k_clock posix_clocks[MAX_CLOCKS];
70437 +static struct k_clock *posix_clocks[MAX_CLOCKS];
70438
70439 /*
70440 * These ones are defined below.
70441 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
70442 */
70443 static __init int init_posix_timers(void)
70444 {
70445 - struct k_clock clock_realtime = {
70446 + static struct k_clock clock_realtime = {
70447 .clock_getres = hrtimer_get_res,
70448 .clock_get = posix_clock_realtime_get,
70449 .clock_set = posix_clock_realtime_set,
70450 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
70451 .timer_get = common_timer_get,
70452 .timer_del = common_timer_del,
70453 };
70454 - struct k_clock clock_monotonic = {
70455 + static struct k_clock clock_monotonic = {
70456 .clock_getres = hrtimer_get_res,
70457 .clock_get = posix_ktime_get_ts,
70458 .nsleep = common_nsleep,
70459 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
70460 .timer_get = common_timer_get,
70461 .timer_del = common_timer_del,
70462 };
70463 - struct k_clock clock_monotonic_raw = {
70464 + static struct k_clock clock_monotonic_raw = {
70465 .clock_getres = hrtimer_get_res,
70466 .clock_get = posix_get_monotonic_raw,
70467 };
70468 - struct k_clock clock_realtime_coarse = {
70469 + static struct k_clock clock_realtime_coarse = {
70470 .clock_getres = posix_get_coarse_res,
70471 .clock_get = posix_get_realtime_coarse,
70472 };
70473 - struct k_clock clock_monotonic_coarse = {
70474 + static struct k_clock clock_monotonic_coarse = {
70475 .clock_getres = posix_get_coarse_res,
70476 .clock_get = posix_get_monotonic_coarse,
70477 };
70478 - struct k_clock clock_boottime = {
70479 + static struct k_clock clock_boottime = {
70480 .clock_getres = hrtimer_get_res,
70481 .clock_get = posix_get_boottime,
70482 .nsleep = common_nsleep,
70483 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
70484 return;
70485 }
70486
70487 - posix_clocks[clock_id] = *new_clock;
70488 + posix_clocks[clock_id] = new_clock;
70489 }
70490 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
70491
70492 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
70493 return (id & CLOCKFD_MASK) == CLOCKFD ?
70494 &clock_posix_dynamic : &clock_posix_cpu;
70495
70496 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
70497 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
70498 return NULL;
70499 - return &posix_clocks[id];
70500 + return posix_clocks[id];
70501 }
70502
70503 static int common_timer_create(struct k_itimer *new_timer)
70504 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
70505 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
70506 return -EFAULT;
70507
70508 + /* only the CLOCK_REALTIME clock can be set, all other clocks
70509 + have their clock_set fptr set to a nosettime dummy function
70510 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
70511 + call common_clock_set, which calls do_sys_settimeofday, which
70512 + we hook
70513 + */
70514 +
70515 return kc->clock_set(which_clock, &new_tp);
70516 }
70517
70518 diff --git a/kernel/power/process.c b/kernel/power/process.c
70519 index 87da817..30ddd13 100644
70520 --- a/kernel/power/process.c
70521 +++ b/kernel/power/process.c
70522 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
70523 u64 elapsed_csecs64;
70524 unsigned int elapsed_csecs;
70525 bool wakeup = false;
70526 + bool timedout = false;
70527
70528 do_gettimeofday(&start);
70529
70530 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
70531
70532 while (true) {
70533 todo = 0;
70534 + if (time_after(jiffies, end_time))
70535 + timedout = true;
70536 read_lock(&tasklist_lock);
70537 do_each_thread(g, p) {
70538 if (p == current || !freeze_task(p))
70539 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
70540 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
70541 * transition can't race with task state testing here.
70542 */
70543 - if (!task_is_stopped_or_traced(p) &&
70544 - !freezer_should_skip(p))
70545 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
70546 todo++;
70547 + if (timedout) {
70548 + printk(KERN_ERR "Task refusing to freeze:\n");
70549 + sched_show_task(p);
70550 + }
70551 + }
70552 } while_each_thread(g, p);
70553 read_unlock(&tasklist_lock);
70554
70555 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
70556 todo += wq_busy;
70557 }
70558
70559 - if (!todo || time_after(jiffies, end_time))
70560 + if (!todo || timedout)
70561 break;
70562
70563 if (pm_wakeup_pending()) {
70564 diff --git a/kernel/printk.c b/kernel/printk.c
70565 index f8e0b5a..dda2a5c 100644
70566 --- a/kernel/printk.c
70567 +++ b/kernel/printk.c
70568 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
70569 if (from_file && type != SYSLOG_ACTION_OPEN)
70570 return 0;
70571
70572 +#ifdef CONFIG_GRKERNSEC_DMESG
70573 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
70574 + return -EPERM;
70575 +#endif
70576 +
70577 if (syslog_action_restricted(type)) {
70578 if (capable(CAP_SYSLOG))
70579 return 0;
70580 diff --git a/kernel/profile.c b/kernel/profile.c
70581 index 76b8e77..a2930e8 100644
70582 --- a/kernel/profile.c
70583 +++ b/kernel/profile.c
70584 @@ -39,7 +39,7 @@ struct profile_hit {
70585 /* Oprofile timer tick hook */
70586 static int (*timer_hook)(struct pt_regs *) __read_mostly;
70587
70588 -static atomic_t *prof_buffer;
70589 +static atomic_unchecked_t *prof_buffer;
70590 static unsigned long prof_len, prof_shift;
70591
70592 int prof_on __read_mostly;
70593 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
70594 hits[i].pc = 0;
70595 continue;
70596 }
70597 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
70598 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
70599 hits[i].hits = hits[i].pc = 0;
70600 }
70601 }
70602 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
70603 * Add the current hit(s) and flush the write-queue out
70604 * to the global buffer:
70605 */
70606 - atomic_add(nr_hits, &prof_buffer[pc]);
70607 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
70608 for (i = 0; i < NR_PROFILE_HIT; ++i) {
70609 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
70610 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
70611 hits[i].pc = hits[i].hits = 0;
70612 }
70613 out:
70614 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
70615 {
70616 unsigned long pc;
70617 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
70618 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
70619 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
70620 }
70621 #endif /* !CONFIG_SMP */
70622
70623 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
70624 return -EFAULT;
70625 buf++; p++; count--; read++;
70626 }
70627 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
70628 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
70629 if (copy_to_user(buf, (void *)pnt, count))
70630 return -EFAULT;
70631 read += count;
70632 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
70633 }
70634 #endif
70635 profile_discard_flip_buffers();
70636 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
70637 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
70638 return count;
70639 }
70640
70641 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
70642 index 1f5e55d..8b8f969 100644
70643 --- a/kernel/ptrace.c
70644 +++ b/kernel/ptrace.c
70645 @@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
70646
70647 if (seize)
70648 flags |= PT_SEIZED;
70649 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
70650 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
70651 flags |= PT_PTRACE_CAP;
70652 task->ptrace = flags;
70653
70654 @@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
70655 break;
70656 return -EIO;
70657 }
70658 - if (copy_to_user(dst, buf, retval))
70659 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
70660 return -EFAULT;
70661 copied += retval;
70662 src += retval;
70663 @@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
70664 bool seized = child->ptrace & PT_SEIZED;
70665 int ret = -EIO;
70666 siginfo_t siginfo, *si;
70667 - void __user *datavp = (void __user *) data;
70668 + void __user *datavp = (__force void __user *) data;
70669 unsigned long __user *datalp = datavp;
70670 unsigned long flags;
70671
70672 @@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
70673 goto out;
70674 }
70675
70676 + if (gr_handle_ptrace(child, request)) {
70677 + ret = -EPERM;
70678 + goto out_put_task_struct;
70679 + }
70680 +
70681 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
70682 ret = ptrace_attach(child, request, addr, data);
70683 /*
70684 * Some architectures need to do book-keeping after
70685 * a ptrace attach.
70686 */
70687 - if (!ret)
70688 + if (!ret) {
70689 arch_ptrace_attach(child);
70690 + gr_audit_ptrace(child);
70691 + }
70692 goto out_put_task_struct;
70693 }
70694
70695 @@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
70696 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
70697 if (copied != sizeof(tmp))
70698 return -EIO;
70699 - return put_user(tmp, (unsigned long __user *)data);
70700 + return put_user(tmp, (__force unsigned long __user *)data);
70701 }
70702
70703 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
70704 @@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
70705 goto out;
70706 }
70707
70708 + if (gr_handle_ptrace(child, request)) {
70709 + ret = -EPERM;
70710 + goto out_put_task_struct;
70711 + }
70712 +
70713 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
70714 ret = ptrace_attach(child, request, addr, data);
70715 /*
70716 * Some architectures need to do book-keeping after
70717 * a ptrace attach.
70718 */
70719 - if (!ret)
70720 + if (!ret) {
70721 arch_ptrace_attach(child);
70722 + gr_audit_ptrace(child);
70723 + }
70724 goto out_put_task_struct;
70725 }
70726
70727 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
70728 index e4c6a59..c86621a 100644
70729 --- a/kernel/rcutiny.c
70730 +++ b/kernel/rcutiny.c
70731 @@ -46,7 +46,7 @@
70732 struct rcu_ctrlblk;
70733 static void invoke_rcu_callbacks(void);
70734 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
70735 -static void rcu_process_callbacks(struct softirq_action *unused);
70736 +static void rcu_process_callbacks(void);
70737 static void __call_rcu(struct rcu_head *head,
70738 void (*func)(struct rcu_head *rcu),
70739 struct rcu_ctrlblk *rcp);
70740 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
70741 rcu_is_callbacks_kthread()));
70742 }
70743
70744 -static void rcu_process_callbacks(struct softirq_action *unused)
70745 +static void rcu_process_callbacks(void)
70746 {
70747 __rcu_process_callbacks(&rcu_sched_ctrlblk);
70748 __rcu_process_callbacks(&rcu_bh_ctrlblk);
70749 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
70750 index 3d01902..afbf46e 100644
70751 --- a/kernel/rcutiny_plugin.h
70752 +++ b/kernel/rcutiny_plugin.h
70753 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
70754 have_rcu_kthread_work = morework;
70755 local_irq_restore(flags);
70756 if (work)
70757 - rcu_process_callbacks(NULL);
70758 + rcu_process_callbacks();
70759 schedule_timeout_interruptible(1); /* Leave CPU for others. */
70760 }
70761
70762 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
70763 index aaa7b9f..055ff1e 100644
70764 --- a/kernel/rcutorture.c
70765 +++ b/kernel/rcutorture.c
70766 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
70767 { 0 };
70768 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
70769 { 0 };
70770 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
70771 -static atomic_t n_rcu_torture_alloc;
70772 -static atomic_t n_rcu_torture_alloc_fail;
70773 -static atomic_t n_rcu_torture_free;
70774 -static atomic_t n_rcu_torture_mberror;
70775 -static atomic_t n_rcu_torture_error;
70776 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
70777 +static atomic_unchecked_t n_rcu_torture_alloc;
70778 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
70779 +static atomic_unchecked_t n_rcu_torture_free;
70780 +static atomic_unchecked_t n_rcu_torture_mberror;
70781 +static atomic_unchecked_t n_rcu_torture_error;
70782 static long n_rcu_torture_barrier_error;
70783 static long n_rcu_torture_boost_ktrerror;
70784 static long n_rcu_torture_boost_rterror;
70785 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
70786
70787 spin_lock_bh(&rcu_torture_lock);
70788 if (list_empty(&rcu_torture_freelist)) {
70789 - atomic_inc(&n_rcu_torture_alloc_fail);
70790 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
70791 spin_unlock_bh(&rcu_torture_lock);
70792 return NULL;
70793 }
70794 - atomic_inc(&n_rcu_torture_alloc);
70795 + atomic_inc_unchecked(&n_rcu_torture_alloc);
70796 p = rcu_torture_freelist.next;
70797 list_del_init(p);
70798 spin_unlock_bh(&rcu_torture_lock);
70799 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
70800 static void
70801 rcu_torture_free(struct rcu_torture *p)
70802 {
70803 - atomic_inc(&n_rcu_torture_free);
70804 + atomic_inc_unchecked(&n_rcu_torture_free);
70805 spin_lock_bh(&rcu_torture_lock);
70806 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
70807 spin_unlock_bh(&rcu_torture_lock);
70808 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
70809 i = rp->rtort_pipe_count;
70810 if (i > RCU_TORTURE_PIPE_LEN)
70811 i = RCU_TORTURE_PIPE_LEN;
70812 - atomic_inc(&rcu_torture_wcount[i]);
70813 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70814 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
70815 rp->rtort_mbtest = 0;
70816 rcu_torture_free(rp);
70817 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
70818 i = rp->rtort_pipe_count;
70819 if (i > RCU_TORTURE_PIPE_LEN)
70820 i = RCU_TORTURE_PIPE_LEN;
70821 - atomic_inc(&rcu_torture_wcount[i]);
70822 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70823 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
70824 rp->rtort_mbtest = 0;
70825 list_del(&rp->rtort_free);
70826 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
70827 i = old_rp->rtort_pipe_count;
70828 if (i > RCU_TORTURE_PIPE_LEN)
70829 i = RCU_TORTURE_PIPE_LEN;
70830 - atomic_inc(&rcu_torture_wcount[i]);
70831 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70832 old_rp->rtort_pipe_count++;
70833 cur_ops->deferred_free(old_rp);
70834 }
70835 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
70836 }
70837 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
70838 if (p->rtort_mbtest == 0)
70839 - atomic_inc(&n_rcu_torture_mberror);
70840 + atomic_inc_unchecked(&n_rcu_torture_mberror);
70841 spin_lock(&rand_lock);
70842 cur_ops->read_delay(&rand);
70843 n_rcu_torture_timers++;
70844 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
70845 }
70846 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
70847 if (p->rtort_mbtest == 0)
70848 - atomic_inc(&n_rcu_torture_mberror);
70849 + atomic_inc_unchecked(&n_rcu_torture_mberror);
70850 cur_ops->read_delay(&rand);
70851 preempt_disable();
70852 pipe_count = p->rtort_pipe_count;
70853 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
70854 rcu_torture_current,
70855 rcu_torture_current_version,
70856 list_empty(&rcu_torture_freelist),
70857 - atomic_read(&n_rcu_torture_alloc),
70858 - atomic_read(&n_rcu_torture_alloc_fail),
70859 - atomic_read(&n_rcu_torture_free));
70860 + atomic_read_unchecked(&n_rcu_torture_alloc),
70861 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
70862 + atomic_read_unchecked(&n_rcu_torture_free));
70863 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
70864 - atomic_read(&n_rcu_torture_mberror),
70865 + atomic_read_unchecked(&n_rcu_torture_mberror),
70866 n_rcu_torture_boost_ktrerror,
70867 n_rcu_torture_boost_rterror);
70868 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
70869 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
70870 n_barrier_attempts,
70871 n_rcu_torture_barrier_error);
70872 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
70873 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
70874 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
70875 n_rcu_torture_barrier_error != 0 ||
70876 n_rcu_torture_boost_ktrerror != 0 ||
70877 n_rcu_torture_boost_rterror != 0 ||
70878 n_rcu_torture_boost_failure != 0 ||
70879 i > 1) {
70880 cnt += sprintf(&page[cnt], "!!! ");
70881 - atomic_inc(&n_rcu_torture_error);
70882 + atomic_inc_unchecked(&n_rcu_torture_error);
70883 WARN_ON_ONCE(1);
70884 }
70885 cnt += sprintf(&page[cnt], "Reader Pipe: ");
70886 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
70887 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
70888 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70889 cnt += sprintf(&page[cnt], " %d",
70890 - atomic_read(&rcu_torture_wcount[i]));
70891 + atomic_read_unchecked(&rcu_torture_wcount[i]));
70892 }
70893 cnt += sprintf(&page[cnt], "\n");
70894 if (cur_ops->stats)
70895 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
70896
70897 if (cur_ops->cleanup)
70898 cur_ops->cleanup();
70899 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70900 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70901 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
70902 else if (n_online_successes != n_online_attempts ||
70903 n_offline_successes != n_offline_attempts)
70904 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
70905
70906 rcu_torture_current = NULL;
70907 rcu_torture_current_version = 0;
70908 - atomic_set(&n_rcu_torture_alloc, 0);
70909 - atomic_set(&n_rcu_torture_alloc_fail, 0);
70910 - atomic_set(&n_rcu_torture_free, 0);
70911 - atomic_set(&n_rcu_torture_mberror, 0);
70912 - atomic_set(&n_rcu_torture_error, 0);
70913 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
70914 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
70915 + atomic_set_unchecked(&n_rcu_torture_free, 0);
70916 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
70917 + atomic_set_unchecked(&n_rcu_torture_error, 0);
70918 n_rcu_torture_barrier_error = 0;
70919 n_rcu_torture_boost_ktrerror = 0;
70920 n_rcu_torture_boost_rterror = 0;
70921 n_rcu_torture_boost_failure = 0;
70922 n_rcu_torture_boosts = 0;
70923 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
70924 - atomic_set(&rcu_torture_wcount[i], 0);
70925 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
70926 for_each_possible_cpu(cpu) {
70927 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70928 per_cpu(rcu_torture_count, cpu)[i] = 0;
70929 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
70930 index 2682295..0f2297e 100644
70931 --- a/kernel/rcutree.c
70932 +++ b/kernel/rcutree.c
70933 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
70934 rcu_prepare_for_idle(smp_processor_id());
70935 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70936 smp_mb__before_atomic_inc(); /* See above. */
70937 - atomic_inc(&rdtp->dynticks);
70938 + atomic_inc_unchecked(&rdtp->dynticks);
70939 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
70940 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70941 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70942
70943 /*
70944 * It is illegal to enter an extended quiescent state while
70945 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
70946 int user)
70947 {
70948 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
70949 - atomic_inc(&rdtp->dynticks);
70950 + atomic_inc_unchecked(&rdtp->dynticks);
70951 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70952 smp_mb__after_atomic_inc(); /* See above. */
70953 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70954 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70955 rcu_cleanup_after_idle(smp_processor_id());
70956 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
70957 if (!user && !is_idle_task(current)) {
70958 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
70959 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
70960
70961 if (rdtp->dynticks_nmi_nesting == 0 &&
70962 - (atomic_read(&rdtp->dynticks) & 0x1))
70963 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
70964 return;
70965 rdtp->dynticks_nmi_nesting++;
70966 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
70967 - atomic_inc(&rdtp->dynticks);
70968 + atomic_inc_unchecked(&rdtp->dynticks);
70969 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70970 smp_mb__after_atomic_inc(); /* See above. */
70971 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70972 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70973 }
70974
70975 /**
70976 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
70977 return;
70978 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70979 smp_mb__before_atomic_inc(); /* See above. */
70980 - atomic_inc(&rdtp->dynticks);
70981 + atomic_inc_unchecked(&rdtp->dynticks);
70982 smp_mb__after_atomic_inc(); /* Force delay to next write. */
70983 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70984 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70985 }
70986
70987 /**
70988 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
70989 int ret;
70990
70991 preempt_disable();
70992 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70993 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70994 preempt_enable();
70995 return ret;
70996 }
70997 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
70998 */
70999 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71000 {
71001 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71002 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71003 return (rdp->dynticks_snap & 0x1) == 0;
71004 }
71005
71006 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71007 unsigned int curr;
71008 unsigned int snap;
71009
71010 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71011 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71012 snap = (unsigned int)rdp->dynticks_snap;
71013
71014 /*
71015 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71016 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71017 */
71018 if (till_stall_check < 3) {
71019 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71020 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71021 till_stall_check = 3;
71022 } else if (till_stall_check > 300) {
71023 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71024 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71025 till_stall_check = 300;
71026 }
71027 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71028 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71029 rsp->qlen += rdp->qlen;
71030 rdp->n_cbs_orphaned += rdp->qlen;
71031 rdp->qlen_lazy = 0;
71032 - ACCESS_ONCE(rdp->qlen) = 0;
71033 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71034 }
71035
71036 /*
71037 @@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71038 }
71039 smp_mb(); /* List handling before counting for rcu_barrier(). */
71040 rdp->qlen_lazy -= count_lazy;
71041 - ACCESS_ONCE(rdp->qlen) -= count;
71042 + ACCESS_ONCE_RW(rdp->qlen) -= count;
71043 rdp->n_cbs_invoked += count;
71044
71045 /* Reinstate batch limit if we have worked down the excess. */
71046 @@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71047 /*
71048 * Do RCU core processing for the current CPU.
71049 */
71050 -static void rcu_process_callbacks(struct softirq_action *unused)
71051 +static void rcu_process_callbacks(void)
71052 {
71053 struct rcu_state *rsp;
71054
71055 @@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71056 local_irq_restore(flags);
71057 return;
71058 }
71059 - ACCESS_ONCE(rdp->qlen)++;
71060 + ACCESS_ONCE_RW(rdp->qlen)++;
71061 if (lazy)
71062 rdp->qlen_lazy++;
71063 else
71064 @@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71065 }
71066 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71067
71068 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71069 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71070 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71071 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71072
71073 static int synchronize_sched_expedited_cpu_stop(void *data)
71074 {
71075 @@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71076 int firstsnap, s, snap, trycount = 0;
71077
71078 /* Note that atomic_inc_return() implies full memory barrier. */
71079 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71080 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71081 get_online_cpus();
71082 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71083
71084 @@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71085 }
71086
71087 /* Check to see if someone else did our work for us. */
71088 - s = atomic_read(&sync_sched_expedited_done);
71089 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71090 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71091 smp_mb(); /* ensure test happens before caller kfree */
71092 return;
71093 @@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71094 * grace period works for us.
71095 */
71096 get_online_cpus();
71097 - snap = atomic_read(&sync_sched_expedited_started);
71098 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
71099 smp_mb(); /* ensure read is before try_stop_cpus(). */
71100 }
71101
71102 @@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71103 * than we did beat us to the punch.
71104 */
71105 do {
71106 - s = atomic_read(&sync_sched_expedited_done);
71107 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71108 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71109 smp_mb(); /* ensure test happens before caller kfree */
71110 break;
71111 }
71112 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71113 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71114
71115 put_online_cpus();
71116 }
71117 @@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71118 * ACCESS_ONCE() to prevent the compiler from speculating
71119 * the increment to precede the early-exit check.
71120 */
71121 - ACCESS_ONCE(rsp->n_barrier_done)++;
71122 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71123 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71124 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71125 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71126 @@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71127
71128 /* Increment ->n_barrier_done to prevent duplicate work. */
71129 smp_mb(); /* Keep increment after above mechanism. */
71130 - ACCESS_ONCE(rsp->n_barrier_done)++;
71131 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71132 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71133 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71134 smp_mb(); /* Keep increment before caller's subsequent code. */
71135 @@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71136 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71137 init_callback_list(rdp);
71138 rdp->qlen_lazy = 0;
71139 - ACCESS_ONCE(rdp->qlen) = 0;
71140 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71141 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71142 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71143 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71144 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71145 #ifdef CONFIG_RCU_USER_QS
71146 WARN_ON_ONCE(rdp->dynticks->in_user);
71147 #endif
71148 @@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71149 rdp->blimit = blimit;
71150 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71151 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71152 - atomic_set(&rdp->dynticks->dynticks,
71153 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71154 + atomic_set_unchecked(&rdp->dynticks->dynticks,
71155 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71156 rcu_prepare_for_idle_init(cpu);
71157 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71158
71159 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71160 index a240f03..d469618 100644
71161 --- a/kernel/rcutree.h
71162 +++ b/kernel/rcutree.h
71163 @@ -86,7 +86,7 @@ struct rcu_dynticks {
71164 long long dynticks_nesting; /* Track irq/process nesting level. */
71165 /* Process level is worth LLONG_MAX/2. */
71166 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71167 - atomic_t dynticks; /* Even value for idle, else odd. */
71168 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71169 #ifdef CONFIG_RCU_FAST_NO_HZ
71170 int dyntick_drain; /* Prepare-for-idle state variable. */
71171 unsigned long dyntick_holdoff;
71172 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71173 index f921154..34c4873 100644
71174 --- a/kernel/rcutree_plugin.h
71175 +++ b/kernel/rcutree_plugin.h
71176 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71177
71178 /* Clean up and exit. */
71179 smp_mb(); /* ensure expedited GP seen before counter increment. */
71180 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
71181 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
71182 unlock_mb_ret:
71183 mutex_unlock(&sync_rcu_preempt_exp_mutex);
71184 mb_ret:
71185 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
71186 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
71187 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
71188 cpu, ticks_value, ticks_title,
71189 - atomic_read(&rdtp->dynticks) & 0xfff,
71190 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
71191 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
71192 fast_no_hz);
71193 }
71194 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
71195 index 693513b..b9f1d63 100644
71196 --- a/kernel/rcutree_trace.c
71197 +++ b/kernel/rcutree_trace.c
71198 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
71199 rdp->completed, rdp->gpnum,
71200 rdp->passed_quiesce, rdp->qs_pending);
71201 seq_printf(m, " dt=%d/%llx/%d df=%lu",
71202 - atomic_read(&rdp->dynticks->dynticks),
71203 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71204 rdp->dynticks->dynticks_nesting,
71205 rdp->dynticks->dynticks_nmi_nesting,
71206 rdp->dynticks_fqs);
71207 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
71208 rdp->completed, rdp->gpnum,
71209 rdp->passed_quiesce, rdp->qs_pending);
71210 seq_printf(m, ",%d,%llx,%d,%lu",
71211 - atomic_read(&rdp->dynticks->dynticks),
71212 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71213 rdp->dynticks->dynticks_nesting,
71214 rdp->dynticks->dynticks_nmi_nesting,
71215 rdp->dynticks_fqs);
71216 diff --git a/kernel/resource.c b/kernel/resource.c
71217 index 73f35d4..4684fc4 100644
71218 --- a/kernel/resource.c
71219 +++ b/kernel/resource.c
71220 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
71221
71222 static int __init ioresources_init(void)
71223 {
71224 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71225 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71226 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
71227 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
71228 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71229 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
71230 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
71231 +#endif
71232 +#else
71233 proc_create("ioports", 0, NULL, &proc_ioports_operations);
71234 proc_create("iomem", 0, NULL, &proc_iomem_operations);
71235 +#endif
71236 return 0;
71237 }
71238 __initcall(ioresources_init);
71239 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
71240 index 98ec494..4241d6d 100644
71241 --- a/kernel/rtmutex-tester.c
71242 +++ b/kernel/rtmutex-tester.c
71243 @@ -20,7 +20,7 @@
71244 #define MAX_RT_TEST_MUTEXES 8
71245
71246 static spinlock_t rttest_lock;
71247 -static atomic_t rttest_event;
71248 +static atomic_unchecked_t rttest_event;
71249
71250 struct test_thread_data {
71251 int opcode;
71252 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71253
71254 case RTTEST_LOCKCONT:
71255 td->mutexes[td->opdata] = 1;
71256 - td->event = atomic_add_return(1, &rttest_event);
71257 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71258 return 0;
71259
71260 case RTTEST_RESET:
71261 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71262 return 0;
71263
71264 case RTTEST_RESETEVENT:
71265 - atomic_set(&rttest_event, 0);
71266 + atomic_set_unchecked(&rttest_event, 0);
71267 return 0;
71268
71269 default:
71270 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71271 return ret;
71272
71273 td->mutexes[id] = 1;
71274 - td->event = atomic_add_return(1, &rttest_event);
71275 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71276 rt_mutex_lock(&mutexes[id]);
71277 - td->event = atomic_add_return(1, &rttest_event);
71278 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71279 td->mutexes[id] = 4;
71280 return 0;
71281
71282 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71283 return ret;
71284
71285 td->mutexes[id] = 1;
71286 - td->event = atomic_add_return(1, &rttest_event);
71287 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71288 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
71289 - td->event = atomic_add_return(1, &rttest_event);
71290 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71291 td->mutexes[id] = ret ? 0 : 4;
71292 return ret ? -EINTR : 0;
71293
71294 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71295 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
71296 return ret;
71297
71298 - td->event = atomic_add_return(1, &rttest_event);
71299 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71300 rt_mutex_unlock(&mutexes[id]);
71301 - td->event = atomic_add_return(1, &rttest_event);
71302 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71303 td->mutexes[id] = 0;
71304 return 0;
71305
71306 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71307 break;
71308
71309 td->mutexes[dat] = 2;
71310 - td->event = atomic_add_return(1, &rttest_event);
71311 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71312 break;
71313
71314 default:
71315 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71316 return;
71317
71318 td->mutexes[dat] = 3;
71319 - td->event = atomic_add_return(1, &rttest_event);
71320 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71321 break;
71322
71323 case RTTEST_LOCKNOWAIT:
71324 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71325 return;
71326
71327 td->mutexes[dat] = 1;
71328 - td->event = atomic_add_return(1, &rttest_event);
71329 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71330 return;
71331
71332 default:
71333 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
71334 index 15f60d0..7e50319 100644
71335 --- a/kernel/sched/auto_group.c
71336 +++ b/kernel/sched/auto_group.c
71337 @@ -11,7 +11,7 @@
71338
71339 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
71340 static struct autogroup autogroup_default;
71341 -static atomic_t autogroup_seq_nr;
71342 +static atomic_unchecked_t autogroup_seq_nr;
71343
71344 void __init autogroup_init(struct task_struct *init_task)
71345 {
71346 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
71347
71348 kref_init(&ag->kref);
71349 init_rwsem(&ag->lock);
71350 - ag->id = atomic_inc_return(&autogroup_seq_nr);
71351 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
71352 ag->tg = tg;
71353 #ifdef CONFIG_RT_GROUP_SCHED
71354 /*
71355 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
71356 index 2d8927f..f617765 100644
71357 --- a/kernel/sched/core.c
71358 +++ b/kernel/sched/core.c
71359 @@ -3562,6 +3562,8 @@ int can_nice(const struct task_struct *p, const int nice)
71360 /* convert nice value [19,-20] to rlimit style value [1,40] */
71361 int nice_rlim = 20 - nice;
71362
71363 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
71364 +
71365 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
71366 capable(CAP_SYS_NICE));
71367 }
71368 @@ -3595,7 +3597,8 @@ SYSCALL_DEFINE1(nice, int, increment)
71369 if (nice > 19)
71370 nice = 19;
71371
71372 - if (increment < 0 && !can_nice(current, nice))
71373 + if (increment < 0 && (!can_nice(current, nice) ||
71374 + gr_handle_chroot_nice()))
71375 return -EPERM;
71376
71377 retval = security_task_setnice(current, nice);
71378 @@ -3749,6 +3752,7 @@ recheck:
71379 unsigned long rlim_rtprio =
71380 task_rlimit(p, RLIMIT_RTPRIO);
71381
71382 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
71383 /* can't set/change the rt policy */
71384 if (policy != p->policy && !rlim_rtprio)
71385 return -EPERM;
71386 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
71387 index 6b800a1..0c36227 100644
71388 --- a/kernel/sched/fair.c
71389 +++ b/kernel/sched/fair.c
71390 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
71391 * run_rebalance_domains is triggered when needed from the scheduler tick.
71392 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
71393 */
71394 -static void run_rebalance_domains(struct softirq_action *h)
71395 +static void run_rebalance_domains(void)
71396 {
71397 int this_cpu = smp_processor_id();
71398 struct rq *this_rq = cpu_rq(this_cpu);
71399 diff --git a/kernel/signal.c b/kernel/signal.c
71400 index e4d4014..76cf5dd 100644
71401 --- a/kernel/signal.c
71402 +++ b/kernel/signal.c
71403 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
71404
71405 int print_fatal_signals __read_mostly;
71406
71407 -static void __user *sig_handler(struct task_struct *t, int sig)
71408 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
71409 {
71410 return t->sighand->action[sig - 1].sa.sa_handler;
71411 }
71412
71413 -static int sig_handler_ignored(void __user *handler, int sig)
71414 +static int sig_handler_ignored(__sighandler_t handler, int sig)
71415 {
71416 /* Is it explicitly or implicitly ignored? */
71417 return handler == SIG_IGN ||
71418 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
71419
71420 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
71421 {
71422 - void __user *handler;
71423 + __sighandler_t handler;
71424
71425 handler = sig_handler(t, sig);
71426
71427 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
71428 atomic_inc(&user->sigpending);
71429 rcu_read_unlock();
71430
71431 + if (!override_rlimit)
71432 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
71433 +
71434 if (override_rlimit ||
71435 atomic_read(&user->sigpending) <=
71436 task_rlimit(t, RLIMIT_SIGPENDING)) {
71437 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
71438
71439 int unhandled_signal(struct task_struct *tsk, int sig)
71440 {
71441 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
71442 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
71443 if (is_global_init(tsk))
71444 return 1;
71445 if (handler != SIG_IGN && handler != SIG_DFL)
71446 @@ -817,6 +820,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
71447 }
71448 }
71449
71450 + /* allow glibc communication via tgkill to other threads in our
71451 + thread group */
71452 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
71453 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
71454 + && gr_handle_signal(t, sig))
71455 + return -EPERM;
71456 +
71457 return security_task_kill(t, info, sig, 0);
71458 }
71459
71460 @@ -1198,7 +1208,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
71461 return send_signal(sig, info, p, 1);
71462 }
71463
71464 -static int
71465 +int
71466 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71467 {
71468 return send_signal(sig, info, t, 0);
71469 @@ -1235,6 +1245,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71470 unsigned long int flags;
71471 int ret, blocked, ignored;
71472 struct k_sigaction *action;
71473 + int is_unhandled = 0;
71474
71475 spin_lock_irqsave(&t->sighand->siglock, flags);
71476 action = &t->sighand->action[sig-1];
71477 @@ -1249,9 +1260,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71478 }
71479 if (action->sa.sa_handler == SIG_DFL)
71480 t->signal->flags &= ~SIGNAL_UNKILLABLE;
71481 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
71482 + is_unhandled = 1;
71483 ret = specific_send_sig_info(sig, info, t);
71484 spin_unlock_irqrestore(&t->sighand->siglock, flags);
71485
71486 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
71487 + normal operation */
71488 + if (is_unhandled) {
71489 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
71490 + gr_handle_crash(t, sig);
71491 + }
71492 +
71493 return ret;
71494 }
71495
71496 @@ -1318,8 +1338,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
71497 ret = check_kill_permission(sig, info, p);
71498 rcu_read_unlock();
71499
71500 - if (!ret && sig)
71501 + if (!ret && sig) {
71502 ret = do_send_sig_info(sig, info, p, true);
71503 + if (!ret)
71504 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
71505 + }
71506
71507 return ret;
71508 }
71509 @@ -2864,7 +2887,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
71510 int error = -ESRCH;
71511
71512 rcu_read_lock();
71513 - p = find_task_by_vpid(pid);
71514 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71515 + /* allow glibc communication via tgkill to other threads in our
71516 + thread group */
71517 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
71518 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
71519 + p = find_task_by_vpid_unrestricted(pid);
71520 + else
71521 +#endif
71522 + p = find_task_by_vpid(pid);
71523 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
71524 error = check_kill_permission(sig, info, p);
71525 /*
71526 diff --git a/kernel/softirq.c b/kernel/softirq.c
71527 index cc96bdc..8bb9750 100644
71528 --- a/kernel/softirq.c
71529 +++ b/kernel/softirq.c
71530 @@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
71531
71532 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
71533
71534 -char *softirq_to_name[NR_SOFTIRQS] = {
71535 +const char * const softirq_to_name[NR_SOFTIRQS] = {
71536 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
71537 "TASKLET", "SCHED", "HRTIMER", "RCU"
71538 };
71539 @@ -244,7 +244,7 @@ restart:
71540 kstat_incr_softirqs_this_cpu(vec_nr);
71541
71542 trace_softirq_entry(vec_nr);
71543 - h->action(h);
71544 + h->action();
71545 trace_softirq_exit(vec_nr);
71546 if (unlikely(prev_count != preempt_count())) {
71547 printk(KERN_ERR "huh, entered softirq %u %s %p"
71548 @@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
71549 or_softirq_pending(1UL << nr);
71550 }
71551
71552 -void open_softirq(int nr, void (*action)(struct softirq_action *))
71553 +void open_softirq(int nr, void (*action)(void))
71554 {
71555 - softirq_vec[nr].action = action;
71556 + pax_open_kernel();
71557 + *(void **)&softirq_vec[nr].action = action;
71558 + pax_close_kernel();
71559 }
71560
71561 /*
71562 @@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
71563
71564 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
71565
71566 -static void tasklet_action(struct softirq_action *a)
71567 +static void tasklet_action(void)
71568 {
71569 struct tasklet_struct *list;
71570
71571 @@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
71572 }
71573 }
71574
71575 -static void tasklet_hi_action(struct softirq_action *a)
71576 +static void tasklet_hi_action(void)
71577 {
71578 struct tasklet_struct *list;
71579
71580 diff --git a/kernel/srcu.c b/kernel/srcu.c
71581 index 97c465e..d83f3bb 100644
71582 --- a/kernel/srcu.c
71583 +++ b/kernel/srcu.c
71584 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
71585 preempt_disable();
71586 idx = rcu_dereference_index_check(sp->completed,
71587 rcu_read_lock_sched_held()) & 0x1;
71588 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
71589 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
71590 smp_mb(); /* B */ /* Avoid leaking the critical section. */
71591 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
71592 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
71593 preempt_enable();
71594 return idx;
71595 }
71596 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
71597 {
71598 preempt_disable();
71599 smp_mb(); /* C */ /* Avoid leaking the critical section. */
71600 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
71601 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
71602 preempt_enable();
71603 }
71604 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
71605 diff --git a/kernel/sys.c b/kernel/sys.c
71606 index e6e0ece..1f2e413 100644
71607 --- a/kernel/sys.c
71608 +++ b/kernel/sys.c
71609 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
71610 error = -EACCES;
71611 goto out;
71612 }
71613 +
71614 + if (gr_handle_chroot_setpriority(p, niceval)) {
71615 + error = -EACCES;
71616 + goto out;
71617 + }
71618 +
71619 no_nice = security_task_setnice(p, niceval);
71620 if (no_nice) {
71621 error = no_nice;
71622 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
71623 goto error;
71624 }
71625
71626 + if (gr_check_group_change(new->gid, new->egid, -1))
71627 + goto error;
71628 +
71629 if (rgid != (gid_t) -1 ||
71630 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
71631 new->sgid = new->egid;
71632 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
71633 old = current_cred();
71634
71635 retval = -EPERM;
71636 +
71637 + if (gr_check_group_change(kgid, kgid, kgid))
71638 + goto error;
71639 +
71640 if (nsown_capable(CAP_SETGID))
71641 new->gid = new->egid = new->sgid = new->fsgid = kgid;
71642 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
71643 @@ -647,7 +660,7 @@ error:
71644 /*
71645 * change the user struct in a credentials set to match the new UID
71646 */
71647 -static int set_user(struct cred *new)
71648 +int set_user(struct cred *new)
71649 {
71650 struct user_struct *new_user;
71651
71652 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
71653 goto error;
71654 }
71655
71656 + if (gr_check_user_change(new->uid, new->euid, -1))
71657 + goto error;
71658 +
71659 if (!uid_eq(new->uid, old->uid)) {
71660 retval = set_user(new);
71661 if (retval < 0)
71662 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
71663 old = current_cred();
71664
71665 retval = -EPERM;
71666 +
71667 + if (gr_check_crash_uid(kuid))
71668 + goto error;
71669 + if (gr_check_user_change(kuid, kuid, kuid))
71670 + goto error;
71671 +
71672 if (nsown_capable(CAP_SETUID)) {
71673 new->suid = new->uid = kuid;
71674 if (!uid_eq(kuid, old->uid)) {
71675 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
71676 goto error;
71677 }
71678
71679 + if (gr_check_user_change(kruid, keuid, -1))
71680 + goto error;
71681 +
71682 if (ruid != (uid_t) -1) {
71683 new->uid = kruid;
71684 if (!uid_eq(kruid, old->uid)) {
71685 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
71686 goto error;
71687 }
71688
71689 + if (gr_check_group_change(krgid, kegid, -1))
71690 + goto error;
71691 +
71692 if (rgid != (gid_t) -1)
71693 new->gid = krgid;
71694 if (egid != (gid_t) -1)
71695 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
71696 if (!uid_valid(kuid))
71697 return old_fsuid;
71698
71699 + if (gr_check_user_change(-1, -1, kuid))
71700 + goto error;
71701 +
71702 new = prepare_creds();
71703 if (!new)
71704 return old_fsuid;
71705 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
71706 }
71707 }
71708
71709 +error:
71710 abort_creds(new);
71711 return old_fsuid;
71712
71713 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
71714 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
71715 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
71716 nsown_capable(CAP_SETGID)) {
71717 + if (gr_check_group_change(-1, -1, kgid))
71718 + goto error;
71719 +
71720 if (!gid_eq(kgid, old->fsgid)) {
71721 new->fsgid = kgid;
71722 goto change_okay;
71723 }
71724 }
71725
71726 +error:
71727 abort_creds(new);
71728 return old_fsgid;
71729
71730 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
71731 return -EFAULT;
71732
71733 down_read(&uts_sem);
71734 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
71735 + error = __copy_to_user(name->sysname, &utsname()->sysname,
71736 __OLD_UTS_LEN);
71737 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
71738 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
71739 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
71740 __OLD_UTS_LEN);
71741 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
71742 - error |= __copy_to_user(&name->release, &utsname()->release,
71743 + error |= __copy_to_user(name->release, &utsname()->release,
71744 __OLD_UTS_LEN);
71745 error |= __put_user(0, name->release + __OLD_UTS_LEN);
71746 - error |= __copy_to_user(&name->version, &utsname()->version,
71747 + error |= __copy_to_user(name->version, &utsname()->version,
71748 __OLD_UTS_LEN);
71749 error |= __put_user(0, name->version + __OLD_UTS_LEN);
71750 - error |= __copy_to_user(&name->machine, &utsname()->machine,
71751 + error |= __copy_to_user(name->machine, &utsname()->machine,
71752 __OLD_UTS_LEN);
71753 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
71754 up_read(&uts_sem);
71755 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
71756 error = get_dumpable(me->mm);
71757 break;
71758 case PR_SET_DUMPABLE:
71759 - if (arg2 < 0 || arg2 > 1) {
71760 + if (arg2 > 1) {
71761 error = -EINVAL;
71762 break;
71763 }
71764 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
71765 index 26f65ea..df8e5ad 100644
71766 --- a/kernel/sysctl.c
71767 +++ b/kernel/sysctl.c
71768 @@ -92,7 +92,6 @@
71769
71770
71771 #if defined(CONFIG_SYSCTL)
71772 -
71773 /* External variables not in a header file. */
71774 extern int sysctl_overcommit_memory;
71775 extern int sysctl_overcommit_ratio;
71776 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
71777 void __user *buffer, size_t *lenp, loff_t *ppos);
71778 #endif
71779
71780 -#ifdef CONFIG_PRINTK
71781 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71782 void __user *buffer, size_t *lenp, loff_t *ppos);
71783 -#endif
71784
71785 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
71786 void __user *buffer, size_t *lenp, loff_t *ppos);
71787 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
71788
71789 #endif
71790
71791 +extern struct ctl_table grsecurity_table[];
71792 +
71793 static struct ctl_table kern_table[];
71794 static struct ctl_table vm_table[];
71795 static struct ctl_table fs_table[];
71796 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
71797 int sysctl_legacy_va_layout;
71798 #endif
71799
71800 +#ifdef CONFIG_PAX_SOFTMODE
71801 +static ctl_table pax_table[] = {
71802 + {
71803 + .procname = "softmode",
71804 + .data = &pax_softmode,
71805 + .maxlen = sizeof(unsigned int),
71806 + .mode = 0600,
71807 + .proc_handler = &proc_dointvec,
71808 + },
71809 +
71810 + { }
71811 +};
71812 +#endif
71813 +
71814 /* The default sysctl tables: */
71815
71816 static struct ctl_table sysctl_base_table[] = {
71817 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
71818 #endif
71819
71820 static struct ctl_table kern_table[] = {
71821 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
71822 + {
71823 + .procname = "grsecurity",
71824 + .mode = 0500,
71825 + .child = grsecurity_table,
71826 + },
71827 +#endif
71828 +
71829 +#ifdef CONFIG_PAX_SOFTMODE
71830 + {
71831 + .procname = "pax",
71832 + .mode = 0500,
71833 + .child = pax_table,
71834 + },
71835 +#endif
71836 +
71837 {
71838 .procname = "sched_child_runs_first",
71839 .data = &sysctl_sched_child_runs_first,
71840 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
71841 .data = &modprobe_path,
71842 .maxlen = KMOD_PATH_LEN,
71843 .mode = 0644,
71844 - .proc_handler = proc_dostring,
71845 + .proc_handler = proc_dostring_modpriv,
71846 },
71847 {
71848 .procname = "modules_disabled",
71849 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
71850 .extra1 = &zero,
71851 .extra2 = &one,
71852 },
71853 +#endif
71854 {
71855 .procname = "kptr_restrict",
71856 .data = &kptr_restrict,
71857 .maxlen = sizeof(int),
71858 .mode = 0644,
71859 .proc_handler = proc_dointvec_minmax_sysadmin,
71860 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71861 + .extra1 = &two,
71862 +#else
71863 .extra1 = &zero,
71864 +#endif
71865 .extra2 = &two,
71866 },
71867 -#endif
71868 {
71869 .procname = "ngroups_max",
71870 .data = &ngroups_max,
71871 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
71872 .proc_handler = proc_dointvec_minmax,
71873 .extra1 = &zero,
71874 },
71875 + {
71876 + .procname = "heap_stack_gap",
71877 + .data = &sysctl_heap_stack_gap,
71878 + .maxlen = sizeof(sysctl_heap_stack_gap),
71879 + .mode = 0644,
71880 + .proc_handler = proc_doulongvec_minmax,
71881 + },
71882 #else
71883 {
71884 .procname = "nr_trim_pages",
71885 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
71886 buffer, lenp, ppos);
71887 }
71888
71889 +int proc_dostring_modpriv(struct ctl_table *table, int write,
71890 + void __user *buffer, size_t *lenp, loff_t *ppos)
71891 +{
71892 + if (write && !capable(CAP_SYS_MODULE))
71893 + return -EPERM;
71894 +
71895 + return _proc_do_string(table->data, table->maxlen, write,
71896 + buffer, lenp, ppos);
71897 +}
71898 +
71899 static size_t proc_skip_spaces(char **buf)
71900 {
71901 size_t ret;
71902 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
71903 len = strlen(tmp);
71904 if (len > *size)
71905 len = *size;
71906 + if (len > sizeof(tmp))
71907 + len = sizeof(tmp);
71908 if (copy_to_user(*buf, tmp, len))
71909 return -EFAULT;
71910 *size -= len;
71911 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
71912 return err;
71913 }
71914
71915 -#ifdef CONFIG_PRINTK
71916 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71917 void __user *buffer, size_t *lenp, loff_t *ppos)
71918 {
71919 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71920
71921 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
71922 }
71923 -#endif
71924
71925 struct do_proc_dointvec_minmax_conv_param {
71926 int *min;
71927 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
71928 *i = val;
71929 } else {
71930 val = convdiv * (*i) / convmul;
71931 - if (!first)
71932 + if (!first) {
71933 err = proc_put_char(&buffer, &left, '\t');
71934 + if (err)
71935 + break;
71936 + }
71937 err = proc_put_long(&buffer, &left, val, false);
71938 if (err)
71939 break;
71940 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
71941 return -ENOSYS;
71942 }
71943
71944 +int proc_dostring_modpriv(struct ctl_table *table, int write,
71945 + void __user *buffer, size_t *lenp, loff_t *ppos)
71946 +{
71947 + return -ENOSYS;
71948 +}
71949 +
71950 int proc_dointvec(struct ctl_table *table, int write,
71951 void __user *buffer, size_t *lenp, loff_t *ppos)
71952 {
71953 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
71954 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
71955 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
71956 EXPORT_SYMBOL(proc_dostring);
71957 +EXPORT_SYMBOL(proc_dostring_modpriv);
71958 EXPORT_SYMBOL(proc_doulongvec_minmax);
71959 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
71960 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
71961 index 65bdcf1..21eb831 100644
71962 --- a/kernel/sysctl_binary.c
71963 +++ b/kernel/sysctl_binary.c
71964 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
71965 int i;
71966
71967 set_fs(KERNEL_DS);
71968 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71969 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71970 set_fs(old_fs);
71971 if (result < 0)
71972 goto out_kfree;
71973 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
71974 }
71975
71976 set_fs(KERNEL_DS);
71977 - result = vfs_write(file, buffer, str - buffer, &pos);
71978 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71979 set_fs(old_fs);
71980 if (result < 0)
71981 goto out_kfree;
71982 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
71983 int i;
71984
71985 set_fs(KERNEL_DS);
71986 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71987 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71988 set_fs(old_fs);
71989 if (result < 0)
71990 goto out_kfree;
71991 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
71992 }
71993
71994 set_fs(KERNEL_DS);
71995 - result = vfs_write(file, buffer, str - buffer, &pos);
71996 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71997 set_fs(old_fs);
71998 if (result < 0)
71999 goto out_kfree;
72000 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72001 int i;
72002
72003 set_fs(KERNEL_DS);
72004 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72005 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72006 set_fs(old_fs);
72007 if (result < 0)
72008 goto out;
72009 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72010 __le16 dnaddr;
72011
72012 set_fs(KERNEL_DS);
72013 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72014 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72015 set_fs(old_fs);
72016 if (result < 0)
72017 goto out;
72018 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72019 le16_to_cpu(dnaddr) & 0x3ff);
72020
72021 set_fs(KERNEL_DS);
72022 - result = vfs_write(file, buf, len, &pos);
72023 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72024 set_fs(old_fs);
72025 if (result < 0)
72026 goto out;
72027 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72028 index 145bb4d..b2aa969 100644
72029 --- a/kernel/taskstats.c
72030 +++ b/kernel/taskstats.c
72031 @@ -28,9 +28,12 @@
72032 #include <linux/fs.h>
72033 #include <linux/file.h>
72034 #include <linux/pid_namespace.h>
72035 +#include <linux/grsecurity.h>
72036 #include <net/genetlink.h>
72037 #include <linux/atomic.h>
72038
72039 +extern int gr_is_taskstats_denied(int pid);
72040 +
72041 /*
72042 * Maximum length of a cpumask that can be specified in
72043 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72044 @@ -570,6 +573,9 @@ err:
72045
72046 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72047 {
72048 + if (gr_is_taskstats_denied(current->pid))
72049 + return -EACCES;
72050 +
72051 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72052 return cmd_attr_register_cpumask(info);
72053 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72054 diff --git a/kernel/time.c b/kernel/time.c
72055 index d226c6a..c7c0960 100644
72056 --- a/kernel/time.c
72057 +++ b/kernel/time.c
72058 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72059 return error;
72060
72061 if (tz) {
72062 + /* we log in do_settimeofday called below, so don't log twice
72063 + */
72064 + if (!tv)
72065 + gr_log_timechange();
72066 +
72067 sys_tz = *tz;
72068 update_vsyscall_tz();
72069 if (firsttime) {
72070 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72071 index f11d83b..d016d91 100644
72072 --- a/kernel/time/alarmtimer.c
72073 +++ b/kernel/time/alarmtimer.c
72074 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72075 struct platform_device *pdev;
72076 int error = 0;
72077 int i;
72078 - struct k_clock alarm_clock = {
72079 + static struct k_clock alarm_clock = {
72080 .clock_getres = alarm_clock_getres,
72081 .clock_get = alarm_clock_get,
72082 .timer_create = alarm_timer_create,
72083 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72084 index f113755..ec24223 100644
72085 --- a/kernel/time/tick-broadcast.c
72086 +++ b/kernel/time/tick-broadcast.c
72087 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72088 * then clear the broadcast bit.
72089 */
72090 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72091 - int cpu = smp_processor_id();
72092 + cpu = smp_processor_id();
72093
72094 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72095 tick_broadcast_clear_oneshot(cpu);
72096 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72097 index e424970..4c7962b 100644
72098 --- a/kernel/time/timekeeping.c
72099 +++ b/kernel/time/timekeeping.c
72100 @@ -15,6 +15,7 @@
72101 #include <linux/init.h>
72102 #include <linux/mm.h>
72103 #include <linux/sched.h>
72104 +#include <linux/grsecurity.h>
72105 #include <linux/syscore_ops.h>
72106 #include <linux/clocksource.h>
72107 #include <linux/jiffies.h>
72108 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72109 if (!timespec_valid_strict(tv))
72110 return -EINVAL;
72111
72112 + gr_log_timechange();
72113 +
72114 write_seqlock_irqsave(&tk->lock, flags);
72115
72116 timekeeping_forward_now(tk);
72117 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72118 index af5a7e9..715611a 100644
72119 --- a/kernel/time/timer_list.c
72120 +++ b/kernel/time/timer_list.c
72121 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72122
72123 static void print_name_offset(struct seq_file *m, void *sym)
72124 {
72125 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72126 + SEQ_printf(m, "<%p>", NULL);
72127 +#else
72128 char symname[KSYM_NAME_LEN];
72129
72130 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72131 SEQ_printf(m, "<%pK>", sym);
72132 else
72133 SEQ_printf(m, "%s", symname);
72134 +#endif
72135 }
72136
72137 static void
72138 @@ -112,7 +116,11 @@ next_one:
72139 static void
72140 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72141 {
72142 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72143 + SEQ_printf(m, " .base: %p\n", NULL);
72144 +#else
72145 SEQ_printf(m, " .base: %pK\n", base);
72146 +#endif
72147 SEQ_printf(m, " .index: %d\n",
72148 base->index);
72149 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72150 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72151 {
72152 struct proc_dir_entry *pe;
72153
72154 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72155 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72156 +#else
72157 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72158 +#endif
72159 if (!pe)
72160 return -ENOMEM;
72161 return 0;
72162 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72163 index 0b537f2..40d6c20 100644
72164 --- a/kernel/time/timer_stats.c
72165 +++ b/kernel/time/timer_stats.c
72166 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72167 static unsigned long nr_entries;
72168 static struct entry entries[MAX_ENTRIES];
72169
72170 -static atomic_t overflow_count;
72171 +static atomic_unchecked_t overflow_count;
72172
72173 /*
72174 * The entries are in a hash-table, for fast lookup:
72175 @@ -140,7 +140,7 @@ static void reset_entries(void)
72176 nr_entries = 0;
72177 memset(entries, 0, sizeof(entries));
72178 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72179 - atomic_set(&overflow_count, 0);
72180 + atomic_set_unchecked(&overflow_count, 0);
72181 }
72182
72183 static struct entry *alloc_entry(void)
72184 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72185 if (likely(entry))
72186 entry->count++;
72187 else
72188 - atomic_inc(&overflow_count);
72189 + atomic_inc_unchecked(&overflow_count);
72190
72191 out_unlock:
72192 raw_spin_unlock_irqrestore(lock, flags);
72193 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72194
72195 static void print_name_offset(struct seq_file *m, unsigned long addr)
72196 {
72197 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72198 + seq_printf(m, "<%p>", NULL);
72199 +#else
72200 char symname[KSYM_NAME_LEN];
72201
72202 if (lookup_symbol_name(addr, symname) < 0)
72203 - seq_printf(m, "<%p>", (void *)addr);
72204 + seq_printf(m, "<%pK>", (void *)addr);
72205 else
72206 seq_printf(m, "%s", symname);
72207 +#endif
72208 }
72209
72210 static int tstats_show(struct seq_file *m, void *v)
72211 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
72212
72213 seq_puts(m, "Timer Stats Version: v0.2\n");
72214 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
72215 - if (atomic_read(&overflow_count))
72216 + if (atomic_read_unchecked(&overflow_count))
72217 seq_printf(m, "Overflow: %d entries\n",
72218 - atomic_read(&overflow_count));
72219 + atomic_read_unchecked(&overflow_count));
72220
72221 for (i = 0; i < nr_entries; i++) {
72222 entry = entries + i;
72223 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
72224 {
72225 struct proc_dir_entry *pe;
72226
72227 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72228 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
72229 +#else
72230 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
72231 +#endif
72232 if (!pe)
72233 return -ENOMEM;
72234 return 0;
72235 diff --git a/kernel/timer.c b/kernel/timer.c
72236 index 367d008..46857a0 100644
72237 --- a/kernel/timer.c
72238 +++ b/kernel/timer.c
72239 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
72240 /*
72241 * This function runs timers and the timer-tq in bottom half context.
72242 */
72243 -static void run_timer_softirq(struct softirq_action *h)
72244 +static void run_timer_softirq(void)
72245 {
72246 struct tvec_base *base = __this_cpu_read(tvec_bases);
72247
72248 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
72249 return NOTIFY_OK;
72250 }
72251
72252 -static struct notifier_block __cpuinitdata timers_nb = {
72253 +static struct notifier_block __cpuinitconst timers_nb = {
72254 .notifier_call = timer_cpu_notify,
72255 };
72256
72257 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
72258 index c0bd030..62a1927 100644
72259 --- a/kernel/trace/blktrace.c
72260 +++ b/kernel/trace/blktrace.c
72261 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
72262 struct blk_trace *bt = filp->private_data;
72263 char buf[16];
72264
72265 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
72266 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
72267
72268 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
72269 }
72270 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
72271 return 1;
72272
72273 bt = buf->chan->private_data;
72274 - atomic_inc(&bt->dropped);
72275 + atomic_inc_unchecked(&bt->dropped);
72276 return 0;
72277 }
72278
72279 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
72280
72281 bt->dir = dir;
72282 bt->dev = dev;
72283 - atomic_set(&bt->dropped, 0);
72284 + atomic_set_unchecked(&bt->dropped, 0);
72285
72286 ret = -EIO;
72287 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
72288 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
72289 index 51b7159..18137d6 100644
72290 --- a/kernel/trace/ftrace.c
72291 +++ b/kernel/trace/ftrace.c
72292 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
72293 if (unlikely(ftrace_disabled))
72294 return 0;
72295
72296 + ret = ftrace_arch_code_modify_prepare();
72297 + FTRACE_WARN_ON(ret);
72298 + if (ret)
72299 + return 0;
72300 +
72301 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
72302 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
72303 if (ret) {
72304 ftrace_bug(ret, ip);
72305 - return 0;
72306 }
72307 - return 1;
72308 + return ret ? 0 : 1;
72309 }
72310
72311 /*
72312 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
72313
72314 int
72315 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
72316 - void *data)
72317 + void *data)
72318 {
72319 struct ftrace_func_probe *entry;
72320 struct ftrace_page *pg;
72321 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
72322 if (!count)
72323 return 0;
72324
72325 + pax_open_kernel();
72326 sort(start, count, sizeof(*start),
72327 ftrace_cmp_ips, ftrace_swap_ips);
72328 + pax_close_kernel();
72329
72330 start_pg = ftrace_allocate_pages(count);
72331 if (!start_pg)
72332 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
72333 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
72334
72335 static int ftrace_graph_active;
72336 -static struct notifier_block ftrace_suspend_notifier;
72337 -
72338 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
72339 {
72340 return 0;
72341 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
72342 return NOTIFY_DONE;
72343 }
72344
72345 +static struct notifier_block ftrace_suspend_notifier = {
72346 + .notifier_call = ftrace_suspend_notifier_call
72347 +};
72348 +
72349 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72350 trace_func_graph_ent_t entryfunc)
72351 {
72352 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72353 goto out;
72354 }
72355
72356 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
72357 register_pm_notifier(&ftrace_suspend_notifier);
72358
72359 ftrace_graph_active++;
72360 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
72361 index 4cb5e51..e7e05d9 100644
72362 --- a/kernel/trace/ring_buffer.c
72363 +++ b/kernel/trace/ring_buffer.c
72364 @@ -346,9 +346,9 @@ struct buffer_data_page {
72365 */
72366 struct buffer_page {
72367 struct list_head list; /* list of buffer pages */
72368 - local_t write; /* index for next write */
72369 + local_unchecked_t write; /* index for next write */
72370 unsigned read; /* index for next read */
72371 - local_t entries; /* entries on this page */
72372 + local_unchecked_t entries; /* entries on this page */
72373 unsigned long real_end; /* real end of data */
72374 struct buffer_data_page *page; /* Actual data page */
72375 };
72376 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
72377 unsigned long lost_events;
72378 unsigned long last_overrun;
72379 local_t entries_bytes;
72380 - local_t commit_overrun;
72381 - local_t overrun;
72382 + local_unchecked_t commit_overrun;
72383 + local_unchecked_t overrun;
72384 local_t entries;
72385 local_t committing;
72386 local_t commits;
72387 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
72388 *
72389 * We add a counter to the write field to denote this.
72390 */
72391 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
72392 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
72393 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
72394 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
72395
72396 /*
72397 * Just make sure we have seen our old_write and synchronize
72398 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
72399 * cmpxchg to only update if an interrupt did not already
72400 * do it for us. If the cmpxchg fails, we don't care.
72401 */
72402 - (void)local_cmpxchg(&next_page->write, old_write, val);
72403 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
72404 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
72405 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
72406
72407 /*
72408 * No need to worry about races with clearing out the commit.
72409 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
72410
72411 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
72412 {
72413 - return local_read(&bpage->entries) & RB_WRITE_MASK;
72414 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
72415 }
72416
72417 static inline unsigned long rb_page_write(struct buffer_page *bpage)
72418 {
72419 - return local_read(&bpage->write) & RB_WRITE_MASK;
72420 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
72421 }
72422
72423 static int
72424 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
72425 * bytes consumed in ring buffer from here.
72426 * Increment overrun to account for the lost events.
72427 */
72428 - local_add(page_entries, &cpu_buffer->overrun);
72429 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
72430 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
72431 }
72432
72433 @@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
72434 * it is our responsibility to update
72435 * the counters.
72436 */
72437 - local_add(entries, &cpu_buffer->overrun);
72438 + local_add_unchecked(entries, &cpu_buffer->overrun);
72439 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
72440
72441 /*
72442 @@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72443 if (tail == BUF_PAGE_SIZE)
72444 tail_page->real_end = 0;
72445
72446 - local_sub(length, &tail_page->write);
72447 + local_sub_unchecked(length, &tail_page->write);
72448 return;
72449 }
72450
72451 @@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72452 rb_event_set_padding(event);
72453
72454 /* Set the write back to the previous setting */
72455 - local_sub(length, &tail_page->write);
72456 + local_sub_unchecked(length, &tail_page->write);
72457 return;
72458 }
72459
72460 @@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72461
72462 /* Set write to end of buffer */
72463 length = (tail + length) - BUF_PAGE_SIZE;
72464 - local_sub(length, &tail_page->write);
72465 + local_sub_unchecked(length, &tail_page->write);
72466 }
72467
72468 /*
72469 @@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
72470 * about it.
72471 */
72472 if (unlikely(next_page == commit_page)) {
72473 - local_inc(&cpu_buffer->commit_overrun);
72474 + local_inc_unchecked(&cpu_buffer->commit_overrun);
72475 goto out_reset;
72476 }
72477
72478 @@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
72479 cpu_buffer->tail_page) &&
72480 (cpu_buffer->commit_page ==
72481 cpu_buffer->reader_page))) {
72482 - local_inc(&cpu_buffer->commit_overrun);
72483 + local_inc_unchecked(&cpu_buffer->commit_overrun);
72484 goto out_reset;
72485 }
72486 }
72487 @@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
72488 length += RB_LEN_TIME_EXTEND;
72489
72490 tail_page = cpu_buffer->tail_page;
72491 - write = local_add_return(length, &tail_page->write);
72492 + write = local_add_return_unchecked(length, &tail_page->write);
72493
72494 /* set write to only the index of the write */
72495 write &= RB_WRITE_MASK;
72496 @@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
72497 kmemcheck_annotate_bitfield(event, bitfield);
72498 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
72499
72500 - local_inc(&tail_page->entries);
72501 + local_inc_unchecked(&tail_page->entries);
72502
72503 /*
72504 * If this is the first commit on the page, then update
72505 @@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
72506
72507 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
72508 unsigned long write_mask =
72509 - local_read(&bpage->write) & ~RB_WRITE_MASK;
72510 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
72511 unsigned long event_length = rb_event_length(event);
72512 /*
72513 * This is on the tail page. It is possible that
72514 @@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
72515 */
72516 old_index += write_mask;
72517 new_index += write_mask;
72518 - index = local_cmpxchg(&bpage->write, old_index, new_index);
72519 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
72520 if (index == old_index) {
72521 /* update counters */
72522 local_sub(event_length, &cpu_buffer->entries_bytes);
72523 @@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
72524
72525 /* Do the likely case first */
72526 if (likely(bpage->page == (void *)addr)) {
72527 - local_dec(&bpage->entries);
72528 + local_dec_unchecked(&bpage->entries);
72529 return;
72530 }
72531
72532 @@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
72533 start = bpage;
72534 do {
72535 if (bpage->page == (void *)addr) {
72536 - local_dec(&bpage->entries);
72537 + local_dec_unchecked(&bpage->entries);
72538 return;
72539 }
72540 rb_inc_page(cpu_buffer, &bpage);
72541 @@ -2923,7 +2923,7 @@ static inline unsigned long
72542 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
72543 {
72544 return local_read(&cpu_buffer->entries) -
72545 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
72546 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
72547 }
72548
72549 /**
72550 @@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
72551 return 0;
72552
72553 cpu_buffer = buffer->buffers[cpu];
72554 - ret = local_read(&cpu_buffer->overrun);
72555 + ret = local_read_unchecked(&cpu_buffer->overrun);
72556
72557 return ret;
72558 }
72559 @@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
72560 return 0;
72561
72562 cpu_buffer = buffer->buffers[cpu];
72563 - ret = local_read(&cpu_buffer->commit_overrun);
72564 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
72565
72566 return ret;
72567 }
72568 @@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
72569 /* if you care about this being correct, lock the buffer */
72570 for_each_buffer_cpu(buffer, cpu) {
72571 cpu_buffer = buffer->buffers[cpu];
72572 - overruns += local_read(&cpu_buffer->overrun);
72573 + overruns += local_read_unchecked(&cpu_buffer->overrun);
72574 }
72575
72576 return overruns;
72577 @@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
72578 /*
72579 * Reset the reader page to size zero.
72580 */
72581 - local_set(&cpu_buffer->reader_page->write, 0);
72582 - local_set(&cpu_buffer->reader_page->entries, 0);
72583 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
72584 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
72585 local_set(&cpu_buffer->reader_page->page->commit, 0);
72586 cpu_buffer->reader_page->real_end = 0;
72587
72588 @@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
72589 * want to compare with the last_overrun.
72590 */
72591 smp_mb();
72592 - overwrite = local_read(&(cpu_buffer->overrun));
72593 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
72594
72595 /*
72596 * Here's the tricky part.
72597 @@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
72598
72599 cpu_buffer->head_page
72600 = list_entry(cpu_buffer->pages, struct buffer_page, list);
72601 - local_set(&cpu_buffer->head_page->write, 0);
72602 - local_set(&cpu_buffer->head_page->entries, 0);
72603 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
72604 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
72605 local_set(&cpu_buffer->head_page->page->commit, 0);
72606
72607 cpu_buffer->head_page->read = 0;
72608 @@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
72609
72610 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
72611 INIT_LIST_HEAD(&cpu_buffer->new_pages);
72612 - local_set(&cpu_buffer->reader_page->write, 0);
72613 - local_set(&cpu_buffer->reader_page->entries, 0);
72614 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
72615 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
72616 local_set(&cpu_buffer->reader_page->page->commit, 0);
72617 cpu_buffer->reader_page->read = 0;
72618
72619 - local_set(&cpu_buffer->commit_overrun, 0);
72620 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
72621 local_set(&cpu_buffer->entries_bytes, 0);
72622 - local_set(&cpu_buffer->overrun, 0);
72623 + local_set_unchecked(&cpu_buffer->overrun, 0);
72624 local_set(&cpu_buffer->entries, 0);
72625 local_set(&cpu_buffer->committing, 0);
72626 local_set(&cpu_buffer->commits, 0);
72627 @@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
72628 rb_init_page(bpage);
72629 bpage = reader->page;
72630 reader->page = *data_page;
72631 - local_set(&reader->write, 0);
72632 - local_set(&reader->entries, 0);
72633 + local_set_unchecked(&reader->write, 0);
72634 + local_set_unchecked(&reader->entries, 0);
72635 reader->read = 0;
72636 *data_page = bpage;
72637
72638 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
72639 index 31e4f55..62da00f 100644
72640 --- a/kernel/trace/trace.c
72641 +++ b/kernel/trace/trace.c
72642 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
72643 };
72644 #endif
72645
72646 -static struct dentry *d_tracer;
72647 -
72648 struct dentry *tracing_init_dentry(void)
72649 {
72650 + static struct dentry *d_tracer;
72651 static int once;
72652
72653 if (d_tracer)
72654 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
72655 return d_tracer;
72656 }
72657
72658 -static struct dentry *d_percpu;
72659 -
72660 struct dentry *tracing_dentry_percpu(void)
72661 {
72662 + static struct dentry *d_percpu;
72663 static int once;
72664 struct dentry *d_tracer;
72665
72666 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
72667 index d608d09..7eddcb1 100644
72668 --- a/kernel/trace/trace_events.c
72669 +++ b/kernel/trace/trace_events.c
72670 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
72671 struct ftrace_module_file_ops {
72672 struct list_head list;
72673 struct module *mod;
72674 - struct file_operations id;
72675 - struct file_operations enable;
72676 - struct file_operations format;
72677 - struct file_operations filter;
72678 };
72679
72680 static struct ftrace_module_file_ops *
72681 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
72682
72683 file_ops->mod = mod;
72684
72685 - file_ops->id = ftrace_event_id_fops;
72686 - file_ops->id.owner = mod;
72687 -
72688 - file_ops->enable = ftrace_enable_fops;
72689 - file_ops->enable.owner = mod;
72690 -
72691 - file_ops->filter = ftrace_event_filter_fops;
72692 - file_ops->filter.owner = mod;
72693 -
72694 - file_ops->format = ftrace_event_format_fops;
72695 - file_ops->format.owner = mod;
72696 + pax_open_kernel();
72697 + *(void **)&mod->trace_id.owner = mod;
72698 + *(void **)&mod->trace_enable.owner = mod;
72699 + *(void **)&mod->trace_filter.owner = mod;
72700 + *(void **)&mod->trace_format.owner = mod;
72701 + pax_close_kernel();
72702
72703 list_add(&file_ops->list, &ftrace_module_file_list);
72704
72705 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
72706
72707 for_each_event(call, start, end) {
72708 __trace_add_event_call(*call, mod,
72709 - &file_ops->id, &file_ops->enable,
72710 - &file_ops->filter, &file_ops->format);
72711 + &mod->trace_id, &mod->trace_enable,
72712 + &mod->trace_filter, &mod->trace_format);
72713 }
72714 }
72715
72716 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
72717 index fd3c8aa..5f324a6 100644
72718 --- a/kernel/trace/trace_mmiotrace.c
72719 +++ b/kernel/trace/trace_mmiotrace.c
72720 @@ -24,7 +24,7 @@ struct header_iter {
72721 static struct trace_array *mmio_trace_array;
72722 static bool overrun_detected;
72723 static unsigned long prev_overruns;
72724 -static atomic_t dropped_count;
72725 +static atomic_unchecked_t dropped_count;
72726
72727 static void mmio_reset_data(struct trace_array *tr)
72728 {
72729 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
72730
72731 static unsigned long count_overruns(struct trace_iterator *iter)
72732 {
72733 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
72734 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
72735 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
72736
72737 if (over > prev_overruns)
72738 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
72739 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
72740 sizeof(*entry), 0, pc);
72741 if (!event) {
72742 - atomic_inc(&dropped_count);
72743 + atomic_inc_unchecked(&dropped_count);
72744 return;
72745 }
72746 entry = ring_buffer_event_data(event);
72747 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
72748 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
72749 sizeof(*entry), 0, pc);
72750 if (!event) {
72751 - atomic_inc(&dropped_count);
72752 + atomic_inc_unchecked(&dropped_count);
72753 return;
72754 }
72755 entry = ring_buffer_event_data(event);
72756 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
72757 index 123b189..4383774 100644
72758 --- a/kernel/trace/trace_output.c
72759 +++ b/kernel/trace/trace_output.c
72760 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
72761
72762 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
72763 if (!IS_ERR(p)) {
72764 - p = mangle_path(s->buffer + s->len, p, "\n");
72765 + p = mangle_path(s->buffer + s->len, p, "\n\\");
72766 if (p) {
72767 s->len = p - s->buffer;
72768 return 1;
72769 @@ -825,13 +825,13 @@ int register_ftrace_event(struct trace_event *event)
72770 }
72771
72772 if (event->funcs->trace == NULL)
72773 - event->funcs->trace = trace_nop_print;
72774 + *(void **)&event->funcs->trace = trace_nop_print;
72775 if (event->funcs->raw == NULL)
72776 - event->funcs->raw = trace_nop_print;
72777 + *(void **)&event->funcs->raw = trace_nop_print;
72778 if (event->funcs->hex == NULL)
72779 - event->funcs->hex = trace_nop_print;
72780 + *(void **)&event->funcs->hex = trace_nop_print;
72781 if (event->funcs->binary == NULL)
72782 - event->funcs->binary = trace_nop_print;
72783 + *(void **)&event->funcs->binary = trace_nop_print;
72784
72785 key = event->type & (EVENT_HASHSIZE - 1);
72786
72787 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
72788 index 0c1b1657..95337e9 100644
72789 --- a/kernel/trace/trace_stack.c
72790 +++ b/kernel/trace/trace_stack.c
72791 @@ -53,7 +53,7 @@ static inline void check_stack(void)
72792 return;
72793
72794 /* we do not handle interrupt stacks yet */
72795 - if (!object_is_on_stack(&this_size))
72796 + if (!object_starts_on_stack(&this_size))
72797 return;
72798
72799 local_irq_save(flags);
72800 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
72801 index 28e9d6c9..50381bd 100644
72802 --- a/lib/Kconfig.debug
72803 +++ b/lib/Kconfig.debug
72804 @@ -1278,6 +1278,7 @@ config LATENCYTOP
72805 depends on DEBUG_KERNEL
72806 depends on STACKTRACE_SUPPORT
72807 depends on PROC_FS
72808 + depends on !GRKERNSEC_HIDESYM
72809 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
72810 select KALLSYMS
72811 select KALLSYMS_ALL
72812 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
72813
72814 config PROVIDE_OHCI1394_DMA_INIT
72815 bool "Remote debugging over FireWire early on boot"
72816 - depends on PCI && X86
72817 + depends on PCI && X86 && !GRKERNSEC
72818 help
72819 If you want to debug problems which hang or crash the kernel early
72820 on boot and the crashing machine has a FireWire port, you can use
72821 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
72822
72823 config FIREWIRE_OHCI_REMOTE_DMA
72824 bool "Remote debugging over FireWire with firewire-ohci"
72825 - depends on FIREWIRE_OHCI
72826 + depends on FIREWIRE_OHCI && !GRKERNSEC
72827 help
72828 This option lets you use the FireWire bus for remote debugging
72829 with help of the firewire-ohci driver. It enables unfiltered
72830 diff --git a/lib/Makefile b/lib/Makefile
72831 index a08b791..a3ff1eb 100644
72832 --- a/lib/Makefile
72833 +++ b/lib/Makefile
72834 @@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
72835
72836 obj-$(CONFIG_BTREE) += btree.o
72837 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
72838 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
72839 +obj-y += list_debug.o
72840 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
72841
72842 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
72843 diff --git a/lib/bitmap.c b/lib/bitmap.c
72844 index 06fdfa1..97c5c7d 100644
72845 --- a/lib/bitmap.c
72846 +++ b/lib/bitmap.c
72847 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
72848 {
72849 int c, old_c, totaldigits, ndigits, nchunks, nbits;
72850 u32 chunk;
72851 - const char __user __force *ubuf = (const char __user __force *)buf;
72852 + const char __user *ubuf = (const char __force_user *)buf;
72853
72854 bitmap_zero(maskp, nmaskbits);
72855
72856 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
72857 {
72858 if (!access_ok(VERIFY_READ, ubuf, ulen))
72859 return -EFAULT;
72860 - return __bitmap_parse((const char __force *)ubuf,
72861 + return __bitmap_parse((const char __force_kernel *)ubuf,
72862 ulen, 1, maskp, nmaskbits);
72863
72864 }
72865 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
72866 {
72867 unsigned a, b;
72868 int c, old_c, totaldigits;
72869 - const char __user __force *ubuf = (const char __user __force *)buf;
72870 + const char __user *ubuf = (const char __force_user *)buf;
72871 int exp_digit, in_range;
72872
72873 totaldigits = c = 0;
72874 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
72875 {
72876 if (!access_ok(VERIFY_READ, ubuf, ulen))
72877 return -EFAULT;
72878 - return __bitmap_parselist((const char __force *)ubuf,
72879 + return __bitmap_parselist((const char __force_kernel *)ubuf,
72880 ulen, 1, maskp, nmaskbits);
72881 }
72882 EXPORT_SYMBOL(bitmap_parselist_user);
72883 diff --git a/lib/bug.c b/lib/bug.c
72884 index a28c141..2bd3d95 100644
72885 --- a/lib/bug.c
72886 +++ b/lib/bug.c
72887 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
72888 return BUG_TRAP_TYPE_NONE;
72889
72890 bug = find_bug(bugaddr);
72891 + if (!bug)
72892 + return BUG_TRAP_TYPE_NONE;
72893
72894 file = NULL;
72895 line = 0;
72896 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
72897 index d11808c..dc2d6f8 100644
72898 --- a/lib/debugobjects.c
72899 +++ b/lib/debugobjects.c
72900 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
72901 if (limit > 4)
72902 return;
72903
72904 - is_on_stack = object_is_on_stack(addr);
72905 + is_on_stack = object_starts_on_stack(addr);
72906 if (is_on_stack == onstack)
72907 return;
72908
72909 diff --git a/lib/devres.c b/lib/devres.c
72910 index 80b9c76..9e32279 100644
72911 --- a/lib/devres.c
72912 +++ b/lib/devres.c
72913 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
72914 void devm_iounmap(struct device *dev, void __iomem *addr)
72915 {
72916 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
72917 - (void *)addr));
72918 + (void __force *)addr));
72919 iounmap(addr);
72920 }
72921 EXPORT_SYMBOL(devm_iounmap);
72922 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
72923 {
72924 ioport_unmap(addr);
72925 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
72926 - devm_ioport_map_match, (void *)addr));
72927 + devm_ioport_map_match, (void __force *)addr));
72928 }
72929 EXPORT_SYMBOL(devm_ioport_unmap);
72930
72931 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
72932 index d84beb9..da44791 100644
72933 --- a/lib/dma-debug.c
72934 +++ b/lib/dma-debug.c
72935 @@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
72936
72937 void dma_debug_add_bus(struct bus_type *bus)
72938 {
72939 - struct notifier_block *nb;
72940 + notifier_block_no_const *nb;
72941
72942 if (global_disable)
72943 return;
72944 @@ -919,7 +919,7 @@ out:
72945
72946 static void check_for_stack(struct device *dev, void *addr)
72947 {
72948 - if (object_is_on_stack(addr))
72949 + if (object_starts_on_stack(addr))
72950 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
72951 "stack [addr=%p]\n", addr);
72952 }
72953 diff --git a/lib/inflate.c b/lib/inflate.c
72954 index 013a761..c28f3fc 100644
72955 --- a/lib/inflate.c
72956 +++ b/lib/inflate.c
72957 @@ -269,7 +269,7 @@ static void free(void *where)
72958 malloc_ptr = free_mem_ptr;
72959 }
72960 #else
72961 -#define malloc(a) kmalloc(a, GFP_KERNEL)
72962 +#define malloc(a) kmalloc((a), GFP_KERNEL)
72963 #define free(a) kfree(a)
72964 #endif
72965
72966 diff --git a/lib/ioremap.c b/lib/ioremap.c
72967 index 0c9216c..863bd89 100644
72968 --- a/lib/ioremap.c
72969 +++ b/lib/ioremap.c
72970 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
72971 unsigned long next;
72972
72973 phys_addr -= addr;
72974 - pmd = pmd_alloc(&init_mm, pud, addr);
72975 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
72976 if (!pmd)
72977 return -ENOMEM;
72978 do {
72979 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
72980 unsigned long next;
72981
72982 phys_addr -= addr;
72983 - pud = pud_alloc(&init_mm, pgd, addr);
72984 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
72985 if (!pud)
72986 return -ENOMEM;
72987 do {
72988 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
72989 index bd2bea9..6b3c95e 100644
72990 --- a/lib/is_single_threaded.c
72991 +++ b/lib/is_single_threaded.c
72992 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
72993 struct task_struct *p, *t;
72994 bool ret;
72995
72996 + if (!mm)
72997 + return true;
72998 +
72999 if (atomic_read(&task->signal->live) != 1)
73000 return false;
73001
73002 diff --git a/lib/list_debug.c b/lib/list_debug.c
73003 index c24c2f7..3fc5da0 100644
73004 --- a/lib/list_debug.c
73005 +++ b/lib/list_debug.c
73006 @@ -11,7 +11,9 @@
73007 #include <linux/bug.h>
73008 #include <linux/kernel.h>
73009 #include <linux/rculist.h>
73010 +#include <linux/mm.h>
73011
73012 +#ifdef CONFIG_DEBUG_LIST
73013 /*
73014 * Insert a new entry between two known consecutive entries.
73015 *
73016 @@ -19,21 +21,32 @@
73017 * the prev/next entries already!
73018 */
73019
73020 -void __list_add(struct list_head *new,
73021 - struct list_head *prev,
73022 - struct list_head *next)
73023 +static bool __list_add_debug(struct list_head *new,
73024 + struct list_head *prev,
73025 + struct list_head *next)
73026 {
73027 - WARN(next->prev != prev,
73028 + if (WARN(next->prev != prev,
73029 "list_add corruption. next->prev should be "
73030 "prev (%p), but was %p. (next=%p).\n",
73031 - prev, next->prev, next);
73032 - WARN(prev->next != next,
73033 + prev, next->prev, next) ||
73034 + WARN(prev->next != next,
73035 "list_add corruption. prev->next should be "
73036 "next (%p), but was %p. (prev=%p).\n",
73037 - next, prev->next, prev);
73038 - WARN(new == prev || new == next,
73039 + next, prev->next, prev) ||
73040 + WARN(new == prev || new == next,
73041 "list_add double add: new=%p, prev=%p, next=%p.\n",
73042 - new, prev, next);
73043 + new, prev, next))
73044 + return false;
73045 + return true;
73046 +}
73047 +
73048 +void __list_add(struct list_head *new,
73049 + struct list_head *prev,
73050 + struct list_head *next)
73051 +{
73052 + if (!__list_add_debug(new, prev, next))
73053 + return;
73054 +
73055 next->prev = new;
73056 new->next = next;
73057 new->prev = prev;
73058 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73059 }
73060 EXPORT_SYMBOL(__list_add);
73061
73062 -void __list_del_entry(struct list_head *entry)
73063 +static bool __list_del_entry_debug(struct list_head *entry)
73064 {
73065 struct list_head *prev, *next;
73066
73067 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73068 WARN(next->prev != entry,
73069 "list_del corruption. next->prev should be %p, "
73070 "but was %p\n", entry, next->prev))
73071 + return false;
73072 + return true;
73073 +}
73074 +
73075 +void __list_del_entry(struct list_head *entry)
73076 +{
73077 + if (!__list_del_entry_debug(entry))
73078 return;
73079
73080 - __list_del(prev, next);
73081 + __list_del(entry->prev, entry->next);
73082 }
73083 EXPORT_SYMBOL(__list_del_entry);
73084
73085 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73086 void __list_add_rcu(struct list_head *new,
73087 struct list_head *prev, struct list_head *next)
73088 {
73089 - WARN(next->prev != prev,
73090 + if (WARN(next->prev != prev,
73091 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73092 - prev, next->prev, next);
73093 - WARN(prev->next != next,
73094 + prev, next->prev, next) ||
73095 + WARN(prev->next != next,
73096 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73097 - next, prev->next, prev);
73098 + next, prev->next, prev))
73099 + return;
73100 +
73101 new->next = next;
73102 new->prev = prev;
73103 rcu_assign_pointer(list_next_rcu(prev), new);
73104 next->prev = new;
73105 }
73106 EXPORT_SYMBOL(__list_add_rcu);
73107 +#endif
73108 +
73109 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
73110 +{
73111 + struct list_head *prev, *next;
73112 +
73113 + prev = head->prev;
73114 + next = head;
73115 +
73116 +#ifdef CONFIG_DEBUG_LIST
73117 + if (!__list_add_debug(new, prev, next))
73118 + return;
73119 +#endif
73120 +
73121 + pax_open_kernel();
73122 + next->prev = new;
73123 + new->next = next;
73124 + new->prev = prev;
73125 + prev->next = new;
73126 + pax_close_kernel();
73127 +}
73128 +EXPORT_SYMBOL(pax_list_add_tail);
73129 +
73130 +void pax_list_del(struct list_head *entry)
73131 +{
73132 +#ifdef CONFIG_DEBUG_LIST
73133 + if (!__list_del_entry_debug(entry))
73134 + return;
73135 +#endif
73136 +
73137 + pax_open_kernel();
73138 + __list_del(entry->prev, entry->next);
73139 + entry->next = LIST_POISON1;
73140 + entry->prev = LIST_POISON2;
73141 + pax_close_kernel();
73142 +}
73143 +EXPORT_SYMBOL(pax_list_del);
73144 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73145 index e796429..6e38f9f 100644
73146 --- a/lib/radix-tree.c
73147 +++ b/lib/radix-tree.c
73148 @@ -92,7 +92,7 @@ struct radix_tree_preload {
73149 int nr;
73150 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73151 };
73152 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73153 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73154
73155 static inline void *ptr_to_indirect(void *ptr)
73156 {
73157 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73158 index bb2b201..46abaf9 100644
73159 --- a/lib/strncpy_from_user.c
73160 +++ b/lib/strncpy_from_user.c
73161 @@ -21,7 +21,7 @@
73162 */
73163 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73164 {
73165 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73166 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73167 long res = 0;
73168
73169 /*
73170 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73171 index a28df52..3d55877 100644
73172 --- a/lib/strnlen_user.c
73173 +++ b/lib/strnlen_user.c
73174 @@ -26,7 +26,7 @@
73175 */
73176 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
73177 {
73178 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73179 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73180 long align, res = 0;
73181 unsigned long c;
73182
73183 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
73184 index 39c99fe..18f060b 100644
73185 --- a/lib/vsprintf.c
73186 +++ b/lib/vsprintf.c
73187 @@ -16,6 +16,9 @@
73188 * - scnprintf and vscnprintf
73189 */
73190
73191 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73192 +#define __INCLUDED_BY_HIDESYM 1
73193 +#endif
73194 #include <stdarg.h>
73195 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
73196 #include <linux/types.h>
73197 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
73198 char sym[KSYM_SYMBOL_LEN];
73199 if (ext == 'B')
73200 sprint_backtrace(sym, value);
73201 - else if (ext != 'f' && ext != 's')
73202 + else if (ext != 'f' && ext != 's' && ext != 'a')
73203 sprint_symbol(sym, value);
73204 else
73205 sprint_symbol_no_offset(sym, value);
73206 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
73207 return number(buf, end, *(const netdev_features_t *)addr, spec);
73208 }
73209
73210 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73211 +int kptr_restrict __read_mostly = 2;
73212 +#else
73213 int kptr_restrict __read_mostly;
73214 +#endif
73215
73216 /*
73217 * Show a '%p' thing. A kernel extension is that the '%p' is followed
73218 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
73219 * - 'S' For symbolic direct pointers with offset
73220 * - 's' For symbolic direct pointers without offset
73221 * - 'B' For backtraced symbolic direct pointers with offset
73222 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
73223 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
73224 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
73225 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
73226 * - 'M' For a 6-byte MAC address, it prints the address in the
73227 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73228
73229 if (!ptr && *fmt != 'K') {
73230 /*
73231 - * Print (null) with the same width as a pointer so it makes
73232 + * Print (nil) with the same width as a pointer so it makes
73233 * tabular output look nice.
73234 */
73235 if (spec.field_width == -1)
73236 spec.field_width = default_width;
73237 - return string(buf, end, "(null)", spec);
73238 + return string(buf, end, "(nil)", spec);
73239 }
73240
73241 switch (*fmt) {
73242 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73243 /* Fallthrough */
73244 case 'S':
73245 case 's':
73246 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73247 + break;
73248 +#else
73249 + return symbol_string(buf, end, ptr, spec, *fmt);
73250 +#endif
73251 + case 'A':
73252 + case 'a':
73253 case 'B':
73254 return symbol_string(buf, end, ptr, spec, *fmt);
73255 case 'R':
73256 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73257 va_end(va);
73258 return buf;
73259 }
73260 + case 'P':
73261 + break;
73262 case 'K':
73263 /*
73264 * %pK cannot be used in IRQ context because its test
73265 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73266 }
73267 break;
73268 }
73269 +
73270 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73271 + /* 'P' = approved pointers to copy to userland,
73272 + as in the /proc/kallsyms case, as we make it display nothing
73273 + for non-root users, and the real contents for root users
73274 + Also ignore 'K' pointers, since we force their NULLing for non-root users
73275 + above
73276 + */
73277 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
73278 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
73279 + dump_stack();
73280 + ptr = NULL;
73281 + }
73282 +#endif
73283 +
73284 spec.flags |= SMALL;
73285 if (spec.field_width == -1) {
73286 spec.field_width = default_width;
73287 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73288 typeof(type) value; \
73289 if (sizeof(type) == 8) { \
73290 args = PTR_ALIGN(args, sizeof(u32)); \
73291 - *(u32 *)&value = *(u32 *)args; \
73292 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
73293 + *(u32 *)&value = *(const u32 *)args; \
73294 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
73295 } else { \
73296 args = PTR_ALIGN(args, sizeof(type)); \
73297 - value = *(typeof(type) *)args; \
73298 + value = *(const typeof(type) *)args; \
73299 } \
73300 args += sizeof(type); \
73301 value; \
73302 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73303 case FORMAT_TYPE_STR: {
73304 const char *str_arg = args;
73305 args += strlen(str_arg) + 1;
73306 - str = string(str, end, (char *)str_arg, spec);
73307 + str = string(str, end, str_arg, spec);
73308 break;
73309 }
73310
73311 diff --git a/localversion-grsec b/localversion-grsec
73312 new file mode 100644
73313 index 0000000..7cd6065
73314 --- /dev/null
73315 +++ b/localversion-grsec
73316 @@ -0,0 +1 @@
73317 +-grsec
73318 diff --git a/mm/Kconfig b/mm/Kconfig
73319 index a3f8ddd..f31e92e 100644
73320 --- a/mm/Kconfig
73321 +++ b/mm/Kconfig
73322 @@ -252,10 +252,10 @@ config KSM
73323 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
73324
73325 config DEFAULT_MMAP_MIN_ADDR
73326 - int "Low address space to protect from user allocation"
73327 + int "Low address space to protect from user allocation"
73328 depends on MMU
73329 - default 4096
73330 - help
73331 + default 65536
73332 + help
73333 This is the portion of low virtual memory which should be protected
73334 from userspace allocation. Keeping a user from writing to low pages
73335 can help reduce the impact of kernel NULL pointer bugs.
73336 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
73337
73338 config HWPOISON_INJECT
73339 tristate "HWPoison pages injector"
73340 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
73341 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
73342 select PROC_PAGE_MONITOR
73343
73344 config NOMMU_INITIAL_TRIM_EXCESS
73345 diff --git a/mm/filemap.c b/mm/filemap.c
73346 index 83efee7..3f99381 100644
73347 --- a/mm/filemap.c
73348 +++ b/mm/filemap.c
73349 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
73350 struct address_space *mapping = file->f_mapping;
73351
73352 if (!mapping->a_ops->readpage)
73353 - return -ENOEXEC;
73354 + return -ENODEV;
73355 file_accessed(file);
73356 vma->vm_ops = &generic_file_vm_ops;
73357 return 0;
73358 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
73359 *pos = i_size_read(inode);
73360
73361 if (limit != RLIM_INFINITY) {
73362 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
73363 if (*pos >= limit) {
73364 send_sig(SIGXFSZ, current, 0);
73365 return -EFBIG;
73366 diff --git a/mm/fremap.c b/mm/fremap.c
73367 index a0aaf0e..20325c3 100644
73368 --- a/mm/fremap.c
73369 +++ b/mm/fremap.c
73370 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
73371 retry:
73372 vma = find_vma(mm, start);
73373
73374 +#ifdef CONFIG_PAX_SEGMEXEC
73375 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
73376 + goto out;
73377 +#endif
73378 +
73379 /*
73380 * Make sure the vma is shared, that it supports prefaulting,
73381 * and that the remapped range is valid and fully within
73382 diff --git a/mm/highmem.c b/mm/highmem.c
73383 index 09fc744..3936897 100644
73384 --- a/mm/highmem.c
73385 +++ b/mm/highmem.c
73386 @@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
73387 * So no dangers, even with speculative execution.
73388 */
73389 page = pte_page(pkmap_page_table[i]);
73390 + pax_open_kernel();
73391 pte_clear(&init_mm, (unsigned long)page_address(page),
73392 &pkmap_page_table[i]);
73393 -
73394 + pax_close_kernel();
73395 set_page_address(page, NULL);
73396 need_flush = 1;
73397 }
73398 @@ -199,9 +200,11 @@ start:
73399 }
73400 }
73401 vaddr = PKMAP_ADDR(last_pkmap_nr);
73402 +
73403 + pax_open_kernel();
73404 set_pte_at(&init_mm, vaddr,
73405 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
73406 -
73407 + pax_close_kernel();
73408 pkmap_count[last_pkmap_nr] = 1;
73409 set_page_address(page, (void *)vaddr);
73410
73411 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
73412 index 40f17c3..c1cc011 100644
73413 --- a/mm/huge_memory.c
73414 +++ b/mm/huge_memory.c
73415 @@ -710,7 +710,7 @@ out:
73416 * run pte_offset_map on the pmd, if an huge pmd could
73417 * materialize from under us from a different thread.
73418 */
73419 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
73420 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73421 return VM_FAULT_OOM;
73422 /* if an huge pmd materialized from under us just retry later */
73423 if (unlikely(pmd_trans_huge(*pmd)))
73424 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
73425 index f198aca..a19a5a5 100644
73426 --- a/mm/hugetlb.c
73427 +++ b/mm/hugetlb.c
73428 @@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
73429 return 1;
73430 }
73431
73432 +#ifdef CONFIG_PAX_SEGMEXEC
73433 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
73434 +{
73435 + struct mm_struct *mm = vma->vm_mm;
73436 + struct vm_area_struct *vma_m;
73437 + unsigned long address_m;
73438 + pte_t *ptep_m;
73439 +
73440 + vma_m = pax_find_mirror_vma(vma);
73441 + if (!vma_m)
73442 + return;
73443 +
73444 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
73445 + address_m = address + SEGMEXEC_TASK_SIZE;
73446 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
73447 + get_page(page_m);
73448 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
73449 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
73450 +}
73451 +#endif
73452 +
73453 /*
73454 * Hugetlb_cow() should be called with page lock of the original hugepage held.
73455 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
73456 @@ -2627,6 +2648,11 @@ retry_avoidcopy:
73457 make_huge_pte(vma, new_page, 1));
73458 page_remove_rmap(old_page);
73459 hugepage_add_new_anon_rmap(new_page, vma, address);
73460 +
73461 +#ifdef CONFIG_PAX_SEGMEXEC
73462 + pax_mirror_huge_pte(vma, address, new_page);
73463 +#endif
73464 +
73465 /* Make the old page be freed below */
73466 new_page = old_page;
73467 }
73468 @@ -2786,6 +2812,10 @@ retry:
73469 && (vma->vm_flags & VM_SHARED)));
73470 set_huge_pte_at(mm, address, ptep, new_pte);
73471
73472 +#ifdef CONFIG_PAX_SEGMEXEC
73473 + pax_mirror_huge_pte(vma, address, page);
73474 +#endif
73475 +
73476 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
73477 /* Optimization, do the COW without a second fault */
73478 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
73479 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73480 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
73481 struct hstate *h = hstate_vma(vma);
73482
73483 +#ifdef CONFIG_PAX_SEGMEXEC
73484 + struct vm_area_struct *vma_m;
73485 +#endif
73486 +
73487 address &= huge_page_mask(h);
73488
73489 ptep = huge_pte_offset(mm, address);
73490 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73491 VM_FAULT_SET_HINDEX(hstate_index(h));
73492 }
73493
73494 +#ifdef CONFIG_PAX_SEGMEXEC
73495 + vma_m = pax_find_mirror_vma(vma);
73496 + if (vma_m) {
73497 + unsigned long address_m;
73498 +
73499 + if (vma->vm_start > vma_m->vm_start) {
73500 + address_m = address;
73501 + address -= SEGMEXEC_TASK_SIZE;
73502 + vma = vma_m;
73503 + h = hstate_vma(vma);
73504 + } else
73505 + address_m = address + SEGMEXEC_TASK_SIZE;
73506 +
73507 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
73508 + return VM_FAULT_OOM;
73509 + address_m &= HPAGE_MASK;
73510 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
73511 + }
73512 +#endif
73513 +
73514 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
73515 if (!ptep)
73516 return VM_FAULT_OOM;
73517 diff --git a/mm/internal.h b/mm/internal.h
73518 index 3c5197d..08d0065 100644
73519 --- a/mm/internal.h
73520 +++ b/mm/internal.h
73521 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
73522 * in mm/page_alloc.c
73523 */
73524 extern void __free_pages_bootmem(struct page *page, unsigned int order);
73525 +extern void free_compound_page(struct page *page);
73526 extern void prep_compound_page(struct page *page, unsigned long order);
73527 #ifdef CONFIG_MEMORY_FAILURE
73528 extern bool is_free_buddy_page(struct page *page);
73529 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
73530 index a217cc5..74c9ec0 100644
73531 --- a/mm/kmemleak.c
73532 +++ b/mm/kmemleak.c
73533 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
73534
73535 for (i = 0; i < object->trace_len; i++) {
73536 void *ptr = (void *)object->trace[i];
73537 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
73538 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
73539 }
73540 }
73541
73542 diff --git a/mm/maccess.c b/mm/maccess.c
73543 index d53adf9..03a24bf 100644
73544 --- a/mm/maccess.c
73545 +++ b/mm/maccess.c
73546 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
73547 set_fs(KERNEL_DS);
73548 pagefault_disable();
73549 ret = __copy_from_user_inatomic(dst,
73550 - (__force const void __user *)src, size);
73551 + (const void __force_user *)src, size);
73552 pagefault_enable();
73553 set_fs(old_fs);
73554
73555 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
73556
73557 set_fs(KERNEL_DS);
73558 pagefault_disable();
73559 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
73560 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
73561 pagefault_enable();
73562 set_fs(old_fs);
73563
73564 diff --git a/mm/madvise.c b/mm/madvise.c
73565 index 03dfa5c..b032917 100644
73566 --- a/mm/madvise.c
73567 +++ b/mm/madvise.c
73568 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
73569 pgoff_t pgoff;
73570 unsigned long new_flags = vma->vm_flags;
73571
73572 +#ifdef CONFIG_PAX_SEGMEXEC
73573 + struct vm_area_struct *vma_m;
73574 +#endif
73575 +
73576 switch (behavior) {
73577 case MADV_NORMAL:
73578 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
73579 @@ -123,6 +127,13 @@ success:
73580 /*
73581 * vm_flags is protected by the mmap_sem held in write mode.
73582 */
73583 +
73584 +#ifdef CONFIG_PAX_SEGMEXEC
73585 + vma_m = pax_find_mirror_vma(vma);
73586 + if (vma_m)
73587 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
73588 +#endif
73589 +
73590 vma->vm_flags = new_flags;
73591
73592 out:
73593 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
73594 struct vm_area_struct ** prev,
73595 unsigned long start, unsigned long end)
73596 {
73597 +
73598 +#ifdef CONFIG_PAX_SEGMEXEC
73599 + struct vm_area_struct *vma_m;
73600 +#endif
73601 +
73602 *prev = vma;
73603 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
73604 return -EINVAL;
73605 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
73606 zap_page_range(vma, start, end - start, &details);
73607 } else
73608 zap_page_range(vma, start, end - start, NULL);
73609 +
73610 +#ifdef CONFIG_PAX_SEGMEXEC
73611 + vma_m = pax_find_mirror_vma(vma);
73612 + if (vma_m) {
73613 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
73614 + struct zap_details details = {
73615 + .nonlinear_vma = vma_m,
73616 + .last_index = ULONG_MAX,
73617 + };
73618 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
73619 + } else
73620 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
73621 + }
73622 +#endif
73623 +
73624 return 0;
73625 }
73626
73627 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
73628 if (end < start)
73629 goto out;
73630
73631 +#ifdef CONFIG_PAX_SEGMEXEC
73632 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73633 + if (end > SEGMEXEC_TASK_SIZE)
73634 + goto out;
73635 + } else
73636 +#endif
73637 +
73638 + if (end > TASK_SIZE)
73639 + goto out;
73640 +
73641 error = 0;
73642 if (end == start)
73643 goto out;
73644 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
73645 index 8b20278..05dac18 100644
73646 --- a/mm/memory-failure.c
73647 +++ b/mm/memory-failure.c
73648 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
73649
73650 int sysctl_memory_failure_recovery __read_mostly = 1;
73651
73652 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
73653 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
73654
73655 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
73656
73657 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
73658 pfn, t->comm, t->pid);
73659 si.si_signo = SIGBUS;
73660 si.si_errno = 0;
73661 - si.si_addr = (void *)addr;
73662 + si.si_addr = (void __user *)addr;
73663 #ifdef __ARCH_SI_TRAPNO
73664 si.si_trapno = trapno;
73665 #endif
73666 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
73667 }
73668
73669 nr_pages = 1 << compound_trans_order(hpage);
73670 - atomic_long_add(nr_pages, &mce_bad_pages);
73671 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
73672
73673 /*
73674 * We need/can do nothing about count=0 pages.
73675 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
73676 if (!PageHWPoison(hpage)
73677 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
73678 || (p != hpage && TestSetPageHWPoison(hpage))) {
73679 - atomic_long_sub(nr_pages, &mce_bad_pages);
73680 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
73681 return 0;
73682 }
73683 set_page_hwpoison_huge_page(hpage);
73684 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
73685 }
73686 if (hwpoison_filter(p)) {
73687 if (TestClearPageHWPoison(p))
73688 - atomic_long_sub(nr_pages, &mce_bad_pages);
73689 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
73690 unlock_page(hpage);
73691 put_page(hpage);
73692 return 0;
73693 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
73694 return 0;
73695 }
73696 if (TestClearPageHWPoison(p))
73697 - atomic_long_sub(nr_pages, &mce_bad_pages);
73698 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
73699 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
73700 return 0;
73701 }
73702 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
73703 */
73704 if (TestClearPageHWPoison(page)) {
73705 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
73706 - atomic_long_sub(nr_pages, &mce_bad_pages);
73707 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
73708 freeit = 1;
73709 if (PageHuge(page))
73710 clear_page_hwpoison_huge_page(page);
73711 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
73712 }
73713 done:
73714 if (!PageHWPoison(hpage))
73715 - atomic_long_add(1 << compound_trans_order(hpage),
73716 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
73717 &mce_bad_pages);
73718 set_page_hwpoison_huge_page(hpage);
73719 dequeue_hwpoisoned_huge_page(hpage);
73720 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
73721 return ret;
73722
73723 done:
73724 - atomic_long_add(1, &mce_bad_pages);
73725 + atomic_long_add_unchecked(1, &mce_bad_pages);
73726 SetPageHWPoison(page);
73727 /* keep elevated page count for bad page */
73728 return ret;
73729 diff --git a/mm/memory.c b/mm/memory.c
73730 index f2973b2..fd020a7 100644
73731 --- a/mm/memory.c
73732 +++ b/mm/memory.c
73733 @@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
73734 free_pte_range(tlb, pmd, addr);
73735 } while (pmd++, addr = next, addr != end);
73736
73737 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
73738 start &= PUD_MASK;
73739 if (start < floor)
73740 return;
73741 @@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
73742 pmd = pmd_offset(pud, start);
73743 pud_clear(pud);
73744 pmd_free_tlb(tlb, pmd, start);
73745 +#endif
73746 +
73747 }
73748
73749 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
73750 @@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
73751 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
73752 } while (pud++, addr = next, addr != end);
73753
73754 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
73755 start &= PGDIR_MASK;
73756 if (start < floor)
73757 return;
73758 @@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
73759 pud = pud_offset(pgd, start);
73760 pgd_clear(pgd);
73761 pud_free_tlb(tlb, pud, start);
73762 +#endif
73763 +
73764 }
73765
73766 /*
73767 @@ -1626,12 +1632,6 @@ no_page_table:
73768 return page;
73769 }
73770
73771 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
73772 -{
73773 - return stack_guard_page_start(vma, addr) ||
73774 - stack_guard_page_end(vma, addr+PAGE_SIZE);
73775 -}
73776 -
73777 /**
73778 * __get_user_pages() - pin user pages in memory
73779 * @tsk: task_struct of target task
73780 @@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
73781 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
73782 i = 0;
73783
73784 - do {
73785 + while (nr_pages) {
73786 struct vm_area_struct *vma;
73787
73788 - vma = find_extend_vma(mm, start);
73789 + vma = find_vma(mm, start);
73790 if (!vma && in_gate_area(mm, start)) {
73791 unsigned long pg = start & PAGE_MASK;
73792 pgd_t *pgd;
73793 @@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
73794 goto next_page;
73795 }
73796
73797 - if (!vma ||
73798 + if (!vma || start < vma->vm_start ||
73799 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
73800 !(vm_flags & vma->vm_flags))
73801 return i ? : -EFAULT;
73802 @@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
73803 int ret;
73804 unsigned int fault_flags = 0;
73805
73806 - /* For mlock, just skip the stack guard page. */
73807 - if (foll_flags & FOLL_MLOCK) {
73808 - if (stack_guard_page(vma, start))
73809 - goto next_page;
73810 - }
73811 if (foll_flags & FOLL_WRITE)
73812 fault_flags |= FAULT_FLAG_WRITE;
73813 if (nonblocking)
73814 @@ -1860,7 +1855,7 @@ next_page:
73815 start += PAGE_SIZE;
73816 nr_pages--;
73817 } while (nr_pages && start < vma->vm_end);
73818 - } while (nr_pages);
73819 + }
73820 return i;
73821 }
73822 EXPORT_SYMBOL(__get_user_pages);
73823 @@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
73824 page_add_file_rmap(page);
73825 set_pte_at(mm, addr, pte, mk_pte(page, prot));
73826
73827 +#ifdef CONFIG_PAX_SEGMEXEC
73828 + pax_mirror_file_pte(vma, addr, page, ptl);
73829 +#endif
73830 +
73831 retval = 0;
73832 pte_unmap_unlock(pte, ptl);
73833 return retval;
73834 @@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
73835 if (!page_count(page))
73836 return -EINVAL;
73837 if (!(vma->vm_flags & VM_MIXEDMAP)) {
73838 +
73839 +#ifdef CONFIG_PAX_SEGMEXEC
73840 + struct vm_area_struct *vma_m;
73841 +#endif
73842 +
73843 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
73844 BUG_ON(vma->vm_flags & VM_PFNMAP);
73845 vma->vm_flags |= VM_MIXEDMAP;
73846 +
73847 +#ifdef CONFIG_PAX_SEGMEXEC
73848 + vma_m = pax_find_mirror_vma(vma);
73849 + if (vma_m)
73850 + vma_m->vm_flags |= VM_MIXEDMAP;
73851 +#endif
73852 +
73853 }
73854 return insert_page(vma, addr, page, vma->vm_page_prot);
73855 }
73856 @@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
73857 unsigned long pfn)
73858 {
73859 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
73860 + BUG_ON(vma->vm_mirror);
73861
73862 if (addr < vma->vm_start || addr >= vma->vm_end)
73863 return -EFAULT;
73864 @@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
73865
73866 BUG_ON(pud_huge(*pud));
73867
73868 - pmd = pmd_alloc(mm, pud, addr);
73869 + pmd = (mm == &init_mm) ?
73870 + pmd_alloc_kernel(mm, pud, addr) :
73871 + pmd_alloc(mm, pud, addr);
73872 if (!pmd)
73873 return -ENOMEM;
73874 do {
73875 @@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
73876 unsigned long next;
73877 int err;
73878
73879 - pud = pud_alloc(mm, pgd, addr);
73880 + pud = (mm == &init_mm) ?
73881 + pud_alloc_kernel(mm, pgd, addr) :
73882 + pud_alloc(mm, pgd, addr);
73883 if (!pud)
73884 return -ENOMEM;
73885 do {
73886 @@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
73887 copy_user_highpage(dst, src, va, vma);
73888 }
73889
73890 +#ifdef CONFIG_PAX_SEGMEXEC
73891 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
73892 +{
73893 + struct mm_struct *mm = vma->vm_mm;
73894 + spinlock_t *ptl;
73895 + pte_t *pte, entry;
73896 +
73897 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
73898 + entry = *pte;
73899 + if (!pte_present(entry)) {
73900 + if (!pte_none(entry)) {
73901 + BUG_ON(pte_file(entry));
73902 + free_swap_and_cache(pte_to_swp_entry(entry));
73903 + pte_clear_not_present_full(mm, address, pte, 0);
73904 + }
73905 + } else {
73906 + struct page *page;
73907 +
73908 + flush_cache_page(vma, address, pte_pfn(entry));
73909 + entry = ptep_clear_flush(vma, address, pte);
73910 + BUG_ON(pte_dirty(entry));
73911 + page = vm_normal_page(vma, address, entry);
73912 + if (page) {
73913 + update_hiwater_rss(mm);
73914 + if (PageAnon(page))
73915 + dec_mm_counter_fast(mm, MM_ANONPAGES);
73916 + else
73917 + dec_mm_counter_fast(mm, MM_FILEPAGES);
73918 + page_remove_rmap(page);
73919 + page_cache_release(page);
73920 + }
73921 + }
73922 + pte_unmap_unlock(pte, ptl);
73923 +}
73924 +
73925 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
73926 + *
73927 + * the ptl of the lower mapped page is held on entry and is not released on exit
73928 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
73929 + */
73930 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
73931 +{
73932 + struct mm_struct *mm = vma->vm_mm;
73933 + unsigned long address_m;
73934 + spinlock_t *ptl_m;
73935 + struct vm_area_struct *vma_m;
73936 + pmd_t *pmd_m;
73937 + pte_t *pte_m, entry_m;
73938 +
73939 + BUG_ON(!page_m || !PageAnon(page_m));
73940 +
73941 + vma_m = pax_find_mirror_vma(vma);
73942 + if (!vma_m)
73943 + return;
73944 +
73945 + BUG_ON(!PageLocked(page_m));
73946 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
73947 + address_m = address + SEGMEXEC_TASK_SIZE;
73948 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
73949 + pte_m = pte_offset_map(pmd_m, address_m);
73950 + ptl_m = pte_lockptr(mm, pmd_m);
73951 + if (ptl != ptl_m) {
73952 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
73953 + if (!pte_none(*pte_m))
73954 + goto out;
73955 + }
73956 +
73957 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
73958 + page_cache_get(page_m);
73959 + page_add_anon_rmap(page_m, vma_m, address_m);
73960 + inc_mm_counter_fast(mm, MM_ANONPAGES);
73961 + set_pte_at(mm, address_m, pte_m, entry_m);
73962 + update_mmu_cache(vma_m, address_m, entry_m);
73963 +out:
73964 + if (ptl != ptl_m)
73965 + spin_unlock(ptl_m);
73966 + pte_unmap(pte_m);
73967 + unlock_page(page_m);
73968 +}
73969 +
73970 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
73971 +{
73972 + struct mm_struct *mm = vma->vm_mm;
73973 + unsigned long address_m;
73974 + spinlock_t *ptl_m;
73975 + struct vm_area_struct *vma_m;
73976 + pmd_t *pmd_m;
73977 + pte_t *pte_m, entry_m;
73978 +
73979 + BUG_ON(!page_m || PageAnon(page_m));
73980 +
73981 + vma_m = pax_find_mirror_vma(vma);
73982 + if (!vma_m)
73983 + return;
73984 +
73985 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
73986 + address_m = address + SEGMEXEC_TASK_SIZE;
73987 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
73988 + pte_m = pte_offset_map(pmd_m, address_m);
73989 + ptl_m = pte_lockptr(mm, pmd_m);
73990 + if (ptl != ptl_m) {
73991 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
73992 + if (!pte_none(*pte_m))
73993 + goto out;
73994 + }
73995 +
73996 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
73997 + page_cache_get(page_m);
73998 + page_add_file_rmap(page_m);
73999 + inc_mm_counter_fast(mm, MM_FILEPAGES);
74000 + set_pte_at(mm, address_m, pte_m, entry_m);
74001 + update_mmu_cache(vma_m, address_m, entry_m);
74002 +out:
74003 + if (ptl != ptl_m)
74004 + spin_unlock(ptl_m);
74005 + pte_unmap(pte_m);
74006 +}
74007 +
74008 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74009 +{
74010 + struct mm_struct *mm = vma->vm_mm;
74011 + unsigned long address_m;
74012 + spinlock_t *ptl_m;
74013 + struct vm_area_struct *vma_m;
74014 + pmd_t *pmd_m;
74015 + pte_t *pte_m, entry_m;
74016 +
74017 + vma_m = pax_find_mirror_vma(vma);
74018 + if (!vma_m)
74019 + return;
74020 +
74021 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74022 + address_m = address + SEGMEXEC_TASK_SIZE;
74023 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74024 + pte_m = pte_offset_map(pmd_m, address_m);
74025 + ptl_m = pte_lockptr(mm, pmd_m);
74026 + if (ptl != ptl_m) {
74027 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74028 + if (!pte_none(*pte_m))
74029 + goto out;
74030 + }
74031 +
74032 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74033 + set_pte_at(mm, address_m, pte_m, entry_m);
74034 +out:
74035 + if (ptl != ptl_m)
74036 + spin_unlock(ptl_m);
74037 + pte_unmap(pte_m);
74038 +}
74039 +
74040 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74041 +{
74042 + struct page *page_m;
74043 + pte_t entry;
74044 +
74045 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74046 + goto out;
74047 +
74048 + entry = *pte;
74049 + page_m = vm_normal_page(vma, address, entry);
74050 + if (!page_m)
74051 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74052 + else if (PageAnon(page_m)) {
74053 + if (pax_find_mirror_vma(vma)) {
74054 + pte_unmap_unlock(pte, ptl);
74055 + lock_page(page_m);
74056 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74057 + if (pte_same(entry, *pte))
74058 + pax_mirror_anon_pte(vma, address, page_m, ptl);
74059 + else
74060 + unlock_page(page_m);
74061 + }
74062 + } else
74063 + pax_mirror_file_pte(vma, address, page_m, ptl);
74064 +
74065 +out:
74066 + pte_unmap_unlock(pte, ptl);
74067 +}
74068 +#endif
74069 +
74070 /*
74071 * This routine handles present pages, when users try to write
74072 * to a shared page. It is done by copying the page to a new address
74073 @@ -2720,6 +2916,12 @@ gotten:
74074 */
74075 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74076 if (likely(pte_same(*page_table, orig_pte))) {
74077 +
74078 +#ifdef CONFIG_PAX_SEGMEXEC
74079 + if (pax_find_mirror_vma(vma))
74080 + BUG_ON(!trylock_page(new_page));
74081 +#endif
74082 +
74083 if (old_page) {
74084 if (!PageAnon(old_page)) {
74085 dec_mm_counter_fast(mm, MM_FILEPAGES);
74086 @@ -2771,6 +2973,10 @@ gotten:
74087 page_remove_rmap(old_page);
74088 }
74089
74090 +#ifdef CONFIG_PAX_SEGMEXEC
74091 + pax_mirror_anon_pte(vma, address, new_page, ptl);
74092 +#endif
74093 +
74094 /* Free the old page.. */
74095 new_page = old_page;
74096 ret |= VM_FAULT_WRITE;
74097 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74098 swap_free(entry);
74099 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74100 try_to_free_swap(page);
74101 +
74102 +#ifdef CONFIG_PAX_SEGMEXEC
74103 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74104 +#endif
74105 +
74106 unlock_page(page);
74107 if (swapcache) {
74108 /*
74109 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74110
74111 /* No need to invalidate - it was non-present before */
74112 update_mmu_cache(vma, address, page_table);
74113 +
74114 +#ifdef CONFIG_PAX_SEGMEXEC
74115 + pax_mirror_anon_pte(vma, address, page, ptl);
74116 +#endif
74117 +
74118 unlock:
74119 pte_unmap_unlock(page_table, ptl);
74120 out:
74121 @@ -3093,40 +3309,6 @@ out_release:
74122 }
74123
74124 /*
74125 - * This is like a special single-page "expand_{down|up}wards()",
74126 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
74127 - * doesn't hit another vma.
74128 - */
74129 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74130 -{
74131 - address &= PAGE_MASK;
74132 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74133 - struct vm_area_struct *prev = vma->vm_prev;
74134 -
74135 - /*
74136 - * Is there a mapping abutting this one below?
74137 - *
74138 - * That's only ok if it's the same stack mapping
74139 - * that has gotten split..
74140 - */
74141 - if (prev && prev->vm_end == address)
74142 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74143 -
74144 - expand_downwards(vma, address - PAGE_SIZE);
74145 - }
74146 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74147 - struct vm_area_struct *next = vma->vm_next;
74148 -
74149 - /* As VM_GROWSDOWN but s/below/above/ */
74150 - if (next && next->vm_start == address + PAGE_SIZE)
74151 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74152 -
74153 - expand_upwards(vma, address + PAGE_SIZE);
74154 - }
74155 - return 0;
74156 -}
74157 -
74158 -/*
74159 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74160 * but allow concurrent faults), and pte mapped but not yet locked.
74161 * We return with mmap_sem still held, but pte unmapped and unlocked.
74162 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74163 unsigned long address, pte_t *page_table, pmd_t *pmd,
74164 unsigned int flags)
74165 {
74166 - struct page *page;
74167 + struct page *page = NULL;
74168 spinlock_t *ptl;
74169 pte_t entry;
74170
74171 - pte_unmap(page_table);
74172 -
74173 - /* Check if we need to add a guard page to the stack */
74174 - if (check_stack_guard_page(vma, address) < 0)
74175 - return VM_FAULT_SIGBUS;
74176 -
74177 - /* Use the zero-page for reads */
74178 if (!(flags & FAULT_FLAG_WRITE)) {
74179 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
74180 vma->vm_page_prot));
74181 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74182 + ptl = pte_lockptr(mm, pmd);
74183 + spin_lock(ptl);
74184 if (!pte_none(*page_table))
74185 goto unlock;
74186 goto setpte;
74187 }
74188
74189 /* Allocate our own private page. */
74190 + pte_unmap(page_table);
74191 +
74192 if (unlikely(anon_vma_prepare(vma)))
74193 goto oom;
74194 page = alloc_zeroed_user_highpage_movable(vma, address);
74195 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74196 if (!pte_none(*page_table))
74197 goto release;
74198
74199 +#ifdef CONFIG_PAX_SEGMEXEC
74200 + if (pax_find_mirror_vma(vma))
74201 + BUG_ON(!trylock_page(page));
74202 +#endif
74203 +
74204 inc_mm_counter_fast(mm, MM_ANONPAGES);
74205 page_add_new_anon_rmap(page, vma, address);
74206 setpte:
74207 @@ -3181,6 +3364,12 @@ setpte:
74208
74209 /* No need to invalidate - it was non-present before */
74210 update_mmu_cache(vma, address, page_table);
74211 +
74212 +#ifdef CONFIG_PAX_SEGMEXEC
74213 + if (page)
74214 + pax_mirror_anon_pte(vma, address, page, ptl);
74215 +#endif
74216 +
74217 unlock:
74218 pte_unmap_unlock(page_table, ptl);
74219 return 0;
74220 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74221 */
74222 /* Only go through if we didn't race with anybody else... */
74223 if (likely(pte_same(*page_table, orig_pte))) {
74224 +
74225 +#ifdef CONFIG_PAX_SEGMEXEC
74226 + if (anon && pax_find_mirror_vma(vma))
74227 + BUG_ON(!trylock_page(page));
74228 +#endif
74229 +
74230 flush_icache_page(vma, page);
74231 entry = mk_pte(page, vma->vm_page_prot);
74232 if (flags & FAULT_FLAG_WRITE)
74233 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74234
74235 /* no need to invalidate: a not-present page won't be cached */
74236 update_mmu_cache(vma, address, page_table);
74237 +
74238 +#ifdef CONFIG_PAX_SEGMEXEC
74239 + if (anon)
74240 + pax_mirror_anon_pte(vma, address, page, ptl);
74241 + else
74242 + pax_mirror_file_pte(vma, address, page, ptl);
74243 +#endif
74244 +
74245 } else {
74246 if (cow_page)
74247 mem_cgroup_uncharge_page(cow_page);
74248 @@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
74249 if (flags & FAULT_FLAG_WRITE)
74250 flush_tlb_fix_spurious_fault(vma, address);
74251 }
74252 +
74253 +#ifdef CONFIG_PAX_SEGMEXEC
74254 + pax_mirror_pte(vma, address, pte, pmd, ptl);
74255 + return 0;
74256 +#endif
74257 +
74258 unlock:
74259 pte_unmap_unlock(pte, ptl);
74260 return 0;
74261 @@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74262 pmd_t *pmd;
74263 pte_t *pte;
74264
74265 +#ifdef CONFIG_PAX_SEGMEXEC
74266 + struct vm_area_struct *vma_m;
74267 +#endif
74268 +
74269 __set_current_state(TASK_RUNNING);
74270
74271 count_vm_event(PGFAULT);
74272 @@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74273 if (unlikely(is_vm_hugetlb_page(vma)))
74274 return hugetlb_fault(mm, vma, address, flags);
74275
74276 +#ifdef CONFIG_PAX_SEGMEXEC
74277 + vma_m = pax_find_mirror_vma(vma);
74278 + if (vma_m) {
74279 + unsigned long address_m;
74280 + pgd_t *pgd_m;
74281 + pud_t *pud_m;
74282 + pmd_t *pmd_m;
74283 +
74284 + if (vma->vm_start > vma_m->vm_start) {
74285 + address_m = address;
74286 + address -= SEGMEXEC_TASK_SIZE;
74287 + vma = vma_m;
74288 + } else
74289 + address_m = address + SEGMEXEC_TASK_SIZE;
74290 +
74291 + pgd_m = pgd_offset(mm, address_m);
74292 + pud_m = pud_alloc(mm, pgd_m, address_m);
74293 + if (!pud_m)
74294 + return VM_FAULT_OOM;
74295 + pmd_m = pmd_alloc(mm, pud_m, address_m);
74296 + if (!pmd_m)
74297 + return VM_FAULT_OOM;
74298 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
74299 + return VM_FAULT_OOM;
74300 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
74301 + }
74302 +#endif
74303 +
74304 retry:
74305 pgd = pgd_offset(mm, address);
74306 pud = pud_alloc(mm, pgd, address);
74307 @@ -3565,7 +3806,7 @@ retry:
74308 * run pte_offset_map on the pmd, if an huge pmd could
74309 * materialize from under us from a different thread.
74310 */
74311 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
74312 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74313 return VM_FAULT_OOM;
74314 /* if an huge pmd materialized from under us just retry later */
74315 if (unlikely(pmd_trans_huge(*pmd)))
74316 @@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74317 spin_unlock(&mm->page_table_lock);
74318 return 0;
74319 }
74320 +
74321 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74322 +{
74323 + pud_t *new = pud_alloc_one(mm, address);
74324 + if (!new)
74325 + return -ENOMEM;
74326 +
74327 + smp_wmb(); /* See comment in __pte_alloc */
74328 +
74329 + spin_lock(&mm->page_table_lock);
74330 + if (pgd_present(*pgd)) /* Another has populated it */
74331 + pud_free(mm, new);
74332 + else
74333 + pgd_populate_kernel(mm, pgd, new);
74334 + spin_unlock(&mm->page_table_lock);
74335 + return 0;
74336 +}
74337 #endif /* __PAGETABLE_PUD_FOLDED */
74338
74339 #ifndef __PAGETABLE_PMD_FOLDED
74340 @@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
74341 spin_unlock(&mm->page_table_lock);
74342 return 0;
74343 }
74344 +
74345 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
74346 +{
74347 + pmd_t *new = pmd_alloc_one(mm, address);
74348 + if (!new)
74349 + return -ENOMEM;
74350 +
74351 + smp_wmb(); /* See comment in __pte_alloc */
74352 +
74353 + spin_lock(&mm->page_table_lock);
74354 +#ifndef __ARCH_HAS_4LEVEL_HACK
74355 + if (pud_present(*pud)) /* Another has populated it */
74356 + pmd_free(mm, new);
74357 + else
74358 + pud_populate_kernel(mm, pud, new);
74359 +#else
74360 + if (pgd_present(*pud)) /* Another has populated it */
74361 + pmd_free(mm, new);
74362 + else
74363 + pgd_populate_kernel(mm, pud, new);
74364 +#endif /* __ARCH_HAS_4LEVEL_HACK */
74365 + spin_unlock(&mm->page_table_lock);
74366 + return 0;
74367 +}
74368 #endif /* __PAGETABLE_PMD_FOLDED */
74369
74370 int make_pages_present(unsigned long addr, unsigned long end)
74371 @@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
74372 gate_vma.vm_start = FIXADDR_USER_START;
74373 gate_vma.vm_end = FIXADDR_USER_END;
74374 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
74375 - gate_vma.vm_page_prot = __P101;
74376 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
74377
74378 return 0;
74379 }
74380 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
74381 index 002c281..9429765 100644
74382 --- a/mm/mempolicy.c
74383 +++ b/mm/mempolicy.c
74384 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
74385 unsigned long vmstart;
74386 unsigned long vmend;
74387
74388 +#ifdef CONFIG_PAX_SEGMEXEC
74389 + struct vm_area_struct *vma_m;
74390 +#endif
74391 +
74392 vma = find_vma(mm, start);
74393 if (!vma || vma->vm_start > start)
74394 return -EFAULT;
74395 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
74396 if (err)
74397 goto out;
74398 }
74399 +
74400 err = vma_replace_policy(vma, new_pol);
74401 if (err)
74402 goto out;
74403 +
74404 +#ifdef CONFIG_PAX_SEGMEXEC
74405 + vma_m = pax_find_mirror_vma(vma);
74406 + if (vma_m) {
74407 + err = vma_replace_policy(vma_m, new_pol);
74408 + if (err)
74409 + goto out;
74410 + }
74411 +#endif
74412 +
74413 }
74414
74415 out:
74416 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
74417
74418 if (end < start)
74419 return -EINVAL;
74420 +
74421 +#ifdef CONFIG_PAX_SEGMEXEC
74422 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74423 + if (end > SEGMEXEC_TASK_SIZE)
74424 + return -EINVAL;
74425 + } else
74426 +#endif
74427 +
74428 + if (end > TASK_SIZE)
74429 + return -EINVAL;
74430 +
74431 if (end == start)
74432 return 0;
74433
74434 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
74435 */
74436 tcred = __task_cred(task);
74437 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
74438 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
74439 - !capable(CAP_SYS_NICE)) {
74440 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
74441 rcu_read_unlock();
74442 err = -EPERM;
74443 goto out_put;
74444 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
74445 goto out;
74446 }
74447
74448 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
74449 + if (mm != current->mm &&
74450 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
74451 + mmput(mm);
74452 + err = -EPERM;
74453 + goto out;
74454 + }
74455 +#endif
74456 +
74457 err = do_migrate_pages(mm, old, new,
74458 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
74459
74460 diff --git a/mm/migrate.c b/mm/migrate.c
74461 index 77ed2d7..317d528 100644
74462 --- a/mm/migrate.c
74463 +++ b/mm/migrate.c
74464 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
74465 */
74466 tcred = __task_cred(task);
74467 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
74468 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
74469 - !capable(CAP_SYS_NICE)) {
74470 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
74471 rcu_read_unlock();
74472 err = -EPERM;
74473 goto out;
74474 diff --git a/mm/mlock.c b/mm/mlock.c
74475 index f0b9ce5..da8d069 100644
74476 --- a/mm/mlock.c
74477 +++ b/mm/mlock.c
74478 @@ -13,6 +13,7 @@
74479 #include <linux/pagemap.h>
74480 #include <linux/mempolicy.h>
74481 #include <linux/syscalls.h>
74482 +#include <linux/security.h>
74483 #include <linux/sched.h>
74484 #include <linux/export.h>
74485 #include <linux/rmap.h>
74486 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
74487 {
74488 unsigned long nstart, end, tmp;
74489 struct vm_area_struct * vma, * prev;
74490 - int error;
74491 + int error = 0;
74492
74493 VM_BUG_ON(start & ~PAGE_MASK);
74494 VM_BUG_ON(len != PAGE_ALIGN(len));
74495 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
74496 return -EINVAL;
74497 if (end == start)
74498 return 0;
74499 + if (end > TASK_SIZE)
74500 + return -EINVAL;
74501 +
74502 vma = find_vma(current->mm, start);
74503 if (!vma || vma->vm_start > start)
74504 return -ENOMEM;
74505 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
74506 for (nstart = start ; ; ) {
74507 vm_flags_t newflags;
74508
74509 +#ifdef CONFIG_PAX_SEGMEXEC
74510 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
74511 + break;
74512 +#endif
74513 +
74514 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
74515
74516 newflags = vma->vm_flags | VM_LOCKED;
74517 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
74518 lock_limit >>= PAGE_SHIFT;
74519
74520 /* check against resource limits */
74521 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
74522 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
74523 error = do_mlock(start, len, 1);
74524 up_write(&current->mm->mmap_sem);
74525 @@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
74526 static int do_mlockall(int flags)
74527 {
74528 struct vm_area_struct * vma, * prev = NULL;
74529 - unsigned int def_flags = 0;
74530
74531 if (flags & MCL_FUTURE)
74532 - def_flags = VM_LOCKED;
74533 - current->mm->def_flags = def_flags;
74534 + current->mm->def_flags |= VM_LOCKED;
74535 + else
74536 + current->mm->def_flags &= ~VM_LOCKED;
74537 if (flags == MCL_FUTURE)
74538 goto out;
74539
74540 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
74541 vm_flags_t newflags;
74542
74543 +#ifdef CONFIG_PAX_SEGMEXEC
74544 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
74545 + break;
74546 +#endif
74547 +
74548 + BUG_ON(vma->vm_end > TASK_SIZE);
74549 newflags = vma->vm_flags | VM_LOCKED;
74550 if (!(flags & MCL_CURRENT))
74551 newflags &= ~VM_LOCKED;
74552 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
74553 lock_limit >>= PAGE_SHIFT;
74554
74555 ret = -ENOMEM;
74556 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
74557 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
74558 capable(CAP_IPC_LOCK))
74559 ret = do_mlockall(flags);
74560 diff --git a/mm/mmap.c b/mm/mmap.c
74561 index 9a796c4..4fba820 100644
74562 --- a/mm/mmap.c
74563 +++ b/mm/mmap.c
74564 @@ -47,6 +47,16 @@
74565 #define arch_rebalance_pgtables(addr, len) (addr)
74566 #endif
74567
74568 +static inline void verify_mm_writelocked(struct mm_struct *mm)
74569 +{
74570 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
74571 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74572 + up_read(&mm->mmap_sem);
74573 + BUG();
74574 + }
74575 +#endif
74576 +}
74577 +
74578 static void unmap_region(struct mm_struct *mm,
74579 struct vm_area_struct *vma, struct vm_area_struct *prev,
74580 unsigned long start, unsigned long end);
74581 @@ -66,22 +76,32 @@ static void unmap_region(struct mm_struct *mm,
74582 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
74583 *
74584 */
74585 -pgprot_t protection_map[16] = {
74586 +pgprot_t protection_map[16] __read_only = {
74587 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
74588 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
74589 };
74590
74591 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
74592 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
74593 {
74594 - return __pgprot(pgprot_val(protection_map[vm_flags &
74595 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
74596 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
74597 pgprot_val(arch_vm_get_page_prot(vm_flags)));
74598 +
74599 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74600 + if (!(__supported_pte_mask & _PAGE_NX) &&
74601 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
74602 + (vm_flags & (VM_READ | VM_WRITE)))
74603 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
74604 +#endif
74605 +
74606 + return prot;
74607 }
74608 EXPORT_SYMBOL(vm_get_page_prot);
74609
74610 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
74611 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
74612 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
74613 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
74614 /*
74615 * Make sure vm_committed_as in one cacheline and not cacheline shared with
74616 * other variables. It can be updated by several CPUs frequently.
74617 @@ -223,6 +243,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
74618 struct vm_area_struct *next = vma->vm_next;
74619
74620 might_sleep();
74621 + BUG_ON(vma->vm_mirror);
74622 if (vma->vm_ops && vma->vm_ops->close)
74623 vma->vm_ops->close(vma);
74624 if (vma->vm_file)
74625 @@ -266,6 +287,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
74626 * not page aligned -Ram Gupta
74627 */
74628 rlim = rlimit(RLIMIT_DATA);
74629 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
74630 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
74631 (mm->end_data - mm->start_data) > rlim)
74632 goto out;
74633 @@ -736,6 +758,12 @@ static int
74634 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
74635 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
74636 {
74637 +
74638 +#ifdef CONFIG_PAX_SEGMEXEC
74639 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
74640 + return 0;
74641 +#endif
74642 +
74643 if (is_mergeable_vma(vma, file, vm_flags) &&
74644 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
74645 if (vma->vm_pgoff == vm_pgoff)
74646 @@ -755,6 +783,12 @@ static int
74647 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
74648 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
74649 {
74650 +
74651 +#ifdef CONFIG_PAX_SEGMEXEC
74652 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
74653 + return 0;
74654 +#endif
74655 +
74656 if (is_mergeable_vma(vma, file, vm_flags) &&
74657 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
74658 pgoff_t vm_pglen;
74659 @@ -797,13 +831,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
74660 struct vm_area_struct *vma_merge(struct mm_struct *mm,
74661 struct vm_area_struct *prev, unsigned long addr,
74662 unsigned long end, unsigned long vm_flags,
74663 - struct anon_vma *anon_vma, struct file *file,
74664 + struct anon_vma *anon_vma, struct file *file,
74665 pgoff_t pgoff, struct mempolicy *policy)
74666 {
74667 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
74668 struct vm_area_struct *area, *next;
74669 int err;
74670
74671 +#ifdef CONFIG_PAX_SEGMEXEC
74672 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
74673 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
74674 +
74675 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
74676 +#endif
74677 +
74678 /*
74679 * We later require that vma->vm_flags == vm_flags,
74680 * so this tests vma->vm_flags & VM_SPECIAL, too.
74681 @@ -819,6 +860,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
74682 if (next && next->vm_end == end) /* cases 6, 7, 8 */
74683 next = next->vm_next;
74684
74685 +#ifdef CONFIG_PAX_SEGMEXEC
74686 + if (prev)
74687 + prev_m = pax_find_mirror_vma(prev);
74688 + if (area)
74689 + area_m = pax_find_mirror_vma(area);
74690 + if (next)
74691 + next_m = pax_find_mirror_vma(next);
74692 +#endif
74693 +
74694 /*
74695 * Can it merge with the predecessor?
74696 */
74697 @@ -838,9 +888,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
74698 /* cases 1, 6 */
74699 err = vma_adjust(prev, prev->vm_start,
74700 next->vm_end, prev->vm_pgoff, NULL);
74701 - } else /* cases 2, 5, 7 */
74702 +
74703 +#ifdef CONFIG_PAX_SEGMEXEC
74704 + if (!err && prev_m)
74705 + err = vma_adjust(prev_m, prev_m->vm_start,
74706 + next_m->vm_end, prev_m->vm_pgoff, NULL);
74707 +#endif
74708 +
74709 + } else { /* cases 2, 5, 7 */
74710 err = vma_adjust(prev, prev->vm_start,
74711 end, prev->vm_pgoff, NULL);
74712 +
74713 +#ifdef CONFIG_PAX_SEGMEXEC
74714 + if (!err && prev_m)
74715 + err = vma_adjust(prev_m, prev_m->vm_start,
74716 + end_m, prev_m->vm_pgoff, NULL);
74717 +#endif
74718 +
74719 + }
74720 if (err)
74721 return NULL;
74722 khugepaged_enter_vma_merge(prev);
74723 @@ -854,12 +919,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
74724 mpol_equal(policy, vma_policy(next)) &&
74725 can_vma_merge_before(next, vm_flags,
74726 anon_vma, file, pgoff+pglen)) {
74727 - if (prev && addr < prev->vm_end) /* case 4 */
74728 + if (prev && addr < prev->vm_end) { /* case 4 */
74729 err = vma_adjust(prev, prev->vm_start,
74730 addr, prev->vm_pgoff, NULL);
74731 - else /* cases 3, 8 */
74732 +
74733 +#ifdef CONFIG_PAX_SEGMEXEC
74734 + if (!err && prev_m)
74735 + err = vma_adjust(prev_m, prev_m->vm_start,
74736 + addr_m, prev_m->vm_pgoff, NULL);
74737 +#endif
74738 +
74739 + } else { /* cases 3, 8 */
74740 err = vma_adjust(area, addr, next->vm_end,
74741 next->vm_pgoff - pglen, NULL);
74742 +
74743 +#ifdef CONFIG_PAX_SEGMEXEC
74744 + if (!err && area_m)
74745 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
74746 + next_m->vm_pgoff - pglen, NULL);
74747 +#endif
74748 +
74749 + }
74750 if (err)
74751 return NULL;
74752 khugepaged_enter_vma_merge(area);
74753 @@ -968,16 +1048,13 @@ none:
74754 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
74755 struct file *file, long pages)
74756 {
74757 - const unsigned long stack_flags
74758 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
74759 -
74760 mm->total_vm += pages;
74761
74762 if (file) {
74763 mm->shared_vm += pages;
74764 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
74765 mm->exec_vm += pages;
74766 - } else if (flags & stack_flags)
74767 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
74768 mm->stack_vm += pages;
74769 }
74770 #endif /* CONFIG_PROC_FS */
74771 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
74772 * (the exception is when the underlying filesystem is noexec
74773 * mounted, in which case we dont add PROT_EXEC.)
74774 */
74775 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74776 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74777 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
74778 prot |= PROT_EXEC;
74779
74780 @@ -1039,7 +1116,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
74781 /* Obtain the address to map to. we verify (or select) it and ensure
74782 * that it represents a valid section of the address space.
74783 */
74784 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
74785 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
74786 if (addr & ~PAGE_MASK)
74787 return addr;
74788
74789 @@ -1050,6 +1127,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
74790 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
74791 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
74792
74793 +#ifdef CONFIG_PAX_MPROTECT
74794 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74795 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74796 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
74797 + gr_log_rwxmmap(file);
74798 +
74799 +#ifdef CONFIG_PAX_EMUPLT
74800 + vm_flags &= ~VM_EXEC;
74801 +#else
74802 + return -EPERM;
74803 +#endif
74804 +
74805 + }
74806 +
74807 + if (!(vm_flags & VM_EXEC))
74808 + vm_flags &= ~VM_MAYEXEC;
74809 +#else
74810 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74811 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74812 +#endif
74813 + else
74814 + vm_flags &= ~VM_MAYWRITE;
74815 + }
74816 +#endif
74817 +
74818 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74819 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
74820 + vm_flags &= ~VM_PAGEEXEC;
74821 +#endif
74822 +
74823 if (flags & MAP_LOCKED)
74824 if (!can_do_mlock())
74825 return -EPERM;
74826 @@ -1061,6 +1168,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
74827 locked += mm->locked_vm;
74828 lock_limit = rlimit(RLIMIT_MEMLOCK);
74829 lock_limit >>= PAGE_SHIFT;
74830 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
74831 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
74832 return -EAGAIN;
74833 }
74834 @@ -1127,6 +1235,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
74835 }
74836 }
74837
74838 + if (!gr_acl_handle_mmap(file, prot))
74839 + return -EACCES;
74840 +
74841 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
74842 }
74843
74844 @@ -1203,7 +1314,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
74845 vm_flags_t vm_flags = vma->vm_flags;
74846
74847 /* If it was private or non-writable, the write bit is already clear */
74848 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
74849 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
74850 return 0;
74851
74852 /* The backer wishes to know when pages are first written to? */
74853 @@ -1252,13 +1363,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
74854 unsigned long charged = 0;
74855 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
74856
74857 +#ifdef CONFIG_PAX_SEGMEXEC
74858 + struct vm_area_struct *vma_m = NULL;
74859 +#endif
74860 +
74861 + /*
74862 + * mm->mmap_sem is required to protect against another thread
74863 + * changing the mappings in case we sleep.
74864 + */
74865 + verify_mm_writelocked(mm);
74866 +
74867 /* Clear old maps */
74868 error = -ENOMEM;
74869 -munmap_back:
74870 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
74871 if (do_munmap(mm, addr, len))
74872 return -ENOMEM;
74873 - goto munmap_back;
74874 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
74875 }
74876
74877 /* Check against address space limit. */
74878 @@ -1307,6 +1427,16 @@ munmap_back:
74879 goto unacct_error;
74880 }
74881
74882 +#ifdef CONFIG_PAX_SEGMEXEC
74883 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
74884 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74885 + if (!vma_m) {
74886 + error = -ENOMEM;
74887 + goto free_vma;
74888 + }
74889 + }
74890 +#endif
74891 +
74892 vma->vm_mm = mm;
74893 vma->vm_start = addr;
74894 vma->vm_end = addr + len;
74895 @@ -1331,6 +1461,13 @@ munmap_back:
74896 if (error)
74897 goto unmap_and_free_vma;
74898
74899 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74900 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
74901 + vma->vm_flags |= VM_PAGEEXEC;
74902 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74903 + }
74904 +#endif
74905 +
74906 /* Can addr have changed??
74907 *
74908 * Answer: Yes, several device drivers can do it in their
74909 @@ -1365,6 +1502,11 @@ munmap_back:
74910 vma_link(mm, vma, prev, rb_link, rb_parent);
74911 file = vma->vm_file;
74912
74913 +#ifdef CONFIG_PAX_SEGMEXEC
74914 + if (vma_m)
74915 + BUG_ON(pax_mirror_vma(vma_m, vma));
74916 +#endif
74917 +
74918 /* Once vma denies write, undo our temporary denial count */
74919 if (correct_wcount)
74920 atomic_inc(&inode->i_writecount);
74921 @@ -1372,6 +1514,7 @@ out:
74922 perf_event_mmap(vma);
74923
74924 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
74925 + track_exec_limit(mm, addr, addr + len, vm_flags);
74926 if (vm_flags & VM_LOCKED) {
74927 if (!mlock_vma_pages_range(vma, addr, addr + len))
74928 mm->locked_vm += (len >> PAGE_SHIFT);
74929 @@ -1393,6 +1536,12 @@ unmap_and_free_vma:
74930 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
74931 charged = 0;
74932 free_vma:
74933 +
74934 +#ifdef CONFIG_PAX_SEGMEXEC
74935 + if (vma_m)
74936 + kmem_cache_free(vm_area_cachep, vma_m);
74937 +#endif
74938 +
74939 kmem_cache_free(vm_area_cachep, vma);
74940 unacct_error:
74941 if (charged)
74942 @@ -1400,6 +1549,44 @@ unacct_error:
74943 return error;
74944 }
74945
74946 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
74947 +{
74948 + if (!vma) {
74949 +#ifdef CONFIG_STACK_GROWSUP
74950 + if (addr > sysctl_heap_stack_gap)
74951 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
74952 + else
74953 + vma = find_vma(current->mm, 0);
74954 + if (vma && (vma->vm_flags & VM_GROWSUP))
74955 + return false;
74956 +#endif
74957 + return true;
74958 + }
74959 +
74960 + if (addr + len > vma->vm_start)
74961 + return false;
74962 +
74963 + if (vma->vm_flags & VM_GROWSDOWN)
74964 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
74965 +#ifdef CONFIG_STACK_GROWSUP
74966 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
74967 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
74968 +#endif
74969 +
74970 + return true;
74971 +}
74972 +
74973 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
74974 +{
74975 + if (vma->vm_start < len)
74976 + return -ENOMEM;
74977 + if (!(vma->vm_flags & VM_GROWSDOWN))
74978 + return vma->vm_start - len;
74979 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
74980 + return vma->vm_start - len - sysctl_heap_stack_gap;
74981 + return -ENOMEM;
74982 +}
74983 +
74984 /* Get an address range which is currently unmapped.
74985 * For shmat() with addr=0.
74986 *
74987 @@ -1426,18 +1613,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
74988 if (flags & MAP_FIXED)
74989 return addr;
74990
74991 +#ifdef CONFIG_PAX_RANDMMAP
74992 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
74993 +#endif
74994 +
74995 if (addr) {
74996 addr = PAGE_ALIGN(addr);
74997 - vma = find_vma(mm, addr);
74998 - if (TASK_SIZE - len >= addr &&
74999 - (!vma || addr + len <= vma->vm_start))
75000 - return addr;
75001 + if (TASK_SIZE - len >= addr) {
75002 + vma = find_vma(mm, addr);
75003 + if (check_heap_stack_gap(vma, addr, len))
75004 + return addr;
75005 + }
75006 }
75007 if (len > mm->cached_hole_size) {
75008 - start_addr = addr = mm->free_area_cache;
75009 + start_addr = addr = mm->free_area_cache;
75010 } else {
75011 - start_addr = addr = TASK_UNMAPPED_BASE;
75012 - mm->cached_hole_size = 0;
75013 + start_addr = addr = mm->mmap_base;
75014 + mm->cached_hole_size = 0;
75015 }
75016
75017 full_search:
75018 @@ -1448,34 +1640,40 @@ full_search:
75019 * Start a new search - just in case we missed
75020 * some holes.
75021 */
75022 - if (start_addr != TASK_UNMAPPED_BASE) {
75023 - addr = TASK_UNMAPPED_BASE;
75024 - start_addr = addr;
75025 + if (start_addr != mm->mmap_base) {
75026 + start_addr = addr = mm->mmap_base;
75027 mm->cached_hole_size = 0;
75028 goto full_search;
75029 }
75030 return -ENOMEM;
75031 }
75032 - if (!vma || addr + len <= vma->vm_start) {
75033 - /*
75034 - * Remember the place where we stopped the search:
75035 - */
75036 - mm->free_area_cache = addr + len;
75037 - return addr;
75038 - }
75039 + if (check_heap_stack_gap(vma, addr, len))
75040 + break;
75041 if (addr + mm->cached_hole_size < vma->vm_start)
75042 mm->cached_hole_size = vma->vm_start - addr;
75043 addr = vma->vm_end;
75044 }
75045 +
75046 + /*
75047 + * Remember the place where we stopped the search:
75048 + */
75049 + mm->free_area_cache = addr + len;
75050 + return addr;
75051 }
75052 #endif
75053
75054 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75055 {
75056 +
75057 +#ifdef CONFIG_PAX_SEGMEXEC
75058 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75059 + return;
75060 +#endif
75061 +
75062 /*
75063 * Is this a new hole at the lowest possible address?
75064 */
75065 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75066 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75067 mm->free_area_cache = addr;
75068 }
75069
75070 @@ -1491,7 +1689,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75071 {
75072 struct vm_area_struct *vma;
75073 struct mm_struct *mm = current->mm;
75074 - unsigned long addr = addr0, start_addr;
75075 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75076
75077 /* requested length too big for entire address space */
75078 if (len > TASK_SIZE)
75079 @@ -1500,13 +1698,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75080 if (flags & MAP_FIXED)
75081 return addr;
75082
75083 +#ifdef CONFIG_PAX_RANDMMAP
75084 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75085 +#endif
75086 +
75087 /* requesting a specific address */
75088 if (addr) {
75089 addr = PAGE_ALIGN(addr);
75090 - vma = find_vma(mm, addr);
75091 - if (TASK_SIZE - len >= addr &&
75092 - (!vma || addr + len <= vma->vm_start))
75093 - return addr;
75094 + if (TASK_SIZE - len >= addr) {
75095 + vma = find_vma(mm, addr);
75096 + if (check_heap_stack_gap(vma, addr, len))
75097 + return addr;
75098 + }
75099 }
75100
75101 /* check if free_area_cache is useful for us */
75102 @@ -1530,7 +1733,7 @@ try_again:
75103 * return with success:
75104 */
75105 vma = find_vma(mm, addr);
75106 - if (!vma || addr+len <= vma->vm_start)
75107 + if (check_heap_stack_gap(vma, addr, len))
75108 /* remember the address as a hint for next time */
75109 return (mm->free_area_cache = addr);
75110
75111 @@ -1539,8 +1742,8 @@ try_again:
75112 mm->cached_hole_size = vma->vm_start - addr;
75113
75114 /* try just below the current vma->vm_start */
75115 - addr = vma->vm_start-len;
75116 - } while (len < vma->vm_start);
75117 + addr = skip_heap_stack_gap(vma, len);
75118 + } while (!IS_ERR_VALUE(addr));
75119
75120 fail:
75121 /*
75122 @@ -1563,13 +1766,21 @@ fail:
75123 * can happen with large stack limits and large mmap()
75124 * allocations.
75125 */
75126 + mm->mmap_base = TASK_UNMAPPED_BASE;
75127 +
75128 +#ifdef CONFIG_PAX_RANDMMAP
75129 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75130 + mm->mmap_base += mm->delta_mmap;
75131 +#endif
75132 +
75133 + mm->free_area_cache = mm->mmap_base;
75134 mm->cached_hole_size = ~0UL;
75135 - mm->free_area_cache = TASK_UNMAPPED_BASE;
75136 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
75137 /*
75138 * Restore the topdown base:
75139 */
75140 - mm->free_area_cache = mm->mmap_base;
75141 + mm->mmap_base = base;
75142 + mm->free_area_cache = base;
75143 mm->cached_hole_size = ~0UL;
75144
75145 return addr;
75146 @@ -1578,6 +1789,12 @@ fail:
75147
75148 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75149 {
75150 +
75151 +#ifdef CONFIG_PAX_SEGMEXEC
75152 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75153 + return;
75154 +#endif
75155 +
75156 /*
75157 * Is this a new hole at the highest possible address?
75158 */
75159 @@ -1585,8 +1802,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75160 mm->free_area_cache = addr;
75161
75162 /* dont allow allocations above current base */
75163 - if (mm->free_area_cache > mm->mmap_base)
75164 + if (mm->free_area_cache > mm->mmap_base) {
75165 mm->free_area_cache = mm->mmap_base;
75166 + mm->cached_hole_size = ~0UL;
75167 + }
75168 }
75169
75170 unsigned long
75171 @@ -1685,6 +1904,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
75172 return vma;
75173 }
75174
75175 +#ifdef CONFIG_PAX_SEGMEXEC
75176 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
75177 +{
75178 + struct vm_area_struct *vma_m;
75179 +
75180 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
75181 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
75182 + BUG_ON(vma->vm_mirror);
75183 + return NULL;
75184 + }
75185 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
75186 + vma_m = vma->vm_mirror;
75187 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
75188 + BUG_ON(vma->vm_file != vma_m->vm_file);
75189 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
75190 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
75191 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
75192 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
75193 + return vma_m;
75194 +}
75195 +#endif
75196 +
75197 /*
75198 * Verify that the stack growth is acceptable and
75199 * update accounting. This is shared with both the
75200 @@ -1701,6 +1942,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75201 return -ENOMEM;
75202
75203 /* Stack limit test */
75204 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
75205 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
75206 return -ENOMEM;
75207
75208 @@ -1711,6 +1953,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75209 locked = mm->locked_vm + grow;
75210 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
75211 limit >>= PAGE_SHIFT;
75212 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75213 if (locked > limit && !capable(CAP_IPC_LOCK))
75214 return -ENOMEM;
75215 }
75216 @@ -1740,37 +1983,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75217 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
75218 * vma is the last one with address > vma->vm_end. Have to extend vma.
75219 */
75220 +#ifndef CONFIG_IA64
75221 +static
75222 +#endif
75223 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75224 {
75225 int error;
75226 + bool locknext;
75227
75228 if (!(vma->vm_flags & VM_GROWSUP))
75229 return -EFAULT;
75230
75231 + /* Also guard against wrapping around to address 0. */
75232 + if (address < PAGE_ALIGN(address+1))
75233 + address = PAGE_ALIGN(address+1);
75234 + else
75235 + return -ENOMEM;
75236 +
75237 /*
75238 * We must make sure the anon_vma is allocated
75239 * so that the anon_vma locking is not a noop.
75240 */
75241 if (unlikely(anon_vma_prepare(vma)))
75242 return -ENOMEM;
75243 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
75244 + if (locknext && anon_vma_prepare(vma->vm_next))
75245 + return -ENOMEM;
75246 vma_lock_anon_vma(vma);
75247 + if (locknext)
75248 + vma_lock_anon_vma(vma->vm_next);
75249
75250 /*
75251 * vma->vm_start/vm_end cannot change under us because the caller
75252 * is required to hold the mmap_sem in read mode. We need the
75253 - * anon_vma lock to serialize against concurrent expand_stacks.
75254 - * Also guard against wrapping around to address 0.
75255 + * anon_vma locks to serialize against concurrent expand_stacks
75256 + * and expand_upwards.
75257 */
75258 - if (address < PAGE_ALIGN(address+4))
75259 - address = PAGE_ALIGN(address+4);
75260 - else {
75261 - vma_unlock_anon_vma(vma);
75262 - return -ENOMEM;
75263 - }
75264 error = 0;
75265
75266 /* Somebody else might have raced and expanded it already */
75267 - if (address > vma->vm_end) {
75268 + 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)
75269 + error = -ENOMEM;
75270 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
75271 unsigned long size, grow;
75272
75273 size = address - vma->vm_start;
75274 @@ -1787,6 +2041,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75275 }
75276 }
75277 }
75278 + if (locknext)
75279 + vma_unlock_anon_vma(vma->vm_next);
75280 vma_unlock_anon_vma(vma);
75281 khugepaged_enter_vma_merge(vma);
75282 validate_mm(vma->vm_mm);
75283 @@ -1801,6 +2057,8 @@ int expand_downwards(struct vm_area_struct *vma,
75284 unsigned long address)
75285 {
75286 int error;
75287 + bool lockprev = false;
75288 + struct vm_area_struct *prev;
75289
75290 /*
75291 * We must make sure the anon_vma is allocated
75292 @@ -1814,6 +2072,15 @@ int expand_downwards(struct vm_area_struct *vma,
75293 if (error)
75294 return error;
75295
75296 + prev = vma->vm_prev;
75297 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
75298 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
75299 +#endif
75300 + if (lockprev && anon_vma_prepare(prev))
75301 + return -ENOMEM;
75302 + if (lockprev)
75303 + vma_lock_anon_vma(prev);
75304 +
75305 vma_lock_anon_vma(vma);
75306
75307 /*
75308 @@ -1823,9 +2090,17 @@ int expand_downwards(struct vm_area_struct *vma,
75309 */
75310
75311 /* Somebody else might have raced and expanded it already */
75312 - if (address < vma->vm_start) {
75313 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
75314 + error = -ENOMEM;
75315 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
75316 unsigned long size, grow;
75317
75318 +#ifdef CONFIG_PAX_SEGMEXEC
75319 + struct vm_area_struct *vma_m;
75320 +
75321 + vma_m = pax_find_mirror_vma(vma);
75322 +#endif
75323 +
75324 size = vma->vm_end - address;
75325 grow = (vma->vm_start - address) >> PAGE_SHIFT;
75326
75327 @@ -1837,6 +2112,17 @@ int expand_downwards(struct vm_area_struct *vma,
75328 vma->vm_start = address;
75329 vma->vm_pgoff -= grow;
75330 anon_vma_interval_tree_post_update_vma(vma);
75331 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
75332 +
75333 +#ifdef CONFIG_PAX_SEGMEXEC
75334 + if (vma_m) {
75335 + anon_vma_interval_tree_pre_update_vma(vma_m);
75336 + vma_m->vm_start -= grow << PAGE_SHIFT;
75337 + vma_m->vm_pgoff -= grow;
75338 + anon_vma_interval_tree_post_update_vma(vma_m);
75339 + }
75340 +#endif
75341 +
75342 perf_event_mmap(vma);
75343 }
75344 }
75345 @@ -1914,6 +2200,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
75346 do {
75347 long nrpages = vma_pages(vma);
75348
75349 +#ifdef CONFIG_PAX_SEGMEXEC
75350 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
75351 + vma = remove_vma(vma);
75352 + continue;
75353 + }
75354 +#endif
75355 +
75356 if (vma->vm_flags & VM_ACCOUNT)
75357 nr_accounted += nrpages;
75358 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
75359 @@ -1959,6 +2252,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
75360 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
75361 vma->vm_prev = NULL;
75362 do {
75363 +
75364 +#ifdef CONFIG_PAX_SEGMEXEC
75365 + if (vma->vm_mirror) {
75366 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
75367 + vma->vm_mirror->vm_mirror = NULL;
75368 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
75369 + vma->vm_mirror = NULL;
75370 + }
75371 +#endif
75372 +
75373 rb_erase(&vma->vm_rb, &mm->mm_rb);
75374 mm->map_count--;
75375 tail_vma = vma;
75376 @@ -1987,14 +2290,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75377 struct vm_area_struct *new;
75378 int err = -ENOMEM;
75379
75380 +#ifdef CONFIG_PAX_SEGMEXEC
75381 + struct vm_area_struct *vma_m, *new_m = NULL;
75382 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
75383 +#endif
75384 +
75385 if (is_vm_hugetlb_page(vma) && (addr &
75386 ~(huge_page_mask(hstate_vma(vma)))))
75387 return -EINVAL;
75388
75389 +#ifdef CONFIG_PAX_SEGMEXEC
75390 + vma_m = pax_find_mirror_vma(vma);
75391 +#endif
75392 +
75393 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75394 if (!new)
75395 goto out_err;
75396
75397 +#ifdef CONFIG_PAX_SEGMEXEC
75398 + if (vma_m) {
75399 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75400 + if (!new_m) {
75401 + kmem_cache_free(vm_area_cachep, new);
75402 + goto out_err;
75403 + }
75404 + }
75405 +#endif
75406 +
75407 /* most fields are the same, copy all, and then fixup */
75408 *new = *vma;
75409
75410 @@ -2007,6 +2329,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75411 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
75412 }
75413
75414 +#ifdef CONFIG_PAX_SEGMEXEC
75415 + if (vma_m) {
75416 + *new_m = *vma_m;
75417 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
75418 + new_m->vm_mirror = new;
75419 + new->vm_mirror = new_m;
75420 +
75421 + if (new_below)
75422 + new_m->vm_end = addr_m;
75423 + else {
75424 + new_m->vm_start = addr_m;
75425 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
75426 + }
75427 + }
75428 +#endif
75429 +
75430 pol = mpol_dup(vma_policy(vma));
75431 if (IS_ERR(pol)) {
75432 err = PTR_ERR(pol);
75433 @@ -2029,6 +2367,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75434 else
75435 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
75436
75437 +#ifdef CONFIG_PAX_SEGMEXEC
75438 + if (!err && vma_m) {
75439 + if (anon_vma_clone(new_m, vma_m))
75440 + goto out_free_mpol;
75441 +
75442 + mpol_get(pol);
75443 + vma_set_policy(new_m, pol);
75444 +
75445 + if (new_m->vm_file)
75446 + get_file(new_m->vm_file);
75447 +
75448 + if (new_m->vm_ops && new_m->vm_ops->open)
75449 + new_m->vm_ops->open(new_m);
75450 +
75451 + if (new_below)
75452 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
75453 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
75454 + else
75455 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
75456 +
75457 + if (err) {
75458 + if (new_m->vm_ops && new_m->vm_ops->close)
75459 + new_m->vm_ops->close(new_m);
75460 + if (new_m->vm_file)
75461 + fput(new_m->vm_file);
75462 + mpol_put(pol);
75463 + }
75464 + }
75465 +#endif
75466 +
75467 /* Success. */
75468 if (!err)
75469 return 0;
75470 @@ -2038,10 +2406,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75471 new->vm_ops->close(new);
75472 if (new->vm_file)
75473 fput(new->vm_file);
75474 - unlink_anon_vmas(new);
75475 out_free_mpol:
75476 mpol_put(pol);
75477 out_free_vma:
75478 +
75479 +#ifdef CONFIG_PAX_SEGMEXEC
75480 + if (new_m) {
75481 + unlink_anon_vmas(new_m);
75482 + kmem_cache_free(vm_area_cachep, new_m);
75483 + }
75484 +#endif
75485 +
75486 + unlink_anon_vmas(new);
75487 kmem_cache_free(vm_area_cachep, new);
75488 out_err:
75489 return err;
75490 @@ -2054,6 +2430,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75491 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
75492 unsigned long addr, int new_below)
75493 {
75494 +
75495 +#ifdef CONFIG_PAX_SEGMEXEC
75496 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75497 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
75498 + if (mm->map_count >= sysctl_max_map_count-1)
75499 + return -ENOMEM;
75500 + } else
75501 +#endif
75502 +
75503 if (mm->map_count >= sysctl_max_map_count)
75504 return -ENOMEM;
75505
75506 @@ -2065,11 +2450,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
75507 * work. This now handles partial unmappings.
75508 * Jeremy Fitzhardinge <jeremy@goop.org>
75509 */
75510 +#ifdef CONFIG_PAX_SEGMEXEC
75511 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75512 {
75513 + int ret = __do_munmap(mm, start, len);
75514 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
75515 + return ret;
75516 +
75517 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
75518 +}
75519 +
75520 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75521 +#else
75522 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75523 +#endif
75524 +{
75525 unsigned long end;
75526 struct vm_area_struct *vma, *prev, *last;
75527
75528 + /*
75529 + * mm->mmap_sem is required to protect against another thread
75530 + * changing the mappings in case we sleep.
75531 + */
75532 + verify_mm_writelocked(mm);
75533 +
75534 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
75535 return -EINVAL;
75536
75537 @@ -2144,6 +2548,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75538 /* Fix up all other VM information */
75539 remove_vma_list(mm, vma);
75540
75541 + track_exec_limit(mm, start, end, 0UL);
75542 +
75543 return 0;
75544 }
75545
75546 @@ -2152,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
75547 int ret;
75548 struct mm_struct *mm = current->mm;
75549
75550 +
75551 +#ifdef CONFIG_PAX_SEGMEXEC
75552 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
75553 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
75554 + return -EINVAL;
75555 +#endif
75556 +
75557 down_write(&mm->mmap_sem);
75558 ret = do_munmap(mm, start, len);
75559 up_write(&mm->mmap_sem);
75560 @@ -2165,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
75561 return vm_munmap(addr, len);
75562 }
75563
75564 -static inline void verify_mm_writelocked(struct mm_struct *mm)
75565 -{
75566 -#ifdef CONFIG_DEBUG_VM
75567 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75568 - WARN_ON(1);
75569 - up_read(&mm->mmap_sem);
75570 - }
75571 -#endif
75572 -}
75573 -
75574 /*
75575 * this is really a simplified "do_mmap". it only handles
75576 * anonymous maps. eventually we may be able to do some
75577 @@ -2188,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
75578 struct rb_node ** rb_link, * rb_parent;
75579 pgoff_t pgoff = addr >> PAGE_SHIFT;
75580 int error;
75581 + unsigned long charged;
75582
75583 len = PAGE_ALIGN(len);
75584 if (!len)
75585 @@ -2195,16 +2599,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
75586
75587 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
75588
75589 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
75590 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
75591 + flags &= ~VM_EXEC;
75592 +
75593 +#ifdef CONFIG_PAX_MPROTECT
75594 + if (mm->pax_flags & MF_PAX_MPROTECT)
75595 + flags &= ~VM_MAYEXEC;
75596 +#endif
75597 +
75598 + }
75599 +#endif
75600 +
75601 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
75602 if (error & ~PAGE_MASK)
75603 return error;
75604
75605 + charged = len >> PAGE_SHIFT;
75606 +
75607 /*
75608 * mlock MCL_FUTURE?
75609 */
75610 if (mm->def_flags & VM_LOCKED) {
75611 unsigned long locked, lock_limit;
75612 - locked = len >> PAGE_SHIFT;
75613 + locked = charged;
75614 locked += mm->locked_vm;
75615 lock_limit = rlimit(RLIMIT_MEMLOCK);
75616 lock_limit >>= PAGE_SHIFT;
75617 @@ -2221,21 +2639,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
75618 /*
75619 * Clear old maps. this also does some error checking for us
75620 */
75621 - munmap_back:
75622 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75623 if (do_munmap(mm, addr, len))
75624 return -ENOMEM;
75625 - goto munmap_back;
75626 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75627 }
75628
75629 /* Check against address space limits *after* clearing old maps... */
75630 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
75631 + if (!may_expand_vm(mm, charged))
75632 return -ENOMEM;
75633
75634 if (mm->map_count > sysctl_max_map_count)
75635 return -ENOMEM;
75636
75637 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
75638 + if (security_vm_enough_memory_mm(mm, charged))
75639 return -ENOMEM;
75640
75641 /* Can we just expand an old private anonymous mapping? */
75642 @@ -2249,7 +2666,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
75643 */
75644 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75645 if (!vma) {
75646 - vm_unacct_memory(len >> PAGE_SHIFT);
75647 + vm_unacct_memory(charged);
75648 return -ENOMEM;
75649 }
75650
75651 @@ -2263,11 +2680,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
75652 vma_link(mm, vma, prev, rb_link, rb_parent);
75653 out:
75654 perf_event_mmap(vma);
75655 - mm->total_vm += len >> PAGE_SHIFT;
75656 + mm->total_vm += charged;
75657 if (flags & VM_LOCKED) {
75658 if (!mlock_vma_pages_range(vma, addr, addr + len))
75659 - mm->locked_vm += (len >> PAGE_SHIFT);
75660 + mm->locked_vm += charged;
75661 }
75662 + track_exec_limit(mm, addr, addr + len, flags);
75663 return addr;
75664 }
75665
75666 @@ -2325,6 +2743,7 @@ void exit_mmap(struct mm_struct *mm)
75667 while (vma) {
75668 if (vma->vm_flags & VM_ACCOUNT)
75669 nr_accounted += vma_pages(vma);
75670 + vma->vm_mirror = NULL;
75671 vma = remove_vma(vma);
75672 }
75673 vm_unacct_memory(nr_accounted);
75674 @@ -2341,6 +2760,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
75675 struct vm_area_struct *prev;
75676 struct rb_node **rb_link, *rb_parent;
75677
75678 +#ifdef CONFIG_PAX_SEGMEXEC
75679 + struct vm_area_struct *vma_m = NULL;
75680 +#endif
75681 +
75682 + if (security_mmap_addr(vma->vm_start))
75683 + return -EPERM;
75684 +
75685 /*
75686 * The vm_pgoff of a purely anonymous vma should be irrelevant
75687 * until its first write fault, when page's anon_vma and index
75688 @@ -2364,7 +2790,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
75689 security_vm_enough_memory_mm(mm, vma_pages(vma)))
75690 return -ENOMEM;
75691
75692 +#ifdef CONFIG_PAX_SEGMEXEC
75693 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
75694 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75695 + if (!vma_m)
75696 + return -ENOMEM;
75697 + }
75698 +#endif
75699 +
75700 vma_link(mm, vma, prev, rb_link, rb_parent);
75701 +
75702 +#ifdef CONFIG_PAX_SEGMEXEC
75703 + if (vma_m)
75704 + BUG_ON(pax_mirror_vma(vma_m, vma));
75705 +#endif
75706 +
75707 return 0;
75708 }
75709
75710 @@ -2384,6 +2824,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
75711 struct mempolicy *pol;
75712 bool faulted_in_anon_vma = true;
75713
75714 + BUG_ON(vma->vm_mirror);
75715 +
75716 /*
75717 * If anonymous vma has not yet been faulted, update new pgoff
75718 * to match new location, to increase its chance of merging.
75719 @@ -2450,6 +2892,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
75720 return NULL;
75721 }
75722
75723 +#ifdef CONFIG_PAX_SEGMEXEC
75724 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
75725 +{
75726 + struct vm_area_struct *prev_m;
75727 + struct rb_node **rb_link_m, *rb_parent_m;
75728 + struct mempolicy *pol_m;
75729 +
75730 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
75731 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
75732 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
75733 + *vma_m = *vma;
75734 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
75735 + if (anon_vma_clone(vma_m, vma))
75736 + return -ENOMEM;
75737 + pol_m = vma_policy(vma_m);
75738 + mpol_get(pol_m);
75739 + vma_set_policy(vma_m, pol_m);
75740 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
75741 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
75742 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
75743 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
75744 + if (vma_m->vm_file)
75745 + get_file(vma_m->vm_file);
75746 + if (vma_m->vm_ops && vma_m->vm_ops->open)
75747 + vma_m->vm_ops->open(vma_m);
75748 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
75749 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
75750 + vma_m->vm_mirror = vma;
75751 + vma->vm_mirror = vma_m;
75752 + return 0;
75753 +}
75754 +#endif
75755 +
75756 /*
75757 * Return true if the calling process may expand its vm space by the passed
75758 * number of pages
75759 @@ -2461,6 +2936,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
75760
75761 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
75762
75763 +#ifdef CONFIG_PAX_RANDMMAP
75764 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75765 + cur -= mm->brk_gap;
75766 +#endif
75767 +
75768 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
75769 if (cur + npages > lim)
75770 return 0;
75771 return 1;
75772 @@ -2531,6 +3012,22 @@ int install_special_mapping(struct mm_struct *mm,
75773 vma->vm_start = addr;
75774 vma->vm_end = addr + len;
75775
75776 +#ifdef CONFIG_PAX_MPROTECT
75777 + if (mm->pax_flags & MF_PAX_MPROTECT) {
75778 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
75779 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
75780 + return -EPERM;
75781 + if (!(vm_flags & VM_EXEC))
75782 + vm_flags &= ~VM_MAYEXEC;
75783 +#else
75784 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75785 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75786 +#endif
75787 + else
75788 + vm_flags &= ~VM_MAYWRITE;
75789 + }
75790 +#endif
75791 +
75792 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
75793 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75794
75795 diff --git a/mm/mprotect.c b/mm/mprotect.c
75796 index a409926..8b32e6d 100644
75797 --- a/mm/mprotect.c
75798 +++ b/mm/mprotect.c
75799 @@ -23,10 +23,17 @@
75800 #include <linux/mmu_notifier.h>
75801 #include <linux/migrate.h>
75802 #include <linux/perf_event.h>
75803 +
75804 +#ifdef CONFIG_PAX_MPROTECT
75805 +#include <linux/elf.h>
75806 +#include <linux/binfmts.h>
75807 +#endif
75808 +
75809 #include <asm/uaccess.h>
75810 #include <asm/pgtable.h>
75811 #include <asm/cacheflush.h>
75812 #include <asm/tlbflush.h>
75813 +#include <asm/mmu_context.h>
75814
75815 #ifndef pgprot_modify
75816 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
75817 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
75818 flush_tlb_range(vma, start, end);
75819 }
75820
75821 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75822 +/* called while holding the mmap semaphor for writing except stack expansion */
75823 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
75824 +{
75825 + unsigned long oldlimit, newlimit = 0UL;
75826 +
75827 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
75828 + return;
75829 +
75830 + spin_lock(&mm->page_table_lock);
75831 + oldlimit = mm->context.user_cs_limit;
75832 + if ((prot & VM_EXEC) && oldlimit < end)
75833 + /* USER_CS limit moved up */
75834 + newlimit = end;
75835 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
75836 + /* USER_CS limit moved down */
75837 + newlimit = start;
75838 +
75839 + if (newlimit) {
75840 + mm->context.user_cs_limit = newlimit;
75841 +
75842 +#ifdef CONFIG_SMP
75843 + wmb();
75844 + cpus_clear(mm->context.cpu_user_cs_mask);
75845 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
75846 +#endif
75847 +
75848 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
75849 + }
75850 + spin_unlock(&mm->page_table_lock);
75851 + if (newlimit == end) {
75852 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
75853 +
75854 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
75855 + if (is_vm_hugetlb_page(vma))
75856 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
75857 + else
75858 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
75859 + }
75860 +}
75861 +#endif
75862 +
75863 int
75864 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
75865 unsigned long start, unsigned long end, unsigned long newflags)
75866 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
75867 int error;
75868 int dirty_accountable = 0;
75869
75870 +#ifdef CONFIG_PAX_SEGMEXEC
75871 + struct vm_area_struct *vma_m = NULL;
75872 + unsigned long start_m, end_m;
75873 +
75874 + start_m = start + SEGMEXEC_TASK_SIZE;
75875 + end_m = end + SEGMEXEC_TASK_SIZE;
75876 +#endif
75877 +
75878 if (newflags == oldflags) {
75879 *pprev = vma;
75880 return 0;
75881 }
75882
75883 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
75884 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
75885 +
75886 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
75887 + return -ENOMEM;
75888 +
75889 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
75890 + return -ENOMEM;
75891 + }
75892 +
75893 /*
75894 * If we make a private mapping writable we increase our commit;
75895 * but (without finer accounting) cannot reduce our commit if we
75896 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
75897 }
75898 }
75899
75900 +#ifdef CONFIG_PAX_SEGMEXEC
75901 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
75902 + if (start != vma->vm_start) {
75903 + error = split_vma(mm, vma, start, 1);
75904 + if (error)
75905 + goto fail;
75906 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
75907 + *pprev = (*pprev)->vm_next;
75908 + }
75909 +
75910 + if (end != vma->vm_end) {
75911 + error = split_vma(mm, vma, end, 0);
75912 + if (error)
75913 + goto fail;
75914 + }
75915 +
75916 + if (pax_find_mirror_vma(vma)) {
75917 + error = __do_munmap(mm, start_m, end_m - start_m);
75918 + if (error)
75919 + goto fail;
75920 + } else {
75921 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75922 + if (!vma_m) {
75923 + error = -ENOMEM;
75924 + goto fail;
75925 + }
75926 + vma->vm_flags = newflags;
75927 + error = pax_mirror_vma(vma_m, vma);
75928 + if (error) {
75929 + vma->vm_flags = oldflags;
75930 + goto fail;
75931 + }
75932 + }
75933 + }
75934 +#endif
75935 +
75936 /*
75937 * First try to merge with previous and/or next vma.
75938 */
75939 @@ -204,9 +307,21 @@ success:
75940 * vm_flags and vm_page_prot are protected by the mmap_sem
75941 * held in write mode.
75942 */
75943 +
75944 +#ifdef CONFIG_PAX_SEGMEXEC
75945 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
75946 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
75947 +#endif
75948 +
75949 vma->vm_flags = newflags;
75950 +
75951 +#ifdef CONFIG_PAX_MPROTECT
75952 + if (mm->binfmt && mm->binfmt->handle_mprotect)
75953 + mm->binfmt->handle_mprotect(vma, newflags);
75954 +#endif
75955 +
75956 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
75957 - vm_get_page_prot(newflags));
75958 + vm_get_page_prot(vma->vm_flags));
75959
75960 if (vma_wants_writenotify(vma)) {
75961 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
75962 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
75963 end = start + len;
75964 if (end <= start)
75965 return -ENOMEM;
75966 +
75967 +#ifdef CONFIG_PAX_SEGMEXEC
75968 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75969 + if (end > SEGMEXEC_TASK_SIZE)
75970 + return -EINVAL;
75971 + } else
75972 +#endif
75973 +
75974 + if (end > TASK_SIZE)
75975 + return -EINVAL;
75976 +
75977 if (!arch_validate_prot(prot))
75978 return -EINVAL;
75979
75980 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
75981 /*
75982 * Does the application expect PROT_READ to imply PROT_EXEC:
75983 */
75984 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75985 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75986 prot |= PROT_EXEC;
75987
75988 vm_flags = calc_vm_prot_bits(prot);
75989 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
75990 if (start > vma->vm_start)
75991 prev = vma;
75992
75993 +#ifdef CONFIG_PAX_MPROTECT
75994 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
75995 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
75996 +#endif
75997 +
75998 for (nstart = start ; ; ) {
75999 unsigned long newflags;
76000
76001 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76002
76003 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76004 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76005 + if (prot & (PROT_WRITE | PROT_EXEC))
76006 + gr_log_rwxmprotect(vma->vm_file);
76007 +
76008 + error = -EACCES;
76009 + goto out;
76010 + }
76011 +
76012 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76013 error = -EACCES;
76014 goto out;
76015 }
76016 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76017 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76018 if (error)
76019 goto out;
76020 +
76021 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
76022 +
76023 nstart = tmp;
76024
76025 if (nstart < prev->vm_end)
76026 diff --git a/mm/mremap.c b/mm/mremap.c
76027 index 1b61c2d..1cc0e3c 100644
76028 --- a/mm/mremap.c
76029 +++ b/mm/mremap.c
76030 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76031 continue;
76032 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76033 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76034 +
76035 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76036 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76037 + pte = pte_exprotect(pte);
76038 +#endif
76039 +
76040 set_pte_at(mm, new_addr, new_pte, pte);
76041 }
76042
76043 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76044 if (is_vm_hugetlb_page(vma))
76045 goto Einval;
76046
76047 +#ifdef CONFIG_PAX_SEGMEXEC
76048 + if (pax_find_mirror_vma(vma))
76049 + goto Einval;
76050 +#endif
76051 +
76052 /* We can't remap across vm area boundaries */
76053 if (old_len > vma->vm_end - addr)
76054 goto Efault;
76055 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76056 unsigned long ret = -EINVAL;
76057 unsigned long charged = 0;
76058 unsigned long map_flags;
76059 + unsigned long pax_task_size = TASK_SIZE;
76060
76061 if (new_addr & ~PAGE_MASK)
76062 goto out;
76063
76064 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76065 +#ifdef CONFIG_PAX_SEGMEXEC
76066 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76067 + pax_task_size = SEGMEXEC_TASK_SIZE;
76068 +#endif
76069 +
76070 + pax_task_size -= PAGE_SIZE;
76071 +
76072 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76073 goto out;
76074
76075 /* Check if the location we're moving into overlaps the
76076 * old location at all, and fail if it does.
76077 */
76078 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
76079 - goto out;
76080 -
76081 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
76082 + if (addr + old_len > new_addr && new_addr + new_len > addr)
76083 goto out;
76084
76085 ret = do_munmap(mm, new_addr, new_len);
76086 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76087 struct vm_area_struct *vma;
76088 unsigned long ret = -EINVAL;
76089 unsigned long charged = 0;
76090 + unsigned long pax_task_size = TASK_SIZE;
76091
76092 down_write(&current->mm->mmap_sem);
76093
76094 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76095 if (!new_len)
76096 goto out;
76097
76098 +#ifdef CONFIG_PAX_SEGMEXEC
76099 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76100 + pax_task_size = SEGMEXEC_TASK_SIZE;
76101 +#endif
76102 +
76103 + pax_task_size -= PAGE_SIZE;
76104 +
76105 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
76106 + old_len > pax_task_size || addr > pax_task_size-old_len)
76107 + goto out;
76108 +
76109 if (flags & MREMAP_FIXED) {
76110 if (flags & MREMAP_MAYMOVE)
76111 ret = mremap_to(addr, old_len, new_addr, new_len);
76112 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76113 addr + new_len);
76114 }
76115 ret = addr;
76116 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
76117 goto out;
76118 }
76119 }
76120 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76121 goto out;
76122 }
76123
76124 + map_flags = vma->vm_flags;
76125 ret = move_vma(vma, addr, old_len, new_len, new_addr);
76126 + if (!(ret & ~PAGE_MASK)) {
76127 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
76128 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
76129 + }
76130 }
76131 out:
76132 if (ret & ~PAGE_MASK)
76133 diff --git a/mm/nommu.c b/mm/nommu.c
76134 index 45131b4..c521665 100644
76135 --- a/mm/nommu.c
76136 +++ b/mm/nommu.c
76137 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76138 int sysctl_overcommit_ratio = 50; /* default is 50% */
76139 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
76140 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
76141 -int heap_stack_gap = 0;
76142
76143 atomic_long_t mmap_pages_allocated;
76144
76145 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
76146 EXPORT_SYMBOL(find_vma);
76147
76148 /*
76149 - * find a VMA
76150 - * - we don't extend stack VMAs under NOMMU conditions
76151 - */
76152 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
76153 -{
76154 - return find_vma(mm, addr);
76155 -}
76156 -
76157 -/*
76158 * expand a stack to a given address
76159 * - not supported under NOMMU conditions
76160 */
76161 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76162
76163 /* most fields are the same, copy all, and then fixup */
76164 *new = *vma;
76165 + INIT_LIST_HEAD(&new->anon_vma_chain);
76166 *region = *vma->vm_region;
76167 new->vm_region = region;
76168
76169 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
76170 index ceb4168..d7774f2 100644
76171 --- a/mm/page_alloc.c
76172 +++ b/mm/page_alloc.c
76173 @@ -340,7 +340,7 @@ out:
76174 * This usage means that zero-order pages may not be compound.
76175 */
76176
76177 -static void free_compound_page(struct page *page)
76178 +void free_compound_page(struct page *page)
76179 {
76180 __free_pages_ok(page, compound_order(page));
76181 }
76182 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76183 int i;
76184 int bad = 0;
76185
76186 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
76187 + unsigned long index = 1UL << order;
76188 +#endif
76189 +
76190 trace_mm_page_free(page, order);
76191 kmemcheck_free_shadow(page, order);
76192
76193 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76194 debug_check_no_obj_freed(page_address(page),
76195 PAGE_SIZE << order);
76196 }
76197 +
76198 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
76199 + for (; index; --index)
76200 + sanitize_highpage(page + index - 1);
76201 +#endif
76202 +
76203 arch_free_page(page, order);
76204 kernel_map_pages(page, 1 << order, 0);
76205
76206 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
76207 arch_alloc_page(page, order);
76208 kernel_map_pages(page, 1 << order, 1);
76209
76210 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
76211 if (gfp_flags & __GFP_ZERO)
76212 prep_zero_page(page, order, gfp_flags);
76213 +#endif
76214
76215 if (order && (gfp_flags & __GFP_COMP))
76216 prep_compound_page(page, order);
76217 @@ -3684,7 +3696,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
76218 unsigned long pfn;
76219
76220 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
76221 +#ifdef CONFIG_X86_32
76222 + /* boot failures in VMware 8 on 32bit vanilla since
76223 + this change */
76224 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
76225 +#else
76226 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
76227 +#endif
76228 return 1;
76229 }
76230 return 0;
76231 diff --git a/mm/percpu.c b/mm/percpu.c
76232 index ddc5efb..f632d2c 100644
76233 --- a/mm/percpu.c
76234 +++ b/mm/percpu.c
76235 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
76236 static unsigned int pcpu_high_unit_cpu __read_mostly;
76237
76238 /* the address of the first chunk which starts with the kernel static area */
76239 -void *pcpu_base_addr __read_mostly;
76240 +void *pcpu_base_addr __read_only;
76241 EXPORT_SYMBOL_GPL(pcpu_base_addr);
76242
76243 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
76244 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
76245 index 926b466..b23df53 100644
76246 --- a/mm/process_vm_access.c
76247 +++ b/mm/process_vm_access.c
76248 @@ -13,6 +13,7 @@
76249 #include <linux/uio.h>
76250 #include <linux/sched.h>
76251 #include <linux/highmem.h>
76252 +#include <linux/security.h>
76253 #include <linux/ptrace.h>
76254 #include <linux/slab.h>
76255 #include <linux/syscalls.h>
76256 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76257 size_t iov_l_curr_offset = 0;
76258 ssize_t iov_len;
76259
76260 + return -ENOSYS; // PaX: until properly audited
76261 +
76262 /*
76263 * Work out how many pages of struct pages we're going to need
76264 * when eventually calling get_user_pages
76265 */
76266 for (i = 0; i < riovcnt; i++) {
76267 iov_len = rvec[i].iov_len;
76268 - if (iov_len > 0) {
76269 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
76270 - + iov_len)
76271 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
76272 - / PAGE_SIZE + 1;
76273 - nr_pages = max(nr_pages, nr_pages_iov);
76274 - }
76275 + if (iov_len <= 0)
76276 + continue;
76277 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
76278 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
76279 + nr_pages = max(nr_pages, nr_pages_iov);
76280 }
76281
76282 if (nr_pages == 0)
76283 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76284 goto free_proc_pages;
76285 }
76286
76287 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
76288 + rc = -EPERM;
76289 + goto put_task_struct;
76290 + }
76291 +
76292 mm = mm_access(task, PTRACE_MODE_ATTACH);
76293 if (!mm || IS_ERR(mm)) {
76294 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
76295 diff --git a/mm/rmap.c b/mm/rmap.c
76296 index 2ee1ef0..2e175ba 100644
76297 --- a/mm/rmap.c
76298 +++ b/mm/rmap.c
76299 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76300 struct anon_vma *anon_vma = vma->anon_vma;
76301 struct anon_vma_chain *avc;
76302
76303 +#ifdef CONFIG_PAX_SEGMEXEC
76304 + struct anon_vma_chain *avc_m = NULL;
76305 +#endif
76306 +
76307 might_sleep();
76308 if (unlikely(!anon_vma)) {
76309 struct mm_struct *mm = vma->vm_mm;
76310 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76311 if (!avc)
76312 goto out_enomem;
76313
76314 +#ifdef CONFIG_PAX_SEGMEXEC
76315 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
76316 + if (!avc_m)
76317 + goto out_enomem_free_avc;
76318 +#endif
76319 +
76320 anon_vma = find_mergeable_anon_vma(vma);
76321 allocated = NULL;
76322 if (!anon_vma) {
76323 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76324 /* page_table_lock to protect against threads */
76325 spin_lock(&mm->page_table_lock);
76326 if (likely(!vma->anon_vma)) {
76327 +
76328 +#ifdef CONFIG_PAX_SEGMEXEC
76329 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
76330 +
76331 + if (vma_m) {
76332 + BUG_ON(vma_m->anon_vma);
76333 + vma_m->anon_vma = anon_vma;
76334 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
76335 + avc_m = NULL;
76336 + }
76337 +#endif
76338 +
76339 vma->anon_vma = anon_vma;
76340 anon_vma_chain_link(vma, avc, anon_vma);
76341 allocated = NULL;
76342 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76343
76344 if (unlikely(allocated))
76345 put_anon_vma(allocated);
76346 +
76347 +#ifdef CONFIG_PAX_SEGMEXEC
76348 + if (unlikely(avc_m))
76349 + anon_vma_chain_free(avc_m);
76350 +#endif
76351 +
76352 if (unlikely(avc))
76353 anon_vma_chain_free(avc);
76354 }
76355 return 0;
76356
76357 out_enomem_free_avc:
76358 +
76359 +#ifdef CONFIG_PAX_SEGMEXEC
76360 + if (avc_m)
76361 + anon_vma_chain_free(avc_m);
76362 +#endif
76363 +
76364 anon_vma_chain_free(avc);
76365 out_enomem:
76366 return -ENOMEM;
76367 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
76368 * Attach the anon_vmas from src to dst.
76369 * Returns 0 on success, -ENOMEM on failure.
76370 */
76371 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
76372 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
76373 {
76374 struct anon_vma_chain *avc, *pavc;
76375 struct anon_vma *root = NULL;
76376 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
76377 * the corresponding VMA in the parent process is attached to.
76378 * Returns 0 on success, non-zero on failure.
76379 */
76380 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
76381 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
76382 {
76383 struct anon_vma_chain *avc;
76384 struct anon_vma *anon_vma;
76385 diff --git a/mm/shmem.c b/mm/shmem.c
76386 index 50c5b8f..0bc87f7 100644
76387 --- a/mm/shmem.c
76388 +++ b/mm/shmem.c
76389 @@ -31,7 +31,7 @@
76390 #include <linux/export.h>
76391 #include <linux/swap.h>
76392
76393 -static struct vfsmount *shm_mnt;
76394 +struct vfsmount *shm_mnt;
76395
76396 #ifdef CONFIG_SHMEM
76397 /*
76398 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
76399 #define BOGO_DIRENT_SIZE 20
76400
76401 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
76402 -#define SHORT_SYMLINK_LEN 128
76403 +#define SHORT_SYMLINK_LEN 64
76404
76405 /*
76406 * shmem_fallocate and shmem_writepage communicate via inode->i_private
76407 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
76408 static int shmem_xattr_validate(const char *name)
76409 {
76410 struct { const char *prefix; size_t len; } arr[] = {
76411 +
76412 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
76413 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
76414 +#endif
76415 +
76416 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
76417 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
76418 };
76419 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
76420 if (err)
76421 return err;
76422
76423 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
76424 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
76425 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
76426 + return -EOPNOTSUPP;
76427 + if (size > 8)
76428 + return -EINVAL;
76429 + }
76430 +#endif
76431 +
76432 return simple_xattr_set(&info->xattrs, name, value, size, flags);
76433 }
76434
76435 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
76436 int err = -ENOMEM;
76437
76438 /* Round up to L1_CACHE_BYTES to resist false sharing */
76439 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
76440 - L1_CACHE_BYTES), GFP_KERNEL);
76441 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
76442 if (!sbinfo)
76443 return -ENOMEM;
76444
76445 diff --git a/mm/slab.c b/mm/slab.c
76446 index 33d3363..93c6810 100644
76447 --- a/mm/slab.c
76448 +++ b/mm/slab.c
76449 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
76450
76451 /* Legal flag mask for kmem_cache_create(). */
76452 #if DEBUG
76453 -# define CREATE_MASK (SLAB_RED_ZONE | \
76454 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
76455 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
76456 SLAB_CACHE_DMA | \
76457 SLAB_STORE_USER | \
76458 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
76459 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
76460 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
76461 #else
76462 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
76463 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
76464 SLAB_CACHE_DMA | \
76465 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
76466 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
76467 @@ -322,7 +322,7 @@ struct kmem_list3 {
76468 * Need this for bootstrapping a per node allocator.
76469 */
76470 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
76471 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
76472 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
76473 #define CACHE_CACHE 0
76474 #define SIZE_AC MAX_NUMNODES
76475 #define SIZE_L3 (2 * MAX_NUMNODES)
76476 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
76477 if ((x)->max_freeable < i) \
76478 (x)->max_freeable = i; \
76479 } while (0)
76480 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
76481 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
76482 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
76483 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
76484 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
76485 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
76486 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
76487 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
76488 #else
76489 #define STATS_INC_ACTIVE(x) do { } while (0)
76490 #define STATS_DEC_ACTIVE(x) do { } while (0)
76491 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
76492 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
76493 */
76494 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
76495 - const struct slab *slab, void *obj)
76496 + const struct slab *slab, const void *obj)
76497 {
76498 u32 offset = (obj - slab->s_mem);
76499 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
76500 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
76501 struct cache_names {
76502 char *name;
76503 char *name_dma;
76504 + char *name_usercopy;
76505 };
76506
76507 static struct cache_names __initdata cache_names[] = {
76508 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
76509 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
76510 #include <linux/kmalloc_sizes.h>
76511 - {NULL,}
76512 + {NULL}
76513 #undef CACHE
76514 };
76515
76516 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
76517 if (unlikely(gfpflags & GFP_DMA))
76518 return csizep->cs_dmacachep;
76519 #endif
76520 +
76521 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76522 + if (unlikely(gfpflags & GFP_USERCOPY))
76523 + return csizep->cs_usercopycachep;
76524 +#endif
76525 +
76526 return csizep->cs_cachep;
76527 }
76528
76529 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
76530 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
76531 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
76532 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
76533 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
76534 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
76535 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
76536
76537 if (INDEX_AC != INDEX_L3) {
76538 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
76539 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
76540 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
76541 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
76542 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
76543 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
76544 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
76545 }
76546
76547 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
76548 sizes->cs_cachep->size = sizes->cs_size;
76549 sizes->cs_cachep->object_size = sizes->cs_size;
76550 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
76551 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
76552 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
76553 list_add(&sizes->cs_cachep->list, &slab_caches);
76554 }
76555 #ifdef CONFIG_ZONE_DMA
76556 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
76557 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
76558 list_add(&sizes->cs_dmacachep->list, &slab_caches);
76559 #endif
76560 +
76561 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76562 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
76563 + sizes->cs_usercopycachep->name = names->name_dma;
76564 + sizes->cs_usercopycachep->size = sizes->cs_size;
76565 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
76566 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
76567 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
76568 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
76569 +#endif
76570 +
76571 sizes++;
76572 names++;
76573 }
76574 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
76575 }
76576 /* cpu stats */
76577 {
76578 - unsigned long allochit = atomic_read(&cachep->allochit);
76579 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
76580 - unsigned long freehit = atomic_read(&cachep->freehit);
76581 - unsigned long freemiss = atomic_read(&cachep->freemiss);
76582 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
76583 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
76584 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
76585 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
76586
76587 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
76588 allochit, allocmiss, freehit, freemiss);
76589 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
76590 {
76591 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
76592 #ifdef CONFIG_DEBUG_SLAB_LEAK
76593 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
76594 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
76595 #endif
76596 return 0;
76597 }
76598 module_init(slab_proc_init);
76599 #endif
76600
76601 +bool is_usercopy_object(const void *ptr)
76602 +{
76603 + struct page *page;
76604 + struct kmem_cache *cachep;
76605 +
76606 + if (ZERO_OR_NULL_PTR(ptr))
76607 + return false;
76608 +
76609 + if (!slab_is_available())
76610 + return false;
76611 +
76612 + if (!virt_addr_valid(ptr))
76613 + return false;
76614 +
76615 + page = virt_to_head_page(ptr);
76616 +
76617 + if (!PageSlab(page))
76618 + return false;
76619 +
76620 + cachep = page->slab_cache;
76621 + return cachep->flags & SLAB_USERCOPY;
76622 +}
76623 +
76624 +#ifdef CONFIG_PAX_USERCOPY
76625 +const char *check_heap_object(const void *ptr, unsigned long n)
76626 +{
76627 + struct page *page;
76628 + struct kmem_cache *cachep;
76629 + struct slab *slabp;
76630 + unsigned int objnr;
76631 + unsigned long offset;
76632 +
76633 + if (ZERO_OR_NULL_PTR(ptr))
76634 + return "<null>";
76635 +
76636 + if (!virt_addr_valid(ptr))
76637 + return NULL;
76638 +
76639 + page = virt_to_head_page(ptr);
76640 +
76641 + if (!PageSlab(page))
76642 + return NULL;
76643 +
76644 + cachep = page->slab_cache;
76645 + if (!(cachep->flags & SLAB_USERCOPY))
76646 + return cachep->name;
76647 +
76648 + slabp = page->slab_page;
76649 + objnr = obj_to_index(cachep, slabp, ptr);
76650 + BUG_ON(objnr >= cachep->num);
76651 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
76652 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
76653 + return NULL;
76654 +
76655 + return cachep->name;
76656 +}
76657 +#endif
76658 +
76659 /**
76660 * ksize - get the actual amount of memory allocated for a given object
76661 * @objp: Pointer to the object
76662 diff --git a/mm/slab_common.c b/mm/slab_common.c
76663 index 069a24e6..226a310 100644
76664 --- a/mm/slab_common.c
76665 +++ b/mm/slab_common.c
76666 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
76667 err = __kmem_cache_create(s, flags);
76668 if (!err) {
76669
76670 - s->refcount = 1;
76671 + atomic_set(&s->refcount, 1);
76672 list_add(&s->list, &slab_caches);
76673
76674 } else {
76675 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
76676 {
76677 get_online_cpus();
76678 mutex_lock(&slab_mutex);
76679 - s->refcount--;
76680 - if (!s->refcount) {
76681 + if (atomic_dec_and_test(&s->refcount)) {
76682 list_del(&s->list);
76683
76684 if (!__kmem_cache_shutdown(s)) {
76685 diff --git a/mm/slob.c b/mm/slob.c
76686 index 1e921c5..1ce12c2 100644
76687 --- a/mm/slob.c
76688 +++ b/mm/slob.c
76689 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
76690 /*
76691 * Return the size of a slob block.
76692 */
76693 -static slobidx_t slob_units(slob_t *s)
76694 +static slobidx_t slob_units(const slob_t *s)
76695 {
76696 if (s->units > 0)
76697 return s->units;
76698 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
76699 /*
76700 * Return the next free slob block pointer after this one.
76701 */
76702 -static slob_t *slob_next(slob_t *s)
76703 +static slob_t *slob_next(const slob_t *s)
76704 {
76705 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
76706 slobidx_t next;
76707 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
76708 /*
76709 * Returns true if s is the last free block in its page.
76710 */
76711 -static int slob_last(slob_t *s)
76712 +static int slob_last(const slob_t *s)
76713 {
76714 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
76715 }
76716
76717 -static void *slob_new_pages(gfp_t gfp, int order, int node)
76718 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
76719 {
76720 - void *page;
76721 + struct page *page;
76722
76723 #ifdef CONFIG_NUMA
76724 if (node != NUMA_NO_NODE)
76725 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
76726 if (!page)
76727 return NULL;
76728
76729 - return page_address(page);
76730 + __SetPageSlab(page);
76731 + return page;
76732 }
76733
76734 -static void slob_free_pages(void *b, int order)
76735 +static void slob_free_pages(struct page *sp, int order)
76736 {
76737 if (current->reclaim_state)
76738 current->reclaim_state->reclaimed_slab += 1 << order;
76739 - free_pages((unsigned long)b, order);
76740 + __ClearPageSlab(sp);
76741 + reset_page_mapcount(sp);
76742 + sp->private = 0;
76743 + __free_pages(sp, order);
76744 }
76745
76746 /*
76747 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
76748
76749 /* Not enough space: must allocate a new page */
76750 if (!b) {
76751 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
76752 - if (!b)
76753 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
76754 + if (!sp)
76755 return NULL;
76756 - sp = virt_to_page(b);
76757 - __SetPageSlab(sp);
76758 + b = page_address(sp);
76759
76760 spin_lock_irqsave(&slob_lock, flags);
76761 sp->units = SLOB_UNITS(PAGE_SIZE);
76762 sp->freelist = b;
76763 + sp->private = 0;
76764 INIT_LIST_HEAD(&sp->list);
76765 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
76766 set_slob_page_free(sp, slob_list);
76767 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
76768 if (slob_page_free(sp))
76769 clear_slob_page_free(sp);
76770 spin_unlock_irqrestore(&slob_lock, flags);
76771 - __ClearPageSlab(sp);
76772 - reset_page_mapcount(sp);
76773 - slob_free_pages(b, 0);
76774 + slob_free_pages(sp, 0);
76775 return;
76776 }
76777
76778 @@ -426,11 +428,10 @@ out:
76779 */
76780
76781 static __always_inline void *
76782 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
76783 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
76784 {
76785 - unsigned int *m;
76786 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
76787 - void *ret;
76788 + slob_t *m;
76789 + void *ret = NULL;
76790
76791 gfp &= gfp_allowed_mask;
76792
76793 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
76794
76795 if (!m)
76796 return NULL;
76797 - *m = size;
76798 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
76799 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
76800 + m[0].units = size;
76801 + m[1].units = align;
76802 ret = (void *)m + align;
76803
76804 trace_kmalloc_node(caller, ret,
76805 size, size + align, gfp, node);
76806 } else {
76807 unsigned int order = get_order(size);
76808 + struct page *page;
76809
76810 if (likely(order))
76811 gfp |= __GFP_COMP;
76812 - ret = slob_new_pages(gfp, order, node);
76813 - if (ret) {
76814 - struct page *page;
76815 - page = virt_to_page(ret);
76816 + page = slob_new_pages(gfp, order, node);
76817 + if (page) {
76818 + ret = page_address(page);
76819 page->private = size;
76820 }
76821
76822 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
76823 size, PAGE_SIZE << order, gfp, node);
76824 }
76825
76826 - kmemleak_alloc(ret, size, 1, gfp);
76827 + return ret;
76828 +}
76829 +
76830 +static __always_inline void *
76831 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
76832 +{
76833 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
76834 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
76835 +
76836 + if (!ZERO_OR_NULL_PTR(ret))
76837 + kmemleak_alloc(ret, size, 1, gfp);
76838 return ret;
76839 }
76840
76841 @@ -501,15 +515,91 @@ void kfree(const void *block)
76842 kmemleak_free(block);
76843
76844 sp = virt_to_page(block);
76845 - if (PageSlab(sp)) {
76846 + VM_BUG_ON(!PageSlab(sp));
76847 + if (!sp->private) {
76848 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
76849 - unsigned int *m = (unsigned int *)(block - align);
76850 - slob_free(m, *m + align);
76851 - } else
76852 + slob_t *m = (slob_t *)(block - align);
76853 + slob_free(m, m[0].units + align);
76854 + } else {
76855 + __ClearPageSlab(sp);
76856 + reset_page_mapcount(sp);
76857 + sp->private = 0;
76858 put_page(sp);
76859 + }
76860 }
76861 EXPORT_SYMBOL(kfree);
76862
76863 +bool is_usercopy_object(const void *ptr)
76864 +{
76865 + if (!slab_is_available())
76866 + return false;
76867 +
76868 + // PAX: TODO
76869 +
76870 + return false;
76871 +}
76872 +
76873 +#ifdef CONFIG_PAX_USERCOPY
76874 +const char *check_heap_object(const void *ptr, unsigned long n)
76875 +{
76876 + struct page *page;
76877 + const slob_t *free;
76878 + const void *base;
76879 + unsigned long flags;
76880 +
76881 + if (ZERO_OR_NULL_PTR(ptr))
76882 + return "<null>";
76883 +
76884 + if (!virt_addr_valid(ptr))
76885 + return NULL;
76886 +
76887 + page = virt_to_head_page(ptr);
76888 + if (!PageSlab(page))
76889 + return NULL;
76890 +
76891 + if (page->private) {
76892 + base = page;
76893 + if (base <= ptr && n <= page->private - (ptr - base))
76894 + return NULL;
76895 + return "<slob>";
76896 + }
76897 +
76898 + /* some tricky double walking to find the chunk */
76899 + spin_lock_irqsave(&slob_lock, flags);
76900 + base = (void *)((unsigned long)ptr & PAGE_MASK);
76901 + free = page->freelist;
76902 +
76903 + while (!slob_last(free) && (void *)free <= ptr) {
76904 + base = free + slob_units(free);
76905 + free = slob_next(free);
76906 + }
76907 +
76908 + while (base < (void *)free) {
76909 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
76910 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
76911 + int offset;
76912 +
76913 + if (ptr < base + align)
76914 + break;
76915 +
76916 + offset = ptr - base - align;
76917 + if (offset >= m) {
76918 + base += size;
76919 + continue;
76920 + }
76921 +
76922 + if (n > m - offset)
76923 + break;
76924 +
76925 + spin_unlock_irqrestore(&slob_lock, flags);
76926 + return NULL;
76927 + }
76928 +
76929 + spin_unlock_irqrestore(&slob_lock, flags);
76930 + return "<slob>";
76931 +}
76932 +#endif
76933 +
76934 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
76935 size_t ksize(const void *block)
76936 {
76937 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
76938 return 0;
76939
76940 sp = virt_to_page(block);
76941 - if (PageSlab(sp)) {
76942 + VM_BUG_ON(!PageSlab(sp));
76943 + if (!sp->private) {
76944 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
76945 - unsigned int *m = (unsigned int *)(block - align);
76946 - return SLOB_UNITS(*m) * SLOB_UNIT;
76947 + slob_t *m = (slob_t *)(block - align);
76948 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
76949 } else
76950 return sp->private;
76951 }
76952 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
76953
76954 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
76955 {
76956 - void *b;
76957 + void *b = NULL;
76958
76959 flags &= gfp_allowed_mask;
76960
76961 lockdep_trace_alloc(flags);
76962
76963 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76964 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
76965 +#else
76966 if (c->size < PAGE_SIZE) {
76967 b = slob_alloc(c->size, flags, c->align, node);
76968 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
76969 SLOB_UNITS(c->size) * SLOB_UNIT,
76970 flags, node);
76971 } else {
76972 - b = slob_new_pages(flags, get_order(c->size), node);
76973 + struct page *sp;
76974 +
76975 + sp = slob_new_pages(flags, get_order(c->size), node);
76976 + if (sp) {
76977 + b = page_address(sp);
76978 + sp->private = c->size;
76979 + }
76980 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
76981 PAGE_SIZE << get_order(c->size),
76982 flags, node);
76983 }
76984 +#endif
76985
76986 if (c->ctor)
76987 c->ctor(b);
76988 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
76989
76990 static void __kmem_cache_free(void *b, int size)
76991 {
76992 - if (size < PAGE_SIZE)
76993 + struct page *sp;
76994 +
76995 + sp = virt_to_page(b);
76996 + BUG_ON(!PageSlab(sp));
76997 + if (!sp->private)
76998 slob_free(b, size);
76999 else
77000 - slob_free_pages(b, get_order(size));
77001 + slob_free_pages(sp, get_order(size));
77002 }
77003
77004 static void kmem_rcu_free(struct rcu_head *head)
77005 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77006
77007 void kmem_cache_free(struct kmem_cache *c, void *b)
77008 {
77009 + int size = c->size;
77010 +
77011 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77012 + if (size + c->align < PAGE_SIZE) {
77013 + size += c->align;
77014 + b -= c->align;
77015 + }
77016 +#endif
77017 +
77018 kmemleak_free_recursive(b, c->flags);
77019 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77020 struct slob_rcu *slob_rcu;
77021 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77022 - slob_rcu->size = c->size;
77023 + slob_rcu = b + (size - sizeof(struct slob_rcu));
77024 + slob_rcu->size = size;
77025 call_rcu(&slob_rcu->head, kmem_rcu_free);
77026 } else {
77027 - __kmem_cache_free(b, c->size);
77028 + __kmem_cache_free(b, size);
77029 }
77030
77031 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77032 + trace_kfree(_RET_IP_, b);
77033 +#else
77034 trace_kmem_cache_free(_RET_IP_, b);
77035 +#endif
77036 +
77037 }
77038 EXPORT_SYMBOL(kmem_cache_free);
77039
77040 diff --git a/mm/slub.c b/mm/slub.c
77041 index a0d6984..e280e5d 100644
77042 --- a/mm/slub.c
77043 +++ b/mm/slub.c
77044 @@ -201,7 +201,7 @@ struct track {
77045
77046 enum track_item { TRACK_ALLOC, TRACK_FREE };
77047
77048 -#ifdef CONFIG_SYSFS
77049 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77050 static int sysfs_slab_add(struct kmem_cache *);
77051 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77052 static void sysfs_slab_remove(struct kmem_cache *);
77053 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77054 if (!t->addr)
77055 return;
77056
77057 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77058 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77059 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77060 #ifdef CONFIG_STACKTRACE
77061 {
77062 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77063
77064 page = virt_to_head_page(x);
77065
77066 + BUG_ON(!PageSlab(page));
77067 +
77068 if (kmem_cache_debug(s) && page->slab != s) {
77069 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77070 " is from %s\n", page->slab->name, s->name);
77071 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
77072 * Merge control. If this is set then no merging of slab caches will occur.
77073 * (Could be removed. This was introduced to pacify the merge skeptics.)
77074 */
77075 -static int slub_nomerge;
77076 +static int slub_nomerge = 1;
77077
77078 /*
77079 * Calculate the order of allocation given an slab object size.
77080 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
77081 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
77082 #endif
77083
77084 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77085 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
77086 +#endif
77087 +
77088 static int __init setup_slub_min_order(char *str)
77089 {
77090 get_option(&str, &slub_min_order);
77091 @@ -3342,6 +3348,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77092 return kmalloc_dma_caches[index];
77093
77094 #endif
77095 +
77096 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77097 + if (flags & SLAB_USERCOPY)
77098 + return kmalloc_usercopy_caches[index];
77099 +
77100 +#endif
77101 +
77102 return kmalloc_caches[index];
77103 }
77104
77105 @@ -3410,6 +3423,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
77106 EXPORT_SYMBOL(__kmalloc_node);
77107 #endif
77108
77109 +bool is_usercopy_object(const void *ptr)
77110 +{
77111 + struct page *page;
77112 + struct kmem_cache *s;
77113 +
77114 + if (ZERO_OR_NULL_PTR(ptr))
77115 + return false;
77116 +
77117 + if (!slab_is_available())
77118 + return false;
77119 +
77120 + if (!virt_addr_valid(ptr))
77121 + return false;
77122 +
77123 + page = virt_to_head_page(ptr);
77124 +
77125 + if (!PageSlab(page))
77126 + return false;
77127 +
77128 + s = page->slab;
77129 + return s->flags & SLAB_USERCOPY;
77130 +}
77131 +
77132 +#ifdef CONFIG_PAX_USERCOPY
77133 +const char *check_heap_object(const void *ptr, unsigned long n)
77134 +{
77135 + struct page *page;
77136 + struct kmem_cache *s;
77137 + unsigned long offset;
77138 +
77139 + if (ZERO_OR_NULL_PTR(ptr))
77140 + return "<null>";
77141 +
77142 + if (!virt_addr_valid(ptr))
77143 + return NULL;
77144 +
77145 + page = virt_to_head_page(ptr);
77146 +
77147 + if (!PageSlab(page))
77148 + return NULL;
77149 +
77150 + s = page->slab;
77151 + if (!(s->flags & SLAB_USERCOPY))
77152 + return s->name;
77153 +
77154 + offset = (ptr - page_address(page)) % s->size;
77155 + if (offset <= s->object_size && n <= s->object_size - offset)
77156 + return NULL;
77157 +
77158 + return s->name;
77159 +}
77160 +#endif
77161 +
77162 size_t ksize(const void *object)
77163 {
77164 struct page *page;
77165 @@ -3684,7 +3750,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
77166 int node;
77167
77168 list_add(&s->list, &slab_caches);
77169 - s->refcount = -1;
77170 + atomic_set(&s->refcount, -1);
77171
77172 for_each_node_state(node, N_NORMAL_MEMORY) {
77173 struct kmem_cache_node *n = get_node(s, node);
77174 @@ -3807,17 +3873,17 @@ void __init kmem_cache_init(void)
77175
77176 /* Caches that are not of the two-to-the-power-of size */
77177 if (KMALLOC_MIN_SIZE <= 32) {
77178 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
77179 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
77180 caches++;
77181 }
77182
77183 if (KMALLOC_MIN_SIZE <= 64) {
77184 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
77185 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
77186 caches++;
77187 }
77188
77189 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
77190 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
77191 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
77192 caches++;
77193 }
77194
77195 @@ -3859,6 +3925,22 @@ void __init kmem_cache_init(void)
77196 }
77197 }
77198 #endif
77199 +
77200 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77201 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
77202 + struct kmem_cache *s = kmalloc_caches[i];
77203 +
77204 + if (s && s->size) {
77205 + char *name = kasprintf(GFP_NOWAIT,
77206 + "usercopy-kmalloc-%d", s->object_size);
77207 +
77208 + BUG_ON(!name);
77209 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
77210 + s->object_size, SLAB_USERCOPY);
77211 + }
77212 + }
77213 +#endif
77214 +
77215 printk(KERN_INFO
77216 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
77217 " CPUs=%d, Nodes=%d\n",
77218 @@ -3885,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
77219 /*
77220 * We may have set a slab to be unmergeable during bootstrap.
77221 */
77222 - if (s->refcount < 0)
77223 + if (atomic_read(&s->refcount) < 0)
77224 return 1;
77225
77226 return 0;
77227 @@ -3939,7 +4021,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77228
77229 s = find_mergeable(size, align, flags, name, ctor);
77230 if (s) {
77231 - s->refcount++;
77232 + atomic_inc(&s->refcount);
77233 /*
77234 * Adjust the object sizes so that we clear
77235 * the complete object on kzalloc.
77236 @@ -3948,7 +4030,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77237 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
77238
77239 if (sysfs_slab_alias(s, name)) {
77240 - s->refcount--;
77241 + atomic_dec(&s->refcount);
77242 s = NULL;
77243 }
77244 }
77245 @@ -4063,7 +4145,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
77246 }
77247 #endif
77248
77249 -#ifdef CONFIG_SYSFS
77250 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77251 static int count_inuse(struct page *page)
77252 {
77253 return page->inuse;
77254 @@ -4450,12 +4532,12 @@ static void resiliency_test(void)
77255 validate_slab_cache(kmalloc_caches[9]);
77256 }
77257 #else
77258 -#ifdef CONFIG_SYSFS
77259 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77260 static void resiliency_test(void) {};
77261 #endif
77262 #endif
77263
77264 -#ifdef CONFIG_SYSFS
77265 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77266 enum slab_stat_type {
77267 SL_ALL, /* All slabs */
77268 SL_PARTIAL, /* Only partially allocated slabs */
77269 @@ -4699,7 +4781,7 @@ SLAB_ATTR_RO(ctor);
77270
77271 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
77272 {
77273 - return sprintf(buf, "%d\n", s->refcount - 1);
77274 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
77275 }
77276 SLAB_ATTR_RO(aliases);
77277
77278 @@ -5261,6 +5343,7 @@ static char *create_unique_id(struct kmem_cache *s)
77279 return name;
77280 }
77281
77282 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77283 static int sysfs_slab_add(struct kmem_cache *s)
77284 {
77285 int err;
77286 @@ -5323,6 +5406,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
77287 kobject_del(&s->kobj);
77288 kobject_put(&s->kobj);
77289 }
77290 +#endif
77291
77292 /*
77293 * Need to buffer aliases during bootup until sysfs becomes
77294 @@ -5336,6 +5420,7 @@ struct saved_alias {
77295
77296 static struct saved_alias *alias_list;
77297
77298 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77299 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77300 {
77301 struct saved_alias *al;
77302 @@ -5358,6 +5443,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77303 alias_list = al;
77304 return 0;
77305 }
77306 +#endif
77307
77308 static int __init slab_sysfs_init(void)
77309 {
77310 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
77311 index 1b7e22a..3fcd4f3 100644
77312 --- a/mm/sparse-vmemmap.c
77313 +++ b/mm/sparse-vmemmap.c
77314 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
77315 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77316 if (!p)
77317 return NULL;
77318 - pud_populate(&init_mm, pud, p);
77319 + pud_populate_kernel(&init_mm, pud, p);
77320 }
77321 return pud;
77322 }
77323 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
77324 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77325 if (!p)
77326 return NULL;
77327 - pgd_populate(&init_mm, pgd, p);
77328 + pgd_populate_kernel(&init_mm, pgd, p);
77329 }
77330 return pgd;
77331 }
77332 diff --git a/mm/swap.c b/mm/swap.c
77333 index 6310dc2..3662b3f 100644
77334 --- a/mm/swap.c
77335 +++ b/mm/swap.c
77336 @@ -30,6 +30,7 @@
77337 #include <linux/backing-dev.h>
77338 #include <linux/memcontrol.h>
77339 #include <linux/gfp.h>
77340 +#include <linux/hugetlb.h>
77341
77342 #include "internal.h"
77343
77344 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
77345
77346 __page_cache_release(page);
77347 dtor = get_compound_page_dtor(page);
77348 + if (!PageHuge(page))
77349 + BUG_ON(dtor != free_compound_page);
77350 (*dtor)(page);
77351 }
77352
77353 diff --git a/mm/swapfile.c b/mm/swapfile.c
77354 index f91a255..9dcac21 100644
77355 --- a/mm/swapfile.c
77356 +++ b/mm/swapfile.c
77357 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
77358
77359 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
77360 /* Activity counter to indicate that a swapon or swapoff has occurred */
77361 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
77362 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
77363
77364 static inline unsigned char swap_count(unsigned char ent)
77365 {
77366 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
77367 }
77368 filp_close(swap_file, NULL);
77369 err = 0;
77370 - atomic_inc(&proc_poll_event);
77371 + atomic_inc_unchecked(&proc_poll_event);
77372 wake_up_interruptible(&proc_poll_wait);
77373
77374 out_dput:
77375 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
77376
77377 poll_wait(file, &proc_poll_wait, wait);
77378
77379 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
77380 - seq->poll_event = atomic_read(&proc_poll_event);
77381 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
77382 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
77383 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
77384 }
77385
77386 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
77387 return ret;
77388
77389 seq = file->private_data;
77390 - seq->poll_event = atomic_read(&proc_poll_event);
77391 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
77392 return 0;
77393 }
77394
77395 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
77396 (frontswap_map) ? "FS" : "");
77397
77398 mutex_unlock(&swapon_mutex);
77399 - atomic_inc(&proc_poll_event);
77400 + atomic_inc_unchecked(&proc_poll_event);
77401 wake_up_interruptible(&proc_poll_wait);
77402
77403 if (S_ISREG(inode->i_mode))
77404 diff --git a/mm/util.c b/mm/util.c
77405 index dc3036c..b6c7c9d 100644
77406 --- a/mm/util.c
77407 +++ b/mm/util.c
77408 @@ -292,6 +292,12 @@ done:
77409 void arch_pick_mmap_layout(struct mm_struct *mm)
77410 {
77411 mm->mmap_base = TASK_UNMAPPED_BASE;
77412 +
77413 +#ifdef CONFIG_PAX_RANDMMAP
77414 + if (mm->pax_flags & MF_PAX_RANDMMAP)
77415 + mm->mmap_base += mm->delta_mmap;
77416 +#endif
77417 +
77418 mm->get_unmapped_area = arch_get_unmapped_area;
77419 mm->unmap_area = arch_unmap_area;
77420 }
77421 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
77422 index 78e0830..bc6bbd8 100644
77423 --- a/mm/vmalloc.c
77424 +++ b/mm/vmalloc.c
77425 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
77426
77427 pte = pte_offset_kernel(pmd, addr);
77428 do {
77429 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
77430 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
77431 +
77432 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77433 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
77434 + BUG_ON(!pte_exec(*pte));
77435 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
77436 + continue;
77437 + }
77438 +#endif
77439 +
77440 + {
77441 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
77442 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
77443 + }
77444 } while (pte++, addr += PAGE_SIZE, addr != end);
77445 }
77446
77447 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
77448 pte = pte_alloc_kernel(pmd, addr);
77449 if (!pte)
77450 return -ENOMEM;
77451 +
77452 + pax_open_kernel();
77453 do {
77454 struct page *page = pages[*nr];
77455
77456 - if (WARN_ON(!pte_none(*pte)))
77457 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77458 + if (pgprot_val(prot) & _PAGE_NX)
77459 +#endif
77460 +
77461 + if (!pte_none(*pte)) {
77462 + pax_close_kernel();
77463 + WARN_ON(1);
77464 return -EBUSY;
77465 - if (WARN_ON(!page))
77466 + }
77467 + if (!page) {
77468 + pax_close_kernel();
77469 + WARN_ON(1);
77470 return -ENOMEM;
77471 + }
77472 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
77473 (*nr)++;
77474 } while (pte++, addr += PAGE_SIZE, addr != end);
77475 + pax_close_kernel();
77476 return 0;
77477 }
77478
77479 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
77480 pmd_t *pmd;
77481 unsigned long next;
77482
77483 - pmd = pmd_alloc(&init_mm, pud, addr);
77484 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
77485 if (!pmd)
77486 return -ENOMEM;
77487 do {
77488 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
77489 pud_t *pud;
77490 unsigned long next;
77491
77492 - pud = pud_alloc(&init_mm, pgd, addr);
77493 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
77494 if (!pud)
77495 return -ENOMEM;
77496 do {
77497 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
77498 * and fall back on vmalloc() if that fails. Others
77499 * just put it in the vmalloc space.
77500 */
77501 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
77502 +#ifdef CONFIG_MODULES
77503 +#ifdef MODULES_VADDR
77504 unsigned long addr = (unsigned long)x;
77505 if (addr >= MODULES_VADDR && addr < MODULES_END)
77506 return 1;
77507 #endif
77508 +
77509 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77510 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
77511 + return 1;
77512 +#endif
77513 +
77514 +#endif
77515 +
77516 return is_vmalloc_addr(x);
77517 }
77518
77519 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
77520
77521 if (!pgd_none(*pgd)) {
77522 pud_t *pud = pud_offset(pgd, addr);
77523 +#ifdef CONFIG_X86
77524 + if (!pud_large(*pud))
77525 +#endif
77526 if (!pud_none(*pud)) {
77527 pmd_t *pmd = pmd_offset(pud, addr);
77528 +#ifdef CONFIG_X86
77529 + if (!pmd_large(*pmd))
77530 +#endif
77531 if (!pmd_none(*pmd)) {
77532 pte_t *ptep, pte;
77533
77534 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
77535 * Allocate a region of KVA of the specified size and alignment, within the
77536 * vstart and vend.
77537 */
77538 -static struct vmap_area *alloc_vmap_area(unsigned long size,
77539 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
77540 unsigned long align,
77541 unsigned long vstart, unsigned long vend,
77542 int node, gfp_t gfp_mask)
77543 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
77544 struct vm_struct *area;
77545
77546 BUG_ON(in_interrupt());
77547 +
77548 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77549 + if (flags & VM_KERNEXEC) {
77550 + if (start != VMALLOC_START || end != VMALLOC_END)
77551 + return NULL;
77552 + start = (unsigned long)MODULES_EXEC_VADDR;
77553 + end = (unsigned long)MODULES_EXEC_END;
77554 + }
77555 +#endif
77556 +
77557 if (flags & VM_IOREMAP) {
77558 int bit = fls(size);
77559
77560 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
77561 if (count > totalram_pages)
77562 return NULL;
77563
77564 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77565 + if (!(pgprot_val(prot) & _PAGE_NX))
77566 + flags |= VM_KERNEXEC;
77567 +#endif
77568 +
77569 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
77570 __builtin_return_address(0));
77571 if (!area)
77572 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
77573 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
77574 goto fail;
77575
77576 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77577 + if (!(pgprot_val(prot) & _PAGE_NX))
77578 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
77579 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
77580 + else
77581 +#endif
77582 +
77583 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
77584 start, end, node, gfp_mask, caller);
77585 if (!area)
77586 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
77587 * For tight control over page level allocator and protection flags
77588 * use __vmalloc() instead.
77589 */
77590 -
77591 void *vmalloc_exec(unsigned long size)
77592 {
77593 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
77594 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
77595 -1, __builtin_return_address(0));
77596 }
77597
77598 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
77599 unsigned long uaddr = vma->vm_start;
77600 unsigned long usize = vma->vm_end - vma->vm_start;
77601
77602 + BUG_ON(vma->vm_mirror);
77603 +
77604 if ((PAGE_SIZE-1) & (unsigned long)addr)
77605 return -EINVAL;
77606
77607 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
77608 v->addr, v->addr + v->size, v->size);
77609
77610 if (v->caller)
77611 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77612 + seq_printf(m, " %pK", v->caller);
77613 +#else
77614 seq_printf(m, " %pS", v->caller);
77615 +#endif
77616
77617 if (v->nr_pages)
77618 seq_printf(m, " pages=%d", v->nr_pages);
77619 diff --git a/mm/vmstat.c b/mm/vmstat.c
77620 index c737057..a49753a 100644
77621 --- a/mm/vmstat.c
77622 +++ b/mm/vmstat.c
77623 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
77624 *
77625 * vm_stat contains the global counters
77626 */
77627 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
77628 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
77629 EXPORT_SYMBOL(vm_stat);
77630
77631 #ifdef CONFIG_SMP
77632 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
77633 v = p->vm_stat_diff[i];
77634 p->vm_stat_diff[i] = 0;
77635 local_irq_restore(flags);
77636 - atomic_long_add(v, &zone->vm_stat[i]);
77637 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
77638 global_diff[i] += v;
77639 #ifdef CONFIG_NUMA
77640 /* 3 seconds idle till flush */
77641 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
77642
77643 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
77644 if (global_diff[i])
77645 - atomic_long_add(global_diff[i], &vm_stat[i]);
77646 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
77647 }
77648
77649 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
77650 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
77651 if (pset->vm_stat_diff[i]) {
77652 int v = pset->vm_stat_diff[i];
77653 pset->vm_stat_diff[i] = 0;
77654 - atomic_long_add(v, &zone->vm_stat[i]);
77655 - atomic_long_add(v, &vm_stat[i]);
77656 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
77657 + atomic_long_add_unchecked(v, &vm_stat[i]);
77658 }
77659 }
77660 #endif
77661 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
77662 start_cpu_timer(cpu);
77663 #endif
77664 #ifdef CONFIG_PROC_FS
77665 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
77666 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
77667 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
77668 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
77669 + {
77670 + mode_t gr_mode = S_IRUGO;
77671 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
77672 + gr_mode = S_IRUSR;
77673 +#endif
77674 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
77675 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
77676 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
77677 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
77678 +#else
77679 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
77680 +#endif
77681 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
77682 + }
77683 #endif
77684 return 0;
77685 }
77686 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
77687 index ee07072..593e3fd 100644
77688 --- a/net/8021q/vlan.c
77689 +++ b/net/8021q/vlan.c
77690 @@ -484,7 +484,7 @@ out:
77691 return NOTIFY_DONE;
77692 }
77693
77694 -static struct notifier_block vlan_notifier_block __read_mostly = {
77695 +static struct notifier_block vlan_notifier_block = {
77696 .notifier_call = vlan_device_event,
77697 };
77698
77699 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
77700 err = -EPERM;
77701 if (!capable(CAP_NET_ADMIN))
77702 break;
77703 - if ((args.u.name_type >= 0) &&
77704 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
77705 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
77706 struct vlan_net *vn;
77707
77708 vn = net_generic(net, vlan_net_id);
77709 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
77710 index 02efb25..41541a9 100644
77711 --- a/net/9p/trans_fd.c
77712 +++ b/net/9p/trans_fd.c
77713 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
77714 oldfs = get_fs();
77715 set_fs(get_ds());
77716 /* The cast to a user pointer is valid due to the set_fs() */
77717 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
77718 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
77719 set_fs(oldfs);
77720
77721 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
77722 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
77723 index 876fbe8..8bbea9f 100644
77724 --- a/net/atm/atm_misc.c
77725 +++ b/net/atm/atm_misc.c
77726 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
77727 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
77728 return 1;
77729 atm_return(vcc, truesize);
77730 - atomic_inc(&vcc->stats->rx_drop);
77731 + atomic_inc_unchecked(&vcc->stats->rx_drop);
77732 return 0;
77733 }
77734 EXPORT_SYMBOL(atm_charge);
77735 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
77736 }
77737 }
77738 atm_return(vcc, guess);
77739 - atomic_inc(&vcc->stats->rx_drop);
77740 + atomic_inc_unchecked(&vcc->stats->rx_drop);
77741 return NULL;
77742 }
77743 EXPORT_SYMBOL(atm_alloc_charge);
77744 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
77745
77746 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
77747 {
77748 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
77749 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
77750 __SONET_ITEMS
77751 #undef __HANDLE_ITEM
77752 }
77753 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
77754
77755 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
77756 {
77757 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
77758 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
77759 __SONET_ITEMS
77760 #undef __HANDLE_ITEM
77761 }
77762 diff --git a/net/atm/lec.h b/net/atm/lec.h
77763 index a86aff9..3a0d6f6 100644
77764 --- a/net/atm/lec.h
77765 +++ b/net/atm/lec.h
77766 @@ -48,7 +48,7 @@ struct lane2_ops {
77767 const u8 *tlvs, u32 sizeoftlvs);
77768 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
77769 const u8 *tlvs, u32 sizeoftlvs);
77770 -};
77771 +} __no_const;
77772
77773 /*
77774 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
77775 diff --git a/net/atm/proc.c b/net/atm/proc.c
77776 index 0d020de..011c7bb 100644
77777 --- a/net/atm/proc.c
77778 +++ b/net/atm/proc.c
77779 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
77780 const struct k_atm_aal_stats *stats)
77781 {
77782 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
77783 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
77784 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
77785 - atomic_read(&stats->rx_drop));
77786 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
77787 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
77788 + atomic_read_unchecked(&stats->rx_drop));
77789 }
77790
77791 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
77792 diff --git a/net/atm/resources.c b/net/atm/resources.c
77793 index 0447d5d..3cf4728 100644
77794 --- a/net/atm/resources.c
77795 +++ b/net/atm/resources.c
77796 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
77797 static void copy_aal_stats(struct k_atm_aal_stats *from,
77798 struct atm_aal_stats *to)
77799 {
77800 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
77801 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
77802 __AAL_STAT_ITEMS
77803 #undef __HANDLE_ITEM
77804 }
77805 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
77806 static void subtract_aal_stats(struct k_atm_aal_stats *from,
77807 struct atm_aal_stats *to)
77808 {
77809 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
77810 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
77811 __AAL_STAT_ITEMS
77812 #undef __HANDLE_ITEM
77813 }
77814 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
77815 index c6fcc76..1270d14 100644
77816 --- a/net/batman-adv/bat_iv_ogm.c
77817 +++ b/net/batman-adv/bat_iv_ogm.c
77818 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
77819
77820 /* randomize initial seqno to avoid collision */
77821 get_random_bytes(&random_seqno, sizeof(random_seqno));
77822 - atomic_set(&hard_iface->seqno, random_seqno);
77823 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
77824
77825 hard_iface->packet_len = BATADV_OGM_HLEN;
77826 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
77827 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
77828 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
77829
77830 /* change sequence number to network order */
77831 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
77832 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
77833 batadv_ogm_packet->seqno = htonl(seqno);
77834 - atomic_inc(&hard_iface->seqno);
77835 + atomic_inc_unchecked(&hard_iface->seqno);
77836
77837 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
77838 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
77839 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
77840 return;
77841
77842 /* could be changed by schedule_own_packet() */
77843 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
77844 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
77845
77846 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
77847 has_directlink_flag = 1;
77848 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
77849 index d112fd6..686a447 100644
77850 --- a/net/batman-adv/hard-interface.c
77851 +++ b/net/batman-adv/hard-interface.c
77852 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
77853 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
77854 dev_add_pack(&hard_iface->batman_adv_ptype);
77855
77856 - atomic_set(&hard_iface->frag_seqno, 1);
77857 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
77858 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
77859 hard_iface->net_dev->name);
77860
77861 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
77862 /* This can't be called via a bat_priv callback because
77863 * we have no bat_priv yet.
77864 */
77865 - atomic_set(&hard_iface->seqno, 1);
77866 + atomic_set_unchecked(&hard_iface->seqno, 1);
77867 hard_iface->packet_buff = NULL;
77868
77869 return hard_iface;
77870 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
77871 index ce0684a..4a0cbf1 100644
77872 --- a/net/batman-adv/soft-interface.c
77873 +++ b/net/batman-adv/soft-interface.c
77874 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
77875 primary_if->net_dev->dev_addr, ETH_ALEN);
77876
77877 /* set broadcast sequence number */
77878 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
77879 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
77880 bcast_packet->seqno = htonl(seqno);
77881
77882 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
77883 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
77884 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
77885
77886 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
77887 - atomic_set(&bat_priv->bcast_seqno, 1);
77888 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
77889 atomic_set(&bat_priv->tt.vn, 0);
77890 atomic_set(&bat_priv->tt.local_changes, 0);
77891 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
77892 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
77893 index ac1e07a..4c846e2 100644
77894 --- a/net/batman-adv/types.h
77895 +++ b/net/batman-adv/types.h
77896 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
77897 int16_t if_num;
77898 char if_status;
77899 struct net_device *net_dev;
77900 - atomic_t seqno;
77901 - atomic_t frag_seqno;
77902 + atomic_unchecked_t seqno;
77903 + atomic_unchecked_t frag_seqno;
77904 unsigned char *packet_buff;
77905 int packet_len;
77906 struct kobject *hardif_obj;
77907 @@ -244,7 +244,7 @@ struct batadv_priv {
77908 atomic_t orig_interval; /* uint */
77909 atomic_t hop_penalty; /* uint */
77910 atomic_t log_level; /* uint */
77911 - atomic_t bcast_seqno;
77912 + atomic_unchecked_t bcast_seqno;
77913 atomic_t bcast_queue_left;
77914 atomic_t batman_queue_left;
77915 char num_ifaces;
77916 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
77917 index f397232..3206a33 100644
77918 --- a/net/batman-adv/unicast.c
77919 +++ b/net/batman-adv/unicast.c
77920 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
77921 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
77922 frag2->flags = large_tail;
77923
77924 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
77925 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
77926 frag1->seqno = htons(seqno - 1);
77927 frag2->seqno = htons(seqno);
77928
77929 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
77930 index 07f0739..3c42e34 100644
77931 --- a/net/bluetooth/hci_sock.c
77932 +++ b/net/bluetooth/hci_sock.c
77933 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
77934 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
77935 }
77936
77937 - len = min_t(unsigned int, len, sizeof(uf));
77938 + len = min((size_t)len, sizeof(uf));
77939 if (copy_from_user(&uf, optval, len)) {
77940 err = -EFAULT;
77941 break;
77942 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
77943 index a91239d..d7ed533 100644
77944 --- a/net/bluetooth/l2cap_core.c
77945 +++ b/net/bluetooth/l2cap_core.c
77946 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
77947 break;
77948
77949 case L2CAP_CONF_RFC:
77950 - if (olen == sizeof(rfc))
77951 - memcpy(&rfc, (void *)val, olen);
77952 + if (olen != sizeof(rfc))
77953 + break;
77954 +
77955 + memcpy(&rfc, (void *)val, olen);
77956
77957 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
77958 rfc.mode != chan->mode)
77959 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
77960 index 083f2bf..799f9448 100644
77961 --- a/net/bluetooth/l2cap_sock.c
77962 +++ b/net/bluetooth/l2cap_sock.c
77963 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
77964 struct sock *sk = sock->sk;
77965 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
77966 struct l2cap_options opts;
77967 - int len, err = 0;
77968 + int err = 0;
77969 + size_t len = optlen;
77970 u32 opt;
77971
77972 BT_DBG("sk %p", sk);
77973 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
77974 opts.max_tx = chan->max_tx;
77975 opts.txwin_size = chan->tx_win;
77976
77977 - len = min_t(unsigned int, sizeof(opts), optlen);
77978 + len = min(sizeof(opts), len);
77979 if (copy_from_user((char *) &opts, optval, len)) {
77980 err = -EFAULT;
77981 break;
77982 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
77983 struct bt_security sec;
77984 struct bt_power pwr;
77985 struct l2cap_conn *conn;
77986 - int len, err = 0;
77987 + int err = 0;
77988 + size_t len = optlen;
77989 u32 opt;
77990
77991 BT_DBG("sk %p", sk);
77992 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
77993
77994 sec.level = BT_SECURITY_LOW;
77995
77996 - len = min_t(unsigned int, sizeof(sec), optlen);
77997 + len = min(sizeof(sec), len);
77998 if (copy_from_user((char *) &sec, optval, len)) {
77999 err = -EFAULT;
78000 break;
78001 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78002
78003 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78004
78005 - len = min_t(unsigned int, sizeof(pwr), optlen);
78006 + len = min(sizeof(pwr), len);
78007 if (copy_from_user((char *) &pwr, optval, len)) {
78008 err = -EFAULT;
78009 break;
78010 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78011 index 868a909..d044bc3 100644
78012 --- a/net/bluetooth/rfcomm/sock.c
78013 +++ b/net/bluetooth/rfcomm/sock.c
78014 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78015 struct sock *sk = sock->sk;
78016 struct bt_security sec;
78017 int err = 0;
78018 - size_t len;
78019 + size_t len = optlen;
78020 u32 opt;
78021
78022 BT_DBG("sk %p", sk);
78023 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78024
78025 sec.level = BT_SECURITY_LOW;
78026
78027 - len = min_t(unsigned int, sizeof(sec), optlen);
78028 + len = min(sizeof(sec), len);
78029 if (copy_from_user((char *) &sec, optval, len)) {
78030 err = -EFAULT;
78031 break;
78032 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78033 index ccc2487..921073d 100644
78034 --- a/net/bluetooth/rfcomm/tty.c
78035 +++ b/net/bluetooth/rfcomm/tty.c
78036 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78037 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78038
78039 spin_lock_irqsave(&dev->port.lock, flags);
78040 - if (dev->port.count > 0) {
78041 + if (atomic_read(&dev->port.count) > 0) {
78042 spin_unlock_irqrestore(&dev->port.lock, flags);
78043 return;
78044 }
78045 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78046 return -ENODEV;
78047
78048 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78049 - dev->channel, dev->port.count);
78050 + dev->channel, atomic_read(&dev->port.count));
78051
78052 spin_lock_irqsave(&dev->port.lock, flags);
78053 - if (++dev->port.count > 1) {
78054 + if (atomic_inc_return(&dev->port.count) > 1) {
78055 spin_unlock_irqrestore(&dev->port.lock, flags);
78056 return 0;
78057 }
78058 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78059 return;
78060
78061 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78062 - dev->port.count);
78063 + atomic_read(&dev->port.count));
78064
78065 spin_lock_irqsave(&dev->port.lock, flags);
78066 - if (!--dev->port.count) {
78067 + if (!atomic_dec_return(&dev->port.count)) {
78068 spin_unlock_irqrestore(&dev->port.lock, flags);
78069 if (dev->tty_dev->parent)
78070 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78071 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78072 index 5fe2ff3..121d696 100644
78073 --- a/net/bridge/netfilter/ebtables.c
78074 +++ b/net/bridge/netfilter/ebtables.c
78075 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78076 tmp.valid_hooks = t->table->valid_hooks;
78077 }
78078 mutex_unlock(&ebt_mutex);
78079 - if (copy_to_user(user, &tmp, *len) != 0){
78080 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78081 BUGPRINT("c2u Didn't work\n");
78082 ret = -EFAULT;
78083 break;
78084 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78085 goto out;
78086 tmp.valid_hooks = t->valid_hooks;
78087
78088 - if (copy_to_user(user, &tmp, *len) != 0) {
78089 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78090 ret = -EFAULT;
78091 break;
78092 }
78093 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78094 tmp.entries_size = t->table->entries_size;
78095 tmp.valid_hooks = t->table->valid_hooks;
78096
78097 - if (copy_to_user(user, &tmp, *len) != 0) {
78098 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78099 ret = -EFAULT;
78100 break;
78101 }
78102 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
78103 index 44f270f..1f5602d 100644
78104 --- a/net/caif/cfctrl.c
78105 +++ b/net/caif/cfctrl.c
78106 @@ -10,6 +10,7 @@
78107 #include <linux/spinlock.h>
78108 #include <linux/slab.h>
78109 #include <linux/pkt_sched.h>
78110 +#include <linux/sched.h>
78111 #include <net/caif/caif_layer.h>
78112 #include <net/caif/cfpkt.h>
78113 #include <net/caif/cfctrl.h>
78114 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
78115 memset(&dev_info, 0, sizeof(dev_info));
78116 dev_info.id = 0xff;
78117 cfsrvl_init(&this->serv, 0, &dev_info, false);
78118 - atomic_set(&this->req_seq_no, 1);
78119 - atomic_set(&this->rsp_seq_no, 1);
78120 + atomic_set_unchecked(&this->req_seq_no, 1);
78121 + atomic_set_unchecked(&this->rsp_seq_no, 1);
78122 this->serv.layer.receive = cfctrl_recv;
78123 sprintf(this->serv.layer.name, "ctrl");
78124 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
78125 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
78126 struct cfctrl_request_info *req)
78127 {
78128 spin_lock_bh(&ctrl->info_list_lock);
78129 - atomic_inc(&ctrl->req_seq_no);
78130 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
78131 + atomic_inc_unchecked(&ctrl->req_seq_no);
78132 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
78133 list_add_tail(&req->list, &ctrl->list);
78134 spin_unlock_bh(&ctrl->info_list_lock);
78135 }
78136 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
78137 if (p != first)
78138 pr_warn("Requests are not received in order\n");
78139
78140 - atomic_set(&ctrl->rsp_seq_no,
78141 + atomic_set_unchecked(&ctrl->rsp_seq_no,
78142 p->sequence_no);
78143 list_del(&p->list);
78144 goto out;
78145 diff --git a/net/can/af_can.c b/net/can/af_can.c
78146 index ddac1ee..3ee0a78 100644
78147 --- a/net/can/af_can.c
78148 +++ b/net/can/af_can.c
78149 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
78150 };
78151
78152 /* notifier block for netdevice event */
78153 -static struct notifier_block can_netdev_notifier __read_mostly = {
78154 +static struct notifier_block can_netdev_notifier = {
78155 .notifier_call = can_notifier,
78156 };
78157
78158 diff --git a/net/can/gw.c b/net/can/gw.c
78159 index 1f5c978..ef714c7 100644
78160 --- a/net/can/gw.c
78161 +++ b/net/can/gw.c
78162 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78163 MODULE_ALIAS("can-gw");
78164
78165 static HLIST_HEAD(cgw_list);
78166 -static struct notifier_block notifier;
78167
78168 static struct kmem_cache *cgw_cache __read_mostly;
78169
78170 @@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
78171 return err;
78172 }
78173
78174 +static struct notifier_block notifier = {
78175 + .notifier_call = cgw_notifier
78176 +};
78177 +
78178 static __init int cgw_module_init(void)
78179 {
78180 printk(banner);
78181 @@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
78182 return -ENOMEM;
78183
78184 /* set notifier */
78185 - notifier.notifier_call = cgw_notifier;
78186 register_netdevice_notifier(&notifier);
78187
78188 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
78189 diff --git a/net/compat.c b/net/compat.c
78190 index 79ae884..17c5c09 100644
78191 --- a/net/compat.c
78192 +++ b/net/compat.c
78193 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
78194 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
78195 __get_user(kmsg->msg_flags, &umsg->msg_flags))
78196 return -EFAULT;
78197 - kmsg->msg_name = compat_ptr(tmp1);
78198 - kmsg->msg_iov = compat_ptr(tmp2);
78199 - kmsg->msg_control = compat_ptr(tmp3);
78200 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
78201 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
78202 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
78203 return 0;
78204 }
78205
78206 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78207
78208 if (kern_msg->msg_namelen) {
78209 if (mode == VERIFY_READ) {
78210 - int err = move_addr_to_kernel(kern_msg->msg_name,
78211 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
78212 kern_msg->msg_namelen,
78213 kern_address);
78214 if (err < 0)
78215 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78216 kern_msg->msg_name = NULL;
78217
78218 tot_len = iov_from_user_compat_to_kern(kern_iov,
78219 - (struct compat_iovec __user *)kern_msg->msg_iov,
78220 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
78221 kern_msg->msg_iovlen);
78222 if (tot_len >= 0)
78223 kern_msg->msg_iov = kern_iov;
78224 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78225
78226 #define CMSG_COMPAT_FIRSTHDR(msg) \
78227 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
78228 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
78229 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
78230 (struct compat_cmsghdr __user *)NULL)
78231
78232 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
78233 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
78234 (ucmlen) <= (unsigned long) \
78235 ((mhdr)->msg_controllen - \
78236 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
78237 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
78238
78239 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
78240 struct compat_cmsghdr __user *cmsg, int cmsg_len)
78241 {
78242 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
78243 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
78244 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
78245 msg->msg_controllen)
78246 return NULL;
78247 return (struct compat_cmsghdr __user *)ptr;
78248 @@ -219,7 +219,7 @@ Efault:
78249
78250 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
78251 {
78252 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78253 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78254 struct compat_cmsghdr cmhdr;
78255 struct compat_timeval ctv;
78256 struct compat_timespec cts[3];
78257 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
78258
78259 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
78260 {
78261 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78262 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78263 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
78264 int fdnum = scm->fp->count;
78265 struct file **fp = scm->fp->fp;
78266 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
78267 return -EFAULT;
78268 old_fs = get_fs();
78269 set_fs(KERNEL_DS);
78270 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
78271 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
78272 set_fs(old_fs);
78273
78274 return err;
78275 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
78276 len = sizeof(ktime);
78277 old_fs = get_fs();
78278 set_fs(KERNEL_DS);
78279 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
78280 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
78281 set_fs(old_fs);
78282
78283 if (!err) {
78284 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78285 case MCAST_JOIN_GROUP:
78286 case MCAST_LEAVE_GROUP:
78287 {
78288 - struct compat_group_req __user *gr32 = (void *)optval;
78289 + struct compat_group_req __user *gr32 = (void __user *)optval;
78290 struct group_req __user *kgr =
78291 compat_alloc_user_space(sizeof(struct group_req));
78292 u32 interface;
78293 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78294 case MCAST_BLOCK_SOURCE:
78295 case MCAST_UNBLOCK_SOURCE:
78296 {
78297 - struct compat_group_source_req __user *gsr32 = (void *)optval;
78298 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
78299 struct group_source_req __user *kgsr = compat_alloc_user_space(
78300 sizeof(struct group_source_req));
78301 u32 interface;
78302 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78303 }
78304 case MCAST_MSFILTER:
78305 {
78306 - struct compat_group_filter __user *gf32 = (void *)optval;
78307 + struct compat_group_filter __user *gf32 = (void __user *)optval;
78308 struct group_filter __user *kgf;
78309 u32 interface, fmode, numsrc;
78310
78311 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
78312 char __user *optval, int __user *optlen,
78313 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
78314 {
78315 - struct compat_group_filter __user *gf32 = (void *)optval;
78316 + struct compat_group_filter __user *gf32 = (void __user *)optval;
78317 struct group_filter __user *kgf;
78318 int __user *koptlen;
78319 u32 interface, fmode, numsrc;
78320 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
78321
78322 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
78323 return -EINVAL;
78324 - if (copy_from_user(a, args, nas[call]))
78325 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
78326 return -EFAULT;
78327 a0 = a[0];
78328 a1 = a[1];
78329 diff --git a/net/core/datagram.c b/net/core/datagram.c
78330 index 0337e2b..47914a0 100644
78331 --- a/net/core/datagram.c
78332 +++ b/net/core/datagram.c
78333 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
78334 }
78335
78336 kfree_skb(skb);
78337 - atomic_inc(&sk->sk_drops);
78338 + atomic_inc_unchecked(&sk->sk_drops);
78339 sk_mem_reclaim_partial(sk);
78340
78341 return err;
78342 diff --git a/net/core/dev.c b/net/core/dev.c
78343 index e5942bf..25998c3 100644
78344 --- a/net/core/dev.c
78345 +++ b/net/core/dev.c
78346 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
78347 if (no_module && capable(CAP_NET_ADMIN))
78348 no_module = request_module("netdev-%s", name);
78349 if (no_module && capable(CAP_SYS_MODULE)) {
78350 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
78351 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
78352 +#else
78353 if (!request_module("%s", name))
78354 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
78355 name);
78356 +#endif
78357 }
78358 }
78359 EXPORT_SYMBOL(dev_load);
78360 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
78361 {
78362 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
78363 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
78364 - atomic_long_inc(&dev->rx_dropped);
78365 + atomic_long_inc_unchecked(&dev->rx_dropped);
78366 kfree_skb(skb);
78367 return NET_RX_DROP;
78368 }
78369 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
78370 nf_reset(skb);
78371
78372 if (unlikely(!is_skb_forwardable(dev, skb))) {
78373 - atomic_long_inc(&dev->rx_dropped);
78374 + atomic_long_inc_unchecked(&dev->rx_dropped);
78375 kfree_skb(skb);
78376 return NET_RX_DROP;
78377 }
78378 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
78379
78380 struct dev_gso_cb {
78381 void (*destructor)(struct sk_buff *skb);
78382 -};
78383 +} __no_const;
78384
78385 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
78386
78387 @@ -2955,7 +2959,7 @@ enqueue:
78388
78389 local_irq_restore(flags);
78390
78391 - atomic_long_inc(&skb->dev->rx_dropped);
78392 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
78393 kfree_skb(skb);
78394 return NET_RX_DROP;
78395 }
78396 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
78397 }
78398 EXPORT_SYMBOL(netif_rx_ni);
78399
78400 -static void net_tx_action(struct softirq_action *h)
78401 +static void net_tx_action(void)
78402 {
78403 struct softnet_data *sd = &__get_cpu_var(softnet_data);
78404
78405 @@ -3358,7 +3362,7 @@ ncls:
78406 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
78407 } else {
78408 drop:
78409 - atomic_long_inc(&skb->dev->rx_dropped);
78410 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
78411 kfree_skb(skb);
78412 /* Jamal, now you will not able to escape explaining
78413 * me how you were going to use this. :-)
78414 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
78415 }
78416 EXPORT_SYMBOL(netif_napi_del);
78417
78418 -static void net_rx_action(struct softirq_action *h)
78419 +static void net_rx_action(void)
78420 {
78421 struct softnet_data *sd = &__get_cpu_var(softnet_data);
78422 unsigned long time_limit = jiffies + 2;
78423 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
78424 else
78425 seq_printf(seq, "%04x", ntohs(pt->type));
78426
78427 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78428 + seq_printf(seq, " %-8s %p\n",
78429 + pt->dev ? pt->dev->name : "", NULL);
78430 +#else
78431 seq_printf(seq, " %-8s %pF\n",
78432 pt->dev ? pt->dev->name : "", pt->func);
78433 +#endif
78434 }
78435
78436 return 0;
78437 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
78438 } else {
78439 netdev_stats_to_stats64(storage, &dev->stats);
78440 }
78441 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
78442 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
78443 return storage;
78444 }
78445 EXPORT_SYMBOL(dev_get_stats);
78446 diff --git a/net/core/flow.c b/net/core/flow.c
78447 index e318c7e..168b1d0 100644
78448 --- a/net/core/flow.c
78449 +++ b/net/core/flow.c
78450 @@ -61,7 +61,7 @@ struct flow_cache {
78451 struct timer_list rnd_timer;
78452 };
78453
78454 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
78455 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
78456 EXPORT_SYMBOL(flow_cache_genid);
78457 static struct flow_cache flow_cache_global;
78458 static struct kmem_cache *flow_cachep __read_mostly;
78459 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
78460
78461 static int flow_entry_valid(struct flow_cache_entry *fle)
78462 {
78463 - if (atomic_read(&flow_cache_genid) != fle->genid)
78464 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
78465 return 0;
78466 if (fle->object && !fle->object->ops->check(fle->object))
78467 return 0;
78468 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
78469 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
78470 fcp->hash_count++;
78471 }
78472 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
78473 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
78474 flo = fle->object;
78475 if (!flo)
78476 goto ret_object;
78477 @@ -280,7 +280,7 @@ nocache:
78478 }
78479 flo = resolver(net, key, family, dir, flo, ctx);
78480 if (fle) {
78481 - fle->genid = atomic_read(&flow_cache_genid);
78482 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
78483 if (!IS_ERR(flo))
78484 fle->object = flo;
78485 else
78486 diff --git a/net/core/iovec.c b/net/core/iovec.c
78487 index 7e7aeb0..2a998cb 100644
78488 --- a/net/core/iovec.c
78489 +++ b/net/core/iovec.c
78490 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
78491 if (m->msg_namelen) {
78492 if (mode == VERIFY_READ) {
78493 void __user *namep;
78494 - namep = (void __user __force *) m->msg_name;
78495 + namep = (void __force_user *) m->msg_name;
78496 err = move_addr_to_kernel(namep, m->msg_namelen,
78497 address);
78498 if (err < 0)
78499 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
78500 }
78501
78502 size = m->msg_iovlen * sizeof(struct iovec);
78503 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
78504 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
78505 return -EFAULT;
78506
78507 m->msg_iov = iov;
78508 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
78509 index fad649a..f2fdac4 100644
78510 --- a/net/core/rtnetlink.c
78511 +++ b/net/core/rtnetlink.c
78512 @@ -198,14 +198,16 @@ int __rtnl_register(int protocol, int msgtype,
78513 rtnl_msg_handlers[protocol] = tab;
78514 }
78515
78516 + pax_open_kernel();
78517 if (doit)
78518 - tab[msgindex].doit = doit;
78519 + *(void **)&tab[msgindex].doit = doit;
78520
78521 if (dumpit)
78522 - tab[msgindex].dumpit = dumpit;
78523 + *(void **)&tab[msgindex].dumpit = dumpit;
78524
78525 if (calcit)
78526 - tab[msgindex].calcit = calcit;
78527 + *(void **)&tab[msgindex].calcit = calcit;
78528 + pax_close_kernel();
78529
78530 return 0;
78531 }
78532 @@ -248,8 +250,10 @@ int rtnl_unregister(int protocol, int msgtype)
78533 if (rtnl_msg_handlers[protocol] == NULL)
78534 return -ENOENT;
78535
78536 - rtnl_msg_handlers[protocol][msgindex].doit = NULL;
78537 - rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
78538 + pax_open_kernel();
78539 + *(void **)&rtnl_msg_handlers[protocol][msgindex].doit = NULL;
78540 + *(void **)&rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
78541 + pax_close_kernel();
78542
78543 return 0;
78544 }
78545 diff --git a/net/core/scm.c b/net/core/scm.c
78546 index ab57084..0190c8f 100644
78547 --- a/net/core/scm.c
78548 +++ b/net/core/scm.c
78549 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
78550 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
78551 {
78552 struct cmsghdr __user *cm
78553 - = (__force struct cmsghdr __user *)msg->msg_control;
78554 + = (struct cmsghdr __force_user *)msg->msg_control;
78555 struct cmsghdr cmhdr;
78556 int cmlen = CMSG_LEN(len);
78557 int err;
78558 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
78559 err = -EFAULT;
78560 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
78561 goto out;
78562 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
78563 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
78564 goto out;
78565 cmlen = CMSG_SPACE(len);
78566 if (msg->msg_controllen < cmlen)
78567 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
78568 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
78569 {
78570 struct cmsghdr __user *cm
78571 - = (__force struct cmsghdr __user*)msg->msg_control;
78572 + = (struct cmsghdr __force_user *)msg->msg_control;
78573
78574 int fdmax = 0;
78575 int fdnum = scm->fp->count;
78576 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
78577 if (fdnum < fdmax)
78578 fdmax = fdnum;
78579
78580 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
78581 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
78582 i++, cmfptr++)
78583 {
78584 struct socket *sock;
78585 diff --git a/net/core/sock.c b/net/core/sock.c
78586 index 8a146cf..ee08914d 100644
78587 --- a/net/core/sock.c
78588 +++ b/net/core/sock.c
78589 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78590 struct sk_buff_head *list = &sk->sk_receive_queue;
78591
78592 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
78593 - atomic_inc(&sk->sk_drops);
78594 + atomic_inc_unchecked(&sk->sk_drops);
78595 trace_sock_rcvqueue_full(sk, skb);
78596 return -ENOMEM;
78597 }
78598 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78599 return err;
78600
78601 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
78602 - atomic_inc(&sk->sk_drops);
78603 + atomic_inc_unchecked(&sk->sk_drops);
78604 return -ENOBUFS;
78605 }
78606
78607 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78608 skb_dst_force(skb);
78609
78610 spin_lock_irqsave(&list->lock, flags);
78611 - skb->dropcount = atomic_read(&sk->sk_drops);
78612 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78613 __skb_queue_tail(list, skb);
78614 spin_unlock_irqrestore(&list->lock, flags);
78615
78616 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
78617 skb->dev = NULL;
78618
78619 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
78620 - atomic_inc(&sk->sk_drops);
78621 + atomic_inc_unchecked(&sk->sk_drops);
78622 goto discard_and_relse;
78623 }
78624 if (nested)
78625 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
78626 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
78627 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
78628 bh_unlock_sock(sk);
78629 - atomic_inc(&sk->sk_drops);
78630 + atomic_inc_unchecked(&sk->sk_drops);
78631 goto discard_and_relse;
78632 }
78633
78634 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
78635 struct timeval tm;
78636 } v;
78637
78638 - int lv = sizeof(int);
78639 - int len;
78640 + unsigned int lv = sizeof(int);
78641 + unsigned int len;
78642
78643 if (get_user(len, optlen))
78644 return -EFAULT;
78645 - if (len < 0)
78646 + if (len > INT_MAX)
78647 return -EINVAL;
78648
78649 memset(&v, 0, sizeof(v));
78650 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
78651
78652 case SO_PEERNAME:
78653 {
78654 - char address[128];
78655 + char address[_K_SS_MAXSIZE];
78656
78657 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
78658 return -ENOTCONN;
78659 - if (lv < len)
78660 + if (lv < len || sizeof address < len)
78661 return -EINVAL;
78662 if (copy_to_user(optval, address, len))
78663 return -EFAULT;
78664 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
78665
78666 if (len > lv)
78667 len = lv;
78668 - if (copy_to_user(optval, &v, len))
78669 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
78670 return -EFAULT;
78671 lenout:
78672 if (put_user(len, optlen))
78673 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
78674 */
78675 smp_wmb();
78676 atomic_set(&sk->sk_refcnt, 1);
78677 - atomic_set(&sk->sk_drops, 0);
78678 + atomic_set_unchecked(&sk->sk_drops, 0);
78679 }
78680 EXPORT_SYMBOL(sock_init_data);
78681
78682 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
78683 index 602cd63..05c6c60 100644
78684 --- a/net/core/sock_diag.c
78685 +++ b/net/core/sock_diag.c
78686 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
78687
78688 int sock_diag_check_cookie(void *sk, __u32 *cookie)
78689 {
78690 +#ifndef CONFIG_GRKERNSEC_HIDESYM
78691 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
78692 cookie[1] != INET_DIAG_NOCOOKIE) &&
78693 ((u32)(unsigned long)sk != cookie[0] ||
78694 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
78695 return -ESTALE;
78696 else
78697 +#endif
78698 return 0;
78699 }
78700 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
78701
78702 void sock_diag_save_cookie(void *sk, __u32 *cookie)
78703 {
78704 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78705 + cookie[0] = 0;
78706 + cookie[1] = 0;
78707 +#else
78708 cookie[0] = (u32)(unsigned long)sk;
78709 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
78710 +#endif
78711 }
78712 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
78713
78714 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
78715 index a55eecc..dd8428c 100644
78716 --- a/net/decnet/sysctl_net_decnet.c
78717 +++ b/net/decnet/sysctl_net_decnet.c
78718 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
78719
78720 if (len > *lenp) len = *lenp;
78721
78722 - if (copy_to_user(buffer, addr, len))
78723 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
78724 return -EFAULT;
78725
78726 *lenp = len;
78727 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
78728
78729 if (len > *lenp) len = *lenp;
78730
78731 - if (copy_to_user(buffer, devname, len))
78732 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
78733 return -EFAULT;
78734
78735 *lenp = len;
78736 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
78737 index 2a6abc1..c379ba7 100644
78738 --- a/net/ipv4/devinet.c
78739 +++ b/net/ipv4/devinet.c
78740 @@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
78741 if (!ifa) {
78742 ret = -ENOBUFS;
78743 ifa = inet_alloc_ifa();
78744 + if (!ifa)
78745 + break;
78746 INIT_HLIST_NODE(&ifa->hash);
78747 - if (!ifa)
78748 - break;
78749 if (colon)
78750 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
78751 else
78752 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
78753 index 825c608..750ff29 100644
78754 --- a/net/ipv4/fib_frontend.c
78755 +++ b/net/ipv4/fib_frontend.c
78756 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
78757 #ifdef CONFIG_IP_ROUTE_MULTIPATH
78758 fib_sync_up(dev);
78759 #endif
78760 - atomic_inc(&net->ipv4.dev_addr_genid);
78761 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
78762 rt_cache_flush(dev_net(dev));
78763 break;
78764 case NETDEV_DOWN:
78765 fib_del_ifaddr(ifa, NULL);
78766 - atomic_inc(&net->ipv4.dev_addr_genid);
78767 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
78768 if (ifa->ifa_dev->ifa_list == NULL) {
78769 /* Last address was deleted from this interface.
78770 * Disable IP.
78771 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
78772 #ifdef CONFIG_IP_ROUTE_MULTIPATH
78773 fib_sync_up(dev);
78774 #endif
78775 - atomic_inc(&net->ipv4.dev_addr_genid);
78776 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
78777 rt_cache_flush(net);
78778 break;
78779 case NETDEV_DOWN:
78780 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
78781 index 71b125c..f4c70b0 100644
78782 --- a/net/ipv4/fib_semantics.c
78783 +++ b/net/ipv4/fib_semantics.c
78784 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
78785 nh->nh_saddr = inet_select_addr(nh->nh_dev,
78786 nh->nh_gw,
78787 nh->nh_parent->fib_scope);
78788 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
78789 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
78790
78791 return nh->nh_saddr;
78792 }
78793 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
78794 index 7880af9..70f92a3 100644
78795 --- a/net/ipv4/inet_hashtables.c
78796 +++ b/net/ipv4/inet_hashtables.c
78797 @@ -18,12 +18,15 @@
78798 #include <linux/sched.h>
78799 #include <linux/slab.h>
78800 #include <linux/wait.h>
78801 +#include <linux/security.h>
78802
78803 #include <net/inet_connection_sock.h>
78804 #include <net/inet_hashtables.h>
78805 #include <net/secure_seq.h>
78806 #include <net/ip.h>
78807
78808 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
78809 +
78810 /*
78811 * Allocate and initialize a new local port bind bucket.
78812 * The bindhash mutex for snum's hash chain must be held here.
78813 @@ -530,6 +533,8 @@ ok:
78814 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
78815 spin_unlock(&head->lock);
78816
78817 + gr_update_task_in_ip_table(current, inet_sk(sk));
78818 +
78819 if (tw) {
78820 inet_twsk_deschedule(tw, death_row);
78821 while (twrefcnt) {
78822 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
78823 index 000e3d2..5472da3 100644
78824 --- a/net/ipv4/inetpeer.c
78825 +++ b/net/ipv4/inetpeer.c
78826 @@ -503,8 +503,8 @@ relookup:
78827 if (p) {
78828 p->daddr = *daddr;
78829 atomic_set(&p->refcnt, 1);
78830 - atomic_set(&p->rid, 0);
78831 - atomic_set(&p->ip_id_count,
78832 + atomic_set_unchecked(&p->rid, 0);
78833 + atomic_set_unchecked(&p->ip_id_count,
78834 (daddr->family == AF_INET) ?
78835 secure_ip_id(daddr->addr.a4) :
78836 secure_ipv6_id(daddr->addr.a6));
78837 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
78838 index 8d5cc75..821fd11 100644
78839 --- a/net/ipv4/ip_fragment.c
78840 +++ b/net/ipv4/ip_fragment.c
78841 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
78842 return 0;
78843
78844 start = qp->rid;
78845 - end = atomic_inc_return(&peer->rid);
78846 + end = atomic_inc_return_unchecked(&peer->rid);
78847 qp->rid = end;
78848
78849 rc = qp->q.fragments && (end - start) > max;
78850 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
78851 index 14bbfcf..644f472 100644
78852 --- a/net/ipv4/ip_sockglue.c
78853 +++ b/net/ipv4/ip_sockglue.c
78854 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
78855 len = min_t(unsigned int, len, opt->optlen);
78856 if (put_user(len, optlen))
78857 return -EFAULT;
78858 - if (copy_to_user(optval, opt->__data, len))
78859 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
78860 + copy_to_user(optval, opt->__data, len))
78861 return -EFAULT;
78862 return 0;
78863 }
78864 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
78865 if (sk->sk_type != SOCK_STREAM)
78866 return -ENOPROTOOPT;
78867
78868 - msg.msg_control = optval;
78869 + msg.msg_control = (void __force_kernel *)optval;
78870 msg.msg_controllen = len;
78871 msg.msg_flags = flags;
78872
78873 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
78874 index 798358b..73570b7 100644
78875 --- a/net/ipv4/ipconfig.c
78876 +++ b/net/ipv4/ipconfig.c
78877 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
78878
78879 mm_segment_t oldfs = get_fs();
78880 set_fs(get_ds());
78881 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
78882 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
78883 set_fs(oldfs);
78884 return res;
78885 }
78886 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
78887
78888 mm_segment_t oldfs = get_fs();
78889 set_fs(get_ds());
78890 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
78891 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
78892 set_fs(oldfs);
78893 return res;
78894 }
78895 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
78896
78897 mm_segment_t oldfs = get_fs();
78898 set_fs(get_ds());
78899 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
78900 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
78901 set_fs(oldfs);
78902 return res;
78903 }
78904 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
78905 index 97e61ea..cac1bbb 100644
78906 --- a/net/ipv4/netfilter/arp_tables.c
78907 +++ b/net/ipv4/netfilter/arp_tables.c
78908 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
78909 #endif
78910
78911 static int get_info(struct net *net, void __user *user,
78912 - const int *len, int compat)
78913 + int len, int compat)
78914 {
78915 char name[XT_TABLE_MAXNAMELEN];
78916 struct xt_table *t;
78917 int ret;
78918
78919 - if (*len != sizeof(struct arpt_getinfo)) {
78920 - duprintf("length %u != %Zu\n", *len,
78921 + if (len != sizeof(struct arpt_getinfo)) {
78922 + duprintf("length %u != %Zu\n", len,
78923 sizeof(struct arpt_getinfo));
78924 return -EINVAL;
78925 }
78926 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
78927 info.size = private->size;
78928 strcpy(info.name, name);
78929
78930 - if (copy_to_user(user, &info, *len) != 0)
78931 + if (copy_to_user(user, &info, len) != 0)
78932 ret = -EFAULT;
78933 else
78934 ret = 0;
78935 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
78936
78937 switch (cmd) {
78938 case ARPT_SO_GET_INFO:
78939 - ret = get_info(sock_net(sk), user, len, 1);
78940 + ret = get_info(sock_net(sk), user, *len, 1);
78941 break;
78942 case ARPT_SO_GET_ENTRIES:
78943 ret = compat_get_entries(sock_net(sk), user, len);
78944 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
78945
78946 switch (cmd) {
78947 case ARPT_SO_GET_INFO:
78948 - ret = get_info(sock_net(sk), user, len, 0);
78949 + ret = get_info(sock_net(sk), user, *len, 0);
78950 break;
78951
78952 case ARPT_SO_GET_ENTRIES:
78953 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
78954 index 170b1fd..6105b91 100644
78955 --- a/net/ipv4/netfilter/ip_tables.c
78956 +++ b/net/ipv4/netfilter/ip_tables.c
78957 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
78958 #endif
78959
78960 static int get_info(struct net *net, void __user *user,
78961 - const int *len, int compat)
78962 + int len, int compat)
78963 {
78964 char name[XT_TABLE_MAXNAMELEN];
78965 struct xt_table *t;
78966 int ret;
78967
78968 - if (*len != sizeof(struct ipt_getinfo)) {
78969 - duprintf("length %u != %zu\n", *len,
78970 + if (len != sizeof(struct ipt_getinfo)) {
78971 + duprintf("length %u != %zu\n", len,
78972 sizeof(struct ipt_getinfo));
78973 return -EINVAL;
78974 }
78975 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
78976 info.size = private->size;
78977 strcpy(info.name, name);
78978
78979 - if (copy_to_user(user, &info, *len) != 0)
78980 + if (copy_to_user(user, &info, len) != 0)
78981 ret = -EFAULT;
78982 else
78983 ret = 0;
78984 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78985
78986 switch (cmd) {
78987 case IPT_SO_GET_INFO:
78988 - ret = get_info(sock_net(sk), user, len, 1);
78989 + ret = get_info(sock_net(sk), user, *len, 1);
78990 break;
78991 case IPT_SO_GET_ENTRIES:
78992 ret = compat_get_entries(sock_net(sk), user, len);
78993 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78994
78995 switch (cmd) {
78996 case IPT_SO_GET_INFO:
78997 - ret = get_info(sock_net(sk), user, len, 0);
78998 + ret = get_info(sock_net(sk), user, *len, 0);
78999 break;
79000
79001 case IPT_SO_GET_ENTRIES:
79002 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79003 index 8f3d054..c58d05d 100644
79004 --- a/net/ipv4/ping.c
79005 +++ b/net/ipv4/ping.c
79006 @@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79007 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79008 0, sock_i_ino(sp),
79009 atomic_read(&sp->sk_refcnt), sp,
79010 - atomic_read(&sp->sk_drops), len);
79011 + atomic_read_unchecked(&sp->sk_drops), len);
79012 }
79013
79014 static int ping_seq_show(struct seq_file *seq, void *v)
79015 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79016 index 73d1e4d..3af0e8f 100644
79017 --- a/net/ipv4/raw.c
79018 +++ b/net/ipv4/raw.c
79019 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79020 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79021 {
79022 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79023 - atomic_inc(&sk->sk_drops);
79024 + atomic_inc_unchecked(&sk->sk_drops);
79025 kfree_skb(skb);
79026 return NET_RX_DROP;
79027 }
79028 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79029
79030 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79031 {
79032 + struct icmp_filter filter;
79033 +
79034 if (optlen > sizeof(struct icmp_filter))
79035 optlen = sizeof(struct icmp_filter);
79036 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79037 + if (copy_from_user(&filter, optval, optlen))
79038 return -EFAULT;
79039 + raw_sk(sk)->filter = filter;
79040 return 0;
79041 }
79042
79043 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79044 {
79045 int len, ret = -EFAULT;
79046 + struct icmp_filter filter;
79047
79048 if (get_user(len, optlen))
79049 goto out;
79050 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79051 if (len > sizeof(struct icmp_filter))
79052 len = sizeof(struct icmp_filter);
79053 ret = -EFAULT;
79054 - if (put_user(len, optlen) ||
79055 - copy_to_user(optval, &raw_sk(sk)->filter, len))
79056 + filter = raw_sk(sk)->filter;
79057 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79058 goto out;
79059 ret = 0;
79060 out: return ret;
79061 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79062 0, 0L, 0,
79063 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79064 0, sock_i_ino(sp),
79065 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79066 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79067 }
79068
79069 static int raw_seq_show(struct seq_file *seq, void *v)
79070 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79071 index df25142..e92a82a 100644
79072 --- a/net/ipv4/route.c
79073 +++ b/net/ipv4/route.c
79074 @@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79075
79076 static __net_init int rt_genid_init(struct net *net)
79077 {
79078 - atomic_set(&net->rt_genid, 0);
79079 + atomic_set_unchecked(&net->rt_genid, 0);
79080 get_random_bytes(&net->ipv4.dev_addr_genid,
79081 sizeof(net->ipv4.dev_addr_genid));
79082 return 0;
79083 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
79084 index 181fc82..cc95f8c 100644
79085 --- a/net/ipv4/tcp_input.c
79086 +++ b/net/ipv4/tcp_input.c
79087 @@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
79088 * simplifies code)
79089 */
79090 static void
79091 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79092 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79093 struct sk_buff *head, struct sk_buff *tail,
79094 u32 start, u32 end)
79095 {
79096 @@ -5536,6 +5536,9 @@ slow_path:
79097 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
79098 goto csum_error;
79099
79100 + if (!th->ack)
79101 + goto discard;
79102 +
79103 /*
79104 * Standard slow path.
79105 */
79106 @@ -5544,7 +5547,7 @@ slow_path:
79107 return 0;
79108
79109 step5:
79110 - if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79111 + if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79112 goto discard;
79113
79114 /* ts_recent update must be made after we are sure that the packet
79115 @@ -5836,6 +5839,7 @@ discard:
79116 tcp_paws_reject(&tp->rx_opt, 0))
79117 goto discard_and_undo;
79118
79119 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
79120 if (th->syn) {
79121 /* We see SYN without ACK. It is attempt of
79122 * simultaneous connect with crossed SYNs.
79123 @@ -5886,6 +5890,7 @@ discard:
79124 goto discard;
79125 #endif
79126 }
79127 +#endif
79128 /* "fifth, if neither of the SYN or RST bits is set then
79129 * drop the segment and return."
79130 */
79131 @@ -5930,7 +5935,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79132 goto discard;
79133
79134 if (th->syn) {
79135 - if (th->fin)
79136 + if (th->fin || th->urg || th->psh)
79137 goto discard;
79138 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
79139 return 1;
79140 @@ -5977,11 +5982,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79141 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
79142 goto discard;
79143 }
79144 +
79145 + if (!th->ack)
79146 + goto discard;
79147 +
79148 if (!tcp_validate_incoming(sk, skb, th, 0))
79149 return 0;
79150
79151 /* step 5: check the ACK field */
79152 - if (th->ack) {
79153 + if (true) {
79154 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
79155
79156 switch (sk->sk_state) {
79157 @@ -6131,8 +6140,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79158 }
79159 break;
79160 }
79161 - } else
79162 - goto discard;
79163 + }
79164
79165 /* ts_recent update must be made after we are sure that the packet
79166 * is in window.
79167 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
79168 index bc3cb46..815ccd6 100644
79169 --- a/net/ipv4/tcp_ipv4.c
79170 +++ b/net/ipv4/tcp_ipv4.c
79171 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
79172 EXPORT_SYMBOL(sysctl_tcp_low_latency);
79173
79174
79175 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79176 +extern int grsec_enable_blackhole;
79177 +#endif
79178 +
79179 #ifdef CONFIG_TCP_MD5SIG
79180 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
79181 __be32 daddr, __be32 saddr, const struct tcphdr *th);
79182 @@ -1899,6 +1903,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
79183 return 0;
79184
79185 reset:
79186 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79187 + if (!grsec_enable_blackhole)
79188 +#endif
79189 tcp_v4_send_reset(rsk, skb);
79190 discard:
79191 kfree_skb(skb);
79192 @@ -1999,12 +2006,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
79193 TCP_SKB_CB(skb)->sacked = 0;
79194
79195 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
79196 - if (!sk)
79197 + if (!sk) {
79198 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79199 + ret = 1;
79200 +#endif
79201 goto no_tcp_socket;
79202 -
79203 + }
79204 process:
79205 - if (sk->sk_state == TCP_TIME_WAIT)
79206 + if (sk->sk_state == TCP_TIME_WAIT) {
79207 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79208 + ret = 2;
79209 +#endif
79210 goto do_time_wait;
79211 + }
79212
79213 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
79214 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
79215 @@ -2055,6 +2069,10 @@ no_tcp_socket:
79216 bad_packet:
79217 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
79218 } else {
79219 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79220 + if (!grsec_enable_blackhole || (ret == 1 &&
79221 + (skb->dev->flags & IFF_LOOPBACK)))
79222 +#endif
79223 tcp_v4_send_reset(NULL, skb);
79224 }
79225
79226 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
79227 index a7302d9..e3ec754 100644
79228 --- a/net/ipv4/tcp_minisocks.c
79229 +++ b/net/ipv4/tcp_minisocks.c
79230 @@ -27,6 +27,10 @@
79231 #include <net/inet_common.h>
79232 #include <net/xfrm.h>
79233
79234 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79235 +extern int grsec_enable_blackhole;
79236 +#endif
79237 +
79238 int sysctl_tcp_syncookies __read_mostly = 1;
79239 EXPORT_SYMBOL(sysctl_tcp_syncookies);
79240
79241 @@ -742,7 +746,10 @@ embryonic_reset:
79242 * avoid becoming vulnerable to outside attack aiming at
79243 * resetting legit local connections.
79244 */
79245 - req->rsk_ops->send_reset(sk, skb);
79246 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79247 + if (!grsec_enable_blackhole)
79248 +#endif
79249 + req->rsk_ops->send_reset(sk, skb);
79250 } else if (fastopen) { /* received a valid RST pkt */
79251 reqsk_fastopen_remove(sk, req, true);
79252 tcp_reset(sk);
79253 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
79254 index 4526fe6..1a34e43 100644
79255 --- a/net/ipv4/tcp_probe.c
79256 +++ b/net/ipv4/tcp_probe.c
79257 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
79258 if (cnt + width >= len)
79259 break;
79260
79261 - if (copy_to_user(buf + cnt, tbuf, width))
79262 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
79263 return -EFAULT;
79264 cnt += width;
79265 }
79266 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
79267 index d47c1b4..b0584de 100644
79268 --- a/net/ipv4/tcp_timer.c
79269 +++ b/net/ipv4/tcp_timer.c
79270 @@ -22,6 +22,10 @@
79271 #include <linux/gfp.h>
79272 #include <net/tcp.h>
79273
79274 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79275 +extern int grsec_lastack_retries;
79276 +#endif
79277 +
79278 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
79279 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
79280 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
79281 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
79282 }
79283 }
79284
79285 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79286 + if ((sk->sk_state == TCP_LAST_ACK) &&
79287 + (grsec_lastack_retries > 0) &&
79288 + (grsec_lastack_retries < retry_until))
79289 + retry_until = grsec_lastack_retries;
79290 +#endif
79291 +
79292 if (retransmits_timed_out(sk, retry_until,
79293 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
79294 /* Has it gone just too far? */
79295 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
79296 index 79c8dbe..aceb1b6 100644
79297 --- a/net/ipv4/udp.c
79298 +++ b/net/ipv4/udp.c
79299 @@ -87,6 +87,7 @@
79300 #include <linux/types.h>
79301 #include <linux/fcntl.h>
79302 #include <linux/module.h>
79303 +#include <linux/security.h>
79304 #include <linux/socket.h>
79305 #include <linux/sockios.h>
79306 #include <linux/igmp.h>
79307 @@ -111,6 +112,10 @@
79308 #include <trace/events/skb.h>
79309 #include "udp_impl.h"
79310
79311 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79312 +extern int grsec_enable_blackhole;
79313 +#endif
79314 +
79315 struct udp_table udp_table __read_mostly;
79316 EXPORT_SYMBOL(udp_table);
79317
79318 @@ -569,6 +574,9 @@ found:
79319 return s;
79320 }
79321
79322 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
79323 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
79324 +
79325 /*
79326 * This routine is called by the ICMP module when it gets some
79327 * sort of error condition. If err < 0 then the socket should
79328 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
79329 dport = usin->sin_port;
79330 if (dport == 0)
79331 return -EINVAL;
79332 +
79333 + err = gr_search_udp_sendmsg(sk, usin);
79334 + if (err)
79335 + return err;
79336 } else {
79337 if (sk->sk_state != TCP_ESTABLISHED)
79338 return -EDESTADDRREQ;
79339 +
79340 + err = gr_search_udp_sendmsg(sk, NULL);
79341 + if (err)
79342 + return err;
79343 +
79344 daddr = inet->inet_daddr;
79345 dport = inet->inet_dport;
79346 /* Open fast path for connected socket.
79347 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
79348 udp_lib_checksum_complete(skb)) {
79349 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79350 IS_UDPLITE(sk));
79351 - atomic_inc(&sk->sk_drops);
79352 + atomic_inc_unchecked(&sk->sk_drops);
79353 __skb_unlink(skb, rcvq);
79354 __skb_queue_tail(&list_kill, skb);
79355 }
79356 @@ -1194,6 +1211,10 @@ try_again:
79357 if (!skb)
79358 goto out;
79359
79360 + err = gr_search_udp_recvmsg(sk, skb);
79361 + if (err)
79362 + goto out_free;
79363 +
79364 ulen = skb->len - sizeof(struct udphdr);
79365 copied = len;
79366 if (copied > ulen)
79367 @@ -1227,7 +1248,7 @@ try_again:
79368 if (unlikely(err)) {
79369 trace_kfree_skb(skb, udp_recvmsg);
79370 if (!peeked) {
79371 - atomic_inc(&sk->sk_drops);
79372 + atomic_inc_unchecked(&sk->sk_drops);
79373 UDP_INC_STATS_USER(sock_net(sk),
79374 UDP_MIB_INERRORS, is_udplite);
79375 }
79376 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79377
79378 drop:
79379 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
79380 - atomic_inc(&sk->sk_drops);
79381 + atomic_inc_unchecked(&sk->sk_drops);
79382 kfree_skb(skb);
79383 return -1;
79384 }
79385 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
79386 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
79387
79388 if (!skb1) {
79389 - atomic_inc(&sk->sk_drops);
79390 + atomic_inc_unchecked(&sk->sk_drops);
79391 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
79392 IS_UDPLITE(sk));
79393 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79394 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
79395 goto csum_error;
79396
79397 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
79398 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79399 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
79400 +#endif
79401 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
79402
79403 /*
79404 @@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
79405 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79406 0, sock_i_ino(sp),
79407 atomic_read(&sp->sk_refcnt), sp,
79408 - atomic_read(&sp->sk_drops), len);
79409 + atomic_read_unchecked(&sp->sk_drops), len);
79410 }
79411
79412 int udp4_seq_show(struct seq_file *seq, void *v)
79413 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
79414 index 0424e4e..308dd43 100644
79415 --- a/net/ipv6/addrconf.c
79416 +++ b/net/ipv6/addrconf.c
79417 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
79418 p.iph.ihl = 5;
79419 p.iph.protocol = IPPROTO_IPV6;
79420 p.iph.ttl = 64;
79421 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
79422 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
79423
79424 if (ops->ndo_do_ioctl) {
79425 mm_segment_t oldfs = get_fs();
79426 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
79427 index d5cb3c4..b3e38d0 100644
79428 --- a/net/ipv6/ip6_gre.c
79429 +++ b/net/ipv6/ip6_gre.c
79430 @@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
79431 }
79432
79433
79434 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
79435 +static struct inet6_protocol ip6gre_protocol = {
79436 .handler = ip6gre_rcv,
79437 .err_handler = ip6gre_err,
79438 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
79439 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
79440 index e02faed..9780f28 100644
79441 --- a/net/ipv6/ipv6_sockglue.c
79442 +++ b/net/ipv6/ipv6_sockglue.c
79443 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
79444 if (sk->sk_type != SOCK_STREAM)
79445 return -ENOPROTOOPT;
79446
79447 - msg.msg_control = optval;
79448 + msg.msg_control = (void __force_kernel *)optval;
79449 msg.msg_controllen = len;
79450 msg.msg_flags = flags;
79451
79452 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
79453 index d7cb045..8c0ded6 100644
79454 --- a/net/ipv6/netfilter/ip6_tables.c
79455 +++ b/net/ipv6/netfilter/ip6_tables.c
79456 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
79457 #endif
79458
79459 static int get_info(struct net *net, void __user *user,
79460 - const int *len, int compat)
79461 + int len, int compat)
79462 {
79463 char name[XT_TABLE_MAXNAMELEN];
79464 struct xt_table *t;
79465 int ret;
79466
79467 - if (*len != sizeof(struct ip6t_getinfo)) {
79468 - duprintf("length %u != %zu\n", *len,
79469 + if (len != sizeof(struct ip6t_getinfo)) {
79470 + duprintf("length %u != %zu\n", len,
79471 sizeof(struct ip6t_getinfo));
79472 return -EINVAL;
79473 }
79474 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
79475 info.size = private->size;
79476 strcpy(info.name, name);
79477
79478 - if (copy_to_user(user, &info, *len) != 0)
79479 + if (copy_to_user(user, &info, len) != 0)
79480 ret = -EFAULT;
79481 else
79482 ret = 0;
79483 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79484
79485 switch (cmd) {
79486 case IP6T_SO_GET_INFO:
79487 - ret = get_info(sock_net(sk), user, len, 1);
79488 + ret = get_info(sock_net(sk), user, *len, 1);
79489 break;
79490 case IP6T_SO_GET_ENTRIES:
79491 ret = compat_get_entries(sock_net(sk), user, len);
79492 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79493
79494 switch (cmd) {
79495 case IP6T_SO_GET_INFO:
79496 - ret = get_info(sock_net(sk), user, len, 0);
79497 + ret = get_info(sock_net(sk), user, *len, 0);
79498 break;
79499
79500 case IP6T_SO_GET_ENTRIES:
79501 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
79502 index d8e95c7..81422bc 100644
79503 --- a/net/ipv6/raw.c
79504 +++ b/net/ipv6/raw.c
79505 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
79506 {
79507 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
79508 skb_checksum_complete(skb)) {
79509 - atomic_inc(&sk->sk_drops);
79510 + atomic_inc_unchecked(&sk->sk_drops);
79511 kfree_skb(skb);
79512 return NET_RX_DROP;
79513 }
79514 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
79515 struct raw6_sock *rp = raw6_sk(sk);
79516
79517 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
79518 - atomic_inc(&sk->sk_drops);
79519 + atomic_inc_unchecked(&sk->sk_drops);
79520 kfree_skb(skb);
79521 return NET_RX_DROP;
79522 }
79523 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
79524
79525 if (inet->hdrincl) {
79526 if (skb_checksum_complete(skb)) {
79527 - atomic_inc(&sk->sk_drops);
79528 + atomic_inc_unchecked(&sk->sk_drops);
79529 kfree_skb(skb);
79530 return NET_RX_DROP;
79531 }
79532 @@ -604,7 +604,7 @@ out:
79533 return err;
79534 }
79535
79536 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
79537 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
79538 struct flowi6 *fl6, struct dst_entry **dstp,
79539 unsigned int flags)
79540 {
79541 @@ -916,12 +916,15 @@ do_confirm:
79542 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
79543 char __user *optval, int optlen)
79544 {
79545 + struct icmp6_filter filter;
79546 +
79547 switch (optname) {
79548 case ICMPV6_FILTER:
79549 if (optlen > sizeof(struct icmp6_filter))
79550 optlen = sizeof(struct icmp6_filter);
79551 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
79552 + if (copy_from_user(&filter, optval, optlen))
79553 return -EFAULT;
79554 + raw6_sk(sk)->filter = filter;
79555 return 0;
79556 default:
79557 return -ENOPROTOOPT;
79558 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
79559 char __user *optval, int __user *optlen)
79560 {
79561 int len;
79562 + struct icmp6_filter filter;
79563
79564 switch (optname) {
79565 case ICMPV6_FILTER:
79566 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
79567 len = sizeof(struct icmp6_filter);
79568 if (put_user(len, optlen))
79569 return -EFAULT;
79570 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
79571 + filter = raw6_sk(sk)->filter;
79572 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
79573 return -EFAULT;
79574 return 0;
79575 default:
79576 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79577 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79578 0,
79579 sock_i_ino(sp),
79580 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79581 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79582 }
79583
79584 static int raw6_seq_show(struct seq_file *seq, void *v)
79585 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
79586 index 73f2a6b..f8049a1 100644
79587 --- a/net/ipv6/tcp_ipv6.c
79588 +++ b/net/ipv6/tcp_ipv6.c
79589 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
79590 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
79591 }
79592
79593 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79594 +extern int grsec_enable_blackhole;
79595 +#endif
79596 +
79597 static void tcp_v6_hash(struct sock *sk)
79598 {
79599 if (sk->sk_state != TCP_CLOSE) {
79600 @@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
79601 return 0;
79602
79603 reset:
79604 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79605 + if (!grsec_enable_blackhole)
79606 +#endif
79607 tcp_v6_send_reset(sk, skb);
79608 discard:
79609 if (opt_skb)
79610 @@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
79611 TCP_SKB_CB(skb)->sacked = 0;
79612
79613 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
79614 - if (!sk)
79615 + if (!sk) {
79616 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79617 + ret = 1;
79618 +#endif
79619 goto no_tcp_socket;
79620 + }
79621
79622 process:
79623 - if (sk->sk_state == TCP_TIME_WAIT)
79624 + if (sk->sk_state == TCP_TIME_WAIT) {
79625 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79626 + ret = 2;
79627 +#endif
79628 goto do_time_wait;
79629 + }
79630
79631 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
79632 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
79633 @@ -1660,6 +1675,10 @@ no_tcp_socket:
79634 bad_packet:
79635 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
79636 } else {
79637 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79638 + if (!grsec_enable_blackhole || (ret == 1 &&
79639 + (skb->dev->flags & IFF_LOOPBACK)))
79640 +#endif
79641 tcp_v6_send_reset(NULL, skb);
79642 }
79643
79644 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
79645 index fc99972..69397e8 100644
79646 --- a/net/ipv6/udp.c
79647 +++ b/net/ipv6/udp.c
79648 @@ -51,6 +51,10 @@
79649 #include <trace/events/skb.h>
79650 #include "udp_impl.h"
79651
79652 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79653 +extern int grsec_enable_blackhole;
79654 +#endif
79655 +
79656 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
79657 {
79658 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
79659 @@ -395,7 +399,7 @@ try_again:
79660 if (unlikely(err)) {
79661 trace_kfree_skb(skb, udpv6_recvmsg);
79662 if (!peeked) {
79663 - atomic_inc(&sk->sk_drops);
79664 + atomic_inc_unchecked(&sk->sk_drops);
79665 if (is_udp4)
79666 UDP_INC_STATS_USER(sock_net(sk),
79667 UDP_MIB_INERRORS,
79668 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79669 return rc;
79670 drop:
79671 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
79672 - atomic_inc(&sk->sk_drops);
79673 + atomic_inc_unchecked(&sk->sk_drops);
79674 kfree_skb(skb);
79675 return -1;
79676 }
79677 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
79678 if (likely(skb1 == NULL))
79679 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
79680 if (!skb1) {
79681 - atomic_inc(&sk->sk_drops);
79682 + atomic_inc_unchecked(&sk->sk_drops);
79683 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
79684 IS_UDPLITE(sk));
79685 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79686 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
79687 goto discard;
79688
79689 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
79690 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79691 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
79692 +#endif
79693 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
79694
79695 kfree_skb(skb);
79696 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
79697 0,
79698 sock_i_ino(sp),
79699 atomic_read(&sp->sk_refcnt), sp,
79700 - atomic_read(&sp->sk_drops));
79701 + atomic_read_unchecked(&sp->sk_drops));
79702 }
79703
79704 int udp6_seq_show(struct seq_file *seq, void *v)
79705 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
79706 index 496ce2c..f79fac8 100644
79707 --- a/net/irda/ircomm/ircomm_tty.c
79708 +++ b/net/irda/ircomm/ircomm_tty.c
79709 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
79710 add_wait_queue(&port->open_wait, &wait);
79711
79712 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
79713 - __FILE__, __LINE__, tty->driver->name, port->count);
79714 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
79715
79716 spin_lock_irqsave(&port->lock, flags);
79717 if (!tty_hung_up_p(filp)) {
79718 extra_count = 1;
79719 - port->count--;
79720 + atomic_dec(&port->count);
79721 }
79722 spin_unlock_irqrestore(&port->lock, flags);
79723 port->blocked_open++;
79724 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
79725 }
79726
79727 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
79728 - __FILE__, __LINE__, tty->driver->name, port->count);
79729 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
79730
79731 schedule();
79732 }
79733 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
79734 if (extra_count) {
79735 /* ++ is not atomic, so this should be protected - Jean II */
79736 spin_lock_irqsave(&port->lock, flags);
79737 - port->count++;
79738 + atomic_inc(&port->count);
79739 spin_unlock_irqrestore(&port->lock, flags);
79740 }
79741 port->blocked_open--;
79742
79743 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
79744 - __FILE__, __LINE__, tty->driver->name, port->count);
79745 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
79746
79747 if (!retval)
79748 port->flags |= ASYNC_NORMAL_ACTIVE;
79749 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
79750
79751 /* ++ is not atomic, so this should be protected - Jean II */
79752 spin_lock_irqsave(&self->port.lock, flags);
79753 - self->port.count++;
79754 + atomic_inc(&self->port.count);
79755 spin_unlock_irqrestore(&self->port.lock, flags);
79756 tty_port_tty_set(&self->port, tty);
79757
79758 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
79759 - self->line, self->port.count);
79760 + self->line, atomic_read(&self->port.count));
79761
79762 /* Not really used by us, but lets do it anyway */
79763 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
79764 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
79765 tty_kref_put(port->tty);
79766 }
79767 port->tty = NULL;
79768 - port->count = 0;
79769 + atomic_set(&port->count, 0);
79770 spin_unlock_irqrestore(&port->lock, flags);
79771
79772 wake_up_interruptible(&port->open_wait);
79773 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
79774 seq_putc(m, '\n');
79775
79776 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
79777 - seq_printf(m, "Open count: %d\n", self->port.count);
79778 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
79779 seq_printf(m, "Max data size: %d\n", self->max_data_size);
79780 seq_printf(m, "Max header size: %d\n", self->max_header_size);
79781
79782 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
79783 index cd6f7a9..e63fe89 100644
79784 --- a/net/iucv/af_iucv.c
79785 +++ b/net/iucv/af_iucv.c
79786 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
79787
79788 write_lock_bh(&iucv_sk_list.lock);
79789
79790 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
79791 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
79792 while (__iucv_get_sock_by_name(name)) {
79793 sprintf(name, "%08x",
79794 - atomic_inc_return(&iucv_sk_list.autobind_name));
79795 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
79796 }
79797
79798 write_unlock_bh(&iucv_sk_list.lock);
79799 diff --git a/net/key/af_key.c b/net/key/af_key.c
79800 index 08897a3..0b812ab 100644
79801 --- a/net/key/af_key.c
79802 +++ b/net/key/af_key.c
79803 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
79804 static u32 get_acqseq(void)
79805 {
79806 u32 res;
79807 - static atomic_t acqseq;
79808 + static atomic_unchecked_t acqseq;
79809
79810 do {
79811 - res = atomic_inc_return(&acqseq);
79812 + res = atomic_inc_return_unchecked(&acqseq);
79813 } while (!res);
79814 return res;
79815 }
79816 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
79817 index 7371f67..9897314 100644
79818 --- a/net/mac80211/cfg.c
79819 +++ b/net/mac80211/cfg.c
79820 @@ -2594,7 +2594,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
79821 else
79822 local->probe_req_reg--;
79823
79824 - if (!local->open_count)
79825 + if (!local_read(&local->open_count))
79826 break;
79827
79828 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
79829 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
79830 index 3da215c..497a6e3 100644
79831 --- a/net/mac80211/ieee80211_i.h
79832 +++ b/net/mac80211/ieee80211_i.h
79833 @@ -28,6 +28,7 @@
79834 #include <net/ieee80211_radiotap.h>
79835 #include <net/cfg80211.h>
79836 #include <net/mac80211.h>
79837 +#include <asm/local.h>
79838 #include "key.h"
79839 #include "sta_info.h"
79840 #include "debug.h"
79841 @@ -852,7 +853,7 @@ struct ieee80211_local {
79842 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
79843 spinlock_t queue_stop_reason_lock;
79844
79845 - int open_count;
79846 + local_t open_count;
79847 int monitors, cooked_mntrs;
79848 /* number of interfaces with corresponding FIF_ flags */
79849 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
79850 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
79851 index 0f5af91..4dba9e7 100644
79852 --- a/net/mac80211/iface.c
79853 +++ b/net/mac80211/iface.c
79854 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
79855 break;
79856 }
79857
79858 - if (local->open_count == 0) {
79859 + if (local_read(&local->open_count) == 0) {
79860 res = drv_start(local);
79861 if (res)
79862 goto err_del_bss;
79863 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
79864 break;
79865 }
79866
79867 - if (local->monitors == 0 && local->open_count == 0) {
79868 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
79869 res = ieee80211_add_virtual_monitor(local);
79870 if (res)
79871 goto err_stop;
79872 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
79873 mutex_unlock(&local->mtx);
79874
79875 if (coming_up)
79876 - local->open_count++;
79877 + local_inc(&local->open_count);
79878
79879 if (hw_reconf_flags)
79880 ieee80211_hw_config(local, hw_reconf_flags);
79881 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
79882 err_del_interface:
79883 drv_remove_interface(local, sdata);
79884 err_stop:
79885 - if (!local->open_count)
79886 + if (!local_read(&local->open_count))
79887 drv_stop(local);
79888 err_del_bss:
79889 sdata->bss = NULL;
79890 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
79891 }
79892
79893 if (going_down)
79894 - local->open_count--;
79895 + local_dec(&local->open_count);
79896
79897 switch (sdata->vif.type) {
79898 case NL80211_IFTYPE_AP_VLAN:
79899 @@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
79900
79901 ieee80211_recalc_ps(local, -1);
79902
79903 - if (local->open_count == 0) {
79904 + if (local_read(&local->open_count) == 0) {
79905 if (local->ops->napi_poll)
79906 napi_disable(&local->napi);
79907 ieee80211_clear_tx_pending(local);
79908 @@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
79909 }
79910 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
79911
79912 - if (local->monitors == local->open_count && local->monitors > 0)
79913 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
79914 ieee80211_add_virtual_monitor(local);
79915 }
79916
79917 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
79918 index f57f597..e0a7c03 100644
79919 --- a/net/mac80211/main.c
79920 +++ b/net/mac80211/main.c
79921 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
79922 local->hw.conf.power_level = power;
79923 }
79924
79925 - if (changed && local->open_count) {
79926 + if (changed && local_read(&local->open_count)) {
79927 ret = drv_config(local, changed);
79928 /*
79929 * Goal:
79930 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
79931 index 5c572e7..ecf75ce 100644
79932 --- a/net/mac80211/pm.c
79933 +++ b/net/mac80211/pm.c
79934 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
79935 struct ieee80211_sub_if_data *sdata;
79936 struct sta_info *sta;
79937
79938 - if (!local->open_count)
79939 + if (!local_read(&local->open_count))
79940 goto suspend;
79941
79942 ieee80211_scan_cancel(local);
79943 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
79944 cancel_work_sync(&local->dynamic_ps_enable_work);
79945 del_timer_sync(&local->dynamic_ps_timer);
79946
79947 - local->wowlan = wowlan && local->open_count;
79948 + local->wowlan = wowlan && local_read(&local->open_count);
79949 if (local->wowlan) {
79950 int err = drv_suspend(local, wowlan);
79951 if (err < 0) {
79952 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
79953 drv_remove_interface(local, sdata);
79954
79955 /* stop hardware - this must stop RX */
79956 - if (local->open_count)
79957 + if (local_read(&local->open_count))
79958 ieee80211_stop_device(local);
79959
79960 suspend:
79961 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
79962 index 3313c11..bec9f17 100644
79963 --- a/net/mac80211/rate.c
79964 +++ b/net/mac80211/rate.c
79965 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
79966
79967 ASSERT_RTNL();
79968
79969 - if (local->open_count)
79970 + if (local_read(&local->open_count))
79971 return -EBUSY;
79972
79973 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
79974 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
79975 index c97a065..ff61928 100644
79976 --- a/net/mac80211/rc80211_pid_debugfs.c
79977 +++ b/net/mac80211/rc80211_pid_debugfs.c
79978 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
79979
79980 spin_unlock_irqrestore(&events->lock, status);
79981
79982 - if (copy_to_user(buf, pb, p))
79983 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
79984 return -EFAULT;
79985
79986 return p;
79987 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
79988 index 0151ae3..26709d3 100644
79989 --- a/net/mac80211/util.c
79990 +++ b/net/mac80211/util.c
79991 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
79992 }
79993 #endif
79994 /* everything else happens only if HW was up & running */
79995 - if (!local->open_count)
79996 + if (!local_read(&local->open_count))
79997 goto wake_up;
79998
79999 /*
80000 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80001 index fefa514..0755f23 100644
80002 --- a/net/netfilter/Kconfig
80003 +++ b/net/netfilter/Kconfig
80004 @@ -929,6 +929,16 @@ config NETFILTER_XT_MATCH_ESP
80005
80006 To compile it as a module, choose M here. If unsure, say N.
80007
80008 +config NETFILTER_XT_MATCH_GRADM
80009 + tristate '"gradm" match support'
80010 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80011 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80012 + ---help---
80013 + The gradm match allows to match on grsecurity RBAC being enabled.
80014 + It is useful when iptables rules are applied early on bootup to
80015 + prevent connections to the machine (except from a trusted host)
80016 + while the RBAC system is disabled.
80017 +
80018 config NETFILTER_XT_MATCH_HASHLIMIT
80019 tristate '"hashlimit" match support'
80020 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80021 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80022 index 3259697..54d5393 100644
80023 --- a/net/netfilter/Makefile
80024 +++ b/net/netfilter/Makefile
80025 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80026 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80027 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80028 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80029 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80030 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80031 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80032 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80033 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80034 index 1548df9..98ad9b4 100644
80035 --- a/net/netfilter/ipvs/ip_vs_conn.c
80036 +++ b/net/netfilter/ipvs/ip_vs_conn.c
80037 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80038 /* Increase the refcnt counter of the dest */
80039 atomic_inc(&dest->refcnt);
80040
80041 - conn_flags = atomic_read(&dest->conn_flags);
80042 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
80043 if (cp->protocol != IPPROTO_UDP)
80044 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80045 flags = cp->flags;
80046 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80047 atomic_set(&cp->refcnt, 1);
80048
80049 atomic_set(&cp->n_control, 0);
80050 - atomic_set(&cp->in_pkts, 0);
80051 + atomic_set_unchecked(&cp->in_pkts, 0);
80052
80053 atomic_inc(&ipvs->conn_count);
80054 if (flags & IP_VS_CONN_F_NO_CPORT)
80055 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80056
80057 /* Don't drop the entry if its number of incoming packets is not
80058 located in [0, 8] */
80059 - i = atomic_read(&cp->in_pkts);
80060 + i = atomic_read_unchecked(&cp->in_pkts);
80061 if (i > 8 || i < 0) return 0;
80062
80063 if (!todrop_rate[i]) return 0;
80064 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80065 index 58918e2..4d177a9 100644
80066 --- a/net/netfilter/ipvs/ip_vs_core.c
80067 +++ b/net/netfilter/ipvs/ip_vs_core.c
80068 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80069 ret = cp->packet_xmit(skb, cp, pd->pp);
80070 /* do not touch skb anymore */
80071
80072 - atomic_inc(&cp->in_pkts);
80073 + atomic_inc_unchecked(&cp->in_pkts);
80074 ip_vs_conn_put(cp);
80075 return ret;
80076 }
80077 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
80078 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
80079 pkts = sysctl_sync_threshold(ipvs);
80080 else
80081 - pkts = atomic_add_return(1, &cp->in_pkts);
80082 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80083
80084 if (ipvs->sync_state & IP_VS_STATE_MASTER)
80085 ip_vs_sync_conn(net, cp, pkts);
80086 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
80087 index c4ee437..a774a74 100644
80088 --- a/net/netfilter/ipvs/ip_vs_ctl.c
80089 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
80090 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
80091 ip_vs_rs_hash(ipvs, dest);
80092 write_unlock_bh(&ipvs->rs_lock);
80093 }
80094 - atomic_set(&dest->conn_flags, conn_flags);
80095 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
80096
80097 /* bind the service */
80098 if (!dest->svc) {
80099 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80100 " %-7s %-6d %-10d %-10d\n",
80101 &dest->addr.in6,
80102 ntohs(dest->port),
80103 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80104 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80105 atomic_read(&dest->weight),
80106 atomic_read(&dest->activeconns),
80107 atomic_read(&dest->inactconns));
80108 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80109 "%-7s %-6d %-10d %-10d\n",
80110 ntohl(dest->addr.ip),
80111 ntohs(dest->port),
80112 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80113 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80114 atomic_read(&dest->weight),
80115 atomic_read(&dest->activeconns),
80116 atomic_read(&dest->inactconns));
80117 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
80118
80119 entry.addr = dest->addr.ip;
80120 entry.port = dest->port;
80121 - entry.conn_flags = atomic_read(&dest->conn_flags);
80122 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
80123 entry.weight = atomic_read(&dest->weight);
80124 entry.u_threshold = dest->u_threshold;
80125 entry.l_threshold = dest->l_threshold;
80126 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
80127 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
80128 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
80129 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
80130 - (atomic_read(&dest->conn_flags) &
80131 + (atomic_read_unchecked(&dest->conn_flags) &
80132 IP_VS_CONN_F_FWD_MASK)) ||
80133 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
80134 atomic_read(&dest->weight)) ||
80135 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
80136 index effa10c..9058928 100644
80137 --- a/net/netfilter/ipvs/ip_vs_sync.c
80138 +++ b/net/netfilter/ipvs/ip_vs_sync.c
80139 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
80140 cp = cp->control;
80141 if (cp) {
80142 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80143 - pkts = atomic_add_return(1, &cp->in_pkts);
80144 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80145 else
80146 pkts = sysctl_sync_threshold(ipvs);
80147 ip_vs_sync_conn(net, cp->control, pkts);
80148 @@ -758,7 +758,7 @@ control:
80149 if (!cp)
80150 return;
80151 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80152 - pkts = atomic_add_return(1, &cp->in_pkts);
80153 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80154 else
80155 pkts = sysctl_sync_threshold(ipvs);
80156 goto sloop;
80157 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
80158
80159 if (opt)
80160 memcpy(&cp->in_seq, opt, sizeof(*opt));
80161 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80162 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80163 cp->state = state;
80164 cp->old_state = cp->state;
80165 /*
80166 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
80167 index cc4c809..50f8fe5 100644
80168 --- a/net/netfilter/ipvs/ip_vs_xmit.c
80169 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
80170 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
80171 else
80172 rc = NF_ACCEPT;
80173 /* do not touch skb anymore */
80174 - atomic_inc(&cp->in_pkts);
80175 + atomic_inc_unchecked(&cp->in_pkts);
80176 goto out;
80177 }
80178
80179 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
80180 else
80181 rc = NF_ACCEPT;
80182 /* do not touch skb anymore */
80183 - atomic_inc(&cp->in_pkts);
80184 + atomic_inc_unchecked(&cp->in_pkts);
80185 goto out;
80186 }
80187
80188 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
80189 index 0f241be..2c9be6d 100644
80190 --- a/net/netfilter/nf_conntrack_core.c
80191 +++ b/net/netfilter/nf_conntrack_core.c
80192 @@ -1532,6 +1532,10 @@ err_extend:
80193 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
80194 #define DYING_NULLS_VAL ((1<<30)+1)
80195
80196 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80197 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
80198 +#endif
80199 +
80200 static int nf_conntrack_init_net(struct net *net)
80201 {
80202 int ret;
80203 @@ -1545,7 +1549,11 @@ static int nf_conntrack_init_net(struct net *net)
80204 goto err_stat;
80205 }
80206
80207 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80208 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
80209 +#else
80210 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
80211 +#endif
80212 if (!net->ct.slabname) {
80213 ret = -ENOMEM;
80214 goto err_slabname;
80215 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
80216 index 9f199f2..719ad23 100644
80217 --- a/net/netfilter/nfnetlink_log.c
80218 +++ b/net/netfilter/nfnetlink_log.c
80219 @@ -71,7 +71,7 @@ struct nfulnl_instance {
80220 };
80221
80222 static DEFINE_SPINLOCK(instances_lock);
80223 -static atomic_t global_seq;
80224 +static atomic_unchecked_t global_seq;
80225
80226 #define INSTANCE_BUCKETS 16
80227 static struct hlist_head instance_table[INSTANCE_BUCKETS];
80228 @@ -527,7 +527,7 @@ __build_packet_message(struct nfulnl_instance *inst,
80229 /* global sequence number */
80230 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
80231 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
80232 - htonl(atomic_inc_return(&global_seq))))
80233 + htonl(atomic_inc_return_unchecked(&global_seq))))
80234 goto nla_put_failure;
80235
80236 if (data_len) {
80237 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
80238 new file mode 100644
80239 index 0000000..c566332
80240 --- /dev/null
80241 +++ b/net/netfilter/xt_gradm.c
80242 @@ -0,0 +1,51 @@
80243 +/*
80244 + * gradm match for netfilter
80245 + * Copyright © Zbigniew Krzystolik, 2010
80246 + *
80247 + * This program is free software; you can redistribute it and/or modify
80248 + * it under the terms of the GNU General Public License; either version
80249 + * 2 or 3 as published by the Free Software Foundation.
80250 + */
80251 +#include <linux/module.h>
80252 +#include <linux/moduleparam.h>
80253 +#include <linux/skbuff.h>
80254 +#include <linux/netfilter/x_tables.h>
80255 +#include <linux/grsecurity.h>
80256 +#include <linux/netfilter/xt_gradm.h>
80257 +
80258 +static bool
80259 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
80260 +{
80261 + const struct xt_gradm_mtinfo *info = par->matchinfo;
80262 + bool retval = false;
80263 + if (gr_acl_is_enabled())
80264 + retval = true;
80265 + return retval ^ info->invflags;
80266 +}
80267 +
80268 +static struct xt_match gradm_mt_reg __read_mostly = {
80269 + .name = "gradm",
80270 + .revision = 0,
80271 + .family = NFPROTO_UNSPEC,
80272 + .match = gradm_mt,
80273 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
80274 + .me = THIS_MODULE,
80275 +};
80276 +
80277 +static int __init gradm_mt_init(void)
80278 +{
80279 + return xt_register_match(&gradm_mt_reg);
80280 +}
80281 +
80282 +static void __exit gradm_mt_exit(void)
80283 +{
80284 + xt_unregister_match(&gradm_mt_reg);
80285 +}
80286 +
80287 +module_init(gradm_mt_init);
80288 +module_exit(gradm_mt_exit);
80289 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
80290 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
80291 +MODULE_LICENSE("GPL");
80292 +MODULE_ALIAS("ipt_gradm");
80293 +MODULE_ALIAS("ip6t_gradm");
80294 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
80295 index 4fe4fb4..87a89e5 100644
80296 --- a/net/netfilter/xt_statistic.c
80297 +++ b/net/netfilter/xt_statistic.c
80298 @@ -19,7 +19,7 @@
80299 #include <linux/module.h>
80300
80301 struct xt_statistic_priv {
80302 - atomic_t count;
80303 + atomic_unchecked_t count;
80304 } ____cacheline_aligned_in_smp;
80305
80306 MODULE_LICENSE("GPL");
80307 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
80308 break;
80309 case XT_STATISTIC_MODE_NTH:
80310 do {
80311 - oval = atomic_read(&info->master->count);
80312 + oval = atomic_read_unchecked(&info->master->count);
80313 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
80314 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
80315 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
80316 if (nval == 0)
80317 ret = !ret;
80318 break;
80319 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
80320 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
80321 if (info->master == NULL)
80322 return -ENOMEM;
80323 - atomic_set(&info->master->count, info->u.nth.count);
80324 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
80325
80326 return 0;
80327 }
80328 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
80329 index 4da797f..eb1df70 100644
80330 --- a/net/netlink/af_netlink.c
80331 +++ b/net/netlink/af_netlink.c
80332 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
80333 sk->sk_error_report(sk);
80334 }
80335 }
80336 - atomic_inc(&sk->sk_drops);
80337 + atomic_inc_unchecked(&sk->sk_drops);
80338 }
80339
80340 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
80341 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
80342 sk_wmem_alloc_get(s),
80343 nlk->cb,
80344 atomic_read(&s->sk_refcnt),
80345 - atomic_read(&s->sk_drops),
80346 + atomic_read_unchecked(&s->sk_drops),
80347 sock_i_ino(s)
80348 );
80349
80350 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
80351 index 7261eb8..44e8ac6 100644
80352 --- a/net/netrom/af_netrom.c
80353 +++ b/net/netrom/af_netrom.c
80354 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
80355 struct sock *sk = sock->sk;
80356 struct nr_sock *nr = nr_sk(sk);
80357
80358 + memset(sax, 0, sizeof(*sax));
80359 lock_sock(sk);
80360 if (peer != 0) {
80361 if (sk->sk_state != TCP_ESTABLISHED) {
80362 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
80363 *uaddr_len = sizeof(struct full_sockaddr_ax25);
80364 } else {
80365 sax->fsa_ax25.sax25_family = AF_NETROM;
80366 - sax->fsa_ax25.sax25_ndigis = 0;
80367 sax->fsa_ax25.sax25_call = nr->source_addr;
80368 *uaddr_len = sizeof(struct sockaddr_ax25);
80369 }
80370 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
80371 index 94060ed..9c066f3 100644
80372 --- a/net/packet/af_packet.c
80373 +++ b/net/packet/af_packet.c
80374 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
80375
80376 spin_lock(&sk->sk_receive_queue.lock);
80377 po->stats.tp_packets++;
80378 - skb->dropcount = atomic_read(&sk->sk_drops);
80379 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
80380 __skb_queue_tail(&sk->sk_receive_queue, skb);
80381 spin_unlock(&sk->sk_receive_queue.lock);
80382 sk->sk_data_ready(sk, skb->len);
80383 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
80384 drop_n_acct:
80385 spin_lock(&sk->sk_receive_queue.lock);
80386 po->stats.tp_drops++;
80387 - atomic_inc(&sk->sk_drops);
80388 + atomic_inc_unchecked(&sk->sk_drops);
80389 spin_unlock(&sk->sk_receive_queue.lock);
80390
80391 drop_n_restore:
80392 @@ -2537,6 +2537,7 @@ out:
80393
80394 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
80395 {
80396 + struct sock_extended_err ee;
80397 struct sock_exterr_skb *serr;
80398 struct sk_buff *skb, *skb2;
80399 int copied, err;
80400 @@ -2558,8 +2559,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
80401 sock_recv_timestamp(msg, sk, skb);
80402
80403 serr = SKB_EXT_ERR(skb);
80404 + ee = serr->ee;
80405 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
80406 - sizeof(serr->ee), &serr->ee);
80407 + sizeof ee, &ee);
80408
80409 msg->msg_flags |= MSG_ERRQUEUE;
80410 err = copied;
80411 @@ -3171,7 +3173,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
80412 case PACKET_HDRLEN:
80413 if (len > sizeof(int))
80414 len = sizeof(int);
80415 - if (copy_from_user(&val, optval, len))
80416 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
80417 return -EFAULT;
80418 switch (val) {
80419 case TPACKET_V1:
80420 @@ -3210,7 +3212,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
80421 len = lv;
80422 if (put_user(len, optlen))
80423 return -EFAULT;
80424 - if (copy_to_user(optval, data, len))
80425 + if (len > sizeof(st) || copy_to_user(optval, data, len))
80426 return -EFAULT;
80427 return 0;
80428 }
80429 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
80430 index 5a940db..f0b9c12 100644
80431 --- a/net/phonet/af_phonet.c
80432 +++ b/net/phonet/af_phonet.c
80433 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
80434 {
80435 struct phonet_protocol *pp;
80436
80437 - if (protocol >= PHONET_NPROTO)
80438 + if (protocol < 0 || protocol >= PHONET_NPROTO)
80439 return NULL;
80440
80441 rcu_read_lock();
80442 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
80443 {
80444 int err = 0;
80445
80446 - if (protocol >= PHONET_NPROTO)
80447 + if (protocol < 0 || protocol >= PHONET_NPROTO)
80448 return -EINVAL;
80449
80450 err = proto_register(pp->prot, 1);
80451 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
80452 index 576f22c..bc7a71b 100644
80453 --- a/net/phonet/pep.c
80454 +++ b/net/phonet/pep.c
80455 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
80456
80457 case PNS_PEP_CTRL_REQ:
80458 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
80459 - atomic_inc(&sk->sk_drops);
80460 + atomic_inc_unchecked(&sk->sk_drops);
80461 break;
80462 }
80463 __skb_pull(skb, 4);
80464 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
80465 }
80466
80467 if (pn->rx_credits == 0) {
80468 - atomic_inc(&sk->sk_drops);
80469 + atomic_inc_unchecked(&sk->sk_drops);
80470 err = -ENOBUFS;
80471 break;
80472 }
80473 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
80474 }
80475
80476 if (pn->rx_credits == 0) {
80477 - atomic_inc(&sk->sk_drops);
80478 + atomic_inc_unchecked(&sk->sk_drops);
80479 err = NET_RX_DROP;
80480 break;
80481 }
80482 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
80483 index b7e9827..c264c85 100644
80484 --- a/net/phonet/socket.c
80485 +++ b/net/phonet/socket.c
80486 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
80487 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
80488 sock_i_ino(sk),
80489 atomic_read(&sk->sk_refcnt), sk,
80490 - atomic_read(&sk->sk_drops), &len);
80491 + atomic_read_unchecked(&sk->sk_drops), &len);
80492 }
80493 seq_printf(seq, "%*s\n", 127 - len, "");
80494 return 0;
80495 diff --git a/net/rds/cong.c b/net/rds/cong.c
80496 index e5b65ac..f3b6fb7 100644
80497 --- a/net/rds/cong.c
80498 +++ b/net/rds/cong.c
80499 @@ -78,7 +78,7 @@
80500 * finds that the saved generation number is smaller than the global generation
80501 * number, it wakes up the process.
80502 */
80503 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
80504 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
80505
80506 /*
80507 * Congestion monitoring
80508 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
80509 rdsdebug("waking map %p for %pI4\n",
80510 map, &map->m_addr);
80511 rds_stats_inc(s_cong_update_received);
80512 - atomic_inc(&rds_cong_generation);
80513 + atomic_inc_unchecked(&rds_cong_generation);
80514 if (waitqueue_active(&map->m_waitq))
80515 wake_up(&map->m_waitq);
80516 if (waitqueue_active(&rds_poll_waitq))
80517 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
80518
80519 int rds_cong_updated_since(unsigned long *recent)
80520 {
80521 - unsigned long gen = atomic_read(&rds_cong_generation);
80522 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
80523
80524 if (likely(*recent == gen))
80525 return 0;
80526 diff --git a/net/rds/ib.h b/net/rds/ib.h
80527 index 8d2b3d5..227ec5b 100644
80528 --- a/net/rds/ib.h
80529 +++ b/net/rds/ib.h
80530 @@ -128,7 +128,7 @@ struct rds_ib_connection {
80531 /* sending acks */
80532 unsigned long i_ack_flags;
80533 #ifdef KERNEL_HAS_ATOMIC64
80534 - atomic64_t i_ack_next; /* next ACK to send */
80535 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
80536 #else
80537 spinlock_t i_ack_lock; /* protect i_ack_next */
80538 u64 i_ack_next; /* next ACK to send */
80539 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
80540 index a1e1162..265e129 100644
80541 --- a/net/rds/ib_cm.c
80542 +++ b/net/rds/ib_cm.c
80543 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
80544 /* Clear the ACK state */
80545 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
80546 #ifdef KERNEL_HAS_ATOMIC64
80547 - atomic64_set(&ic->i_ack_next, 0);
80548 + atomic64_set_unchecked(&ic->i_ack_next, 0);
80549 #else
80550 ic->i_ack_next = 0;
80551 #endif
80552 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
80553 index 8d19491..05a3e65 100644
80554 --- a/net/rds/ib_recv.c
80555 +++ b/net/rds/ib_recv.c
80556 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
80557 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
80558 int ack_required)
80559 {
80560 - atomic64_set(&ic->i_ack_next, seq);
80561 + atomic64_set_unchecked(&ic->i_ack_next, seq);
80562 if (ack_required) {
80563 smp_mb__before_clear_bit();
80564 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
80565 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
80566 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
80567 smp_mb__after_clear_bit();
80568
80569 - return atomic64_read(&ic->i_ack_next);
80570 + return atomic64_read_unchecked(&ic->i_ack_next);
80571 }
80572 #endif
80573
80574 diff --git a/net/rds/iw.h b/net/rds/iw.h
80575 index 04ce3b1..48119a6 100644
80576 --- a/net/rds/iw.h
80577 +++ b/net/rds/iw.h
80578 @@ -134,7 +134,7 @@ struct rds_iw_connection {
80579 /* sending acks */
80580 unsigned long i_ack_flags;
80581 #ifdef KERNEL_HAS_ATOMIC64
80582 - atomic64_t i_ack_next; /* next ACK to send */
80583 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
80584 #else
80585 spinlock_t i_ack_lock; /* protect i_ack_next */
80586 u64 i_ack_next; /* next ACK to send */
80587 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
80588 index a91e1db..cf3053f 100644
80589 --- a/net/rds/iw_cm.c
80590 +++ b/net/rds/iw_cm.c
80591 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
80592 /* Clear the ACK state */
80593 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
80594 #ifdef KERNEL_HAS_ATOMIC64
80595 - atomic64_set(&ic->i_ack_next, 0);
80596 + atomic64_set_unchecked(&ic->i_ack_next, 0);
80597 #else
80598 ic->i_ack_next = 0;
80599 #endif
80600 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
80601 index 4503335..db566b4 100644
80602 --- a/net/rds/iw_recv.c
80603 +++ b/net/rds/iw_recv.c
80604 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
80605 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
80606 int ack_required)
80607 {
80608 - atomic64_set(&ic->i_ack_next, seq);
80609 + atomic64_set_unchecked(&ic->i_ack_next, seq);
80610 if (ack_required) {
80611 smp_mb__before_clear_bit();
80612 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
80613 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
80614 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
80615 smp_mb__after_clear_bit();
80616
80617 - return atomic64_read(&ic->i_ack_next);
80618 + return atomic64_read_unchecked(&ic->i_ack_next);
80619 }
80620 #endif
80621
80622 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
80623 index edac9ef..16bcb98 100644
80624 --- a/net/rds/tcp.c
80625 +++ b/net/rds/tcp.c
80626 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
80627 int val = 1;
80628
80629 set_fs(KERNEL_DS);
80630 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
80631 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
80632 sizeof(val));
80633 set_fs(oldfs);
80634 }
80635 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
80636 index 81cf5a4..b5826ff 100644
80637 --- a/net/rds/tcp_send.c
80638 +++ b/net/rds/tcp_send.c
80639 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
80640
80641 oldfs = get_fs();
80642 set_fs(KERNEL_DS);
80643 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
80644 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
80645 sizeof(val));
80646 set_fs(oldfs);
80647 }
80648 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
80649 index 05996d0..5a1dfe0 100644
80650 --- a/net/rxrpc/af_rxrpc.c
80651 +++ b/net/rxrpc/af_rxrpc.c
80652 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
80653 __be32 rxrpc_epoch;
80654
80655 /* current debugging ID */
80656 -atomic_t rxrpc_debug_id;
80657 +atomic_unchecked_t rxrpc_debug_id;
80658
80659 /* count of skbs currently in use */
80660 atomic_t rxrpc_n_skbs;
80661 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
80662 index e4d9cbc..b229649 100644
80663 --- a/net/rxrpc/ar-ack.c
80664 +++ b/net/rxrpc/ar-ack.c
80665 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
80666
80667 _enter("{%d,%d,%d,%d},",
80668 call->acks_hard, call->acks_unacked,
80669 - atomic_read(&call->sequence),
80670 + atomic_read_unchecked(&call->sequence),
80671 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
80672
80673 stop = 0;
80674 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
80675
80676 /* each Tx packet has a new serial number */
80677 sp->hdr.serial =
80678 - htonl(atomic_inc_return(&call->conn->serial));
80679 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
80680
80681 hdr = (struct rxrpc_header *) txb->head;
80682 hdr->serial = sp->hdr.serial;
80683 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
80684 */
80685 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
80686 {
80687 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
80688 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
80689 }
80690
80691 /*
80692 @@ -629,7 +629,7 @@ process_further:
80693
80694 latest = ntohl(sp->hdr.serial);
80695 hard = ntohl(ack.firstPacket);
80696 - tx = atomic_read(&call->sequence);
80697 + tx = atomic_read_unchecked(&call->sequence);
80698
80699 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
80700 latest,
80701 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
80702 goto maybe_reschedule;
80703
80704 send_ACK_with_skew:
80705 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
80706 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
80707 ntohl(ack.serial));
80708 send_ACK:
80709 mtu = call->conn->trans->peer->if_mtu;
80710 @@ -1173,7 +1173,7 @@ send_ACK:
80711 ackinfo.rxMTU = htonl(5692);
80712 ackinfo.jumbo_max = htonl(4);
80713
80714 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
80715 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
80716 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
80717 ntohl(hdr.serial),
80718 ntohs(ack.maxSkew),
80719 @@ -1191,7 +1191,7 @@ send_ACK:
80720 send_message:
80721 _debug("send message");
80722
80723 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
80724 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
80725 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
80726 send_message_2:
80727
80728 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
80729 index a3bbb36..3341fb9 100644
80730 --- a/net/rxrpc/ar-call.c
80731 +++ b/net/rxrpc/ar-call.c
80732 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
80733 spin_lock_init(&call->lock);
80734 rwlock_init(&call->state_lock);
80735 atomic_set(&call->usage, 1);
80736 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
80737 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
80738 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
80739
80740 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
80741 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
80742 index 4106ca9..a338d7a 100644
80743 --- a/net/rxrpc/ar-connection.c
80744 +++ b/net/rxrpc/ar-connection.c
80745 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
80746 rwlock_init(&conn->lock);
80747 spin_lock_init(&conn->state_lock);
80748 atomic_set(&conn->usage, 1);
80749 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
80750 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
80751 conn->avail_calls = RXRPC_MAXCALLS;
80752 conn->size_align = 4;
80753 conn->header_size = sizeof(struct rxrpc_header);
80754 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
80755 index e7ed43a..6afa140 100644
80756 --- a/net/rxrpc/ar-connevent.c
80757 +++ b/net/rxrpc/ar-connevent.c
80758 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
80759
80760 len = iov[0].iov_len + iov[1].iov_len;
80761
80762 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
80763 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
80764 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
80765
80766 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
80767 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
80768 index 529572f..c758ca7 100644
80769 --- a/net/rxrpc/ar-input.c
80770 +++ b/net/rxrpc/ar-input.c
80771 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
80772 /* track the latest serial number on this connection for ACK packet
80773 * information */
80774 serial = ntohl(sp->hdr.serial);
80775 - hi_serial = atomic_read(&call->conn->hi_serial);
80776 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
80777 while (serial > hi_serial)
80778 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
80779 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
80780 serial);
80781
80782 /* request ACK generation for any ACK or DATA packet that requests
80783 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
80784 index a693aca..81e7293 100644
80785 --- a/net/rxrpc/ar-internal.h
80786 +++ b/net/rxrpc/ar-internal.h
80787 @@ -272,8 +272,8 @@ struct rxrpc_connection {
80788 int error; /* error code for local abort */
80789 int debug_id; /* debug ID for printks */
80790 unsigned int call_counter; /* call ID counter */
80791 - atomic_t serial; /* packet serial number counter */
80792 - atomic_t hi_serial; /* highest serial number received */
80793 + atomic_unchecked_t serial; /* packet serial number counter */
80794 + atomic_unchecked_t hi_serial; /* highest serial number received */
80795 u8 avail_calls; /* number of calls available */
80796 u8 size_align; /* data size alignment (for security) */
80797 u8 header_size; /* rxrpc + security header size */
80798 @@ -346,7 +346,7 @@ struct rxrpc_call {
80799 spinlock_t lock;
80800 rwlock_t state_lock; /* lock for state transition */
80801 atomic_t usage;
80802 - atomic_t sequence; /* Tx data packet sequence counter */
80803 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
80804 u32 abort_code; /* local/remote abort code */
80805 enum { /* current state of call */
80806 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
80807 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
80808 */
80809 extern atomic_t rxrpc_n_skbs;
80810 extern __be32 rxrpc_epoch;
80811 -extern atomic_t rxrpc_debug_id;
80812 +extern atomic_unchecked_t rxrpc_debug_id;
80813 extern struct workqueue_struct *rxrpc_workqueue;
80814
80815 /*
80816 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
80817 index 87f7135..74d3703 100644
80818 --- a/net/rxrpc/ar-local.c
80819 +++ b/net/rxrpc/ar-local.c
80820 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
80821 spin_lock_init(&local->lock);
80822 rwlock_init(&local->services_lock);
80823 atomic_set(&local->usage, 1);
80824 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
80825 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
80826 memcpy(&local->srx, srx, sizeof(*srx));
80827 }
80828
80829 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
80830 index e1ac183..b43e10e 100644
80831 --- a/net/rxrpc/ar-output.c
80832 +++ b/net/rxrpc/ar-output.c
80833 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
80834 sp->hdr.cid = call->cid;
80835 sp->hdr.callNumber = call->call_id;
80836 sp->hdr.seq =
80837 - htonl(atomic_inc_return(&call->sequence));
80838 + htonl(atomic_inc_return_unchecked(&call->sequence));
80839 sp->hdr.serial =
80840 - htonl(atomic_inc_return(&conn->serial));
80841 + htonl(atomic_inc_return_unchecked(&conn->serial));
80842 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
80843 sp->hdr.userStatus = 0;
80844 sp->hdr.securityIndex = conn->security_ix;
80845 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
80846 index bebaa43..2644591 100644
80847 --- a/net/rxrpc/ar-peer.c
80848 +++ b/net/rxrpc/ar-peer.c
80849 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
80850 INIT_LIST_HEAD(&peer->error_targets);
80851 spin_lock_init(&peer->lock);
80852 atomic_set(&peer->usage, 1);
80853 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
80854 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
80855 memcpy(&peer->srx, srx, sizeof(*srx));
80856
80857 rxrpc_assess_MTU_size(peer);
80858 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
80859 index 38047f7..9f48511 100644
80860 --- a/net/rxrpc/ar-proc.c
80861 +++ b/net/rxrpc/ar-proc.c
80862 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
80863 atomic_read(&conn->usage),
80864 rxrpc_conn_states[conn->state],
80865 key_serial(conn->key),
80866 - atomic_read(&conn->serial),
80867 - atomic_read(&conn->hi_serial));
80868 + atomic_read_unchecked(&conn->serial),
80869 + atomic_read_unchecked(&conn->hi_serial));
80870
80871 return 0;
80872 }
80873 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
80874 index 92df566..87ec1bf 100644
80875 --- a/net/rxrpc/ar-transport.c
80876 +++ b/net/rxrpc/ar-transport.c
80877 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
80878 spin_lock_init(&trans->client_lock);
80879 rwlock_init(&trans->conn_lock);
80880 atomic_set(&trans->usage, 1);
80881 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
80882 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
80883
80884 if (peer->srx.transport.family == AF_INET) {
80885 switch (peer->srx.transport_type) {
80886 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
80887 index f226709..0e735a8 100644
80888 --- a/net/rxrpc/rxkad.c
80889 +++ b/net/rxrpc/rxkad.c
80890 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
80891
80892 len = iov[0].iov_len + iov[1].iov_len;
80893
80894 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
80895 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
80896 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
80897
80898 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
80899 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
80900
80901 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
80902
80903 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
80904 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
80905 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
80906
80907 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
80908 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
80909 index ea14cb4..834e8e4 100644
80910 --- a/net/sctp/ipv6.c
80911 +++ b/net/sctp/ipv6.c
80912 @@ -1037,7 +1037,7 @@ void sctp_v6_pf_init(void)
80913
80914 void sctp_v6_pf_exit(void)
80915 {
80916 - list_del(&sctp_af_inet6.list);
80917 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
80918 }
80919
80920 /* Initialize IPv6 support and register with socket layer. */
80921 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
80922 index 9966e7b..540c575 100644
80923 --- a/net/sctp/proc.c
80924 +++ b/net/sctp/proc.c
80925 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
80926 seq_printf(seq,
80927 "%8pK %8pK %-3d %-3d %-2d %-4d "
80928 "%4d %8d %8d %7d %5lu %-5d %5d ",
80929 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
80930 + assoc, sk,
80931 + sctp_sk(sk)->type, sk->sk_state,
80932 assoc->state, hash,
80933 assoc->assoc_id,
80934 assoc->sndbuf_used,
80935 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
80936 index 2d51842..150ba5c 100644
80937 --- a/net/sctp/protocol.c
80938 +++ b/net/sctp/protocol.c
80939 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
80940 return 0;
80941 }
80942
80943 - INIT_LIST_HEAD(&af->list);
80944 - list_add_tail(&af->list, &sctp_address_families);
80945 + pax_open_kernel();
80946 + INIT_LIST_HEAD((struct list_head *)&af->list);
80947 + pax_close_kernel();
80948 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
80949 return 1;
80950 }
80951
80952 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
80953
80954 static void sctp_v4_pf_exit(void)
80955 {
80956 - list_del(&sctp_af_inet.list);
80957 + pax_list_del((struct list_head *)&sctp_af_inet.list);
80958 }
80959
80960 static int sctp_v4_protosw_init(void)
80961 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
80962 index 406d957..543c737 100644
80963 --- a/net/sctp/socket.c
80964 +++ b/net/sctp/socket.c
80965 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
80966 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
80967 if (space_left < addrlen)
80968 return -ENOMEM;
80969 + if (addrlen > sizeof(temp) || addrlen < 0)
80970 + return -EFAULT;
80971 if (copy_to_user(to, &temp, addrlen))
80972 return -EFAULT;
80973 to += addrlen;
80974 diff --git a/net/socket.c b/net/socket.c
80975 index d92c490..b4bc863 100644
80976 --- a/net/socket.c
80977 +++ b/net/socket.c
80978 @@ -89,6 +89,7 @@
80979 #include <linux/magic.h>
80980 #include <linux/slab.h>
80981 #include <linux/xattr.h>
80982 +#include <linux/in.h>
80983
80984 #include <asm/uaccess.h>
80985 #include <asm/unistd.h>
80986 @@ -106,6 +107,8 @@
80987 #include <linux/sockios.h>
80988 #include <linux/atalk.h>
80989
80990 +#include <linux/grsock.h>
80991 +
80992 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
80993 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
80994 unsigned long nr_segs, loff_t pos);
80995 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
80996 &sockfs_dentry_operations, SOCKFS_MAGIC);
80997 }
80998
80999 -static struct vfsmount *sock_mnt __read_mostly;
81000 +struct vfsmount *sock_mnt __read_mostly;
81001
81002 static struct file_system_type sock_fs_type = {
81003 .name = "sockfs",
81004 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
81005 return -EAFNOSUPPORT;
81006 if (type < 0 || type >= SOCK_MAX)
81007 return -EINVAL;
81008 + if (protocol < 0)
81009 + return -EINVAL;
81010
81011 /* Compatibility.
81012
81013 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
81014 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
81015 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
81016
81017 + if(!gr_search_socket(family, type, protocol)) {
81018 + retval = -EACCES;
81019 + goto out;
81020 + }
81021 +
81022 + if (gr_handle_sock_all(family, type, protocol)) {
81023 + retval = -EACCES;
81024 + goto out;
81025 + }
81026 +
81027 retval = sock_create(family, type, protocol, &sock);
81028 if (retval < 0)
81029 goto out;
81030 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81031 if (sock) {
81032 err = move_addr_to_kernel(umyaddr, addrlen, &address);
81033 if (err >= 0) {
81034 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
81035 + err = -EACCES;
81036 + goto error;
81037 + }
81038 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
81039 + if (err)
81040 + goto error;
81041 +
81042 err = security_socket_bind(sock,
81043 (struct sockaddr *)&address,
81044 addrlen);
81045 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81046 (struct sockaddr *)
81047 &address, addrlen);
81048 }
81049 +error:
81050 fput_light(sock->file, fput_needed);
81051 }
81052 return err;
81053 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
81054 if ((unsigned int)backlog > somaxconn)
81055 backlog = somaxconn;
81056
81057 + if (gr_handle_sock_server_other(sock->sk)) {
81058 + err = -EPERM;
81059 + goto error;
81060 + }
81061 +
81062 + err = gr_search_listen(sock);
81063 + if (err)
81064 + goto error;
81065 +
81066 err = security_socket_listen(sock, backlog);
81067 if (!err)
81068 err = sock->ops->listen(sock, backlog);
81069
81070 +error:
81071 fput_light(sock->file, fput_needed);
81072 }
81073 return err;
81074 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81075 newsock->type = sock->type;
81076 newsock->ops = sock->ops;
81077
81078 + if (gr_handle_sock_server_other(sock->sk)) {
81079 + err = -EPERM;
81080 + sock_release(newsock);
81081 + goto out_put;
81082 + }
81083 +
81084 + err = gr_search_accept(sock);
81085 + if (err) {
81086 + sock_release(newsock);
81087 + goto out_put;
81088 + }
81089 +
81090 /*
81091 * We don't need try_module_get here, as the listening socket (sock)
81092 * has the protocol module (sock->ops->owner) held.
81093 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81094 fd_install(newfd, newfile);
81095 err = newfd;
81096
81097 + gr_attach_curr_ip(newsock->sk);
81098 +
81099 out_put:
81100 fput_light(sock->file, fput_needed);
81101 out:
81102 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81103 int, addrlen)
81104 {
81105 struct socket *sock;
81106 + struct sockaddr *sck;
81107 struct sockaddr_storage address;
81108 int err, fput_needed;
81109
81110 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81111 if (err < 0)
81112 goto out_put;
81113
81114 + sck = (struct sockaddr *)&address;
81115 +
81116 + if (gr_handle_sock_client(sck)) {
81117 + err = -EACCES;
81118 + goto out_put;
81119 + }
81120 +
81121 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
81122 + if (err)
81123 + goto out_put;
81124 +
81125 err =
81126 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
81127 if (err)
81128 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
81129 * checking falls down on this.
81130 */
81131 if (copy_from_user(ctl_buf,
81132 - (void __user __force *)msg_sys->msg_control,
81133 + (void __force_user *)msg_sys->msg_control,
81134 ctl_len))
81135 goto out_freectl;
81136 msg_sys->msg_control = ctl_buf;
81137 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
81138 * kernel msghdr to use the kernel address space)
81139 */
81140
81141 - uaddr = (__force void __user *)msg_sys->msg_name;
81142 + uaddr = (void __force_user *)msg_sys->msg_name;
81143 uaddr_len = COMPAT_NAMELEN(msg);
81144 if (MSG_CMSG_COMPAT & flags) {
81145 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
81146 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81147 }
81148
81149 ifr = compat_alloc_user_space(buf_size);
81150 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
81151 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
81152
81153 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
81154 return -EFAULT;
81155 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81156 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
81157
81158 if (copy_in_user(rxnfc, compat_rxnfc,
81159 - (void *)(&rxnfc->fs.m_ext + 1) -
81160 - (void *)rxnfc) ||
81161 + (void __user *)(&rxnfc->fs.m_ext + 1) -
81162 + (void __user *)rxnfc) ||
81163 copy_in_user(&rxnfc->fs.ring_cookie,
81164 &compat_rxnfc->fs.ring_cookie,
81165 - (void *)(&rxnfc->fs.location + 1) -
81166 - (void *)&rxnfc->fs.ring_cookie) ||
81167 + (void __user *)(&rxnfc->fs.location + 1) -
81168 + (void __user *)&rxnfc->fs.ring_cookie) ||
81169 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
81170 sizeof(rxnfc->rule_cnt)))
81171 return -EFAULT;
81172 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81173
81174 if (convert_out) {
81175 if (copy_in_user(compat_rxnfc, rxnfc,
81176 - (const void *)(&rxnfc->fs.m_ext + 1) -
81177 - (const void *)rxnfc) ||
81178 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
81179 + (const void __user *)rxnfc) ||
81180 copy_in_user(&compat_rxnfc->fs.ring_cookie,
81181 &rxnfc->fs.ring_cookie,
81182 - (const void *)(&rxnfc->fs.location + 1) -
81183 - (const void *)&rxnfc->fs.ring_cookie) ||
81184 + (const void __user *)(&rxnfc->fs.location + 1) -
81185 + (const void __user *)&rxnfc->fs.ring_cookie) ||
81186 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
81187 sizeof(rxnfc->rule_cnt)))
81188 return -EFAULT;
81189 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
81190 old_fs = get_fs();
81191 set_fs(KERNEL_DS);
81192 err = dev_ioctl(net, cmd,
81193 - (struct ifreq __user __force *) &kifr);
81194 + (struct ifreq __force_user *) &kifr);
81195 set_fs(old_fs);
81196
81197 return err;
81198 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
81199
81200 old_fs = get_fs();
81201 set_fs(KERNEL_DS);
81202 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
81203 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
81204 set_fs(old_fs);
81205
81206 if (cmd == SIOCGIFMAP && !err) {
81207 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
81208 ret |= __get_user(rtdev, &(ur4->rt_dev));
81209 if (rtdev) {
81210 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
81211 - r4.rt_dev = (char __user __force *)devname;
81212 + r4.rt_dev = (char __force_user *)devname;
81213 devname[15] = 0;
81214 } else
81215 r4.rt_dev = NULL;
81216 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
81217 int __user *uoptlen;
81218 int err;
81219
81220 - uoptval = (char __user __force *) optval;
81221 - uoptlen = (int __user __force *) optlen;
81222 + uoptval = (char __force_user *) optval;
81223 + uoptlen = (int __force_user *) optlen;
81224
81225 set_fs(KERNEL_DS);
81226 if (level == SOL_SOCKET)
81227 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
81228 char __user *uoptval;
81229 int err;
81230
81231 - uoptval = (char __user __force *) optval;
81232 + uoptval = (char __force_user *) optval;
81233
81234 set_fs(KERNEL_DS);
81235 if (level == SOL_SOCKET)
81236 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
81237 index 7865b44..174662e 100644
81238 --- a/net/sunrpc/sched.c
81239 +++ b/net/sunrpc/sched.c
81240 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
81241 #ifdef RPC_DEBUG
81242 static void rpc_task_set_debuginfo(struct rpc_task *task)
81243 {
81244 - static atomic_t rpc_pid;
81245 + static atomic_unchecked_t rpc_pid;
81246
81247 - task->tk_pid = atomic_inc_return(&rpc_pid);
81248 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
81249 }
81250 #else
81251 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
81252 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
81253 index 8343737..677025e 100644
81254 --- a/net/sunrpc/xprtrdma/svc_rdma.c
81255 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
81256 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
81257 static unsigned int min_max_inline = 4096;
81258 static unsigned int max_max_inline = 65536;
81259
81260 -atomic_t rdma_stat_recv;
81261 -atomic_t rdma_stat_read;
81262 -atomic_t rdma_stat_write;
81263 -atomic_t rdma_stat_sq_starve;
81264 -atomic_t rdma_stat_rq_starve;
81265 -atomic_t rdma_stat_rq_poll;
81266 -atomic_t rdma_stat_rq_prod;
81267 -atomic_t rdma_stat_sq_poll;
81268 -atomic_t rdma_stat_sq_prod;
81269 +atomic_unchecked_t rdma_stat_recv;
81270 +atomic_unchecked_t rdma_stat_read;
81271 +atomic_unchecked_t rdma_stat_write;
81272 +atomic_unchecked_t rdma_stat_sq_starve;
81273 +atomic_unchecked_t rdma_stat_rq_starve;
81274 +atomic_unchecked_t rdma_stat_rq_poll;
81275 +atomic_unchecked_t rdma_stat_rq_prod;
81276 +atomic_unchecked_t rdma_stat_sq_poll;
81277 +atomic_unchecked_t rdma_stat_sq_prod;
81278
81279 /* Temporary NFS request map and context caches */
81280 struct kmem_cache *svc_rdma_map_cachep;
81281 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
81282 len -= *ppos;
81283 if (len > *lenp)
81284 len = *lenp;
81285 - if (len && copy_to_user(buffer, str_buf, len))
81286 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
81287 return -EFAULT;
81288 *lenp = len;
81289 *ppos += len;
81290 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
81291 {
81292 .procname = "rdma_stat_read",
81293 .data = &rdma_stat_read,
81294 - .maxlen = sizeof(atomic_t),
81295 + .maxlen = sizeof(atomic_unchecked_t),
81296 .mode = 0644,
81297 .proc_handler = read_reset_stat,
81298 },
81299 {
81300 .procname = "rdma_stat_recv",
81301 .data = &rdma_stat_recv,
81302 - .maxlen = sizeof(atomic_t),
81303 + .maxlen = sizeof(atomic_unchecked_t),
81304 .mode = 0644,
81305 .proc_handler = read_reset_stat,
81306 },
81307 {
81308 .procname = "rdma_stat_write",
81309 .data = &rdma_stat_write,
81310 - .maxlen = sizeof(atomic_t),
81311 + .maxlen = sizeof(atomic_unchecked_t),
81312 .mode = 0644,
81313 .proc_handler = read_reset_stat,
81314 },
81315 {
81316 .procname = "rdma_stat_sq_starve",
81317 .data = &rdma_stat_sq_starve,
81318 - .maxlen = sizeof(atomic_t),
81319 + .maxlen = sizeof(atomic_unchecked_t),
81320 .mode = 0644,
81321 .proc_handler = read_reset_stat,
81322 },
81323 {
81324 .procname = "rdma_stat_rq_starve",
81325 .data = &rdma_stat_rq_starve,
81326 - .maxlen = sizeof(atomic_t),
81327 + .maxlen = sizeof(atomic_unchecked_t),
81328 .mode = 0644,
81329 .proc_handler = read_reset_stat,
81330 },
81331 {
81332 .procname = "rdma_stat_rq_poll",
81333 .data = &rdma_stat_rq_poll,
81334 - .maxlen = sizeof(atomic_t),
81335 + .maxlen = sizeof(atomic_unchecked_t),
81336 .mode = 0644,
81337 .proc_handler = read_reset_stat,
81338 },
81339 {
81340 .procname = "rdma_stat_rq_prod",
81341 .data = &rdma_stat_rq_prod,
81342 - .maxlen = sizeof(atomic_t),
81343 + .maxlen = sizeof(atomic_unchecked_t),
81344 .mode = 0644,
81345 .proc_handler = read_reset_stat,
81346 },
81347 {
81348 .procname = "rdma_stat_sq_poll",
81349 .data = &rdma_stat_sq_poll,
81350 - .maxlen = sizeof(atomic_t),
81351 + .maxlen = sizeof(atomic_unchecked_t),
81352 .mode = 0644,
81353 .proc_handler = read_reset_stat,
81354 },
81355 {
81356 .procname = "rdma_stat_sq_prod",
81357 .data = &rdma_stat_sq_prod,
81358 - .maxlen = sizeof(atomic_t),
81359 + .maxlen = sizeof(atomic_unchecked_t),
81360 .mode = 0644,
81361 .proc_handler = read_reset_stat,
81362 },
81363 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
81364 index 41cb63b..c4a1489 100644
81365 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
81366 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
81367 @@ -501,7 +501,7 @@ next_sge:
81368 svc_rdma_put_context(ctxt, 0);
81369 goto out;
81370 }
81371 - atomic_inc(&rdma_stat_read);
81372 + atomic_inc_unchecked(&rdma_stat_read);
81373
81374 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
81375 chl_map->ch[ch_no].count -= read_wr.num_sge;
81376 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
81377 dto_q);
81378 list_del_init(&ctxt->dto_q);
81379 } else {
81380 - atomic_inc(&rdma_stat_rq_starve);
81381 + atomic_inc_unchecked(&rdma_stat_rq_starve);
81382 clear_bit(XPT_DATA, &xprt->xpt_flags);
81383 ctxt = NULL;
81384 }
81385 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
81386 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
81387 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
81388 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
81389 - atomic_inc(&rdma_stat_recv);
81390 + atomic_inc_unchecked(&rdma_stat_recv);
81391
81392 /* Build up the XDR from the receive buffers. */
81393 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
81394 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
81395 index 42eb7ba..c887c45 100644
81396 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
81397 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
81398 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
81399 write_wr.wr.rdma.remote_addr = to;
81400
81401 /* Post It */
81402 - atomic_inc(&rdma_stat_write);
81403 + atomic_inc_unchecked(&rdma_stat_write);
81404 if (svc_rdma_send(xprt, &write_wr))
81405 goto err;
81406 return 0;
81407 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
81408 index 62e4f9b..dd3f2d7 100644
81409 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
81410 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
81411 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
81412 return;
81413
81414 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
81415 - atomic_inc(&rdma_stat_rq_poll);
81416 + atomic_inc_unchecked(&rdma_stat_rq_poll);
81417
81418 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
81419 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
81420 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
81421 }
81422
81423 if (ctxt)
81424 - atomic_inc(&rdma_stat_rq_prod);
81425 + atomic_inc_unchecked(&rdma_stat_rq_prod);
81426
81427 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
81428 /*
81429 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
81430 return;
81431
81432 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
81433 - atomic_inc(&rdma_stat_sq_poll);
81434 + atomic_inc_unchecked(&rdma_stat_sq_poll);
81435 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
81436 if (wc.status != IB_WC_SUCCESS)
81437 /* Close the transport */
81438 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
81439 }
81440
81441 if (ctxt)
81442 - atomic_inc(&rdma_stat_sq_prod);
81443 + atomic_inc_unchecked(&rdma_stat_sq_prod);
81444 }
81445
81446 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
81447 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
81448 spin_lock_bh(&xprt->sc_lock);
81449 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
81450 spin_unlock_bh(&xprt->sc_lock);
81451 - atomic_inc(&rdma_stat_sq_starve);
81452 + atomic_inc_unchecked(&rdma_stat_sq_starve);
81453
81454 /* See if we can opportunistically reap SQ WR to make room */
81455 sq_cq_reap(xprt);
81456 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
81457 index e3a6e37..be2ea77 100644
81458 --- a/net/sysctl_net.c
81459 +++ b/net/sysctl_net.c
81460 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
81461 struct ctl_table *table)
81462 {
81463 /* Allow network administrator to have same access as root. */
81464 - if (capable(CAP_NET_ADMIN)) {
81465 + if (capable_nolog(CAP_NET_ADMIN)) {
81466 int mode = (table->mode >> 6) & 7;
81467 return (mode << 6) | (mode << 3) | mode;
81468 }
81469 diff --git a/net/tipc/link.c b/net/tipc/link.c
81470 index a79c755..eca357d 100644
81471 --- a/net/tipc/link.c
81472 +++ b/net/tipc/link.c
81473 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
81474 struct tipc_msg fragm_hdr;
81475 struct sk_buff *buf, *buf_chain, *prev;
81476 u32 fragm_crs, fragm_rest, hsz, sect_rest;
81477 - const unchar *sect_crs;
81478 + const unchar __user *sect_crs;
81479 int curr_sect;
81480 u32 fragm_no;
81481
81482 @@ -1210,7 +1210,7 @@ again:
81483
81484 if (!sect_rest) {
81485 sect_rest = msg_sect[++curr_sect].iov_len;
81486 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
81487 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
81488 }
81489
81490 if (sect_rest < fragm_rest)
81491 @@ -1229,7 +1229,7 @@ error:
81492 }
81493 } else
81494 skb_copy_to_linear_data_offset(buf, fragm_crs,
81495 - sect_crs, sz);
81496 + (const void __force_kernel *)sect_crs, sz);
81497 sect_crs += sz;
81498 sect_rest -= sz;
81499 fragm_crs += sz;
81500 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
81501 index f2db8a8..9245aa4 100644
81502 --- a/net/tipc/msg.c
81503 +++ b/net/tipc/msg.c
81504 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
81505 msg_sect[cnt].iov_len);
81506 else
81507 skb_copy_to_linear_data_offset(*buf, pos,
81508 - msg_sect[cnt].iov_base,
81509 + (const void __force_kernel *)msg_sect[cnt].iov_base,
81510 msg_sect[cnt].iov_len);
81511 pos += msg_sect[cnt].iov_len;
81512 }
81513 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
81514 index 0f7d0d0..00f89bf 100644
81515 --- a/net/tipc/subscr.c
81516 +++ b/net/tipc/subscr.c
81517 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
81518 {
81519 struct iovec msg_sect;
81520
81521 - msg_sect.iov_base = (void *)&sub->evt;
81522 + msg_sect.iov_base = (void __force_user *)&sub->evt;
81523 msg_sect.iov_len = sizeof(struct tipc_event);
81524
81525 sub->evt.event = htohl(event, sub->swap);
81526 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
81527 index 5b5c876..3127bf7 100644
81528 --- a/net/unix/af_unix.c
81529 +++ b/net/unix/af_unix.c
81530 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
81531 err = -ECONNREFUSED;
81532 if (!S_ISSOCK(inode->i_mode))
81533 goto put_fail;
81534 +
81535 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
81536 + err = -EACCES;
81537 + goto put_fail;
81538 + }
81539 +
81540 u = unix_find_socket_byinode(inode);
81541 if (!u)
81542 goto put_fail;
81543 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
81544 if (u) {
81545 struct dentry *dentry;
81546 dentry = unix_sk(u)->path.dentry;
81547 +
81548 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
81549 + err = -EPERM;
81550 + sock_put(u);
81551 + goto fail;
81552 + }
81553 +
81554 if (dentry)
81555 touch_atime(&unix_sk(u)->path);
81556 } else
81557 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
81558 */
81559 err = security_path_mknod(&path, dentry, mode, 0);
81560 if (!err) {
81561 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
81562 + err = -EACCES;
81563 + goto out;
81564 + }
81565 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
81566 if (!err) {
81567 res->mnt = mntget(path.mnt);
81568 res->dentry = dget(dentry);
81569 + gr_handle_create(dentry, path.mnt);
81570 }
81571 }
81572 +out:
81573 done_path_create(&path, dentry);
81574 return err;
81575 }
81576 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
81577 index c8717c1..08539f5 100644
81578 --- a/net/wireless/wext-core.c
81579 +++ b/net/wireless/wext-core.c
81580 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
81581 */
81582
81583 /* Support for very large requests */
81584 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
81585 - (user_length > descr->max_tokens)) {
81586 + if (user_length > descr->max_tokens) {
81587 /* Allow userspace to GET more than max so
81588 * we can support any size GET requests.
81589 * There is still a limit : -ENOMEM.
81590 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
81591 }
81592 }
81593
81594 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
81595 - /*
81596 - * If this is a GET, but not NOMAX, it means that the extra
81597 - * data is not bounded by userspace, but by max_tokens. Thus
81598 - * set the length to max_tokens. This matches the extra data
81599 - * allocation.
81600 - * The driver should fill it with the number of tokens it
81601 - * provided, and it may check iwp->length rather than having
81602 - * knowledge of max_tokens. If the driver doesn't change the
81603 - * iwp->length, this ioctl just copies back max_token tokens
81604 - * filled with zeroes. Hopefully the driver isn't claiming
81605 - * them to be valid data.
81606 - */
81607 - iwp->length = descr->max_tokens;
81608 - }
81609 -
81610 err = handler(dev, info, (union iwreq_data *) iwp, extra);
81611
81612 iwp->length += essid_compat;
81613 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
81614 index 41eabc4..8d4e6d6 100644
81615 --- a/net/xfrm/xfrm_policy.c
81616 +++ b/net/xfrm/xfrm_policy.c
81617 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
81618 {
81619 policy->walk.dead = 1;
81620
81621 - atomic_inc(&policy->genid);
81622 + atomic_inc_unchecked(&policy->genid);
81623
81624 if (del_timer(&policy->timer))
81625 xfrm_pol_put(policy);
81626 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
81627 hlist_add_head(&policy->bydst, chain);
81628 xfrm_pol_hold(policy);
81629 net->xfrm.policy_count[dir]++;
81630 - atomic_inc(&flow_cache_genid);
81631 + atomic_inc_unchecked(&flow_cache_genid);
81632 rt_genid_bump(net);
81633 if (delpol)
81634 __xfrm_policy_unlink(delpol, dir);
81635 @@ -1550,7 +1550,7 @@ free_dst:
81636 goto out;
81637 }
81638
81639 -static int inline
81640 +static inline int
81641 xfrm_dst_alloc_copy(void **target, const void *src, int size)
81642 {
81643 if (!*target) {
81644 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
81645 return 0;
81646 }
81647
81648 -static int inline
81649 +static inline int
81650 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
81651 {
81652 #ifdef CONFIG_XFRM_SUB_POLICY
81653 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
81654 #endif
81655 }
81656
81657 -static int inline
81658 +static inline int
81659 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
81660 {
81661 #ifdef CONFIG_XFRM_SUB_POLICY
81662 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
81663
81664 xdst->num_pols = num_pols;
81665 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
81666 - xdst->policy_genid = atomic_read(&pols[0]->genid);
81667 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
81668
81669 return xdst;
81670 }
81671 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
81672 if (xdst->xfrm_genid != dst->xfrm->genid)
81673 return 0;
81674 if (xdst->num_pols > 0 &&
81675 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
81676 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
81677 return 0;
81678
81679 mtu = dst_mtu(dst->child);
81680 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
81681 sizeof(pol->xfrm_vec[i].saddr));
81682 pol->xfrm_vec[i].encap_family = mp->new_family;
81683 /* flush bundles */
81684 - atomic_inc(&pol->genid);
81685 + atomic_inc_unchecked(&pol->genid);
81686 }
81687 }
81688
81689 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
81690 index 3459692..eefb515 100644
81691 --- a/net/xfrm/xfrm_state.c
81692 +++ b/net/xfrm/xfrm_state.c
81693 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
81694 if (!try_module_get(afinfo->owner))
81695 goto out;
81696
81697 - mode->afinfo = afinfo;
81698 + pax_open_kernel();
81699 + *(void **)&mode->afinfo = afinfo;
81700 + pax_close_kernel();
81701 modemap[mode->encap] = mode;
81702 err = 0;
81703
81704 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
81705 index 0e801c3..5c8ad3b 100644
81706 --- a/scripts/Makefile.build
81707 +++ b/scripts/Makefile.build
81708 @@ -111,7 +111,7 @@ endif
81709 endif
81710
81711 # Do not include host rules unless needed
81712 -ifneq ($(hostprogs-y)$(hostprogs-m),)
81713 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
81714 include scripts/Makefile.host
81715 endif
81716
81717 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
81718 index 686cb0d..9d653bf 100644
81719 --- a/scripts/Makefile.clean
81720 +++ b/scripts/Makefile.clean
81721 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
81722 __clean-files := $(extra-y) $(always) \
81723 $(targets) $(clean-files) \
81724 $(host-progs) \
81725 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
81726 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
81727 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
81728
81729 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
81730
81731 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
81732 index 1ac414f..38575f7 100644
81733 --- a/scripts/Makefile.host
81734 +++ b/scripts/Makefile.host
81735 @@ -31,6 +31,8 @@
81736 # Note: Shared libraries consisting of C++ files are not supported
81737
81738 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
81739 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
81740 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
81741
81742 # C code
81743 # Executables compiled from a single .c file
81744 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
81745 # Shared libaries (only .c supported)
81746 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
81747 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
81748 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
81749 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
81750 # Remove .so files from "xxx-objs"
81751 host-cobjs := $(filter-out %.so,$(host-cobjs))
81752 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
81753
81754 -#Object (.o) files used by the shared libaries
81755 +# Object (.o) files used by the shared libaries
81756 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
81757 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
81758
81759 # output directory for programs/.o files
81760 # hostprogs-y := tools/build may have been specified. Retrieve directory
81761 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
81762 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
81763 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
81764 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
81765 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
81766 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
81767 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
81768 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
81769
81770 obj-dirs += $(host-objdirs)
81771 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
81772 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
81773 $(call if_changed_dep,host-cshobjs)
81774
81775 +# Compile .c file, create position independent .o file
81776 +# host-cxxshobjs -> .o
81777 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
81778 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
81779 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
81780 + $(call if_changed_dep,host-cxxshobjs)
81781 +
81782 # Link a shared library, based on position independent .o files
81783 # *.o -> .so shared library (host-cshlib)
81784 quiet_cmd_host-cshlib = HOSTLLD -shared $@
81785 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
81786 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
81787 $(call if_changed,host-cshlib)
81788
81789 +# Link a shared library, based on position independent .o files
81790 +# *.o -> .so shared library (host-cxxshlib)
81791 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
81792 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
81793 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
81794 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
81795 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
81796 + $(call if_changed,host-cxxshlib)
81797 +
81798 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
81799 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
81800 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
81801
81802 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
81803 index cb1f50c..cef2a7c 100644
81804 --- a/scripts/basic/fixdep.c
81805 +++ b/scripts/basic/fixdep.c
81806 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
81807 /*
81808 * Lookup a value in the configuration string.
81809 */
81810 -static int is_defined_config(const char *name, int len, unsigned int hash)
81811 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
81812 {
81813 struct item *aux;
81814
81815 @@ -211,10 +211,10 @@ static void clear_config(void)
81816 /*
81817 * Record the use of a CONFIG_* word.
81818 */
81819 -static void use_config(const char *m, int slen)
81820 +static void use_config(const char *m, unsigned int slen)
81821 {
81822 unsigned int hash = strhash(m, slen);
81823 - int c, i;
81824 + unsigned int c, i;
81825
81826 if (is_defined_config(m, slen, hash))
81827 return;
81828 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
81829
81830 static void parse_config_file(const char *map, size_t len)
81831 {
81832 - const int *end = (const int *) (map + len);
81833 + const unsigned int *end = (const unsigned int *) (map + len);
81834 /* start at +1, so that p can never be < map */
81835 - const int *m = (const int *) map + 1;
81836 + const unsigned int *m = (const unsigned int *) map + 1;
81837 const char *p, *q;
81838
81839 for (; m < end; m++) {
81840 @@ -406,7 +406,7 @@ static void print_deps(void)
81841 static void traps(void)
81842 {
81843 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
81844 - int *p = (int *)test;
81845 + unsigned int *p = (unsigned int *)test;
81846
81847 if (*p != INT_CONF) {
81848 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
81849 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
81850 new file mode 100644
81851 index 0000000..008ac1a
81852 --- /dev/null
81853 +++ b/scripts/gcc-plugin.sh
81854 @@ -0,0 +1,17 @@
81855 +#!/bin/bash
81856 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
81857 +#include "gcc-plugin.h"
81858 +#include "tree.h"
81859 +#include "tm.h"
81860 +#include "rtl.h"
81861 +#ifdef ENABLE_BUILD_WITH_CXX
81862 +#warning $2
81863 +#else
81864 +#warning $1
81865 +#endif
81866 +EOF`
81867 +if [ $? -eq 0 ]
81868 +then
81869 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
81870 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
81871 +fi
81872 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
81873 index b3d907e..a4782ab 100644
81874 --- a/scripts/link-vmlinux.sh
81875 +++ b/scripts/link-vmlinux.sh
81876 @@ -152,7 +152,7 @@ else
81877 fi;
81878
81879 # final build of init/
81880 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
81881 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
81882
81883 kallsymso=""
81884 kallsyms_vmlinux=""
81885 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
81886 index df4fc23..0ea719d 100644
81887 --- a/scripts/mod/file2alias.c
81888 +++ b/scripts/mod/file2alias.c
81889 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
81890 unsigned long size, unsigned long id_size,
81891 void *symval)
81892 {
81893 - int i;
81894 + unsigned int i;
81895
81896 if (size % id_size || size < id_size) {
81897 if (cross_build != 0)
81898 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
81899 /* USB is special because the bcdDevice can be matched against a numeric range */
81900 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
81901 static void do_usb_entry(struct usb_device_id *id,
81902 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
81903 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
81904 unsigned char range_lo, unsigned char range_hi,
81905 unsigned char max, struct module *mod)
81906 {
81907 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
81908 {
81909 unsigned int devlo, devhi;
81910 unsigned char chi, clo, max;
81911 - int ndigits;
81912 + unsigned int ndigits;
81913
81914 id->match_flags = TO_NATIVE(id->match_flags);
81915 id->idVendor = TO_NATIVE(id->idVendor);
81916 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
81917 for (i = 0; i < count; i++) {
81918 const char *id = (char *)devs[i].id;
81919 char acpi_id[sizeof(devs[0].id)];
81920 - int j;
81921 + unsigned int j;
81922
81923 buf_printf(&mod->dev_table_buf,
81924 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
81925 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
81926
81927 for (j = 0; j < PNP_MAX_DEVICES; j++) {
81928 const char *id = (char *)card->devs[j].id;
81929 - int i2, j2;
81930 + unsigned int i2, j2;
81931 int dup = 0;
81932
81933 if (!id[0])
81934 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
81935 /* add an individual alias for every device entry */
81936 if (!dup) {
81937 char acpi_id[sizeof(card->devs[0].id)];
81938 - int k;
81939 + unsigned int k;
81940
81941 buf_printf(&mod->dev_table_buf,
81942 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
81943 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
81944 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
81945 char *alias)
81946 {
81947 - int i, j;
81948 + unsigned int i, j;
81949
81950 sprintf(alias, "dmi*");
81951
81952 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
81953 index 0d93856..e828363 100644
81954 --- a/scripts/mod/modpost.c
81955 +++ b/scripts/mod/modpost.c
81956 @@ -933,6 +933,7 @@ enum mismatch {
81957 ANY_INIT_TO_ANY_EXIT,
81958 ANY_EXIT_TO_ANY_INIT,
81959 EXPORT_TO_INIT_EXIT,
81960 + DATA_TO_TEXT
81961 };
81962
81963 struct sectioncheck {
81964 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
81965 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
81966 .mismatch = EXPORT_TO_INIT_EXIT,
81967 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
81968 +},
81969 +/* Do not reference code from writable data */
81970 +{
81971 + .fromsec = { DATA_SECTIONS, NULL },
81972 + .tosec = { TEXT_SECTIONS, NULL },
81973 + .mismatch = DATA_TO_TEXT
81974 }
81975 };
81976
81977 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
81978 continue;
81979 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
81980 continue;
81981 - if (sym->st_value == addr)
81982 - return sym;
81983 /* Find a symbol nearby - addr are maybe negative */
81984 d = sym->st_value - addr;
81985 + if (d == 0)
81986 + return sym;
81987 if (d < 0)
81988 d = addr - sym->st_value;
81989 if (d < distance) {
81990 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
81991 tosym, prl_to, prl_to, tosym);
81992 free(prl_to);
81993 break;
81994 + case DATA_TO_TEXT:
81995 +#if 0
81996 + fprintf(stderr,
81997 + "The %s %s:%s references\n"
81998 + "the %s %s:%s%s\n",
81999 + from, fromsec, fromsym, to, tosec, tosym, to_p);
82000 +#endif
82001 + break;
82002 }
82003 fprintf(stderr, "\n");
82004 }
82005 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
82006 static void check_sec_ref(struct module *mod, const char *modname,
82007 struct elf_info *elf)
82008 {
82009 - int i;
82010 + unsigned int i;
82011 Elf_Shdr *sechdrs = elf->sechdrs;
82012
82013 /* Walk through all sections */
82014 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
82015 va_end(ap);
82016 }
82017
82018 -void buf_write(struct buffer *buf, const char *s, int len)
82019 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
82020 {
82021 if (buf->size - buf->pos < len) {
82022 buf->size += len + SZ;
82023 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
82024 if (fstat(fileno(file), &st) < 0)
82025 goto close_write;
82026
82027 - if (st.st_size != b->pos)
82028 + if (st.st_size != (off_t)b->pos)
82029 goto close_write;
82030
82031 tmp = NOFAIL(malloc(b->pos));
82032 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
82033 index 51207e4..f7d603d 100644
82034 --- a/scripts/mod/modpost.h
82035 +++ b/scripts/mod/modpost.h
82036 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
82037
82038 struct buffer {
82039 char *p;
82040 - int pos;
82041 - int size;
82042 + unsigned int pos;
82043 + unsigned int size;
82044 };
82045
82046 void __attribute__((format(printf, 2, 3)))
82047 buf_printf(struct buffer *buf, const char *fmt, ...);
82048
82049 void
82050 -buf_write(struct buffer *buf, const char *s, int len);
82051 +buf_write(struct buffer *buf, const char *s, unsigned int len);
82052
82053 struct module {
82054 struct module *next;
82055 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
82056 index 9dfcd6d..099068e 100644
82057 --- a/scripts/mod/sumversion.c
82058 +++ b/scripts/mod/sumversion.c
82059 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
82060 goto out;
82061 }
82062
82063 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
82064 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
82065 warn("writing sum in %s failed: %s\n",
82066 filename, strerror(errno));
82067 goto out;
82068 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
82069 index 5c11312..72742b5 100644
82070 --- a/scripts/pnmtologo.c
82071 +++ b/scripts/pnmtologo.c
82072 @@ -237,14 +237,14 @@ static void write_header(void)
82073 fprintf(out, " * Linux logo %s\n", logoname);
82074 fputs(" */\n\n", out);
82075 fputs("#include <linux/linux_logo.h>\n\n", out);
82076 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
82077 + fprintf(out, "static unsigned char %s_data[] = {\n",
82078 logoname);
82079 }
82080
82081 static void write_footer(void)
82082 {
82083 fputs("\n};\n\n", out);
82084 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
82085 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
82086 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
82087 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
82088 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
82089 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
82090 fputs("\n};\n\n", out);
82091
82092 /* write logo clut */
82093 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
82094 + fprintf(out, "static unsigned char %s_clut[] = {\n",
82095 logoname);
82096 write_hex_cnt = 0;
82097 for (i = 0; i < logo_clutsize; i++) {
82098 diff --git a/security/Kconfig b/security/Kconfig
82099 index e9c6ac7..a9bcf23 100644
82100 --- a/security/Kconfig
82101 +++ b/security/Kconfig
82102 @@ -4,6 +4,896 @@
82103
82104 menu "Security options"
82105
82106 +menu "Grsecurity"
82107 +
82108 + config ARCH_TRACK_EXEC_LIMIT
82109 + bool
82110 +
82111 + config PAX_KERNEXEC_PLUGIN
82112 + bool
82113 +
82114 + config PAX_PER_CPU_PGD
82115 + bool
82116 +
82117 + config TASK_SIZE_MAX_SHIFT
82118 + int
82119 + depends on X86_64
82120 + default 47 if !PAX_PER_CPU_PGD
82121 + default 42 if PAX_PER_CPU_PGD
82122 +
82123 + config PAX_ENABLE_PAE
82124 + bool
82125 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
82126 +
82127 + config PAX_USERCOPY_SLABS
82128 + bool
82129 +
82130 +config GRKERNSEC
82131 + bool "Grsecurity"
82132 + select CRYPTO
82133 + select CRYPTO_SHA256
82134 + select PROC_FS
82135 + select STOP_MACHINE
82136 + help
82137 + If you say Y here, you will be able to configure many features
82138 + that will enhance the security of your system. It is highly
82139 + recommended that you say Y here and read through the help
82140 + for each option so that you fully understand the features and
82141 + can evaluate their usefulness for your machine.
82142 +
82143 +choice
82144 + prompt "Configuration Method"
82145 + depends on GRKERNSEC
82146 + default GRKERNSEC_CONFIG_CUSTOM
82147 + help
82148 +
82149 +config GRKERNSEC_CONFIG_AUTO
82150 + bool "Automatic"
82151 + help
82152 + If you choose this configuration method, you'll be able to answer a small
82153 + number of simple questions about how you plan to use this kernel.
82154 + The settings of grsecurity and PaX will be automatically configured for
82155 + the highest commonly-used settings within the provided constraints.
82156 +
82157 + If you require additional configuration, custom changes can still be made
82158 + from the "custom configuration" menu.
82159 +
82160 +config GRKERNSEC_CONFIG_CUSTOM
82161 + bool "Custom"
82162 + help
82163 + If you choose this configuration method, you'll be able to configure all
82164 + grsecurity and PaX settings manually. Via this method, no options are
82165 + automatically enabled.
82166 +
82167 +endchoice
82168 +
82169 +choice
82170 + prompt "Usage Type"
82171 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82172 + default GRKERNSEC_CONFIG_SERVER
82173 + help
82174 +
82175 +config GRKERNSEC_CONFIG_SERVER
82176 + bool "Server"
82177 + help
82178 + Choose this option if you plan to use this kernel on a server.
82179 +
82180 +config GRKERNSEC_CONFIG_DESKTOP
82181 + bool "Desktop"
82182 + help
82183 + Choose this option if you plan to use this kernel on a desktop.
82184 +
82185 +endchoice
82186 +
82187 +choice
82188 + prompt "Virtualization Type"
82189 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
82190 + default GRKERNSEC_CONFIG_VIRT_NONE
82191 + help
82192 +
82193 +config GRKERNSEC_CONFIG_VIRT_NONE
82194 + bool "None"
82195 + help
82196 + Choose this option if this kernel will be run on bare metal.
82197 +
82198 +config GRKERNSEC_CONFIG_VIRT_GUEST
82199 + bool "Guest"
82200 + help
82201 + Choose this option if this kernel will be run as a VM guest.
82202 +
82203 +config GRKERNSEC_CONFIG_VIRT_HOST
82204 + bool "Host"
82205 + help
82206 + Choose this option if this kernel will be run as a VM host.
82207 +
82208 +endchoice
82209 +
82210 +choice
82211 + prompt "Virtualization Hardware"
82212 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
82213 + help
82214 +
82215 +config GRKERNSEC_CONFIG_VIRT_EPT
82216 + bool "EPT/RVI Processor Support"
82217 + depends on X86
82218 + help
82219 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
82220 + hardware virtualization. This allows for additional kernel hardening protections
82221 + to operate without additional performance impact.
82222 +
82223 + To see if your Intel processor supports EPT, see:
82224 + http://ark.intel.com/Products/VirtualizationTechnology
82225 + (Most Core i3/5/7 support EPT)
82226 +
82227 + To see if your AMD processor supports RVI, see:
82228 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
82229 +
82230 +config GRKERNSEC_CONFIG_VIRT_SOFT
82231 + bool "First-gen/No Hardware Virtualization"
82232 + help
82233 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
82234 + support hardware virtualization or doesn't support the EPT/RVI extensions.
82235 +
82236 +endchoice
82237 +
82238 +choice
82239 + prompt "Virtualization Software"
82240 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
82241 + help
82242 +
82243 +config GRKERNSEC_CONFIG_VIRT_XEN
82244 + bool "Xen"
82245 + help
82246 + Choose this option if this kernel is running as a Xen guest or host.
82247 +
82248 +config GRKERNSEC_CONFIG_VIRT_VMWARE
82249 + bool "VMWare"
82250 + help
82251 + Choose this option if this kernel is running as a VMWare guest or host.
82252 +
82253 +config GRKERNSEC_CONFIG_VIRT_KVM
82254 + bool "KVM"
82255 + help
82256 + Choose this option if this kernel is running as a KVM guest or host.
82257 +
82258 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
82259 + bool "VirtualBox"
82260 + help
82261 + Choose this option if this kernel is running as a VirtualBox guest or host.
82262 +
82263 +endchoice
82264 +
82265 +choice
82266 + prompt "Required Priorities"
82267 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82268 + default GRKERNSEC_CONFIG_PRIORITY_PERF
82269 + help
82270 +
82271 +config GRKERNSEC_CONFIG_PRIORITY_PERF
82272 + bool "Performance"
82273 + help
82274 + Choose this option if performance is of highest priority for this deployment
82275 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
82276 + and freed memory sanitizing will be disabled.
82277 +
82278 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
82279 + bool "Security"
82280 + help
82281 + Choose this option if security is of highest priority for this deployment of
82282 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
82283 + be enabled for this kernel. In a worst-case scenario, these features can
82284 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
82285 +
82286 +endchoice
82287 +
82288 +menu "Default Special Groups"
82289 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82290 +
82291 +config GRKERNSEC_PROC_GID
82292 + int "GID exempted from /proc restrictions"
82293 + default 1001
82294 + help
82295 + Setting this GID determines which group will be exempted from
82296 + grsecurity's /proc restrictions, allowing users of the specified
82297 + group to view network statistics and the existence of other users'
82298 + processes on the system. This GID may also be chosen at boot time
82299 + via "grsec_proc_gid=" on the kernel commandline.
82300 +
82301 +config GRKERNSEC_TPE_UNTRUSTED_GID
82302 + int "GID for TPE-untrusted users"
82303 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
82304 + default 1005
82305 + help
82306 + Setting this GID determines which group untrusted users should
82307 + be added to. These users will be placed under grsecurity's Trusted Path
82308 + Execution mechanism, preventing them from executing their own binaries.
82309 + The users will only be able to execute binaries in directories owned and
82310 + writable only by the root user. If the sysctl option is enabled, a sysctl
82311 + option with name "tpe_gid" is created.
82312 +
82313 +config GRKERNSEC_TPE_TRUSTED_GID
82314 + int "GID for TPE-trusted users"
82315 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
82316 + default 1005
82317 + help
82318 + Setting this GID determines what group TPE restrictions will be
82319 + *disabled* for. If the sysctl option is enabled, a sysctl option
82320 + with name "tpe_gid" is created.
82321 +
82322 +config GRKERNSEC_SYMLINKOWN_GID
82323 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
82324 + depends on GRKERNSEC_CONFIG_SERVER
82325 + default 1006
82326 + help
82327 + Setting this GID determines what group kernel-enforced
82328 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
82329 + is enabled, a sysctl option with name "symlinkown_gid" is created.
82330 +
82331 +
82332 +endmenu
82333 +
82334 +menu "Customize Configuration"
82335 +depends on GRKERNSEC
82336 +
82337 +menu "PaX"
82338 +
82339 +config PAX
82340 + bool "Enable various PaX features"
82341 + default y if GRKERNSEC_CONFIG_AUTO
82342 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
82343 + help
82344 + This allows you to enable various PaX features. PaX adds
82345 + intrusion prevention mechanisms to the kernel that reduce
82346 + the risks posed by exploitable memory corruption bugs.
82347 +
82348 +menu "PaX Control"
82349 + depends on PAX
82350 +
82351 +config PAX_SOFTMODE
82352 + bool 'Support soft mode'
82353 + help
82354 + Enabling this option will allow you to run PaX in soft mode, that
82355 + is, PaX features will not be enforced by default, only on executables
82356 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
82357 + support as they are the only way to mark executables for soft mode use.
82358 +
82359 + Soft mode can be activated by using the "pax_softmode=1" kernel command
82360 + line option on boot. Furthermore you can control various PaX features
82361 + at runtime via the entries in /proc/sys/kernel/pax.
82362 +
82363 +config PAX_EI_PAX
82364 + bool 'Use legacy ELF header marking'
82365 + default y if GRKERNSEC_CONFIG_AUTO
82366 + help
82367 + Enabling this option will allow you to control PaX features on
82368 + a per executable basis via the 'chpax' utility available at
82369 + http://pax.grsecurity.net/. The control flags will be read from
82370 + an otherwise reserved part of the ELF header. This marking has
82371 + numerous drawbacks (no support for soft-mode, toolchain does not
82372 + know about the non-standard use of the ELF header) therefore it
82373 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
82374 + support.
82375 +
82376 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
82377 + support as well, they will override the legacy EI_PAX marks.
82378 +
82379 + If you enable none of the marking options then all applications
82380 + will run with PaX enabled on them by default.
82381 +
82382 +config PAX_PT_PAX_FLAGS
82383 + bool 'Use ELF program header marking'
82384 + default y if GRKERNSEC_CONFIG_AUTO
82385 + help
82386 + Enabling this option will allow you to control PaX features on
82387 + a per executable basis via the 'paxctl' utility available at
82388 + http://pax.grsecurity.net/. The control flags will be read from
82389 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
82390 + has the benefits of supporting both soft mode and being fully
82391 + integrated into the toolchain (the binutils patch is available
82392 + from http://pax.grsecurity.net).
82393 +
82394 + Note that if you enable the legacy EI_PAX marking support as well,
82395 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
82396 +
82397 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
82398 + must make sure that the marks are the same if a binary has both marks.
82399 +
82400 + If you enable none of the marking options then all applications
82401 + will run with PaX enabled on them by default.
82402 +
82403 +config PAX_XATTR_PAX_FLAGS
82404 + bool 'Use filesystem extended attributes marking'
82405 + default y if GRKERNSEC_CONFIG_AUTO
82406 + select CIFS_XATTR if CIFS
82407 + select EXT2_FS_XATTR if EXT2_FS
82408 + select EXT3_FS_XATTR if EXT3_FS
82409 + select EXT4_FS_XATTR if EXT4_FS
82410 + select JFFS2_FS_XATTR if JFFS2_FS
82411 + select REISERFS_FS_XATTR if REISERFS_FS
82412 + select SQUASHFS_XATTR if SQUASHFS
82413 + select TMPFS_XATTR if TMPFS
82414 + select UBIFS_FS_XATTR if UBIFS_FS
82415 + help
82416 + Enabling this option will allow you to control PaX features on
82417 + a per executable basis via the 'setfattr' utility. The control
82418 + flags will be read from the user.pax.flags extended attribute of
82419 + the file. This marking has the benefit of supporting binary-only
82420 + applications that self-check themselves (e.g., skype) and would
82421 + not tolerate chpax/paxctl changes. The main drawback is that
82422 + extended attributes are not supported by some filesystems (e.g.,
82423 + isofs, udf, vfat) so copying files through such filesystems will
82424 + lose the extended attributes and these PaX markings.
82425 +
82426 + Note that if you enable the legacy EI_PAX marking support as well,
82427 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
82428 +
82429 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
82430 + must make sure that the marks are the same if a binary has both marks.
82431 +
82432 + If you enable none of the marking options then all applications
82433 + will run with PaX enabled on them by default.
82434 +
82435 +choice
82436 + prompt 'MAC system integration'
82437 + default PAX_HAVE_ACL_FLAGS
82438 + help
82439 + Mandatory Access Control systems have the option of controlling
82440 + PaX flags on a per executable basis, choose the method supported
82441 + by your particular system.
82442 +
82443 + - "none": if your MAC system does not interact with PaX,
82444 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
82445 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
82446 +
82447 + NOTE: this option is for developers/integrators only.
82448 +
82449 + config PAX_NO_ACL_FLAGS
82450 + bool 'none'
82451 +
82452 + config PAX_HAVE_ACL_FLAGS
82453 + bool 'direct'
82454 +
82455 + config PAX_HOOK_ACL_FLAGS
82456 + bool 'hook'
82457 +endchoice
82458 +
82459 +endmenu
82460 +
82461 +menu "Non-executable pages"
82462 + depends on PAX
82463 +
82464 +config PAX_NOEXEC
82465 + bool "Enforce non-executable pages"
82466 + default y if GRKERNSEC_CONFIG_AUTO
82467 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
82468 + help
82469 + By design some architectures do not allow for protecting memory
82470 + pages against execution or even if they do, Linux does not make
82471 + use of this feature. In practice this means that if a page is
82472 + readable (such as the stack or heap) it is also executable.
82473 +
82474 + There is a well known exploit technique that makes use of this
82475 + fact and a common programming mistake where an attacker can
82476 + introduce code of his choice somewhere in the attacked program's
82477 + memory (typically the stack or the heap) and then execute it.
82478 +
82479 + If the attacked program was running with different (typically
82480 + higher) privileges than that of the attacker, then he can elevate
82481 + his own privilege level (e.g. get a root shell, write to files for
82482 + which he does not have write access to, etc).
82483 +
82484 + Enabling this option will let you choose from various features
82485 + that prevent the injection and execution of 'foreign' code in
82486 + a program.
82487 +
82488 + This will also break programs that rely on the old behaviour and
82489 + expect that dynamically allocated memory via the malloc() family
82490 + of functions is executable (which it is not). Notable examples
82491 + are the XFree86 4.x server, the java runtime and wine.
82492 +
82493 +config PAX_PAGEEXEC
82494 + bool "Paging based non-executable pages"
82495 + default y if GRKERNSEC_CONFIG_AUTO
82496 + 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)
82497 + select S390_SWITCH_AMODE if S390
82498 + select S390_EXEC_PROTECT if S390
82499 + select ARCH_TRACK_EXEC_LIMIT if X86_32
82500 + help
82501 + This implementation is based on the paging feature of the CPU.
82502 + On i386 without hardware non-executable bit support there is a
82503 + variable but usually low performance impact, however on Intel's
82504 + P4 core based CPUs it is very high so you should not enable this
82505 + for kernels meant to be used on such CPUs.
82506 +
82507 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
82508 + with hardware non-executable bit support there is no performance
82509 + impact, on ppc the impact is negligible.
82510 +
82511 + Note that several architectures require various emulations due to
82512 + badly designed userland ABIs, this will cause a performance impact
82513 + but will disappear as soon as userland is fixed. For example, ppc
82514 + userland MUST have been built with secure-plt by a recent toolchain.
82515 +
82516 +config PAX_SEGMEXEC
82517 + bool "Segmentation based non-executable pages"
82518 + default y if GRKERNSEC_CONFIG_AUTO
82519 + depends on PAX_NOEXEC && X86_32
82520 + help
82521 + This implementation is based on the segmentation feature of the
82522 + CPU and has a very small performance impact, however applications
82523 + will be limited to a 1.5 GB address space instead of the normal
82524 + 3 GB.
82525 +
82526 +config PAX_EMUTRAMP
82527 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
82528 + default y if PARISC
82529 + help
82530 + There are some programs and libraries that for one reason or
82531 + another attempt to execute special small code snippets from
82532 + non-executable memory pages. Most notable examples are the
82533 + signal handler return code generated by the kernel itself and
82534 + the GCC trampolines.
82535 +
82536 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
82537 + such programs will no longer work under your kernel.
82538 +
82539 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
82540 + utilities to enable trampoline emulation for the affected programs
82541 + yet still have the protection provided by the non-executable pages.
82542 +
82543 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
82544 + your system will not even boot.
82545 +
82546 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
82547 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
82548 + for the affected files.
82549 +
82550 + NOTE: enabling this feature *may* open up a loophole in the
82551 + protection provided by non-executable pages that an attacker
82552 + could abuse. Therefore the best solution is to not have any
82553 + files on your system that would require this option. This can
82554 + be achieved by not using libc5 (which relies on the kernel
82555 + signal handler return code) and not using or rewriting programs
82556 + that make use of the nested function implementation of GCC.
82557 + Skilled users can just fix GCC itself so that it implements
82558 + nested function calls in a way that does not interfere with PaX.
82559 +
82560 +config PAX_EMUSIGRT
82561 + bool "Automatically emulate sigreturn trampolines"
82562 + depends on PAX_EMUTRAMP && PARISC
82563 + default y
82564 + help
82565 + Enabling this option will have the kernel automatically detect
82566 + and emulate signal return trampolines executing on the stack
82567 + that would otherwise lead to task termination.
82568 +
82569 + This solution is intended as a temporary one for users with
82570 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
82571 + Modula-3 runtime, etc) or executables linked to such, basically
82572 + everything that does not specify its own SA_RESTORER function in
82573 + normal executable memory like glibc 2.1+ does.
82574 +
82575 + On parisc you MUST enable this option, otherwise your system will
82576 + not even boot.
82577 +
82578 + NOTE: this feature cannot be disabled on a per executable basis
82579 + and since it *does* open up a loophole in the protection provided
82580 + by non-executable pages, the best solution is to not have any
82581 + files on your system that would require this option.
82582 +
82583 +config PAX_MPROTECT
82584 + bool "Restrict mprotect()"
82585 + default y if GRKERNSEC_CONFIG_AUTO
82586 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
82587 + help
82588 + Enabling this option will prevent programs from
82589 + - changing the executable status of memory pages that were
82590 + not originally created as executable,
82591 + - making read-only executable pages writable again,
82592 + - creating executable pages from anonymous memory,
82593 + - making read-only-after-relocations (RELRO) data pages writable again.
82594 +
82595 + You should say Y here to complete the protection provided by
82596 + the enforcement of non-executable pages.
82597 +
82598 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
82599 + this feature on a per file basis.
82600 +
82601 +config PAX_MPROTECT_COMPAT
82602 + bool "Use legacy/compat protection demoting (read help)"
82603 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
82604 + depends on PAX_MPROTECT
82605 + help
82606 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
82607 + by sending the proper error code to the application. For some broken
82608 + userland, this can cause problems with Python or other applications. The
82609 + current implementation however allows for applications like clamav to
82610 + detect if JIT compilation/execution is allowed and to fall back gracefully
82611 + to an interpreter-based mode if it does not. While we encourage everyone
82612 + to use the current implementation as-is and push upstream to fix broken
82613 + userland (note that the RWX logging option can assist with this), in some
82614 + environments this may not be possible. Having to disable MPROTECT
82615 + completely on certain binaries reduces the security benefit of PaX,
82616 + so this option is provided for those environments to revert to the old
82617 + behavior.
82618 +
82619 +config PAX_ELFRELOCS
82620 + bool "Allow ELF text relocations (read help)"
82621 + depends on PAX_MPROTECT
82622 + default n
82623 + help
82624 + Non-executable pages and mprotect() restrictions are effective
82625 + in preventing the introduction of new executable code into an
82626 + attacked task's address space. There remain only two venues
82627 + for this kind of attack: if the attacker can execute already
82628 + existing code in the attacked task then he can either have it
82629 + create and mmap() a file containing his code or have it mmap()
82630 + an already existing ELF library that does not have position
82631 + independent code in it and use mprotect() on it to make it
82632 + writable and copy his code there. While protecting against
82633 + the former approach is beyond PaX, the latter can be prevented
82634 + by having only PIC ELF libraries on one's system (which do not
82635 + need to relocate their code). If you are sure this is your case,
82636 + as is the case with all modern Linux distributions, then leave
82637 + this option disabled. You should say 'n' here.
82638 +
82639 +config PAX_ETEXECRELOCS
82640 + bool "Allow ELF ET_EXEC text relocations"
82641 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
82642 + select PAX_ELFRELOCS
82643 + default y
82644 + help
82645 + On some architectures there are incorrectly created applications
82646 + that require text relocations and would not work without enabling
82647 + this option. If you are an alpha, ia64 or parisc user, you should
82648 + enable this option and disable it once you have made sure that
82649 + none of your applications need it.
82650 +
82651 +config PAX_EMUPLT
82652 + bool "Automatically emulate ELF PLT"
82653 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
82654 + default y
82655 + help
82656 + Enabling this option will have the kernel automatically detect
82657 + and emulate the Procedure Linkage Table entries in ELF files.
82658 + On some architectures such entries are in writable memory, and
82659 + become non-executable leading to task termination. Therefore
82660 + it is mandatory that you enable this option on alpha, parisc,
82661 + sparc and sparc64, otherwise your system would not even boot.
82662 +
82663 + NOTE: this feature *does* open up a loophole in the protection
82664 + provided by the non-executable pages, therefore the proper
82665 + solution is to modify the toolchain to produce a PLT that does
82666 + not need to be writable.
82667 +
82668 +config PAX_DLRESOLVE
82669 + bool 'Emulate old glibc resolver stub'
82670 + depends on PAX_EMUPLT && SPARC
82671 + default n
82672 + help
82673 + This option is needed if userland has an old glibc (before 2.4)
82674 + that puts a 'save' instruction into the runtime generated resolver
82675 + stub that needs special emulation.
82676 +
82677 +config PAX_KERNEXEC
82678 + bool "Enforce non-executable kernel pages"
82679 + 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))
82680 + depends on (X86 || ARM_LPAE) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
82681 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
82682 + select PAX_KERNEXEC_PLUGIN if X86_64
82683 + help
82684 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
82685 + that is, enabling this option will make it harder to inject
82686 + and execute 'foreign' code in kernel memory itself.
82687 +
82688 +choice
82689 + prompt "Return Address Instrumentation Method"
82690 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
82691 + depends on PAX_KERNEXEC_PLUGIN
82692 + help
82693 + Select the method used to instrument function pointer dereferences.
82694 + Note that binary modules cannot be instrumented by this approach.
82695 +
82696 + Note that the implementation requires a gcc with plugin support,
82697 + i.e., gcc 4.5 or newer. You may need to install the supporting
82698 + headers explicitly in addition to the normal gcc package.
82699 +
82700 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
82701 + bool "bts"
82702 + help
82703 + This method is compatible with binary only modules but has
82704 + a higher runtime overhead.
82705 +
82706 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
82707 + bool "or"
82708 + depends on !PARAVIRT
82709 + help
82710 + This method is incompatible with binary only modules but has
82711 + a lower runtime overhead.
82712 +endchoice
82713 +
82714 +config PAX_KERNEXEC_PLUGIN_METHOD
82715 + string
82716 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
82717 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
82718 + default ""
82719 +
82720 +config PAX_KERNEXEC_MODULE_TEXT
82721 + int "Minimum amount of memory reserved for module code"
82722 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
82723 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
82724 + depends on PAX_KERNEXEC && X86_32 && MODULES
82725 + help
82726 + Due to implementation details the kernel must reserve a fixed
82727 + amount of memory for module code at compile time that cannot be
82728 + changed at runtime. Here you can specify the minimum amount
82729 + in MB that will be reserved. Due to the same implementation
82730 + details this size will always be rounded up to the next 2/4 MB
82731 + boundary (depends on PAE) so the actually available memory for
82732 + module code will usually be more than this minimum.
82733 +
82734 + The default 4 MB should be enough for most users but if you have
82735 + an excessive number of modules (e.g., most distribution configs
82736 + compile many drivers as modules) or use huge modules such as
82737 + nvidia's kernel driver, you will need to adjust this amount.
82738 + A good rule of thumb is to look at your currently loaded kernel
82739 + modules and add up their sizes.
82740 +
82741 +endmenu
82742 +
82743 +menu "Address Space Layout Randomization"
82744 + depends on PAX
82745 +
82746 +config PAX_ASLR
82747 + bool "Address Space Layout Randomization"
82748 + default y if GRKERNSEC_CONFIG_AUTO
82749 + help
82750 + Many if not most exploit techniques rely on the knowledge of
82751 + certain addresses in the attacked program. The following options
82752 + will allow the kernel to apply a certain amount of randomization
82753 + to specific parts of the program thereby forcing an attacker to
82754 + guess them in most cases. Any failed guess will most likely crash
82755 + the attacked program which allows the kernel to detect such attempts
82756 + and react on them. PaX itself provides no reaction mechanisms,
82757 + instead it is strongly encouraged that you make use of Nergal's
82758 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
82759 + (http://www.grsecurity.net/) built-in crash detection features or
82760 + develop one yourself.
82761 +
82762 + By saying Y here you can choose to randomize the following areas:
82763 + - top of the task's kernel stack
82764 + - top of the task's userland stack
82765 + - base address for mmap() requests that do not specify one
82766 + (this includes all libraries)
82767 + - base address of the main executable
82768 +
82769 + It is strongly recommended to say Y here as address space layout
82770 + randomization has negligible impact on performance yet it provides
82771 + a very effective protection.
82772 +
82773 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
82774 + this feature on a per file basis.
82775 +
82776 +config PAX_RANDKSTACK
82777 + bool "Randomize kernel stack base"
82778 + default y if GRKERNSEC_CONFIG_AUTO
82779 + depends on X86_TSC && X86
82780 + help
82781 + By saying Y here the kernel will randomize every task's kernel
82782 + stack on every system call. This will not only force an attacker
82783 + to guess it but also prevent him from making use of possible
82784 + leaked information about it.
82785 +
82786 + Since the kernel stack is a rather scarce resource, randomization
82787 + may cause unexpected stack overflows, therefore you should very
82788 + carefully test your system. Note that once enabled in the kernel
82789 + configuration, this feature cannot be disabled on a per file basis.
82790 +
82791 +config PAX_RANDUSTACK
82792 + bool "Randomize user stack base"
82793 + default y if GRKERNSEC_CONFIG_AUTO
82794 + depends on PAX_ASLR
82795 + help
82796 + By saying Y here the kernel will randomize every task's userland
82797 + stack. The randomization is done in two steps where the second
82798 + one may apply a big amount of shift to the top of the stack and
82799 + cause problems for programs that want to use lots of memory (more
82800 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
82801 + For this reason the second step can be controlled by 'chpax' or
82802 + 'paxctl' on a per file basis.
82803 +
82804 +config PAX_RANDMMAP
82805 + bool "Randomize mmap() base"
82806 + default y if GRKERNSEC_CONFIG_AUTO
82807 + depends on PAX_ASLR
82808 + help
82809 + By saying Y here the kernel will use a randomized base address for
82810 + mmap() requests that do not specify one themselves. As a result
82811 + all dynamically loaded libraries will appear at random addresses
82812 + and therefore be harder to exploit by a technique where an attacker
82813 + attempts to execute library code for his purposes (e.g. spawn a
82814 + shell from an exploited program that is running at an elevated
82815 + privilege level).
82816 +
82817 + Furthermore, if a program is relinked as a dynamic ELF file, its
82818 + base address will be randomized as well, completing the full
82819 + randomization of the address space layout. Attacking such programs
82820 + becomes a guess game. You can find an example of doing this at
82821 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
82822 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
82823 +
82824 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
82825 + feature on a per file basis.
82826 +
82827 +endmenu
82828 +
82829 +menu "Miscellaneous hardening features"
82830 +
82831 +config PAX_MEMORY_SANITIZE
82832 + bool "Sanitize all freed memory"
82833 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
82834 + depends on !HIBERNATION
82835 + help
82836 + By saying Y here the kernel will erase memory pages as soon as they
82837 + are freed. This in turn reduces the lifetime of data stored in the
82838 + pages, making it less likely that sensitive information such as
82839 + passwords, cryptographic secrets, etc stay in memory for too long.
82840 +
82841 + This is especially useful for programs whose runtime is short, long
82842 + lived processes and the kernel itself benefit from this as long as
82843 + they operate on whole memory pages and ensure timely freeing of pages
82844 + that may hold sensitive information.
82845 +
82846 + The tradeoff is performance impact, on a single CPU system kernel
82847 + compilation sees a 3% slowdown, other systems and workloads may vary
82848 + and you are advised to test this feature on your expected workload
82849 + before deploying it.
82850 +
82851 + Note that this feature does not protect data stored in live pages,
82852 + e.g., process memory swapped to disk may stay there for a long time.
82853 +
82854 +config PAX_MEMORY_STACKLEAK
82855 + bool "Sanitize kernel stack"
82856 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
82857 + depends on X86
82858 + help
82859 + By saying Y here the kernel will erase the kernel stack before it
82860 + returns from a system call. This in turn reduces the information
82861 + that a kernel stack leak bug can reveal.
82862 +
82863 + Note that such a bug can still leak information that was put on
82864 + the stack by the current system call (the one eventually triggering
82865 + the bug) but traces of earlier system calls on the kernel stack
82866 + cannot leak anymore.
82867 +
82868 + The tradeoff is performance impact: on a single CPU system kernel
82869 + compilation sees a 1% slowdown, other systems and workloads may vary
82870 + and you are advised to test this feature on your expected workload
82871 + before deploying it.
82872 +
82873 + Note that the full feature requires a gcc with plugin support,
82874 + i.e., gcc 4.5 or newer. You may need to install the supporting
82875 + headers explicitly in addition to the normal gcc package. Using
82876 + older gcc versions means that functions with large enough stack
82877 + frames may leave uninitialized memory behind that may be exposed
82878 + to a later syscall leaking the stack.
82879 +
82880 +config PAX_MEMORY_UDEREF
82881 + bool "Prevent invalid userland pointer dereference"
82882 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
82883 + depends on X86 && !UML_X86 && !XEN
82884 + select PAX_PER_CPU_PGD if X86_64
82885 + help
82886 + By saying Y here the kernel will be prevented from dereferencing
82887 + userland pointers in contexts where the kernel expects only kernel
82888 + pointers. This is both a useful runtime debugging feature and a
82889 + security measure that prevents exploiting a class of kernel bugs.
82890 +
82891 + The tradeoff is that some virtualization solutions may experience
82892 + a huge slowdown and therefore you should not enable this feature
82893 + for kernels meant to run in such environments. Whether a given VM
82894 + solution is affected or not is best determined by simply trying it
82895 + out, the performance impact will be obvious right on boot as this
82896 + mechanism engages from very early on. A good rule of thumb is that
82897 + VMs running on CPUs without hardware virtualization support (i.e.,
82898 + the majority of IA-32 CPUs) will likely experience the slowdown.
82899 +
82900 +config PAX_REFCOUNT
82901 + bool "Prevent various kernel object reference counter overflows"
82902 + default y if GRKERNSEC_CONFIG_AUTO
82903 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
82904 + help
82905 + By saying Y here the kernel will detect and prevent overflowing
82906 + various (but not all) kinds of object reference counters. Such
82907 + overflows can normally occur due to bugs only and are often, if
82908 + not always, exploitable.
82909 +
82910 + The tradeoff is that data structures protected by an overflowed
82911 + refcount will never be freed and therefore will leak memory. Note
82912 + that this leak also happens even without this protection but in
82913 + that case the overflow can eventually trigger the freeing of the
82914 + data structure while it is still being used elsewhere, resulting
82915 + in the exploitable situation that this feature prevents.
82916 +
82917 + Since this has a negligible performance impact, you should enable
82918 + this feature.
82919 +
82920 +config PAX_USERCOPY
82921 + bool "Harden heap object copies between kernel and userland"
82922 + default y if GRKERNSEC_CONFIG_AUTO
82923 + depends on ARM || IA64 || PPC || SPARC || X86
82924 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
82925 + select PAX_USERCOPY_SLABS
82926 + help
82927 + By saying Y here the kernel will enforce the size of heap objects
82928 + when they are copied in either direction between the kernel and
82929 + userland, even if only a part of the heap object is copied.
82930 +
82931 + Specifically, this checking prevents information leaking from the
82932 + kernel heap during kernel to userland copies (if the kernel heap
82933 + object is otherwise fully initialized) and prevents kernel heap
82934 + overflows during userland to kernel copies.
82935 +
82936 + Note that the current implementation provides the strictest bounds
82937 + checks for the SLUB allocator.
82938 +
82939 + Enabling this option also enables per-slab cache protection against
82940 + data in a given cache being copied into/out of via userland
82941 + accessors. Though the whitelist of regions will be reduced over
82942 + time, it notably protects important data structures like task structs.
82943 +
82944 + If frame pointers are enabled on x86, this option will also restrict
82945 + copies into and out of the kernel stack to local variables within a
82946 + single frame.
82947 +
82948 + Since this has a negligible performance impact, you should enable
82949 + this feature.
82950 +
82951 +config PAX_SIZE_OVERFLOW
82952 + bool "Prevent various integer overflows in function size parameters"
82953 + default y if GRKERNSEC_CONFIG_AUTO
82954 + depends on X86
82955 + help
82956 + By saying Y here the kernel recomputes expressions of function
82957 + arguments marked by a size_overflow attribute with double integer
82958 + precision (DImode/TImode for 32/64 bit integer types).
82959 +
82960 + The recomputed argument is checked against TYPE_MAX and an event
82961 + is logged on overflow and the triggering process is killed.
82962 +
82963 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
82964 +
82965 + Note that the implementation requires a gcc with plugin support,
82966 + i.e., gcc 4.5 or newer. You may need to install the supporting
82967 + headers explicitly in addition to the normal gcc package.
82968 +
82969 +config PAX_LATENT_ENTROPY
82970 + bool "Generate some entropy during boot"
82971 + default y if GRKERNSEC_CONFIG_AUTO
82972 + help
82973 + By saying Y here the kernel will instrument early boot code to
82974 + extract some entropy from both original and artificially created
82975 + program state. This will help especially embedded systems where
82976 + there is little 'natural' source of entropy normally. The cost
82977 + is some slowdown of the boot process.
82978 +
82979 + Note that the implementation requires a gcc with plugin support,
82980 + i.e., gcc 4.5 or newer. You may need to install the supporting
82981 + headers explicitly in addition to the normal gcc package.
82982 +
82983 + Note that entropy extracted this way is not cryptographically
82984 + secure!
82985 +
82986 +endmenu
82987 +
82988 +endmenu
82989 +
82990 +source grsecurity/Kconfig
82991 +
82992 +endmenu
82993 +
82994 +endmenu
82995 +
82996 source security/keys/Kconfig
82997
82998 config SECURITY_DMESG_RESTRICT
82999 @@ -103,7 +993,7 @@ config INTEL_TXT
83000 config LSM_MMAP_MIN_ADDR
83001 int "Low address space for LSM to protect from user allocation"
83002 depends on SECURITY && SECURITY_SELINUX
83003 - default 32768 if ARM
83004 + default 32768 if ALPHA || ARM || PARISC || SPARC32
83005 default 65536
83006 help
83007 This is the portion of low virtual memory which should be protected
83008 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
83009 index 8c2a7f6..b133ac9 100644
83010 --- a/security/apparmor/lsm.c
83011 +++ b/security/apparmor/lsm.c
83012 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
83013 return error;
83014 }
83015
83016 -static struct security_operations apparmor_ops = {
83017 +static struct security_operations apparmor_ops __read_only = {
83018 .name = "apparmor",
83019
83020 .ptrace_access_check = apparmor_ptrace_access_check,
83021 diff --git a/security/commoncap.c b/security/commoncap.c
83022 index 6dbae46..d5611fd 100644
83023 --- a/security/commoncap.c
83024 +++ b/security/commoncap.c
83025 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
83026 return 0;
83027 }
83028
83029 +/* returns:
83030 + 1 for suid privilege
83031 + 2 for sgid privilege
83032 + 3 for fscap privilege
83033 +*/
83034 +int is_privileged_binary(const struct dentry *dentry)
83035 +{
83036 + struct cpu_vfs_cap_data capdata;
83037 + struct inode *inode = dentry->d_inode;
83038 +
83039 + if (!inode || S_ISDIR(inode->i_mode))
83040 + return 0;
83041 +
83042 + if (inode->i_mode & S_ISUID)
83043 + return 1;
83044 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
83045 + return 2;
83046 +
83047 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
83048 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
83049 + return 3;
83050 + }
83051 +
83052 + return 0;
83053 +}
83054 +
83055 /*
83056 * Attempt to get the on-exec apply capability sets for an executable file from
83057 * its xattrs and, if present, apply them to the proposed credentials being
83058 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
83059 const struct cred *cred = current_cred();
83060 kuid_t root_uid = make_kuid(cred->user_ns, 0);
83061
83062 + if (gr_acl_enable_at_secure())
83063 + return 1;
83064 +
83065 if (!uid_eq(cred->uid, root_uid)) {
83066 if (bprm->cap_effective)
83067 return 1;
83068 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
83069 index 6ee8826..6350060 100644
83070 --- a/security/integrity/ima/ima.h
83071 +++ b/security/integrity/ima/ima.h
83072 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83073 extern spinlock_t ima_queue_lock;
83074
83075 struct ima_h_table {
83076 - atomic_long_t len; /* number of stored measurements in the list */
83077 - atomic_long_t violations;
83078 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
83079 + atomic_long_unchecked_t violations;
83080 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
83081 };
83082 extern struct ima_h_table ima_htable;
83083 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
83084 index b356884..fd9676e 100644
83085 --- a/security/integrity/ima/ima_api.c
83086 +++ b/security/integrity/ima/ima_api.c
83087 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83088 int result;
83089
83090 /* can overflow, only indicator */
83091 - atomic_long_inc(&ima_htable.violations);
83092 + atomic_long_inc_unchecked(&ima_htable.violations);
83093
83094 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
83095 if (!entry) {
83096 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
83097 index 38477c9..87a60c7 100644
83098 --- a/security/integrity/ima/ima_fs.c
83099 +++ b/security/integrity/ima/ima_fs.c
83100 @@ -28,12 +28,12 @@
83101 static int valid_policy = 1;
83102 #define TMPBUFLEN 12
83103 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
83104 - loff_t *ppos, atomic_long_t *val)
83105 + loff_t *ppos, atomic_long_unchecked_t *val)
83106 {
83107 char tmpbuf[TMPBUFLEN];
83108 ssize_t len;
83109
83110 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
83111 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
83112 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
83113 }
83114
83115 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
83116 index 55a6271..ad829c3 100644
83117 --- a/security/integrity/ima/ima_queue.c
83118 +++ b/security/integrity/ima/ima_queue.c
83119 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
83120 INIT_LIST_HEAD(&qe->later);
83121 list_add_tail_rcu(&qe->later, &ima_measurements);
83122
83123 - atomic_long_inc(&ima_htable.len);
83124 + atomic_long_inc_unchecked(&ima_htable.len);
83125 key = ima_hash_key(entry->digest);
83126 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
83127 return 0;
83128 diff --git a/security/keys/compat.c b/security/keys/compat.c
83129 index 1c26176..64a1ba2 100644
83130 --- a/security/keys/compat.c
83131 +++ b/security/keys/compat.c
83132 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
83133 if (ret == 0)
83134 goto no_payload_free;
83135
83136 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
83137 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
83138
83139 if (iov != iovstack)
83140 kfree(iov);
83141 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
83142 index 5d34b4e..2456674 100644
83143 --- a/security/keys/keyctl.c
83144 +++ b/security/keys/keyctl.c
83145 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
83146 /*
83147 * Copy the iovec data from userspace
83148 */
83149 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83150 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
83151 unsigned ioc)
83152 {
83153 for (; ioc > 0; ioc--) {
83154 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83155 * If successful, 0 will be returned.
83156 */
83157 long keyctl_instantiate_key_common(key_serial_t id,
83158 - const struct iovec *payload_iov,
83159 + const struct iovec __user *payload_iov,
83160 unsigned ioc,
83161 size_t plen,
83162 key_serial_t ringid)
83163 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
83164 [0].iov_len = plen
83165 };
83166
83167 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
83168 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
83169 }
83170
83171 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
83172 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
83173 if (ret == 0)
83174 goto no_payload_free;
83175
83176 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
83177 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
83178
83179 if (iov != iovstack)
83180 kfree(iov);
83181 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
83182 index 6e42df1..aba52bd 100644
83183 --- a/security/keys/keyring.c
83184 +++ b/security/keys/keyring.c
83185 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
83186 ret = -EFAULT;
83187
83188 for (loop = 0; loop < klist->nkeys; loop++) {
83189 + key_serial_t serial;
83190 key = rcu_deref_link_locked(klist, loop,
83191 keyring);
83192 + serial = key->serial;
83193
83194 tmp = sizeof(key_serial_t);
83195 if (tmp > buflen)
83196 tmp = buflen;
83197
83198 - if (copy_to_user(buffer,
83199 - &key->serial,
83200 - tmp) != 0)
83201 + if (copy_to_user(buffer, &serial, tmp))
83202 goto error;
83203
83204 buflen -= tmp;
83205 diff --git a/security/min_addr.c b/security/min_addr.c
83206 index f728728..6457a0c 100644
83207 --- a/security/min_addr.c
83208 +++ b/security/min_addr.c
83209 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
83210 */
83211 static void update_mmap_min_addr(void)
83212 {
83213 +#ifndef SPARC
83214 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
83215 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
83216 mmap_min_addr = dac_mmap_min_addr;
83217 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
83218 #else
83219 mmap_min_addr = dac_mmap_min_addr;
83220 #endif
83221 +#endif
83222 }
83223
83224 /*
83225 diff --git a/security/security.c b/security/security.c
83226 index 8dcd4ae..1124de7 100644
83227 --- a/security/security.c
83228 +++ b/security/security.c
83229 @@ -20,6 +20,7 @@
83230 #include <linux/ima.h>
83231 #include <linux/evm.h>
83232 #include <linux/fsnotify.h>
83233 +#include <linux/mm.h>
83234 #include <linux/mman.h>
83235 #include <linux/mount.h>
83236 #include <linux/personality.h>
83237 @@ -32,8 +33,8 @@
83238 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
83239 CONFIG_DEFAULT_SECURITY;
83240
83241 -static struct security_operations *security_ops;
83242 -static struct security_operations default_security_ops = {
83243 +static struct security_operations *security_ops __read_only;
83244 +static struct security_operations default_security_ops __read_only = {
83245 .name = "default",
83246 };
83247
83248 @@ -74,7 +75,9 @@ int __init security_init(void)
83249
83250 void reset_security_ops(void)
83251 {
83252 + pax_open_kernel();
83253 security_ops = &default_security_ops;
83254 + pax_close_kernel();
83255 }
83256
83257 /* Save user chosen LSM */
83258 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
83259 index 61a5336..27215d8 100644
83260 --- a/security/selinux/hooks.c
83261 +++ b/security/selinux/hooks.c
83262 @@ -95,8 +95,6 @@
83263
83264 #define NUM_SEL_MNT_OPTS 5
83265
83266 -extern struct security_operations *security_ops;
83267 -
83268 /* SECMARK reference count */
83269 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
83270
83271 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
83272
83273 #endif
83274
83275 -static struct security_operations selinux_ops = {
83276 +static struct security_operations selinux_ops __read_only = {
83277 .name = "selinux",
83278
83279 .ptrace_access_check = selinux_ptrace_access_check,
83280 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
83281 index 65f67cb..3f141ef 100644
83282 --- a/security/selinux/include/xfrm.h
83283 +++ b/security/selinux/include/xfrm.h
83284 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
83285
83286 static inline void selinux_xfrm_notify_policyload(void)
83287 {
83288 - atomic_inc(&flow_cache_genid);
83289 + atomic_inc_unchecked(&flow_cache_genid);
83290 rt_genid_bump(&init_net);
83291 }
83292 #else
83293 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
83294 index 38be92c..21f49ee 100644
83295 --- a/security/smack/smack_lsm.c
83296 +++ b/security/smack/smack_lsm.c
83297 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
83298 return 0;
83299 }
83300
83301 -struct security_operations smack_ops = {
83302 +struct security_operations smack_ops __read_only = {
83303 .name = "smack",
83304
83305 .ptrace_access_check = smack_ptrace_access_check,
83306 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
83307 index a2ee362..5754f34 100644
83308 --- a/security/tomoyo/tomoyo.c
83309 +++ b/security/tomoyo/tomoyo.c
83310 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
83311 * tomoyo_security_ops is a "struct security_operations" which is used for
83312 * registering TOMOYO.
83313 */
83314 -static struct security_operations tomoyo_security_ops = {
83315 +static struct security_operations tomoyo_security_ops __read_only = {
83316 .name = "tomoyo",
83317 .cred_alloc_blank = tomoyo_cred_alloc_blank,
83318 .cred_prepare = tomoyo_cred_prepare,
83319 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
83320 index 20ef514..4182bed 100644
83321 --- a/security/yama/Kconfig
83322 +++ b/security/yama/Kconfig
83323 @@ -1,6 +1,6 @@
83324 config SECURITY_YAMA
83325 bool "Yama support"
83326 - depends on SECURITY
83327 + depends on SECURITY && !GRKERNSEC
83328 select SECURITYFS
83329 select SECURITY_PATH
83330 default n
83331 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
83332 index 4cedc69..e59d8a3 100644
83333 --- a/sound/aoa/codecs/onyx.c
83334 +++ b/sound/aoa/codecs/onyx.c
83335 @@ -54,7 +54,7 @@ struct onyx {
83336 spdif_locked:1,
83337 analog_locked:1,
83338 original_mute:2;
83339 - int open_count;
83340 + local_t open_count;
83341 struct codec_info *codec_info;
83342
83343 /* mutex serializes concurrent access to the device
83344 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
83345 struct onyx *onyx = cii->codec_data;
83346
83347 mutex_lock(&onyx->mutex);
83348 - onyx->open_count++;
83349 + local_inc(&onyx->open_count);
83350 mutex_unlock(&onyx->mutex);
83351
83352 return 0;
83353 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
83354 struct onyx *onyx = cii->codec_data;
83355
83356 mutex_lock(&onyx->mutex);
83357 - onyx->open_count--;
83358 - if (!onyx->open_count)
83359 + if (local_dec_and_test(&onyx->open_count))
83360 onyx->spdif_locked = onyx->analog_locked = 0;
83361 mutex_unlock(&onyx->mutex);
83362
83363 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
83364 index ffd2025..df062c9 100644
83365 --- a/sound/aoa/codecs/onyx.h
83366 +++ b/sound/aoa/codecs/onyx.h
83367 @@ -11,6 +11,7 @@
83368 #include <linux/i2c.h>
83369 #include <asm/pmac_low_i2c.h>
83370 #include <asm/prom.h>
83371 +#include <asm/local.h>
83372
83373 /* PCM3052 register definitions */
83374
83375 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
83376 index 4c1cc51..16040040 100644
83377 --- a/sound/core/oss/pcm_oss.c
83378 +++ b/sound/core/oss/pcm_oss.c
83379 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
83380 if (in_kernel) {
83381 mm_segment_t fs;
83382 fs = snd_enter_user();
83383 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
83384 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
83385 snd_leave_user(fs);
83386 } else {
83387 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
83388 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
83389 }
83390 if (ret != -EPIPE && ret != -ESTRPIPE)
83391 break;
83392 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
83393 if (in_kernel) {
83394 mm_segment_t fs;
83395 fs = snd_enter_user();
83396 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
83397 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
83398 snd_leave_user(fs);
83399 } else {
83400 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
83401 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
83402 }
83403 if (ret == -EPIPE) {
83404 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
83405 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
83406 struct snd_pcm_plugin_channel *channels;
83407 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
83408 if (!in_kernel) {
83409 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
83410 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
83411 return -EFAULT;
83412 buf = runtime->oss.buffer;
83413 }
83414 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
83415 }
83416 } else {
83417 tmp = snd_pcm_oss_write2(substream,
83418 - (const char __force *)buf,
83419 + (const char __force_kernel *)buf,
83420 runtime->oss.period_bytes, 0);
83421 if (tmp <= 0)
83422 goto err;
83423 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
83424 struct snd_pcm_runtime *runtime = substream->runtime;
83425 snd_pcm_sframes_t frames, frames1;
83426 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
83427 - char __user *final_dst = (char __force __user *)buf;
83428 + char __user *final_dst = (char __force_user *)buf;
83429 if (runtime->oss.plugin_first) {
83430 struct snd_pcm_plugin_channel *channels;
83431 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
83432 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
83433 xfer += tmp;
83434 runtime->oss.buffer_used -= tmp;
83435 } else {
83436 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
83437 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
83438 runtime->oss.period_bytes, 0);
83439 if (tmp <= 0)
83440 goto err;
83441 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
83442 size1);
83443 size1 /= runtime->channels; /* frames */
83444 fs = snd_enter_user();
83445 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
83446 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
83447 snd_leave_user(fs);
83448 }
83449 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
83450 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
83451 index 91cdf943..4085161 100644
83452 --- a/sound/core/pcm_compat.c
83453 +++ b/sound/core/pcm_compat.c
83454 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
83455 int err;
83456
83457 fs = snd_enter_user();
83458 - err = snd_pcm_delay(substream, &delay);
83459 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
83460 snd_leave_user(fs);
83461 if (err < 0)
83462 return err;
83463 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
83464 index f9ddecf..e27404d 100644
83465 --- a/sound/core/pcm_native.c
83466 +++ b/sound/core/pcm_native.c
83467 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
83468 switch (substream->stream) {
83469 case SNDRV_PCM_STREAM_PLAYBACK:
83470 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
83471 - (void __user *)arg);
83472 + (void __force_user *)arg);
83473 break;
83474 case SNDRV_PCM_STREAM_CAPTURE:
83475 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
83476 - (void __user *)arg);
83477 + (void __force_user *)arg);
83478 break;
83479 default:
83480 result = -EINVAL;
83481 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
83482 index 60e8fc1..786abcb 100644
83483 --- a/sound/core/seq/seq_device.c
83484 +++ b/sound/core/seq/seq_device.c
83485 @@ -64,7 +64,7 @@ struct ops_list {
83486 int argsize; /* argument size */
83487
83488 /* operators */
83489 - struct snd_seq_dev_ops ops;
83490 + struct snd_seq_dev_ops *ops;
83491
83492 /* registred devices */
83493 struct list_head dev_list; /* list of devices */
83494 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
83495
83496 mutex_lock(&ops->reg_mutex);
83497 /* copy driver operators */
83498 - ops->ops = *entry;
83499 + ops->ops = entry;
83500 ops->driver |= DRIVER_LOADED;
83501 ops->argsize = argsize;
83502
83503 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
83504 dev->name, ops->id, ops->argsize, dev->argsize);
83505 return -EINVAL;
83506 }
83507 - if (ops->ops.init_device(dev) >= 0) {
83508 + if (ops->ops->init_device(dev) >= 0) {
83509 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
83510 ops->num_init_devices++;
83511 } else {
83512 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
83513 dev->name, ops->id, ops->argsize, dev->argsize);
83514 return -EINVAL;
83515 }
83516 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
83517 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
83518 dev->status = SNDRV_SEQ_DEVICE_FREE;
83519 dev->driver_data = NULL;
83520 ops->num_init_devices--;
83521 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
83522 index 2d5514b..3afae9c 100644
83523 --- a/sound/drivers/mts64.c
83524 +++ b/sound/drivers/mts64.c
83525 @@ -29,6 +29,7 @@
83526 #include <sound/initval.h>
83527 #include <sound/rawmidi.h>
83528 #include <sound/control.h>
83529 +#include <asm/local.h>
83530
83531 #define CARD_NAME "Miditerminal 4140"
83532 #define DRIVER_NAME "MTS64"
83533 @@ -67,7 +68,7 @@ struct mts64 {
83534 struct pardevice *pardev;
83535 int pardev_claimed;
83536
83537 - int open_count;
83538 + local_t open_count;
83539 int current_midi_output_port;
83540 int current_midi_input_port;
83541 u8 mode[MTS64_NUM_INPUT_PORTS];
83542 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
83543 {
83544 struct mts64 *mts = substream->rmidi->private_data;
83545
83546 - if (mts->open_count == 0) {
83547 + if (local_read(&mts->open_count) == 0) {
83548 /* We don't need a spinlock here, because this is just called
83549 if the device has not been opened before.
83550 So there aren't any IRQs from the device */
83551 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
83552
83553 msleep(50);
83554 }
83555 - ++(mts->open_count);
83556 + local_inc(&mts->open_count);
83557
83558 return 0;
83559 }
83560 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
83561 struct mts64 *mts = substream->rmidi->private_data;
83562 unsigned long flags;
83563
83564 - --(mts->open_count);
83565 - if (mts->open_count == 0) {
83566 + if (local_dec_return(&mts->open_count) == 0) {
83567 /* We need the spinlock_irqsave here because we can still
83568 have IRQs at this point */
83569 spin_lock_irqsave(&mts->lock, flags);
83570 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
83571
83572 msleep(500);
83573
83574 - } else if (mts->open_count < 0)
83575 - mts->open_count = 0;
83576 + } else if (local_read(&mts->open_count) < 0)
83577 + local_set(&mts->open_count, 0);
83578
83579 return 0;
83580 }
83581 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
83582 index b953fb4..1999c01 100644
83583 --- a/sound/drivers/opl4/opl4_lib.c
83584 +++ b/sound/drivers/opl4/opl4_lib.c
83585 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
83586 MODULE_DESCRIPTION("OPL4 driver");
83587 MODULE_LICENSE("GPL");
83588
83589 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
83590 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
83591 {
83592 int timeout = 10;
83593 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
83594 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
83595 index 8364855..59f2e2b 100644
83596 --- a/sound/drivers/portman2x4.c
83597 +++ b/sound/drivers/portman2x4.c
83598 @@ -48,6 +48,7 @@
83599 #include <sound/initval.h>
83600 #include <sound/rawmidi.h>
83601 #include <sound/control.h>
83602 +#include <asm/local.h>
83603
83604 #define CARD_NAME "Portman 2x4"
83605 #define DRIVER_NAME "portman"
83606 @@ -85,7 +86,7 @@ struct portman {
83607 struct pardevice *pardev;
83608 int pardev_claimed;
83609
83610 - int open_count;
83611 + local_t open_count;
83612 int mode[PORTMAN_NUM_INPUT_PORTS];
83613 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
83614 };
83615 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
83616 index ea995af..f1bfa37 100644
83617 --- a/sound/firewire/amdtp.c
83618 +++ b/sound/firewire/amdtp.c
83619 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
83620 ptr = s->pcm_buffer_pointer + data_blocks;
83621 if (ptr >= pcm->runtime->buffer_size)
83622 ptr -= pcm->runtime->buffer_size;
83623 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
83624 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
83625
83626 s->pcm_period_pointer += data_blocks;
83627 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
83628 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
83629 */
83630 void amdtp_out_stream_update(struct amdtp_out_stream *s)
83631 {
83632 - ACCESS_ONCE(s->source_node_id_field) =
83633 + ACCESS_ONCE_RW(s->source_node_id_field) =
83634 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
83635 }
83636 EXPORT_SYMBOL(amdtp_out_stream_update);
83637 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
83638 index b680c5e..061b7a0 100644
83639 --- a/sound/firewire/amdtp.h
83640 +++ b/sound/firewire/amdtp.h
83641 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
83642 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
83643 struct snd_pcm_substream *pcm)
83644 {
83645 - ACCESS_ONCE(s->pcm) = pcm;
83646 + ACCESS_ONCE_RW(s->pcm) = pcm;
83647 }
83648
83649 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
83650 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
83651 index d428ffe..751ef78 100644
83652 --- a/sound/firewire/isight.c
83653 +++ b/sound/firewire/isight.c
83654 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
83655 ptr += count;
83656 if (ptr >= runtime->buffer_size)
83657 ptr -= runtime->buffer_size;
83658 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
83659 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
83660
83661 isight->period_counter += count;
83662 if (isight->period_counter >= runtime->period_size) {
83663 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
83664 if (err < 0)
83665 return err;
83666
83667 - ACCESS_ONCE(isight->pcm_active) = true;
83668 + ACCESS_ONCE_RW(isight->pcm_active) = true;
83669
83670 return 0;
83671 }
83672 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
83673 {
83674 struct isight *isight = substream->private_data;
83675
83676 - ACCESS_ONCE(isight->pcm_active) = false;
83677 + ACCESS_ONCE_RW(isight->pcm_active) = false;
83678
83679 mutex_lock(&isight->mutex);
83680 isight_stop_streaming(isight);
83681 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
83682
83683 switch (cmd) {
83684 case SNDRV_PCM_TRIGGER_START:
83685 - ACCESS_ONCE(isight->pcm_running) = true;
83686 + ACCESS_ONCE_RW(isight->pcm_running) = true;
83687 break;
83688 case SNDRV_PCM_TRIGGER_STOP:
83689 - ACCESS_ONCE(isight->pcm_running) = false;
83690 + ACCESS_ONCE_RW(isight->pcm_running) = false;
83691 break;
83692 default:
83693 return -EINVAL;
83694 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
83695 index b2b3c01..e1c1e1f 100644
83696 --- a/sound/oss/sb_audio.c
83697 +++ b/sound/oss/sb_audio.c
83698 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
83699 buf16 = (signed short *)(localbuf + localoffs);
83700 while (c)
83701 {
83702 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
83703 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
83704 if (copy_from_user(lbuf8,
83705 userbuf+useroffs + p,
83706 locallen))
83707 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
83708 index 7d8803a..559f8d0 100644
83709 --- a/sound/oss/swarm_cs4297a.c
83710 +++ b/sound/oss/swarm_cs4297a.c
83711 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
83712 {
83713 struct cs4297a_state *s;
83714 u32 pwr, id;
83715 - mm_segment_t fs;
83716 int rval;
83717 #ifndef CONFIG_BCM_CS4297A_CSWARM
83718 u64 cfg;
83719 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
83720 if (!rval) {
83721 char *sb1250_duart_present;
83722
83723 +#if 0
83724 + mm_segment_t fs;
83725 fs = get_fs();
83726 set_fs(KERNEL_DS);
83727 -#if 0
83728 val = SOUND_MASK_LINE;
83729 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
83730 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
83731 val = initvol[i].vol;
83732 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
83733 }
83734 + set_fs(fs);
83735 // cs4297a_write_ac97(s, 0x18, 0x0808);
83736 #else
83737 // cs4297a_write_ac97(s, 0x5e, 0x180);
83738 cs4297a_write_ac97(s, 0x02, 0x0808);
83739 cs4297a_write_ac97(s, 0x18, 0x0808);
83740 #endif
83741 - set_fs(fs);
83742
83743 list_add(&s->list, &cs4297a_devs);
83744
83745 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
83746 index 4631a23..001ae57 100644
83747 --- a/sound/pci/ymfpci/ymfpci.h
83748 +++ b/sound/pci/ymfpci/ymfpci.h
83749 @@ -358,7 +358,7 @@ struct snd_ymfpci {
83750 spinlock_t reg_lock;
83751 spinlock_t voice_lock;
83752 wait_queue_head_t interrupt_sleep;
83753 - atomic_t interrupt_sleep_count;
83754 + atomic_unchecked_t interrupt_sleep_count;
83755 struct snd_info_entry *proc_entry;
83756 const struct firmware *dsp_microcode;
83757 const struct firmware *controller_microcode;
83758 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
83759 index 3a6f03f..bc5c86c 100644
83760 --- a/sound/pci/ymfpci/ymfpci_main.c
83761 +++ b/sound/pci/ymfpci/ymfpci_main.c
83762 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
83763 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
83764 break;
83765 }
83766 - if (atomic_read(&chip->interrupt_sleep_count)) {
83767 - atomic_set(&chip->interrupt_sleep_count, 0);
83768 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
83769 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83770 wake_up(&chip->interrupt_sleep);
83771 }
83772 __end:
83773 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
83774 continue;
83775 init_waitqueue_entry(&wait, current);
83776 add_wait_queue(&chip->interrupt_sleep, &wait);
83777 - atomic_inc(&chip->interrupt_sleep_count);
83778 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
83779 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
83780 remove_wait_queue(&chip->interrupt_sleep, &wait);
83781 }
83782 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
83783 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
83784 spin_unlock(&chip->reg_lock);
83785
83786 - if (atomic_read(&chip->interrupt_sleep_count)) {
83787 - atomic_set(&chip->interrupt_sleep_count, 0);
83788 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
83789 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83790 wake_up(&chip->interrupt_sleep);
83791 }
83792 }
83793 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
83794 spin_lock_init(&chip->reg_lock);
83795 spin_lock_init(&chip->voice_lock);
83796 init_waitqueue_head(&chip->interrupt_sleep);
83797 - atomic_set(&chip->interrupt_sleep_count, 0);
83798 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83799 chip->card = card;
83800 chip->pci = pci;
83801 chip->irq = -1;
83802 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
83803 new file mode 100644
83804 index 0000000..50f2f2f
83805 --- /dev/null
83806 +++ b/tools/gcc/.gitignore
83807 @@ -0,0 +1 @@
83808 +size_overflow_hash.h
83809 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
83810 new file mode 100644
83811 index 0000000..1d09b7e
83812 --- /dev/null
83813 +++ b/tools/gcc/Makefile
83814 @@ -0,0 +1,43 @@
83815 +#CC := gcc
83816 +#PLUGIN_SOURCE_FILES := pax_plugin.c
83817 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
83818 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
83819 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
83820 +
83821 +ifeq ($(PLUGINCC),$(HOSTCC))
83822 +HOSTLIBS := hostlibs
83823 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
83824 +else
83825 +HOSTLIBS := hostcxxlibs
83826 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
83827 +endif
83828 +
83829 +$(HOSTLIBS)-y := constify_plugin.so
83830 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
83831 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
83832 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
83833 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
83834 +$(HOSTLIBS)-y += colorize_plugin.so
83835 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
83836 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
83837 +
83838 +always := $($(HOSTLIBS)-y)
83839 +
83840 +constify_plugin-objs := constify_plugin.o
83841 +stackleak_plugin-objs := stackleak_plugin.o
83842 +kallocstat_plugin-objs := kallocstat_plugin.o
83843 +kernexec_plugin-objs := kernexec_plugin.o
83844 +checker_plugin-objs := checker_plugin.o
83845 +colorize_plugin-objs := colorize_plugin.o
83846 +size_overflow_plugin-objs := size_overflow_plugin.o
83847 +latent_entropy_plugin-objs := latent_entropy_plugin.o
83848 +
83849 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
83850 +
83851 +quiet_cmd_build_size_overflow_hash = GENHASH $@
83852 + cmd_build_size_overflow_hash = \
83853 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
83854 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
83855 + $(call if_changed,build_size_overflow_hash)
83856 +
83857 +targets += size_overflow_hash.h
83858 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
83859 new file mode 100644
83860 index 0000000..d41b5af
83861 --- /dev/null
83862 +++ b/tools/gcc/checker_plugin.c
83863 @@ -0,0 +1,171 @@
83864 +/*
83865 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83866 + * Licensed under the GPL v2
83867 + *
83868 + * Note: the choice of the license means that the compilation process is
83869 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83870 + * but for the kernel it doesn't matter since it doesn't link against
83871 + * any of the gcc libraries
83872 + *
83873 + * gcc plugin to implement various sparse (source code checker) features
83874 + *
83875 + * TODO:
83876 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
83877 + *
83878 + * BUGS:
83879 + * - none known
83880 + */
83881 +#include "gcc-plugin.h"
83882 +#include "config.h"
83883 +#include "system.h"
83884 +#include "coretypes.h"
83885 +#include "tree.h"
83886 +#include "tree-pass.h"
83887 +#include "flags.h"
83888 +#include "intl.h"
83889 +#include "toplev.h"
83890 +#include "plugin.h"
83891 +//#include "expr.h" where are you...
83892 +#include "diagnostic.h"
83893 +#include "plugin-version.h"
83894 +#include "tm.h"
83895 +#include "function.h"
83896 +#include "basic-block.h"
83897 +#include "gimple.h"
83898 +#include "rtl.h"
83899 +#include "emit-rtl.h"
83900 +#include "tree-flow.h"
83901 +#include "target.h"
83902 +
83903 +extern void c_register_addr_space (const char *str, addr_space_t as);
83904 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
83905 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
83906 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
83907 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
83908 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
83909 +
83910 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83911 +extern rtx emit_move_insn(rtx x, rtx y);
83912 +
83913 +int plugin_is_GPL_compatible;
83914 +
83915 +static struct plugin_info checker_plugin_info = {
83916 + .version = "201111150100",
83917 +};
83918 +
83919 +#define ADDR_SPACE_KERNEL 0
83920 +#define ADDR_SPACE_FORCE_KERNEL 1
83921 +#define ADDR_SPACE_USER 2
83922 +#define ADDR_SPACE_FORCE_USER 3
83923 +#define ADDR_SPACE_IOMEM 0
83924 +#define ADDR_SPACE_FORCE_IOMEM 0
83925 +#define ADDR_SPACE_PERCPU 0
83926 +#define ADDR_SPACE_FORCE_PERCPU 0
83927 +#define ADDR_SPACE_RCU 0
83928 +#define ADDR_SPACE_FORCE_RCU 0
83929 +
83930 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
83931 +{
83932 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
83933 +}
83934 +
83935 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
83936 +{
83937 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
83938 +}
83939 +
83940 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
83941 +{
83942 + return default_addr_space_valid_pointer_mode(mode, as);
83943 +}
83944 +
83945 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
83946 +{
83947 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
83948 +}
83949 +
83950 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
83951 +{
83952 + return default_addr_space_legitimize_address(x, oldx, mode, as);
83953 +}
83954 +
83955 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
83956 +{
83957 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
83958 + return true;
83959 +
83960 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
83961 + return true;
83962 +
83963 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
83964 + return true;
83965 +
83966 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
83967 + return true;
83968 +
83969 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
83970 + return true;
83971 +
83972 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
83973 + return true;
83974 +
83975 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
83976 + return true;
83977 +
83978 + return subset == superset;
83979 +}
83980 +
83981 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
83982 +{
83983 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
83984 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
83985 +
83986 + return op;
83987 +}
83988 +
83989 +static void register_checker_address_spaces(void *event_data, void *data)
83990 +{
83991 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
83992 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
83993 + c_register_addr_space("__user", ADDR_SPACE_USER);
83994 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
83995 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
83996 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
83997 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
83998 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
83999 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
84000 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
84001 +
84002 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
84003 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
84004 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
84005 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
84006 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
84007 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
84008 + targetm.addr_space.convert = checker_addr_space_convert;
84009 +}
84010 +
84011 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84012 +{
84013 + const char * const plugin_name = plugin_info->base_name;
84014 + const int argc = plugin_info->argc;
84015 + const struct plugin_argument * const argv = plugin_info->argv;
84016 + int i;
84017 +
84018 + if (!plugin_default_version_check(version, &gcc_version)) {
84019 + error(G_("incompatible gcc/plugin versions"));
84020 + return 1;
84021 + }
84022 +
84023 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
84024 +
84025 + for (i = 0; i < argc; ++i)
84026 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84027 +
84028 + if (TARGET_64BIT == 0)
84029 + return 0;
84030 +
84031 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
84032 +
84033 + return 0;
84034 +}
84035 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
84036 new file mode 100644
84037 index 0000000..846aeb0
84038 --- /dev/null
84039 +++ b/tools/gcc/colorize_plugin.c
84040 @@ -0,0 +1,148 @@
84041 +/*
84042 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
84043 + * Licensed under the GPL v2
84044 + *
84045 + * Note: the choice of the license means that the compilation process is
84046 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84047 + * but for the kernel it doesn't matter since it doesn't link against
84048 + * any of the gcc libraries
84049 + *
84050 + * gcc plugin to colorize diagnostic output
84051 + *
84052 + */
84053 +
84054 +#include "gcc-plugin.h"
84055 +#include "config.h"
84056 +#include "system.h"
84057 +#include "coretypes.h"
84058 +#include "tree.h"
84059 +#include "tree-pass.h"
84060 +#include "flags.h"
84061 +#include "intl.h"
84062 +#include "toplev.h"
84063 +#include "plugin.h"
84064 +#include "diagnostic.h"
84065 +#include "plugin-version.h"
84066 +#include "tm.h"
84067 +
84068 +int plugin_is_GPL_compatible;
84069 +
84070 +static struct plugin_info colorize_plugin_info = {
84071 + .version = "201203092200",
84072 + .help = NULL,
84073 +};
84074 +
84075 +#define GREEN "\033[32m\033[2m"
84076 +#define LIGHTGREEN "\033[32m\033[1m"
84077 +#define YELLOW "\033[33m\033[2m"
84078 +#define LIGHTYELLOW "\033[33m\033[1m"
84079 +#define RED "\033[31m\033[2m"
84080 +#define LIGHTRED "\033[31m\033[1m"
84081 +#define BLUE "\033[34m\033[2m"
84082 +#define LIGHTBLUE "\033[34m\033[1m"
84083 +#define BRIGHT "\033[m\033[1m"
84084 +#define NORMAL "\033[m"
84085 +
84086 +static diagnostic_starter_fn old_starter;
84087 +static diagnostic_finalizer_fn old_finalizer;
84088 +
84089 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84090 +{
84091 + const char *color;
84092 + char *newprefix;
84093 +
84094 + switch (diagnostic->kind) {
84095 + case DK_NOTE:
84096 + color = LIGHTBLUE;
84097 + break;
84098 +
84099 + case DK_PEDWARN:
84100 + case DK_WARNING:
84101 + color = LIGHTYELLOW;
84102 + break;
84103 +
84104 + case DK_ERROR:
84105 + case DK_FATAL:
84106 + case DK_ICE:
84107 + case DK_PERMERROR:
84108 + case DK_SORRY:
84109 + color = LIGHTRED;
84110 + break;
84111 +
84112 + default:
84113 + color = NORMAL;
84114 + }
84115 +
84116 + old_starter(context, diagnostic);
84117 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
84118 + return;
84119 + pp_destroy_prefix(context->printer);
84120 + pp_set_prefix(context->printer, newprefix);
84121 +}
84122 +
84123 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84124 +{
84125 + old_finalizer(context, diagnostic);
84126 +}
84127 +
84128 +static void colorize_arm(void)
84129 +{
84130 + old_starter = diagnostic_starter(global_dc);
84131 + old_finalizer = diagnostic_finalizer(global_dc);
84132 +
84133 + diagnostic_starter(global_dc) = start_colorize;
84134 + diagnostic_finalizer(global_dc) = finalize_colorize;
84135 +}
84136 +
84137 +static unsigned int execute_colorize_rearm(void)
84138 +{
84139 + if (diagnostic_starter(global_dc) == start_colorize)
84140 + return 0;
84141 +
84142 + colorize_arm();
84143 + return 0;
84144 +}
84145 +
84146 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
84147 + .pass = {
84148 + .type = SIMPLE_IPA_PASS,
84149 + .name = "colorize_rearm",
84150 + .gate = NULL,
84151 + .execute = execute_colorize_rearm,
84152 + .sub = NULL,
84153 + .next = NULL,
84154 + .static_pass_number = 0,
84155 + .tv_id = TV_NONE,
84156 + .properties_required = 0,
84157 + .properties_provided = 0,
84158 + .properties_destroyed = 0,
84159 + .todo_flags_start = 0,
84160 + .todo_flags_finish = 0
84161 + }
84162 +};
84163 +
84164 +static void colorize_start_unit(void *gcc_data, void *user_data)
84165 +{
84166 + colorize_arm();
84167 +}
84168 +
84169 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84170 +{
84171 + const char * const plugin_name = plugin_info->base_name;
84172 + struct register_pass_info colorize_rearm_pass_info = {
84173 + .pass = &pass_ipa_colorize_rearm.pass,
84174 + .reference_pass_name = "*free_lang_data",
84175 + .ref_pass_instance_number = 1,
84176 + .pos_op = PASS_POS_INSERT_AFTER
84177 + };
84178 +
84179 + if (!plugin_default_version_check(version, &gcc_version)) {
84180 + error(G_("incompatible gcc/plugin versions"));
84181 + return 1;
84182 + }
84183 +
84184 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
84185 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
84186 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
84187 + return 0;
84188 +}
84189 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
84190 new file mode 100644
84191 index 0000000..1742271
84192 --- /dev/null
84193 +++ b/tools/gcc/constify_plugin.c
84194 @@ -0,0 +1,349 @@
84195 +/*
84196 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
84197 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
84198 + * Licensed under the GPL v2, or (at your option) v3
84199 + *
84200 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
84201 + *
84202 + * Homepage:
84203 + * http://www.grsecurity.net/~ephox/const_plugin/
84204 + *
84205 + * Usage:
84206 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
84207 + * $ gcc -fplugin=constify_plugin.so test.c -O2
84208 + */
84209 +
84210 +#include "gcc-plugin.h"
84211 +#include "config.h"
84212 +#include "system.h"
84213 +#include "coretypes.h"
84214 +#include "tree.h"
84215 +#include "tree-pass.h"
84216 +#include "flags.h"
84217 +#include "intl.h"
84218 +#include "toplev.h"
84219 +#include "plugin.h"
84220 +#include "diagnostic.h"
84221 +#include "plugin-version.h"
84222 +#include "tm.h"
84223 +#include "function.h"
84224 +#include "basic-block.h"
84225 +#include "gimple.h"
84226 +#include "rtl.h"
84227 +#include "emit-rtl.h"
84228 +#include "tree-flow.h"
84229 +
84230 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
84231 +
84232 +int plugin_is_GPL_compatible;
84233 +
84234 +static struct plugin_info const_plugin_info = {
84235 + .version = "201301150230",
84236 + .help = "no-constify\tturn off constification\n",
84237 +};
84238 +
84239 +static tree get_field_type(tree field)
84240 +{
84241 + return strip_array_types(TREE_TYPE(field));
84242 +}
84243 +
84244 +static bool walk_struct(tree node);
84245 +static void deconstify_tree(tree node);
84246 +
84247 +static void deconstify_type(tree type)
84248 +{
84249 + tree field;
84250 +
84251 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
84252 + tree fieldtype = get_field_type(field);
84253 +
84254 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
84255 + continue;
84256 + if (!TYPE_READONLY(fieldtype))
84257 + continue;
84258 + if (!walk_struct(fieldtype))
84259 + continue;
84260 +
84261 + deconstify_tree(field);
84262 + TREE_READONLY(field) = 0;
84263 + }
84264 + TYPE_READONLY(type) = 0;
84265 + C_TYPE_FIELDS_READONLY(type) = 0;
84266 +}
84267 +
84268 +static void deconstify_tree(tree node)
84269 +{
84270 + tree old_type, new_type, field;
84271 +
84272 +// TREE_READONLY(node) = 0;
84273 + old_type = TREE_TYPE(node);
84274 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
84275 + node = old_type;
84276 + old_type = TREE_TYPE(old_type);
84277 + }
84278 +
84279 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
84280 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
84281 +
84282 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
84283 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
84284 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
84285 + DECL_FIELD_CONTEXT(field) = new_type;
84286 +
84287 + deconstify_type(new_type);
84288 +
84289 + TREE_TYPE(node) = new_type;
84290 +}
84291 +
84292 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
84293 +{
84294 + tree type;
84295 +
84296 + *no_add_attrs = true;
84297 + if (TREE_CODE(*node) == FUNCTION_DECL) {
84298 + error("%qE attribute does not apply to functions", name);
84299 + return NULL_TREE;
84300 + }
84301 +
84302 + if (TREE_CODE(*node) == VAR_DECL) {
84303 + error("%qE attribute does not apply to variables", name);
84304 + return NULL_TREE;
84305 + }
84306 +
84307 + if (TYPE_P(*node)) {
84308 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
84309 + *no_add_attrs = false;
84310 + else
84311 + error("%qE attribute applies to struct and union types only", name);
84312 + return NULL_TREE;
84313 + }
84314 +
84315 + type = TREE_TYPE(*node);
84316 +
84317 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
84318 + error("%qE attribute applies to struct and union types only", name);
84319 + return NULL_TREE;
84320 + }
84321 +
84322 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
84323 + error("%qE attribute is already applied to the type", name);
84324 + return NULL_TREE;
84325 + }
84326 +
84327 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
84328 + error("%qE attribute used on type that is not constified", name);
84329 + return NULL_TREE;
84330 + }
84331 +
84332 + if (TREE_CODE(*node) == TYPE_DECL) {
84333 + deconstify_tree(*node);
84334 + return NULL_TREE;
84335 + }
84336 +
84337 + return NULL_TREE;
84338 +}
84339 +
84340 +static void constify_type(tree type)
84341 +{
84342 + TYPE_READONLY(type) = 1;
84343 + C_TYPE_FIELDS_READONLY(type) = 1;
84344 +}
84345 +
84346 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
84347 +{
84348 + *no_add_attrs = true;
84349 + if (!TYPE_P(*node)) {
84350 + error("%qE attribute applies to types only", name);
84351 + return NULL_TREE;
84352 + }
84353 +
84354 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
84355 + error("%qE attribute applies to struct and union types only", name);
84356 + return NULL_TREE;
84357 + }
84358 +
84359 + *no_add_attrs = false;
84360 + constify_type(*node);
84361 + return NULL_TREE;
84362 +}
84363 +
84364 +static struct attribute_spec no_const_attr = {
84365 + .name = "no_const",
84366 + .min_length = 0,
84367 + .max_length = 0,
84368 + .decl_required = false,
84369 + .type_required = false,
84370 + .function_type_required = false,
84371 + .handler = handle_no_const_attribute,
84372 +#if BUILDING_GCC_VERSION >= 4007
84373 + .affects_type_identity = true
84374 +#endif
84375 +};
84376 +
84377 +static struct attribute_spec do_const_attr = {
84378 + .name = "do_const",
84379 + .min_length = 0,
84380 + .max_length = 0,
84381 + .decl_required = false,
84382 + .type_required = false,
84383 + .function_type_required = false,
84384 + .handler = handle_do_const_attribute,
84385 +#if BUILDING_GCC_VERSION >= 4007
84386 + .affects_type_identity = true
84387 +#endif
84388 +};
84389 +
84390 +static void register_attributes(void *event_data, void *data)
84391 +{
84392 + register_attribute(&no_const_attr);
84393 + register_attribute(&do_const_attr);
84394 +}
84395 +
84396 +static bool is_fptr(tree field)
84397 +{
84398 + tree ptr = get_field_type(field);
84399 +
84400 + if (TREE_CODE(ptr) != POINTER_TYPE)
84401 + return false;
84402 +
84403 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
84404 +}
84405 +
84406 +static bool walk_struct(tree node)
84407 +{
84408 + tree field;
84409 +
84410 + if (TYPE_FIELDS(node) == NULL_TREE)
84411 + return false;
84412 +
84413 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
84414 + return true;
84415 +
84416 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
84417 + gcc_assert(!TYPE_READONLY(node));
84418 + deconstify_type(node);
84419 + return false;
84420 + }
84421 +
84422 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
84423 + tree type = get_field_type(field);
84424 + enum tree_code code = TREE_CODE(type);
84425 +
84426 + if (node == type)
84427 + return false;
84428 + if (code == RECORD_TYPE || code == UNION_TYPE) {
84429 + if (!(walk_struct(type)))
84430 + return false;
84431 + } else if (!is_fptr(field) && !TREE_READONLY(field))
84432 + return false;
84433 + }
84434 + return true;
84435 +}
84436 +
84437 +static void finish_type(void *event_data, void *data)
84438 +{
84439 + tree type = (tree)event_data;
84440 +
84441 + if (type == NULL_TREE || type == error_mark_node)
84442 + return;
84443 +
84444 + if (TYPE_READONLY(type))
84445 + return;
84446 +
84447 + if (walk_struct(type))
84448 + constify_type(type);
84449 + else
84450 + deconstify_type(type);
84451 +}
84452 +
84453 +static unsigned int check_local_variables(void)
84454 +{
84455 + unsigned int ret = 0;
84456 + tree var;
84457 + referenced_var_iterator rvi;
84458 +
84459 +#if BUILDING_GCC_VERSION == 4005
84460 + FOR_EACH_REFERENCED_VAR(var, rvi) {
84461 +#else
84462 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
84463 +#endif
84464 + tree type = TREE_TYPE(var);
84465 +
84466 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
84467 + continue;
84468 +
84469 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
84470 + continue;
84471 +
84472 + if (!TYPE_READONLY(type))
84473 + continue;
84474 +
84475 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
84476 +// continue;
84477 +
84478 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
84479 +// continue;
84480 +
84481 + if (walk_struct(type)) {
84482 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
84483 + ret = 1;
84484 + }
84485 + }
84486 + return ret;
84487 +}
84488 +
84489 +struct gimple_opt_pass pass_local_variable = {
84490 + {
84491 + .type = GIMPLE_PASS,
84492 + .name = "check_local_variables",
84493 + .gate = NULL,
84494 + .execute = check_local_variables,
84495 + .sub = NULL,
84496 + .next = NULL,
84497 + .static_pass_number = 0,
84498 + .tv_id = TV_NONE,
84499 + .properties_required = 0,
84500 + .properties_provided = 0,
84501 + .properties_destroyed = 0,
84502 + .todo_flags_start = 0,
84503 + .todo_flags_finish = 0
84504 + }
84505 +};
84506 +
84507 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84508 +{
84509 + const char * const plugin_name = plugin_info->base_name;
84510 + const int argc = plugin_info->argc;
84511 + const struct plugin_argument * const argv = plugin_info->argv;
84512 + int i;
84513 + bool constify = true;
84514 +
84515 + struct register_pass_info local_variable_pass_info = {
84516 + .pass = &pass_local_variable.pass,
84517 + .reference_pass_name = "ssa",
84518 + .ref_pass_instance_number = 1,
84519 + .pos_op = PASS_POS_INSERT_BEFORE
84520 + };
84521 +
84522 + if (!plugin_default_version_check(version, &gcc_version)) {
84523 + error(G_("incompatible gcc/plugin versions"));
84524 + return 1;
84525 + }
84526 +
84527 + for (i = 0; i < argc; ++i) {
84528 + if (!(strcmp(argv[i].key, "no-constify"))) {
84529 + constify = false;
84530 + continue;
84531 + }
84532 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84533 + }
84534 +
84535 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
84536 + if (constify) {
84537 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
84538 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
84539 + }
84540 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84541 +
84542 + return 0;
84543 +}
84544 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
84545 new file mode 100644
84546 index 0000000..e518932
84547 --- /dev/null
84548 +++ b/tools/gcc/generate_size_overflow_hash.sh
84549 @@ -0,0 +1,94 @@
84550 +#!/bin/bash
84551 +
84552 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
84553 +
84554 +header1="size_overflow_hash.h"
84555 +database="size_overflow_hash.data"
84556 +n=65536
84557 +
84558 +usage() {
84559 +cat <<EOF
84560 +usage: $0 options
84561 +OPTIONS:
84562 + -h|--help help
84563 + -o header file
84564 + -d database file
84565 + -n hash array size
84566 +EOF
84567 + return 0
84568 +}
84569 +
84570 +while true
84571 +do
84572 + case "$1" in
84573 + -h|--help) usage && exit 0;;
84574 + -n) n=$2; shift 2;;
84575 + -o) header1="$2"; shift 2;;
84576 + -d) database="$2"; shift 2;;
84577 + --) shift 1; break ;;
84578 + *) break ;;
84579 + esac
84580 +done
84581 +
84582 +create_defines() {
84583 + for i in `seq 0 31`
84584 + do
84585 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
84586 + done
84587 + echo >> "$header1"
84588 +}
84589 +
84590 +create_structs() {
84591 + rm -f "$header1"
84592 +
84593 + create_defines
84594 +
84595 + cat "$database" | while read data
84596 + do
84597 + data_array=($data)
84598 + struct_hash_name="${data_array[0]}"
84599 + funcn="${data_array[1]}"
84600 + params="${data_array[2]}"
84601 + next="${data_array[4]}"
84602 +
84603 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
84604 +
84605 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
84606 + echo -en "\t.param\t= " >> "$header1"
84607 + line=
84608 + for param_num in ${params//-/ };
84609 + do
84610 + line="${line}PARAM"$param_num"|"
84611 + done
84612 +
84613 + echo -e "${line%?},\n};\n" >> "$header1"
84614 + done
84615 +}
84616 +
84617 +create_headers() {
84618 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
84619 +}
84620 +
84621 +create_array_elements() {
84622 + index=0
84623 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
84624 + do
84625 + data_array=($data)
84626 + i="${data_array[3]}"
84627 + hash="${data_array[0]}"
84628 + while [[ $index -lt $i ]]
84629 + do
84630 + echo -e "\t["$index"]\t= NULL," >> "$header1"
84631 + index=$(($index + 1))
84632 + done
84633 + index=$(($index + 1))
84634 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
84635 + done
84636 + echo '};' >> $header1
84637 +}
84638 +
84639 +create_structs
84640 +create_headers
84641 +create_array_elements
84642 +
84643 +exit 0
84644 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
84645 new file mode 100644
84646 index 0000000..a86e422
84647 --- /dev/null
84648 +++ b/tools/gcc/kallocstat_plugin.c
84649 @@ -0,0 +1,167 @@
84650 +/*
84651 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84652 + * Licensed under the GPL v2
84653 + *
84654 + * Note: the choice of the license means that the compilation process is
84655 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84656 + * but for the kernel it doesn't matter since it doesn't link against
84657 + * any of the gcc libraries
84658 + *
84659 + * gcc plugin to find the distribution of k*alloc sizes
84660 + *
84661 + * TODO:
84662 + *
84663 + * BUGS:
84664 + * - none known
84665 + */
84666 +#include "gcc-plugin.h"
84667 +#include "config.h"
84668 +#include "system.h"
84669 +#include "coretypes.h"
84670 +#include "tree.h"
84671 +#include "tree-pass.h"
84672 +#include "flags.h"
84673 +#include "intl.h"
84674 +#include "toplev.h"
84675 +#include "plugin.h"
84676 +//#include "expr.h" where are you...
84677 +#include "diagnostic.h"
84678 +#include "plugin-version.h"
84679 +#include "tm.h"
84680 +#include "function.h"
84681 +#include "basic-block.h"
84682 +#include "gimple.h"
84683 +#include "rtl.h"
84684 +#include "emit-rtl.h"
84685 +
84686 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84687 +
84688 +int plugin_is_GPL_compatible;
84689 +
84690 +static const char * const kalloc_functions[] = {
84691 + "__kmalloc",
84692 + "kmalloc",
84693 + "kmalloc_large",
84694 + "kmalloc_node",
84695 + "kmalloc_order",
84696 + "kmalloc_order_trace",
84697 + "kmalloc_slab",
84698 + "kzalloc",
84699 + "kzalloc_node",
84700 +};
84701 +
84702 +static struct plugin_info kallocstat_plugin_info = {
84703 + .version = "201111150100",
84704 +};
84705 +
84706 +static unsigned int execute_kallocstat(void);
84707 +
84708 +static struct gimple_opt_pass kallocstat_pass = {
84709 + .pass = {
84710 + .type = GIMPLE_PASS,
84711 + .name = "kallocstat",
84712 + .gate = NULL,
84713 + .execute = execute_kallocstat,
84714 + .sub = NULL,
84715 + .next = NULL,
84716 + .static_pass_number = 0,
84717 + .tv_id = TV_NONE,
84718 + .properties_required = 0,
84719 + .properties_provided = 0,
84720 + .properties_destroyed = 0,
84721 + .todo_flags_start = 0,
84722 + .todo_flags_finish = 0
84723 + }
84724 +};
84725 +
84726 +static bool is_kalloc(const char *fnname)
84727 +{
84728 + size_t i;
84729 +
84730 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
84731 + if (!strcmp(fnname, kalloc_functions[i]))
84732 + return true;
84733 + return false;
84734 +}
84735 +
84736 +static unsigned int execute_kallocstat(void)
84737 +{
84738 + basic_block bb;
84739 +
84740 + // 1. loop through BBs and GIMPLE statements
84741 + FOR_EACH_BB(bb) {
84742 + gimple_stmt_iterator gsi;
84743 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84744 + // gimple match:
84745 + tree fndecl, size;
84746 + gimple call_stmt;
84747 + const char *fnname;
84748 +
84749 + // is it a call
84750 + call_stmt = gsi_stmt(gsi);
84751 + if (!is_gimple_call(call_stmt))
84752 + continue;
84753 + fndecl = gimple_call_fndecl(call_stmt);
84754 + if (fndecl == NULL_TREE)
84755 + continue;
84756 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
84757 + continue;
84758 +
84759 + // is it a call to k*alloc
84760 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
84761 + if (!is_kalloc(fnname))
84762 + continue;
84763 +
84764 + // is the size arg the result of a simple const assignment
84765 + size = gimple_call_arg(call_stmt, 0);
84766 + while (true) {
84767 + gimple def_stmt;
84768 + expanded_location xloc;
84769 + size_t size_val;
84770 +
84771 + if (TREE_CODE(size) != SSA_NAME)
84772 + break;
84773 + def_stmt = SSA_NAME_DEF_STMT(size);
84774 + if (!def_stmt || !is_gimple_assign(def_stmt))
84775 + break;
84776 + if (gimple_num_ops(def_stmt) != 2)
84777 + break;
84778 + size = gimple_assign_rhs1(def_stmt);
84779 + if (!TREE_CONSTANT(size))
84780 + continue;
84781 + xloc = expand_location(gimple_location(def_stmt));
84782 + if (!xloc.file)
84783 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
84784 + size_val = TREE_INT_CST_LOW(size);
84785 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
84786 + break;
84787 + }
84788 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
84789 +//debug_tree(gimple_call_fn(call_stmt));
84790 +//print_node(stderr, "pax", fndecl, 4);
84791 + }
84792 + }
84793 +
84794 + return 0;
84795 +}
84796 +
84797 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84798 +{
84799 + const char * const plugin_name = plugin_info->base_name;
84800 + struct register_pass_info kallocstat_pass_info = {
84801 + .pass = &kallocstat_pass.pass,
84802 + .reference_pass_name = "ssa",
84803 + .ref_pass_instance_number = 1,
84804 + .pos_op = PASS_POS_INSERT_AFTER
84805 + };
84806 +
84807 + if (!plugin_default_version_check(version, &gcc_version)) {
84808 + error(G_("incompatible gcc/plugin versions"));
84809 + return 1;
84810 + }
84811 +
84812 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
84813 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
84814 +
84815 + return 0;
84816 +}
84817 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
84818 new file mode 100644
84819 index 0000000..8856202
84820 --- /dev/null
84821 +++ b/tools/gcc/kernexec_plugin.c
84822 @@ -0,0 +1,432 @@
84823 +/*
84824 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84825 + * Licensed under the GPL v2
84826 + *
84827 + * Note: the choice of the license means that the compilation process is
84828 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84829 + * but for the kernel it doesn't matter since it doesn't link against
84830 + * any of the gcc libraries
84831 + *
84832 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
84833 + *
84834 + * TODO:
84835 + *
84836 + * BUGS:
84837 + * - none known
84838 + */
84839 +#include "gcc-plugin.h"
84840 +#include "config.h"
84841 +#include "system.h"
84842 +#include "coretypes.h"
84843 +#include "tree.h"
84844 +#include "tree-pass.h"
84845 +#include "flags.h"
84846 +#include "intl.h"
84847 +#include "toplev.h"
84848 +#include "plugin.h"
84849 +//#include "expr.h" where are you...
84850 +#include "diagnostic.h"
84851 +#include "plugin-version.h"
84852 +#include "tm.h"
84853 +#include "function.h"
84854 +#include "basic-block.h"
84855 +#include "gimple.h"
84856 +#include "rtl.h"
84857 +#include "emit-rtl.h"
84858 +#include "tree-flow.h"
84859 +
84860 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84861 +extern rtx emit_move_insn(rtx x, rtx y);
84862 +
84863 +#if BUILDING_GCC_VERSION <= 4006
84864 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
84865 +#endif
84866 +
84867 +int plugin_is_GPL_compatible;
84868 +
84869 +static struct plugin_info kernexec_plugin_info = {
84870 + .version = "201111291120",
84871 + .help = "method=[bts|or]\tinstrumentation method\n"
84872 +};
84873 +
84874 +static unsigned int execute_kernexec_reload(void);
84875 +static unsigned int execute_kernexec_fptr(void);
84876 +static unsigned int execute_kernexec_retaddr(void);
84877 +static bool kernexec_cmodel_check(void);
84878 +
84879 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
84880 +static void (*kernexec_instrument_retaddr)(rtx);
84881 +
84882 +static struct gimple_opt_pass kernexec_reload_pass = {
84883 + .pass = {
84884 + .type = GIMPLE_PASS,
84885 + .name = "kernexec_reload",
84886 + .gate = kernexec_cmodel_check,
84887 + .execute = execute_kernexec_reload,
84888 + .sub = NULL,
84889 + .next = NULL,
84890 + .static_pass_number = 0,
84891 + .tv_id = TV_NONE,
84892 + .properties_required = 0,
84893 + .properties_provided = 0,
84894 + .properties_destroyed = 0,
84895 + .todo_flags_start = 0,
84896 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
84897 + }
84898 +};
84899 +
84900 +static struct gimple_opt_pass kernexec_fptr_pass = {
84901 + .pass = {
84902 + .type = GIMPLE_PASS,
84903 + .name = "kernexec_fptr",
84904 + .gate = kernexec_cmodel_check,
84905 + .execute = execute_kernexec_fptr,
84906 + .sub = NULL,
84907 + .next = NULL,
84908 + .static_pass_number = 0,
84909 + .tv_id = TV_NONE,
84910 + .properties_required = 0,
84911 + .properties_provided = 0,
84912 + .properties_destroyed = 0,
84913 + .todo_flags_start = 0,
84914 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
84915 + }
84916 +};
84917 +
84918 +static struct rtl_opt_pass kernexec_retaddr_pass = {
84919 + .pass = {
84920 + .type = RTL_PASS,
84921 + .name = "kernexec_retaddr",
84922 + .gate = kernexec_cmodel_check,
84923 + .execute = execute_kernexec_retaddr,
84924 + .sub = NULL,
84925 + .next = NULL,
84926 + .static_pass_number = 0,
84927 + .tv_id = TV_NONE,
84928 + .properties_required = 0,
84929 + .properties_provided = 0,
84930 + .properties_destroyed = 0,
84931 + .todo_flags_start = 0,
84932 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
84933 + }
84934 +};
84935 +
84936 +static bool kernexec_cmodel_check(void)
84937 +{
84938 + tree section;
84939 +
84940 + if (ix86_cmodel != CM_KERNEL)
84941 + return false;
84942 +
84943 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
84944 + if (!section || !TREE_VALUE(section))
84945 + return true;
84946 +
84947 + section = TREE_VALUE(TREE_VALUE(section));
84948 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
84949 + return true;
84950 +
84951 + return false;
84952 +}
84953 +
84954 +/*
84955 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
84956 + */
84957 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
84958 +{
84959 + gimple asm_movabs_stmt;
84960 +
84961 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
84962 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
84963 + gimple_asm_set_volatile(asm_movabs_stmt, true);
84964 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
84965 + update_stmt(asm_movabs_stmt);
84966 +}
84967 +
84968 +/*
84969 + * find all asm() stmts that clobber r10 and add a reload of r10
84970 + */
84971 +static unsigned int execute_kernexec_reload(void)
84972 +{
84973 + basic_block bb;
84974 +
84975 + // 1. loop through BBs and GIMPLE statements
84976 + FOR_EACH_BB(bb) {
84977 + gimple_stmt_iterator gsi;
84978 +
84979 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84980 + // gimple match: __asm__ ("" : : : "r10");
84981 + gimple asm_stmt;
84982 + size_t nclobbers;
84983 +
84984 + // is it an asm ...
84985 + asm_stmt = gsi_stmt(gsi);
84986 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
84987 + continue;
84988 +
84989 + // ... clobbering r10
84990 + nclobbers = gimple_asm_nclobbers(asm_stmt);
84991 + while (nclobbers--) {
84992 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
84993 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
84994 + continue;
84995 + kernexec_reload_fptr_mask(&gsi);
84996 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
84997 + break;
84998 + }
84999 + }
85000 + }
85001 +
85002 + return 0;
85003 +}
85004 +
85005 +/*
85006 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
85007 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
85008 + */
85009 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
85010 +{
85011 + gimple assign_intptr, assign_new_fptr, call_stmt;
85012 + tree intptr, old_fptr, new_fptr, kernexec_mask;
85013 +
85014 + call_stmt = gsi_stmt(*gsi);
85015 + old_fptr = gimple_call_fn(call_stmt);
85016 +
85017 + // create temporary unsigned long variable used for bitops and cast fptr to it
85018 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
85019 + add_referenced_var(intptr);
85020 + mark_sym_for_renaming(intptr);
85021 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
85022 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85023 + update_stmt(assign_intptr);
85024 +
85025 + // apply logical or to temporary unsigned long and bitmask
85026 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
85027 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
85028 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
85029 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85030 + update_stmt(assign_intptr);
85031 +
85032 + // cast temporary unsigned long back to a temporary fptr variable
85033 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
85034 + add_referenced_var(new_fptr);
85035 + mark_sym_for_renaming(new_fptr);
85036 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
85037 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
85038 + update_stmt(assign_new_fptr);
85039 +
85040 + // replace call stmt fn with the new fptr
85041 + gimple_call_set_fn(call_stmt, new_fptr);
85042 + update_stmt(call_stmt);
85043 +}
85044 +
85045 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
85046 +{
85047 + gimple asm_or_stmt, call_stmt;
85048 + tree old_fptr, new_fptr, input, output;
85049 + VEC(tree, gc) *inputs = NULL;
85050 + VEC(tree, gc) *outputs = NULL;
85051 +
85052 + call_stmt = gsi_stmt(*gsi);
85053 + old_fptr = gimple_call_fn(call_stmt);
85054 +
85055 + // create temporary fptr variable
85056 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
85057 + add_referenced_var(new_fptr);
85058 + mark_sym_for_renaming(new_fptr);
85059 +
85060 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
85061 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
85062 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
85063 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
85064 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
85065 + VEC_safe_push(tree, gc, inputs, input);
85066 + VEC_safe_push(tree, gc, outputs, output);
85067 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
85068 + gimple_asm_set_volatile(asm_or_stmt, true);
85069 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
85070 + update_stmt(asm_or_stmt);
85071 +
85072 + // replace call stmt fn with the new fptr
85073 + gimple_call_set_fn(call_stmt, new_fptr);
85074 + update_stmt(call_stmt);
85075 +}
85076 +
85077 +/*
85078 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
85079 + */
85080 +static unsigned int execute_kernexec_fptr(void)
85081 +{
85082 + basic_block bb;
85083 +
85084 + // 1. loop through BBs and GIMPLE statements
85085 + FOR_EACH_BB(bb) {
85086 + gimple_stmt_iterator gsi;
85087 +
85088 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85089 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
85090 + tree fn;
85091 + gimple call_stmt;
85092 +
85093 + // is it a call ...
85094 + call_stmt = gsi_stmt(gsi);
85095 + if (!is_gimple_call(call_stmt))
85096 + continue;
85097 + fn = gimple_call_fn(call_stmt);
85098 + if (TREE_CODE(fn) == ADDR_EXPR)
85099 + continue;
85100 + if (TREE_CODE(fn) != SSA_NAME)
85101 + gcc_unreachable();
85102 +
85103 + // ... through a function pointer
85104 + fn = SSA_NAME_VAR(fn);
85105 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
85106 + continue;
85107 + fn = TREE_TYPE(fn);
85108 + if (TREE_CODE(fn) != POINTER_TYPE)
85109 + continue;
85110 + fn = TREE_TYPE(fn);
85111 + if (TREE_CODE(fn) != FUNCTION_TYPE)
85112 + continue;
85113 +
85114 + kernexec_instrument_fptr(&gsi);
85115 +
85116 +//debug_tree(gimple_call_fn(call_stmt));
85117 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85118 + }
85119 + }
85120 +
85121 + return 0;
85122 +}
85123 +
85124 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
85125 +static void kernexec_instrument_retaddr_bts(rtx insn)
85126 +{
85127 + rtx btsq;
85128 + rtvec argvec, constraintvec, labelvec;
85129 + int line;
85130 +
85131 + // create asm volatile("btsq $63,(%%rsp)":::)
85132 + argvec = rtvec_alloc(0);
85133 + constraintvec = rtvec_alloc(0);
85134 + labelvec = rtvec_alloc(0);
85135 + line = expand_location(RTL_LOCATION(insn)).line;
85136 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85137 + MEM_VOLATILE_P(btsq) = 1;
85138 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
85139 + emit_insn_before(btsq, insn);
85140 +}
85141 +
85142 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
85143 +static void kernexec_instrument_retaddr_or(rtx insn)
85144 +{
85145 + rtx orq;
85146 + rtvec argvec, constraintvec, labelvec;
85147 + int line;
85148 +
85149 + // create asm volatile("orq %%r10,(%%rsp)":::)
85150 + argvec = rtvec_alloc(0);
85151 + constraintvec = rtvec_alloc(0);
85152 + labelvec = rtvec_alloc(0);
85153 + line = expand_location(RTL_LOCATION(insn)).line;
85154 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85155 + MEM_VOLATILE_P(orq) = 1;
85156 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
85157 + emit_insn_before(orq, insn);
85158 +}
85159 +
85160 +/*
85161 + * find all asm level function returns and forcibly set the highest bit of the return address
85162 + */
85163 +static unsigned int execute_kernexec_retaddr(void)
85164 +{
85165 + rtx insn;
85166 +
85167 + // 1. find function returns
85168 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85169 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
85170 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
85171 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
85172 + rtx body;
85173 +
85174 + // is it a retn
85175 + if (!JUMP_P(insn))
85176 + continue;
85177 + body = PATTERN(insn);
85178 + if (GET_CODE(body) == PARALLEL)
85179 + body = XVECEXP(body, 0, 0);
85180 + if (!ANY_RETURN_P(body))
85181 + continue;
85182 + kernexec_instrument_retaddr(insn);
85183 + }
85184 +
85185 +// print_simple_rtl(stderr, get_insns());
85186 +// print_rtl(stderr, get_insns());
85187 +
85188 + return 0;
85189 +}
85190 +
85191 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85192 +{
85193 + const char * const plugin_name = plugin_info->base_name;
85194 + const int argc = plugin_info->argc;
85195 + const struct plugin_argument * const argv = plugin_info->argv;
85196 + int i;
85197 + struct register_pass_info kernexec_reload_pass_info = {
85198 + .pass = &kernexec_reload_pass.pass,
85199 + .reference_pass_name = "ssa",
85200 + .ref_pass_instance_number = 1,
85201 + .pos_op = PASS_POS_INSERT_AFTER
85202 + };
85203 + struct register_pass_info kernexec_fptr_pass_info = {
85204 + .pass = &kernexec_fptr_pass.pass,
85205 + .reference_pass_name = "ssa",
85206 + .ref_pass_instance_number = 1,
85207 + .pos_op = PASS_POS_INSERT_AFTER
85208 + };
85209 + struct register_pass_info kernexec_retaddr_pass_info = {
85210 + .pass = &kernexec_retaddr_pass.pass,
85211 + .reference_pass_name = "pro_and_epilogue",
85212 + .ref_pass_instance_number = 1,
85213 + .pos_op = PASS_POS_INSERT_AFTER
85214 + };
85215 +
85216 + if (!plugin_default_version_check(version, &gcc_version)) {
85217 + error(G_("incompatible gcc/plugin versions"));
85218 + return 1;
85219 + }
85220 +
85221 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
85222 +
85223 + if (TARGET_64BIT == 0)
85224 + return 0;
85225 +
85226 + for (i = 0; i < argc; ++i) {
85227 + if (!strcmp(argv[i].key, "method")) {
85228 + if (!argv[i].value) {
85229 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85230 + continue;
85231 + }
85232 + if (!strcmp(argv[i].value, "bts")) {
85233 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
85234 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
85235 + } else if (!strcmp(argv[i].value, "or")) {
85236 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
85237 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
85238 + fix_register("r10", 1, 1);
85239 + } else
85240 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85241 + continue;
85242 + }
85243 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85244 + }
85245 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
85246 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
85247 +
85248 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
85249 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
85250 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
85251 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
85252 +
85253 + return 0;
85254 +}
85255 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
85256 new file mode 100644
85257 index 0000000..b8008f7
85258 --- /dev/null
85259 +++ b/tools/gcc/latent_entropy_plugin.c
85260 @@ -0,0 +1,295 @@
85261 +/*
85262 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
85263 + * Licensed under the GPL v2
85264 + *
85265 + * Note: the choice of the license means that the compilation process is
85266 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85267 + * but for the kernel it doesn't matter since it doesn't link against
85268 + * any of the gcc libraries
85269 + *
85270 + * gcc plugin to help generate a little bit of entropy from program state,
85271 + * used during boot in the kernel
85272 + *
85273 + * TODO:
85274 + * - add ipa pass to identify not explicitly marked candidate functions
85275 + * - mix in more program state (function arguments/return values, loop variables, etc)
85276 + * - more instrumentation control via attribute parameters
85277 + *
85278 + * BUGS:
85279 + * - LTO needs -flto-partition=none for now
85280 + */
85281 +#include "gcc-plugin.h"
85282 +#include "config.h"
85283 +#include "system.h"
85284 +#include "coretypes.h"
85285 +#include "tree.h"
85286 +#include "tree-pass.h"
85287 +#include "flags.h"
85288 +#include "intl.h"
85289 +#include "toplev.h"
85290 +#include "plugin.h"
85291 +//#include "expr.h" where are you...
85292 +#include "diagnostic.h"
85293 +#include "plugin-version.h"
85294 +#include "tm.h"
85295 +#include "function.h"
85296 +#include "basic-block.h"
85297 +#include "gimple.h"
85298 +#include "rtl.h"
85299 +#include "emit-rtl.h"
85300 +#include "tree-flow.h"
85301 +
85302 +int plugin_is_GPL_compatible;
85303 +
85304 +static tree latent_entropy_decl;
85305 +
85306 +static struct plugin_info latent_entropy_plugin_info = {
85307 + .version = "201207271820",
85308 + .help = NULL
85309 +};
85310 +
85311 +static unsigned int execute_latent_entropy(void);
85312 +static bool gate_latent_entropy(void);
85313 +
85314 +static struct gimple_opt_pass latent_entropy_pass = {
85315 + .pass = {
85316 + .type = GIMPLE_PASS,
85317 + .name = "latent_entropy",
85318 + .gate = gate_latent_entropy,
85319 + .execute = execute_latent_entropy,
85320 + .sub = NULL,
85321 + .next = NULL,
85322 + .static_pass_number = 0,
85323 + .tv_id = TV_NONE,
85324 + .properties_required = PROP_gimple_leh | PROP_cfg,
85325 + .properties_provided = 0,
85326 + .properties_destroyed = 0,
85327 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
85328 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
85329 + }
85330 +};
85331 +
85332 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85333 +{
85334 + if (TREE_CODE(*node) != FUNCTION_DECL) {
85335 + *no_add_attrs = true;
85336 + error("%qE attribute only applies to functions", name);
85337 + }
85338 + return NULL_TREE;
85339 +}
85340 +
85341 +static struct attribute_spec latent_entropy_attr = {
85342 + .name = "latent_entropy",
85343 + .min_length = 0,
85344 + .max_length = 0,
85345 + .decl_required = true,
85346 + .type_required = false,
85347 + .function_type_required = false,
85348 + .handler = handle_latent_entropy_attribute,
85349 +#if BUILDING_GCC_VERSION >= 4007
85350 + .affects_type_identity = false
85351 +#endif
85352 +};
85353 +
85354 +static void register_attributes(void *event_data, void *data)
85355 +{
85356 + register_attribute(&latent_entropy_attr);
85357 +}
85358 +
85359 +static bool gate_latent_entropy(void)
85360 +{
85361 + tree latent_entropy_attr;
85362 +
85363 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
85364 + return latent_entropy_attr != NULL_TREE;
85365 +}
85366 +
85367 +static unsigned HOST_WIDE_INT seed;
85368 +static unsigned HOST_WIDE_INT get_random_const(void)
85369 +{
85370 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
85371 + return seed;
85372 +}
85373 +
85374 +static enum tree_code get_op(tree *rhs)
85375 +{
85376 + static enum tree_code op;
85377 + unsigned HOST_WIDE_INT random_const;
85378 +
85379 + random_const = get_random_const();
85380 +
85381 + switch (op) {
85382 + case BIT_XOR_EXPR:
85383 + op = PLUS_EXPR;
85384 + break;
85385 +
85386 + case PLUS_EXPR:
85387 + if (rhs) {
85388 + op = LROTATE_EXPR;
85389 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
85390 + break;
85391 + }
85392 +
85393 + case LROTATE_EXPR:
85394 + default:
85395 + op = BIT_XOR_EXPR;
85396 + break;
85397 + }
85398 + if (rhs)
85399 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
85400 + return op;
85401 +}
85402 +
85403 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
85404 +{
85405 + gimple_stmt_iterator gsi;
85406 + gimple assign;
85407 + tree addxorrol, rhs;
85408 + enum tree_code op;
85409 +
85410 + op = get_op(&rhs);
85411 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
85412 + assign = gimple_build_assign(local_entropy, addxorrol);
85413 + find_referenced_vars_in(assign);
85414 +//debug_bb(bb);
85415 + gsi = gsi_after_labels(bb);
85416 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
85417 + update_stmt(assign);
85418 +}
85419 +
85420 +static void perturb_latent_entropy(basic_block bb, tree rhs)
85421 +{
85422 + gimple_stmt_iterator gsi;
85423 + gimple assign;
85424 + tree addxorrol, temp;
85425 +
85426 + // 1. create temporary copy of latent_entropy
85427 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
85428 + add_referenced_var(temp);
85429 + mark_sym_for_renaming(temp);
85430 +
85431 + // 2. read...
85432 + assign = gimple_build_assign(temp, latent_entropy_decl);
85433 + find_referenced_vars_in(assign);
85434 + gsi = gsi_after_labels(bb);
85435 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
85436 + update_stmt(assign);
85437 +
85438 + // 3. ...modify...
85439 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
85440 + assign = gimple_build_assign(temp, addxorrol);
85441 + find_referenced_vars_in(assign);
85442 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
85443 + update_stmt(assign);
85444 +
85445 + // 4. ...write latent_entropy
85446 + assign = gimple_build_assign(latent_entropy_decl, temp);
85447 + find_referenced_vars_in(assign);
85448 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
85449 + update_stmt(assign);
85450 +}
85451 +
85452 +static unsigned int execute_latent_entropy(void)
85453 +{
85454 + basic_block bb;
85455 + gimple assign;
85456 + gimple_stmt_iterator gsi;
85457 + tree local_entropy;
85458 +
85459 + if (!latent_entropy_decl) {
85460 + struct varpool_node *node;
85461 +
85462 + for (node = varpool_nodes; node; node = node->next) {
85463 + tree var = node->decl;
85464 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
85465 + continue;
85466 + latent_entropy_decl = var;
85467 +// debug_tree(var);
85468 + break;
85469 + }
85470 + if (!latent_entropy_decl) {
85471 +// debug_tree(current_function_decl);
85472 + return 0;
85473 + }
85474 + }
85475 +
85476 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
85477 +
85478 + // 1. create local entropy variable
85479 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
85480 + add_referenced_var(local_entropy);
85481 + mark_sym_for_renaming(local_entropy);
85482 +
85483 + // 2. initialize local entropy variable
85484 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85485 + if (dom_info_available_p(CDI_DOMINATORS))
85486 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
85487 + gsi = gsi_start_bb(bb);
85488 +
85489 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
85490 +// gimple_set_location(assign, loc);
85491 + find_referenced_vars_in(assign);
85492 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
85493 + update_stmt(assign);
85494 + bb = bb->next_bb;
85495 +
85496 + // 3. instrument each BB with an operation on the local entropy variable
85497 + while (bb != EXIT_BLOCK_PTR) {
85498 + perturb_local_entropy(bb, local_entropy);
85499 + bb = bb->next_bb;
85500 + };
85501 +
85502 + // 4. mix local entropy into the global entropy variable
85503 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
85504 + return 0;
85505 +}
85506 +
85507 +static void start_unit_callback(void *gcc_data, void *user_data)
85508 +{
85509 +#if BUILDING_GCC_VERSION >= 4007
85510 + seed = get_random_seed(false);
85511 +#else
85512 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
85513 + seed *= seed;
85514 +#endif
85515 +
85516 + if (in_lto_p)
85517 + return;
85518 +
85519 + // extern u64 latent_entropy
85520 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
85521 +
85522 + TREE_STATIC(latent_entropy_decl) = 1;
85523 + TREE_PUBLIC(latent_entropy_decl) = 1;
85524 + TREE_USED(latent_entropy_decl) = 1;
85525 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
85526 + DECL_EXTERNAL(latent_entropy_decl) = 1;
85527 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
85528 + DECL_INITIAL(latent_entropy_decl) = NULL;
85529 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
85530 +// varpool_finalize_decl(latent_entropy_decl);
85531 +// varpool_mark_needed_node(latent_entropy_decl);
85532 +}
85533 +
85534 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85535 +{
85536 + const char * const plugin_name = plugin_info->base_name;
85537 + struct register_pass_info latent_entropy_pass_info = {
85538 + .pass = &latent_entropy_pass.pass,
85539 + .reference_pass_name = "optimized",
85540 + .ref_pass_instance_number = 1,
85541 + .pos_op = PASS_POS_INSERT_BEFORE
85542 + };
85543 +
85544 + if (!plugin_default_version_check(version, &gcc_version)) {
85545 + error(G_("incompatible gcc/plugin versions"));
85546 + return 1;
85547 + }
85548 +
85549 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
85550 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
85551 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
85552 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85553 +
85554 + return 0;
85555 +}
85556 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
85557 new file mode 100644
85558 index 0000000..5921fd7
85559 --- /dev/null
85560 +++ b/tools/gcc/size_overflow_hash.data
85561 @@ -0,0 +1,3713 @@
85562 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
85563 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
85564 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
85565 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
85566 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
85567 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
85568 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
85569 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
85570 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
85571 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
85572 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
85573 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
85574 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
85575 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
85576 +create_log_8225 create_log 2 8225 NULL
85577 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
85578 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
85579 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
85580 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
85581 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
85582 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
85583 +padzero_55 padzero 1 55 &sel_read_policyvers_55
85584 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
85585 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
85586 +read_file_blob_57406 read_file_blob 3 57406 NULL
85587 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
85588 +enclosure_register_57412 enclosure_register 3 57412 NULL
85589 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
85590 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
85591 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
85592 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
85593 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
85594 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
85595 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
85596 +init_cdev_8274 init_cdev 1 8274 NULL
85597 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
85598 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
85599 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
85600 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
85601 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
85602 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
85603 +load_msg_95 load_msg 2 95 NULL
85604 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
85605 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
85606 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
85607 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
85608 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
85609 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
85610 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
85611 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
85612 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
85613 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
85614 +send_midi_async_57463 send_midi_async 3 57463 NULL
85615 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
85616 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
85617 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
85618 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
85619 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
85620 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
85621 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
85622 +init_q_132 init_q 4 132 NULL
85623 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
85624 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
85625 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
85626 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
85627 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
85628 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
85629 +uio_read_49300 uio_read 3 49300 NULL
85630 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
85631 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
85632 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
85633 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
85634 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
85635 +play_iframe_8219 play_iframe 3 8219 NULL
85636 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
85637 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
85638 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
85639 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
85640 +init_tag_map_57515 init_tag_map 3 57515 NULL
85641 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
85642 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
85643 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
85644 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
85645 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
85646 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
85647 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
85648 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
85649 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
85650 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
85651 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
85652 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
85653 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
85654 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
85655 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
85656 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
85657 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
85658 +cache_read_24790 cache_read 3 24790 NULL
85659 +px_raw_event_49371 px_raw_event 4 49371 NULL
85660 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
85661 +compat_filldir_32999 compat_filldir 3 32999 NULL
85662 +hci_si_event_1404 hci_si_event 3 1404 NULL
85663 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
85664 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
85665 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
85666 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
85667 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
85668 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
85669 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
85670 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
85671 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
85672 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
85673 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
85674 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
85675 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
85676 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
85677 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
85678 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
85679 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
85680 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
85681 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
85682 +mem_read_57631 mem_read 3 57631 NULL
85683 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
85684 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
85685 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
85686 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
85687 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
85688 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
85689 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
85690 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
85691 +queues_read_24877 queues_read 3 24877 NULL
85692 +__fprog_create_41263 __fprog_create 2 41263 NULL
85693 +syslog_print_307 syslog_print 2 307 NULL
85694 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
85695 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
85696 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
85697 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
85698 +r3964_write_57662 r3964_write 4 57662 NULL
85699 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
85700 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
85701 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
85702 +alloc_context_41283 alloc_context 1 41283 NULL
85703 +__lgwrite_57669 __lgwrite 4 57669 NULL
85704 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
85705 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
85706 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
85707 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
85708 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
85709 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
85710 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
85711 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
85712 +write_node_33121 write_node 4 33121 NULL
85713 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
85714 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
85715 +profile_remove_8556 profile_remove 3 8556 NULL
85716 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
85717 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
85718 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
85719 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
85720 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
85721 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
85722 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
85723 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
85724 +tower_write_8580 tower_write 3 8580 NULL
85725 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
85726 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
85727 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
85728 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
85729 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
85730 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
85731 +smk_write_access_49561 smk_write_access 3 49561 NULL
85732 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
85733 +kmp_init_41373 kmp_init 2 41373 NULL
85734 +context_alloc_24645 context_alloc 3 24645 NULL
85735 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
85736 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
85737 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
85738 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
85739 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
85740 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
85741 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
85742 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
85743 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
85744 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
85745 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
85746 +pp_read_33210 pp_read 3 33210 NULL
85747 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
85748 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
85749 +ivtv_read_57796 ivtv_read 3 57796 NULL
85750 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
85751 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
85752 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
85753 +heap_init_49617 heap_init 2 49617 NULL
85754 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
85755 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
85756 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
85757 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
85758 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
85759 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
85760 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
85761 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
85762 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
85763 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
85764 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
85765 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
85766 +st_write_16874 st_write 3 16874 NULL
85767 +copy_to_user_57835 copy_to_user 3 57835 NULL
85768 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
85769 +pidlist_resize_496 pidlist_resize 2 496 NULL
85770 +flash_read_57843 flash_read 3 57843 NULL
85771 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
85772 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
85773 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
85774 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
85775 +arcfb_write_8702 arcfb_write 3 8702 NULL
85776 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
85777 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
85778 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
85779 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
85780 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
85781 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
85782 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
85783 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
85784 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
85785 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
85786 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
85787 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
85788 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
85789 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
85790 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
85791 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
85792 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
85793 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
85794 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
85795 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
85796 +devres_alloc_551 devres_alloc 2 551 NULL
85797 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
85798 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
85799 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
85800 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
85801 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
85802 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
85803 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
85804 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
85805 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
85806 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
85807 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
85808 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
85809 +sys_prctl_8766 sys_prctl 4 8766 NULL
85810 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
85811 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
85812 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
85813 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
85814 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
85815 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
85816 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
85817 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
85818 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
85819 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
85820 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
85821 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
85822 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
85823 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
85824 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
85825 +gserial_setup_41558 gserial_setup 2 41558 NULL
85826 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
85827 +rx_57944 rx 4 57944 NULL
85828 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
85829 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
85830 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
85831 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
85832 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
85833 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
85834 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
85835 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
85836 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
85837 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
85838 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
85839 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
85840 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
85841 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
85842 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
85843 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
85844 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
85845 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
85846 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
85847 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
85848 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
85849 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
85850 +a2mp_send_41615 a2mp_send 4 41615 NULL
85851 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
85852 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
85853 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
85854 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
85855 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
85856 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
85857 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
85858 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
85859 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
85860 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
85861 +add_uuid_49831 add_uuid 4 49831 NULL
85862 +send_pages_8872 send_pages 3 8872 NULL
85863 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
85864 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
85865 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
85866 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
85867 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
85868 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
85869 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
85870 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
85871 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
85872 +vfs_writev_25278 vfs_writev 3 25278 NULL
85873 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
85874 +alloc_async_14208 alloc_async 1 14208 NULL
85875 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
85876 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
85877 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
85878 +create_entry_33479 create_entry 2 33479 NULL
85879 +mce_async_out_58056 mce_async_out 3 58056 NULL
85880 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
85881 +sys_preadv_17100 sys_preadv 3 17100 NULL
85882 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
85883 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
85884 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
85885 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
85886 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
85887 +res_counter_read_33499 res_counter_read 4 33499 NULL
85888 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
85889 +cm4040_write_58079 cm4040_write 3 58079 NULL
85890 +fb_read_33506 fb_read 3 33506 NULL
85891 +help_25316 help 5 25316 NULL nohasharray
85892 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
85893 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
85894 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
85895 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
85896 +ddp_set_map_751 ddp_set_map 4 751 NULL
85897 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
85898 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
85899 +dvb_video_write_754 dvb_video_write 3 754 NULL
85900 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
85901 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
85902 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
85903 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
85904 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
85905 +udi_log_event_58105 udi_log_event 3 58105 NULL
85906 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
85907 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
85908 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
85909 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
85910 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
85911 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
85912 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
85913 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
85914 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
85915 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
85916 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
85917 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
85918 +sep_read_17161 sep_read 3 17161 NULL
85919 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
85920 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
85921 +dup_array_33551 dup_array 3 33551 NULL
85922 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
85923 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
85924 +fillonedir_41746 fillonedir 3 41746 NULL
85925 +init_bch_64130 init_bch 1-2 64130 NULL
85926 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
85927 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
85928 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
85929 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
85930 +savemem_58129 savemem 3 58129 NULL
85931 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
85932 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
85933 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
85934 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
85935 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
85936 +if_writecmd_815 if_writecmd 2 815 NULL
85937 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
85938 +read_fifo_826 read_fifo 3 826 NULL
85939 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
85940 +scsi_execute_33596 scsi_execute 5 33596 NULL
85941 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
85942 +ms_rw_17220 ms_rw 3-4 17220 NULL
85943 +read_tree_block_841 read_tree_block 3 841 NULL
85944 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
85945 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
85946 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
85947 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
85948 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
85949 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
85950 +um_idi_read_850 um_idi_read 3 850 NULL
85951 +__module_alloc_50004 __module_alloc 1 50004 NULL
85952 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
85953 +ts_read_44687 ts_read 3 44687 NULL
85954 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
85955 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
85956 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
85957 +provide_user_output_41105 provide_user_output 3 41105 NULL
85958 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
85959 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
85960 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
85961 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
85962 +alloc_ep_17269 alloc_ep 1 17269 NULL
85963 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
85964 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
85965 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
85966 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
85967 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
85968 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
85969 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
85970 +create_queues_9088 create_queues 2-3 9088 NULL
85971 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
85972 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
85973 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
85974 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
85975 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
85976 +read_file_debug_58256 read_file_debug 3 58256 NULL
85977 +skb_pad_17302 skb_pad 2 17302 NULL
85978 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
85979 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
85980 +profile_load_58267 profile_load 3 58267 NULL
85981 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
85982 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
85983 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
85984 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
85985 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
85986 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
85987 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
85988 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
85989 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
85990 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
85991 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
85992 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
85993 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
85994 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
85995 +get_packet_41914 get_packet 3 41914 NULL
85996 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
85997 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
85998 +read_file_slot_50111 read_file_slot 3 50111 NULL
85999 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
86000 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
86001 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
86002 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
86003 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
86004 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
86005 +copy_items_50140 copy_items 6 50140 NULL
86006 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
86007 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
86008 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
86009 +map_addr_56144 map_addr 7 56144 NULL
86010 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
86011 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
86012 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
86013 +portnames_read_41958 portnames_read 3 41958 NULL
86014 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
86015 +hashtab_create_33769 hashtab_create 3 33769 NULL
86016 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
86017 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
86018 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
86019 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
86020 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
86021 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
86022 +odev_update_50169 odev_update 2 50169 NULL
86023 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
86024 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
86025 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
86026 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
86027 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
86028 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
86029 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
86030 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
86031 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
86032 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
86033 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
86034 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
86035 +lguest_map_42008 lguest_map 1-2 42008 NULL
86036 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
86037 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
86038 +pool_allocate_42012 pool_allocate 3 42012 NULL
86039 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
86040 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
86041 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
86042 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
86043 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
86044 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
86045 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
86046 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
86047 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
86048 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
86049 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
86050 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
86051 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
86052 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
86053 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
86054 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
86055 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
86056 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
86057 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
86058 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
86059 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
86060 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
86061 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
86062 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
86063 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
86064 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
86065 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
86066 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
86067 +config_proc_write_33878 config_proc_write 3 33878 NULL
86068 +capabilities_read_58457 capabilities_read 3 58457 NULL
86069 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
86070 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
86071 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
86072 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
86073 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
86074 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
86075 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
86076 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
86077 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
86078 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
86079 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
86080 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
86081 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
86082 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
86083 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
86084 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
86085 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
86086 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
86087 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
86088 +vme_user_write_15587 vme_user_write 3 15587 NULL
86089 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
86090 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
86091 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
86092 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
86093 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
86094 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
86095 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
86096 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
86097 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
86098 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
86099 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
86100 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
86101 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
86102 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
86103 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
86104 +read_9397 read 3 9397 NULL
86105 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
86106 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
86107 +printer_write_60276 printer_write 3 60276 NULL
86108 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
86109 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
86110 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
86111 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
86112 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
86113 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
86114 +osst_execute_17607 osst_execute 7-6 17607 NULL
86115 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
86116 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
86117 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
86118 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
86119 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
86120 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
86121 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
86122 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
86123 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
86124 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
86125 +xip_file_read_58592 xip_file_read 3 58592 NULL
86126 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
86127 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
86128 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
86129 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
86130 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
86131 +ppp_write_34034 ppp_write 3 34034 NULL
86132 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
86133 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
86134 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
86135 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
86136 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
86137 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
86138 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
86139 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
86140 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
86141 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
86142 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
86143 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
86144 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
86145 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
86146 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
86147 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
86148 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
86149 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
86150 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
86151 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
86152 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
86153 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
86154 +lp_write_9511 lp_write 3 9511 NULL
86155 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
86156 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
86157 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
86158 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
86159 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
86160 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
86161 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
86162 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
86163 +read_file_dma_9530 read_file_dma 3 9530 NULL
86164 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
86165 +rcname_read_25919 rcname_read 3 25919 NULL
86166 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
86167 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
86168 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
86169 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
86170 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
86171 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
86172 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
86173 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
86174 +key_flags_read_25931 key_flags_read 3 25931 NULL
86175 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
86176 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
86177 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
86178 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
86179 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
86180 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
86181 +fw_node_create_9559 fw_node_create 2 9559 NULL
86182 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
86183 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
86184 +kobj_map_9566 kobj_map 2-3 9566 NULL
86185 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
86186 +acpi_map_58725 acpi_map 1-2 58725 NULL
86187 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
86188 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
86189 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
86190 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
86191 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
86192 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
86193 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
86194 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
86195 +file_read_actor_1401 file_read_actor 4 1401 NULL
86196 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
86197 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
86198 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
86199 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
86200 +do_sync_9604 do_sync 1 9604 NULL
86201 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
86202 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
86203 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
86204 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
86205 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
86206 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
86207 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
86208 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
86209 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
86210 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
86211 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
86212 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
86213 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
86214 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
86215 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
86216 +sge_rx_50594 sge_rx 3 50594 NULL
86217 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
86218 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
86219 +skb_padto_50759 skb_padto 2 50759 NULL
86220 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
86221 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
86222 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
86223 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
86224 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
86225 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
86226 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
86227 +ep_read_58813 ep_read 3 58813 NULL
86228 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
86229 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
86230 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
86231 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
86232 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
86233 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
86234 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
86235 +dns_query_9676 dns_query 3 9676 NULL
86236 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
86237 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
86238 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
86239 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
86240 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
86241 +command_write_58841 command_write 3 58841 NULL
86242 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
86243 +dev_config_8506 dev_config 3 8506 NULL
86244 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
86245 +sys_readv_50664 sys_readv 3 50664 NULL
86246 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
86247 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
86248 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
86249 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
86250 +recover_head_17904 recover_head 3 17904 NULL
86251 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
86252 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
86253 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
86254 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
86255 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
86256 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
86257 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
86258 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
86259 +skb_cow_26138 skb_cow 2 26138 NULL
86260 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
86261 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
86262 +do_sigpending_9766 do_sigpending 2 9766 NULL
86263 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
86264 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
86265 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
86266 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
86267 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
86268 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
86269 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
86270 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
86271 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
86272 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
86273 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
86274 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
86275 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
86276 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
86277 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
86278 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
86279 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
86280 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
86281 +get_registers_26187 get_registers 3 26187 NULL
86282 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
86283 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
86284 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
86285 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
86286 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
86287 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
86288 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
86289 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
86290 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
86291 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
86292 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
86293 +mce_write_26201 mce_write 3 26201 NULL
86294 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
86295 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
86296 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
86297 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
86298 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
86299 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
86300 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
86301 +tpm_write_50798 tpm_write 3 50798 NULL
86302 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
86303 +tun_do_read_50800 tun_do_read 4 50800 NULL
86304 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
86305 +write_flush_50803 write_flush 3 50803 NULL
86306 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
86307 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
86308 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
86309 +dvb_play_50814 dvb_play 3 50814 NULL
86310 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
86311 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
86312 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
86313 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
86314 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
86315 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
86316 +dma_attach_50831 dma_attach 6-7 50831 NULL
86317 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
86318 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
86319 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
86320 +packet_came_18072 packet_came 3 18072 NULL
86321 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
86322 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
86323 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
86324 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
86325 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
86326 +get_vm_area_18080 get_vm_area 1 18080 NULL
86327 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
86328 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
86329 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
86330 +self_check_write_50856 self_check_write 5 50856 NULL
86331 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
86332 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
86333 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
86334 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
86335 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
86336 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
86337 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
86338 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
86339 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
86340 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
86341 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
86342 +vb2_read_42703 vb2_read 3 42703 NULL
86343 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
86344 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
86345 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
86346 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
86347 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
86348 +read_file_misc_9948 read_file_misc 3 9948 NULL
86349 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
86350 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
86351 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
86352 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
86353 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
86354 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
86355 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
86356 +cosa_write_1774 cosa_write 3 1774 NULL
86357 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
86358 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
86359 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
86360 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
86361 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
86362 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
86363 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
86364 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
86365 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
86366 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
86367 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
86368 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
86369 +mld_newpack_50950 mld_newpack 2 50950 NULL
86370 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
86371 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
86372 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
86373 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
86374 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
86375 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
86376 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
86377 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
86378 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
86379 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
86380 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
86381 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
86382 +handle_request_10024 handle_request 9 10024 NULL
86383 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
86384 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
86385 +timeout_write_50991 timeout_write 3 50991 NULL
86386 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
86387 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
86388 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
86389 +proc_write_51003 proc_write 3 51003 NULL
86390 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
86391 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
86392 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
86393 +set_arg_42824 set_arg 3 42824 NULL
86394 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
86395 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
86396 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
86397 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
86398 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
86399 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
86400 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
86401 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
86402 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
86403 +dt3155_read_59226 dt3155_read 3 59226 NULL
86404 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
86405 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
86406 +dump_midi_51040 dump_midi 3 51040 NULL
86407 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
86408 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
86409 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
86410 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
86411 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
86412 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
86413 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
86414 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
86415 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
86416 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
86417 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
86418 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
86419 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
86420 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
86421 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
86422 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
86423 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
86424 +read_vmcore_26501 read_vmcore 3 26501 NULL
86425 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
86426 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
86427 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
86428 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
86429 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
86430 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
86431 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
86432 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
86433 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
86434 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
86435 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
86436 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
86437 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
86438 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
86439 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
86440 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
86441 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
86442 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
86443 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
86444 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
86445 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
86446 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
86447 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
86448 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
86449 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
86450 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
86451 +fd_copyout_59323 fd_copyout 3 59323 NULL
86452 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
86453 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
86454 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
86455 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
86456 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
86457 +solos_param_store_34755 solos_param_store 4 34755 NULL
86458 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
86459 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
86460 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
86461 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
86462 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
86463 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
86464 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
86465 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
86466 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
86467 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
86468 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
86469 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
86470 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
86471 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
86472 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
86473 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
86474 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
86475 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
86476 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
86477 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
86478 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
86479 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
86480 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
86481 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
86482 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
86483 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
86484 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
86485 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
86486 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
86487 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
86488 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
86489 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
86490 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
86491 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
86492 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
86493 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
86494 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
86495 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
86496 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
86497 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
86498 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
86499 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
86500 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
86501 +tipc_send_51238 tipc_send 4 51238 NULL
86502 +drm_property_create_51239 drm_property_create 4 51239 NULL
86503 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
86504 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
86505 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
86506 +audit_expand_2098 audit_expand 2 2098 NULL
86507 +st_read_51251 st_read 3 51251 NULL
86508 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
86509 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
86510 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
86511 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
86512 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
86513 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
86514 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
86515 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
86516 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
86517 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
86518 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
86519 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
86520 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
86521 +c4_add_card_54968 c4_add_card 3 54968 NULL
86522 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
86523 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
86524 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
86525 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
86526 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
86527 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
86528 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
86529 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
86530 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
86531 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
86532 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
86533 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
86534 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
86535 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
86536 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
86537 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
86538 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
86539 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
86540 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
86541 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
86542 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
86543 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
86544 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
86545 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
86546 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
86547 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
86548 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
86549 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
86550 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
86551 +debug_output_18575 debug_output 3 18575 NULL
86552 +Realloc_34961 Realloc 2 34961 NULL
86553 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
86554 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
86555 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
86556 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
86557 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
86558 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
86559 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
86560 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
86561 +vhci_write_2224 vhci_write 3 2224 NULL
86562 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
86563 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
86564 +rb_alloc_3102 rb_alloc 1 3102 NULL
86565 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
86566 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
86567 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
86568 +write_pbl_59583 write_pbl 4 59583 NULL
86569 +from_buffer_18625 from_buffer 3 18625 NULL
86570 +uio_write_43202 uio_write 3 43202 NULL
86571 +memdup_user_59590 memdup_user 2 59590 NULL
86572 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
86573 +iso_callback_43208 iso_callback 3 43208 NULL
86574 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
86575 +smk_write_load_26829 smk_write_load 3 26829 NULL
86576 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
86577 +do_update_counters_2259 do_update_counters 4 2259 NULL
86578 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
86579 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
86580 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
86581 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
86582 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
86583 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
86584 +mtrr_write_59622 mtrr_write 3 59622 NULL
86585 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
86586 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
86587 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
86588 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
86589 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
86590 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
86591 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
86592 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
86593 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
86594 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
86595 +fixup_leb_43256 fixup_leb 3 43256 NULL
86596 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
86597 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
86598 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
86599 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
86600 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
86601 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
86602 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
86603 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
86604 +evtchn_write_43278 evtchn_write 3 43278 NULL
86605 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
86606 +store_ifalias_35088 store_ifalias 4 35088 NULL
86607 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
86608 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
86609 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
86610 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
86611 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
86612 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
86613 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
86614 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
86615 +capi_write_35104 capi_write 3 35104 NULL nohasharray
86616 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
86617 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
86618 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
86619 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
86620 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
86621 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
86622 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
86623 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
86624 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
86625 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
86626 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
86627 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
86628 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
86629 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
86630 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
86631 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
86632 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
86633 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
86634 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
86635 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
86636 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
86637 +do_trimming_26952 do_trimming 3 26952 NULL
86638 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
86639 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
86640 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
86641 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
86642 +alloc_buf_34532 alloc_buf 1 34532 NULL
86643 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
86644 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
86645 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
86646 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
86647 +otp_read_10594 otp_read 2-4-5 10594 NULL
86648 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
86649 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
86650 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
86651 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
86652 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
86653 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
86654 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
86655 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
86656 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
86657 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
86658 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
86659 +venus_remove_59781 venus_remove 4 59781 NULL
86660 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
86661 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
86662 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
86663 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
86664 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
86665 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
86666 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
86667 +xenfb_write_43412 xenfb_write 3 43412 NULL
86668 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
86669 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
86670 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
86671 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
86672 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
86673 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
86674 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
86675 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
86676 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
86677 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
86678 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
86679 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
86680 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
86681 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
86682 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
86683 +cmd_complete_51629 cmd_complete 6 51629 NULL
86684 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
86685 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
86686 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
86687 +set_fd_set_35249 set_fd_set 1 35249 NULL
86688 +wiphy_new_2482 wiphy_new 2 2482 NULL
86689 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
86690 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
86691 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
86692 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
86693 +tcp_push_10680 tcp_push 3 10680 NULL
86694 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
86695 +c101_run_37279 c101_run 2 37279 NULL
86696 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
86697 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
86698 +tun_put_user_59849 tun_put_user 4 59849 NULL
86699 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
86700 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
86701 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
86702 +dm_write_2513 dm_write 3 2513 NULL
86703 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
86704 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
86705 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
86706 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
86707 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
86708 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
86709 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
86710 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
86711 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
86712 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
86713 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
86714 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
86715 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
86716 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
86717 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
86718 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
86719 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
86720 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
86721 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
86722 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
86723 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
86724 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
86725 +sel_write_access_51704 sel_write_access 3 51704 NULL
86726 +sys_syslog_10746 sys_syslog 3 10746 NULL
86727 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
86728 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
86729 +do_readlink_43518 do_readlink 2 43518 NULL
86730 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
86731 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
86732 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
86733 +read_file_reset_52310 read_file_reset 3 52310 NULL
86734 +pms_capture_27142 pms_capture 4 27142 NULL
86735 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
86736 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
86737 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
86738 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
86739 +msg_set_51725 msg_set 3 51725 NULL
86740 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
86741 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
86742 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
86743 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
86744 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
86745 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
86746 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
86747 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
86748 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
86749 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
86750 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
86751 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
86752 +sys_bind_10799 sys_bind 3 10799 NULL
86753 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
86754 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
86755 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
86756 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
86757 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
86758 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
86759 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
86760 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
86761 +send_command_10832 send_command 4 10832 NULL
86762 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
86763 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
86764 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
86765 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
86766 +proc_read_43614 proc_read 3 43614 NULL
86767 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
86768 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
86769 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
86770 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
86771 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
86772 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
86773 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
86774 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
86775 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
86776 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
86777 +vmalloc_15464 vmalloc 1 15464 NULL
86778 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
86779 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
86780 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
86781 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
86782 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
86783 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
86784 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
86785 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
86786 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
86787 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
86788 +adu_write_30487 adu_write 3 30487 NULL
86789 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
86790 +get_scq_10897 get_scq 2 10897 NULL
86791 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
86792 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
86793 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
86794 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
86795 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
86796 +load_module_60056 load_module 2 60056 NULL nohasharray
86797 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
86798 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
86799 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
86800 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
86801 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
86802 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
86803 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
86804 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
86805 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
86806 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
86807 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
86808 +user_read_51881 user_read 3 51881 NULL
86809 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
86810 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
86811 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
86812 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
86813 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
86814 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
86815 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
86816 +async_setkey_35521 async_setkey 3 35521 NULL
86817 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
86818 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
86819 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
86820 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
86821 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
86822 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
86823 +add_tty_40055 add_tty 1 40055 NULL nohasharray
86824 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
86825 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
86826 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
86827 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
86828 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
86829 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
86830 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
86831 +alloc_context_3194 alloc_context 1 3194 NULL
86832 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
86833 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
86834 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
86835 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
86836 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
86837 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
86838 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
86839 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
86840 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
86841 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
86842 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
86843 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
86844 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
86845 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
86846 +init_state_60165 init_state 2 60165 NULL
86847 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
86848 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
86849 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
86850 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
86851 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
86852 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
86853 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
86854 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
86855 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
86856 +calc_hmac_32010 calc_hmac 3 32010 NULL
86857 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
86858 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
86859 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
86860 +kernel_readv_35617 kernel_readv 3 35617 NULL
86861 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
86862 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
86863 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
86864 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
86865 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
86866 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
86867 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
86868 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
86869 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
86870 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
86871 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
86872 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
86873 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
86874 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
86875 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
86876 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
86877 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
86878 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
86879 +store_debug_level_35652 store_debug_level 3 35652 NULL
86880 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
86881 +read_flush_43851 read_flush 3 43851 NULL
86882 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
86883 +cmm_write_2896 cmm_write 3 2896 NULL
86884 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
86885 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
86886 +tunables_write_59563 tunables_write 3 59563 NULL
86887 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
86888 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
86889 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
86890 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
86891 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
86892 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
86893 +dm_table_create_35687 dm_table_create 3 35687 NULL
86894 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
86895 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
86896 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
86897 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
86898 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
86899 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
86900 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
86901 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
86902 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
86903 +debug_read_19322 debug_read 3 19322 NULL
86904 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
86905 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
86906 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
86907 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
86908 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
86909 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
86910 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
86911 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
86912 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
86913 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
86914 +doc_probe_23285 doc_probe 1 23285 NULL
86915 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
86916 +SendString_43928 SendString 3 43928 NULL
86917 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
86918 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
86919 +retry_count_read_52129 retry_count_read 3 52129 NULL
86920 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
86921 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
86922 +read_zero_19366 read_zero 3 19366 NULL
86923 +bch_alloc_4593 bch_alloc 1 4593 NULL
86924 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
86925 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
86926 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
86927 +raid5_resize_63306 raid5_resize 2 63306 NULL
86928 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
86929 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
86930 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
86931 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
86932 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
86933 +depth_write_3021 depth_write 3 3021 NULL
86934 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
86935 +read_file_stations_35795 read_file_stations 3 35795 NULL
86936 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
86937 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
86938 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
86939 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
86940 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
86941 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
86942 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
86943 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
86944 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
86945 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
86946 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
86947 +driver_names_read_60399 driver_names_read 3 60399 NULL
86948 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
86949 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
86950 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
86951 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
86952 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
86953 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
86954 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
86955 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
86956 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
86957 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
86958 +rx_data_60442 rx_data 4 60442 NULL
86959 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
86960 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
86961 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
86962 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
86963 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
86964 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
86965 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
86966 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
86967 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
86968 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
86969 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
86970 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
86971 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
86972 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
86973 +construct_key_11329 construct_key 3 11329 NULL
86974 +evm_write_key_27715 evm_write_key 3 27715 NULL
86975 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
86976 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
86977 +filldir_55137 filldir 3 55137 NULL
86978 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
86979 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
86980 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
86981 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
86982 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
86983 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
86984 +sel_write_create_11353 sel_write_create 3 11353 NULL
86985 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
86986 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
86987 +hwflags_read_52318 hwflags_read 3 52318 NULL
86988 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
86989 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
86990 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
86991 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
86992 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
86993 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
86994 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
86995 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
86996 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
86997 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
86998 +nfsd_read_19568 nfsd_read 5 19568 NULL
86999 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
87000 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
87001 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
87002 +kcalloc_27770 kcalloc 1-2 27770 NULL
87003 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
87004 +bm_status_read_19583 bm_status_read 3 19583 NULL
87005 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
87006 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
87007 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
87008 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
87009 +acl_alloc_35979 acl_alloc 1 35979 NULL
87010 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
87011 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
87012 +str_to_user_11411 str_to_user 2 11411 NULL
87013 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
87014 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
87015 +trace_options_read_11419 trace_options_read 3 11419 NULL
87016 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
87017 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
87018 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
87019 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
87020 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
87021 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
87022 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
87023 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
87024 +console_store_36007 console_store 4 36007 NULL
87025 +bttv_read_11432 bttv_read 3 11432 NULL
87026 +key_key_read_3241 key_key_read 3 3241 NULL
87027 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
87028 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
87029 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
87030 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
87031 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
87032 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
87033 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
87034 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
87035 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
87036 +um_idi_write_18293 um_idi_write 3 18293 NULL
87037 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
87038 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
87039 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
87040 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
87041 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
87042 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
87043 +sys_init_module_36047 sys_init_module 2 36047 NULL
87044 +read_profile_27859 read_profile 3 27859 NULL
87045 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
87046 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
87047 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
87048 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
87049 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
87050 +refill_pool_19477 refill_pool 2 19477 NULL
87051 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
87052 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
87053 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
87054 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
87055 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
87056 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
87057 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
87058 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
87059 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
87060 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
87061 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
87062 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
87063 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
87064 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
87065 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
87066 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
87067 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
87068 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
87069 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
87070 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
87071 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
87072 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
87073 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
87074 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
87075 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
87076 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
87077 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
87078 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
87079 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
87080 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
87081 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
87082 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
87083 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
87084 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
87085 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
87086 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
87087 +init_data_container_60709 init_data_container 1 60709 NULL
87088 +p9_client_read_19750 p9_client_read 5 19750 NULL
87089 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
87090 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
87091 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
87092 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
87093 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
87094 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
87095 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
87096 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
87097 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
87098 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
87099 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
87100 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
87101 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
87102 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
87103 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
87104 +send_stream_3397 send_stream 4 3397 NULL
87105 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
87106 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
87107 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
87108 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
87109 +msix_map_region_3411 msix_map_region 3 3411 NULL
87110 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
87111 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
87112 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
87113 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
87114 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
87115 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
87116 +opticon_write_60775 opticon_write 4 60775 NULL
87117 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
87118 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
87119 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
87120 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
87121 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
87122 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
87123 +vip_read_19832 vip_read 3 19832 NULL
87124 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
87125 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
87126 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
87127 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
87128 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
87129 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
87130 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
87131 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
87132 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
87133 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
87134 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
87135 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
87136 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
87137 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
87138 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
87139 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
87140 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
87141 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
87142 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
87143 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
87144 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
87145 +split_11691 split 2 11691 NULL
87146 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
87147 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
87148 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
87149 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
87150 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
87151 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
87152 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
87153 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
87154 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
87155 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
87156 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
87157 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
87158 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
87159 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
87160 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
87161 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
87162 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
87163 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
87164 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
87165 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
87166 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
87167 +spidev_write_44510 spidev_write 3 44510 NULL
87168 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
87169 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
87170 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
87171 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
87172 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
87173 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
87174 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
87175 +kone_receive_4690 kone_receive 4 4690 NULL
87176 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
87177 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
87178 +evtchn_read_3569 evtchn_read 3 3569 NULL
87179 +video_read_28148 video_read 3 28148 NULL
87180 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
87181 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
87182 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
87183 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
87184 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
87185 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
87186 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
87187 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
87188 +vc_resize_3585 vc_resize 2-3 3585 NULL
87189 +gluebi_write_27905 gluebi_write 3 27905 NULL
87190 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
87191 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
87192 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
87193 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
87194 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
87195 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
87196 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
87197 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
87198 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
87199 +pti_char_write_60960 pti_char_write 3 60960 NULL
87200 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
87201 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
87202 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
87203 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
87204 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
87205 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
87206 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
87207 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
87208 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
87209 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
87210 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
87211 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
87212 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
87213 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
87214 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
87215 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
87216 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
87217 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
87218 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
87219 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
87220 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
87221 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
87222 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
87223 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
87224 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
87225 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
87226 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
87227 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
87228 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
87229 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
87230 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
87231 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
87232 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
87233 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
87234 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
87235 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
87236 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
87237 +symtab_init_61050 symtab_init 2 61050 NULL
87238 +team_options_register_20091 team_options_register 3 20091 NULL
87239 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
87240 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
87241 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
87242 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
87243 +mpi_resize_44674 mpi_resize 2 44674 NULL
87244 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
87245 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
87246 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
87247 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
87248 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
87249 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
87250 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
87251 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
87252 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
87253 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
87254 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
87255 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
87256 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
87257 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
87258 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
87259 +pms_read_53873 pms_read 3 53873 NULL
87260 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
87261 +get_derived_key_61100 get_derived_key 4 61100 NULL
87262 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
87263 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
87264 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
87265 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
87266 +dm_read_15674 dm_read 3 15674 NULL
87267 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
87268 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
87269 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
87270 +kone_send_63435 kone_send 4 63435 NULL
87271 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
87272 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
87273 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
87274 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
87275 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
87276 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
87277 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
87278 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
87279 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
87280 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
87281 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
87282 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
87283 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
87284 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
87285 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
87286 +send_packet_52960 send_packet 4 52960 NULL
87287 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
87288 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
87289 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
87290 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
87291 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
87292 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
87293 +put_cmsg_36589 put_cmsg 4 36589 NULL
87294 +__vmalloc_61168 __vmalloc 1 61168 NULL
87295 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
87296 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
87297 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
87298 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
87299 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
87300 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
87301 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
87302 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
87303 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
87304 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
87305 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
87306 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
87307 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
87308 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
87309 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
87310 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
87311 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
87312 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
87313 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
87314 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
87315 +get_fd_set_3866 get_fd_set 1 3866 NULL
87316 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
87317 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
87318 +unlink_queued_645 unlink_queued 3-4 645 NULL
87319 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
87320 +sisusb_write_44834 sisusb_write 3 44834 NULL
87321 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
87322 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
87323 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
87324 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
87325 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
87326 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
87327 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
87328 +nvram_write_3894 nvram_write 3 3894 NULL
87329 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
87330 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
87331 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
87332 +vcs_write_3910 vcs_write 3 3910 NULL
87333 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
87334 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
87335 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
87336 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
87337 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
87338 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
87339 +do_tty_write_44896 do_tty_write 5 44896 NULL
87340 +set_powered_12129 set_powered 4 12129 NULL
87341 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
87342 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
87343 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
87344 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
87345 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
87346 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
87347 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
87348 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
87349 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
87350 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
87351 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
87352 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
87353 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
87354 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
87355 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
87356 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
87357 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
87358 +gather_array_56641 gather_array 3 56641 NULL
87359 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
87360 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
87361 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
87362 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
87363 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
87364 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
87365 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
87366 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
87367 +do_add_counters_3992 do_add_counters 3 3992 NULL
87368 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
87369 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
87370 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
87371 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
87372 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
87373 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
87374 +mei_write_4005 mei_write 3 4005 NULL
87375 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
87376 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
87377 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
87378 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
87379 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
87380 +receive_copy_12216 receive_copy 3 12216 NULL
87381 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
87382 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
87383 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
87384 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
87385 +change_xattr_61390 change_xattr 5 61390 NULL
87386 +find_skb_20431 find_skb 2 20431 NULL
87387 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
87388 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
87389 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
87390 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
87391 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
87392 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
87393 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
87394 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
87395 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
87396 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
87397 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
87398 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
87399 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
87400 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
87401 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
87402 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
87403 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
87404 +read_buf_20469 read_buf 2 20469 NULL
87405 +cm_write_36858 cm_write 3 36858 NULL
87406 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
87407 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
87408 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
87409 +sel_write_user_45060 sel_write_user 3 45060 NULL
87410 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
87411 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
87412 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
87413 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
87414 +fast_user_write_20494 fast_user_write 5 20494 NULL
87415 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
87416 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
87417 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
87418 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
87419 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
87420 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
87421 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
87422 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
87423 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
87424 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
87425 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
87426 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
87427 +osst_read_40237 osst_read 3 40237 NULL
87428 +tm6000_read_4151 tm6000_read 3 4151 NULL
87429 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
87430 +usbdev_read_45114 usbdev_read 3 45114 NULL
87431 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
87432 +spi_execute_28736 spi_execute 5 28736 NULL
87433 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
87434 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
87435 +get_alua_req_4166 get_alua_req 3 4166 NULL
87436 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
87437 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
87438 +venus_create_20555 venus_create 4 20555 NULL
87439 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
87440 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
87441 +receive_packet_12367 receive_packet 2 12367 NULL
87442 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
87443 +mem_write_22232 mem_write 3 22232 NULL
87444 +read_file_bool_4180 read_file_bool 3 4180 NULL
87445 +send_to_tty_45141 send_to_tty 3 45141 NULL
87446 +fops_read_40672 fops_read 3 40672 NULL
87447 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
87448 +write_leb_36957 write_leb 5 36957 NULL
87449 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
87450 +device_write_45156 device_write 3 45156 NULL
87451 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
87452 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
87453 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
87454 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
87455 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
87456 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
87457 +isp1760_register_628 isp1760_register 1-2 628 NULL
87458 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
87459 +lirc_write_20604 lirc_write 3 20604 NULL
87460 +sel_write_member_28800 sel_write_member 3 28800 NULL
87461 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
87462 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
87463 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
87464 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
87465 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
87466 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
87467 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
87468 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
87469 +setxattr_37006 setxattr 4 37006 NULL
87470 +add_child_45201 add_child 4 45201 NULL
87471 +seq_open_private_61589 seq_open_private 3 61589 NULL
87472 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
87473 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
87474 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
87475 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
87476 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
87477 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
87478 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
87479 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
87480 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
87481 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
87482 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
87483 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
87484 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
87485 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
87486 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
87487 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
87488 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
87489 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
87490 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
87491 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
87492 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
87493 +resize_stripes_61650 resize_stripes 2 61650 NULL
87494 +n2_run_53459 n2_run 3 53459 NULL
87495 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
87496 +parse_command_37079 parse_command 2 37079 NULL
87497 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
87498 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
87499 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
87500 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
87501 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
87502 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
87503 +insert_one_name_61668 insert_one_name 7 61668 NULL
87504 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
87505 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
87506 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
87507 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
87508 +lock_loop_61681 lock_loop 1 61681 NULL
87509 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
87510 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
87511 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
87512 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
87513 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
87514 +push_rx_28939 push_rx 3 28939 NULL
87515 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
87516 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
87517 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
87518 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
87519 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
87520 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
87521 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
87522 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
87523 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
87524 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
87525 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
87526 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
87527 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
87528 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
87529 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
87530 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
87531 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
87532 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
87533 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
87534 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
87535 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
87536 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
87537 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
87538 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
87539 +bin_uuid_28999 bin_uuid 3 28999 NULL
87540 +sys_sendto_20809 sys_sendto 6 20809 NULL
87541 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
87542 +set_registers_53582 set_registers 3 53582 NULL
87543 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
87544 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
87545 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
87546 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
87547 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
87548 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
87549 +keymap_store_45406 keymap_store 4 45406 NULL
87550 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
87551 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
87552 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
87553 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
87554 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
87555 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
87556 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
87557 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
87558 +__do_replace_37227 __do_replace 5 37227 NULL
87559 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
87560 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
87561 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
87562 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
87563 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
87564 +tso_fragment_29050 tso_fragment 3 29050 NULL
87565 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
87566 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
87567 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
87568 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
87569 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
87570 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
87571 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
87572 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
87573 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
87574 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
87575 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
87576 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
87577 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
87578 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
87579 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
87580 +set_link_security_4502 set_link_security 4 4502 NULL
87581 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
87582 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
87583 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
87584 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
87585 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
87586 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
87587 +mmio_read_40348 mmio_read 4 40348 NULL
87588 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
87589 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
87590 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
87591 +ivtv_write_12721 ivtv_write 3 12721 NULL
87592 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
87593 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
87594 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
87595 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
87596 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
87597 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
87598 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
87599 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
87600 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
87601 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
87602 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
87603 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
87604 +send_msg_37323 send_msg 4 37323 NULL
87605 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
87606 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
87607 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
87608 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
87609 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
87610 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
87611 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
87612 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
87613 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
87614 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
87615 +reshape_ring_29147 reshape_ring 2 29147 NULL
87616 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
87617 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
87618 +copy_macs_45534 copy_macs 4 45534 NULL
87619 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
87620 +listxattr_12769 listxattr 3 12769 NULL
87621 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
87622 +wdm_write_53735 wdm_write 3 53735 NULL
87623 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
87624 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
87625 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
87626 +mempool_create_29437 mempool_create 1 29437 NULL
87627 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
87628 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
87629 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
87630 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
87631 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
87632 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
87633 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
87634 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
87635 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
87636 +mgmt_event_12810 mgmt_event 4 12810 NULL
87637 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
87638 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
87639 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
87640 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
87641 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
87642 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
87643 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
87644 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
87645 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
87646 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
87647 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
87648 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
87649 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
87650 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
87651 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
87652 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
87653 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
87654 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
87655 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
87656 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
87657 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
87658 +recover_peb_29238 recover_peb 6-7 29238 NULL
87659 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
87660 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
87661 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
87662 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
87663 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
87664 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
87665 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
87666 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
87667 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
87668 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
87669 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
87670 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
87671 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
87672 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
87673 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
87674 +do_pselect_62061 do_pselect 1 62061 NULL
87675 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
87676 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
87677 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
87678 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
87679 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
87680 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
87681 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
87682 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
87683 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
87684 +sg_read_25799 sg_read 3 25799 NULL
87685 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
87686 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
87687 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
87688 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
87689 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
87690 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
87691 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
87692 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
87693 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
87694 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
87695 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
87696 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
87697 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
87698 +new_skb_21148 new_skb 1 21148 NULL
87699 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
87700 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
87701 +bm_status_write_12964 bm_status_write 3 12964 NULL
87702 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
87703 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
87704 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
87705 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
87706 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
87707 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
87708 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
87709 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
87710 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
87711 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
87712 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
87713 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
87714 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
87715 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
87716 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
87717 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
87718 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
87719 +video_usercopy_62151 video_usercopy 2 62151 NULL
87720 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
87721 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
87722 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
87723 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
87724 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
87725 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
87726 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
87727 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
87728 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
87729 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
87730 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
87731 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
87732 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
87733 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
87734 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
87735 +input_ff_create_21240 input_ff_create 2 21240 NULL
87736 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
87737 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
87738 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
87739 +amthi_read_45831 amthi_read 4 45831 NULL
87740 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
87741 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
87742 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
87743 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
87744 +sys_ipc_4889 sys_ipc 3 4889 NULL
87745 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
87746 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
87747 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
87748 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
87749 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
87750 +do_register_entry_29478 do_register_entry 4 29478 NULL
87751 +isdn_write_45863 isdn_write 3 45863 NULL
87752 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
87753 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
87754 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
87755 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
87756 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
87757 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
87758 +_malloc_54077 _malloc 1 54077 NULL
87759 +add_res_range_21310 add_res_range 4 21310 NULL
87760 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
87761 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
87762 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
87763 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
87764 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
87765 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
87766 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
87767 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
87768 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
87769 +create_xattr_54106 create_xattr 5 54106 NULL
87770 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
87771 +ep_write_59008 ep_write 3 59008 NULL
87772 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
87773 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
87774 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
87775 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
87776 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
87777 +alloc_mr_45935 alloc_mr 1 45935 NULL
87778 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
87779 +isku_receive_54130 isku_receive 4 54130 NULL
87780 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
87781 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
87782 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
87783 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
87784 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
87785 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
87786 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
87787 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
87788 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
87789 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
87790 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
87791 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
87792 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
87793 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
87794 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
87795 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
87796 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
87797 +comedi_read_13199 comedi_read 3 13199 NULL
87798 +flash_write_62354 flash_write 3 62354 NULL
87799 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
87800 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
87801 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
87802 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
87803 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
87804 +proc_file_read_53905 proc_file_read 3 53905 NULL
87805 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
87806 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
87807 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
87808 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
87809 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
87810 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
87811 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
87812 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
87813 +cru_detect_11272 cru_detect 1 11272 NULL
87814 +altera_irscan_62396 altera_irscan 2 62396 NULL
87815 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
87816 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
87817 +fw_download_code_13249 fw_download_code 3 13249 NULL
87818 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
87819 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
87820 +set_ssp_62411 set_ssp 4 62411 NULL
87821 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
87822 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
87823 +get_free_entries_46030 get_free_entries 1 46030 NULL
87824 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
87825 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
87826 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
87827 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
87828 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
87829 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
87830 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
87831 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
87832 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
87833 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
87834 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
87835 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
87836 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
87837 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
87838 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
87839 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
87840 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
87841 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
87842 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
87843 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
87844 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
87845 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
87846 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
87847 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
87848 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
87849 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
87850 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
87851 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
87852 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
87853 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
87854 +probes_write_29711 probes_write 3 29711 NULL
87855 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
87856 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
87857 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
87858 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
87859 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
87860 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
87861 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
87862 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
87863 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
87864 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
87865 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
87866 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
87867 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
87868 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
87869 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
87870 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
87871 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
87872 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
87873 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
87874 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
87875 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
87876 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
87877 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
87878 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
87879 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
87880 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
87881 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
87882 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
87883 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
87884 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
87885 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
87886 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
87887 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
87888 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
87889 +isdn_read_50021 isdn_read 3 50021 NULL
87890 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
87891 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
87892 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
87893 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
87894 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
87895 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
87896 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
87897 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
87898 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
87899 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
87900 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
87901 +get_subdir_62581 get_subdir 3 62581 NULL
87902 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
87903 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
87904 +vfs_readv_38011 vfs_readv 3 38011 NULL
87905 +keyring_read_13438 keyring_read 3 13438 NULL
87906 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
87907 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
87908 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
87909 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
87910 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
87911 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
87912 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
87913 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
87914 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
87915 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
87916 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
87917 +ftrace_write_29551 ftrace_write 3 29551 NULL
87918 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
87919 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
87920 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
87921 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
87922 +dev_write_7708 dev_write 3 7708 NULL
87923 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
87924 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
87925 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
87926 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
87927 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
87928 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
87929 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
87930 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
87931 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
87932 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
87933 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
87934 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
87935 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
87936 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
87937 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
87938 +bm_init_13529 bm_init 2 13529 NULL
87939 +check586_29914 check586 2 29914 NULL
87940 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
87941 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
87942 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
87943 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
87944 +pg_read_17276 pg_read 3 17276 NULL
87945 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
87946 +ep0_read_38095 ep0_read 3 38095 NULL
87947 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
87948 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
87949 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
87950 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
87951 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
87952 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
87953 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
87954 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
87955 +l2down_create_21755 l2down_create 4 21755 NULL
87956 +alloc_tio_13564 alloc_tio 3 13564 NULL
87957 +viacam_read_54526 viacam_read 3 54526 NULL
87958 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
87959 +tunables_read_36385 tunables_read 3 36385 NULL
87960 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
87961 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
87962 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
87963 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
87964 +setsockopt_54539 setsockopt 5 54539 NULL
87965 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
87966 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
87967 +tty_register_device_4544 tty_register_device 2 4544 NULL
87968 +cache_write_13589 cache_write 3 13589 NULL
87969 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
87970 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
87971 +key_replays_read_62746 key_replays_read 3 62746 NULL
87972 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
87973 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
87974 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
87975 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
87976 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
87977 +cdev_add_38176 cdev_add 2-3 38176 NULL
87978 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
87979 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
87980 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
87981 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
87982 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
87983 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
87984 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
87985 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
87986 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
87987 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
87988 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
87989 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
87990 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
87991 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
87992 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
87993 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
87994 +packet_snd_13634 packet_snd 3 13634 NULL
87995 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
87996 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
87997 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
87998 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
87999 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
88000 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
88001 +drp_wmove_30043 drp_wmove 4 30043 NULL
88002 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
88003 +cache_downcall_13666 cache_downcall 3 13666 NULL
88004 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
88005 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
88006 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
88007 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
88008 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
88009 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
88010 +tty_write_5494 tty_write 3 5494 NULL
88011 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
88012 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
88013 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
88014 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
88015 +teiup_create_43201 teiup_create 3 43201 NULL
88016 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
88017 +filldir64_46469 filldir64 3 46469 NULL
88018 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
88019 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
88020 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
88021 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
88022 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
88023 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
88024 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
88025 +spidev_message_5518 spidev_message 3 5518 NULL
88026 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
88027 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
88028 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
88029 +evm_read_key_54674 evm_read_key 3 54674 NULL
88030 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
88031 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
88032 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
88033 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
88034 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
88035 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
88036 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
88037 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
88038 +u32_array_read_2219 u32_array_read 3 2219 NULL
88039 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
88040 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
88041 +sys_add_key_61288 sys_add_key 4 61288 NULL
88042 +kmsg_read_46514 kmsg_read 3 46514 NULL
88043 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
88044 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
88045 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
88046 +recv_stream_30138 recv_stream 4 30138 NULL
88047 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
88048 +getdqbuf_62908 getdqbuf 1 62908 NULL
88049 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
88050 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
88051 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
88052 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
88053 +fir16_create_5574 fir16_create 3 5574 NULL
88054 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
88055 +pt_write_40159 pt_write 3 40159 NULL
88056 +bioset_create_5580 bioset_create 1 5580 NULL
88057 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
88058 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
88059 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
88060 +kzalloc_54740 kzalloc 1 54740 NULL
88061 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
88062 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
88063 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
88064 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
88065 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
88066 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
88067 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
88068 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
88069 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
88070 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
88071 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
88072 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
88073 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
88074 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
88075 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
88076 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
88077 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
88078 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
88079 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
88080 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
88081 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
88082 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
88083 +ti_recv_22027 ti_recv 4 22027 NULL
88084 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
88085 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
88086 +nfsd_write_54809 nfsd_write 6 54809 NULL
88087 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
88088 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
88089 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
88090 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
88091 +get_skb_63008 get_skb 2 63008 NULL
88092 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
88093 +netlink_send_38434 netlink_send 5 38434 NULL
88094 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
88095 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
88096 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
88097 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
88098 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
88099 +write_rio_54837 write_rio 3 54837 NULL
88100 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
88101 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
88102 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
88103 +get_arg_5694 get_arg 3 5694 NULL
88104 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
88105 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
88106 +compat_readv_30273 compat_readv 3 30273 NULL
88107 +printer_read_54851 printer_read 3 54851 NULL
88108 +mem_rw_22085 mem_rw 3 22085 NULL
88109 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
88110 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
88111 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
88112 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
88113 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
88114 +unlink1_63059 unlink1 3 63059 NULL
88115 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
88116 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
88117 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
88118 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
88119 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
88120 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
88121 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
88122 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
88123 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
88124 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
88125 +dev_names_read_38509 dev_names_read 3 38509 NULL
88126 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
88127 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
88128 +get_packet_5747 get_packet 3 5747 NULL
88129 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
88130 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
88131 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
88132 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
88133 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
88134 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
88135 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
88136 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
88137 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
88138 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
88139 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
88140 +resource_from_user_30341 resource_from_user 3 30341 NULL
88141 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
88142 +sound_write_5102 sound_write 3 5102 NULL
88143 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
88144 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
88145 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
88146 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
88147 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
88148 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
88149 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
88150 +com90xx_found_13974 com90xx_found 3 13974 NULL
88151 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
88152 +qcam_read_13977 qcam_read 3 13977 NULL
88153 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
88154 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
88155 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
88156 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
88157 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
88158 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
88159 +generic_readlink_32654 generic_readlink 3 32654 NULL
88160 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
88161 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
88162 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
88163 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
88164 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
88165 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
88166 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
88167 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
88168 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
88169 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
88170 +concat_writev_21451 concat_writev 3 21451 NULL
88171 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
88172 +_queue_data_54983 _queue_data 4 54983 NULL
88173 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
88174 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
88175 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
88176 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
88177 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
88178 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
88179 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
88180 +setup_req_5848 setup_req 3 5848 NULL
88181 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
88182 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
88183 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
88184 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
88185 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
88186 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
88187 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
88188 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
88189 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
88190 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
88191 +cma_create_area_38642 cma_create_area 2 38642 NULL
88192 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
88193 +sriov_enable_59689 sriov_enable 2 59689 NULL
88194 +enable_write_30456 enable_write 3 30456 NULL
88195 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
88196 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
88197 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
88198 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
88199 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
88200 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
88201 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
88202 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
88203 +port_show_regs_5904 port_show_regs 3 5904 NULL
88204 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
88205 +ptp_read_63251 ptp_read 4 63251 NULL
88206 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
88207 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
88208 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
88209 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
88210 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
88211 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
88212 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
88213 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
88214 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
88215 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
88216 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
88217 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
88218 +read_dma_55086 read_dma 3 55086 NULL
88219 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
88220 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
88221 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
88222 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
88223 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
88224 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
88225 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
88226 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
88227 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
88228 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
88229 +em_canid_change_14150 em_canid_change 3 14150 NULL
88230 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
88231 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
88232 +fb_write_46924 fb_write 3 46924 NULL
88233 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
88234 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
88235 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
88236 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
88237 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
88238 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
88239 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
88240 +udf_readpages_38761 udf_readpages 4 38761 NULL
88241 +reada_add_block_54247 reada_add_block 2 54247 NULL
88242 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
88243 +proc_info_read_63344 proc_info_read 3 63344 NULL
88244 +pep_indicate_38611 pep_indicate 5 38611 NULL
88245 +set_le_30581 set_le 4 30581 NULL
88246 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
88247 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
88248 +alloc_private_22399 alloc_private 2 22399 NULL
88249 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
88250 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
88251 +zoran_write_22404 zoran_write 3 22404 NULL
88252 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
88253 +idmouse_read_63374 idmouse_read 3 63374 NULL
88254 +queue_reply_22416 queue_reply 3 22416 NULL
88255 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
88256 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
88257 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
88258 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
88259 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
88260 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
88261 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
88262 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
88263 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
88264 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
88265 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
88266 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
88267 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
88268 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
88269 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
88270 +sys_select_38827 sys_select 1 38827 NULL
88271 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
88272 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
88273 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
88274 +direct_entry_38836 direct_entry 3 38836 NULL
88275 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
88276 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
88277 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
88278 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
88279 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
88280 +write_head_30481 write_head 4 30481 NULL
88281 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
88282 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
88283 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
88284 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
88285 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
88286 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
88287 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
88288 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
88289 +agp_remap_30665 agp_remap 2 30665 NULL
88290 +interfaces_38859 interfaces 2 38859 NULL
88291 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
88292 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
88293 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
88294 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
88295 +qc_capture_19298 qc_capture 3 19298 NULL
88296 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
88297 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
88298 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
88299 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
88300 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
88301 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
88302 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
88303 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
88304 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
88305 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
88306 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
88307 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
88308 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
88309 +read_kcore_63488 read_kcore 3 63488 NULL
88310 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
88311 +__skb_cow_39254 __skb_cow 2 39254 NULL
88312 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
88313 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
88314 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
88315 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
88316 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
88317 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
88318 +mousedev_read_47123 mousedev_read 3 47123 NULL
88319 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
88320 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
88321 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
88322 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
88323 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
88324 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
88325 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
88326 +vme_user_read_55338 vme_user_read 3 55338 NULL
88327 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
88328 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
88329 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
88330 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
88331 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
88332 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
88333 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
88334 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
88335 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
88336 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
88337 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
88338 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
88339 +snapshot_read_22601 snapshot_read 3 22601 NULL
88340 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
88341 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
88342 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
88343 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
88344 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
88345 +__send_to_port_55383 __send_to_port 3 55383 NULL
88346 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
88347 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
88348 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
88349 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
88350 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
88351 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
88352 +get_nodes_39012 get_nodes 3 39012 NULL
88353 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
88354 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
88355 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
88356 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
88357 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
88358 +create_subvol_30836 create_subvol 4 30836 NULL
88359 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
88360 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
88361 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
88362 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
88363 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
88364 +read_oldmem_55658 read_oldmem 3 55658 NULL
88365 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
88366 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
88367 +options_write_47243 options_write 3 47243 NULL
88368 +module_alloc_63630 module_alloc 1 63630 NULL
88369 +alloc_skb_55439 alloc_skb 1 55439 NULL
88370 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
88371 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
88372 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
88373 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
88374 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
88375 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
88376 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
88377 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
88378 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
88379 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
88380 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
88381 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
88382 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
88383 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
88384 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
88385 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
88386 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
88387 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
88388 +vbi_read_63673 vbi_read 3 63673 NULL
88389 +tun_get_user_39099 tun_get_user 4 39099 NULL
88390 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
88391 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
88392 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
88393 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
88394 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
88395 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
88396 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
88397 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
88398 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
88399 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
88400 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
88401 +ax25_output_22736 ax25_output 2 22736 NULL
88402 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
88403 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
88404 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
88405 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
88406 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
88407 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
88408 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
88409 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
88410 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
88411 +hid_input_report_32458 hid_input_report 4 32458 NULL
88412 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
88413 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
88414 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
88415 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
88416 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
88417 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
88418 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
88419 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
88420 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
88421 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
88422 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
88423 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
88424 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
88425 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
88426 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
88427 +get_info_55681 get_info 3 55681 NULL
88428 +setkey_14987 setkey 3 14987 NULL
88429 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
88430 +init_list_set_39188 init_list_set 2-3 39188 NULL
88431 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
88432 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
88433 +l2up_create_6430 l2up_create 3 6430 NULL
88434 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
88435 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
88436 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
88437 +add_partition_55588 add_partition 2 55588 NULL
88438 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
88439 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
88440 +depth_read_31112 depth_read 3 31112 NULL
88441 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
88442 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
88443 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
88444 +profile_replace_14652 profile_replace 3 14652 NULL
88445 +vzalloc_47421 vzalloc 1 47421 NULL
88446 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
88447 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
88448 +sys_writev_28384 sys_writev 3 28384 NULL
88449 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
88450 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
88451 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
88452 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
88453 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
88454 +create_attr_set_22861 create_attr_set 1 22861 NULL
88455 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
88456 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
88457 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
88458 +sel_write_load_63830 sel_write_load 3 63830 NULL
88459 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
88460 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
88461 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
88462 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
88463 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
88464 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
88465 +probe_bios_17467 probe_bios 1 17467 NULL
88466 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
88467 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
88468 +mei_read_6507 mei_read 3 6507 NULL
88469 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
88470 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
88471 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
88472 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
88473 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
88474 +SetArea_50835 SetArea 4 50835 NULL
88475 +tpm_read_50344 tpm_read 3 50344 NULL
88476 +newpart_47485 newpart 6 47485 NULL
88477 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
88478 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
88479 +core_sys_select_47494 core_sys_select 1 47494 NULL
88480 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
88481 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
88482 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
88483 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
88484 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
88485 +unlink_simple_47506 unlink_simple 3 47506 NULL
88486 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
88487 +wdm_read_6549 wdm_read 3 6549 NULL
88488 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
88489 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
88490 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
88491 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
88492 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
88493 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
88494 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
88495 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
88496 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
88497 +filter_read_61692 filter_read 3 61692 NULL
88498 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
88499 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
88500 +debugfs_read_62535 debugfs_read 3 62535 NULL
88501 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
88502 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
88503 +divas_write_63901 divas_write 3 63901 NULL
88504 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
88505 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
88506 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
88507 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
88508 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
88509 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
88510 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
88511 +ipw_write_59807 ipw_write 3 59807 NULL
88512 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
88513 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
88514 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
88515 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
88516 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
88517 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
88518 +cycx_setup_47562 cycx_setup 4 47562 NULL
88519 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
88520 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
88521 +set_local_name_55757 set_local_name 4 55757 NULL
88522 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
88523 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
88524 +read_ldt_47570 read_ldt 2 47570 NULL
88525 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
88526 +pci_iomap_47575 pci_iomap 3 47575 NULL
88527 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
88528 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
88529 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
88530 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
88531 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
88532 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
88533 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
88534 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
88535 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
88536 +conf_read_55786 conf_read 3 55786 NULL
88537 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
88538 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
88539 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
88540 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
88541 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
88542 +user_power_read_39414 user_power_read 3 39414 NULL
88543 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
88544 +uea_request_47613 uea_request 4 47613 NULL
88545 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
88546 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
88547 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
88548 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
88549 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
88550 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
88551 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
88552 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
88553 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
88554 +kmemdup_64015 kmemdup 2 64015 NULL
88555 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
88556 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
88557 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
88558 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
88559 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
88560 +oz_events_read_47535 oz_events_read 3 47535 NULL
88561 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
88562 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
88563 +sys_semop_39457 sys_semop 3 39457 NULL
88564 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
88565 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
88566 +update_pmkid_2481 update_pmkid 4 2481 NULL
88567 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
88568 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
88569 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
88570 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
88571 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
88572 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
88573 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
88574 +mpeg_read_6708 mpeg_read 3 6708 NULL
88575 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
88576 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
88577 +sky2_receive_13407 sky2_receive 2 13407 NULL
88578 +krealloc_14908 krealloc 2 14908 NULL
88579 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
88580 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
88581 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
88582 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
88583 +video_proc_write_6724 video_proc_write 3 6724 NULL
88584 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
88585 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
88586 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
88587 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
88588 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
88589 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
88590 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
88591 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
88592 +command_file_write_31318 command_file_write 3 31318 NULL
88593 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
88594 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
88595 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
88596 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
88597 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
88598 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
88599 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
88600 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
88601 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
88602 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
88603 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
88604 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
88605 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
88606 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
88607 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
88608 +int_proc_write_39542 int_proc_write 3 39542 NULL
88609 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
88610 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
88611 +read_file_ani_23161 read_file_ani 3 23161 NULL
88612 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
88613 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
88614 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
88615 +pp_write_39554 pp_write 3 39554 NULL
88616 +ioremap_23172 ioremap 1-2 23172 NULL
88617 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
88618 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
88619 +usblp_write_23178 usblp_write 3 23178 NULL
88620 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
88621 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
88622 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
88623 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
88624 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
88625 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
88626 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
88627 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
88628 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
88629 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
88630 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
88631 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
88632 +__team_options_register_63941 __team_options_register 3 63941 NULL
88633 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
88634 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
88635 +rvmalloc_46873 rvmalloc 1 46873 NULL
88636 +vmap_15025 vmap 2 15025 NULL
88637 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
88638 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
88639 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
88640 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
88641 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
88642 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
88643 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
88644 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
88645 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
88646 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
88647 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
88648 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
88649 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
88650 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
88651 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
88652 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
88653 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
88654 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
88655 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
88656 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
88657 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
88658 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
88659 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
88660 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
88661 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
88662 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
88663 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
88664 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
88665 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
88666 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
88667 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
88668 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
88669 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
88670 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
88671 +alg_setkey_31485 alg_setkey 3 31485 NULL
88672 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
88673 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
88674 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
88675 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
88676 +vhci_read_47878 vhci_read 3 47878 NULL
88677 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
88678 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
88679 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
88680 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
88681 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
88682 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
88683 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
88684 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
88685 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
88686 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
88687 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
88688 +timeout_read_47915 timeout_read 3 47915 NULL
88689 +hidraw_write_31536 hidraw_write 3 31536 NULL
88690 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
88691 +page_readlink_23346 page_readlink 3 23346 NULL
88692 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
88693 +comedi_write_47926 comedi_write 3 47926 NULL
88694 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
88695 +dsp_write_46218 dsp_write 2 46218 NULL
88696 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
88697 +usbvision_read_31555 usbvision_read 3 31555 NULL
88698 +pd_video_read_24510 pd_video_read 3 24510 NULL
88699 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
88700 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
88701 +request_key_async_6990 request_key_async 4 6990 NULL
88702 +ts_write_64336 ts_write 3 64336 NULL
88703 +handle_response_55951 handle_response 5 55951 NULL
88704 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
88705 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
88706 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
88707 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
88708 +osst_write_31581 osst_write 3 31581 NULL
88709 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
88710 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
88711 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
88712 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
88713 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
88714 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
88715 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
88716 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
88717 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
88718 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
88719 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
88720 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
88721 +ilo_write_64378 ilo_write 3 64378 NULL
88722 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
88723 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
88724 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
88725 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
88726 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
88727 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
88728 +copy_from_user_17559 copy_from_user 3 17559 NULL
88729 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
88730 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
88731 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
88732 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
88733 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
88734 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
88735 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
88736 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
88737 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
88738 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
88739 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
88740 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
88741 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
88742 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
88743 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
88744 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
88745 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
88746 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
88747 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
88748 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
88749 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
88750 +__lgread_31668 __lgread 4 31668 NULL
88751 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
88752 +fd_copyin_56247 fd_copyin 3 56247 NULL
88753 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
88754 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
88755 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
88756 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
88757 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
88758 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
88759 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
88760 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
88761 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
88762 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
88763 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
88764 +event_filter_read_23494 event_filter_read 3 23494 NULL
88765 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
88766 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
88767 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
88768 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
88769 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
88770 +pkt_add_39897 pkt_add 3 39897 NULL
88771 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
88772 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
88773 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
88774 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
88775 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
88776 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
88777 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
88778 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
88779 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
88780 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
88781 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
88782 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
88783 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
88784 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
88785 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
88786 +remove_uuid_64505 remove_uuid 4 64505 NULL
88787 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
88788 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
88789 +create_table_16213 create_table 2 16213 NULL
88790 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
88791 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
88792 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
88793 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
88794 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
88795 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
88796 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
88797 +set_discoverable_48141 set_discoverable 4 48141 NULL
88798 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
88799 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
88800 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
88801 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
88802 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
88803 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
88804 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
88805 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
88806 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
88807 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
88808 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
88809 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
88810 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
88811 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
88812 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
88813 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
88814 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
88815 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
88816 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
88817 +dev_read_56369 dev_read 3 56369 NULL
88818 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
88819 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
88820 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
88821 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
88822 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
88823 +init_ipath_48187 init_ipath 1 48187 NULL
88824 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
88825 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
88826 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
88827 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
88828 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
88829 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
88830 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
88831 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
88832 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
88833 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
88834 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
88835 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
88836 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
88837 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
88838 +use_pool_64607 use_pool 2 64607 NULL
88839 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
88840 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
88841 +store_msg_56417 store_msg 3 56417 NULL
88842 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
88843 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
88844 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
88845 +read_file_recv_48232 read_file_recv 3 48232 NULL
88846 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
88847 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
88848 +fanotify_write_64623 fanotify_write 3 64623 NULL
88849 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
88850 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
88851 +fl_create_56435 fl_create 5 56435 NULL
88852 +gnttab_map_56439 gnttab_map 2 56439 NULL
88853 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
88854 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
88855 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
88856 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
88857 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
88858 +set_connectable_56458 set_connectable 4 56458 NULL
88859 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
88860 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
88861 +add_port_54941 add_port 2 54941 NULL
88862 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
88863 +cx18_read_23699 cx18_read 3 23699 NULL
88864 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
88865 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
88866 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
88867 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
88868 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
88869 +send_set_info_48288 send_set_info 7 48288 NULL
88870 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
88871 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
88872 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
88873 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
88874 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
88875 +new_dir_31919 new_dir 3 31919 NULL
88876 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
88877 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
88878 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
88879 +mgmt_control_7349 mgmt_control 3 7349 NULL
88880 +hash_setkey_48310 hash_setkey 3 48310 NULL
88881 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
88882 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
88883 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
88884 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
88885 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
88886 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
88887 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
88888 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
88889 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
88890 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
88891 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
88892 +vb2_write_31948 vb2_write 3 31948 NULL
88893 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
88894 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
88895 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
88896 +ip_options_get_56538 ip_options_get 4 56538 NULL
88897 +write_62671 write 3 62671 NULL
88898 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
88899 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
88900 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
88901 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
88902 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
88903 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
88904 +skb_add_data_48363 skb_add_data 3 48363 NULL
88905 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
88906 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
88907 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
88908 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
88909 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
88910 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
88911 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
88912 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
88913 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
88914 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
88915 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
88916 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
88917 +system_enable_read_25815 system_enable_read 3 25815 NULL
88918 +allocate_probes_40204 allocate_probes 1 40204 NULL
88919 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
88920 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
88921 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
88922 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
88923 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
88924 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
88925 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
88926 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
88927 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
88928 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
88929 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
88930 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
88931 +fs_path_add_15648 fs_path_add 3 15648 NULL
88932 +event_filter_write_56609 event_filter_write 3 56609 NULL
88933 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
88934 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
88935 +xsd_read_15653 xsd_read 3 15653 NULL
88936 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
88937 +p54_init_common_23850 p54_init_common 1 23850 NULL
88938 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
88939 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
88940 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
88941 +garp_request_join_7471 garp_request_join 4 7471 NULL
88942 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
88943 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
88944 +unifi_read_14899 unifi_read 3 14899 NULL
88945 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
88946 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
88947 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
88948 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
88949 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
88950 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
88951 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
88952 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
88953 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
88954 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
88955 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
88956 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
88957 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
88958 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
88959 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
88960 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
88961 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
88962 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
88963 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
88964 +bio_alloc_32095 bio_alloc 2 32095 NULL
88965 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
88966 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
88967 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
88968 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
88969 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
88970 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
88971 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
88972 +send_control_msg_48498 send_control_msg 6 48498 NULL
88973 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
88974 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
88975 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
88976 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
88977 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
88978 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
88979 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
88980 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
88981 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
88982 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
88983 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
88984 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
88985 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
88986 +alloc_tx_32143 alloc_tx 2 32143 NULL
88987 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
88988 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
88989 +hsc_write_55875 hsc_write 3 55875 NULL
88990 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
88991 +do_test_15766 do_test 1 15766 NULL
88992 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
88993 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
88994 +named_distribute_48544 named_distribute 4 48544 NULL
88995 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
88996 +venus_link_32165 venus_link 5 32165 NULL
88997 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
88998 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
88999 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
89000 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
89001 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
89002 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
89003 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
89004 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
89005 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
89006 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
89007 +groups_alloc_7614 groups_alloc 1 7614 NULL
89008 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
89009 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
89010 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
89011 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
89012 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
89013 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
89014 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
89015 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
89016 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
89017 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
89018 +snapshot_write_28351 snapshot_write 3 28351 NULL
89019 +event_enable_read_7074 event_enable_read 3 7074 NULL
89020 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
89021 +do_syslog_56807 do_syslog 3 56807 NULL
89022 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
89023 +pskb_pull_65005 pskb_pull 2 65005 NULL
89024 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
89025 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
89026 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
89027 +unifi_write_65012 unifi_write 3 65012 NULL
89028 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
89029 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
89030 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
89031 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
89032 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
89033 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
89034 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
89035 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
89036 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
89037 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
89038 +if_write_51756 if_write 3 51756 NULL
89039 +insert_dent_65034 insert_dent 7 65034 NULL
89040 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
89041 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
89042 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
89043 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
89044 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
89045 +lc_create_48662 lc_create 3 48662 NULL
89046 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
89047 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
89048 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
89049 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
89050 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
89051 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
89052 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
89053 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
89054 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
89055 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
89056 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
89057 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
89058 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
89059 +altera_drscan_48698 altera_drscan 2 48698 NULL
89060 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
89061 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
89062 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
89063 +power_read_15939 power_read 3 15939 NULL
89064 +recv_msg_48709 recv_msg 4 48709 NULL
89065 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
89066 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
89067 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
89068 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
89069 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
89070 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
89071 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
89072 +revalidate_19043 revalidate 2 19043 NULL
89073 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
89074 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
89075 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
89076 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
89077 +check_header_56930 check_header 2 56930 NULL
89078 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
89079 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
89080 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
89081 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
89082 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
89083 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
89084 +frame_alloc_15981 frame_alloc 4 15981 NULL
89085 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
89086 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
89087 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
89088 +adu_read_24177 adu_read 3 24177 NULL
89089 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
89090 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
89091 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
89092 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
89093 +vfd_write_14717 vfd_write 3 14717 NULL
89094 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
89095 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
89096 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
89097 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
89098 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
89099 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
89100 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
89101 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
89102 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
89103 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
89104 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
89105 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
89106 +register_device_60015 register_device 2-3 60015 NULL
89107 +got_frame_16028 got_frame 2 16028 NULL
89108 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
89109 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
89110 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
89111 +scsi_register_49094 scsi_register 2 49094 NULL
89112 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
89113 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
89114 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
89115 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
89116 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
89117 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
89118 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
89119 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
89120 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
89121 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
89122 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
89123 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
89124 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
89125 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
89126 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
89127 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
89128 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
89129 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
89130 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
89131 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
89132 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
89133 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
89134 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
89135 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
89136 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
89137 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
89138 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
89139 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
89140 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
89141 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
89142 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
89143 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
89144 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
89145 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
89146 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
89147 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
89148 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
89149 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
89150 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
89151 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
89152 +fsm_init_16134 fsm_init 2 16134 NULL
89153 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
89154 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
89155 +disconnect_32521 disconnect 4 32521 NULL
89156 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
89157 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
89158 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
89159 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
89160 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
89161 +ilo_read_32531 ilo_read 3 32531 NULL
89162 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
89163 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
89164 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
89165 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
89166 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
89167 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
89168 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
89169 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
89170 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
89171 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
89172 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
89173 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
89174 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
89175 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
89176 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
89177 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
89178 +card_send_command_40757 card_send_command 3 40757 NULL
89179 +sys_mbind_7990 sys_mbind 5 7990 NULL
89180 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
89181 +pg_write_40766 pg_write 3 40766 NULL
89182 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
89183 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
89184 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
89185 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
89186 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
89187 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
89188 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
89189 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
89190 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
89191 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
89192 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
89193 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
89194 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
89195 +vcs_read_8017 vcs_read 3 8017 NULL
89196 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
89197 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
89198 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
89199 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
89200 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
89201 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
89202 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
89203 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
89204 +copy_and_check_19089 copy_and_check 3 19089 NULL
89205 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
89206 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
89207 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
89208 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
89209 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
89210 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
89211 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
89212 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
89213 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
89214 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
89215 +smk_user_access_24440 smk_user_access 3 24440 NULL
89216 +xd_rw_49020 xd_rw 3-4 49020 NULL
89217 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
89218 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
89219 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
89220 +kvmalloc_32646 kvmalloc 1 32646 NULL
89221 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
89222 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
89223 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
89224 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
89225 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
89226 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
89227 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
89228 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
89229 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
89230 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
89231 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
89232 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
89233 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
89234 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
89235 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
89236 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
89237 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
89238 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
89239 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
89240 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
89241 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
89242 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
89243 +venus_lookup_8121 venus_lookup 4 8121 NULL
89244 +compat_writev_60063 compat_writev 3 60063 NULL
89245 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
89246 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
89247 +read_file_queue_40895 read_file_queue 3 40895 NULL
89248 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
89249 +waiters_read_40902 waiters_read 3 40902 NULL
89250 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
89251 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
89252 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
89253 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
89254 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
89255 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
89256 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
89257 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
89258 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
89259 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
89260 +alloc_dr_65495 alloc_dr 2 65495 NULL
89261 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
89262 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
89263 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
89264 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
89265 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
89266 +rbd_add_16366 rbd_add 3 16366 NULL
89267 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
89268 +pt_read_49136 pt_read 3 49136 NULL
89269 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
89270 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
89271 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
89272 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
89273 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
89274 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
89275 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
89276 new file mode 100644
89277 index 0000000..792ee60
89278 --- /dev/null
89279 +++ b/tools/gcc/size_overflow_plugin.c
89280 @@ -0,0 +1,1930 @@
89281 +/*
89282 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
89283 + * Licensed under the GPL v2, or (at your option) v3
89284 + *
89285 + * Homepage:
89286 + * http://www.grsecurity.net/~ephox/overflow_plugin/
89287 + *
89288 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
89289 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
89290 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
89291 + *
89292 + * Usage:
89293 + * $ 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
89294 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
89295 + */
89296 +
89297 +#include "gcc-plugin.h"
89298 +#include "config.h"
89299 +#include "system.h"
89300 +#include "coretypes.h"
89301 +#include "tree.h"
89302 +#include "tree-pass.h"
89303 +#include "intl.h"
89304 +#include "plugin-version.h"
89305 +#include "tm.h"
89306 +#include "toplev.h"
89307 +#include "function.h"
89308 +#include "tree-flow.h"
89309 +#include "plugin.h"
89310 +#include "gimple.h"
89311 +#include "c-common.h"
89312 +#include "diagnostic.h"
89313 +#include "cfgloop.h"
89314 +
89315 +#if BUILDING_GCC_VERSION >= 4007
89316 +#include "c-tree.h"
89317 +#else
89318 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
89319 +#endif
89320 +
89321 +struct size_overflow_hash {
89322 + const struct size_overflow_hash * const next;
89323 + const char * const name;
89324 + const unsigned int param;
89325 +};
89326 +
89327 +#include "size_overflow_hash.h"
89328 +
89329 +enum marked {
89330 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
89331 +};
89332 +
89333 +static unsigned int call_count = 0;
89334 +
89335 +#define __unused __attribute__((__unused__))
89336 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
89337 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
89338 +#define BEFORE_STMT true
89339 +#define AFTER_STMT false
89340 +#define CREATE_NEW_VAR NULL_TREE
89341 +#define CODES_LIMIT 32
89342 +#define MAX_PARAM 32
89343 +#define MY_STMT GF_PLF_1
89344 +#define NO_CAST_CHECK GF_PLF_2
89345 +
89346 +#if BUILDING_GCC_VERSION == 4005
89347 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
89348 +#endif
89349 +
89350 +int plugin_is_GPL_compatible;
89351 +void debug_gimple_stmt(gimple gs);
89352 +
89353 +static tree expand(struct pointer_set_t *visited, tree lhs);
89354 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
89355 +static tree report_size_overflow_decl;
89356 +static const_tree const_char_ptr_type_node;
89357 +static unsigned int handle_function(void);
89358 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
89359 +static tree get_size_overflow_type(gimple stmt, const_tree node);
89360 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
89361 +
89362 +static struct plugin_info size_overflow_plugin_info = {
89363 + .version = "20130109beta",
89364 + .help = "no-size-overflow\tturn off size overflow checking\n",
89365 +};
89366 +
89367 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
89368 +{
89369 + unsigned int arg_count;
89370 + enum tree_code code = TREE_CODE(*node);
89371 +
89372 + switch (code) {
89373 + case FUNCTION_DECL:
89374 + arg_count = type_num_arguments(TREE_TYPE(*node));
89375 + break;
89376 + case FUNCTION_TYPE:
89377 + case METHOD_TYPE:
89378 + arg_count = type_num_arguments(*node);
89379 + break;
89380 + default:
89381 + *no_add_attrs = true;
89382 + error("%s: %qE attribute only applies to functions", __func__, name);
89383 + return NULL_TREE;
89384 + }
89385 +
89386 + for (; args; args = TREE_CHAIN(args)) {
89387 + tree position = TREE_VALUE(args);
89388 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
89389 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
89390 + *no_add_attrs = true;
89391 + }
89392 + }
89393 + return NULL_TREE;
89394 +}
89395 +
89396 +static const char* get_asm_name(tree node)
89397 +{
89398 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
89399 +}
89400 +
89401 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
89402 +{
89403 + unsigned int arg_count, arg_num;
89404 + enum tree_code code = TREE_CODE(*node);
89405 +
89406 + switch (code) {
89407 + case FUNCTION_DECL:
89408 + arg_count = type_num_arguments(TREE_TYPE(*node));
89409 + break;
89410 + case FUNCTION_TYPE:
89411 + case METHOD_TYPE:
89412 + arg_count = type_num_arguments(*node);
89413 + break;
89414 + case FIELD_DECL:
89415 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
89416 + if (arg_num != 0) {
89417 + *no_add_attrs = true;
89418 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
89419 + }
89420 + return NULL_TREE;
89421 + default:
89422 + *no_add_attrs = true;
89423 + error("%qE attribute only applies to functions", name);
89424 + return NULL_TREE;
89425 + }
89426 +
89427 + for (; args; args = TREE_CHAIN(args)) {
89428 + tree position = TREE_VALUE(args);
89429 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
89430 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
89431 + *no_add_attrs = true;
89432 + }
89433 + }
89434 + return NULL_TREE;
89435 +}
89436 +
89437 +static struct attribute_spec size_overflow_attr = {
89438 + .name = "size_overflow",
89439 + .min_length = 1,
89440 + .max_length = -1,
89441 + .decl_required = true,
89442 + .type_required = false,
89443 + .function_type_required = false,
89444 + .handler = handle_size_overflow_attribute,
89445 +#if BUILDING_GCC_VERSION >= 4007
89446 + .affects_type_identity = false
89447 +#endif
89448 +};
89449 +
89450 +static struct attribute_spec intentional_overflow_attr = {
89451 + .name = "intentional_overflow",
89452 + .min_length = 1,
89453 + .max_length = -1,
89454 + .decl_required = true,
89455 + .type_required = false,
89456 + .function_type_required = false,
89457 + .handler = handle_intentional_overflow_attribute,
89458 +#if BUILDING_GCC_VERSION >= 4007
89459 + .affects_type_identity = false
89460 +#endif
89461 +};
89462 +
89463 +static void register_attributes(void __unused *event_data, void __unused *data)
89464 +{
89465 + register_attribute(&size_overflow_attr);
89466 + register_attribute(&intentional_overflow_attr);
89467 +}
89468 +
89469 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
89470 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
89471 +{
89472 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
89473 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
89474 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
89475 +
89476 + unsigned int m = 0x57559429;
89477 + unsigned int n = 0x5052acdb;
89478 + const unsigned int *key4 = (const unsigned int *)key;
89479 + unsigned int h = len;
89480 + unsigned int k = len + seed + n;
89481 + unsigned long long p;
89482 +
89483 + while (len >= 8) {
89484 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
89485 + len -= 8;
89486 + }
89487 + if (len >= 4) {
89488 + cwmixb(key4[0]) key4 += 1;
89489 + len -= 4;
89490 + }
89491 + if (len)
89492 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
89493 + cwmixb(h ^ (k + n));
89494 + return k ^ h;
89495 +
89496 +#undef cwfold
89497 +#undef cwmixa
89498 +#undef cwmixb
89499 +}
89500 +
89501 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
89502 +{
89503 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
89504 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
89505 + return fn ^ codes;
89506 +}
89507 +
89508 +static inline tree get_original_function_decl(tree fndecl)
89509 +{
89510 + if (DECL_ABSTRACT_ORIGIN(fndecl))
89511 + return DECL_ABSTRACT_ORIGIN(fndecl);
89512 + return fndecl;
89513 +}
89514 +
89515 +static inline gimple get_def_stmt(const_tree node)
89516 +{
89517 + gcc_assert(node != NULL_TREE);
89518 + gcc_assert(TREE_CODE(node) == SSA_NAME);
89519 + return SSA_NAME_DEF_STMT(node);
89520 +}
89521 +
89522 +static unsigned char get_tree_code(const_tree type)
89523 +{
89524 + switch (TREE_CODE(type)) {
89525 + case ARRAY_TYPE:
89526 + return 0;
89527 + case BOOLEAN_TYPE:
89528 + return 1;
89529 + case ENUMERAL_TYPE:
89530 + return 2;
89531 + case FUNCTION_TYPE:
89532 + return 3;
89533 + case INTEGER_TYPE:
89534 + return 4;
89535 + case POINTER_TYPE:
89536 + return 5;
89537 + case RECORD_TYPE:
89538 + return 6;
89539 + case UNION_TYPE:
89540 + return 7;
89541 + case VOID_TYPE:
89542 + return 8;
89543 + case REAL_TYPE:
89544 + return 9;
89545 + case VECTOR_TYPE:
89546 + return 10;
89547 + case REFERENCE_TYPE:
89548 + return 11;
89549 + case OFFSET_TYPE:
89550 + return 12;
89551 + case COMPLEX_TYPE:
89552 + return 13;
89553 + default:
89554 + debug_tree((tree)type);
89555 + gcc_unreachable();
89556 + }
89557 +}
89558 +
89559 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
89560 +{
89561 + gcc_assert(type != NULL_TREE);
89562 +
89563 + while (type && len < CODES_LIMIT) {
89564 + tree_codes[len] = get_tree_code(type);
89565 + len++;
89566 + type = TREE_TYPE(type);
89567 + }
89568 + return len;
89569 +}
89570 +
89571 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
89572 +{
89573 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
89574 + enum tree_code code = TREE_CODE(type);
89575 + size_t len = 0;
89576 +
89577 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
89578 +
89579 + arg = TYPE_ARG_TYPES(type);
89580 + // skip builtins __builtin_constant_p
89581 + if (!arg && DECL_BUILT_IN(fndecl))
89582 + return 0;
89583 +
89584 + if (TREE_CODE_CLASS(code) == tcc_type)
89585 + result = type;
89586 + else
89587 + result = DECL_RESULT(fndecl);
89588 +
89589 + gcc_assert(result != NULL_TREE);
89590 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
89591 +
89592 + if (arg == NULL_TREE) {
89593 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
89594 + arg_field = DECL_ARGUMENT_FLD(fndecl);
89595 + if (arg_field == NULL_TREE)
89596 + return 0;
89597 + arg = TREE_TYPE(arg_field);
89598 + len = add_type_codes(arg, tree_codes, len);
89599 + gcc_assert(len != 0);
89600 + return len;
89601 + }
89602 +
89603 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
89604 + while (arg && len < CODES_LIMIT) {
89605 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
89606 + arg = TREE_CHAIN(arg);
89607 + }
89608 +
89609 + gcc_assert(len != 0);
89610 + return len;
89611 +}
89612 +
89613 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
89614 +{
89615 + unsigned int hash;
89616 + const struct size_overflow_hash *entry;
89617 + unsigned char tree_codes[CODES_LIMIT];
89618 + size_t len;
89619 + const char *func_name = get_asm_name(fndecl);
89620 +
89621 + len = get_function_decl(fndecl, tree_codes);
89622 + if (len == 0)
89623 + return NULL;
89624 +
89625 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
89626 +
89627 + entry = size_overflow_hash[hash];
89628 + while (entry) {
89629 + if (!strcmp(entry->name, func_name))
89630 + return entry;
89631 + entry = entry->next;
89632 + }
89633 +
89634 + return NULL;
89635 +}
89636 +
89637 +static void check_arg_type(const_tree arg)
89638 +{
89639 + const_tree type = TREE_TYPE(arg);
89640 + enum tree_code code = TREE_CODE(type);
89641 +
89642 + if (code == BOOLEAN_TYPE)
89643 + return;
89644 +
89645 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
89646 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
89647 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
89648 +}
89649 +
89650 +static unsigned int find_arg_number(const_tree arg, tree func)
89651 +{
89652 + tree var;
89653 + unsigned int argnum = 1;
89654 +
89655 + if (TREE_CODE(arg) == SSA_NAME)
89656 + arg = SSA_NAME_VAR(arg);
89657 +
89658 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
89659 + if (strcmp(NAME(arg), NAME(var))) {
89660 + argnum++;
89661 + continue;
89662 + }
89663 + check_arg_type(var);
89664 + return argnum;
89665 + }
89666 + gcc_unreachable();
89667 +}
89668 +
89669 +static tree create_new_var(tree type)
89670 +{
89671 + tree new_var = create_tmp_var(type, "cicus");
89672 +
89673 + add_referenced_var(new_var);
89674 + mark_sym_for_renaming(new_var);
89675 + return new_var;
89676 +}
89677 +
89678 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
89679 +{
89680 + gimple assign;
89681 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89682 + tree type = TREE_TYPE(rhs1);
89683 + tree lhs = create_new_var(type);
89684 +
89685 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
89686 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
89687 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
89688 +
89689 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
89690 + update_stmt(assign);
89691 + gimple_set_plf(assign, MY_STMT, true);
89692 + return assign;
89693 +}
89694 +
89695 +static bool is_bool(const_tree node)
89696 +{
89697 + const_tree type;
89698 +
89699 + if (node == NULL_TREE)
89700 + return false;
89701 +
89702 + type = TREE_TYPE(node);
89703 + if (!INTEGRAL_TYPE_P(type))
89704 + return false;
89705 + if (TREE_CODE(type) == BOOLEAN_TYPE)
89706 + return true;
89707 + if (TYPE_PRECISION(type) == 1)
89708 + return true;
89709 + return false;
89710 +}
89711 +
89712 +static tree cast_a_tree(tree type, tree var)
89713 +{
89714 + gcc_assert(type != NULL_TREE);
89715 + gcc_assert(var != NULL_TREE);
89716 + gcc_assert(fold_convertible_p(type, var));
89717 +
89718 + return fold_convert(type, var);
89719 +}
89720 +
89721 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
89722 +{
89723 + gimple assign;
89724 +
89725 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
89726 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
89727 + gcc_unreachable();
89728 +
89729 + if (lhs == CREATE_NEW_VAR)
89730 + lhs = create_new_var(dst_type);
89731 +
89732 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
89733 +
89734 + if (!gsi_end_p(*gsi)) {
89735 + location_t loc = gimple_location(gsi_stmt(*gsi));
89736 + gimple_set_location(assign, loc);
89737 + }
89738 +
89739 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
89740 +
89741 + if (before)
89742 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
89743 + else
89744 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
89745 + update_stmt(assign);
89746 + gimple_set_plf(assign, MY_STMT, true);
89747 +
89748 + return assign;
89749 +}
89750 +
89751 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
89752 +{
89753 + gimple assign;
89754 + gimple_stmt_iterator gsi;
89755 +
89756 + if (rhs == NULL_TREE)
89757 + return NULL_TREE;
89758 +
89759 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
89760 + return rhs;
89761 +
89762 + gsi = gsi_for_stmt(stmt);
89763 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
89764 + gimple_set_plf(assign, MY_STMT, true);
89765 + return gimple_get_lhs(assign);
89766 +}
89767 +
89768 +static tree cast_to_TI_type(gimple stmt, tree node)
89769 +{
89770 + gimple_stmt_iterator gsi;
89771 + gimple cast_stmt;
89772 + tree type = TREE_TYPE(node);
89773 +
89774 + if (types_compatible_p(type, intTI_type_node))
89775 + return node;
89776 +
89777 + gsi = gsi_for_stmt(stmt);
89778 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89779 + gimple_set_plf(cast_stmt, MY_STMT, true);
89780 + return gimple_get_lhs(cast_stmt);
89781 +}
89782 +
89783 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
89784 +{
89785 + tree lhs;
89786 + gimple_stmt_iterator gsi;
89787 +
89788 + if (rhs1 == NULL_TREE) {
89789 + debug_gimple_stmt(oldstmt);
89790 + error("%s: rhs1 is NULL_TREE", __func__);
89791 + gcc_unreachable();
89792 + }
89793 +
89794 + switch (gimple_code(oldstmt)) {
89795 + case GIMPLE_ASM:
89796 + lhs = rhs1;
89797 + break;
89798 + case GIMPLE_CALL:
89799 + lhs = gimple_call_lhs(oldstmt);
89800 + break;
89801 + case GIMPLE_ASSIGN:
89802 + lhs = gimple_get_lhs(oldstmt);
89803 + break;
89804 + default:
89805 + debug_gimple_stmt(oldstmt);
89806 + gcc_unreachable();
89807 + }
89808 +
89809 + gsi = gsi_for_stmt(oldstmt);
89810 + pointer_set_insert(visited, oldstmt);
89811 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
89812 + basic_block next_bb, cur_bb;
89813 + const_edge e;
89814 +
89815 + gcc_assert(before == false);
89816 + gcc_assert(stmt_can_throw_internal(oldstmt));
89817 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
89818 + gcc_assert(!gsi_end_p(gsi));
89819 +
89820 + cur_bb = gimple_bb(oldstmt);
89821 + next_bb = cur_bb->next_bb;
89822 + e = find_edge(cur_bb, next_bb);
89823 + gcc_assert(e != NULL);
89824 + gcc_assert(e->flags & EDGE_FALLTHRU);
89825 +
89826 + gsi = gsi_after_labels(next_bb);
89827 + gcc_assert(!gsi_end_p(gsi));
89828 +
89829 + before = true;
89830 + oldstmt = gsi_stmt(gsi);
89831 + }
89832 +
89833 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
89834 +}
89835 +
89836 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
89837 +{
89838 + gimple stmt;
89839 + gimple_stmt_iterator gsi;
89840 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
89841 +
89842 + if (gimple_plf(oldstmt, MY_STMT))
89843 + return lhs;
89844 +
89845 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
89846 + rhs1 = gimple_assign_rhs1(oldstmt);
89847 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
89848 + }
89849 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
89850 + rhs2 = gimple_assign_rhs2(oldstmt);
89851 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
89852 + }
89853 +
89854 + stmt = gimple_copy(oldstmt);
89855 + gimple_set_location(stmt, gimple_location(oldstmt));
89856 + gimple_set_plf(stmt, MY_STMT, true);
89857 +
89858 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
89859 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
89860 +
89861 + size_overflow_type = get_size_overflow_type(oldstmt, node);
89862 +
89863 + if (is_bool(lhs))
89864 + new_var = SSA_NAME_VAR(lhs);
89865 + else
89866 + new_var = create_new_var(size_overflow_type);
89867 + new_var = make_ssa_name(new_var, stmt);
89868 + gimple_set_lhs(stmt, new_var);
89869 +
89870 + if (rhs1 != NULL_TREE)
89871 + gimple_assign_set_rhs1(stmt, rhs1);
89872 +
89873 + if (rhs2 != NULL_TREE)
89874 + gimple_assign_set_rhs2(stmt, rhs2);
89875 +#if BUILDING_GCC_VERSION >= 4007
89876 + if (rhs3 != NULL_TREE)
89877 + gimple_assign_set_rhs3(stmt, rhs3);
89878 +#endif
89879 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
89880 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
89881 +
89882 + gsi = gsi_for_stmt(oldstmt);
89883 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
89884 + update_stmt(stmt);
89885 + pointer_set_insert(visited, oldstmt);
89886 + return gimple_get_lhs(stmt);
89887 +}
89888 +
89889 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
89890 +{
89891 + basic_block bb;
89892 + gimple phi;
89893 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
89894 +
89895 + bb = gsi_bb(gsi);
89896 +
89897 + phi = create_phi_node(result, bb);
89898 + gsi = gsi_last(phi_nodes(bb));
89899 + gsi_remove(&gsi, false);
89900 +
89901 + gsi = gsi_for_stmt(oldstmt);
89902 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
89903 + gimple_set_bb(phi, bb);
89904 + gimple_set_plf(phi, MY_STMT, true);
89905 + return phi;
89906 +}
89907 +
89908 +static basic_block create_a_first_bb(void)
89909 +{
89910 + basic_block first_bb;
89911 +
89912 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89913 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
89914 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
89915 + return first_bb;
89916 +}
89917 +
89918 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
89919 +{
89920 + basic_block bb;
89921 + const_gimple newstmt;
89922 + gimple_stmt_iterator gsi;
89923 + bool before = BEFORE_STMT;
89924 +
89925 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
89926 + gsi = gsi_for_stmt(get_def_stmt(arg));
89927 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
89928 + return gimple_get_lhs(newstmt);
89929 + }
89930 +
89931 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
89932 + gsi = gsi_after_labels(bb);
89933 + if (bb->index == 0) {
89934 + bb = create_a_first_bb();
89935 + gsi = gsi_start_bb(bb);
89936 + }
89937 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
89938 + return gimple_get_lhs(newstmt);
89939 +}
89940 +
89941 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
89942 +{
89943 + gimple newstmt;
89944 + gimple_stmt_iterator gsi;
89945 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
89946 + gimple def_newstmt = get_def_stmt(new_rhs);
89947 +
89948 + gsi_insert = gsi_insert_after;
89949 + gsi = gsi_for_stmt(def_newstmt);
89950 +
89951 + switch (gimple_code(get_def_stmt(arg))) {
89952 + case GIMPLE_PHI:
89953 + newstmt = gimple_build_assign(new_var, new_rhs);
89954 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
89955 + gsi_insert = gsi_insert_before;
89956 + break;
89957 + case GIMPLE_ASM:
89958 + case GIMPLE_CALL:
89959 + newstmt = gimple_build_assign(new_var, new_rhs);
89960 + break;
89961 + case GIMPLE_ASSIGN:
89962 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
89963 + break;
89964 + default:
89965 + /* unknown gimple_code (handle_build_new_phi_arg) */
89966 + gcc_unreachable();
89967 + }
89968 +
89969 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
89970 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
89971 + gimple_set_plf(newstmt, MY_STMT, true);
89972 + update_stmt(newstmt);
89973 + return newstmt;
89974 +}
89975 +
89976 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
89977 +{
89978 + const_gimple newstmt;
89979 + gimple def_stmt;
89980 + tree new_rhs;
89981 +
89982 + new_rhs = expand(visited, arg);
89983 + if (new_rhs == NULL_TREE)
89984 + return NULL_TREE;
89985 +
89986 + def_stmt = get_def_stmt(new_rhs);
89987 + if (gimple_code(def_stmt) == GIMPLE_NOP)
89988 + return NULL_TREE;
89989 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
89990 +
89991 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
89992 + return gimple_get_lhs(newstmt);
89993 +}
89994 +
89995 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
89996 +{
89997 + gimple phi, oldstmt = get_def_stmt(orig_result);
89998 + tree new_result, size_overflow_type;
89999 + unsigned int i;
90000 + unsigned int n = gimple_phi_num_args(oldstmt);
90001 +
90002 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
90003 +
90004 + new_result = create_new_var(size_overflow_type);
90005 +
90006 + pointer_set_insert(visited, oldstmt);
90007 + phi = overflow_create_phi_node(oldstmt, new_result);
90008 + for (i = 0; i < n; i++) {
90009 + tree arg, lhs;
90010 +
90011 + arg = gimple_phi_arg_def(oldstmt, i);
90012 + if (is_gimple_constant(arg))
90013 + arg = cast_a_tree(size_overflow_type, arg);
90014 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
90015 + if (lhs == NULL_TREE)
90016 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
90017 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
90018 + }
90019 +
90020 + update_stmt(phi);
90021 + return gimple_phi_result(phi);
90022 +}
90023 +
90024 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
90025 +{
90026 + const_gimple assign;
90027 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90028 + tree origtype = TREE_TYPE(orig_rhs);
90029 +
90030 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
90031 +
90032 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90033 + return gimple_get_lhs(assign);
90034 +}
90035 +
90036 +static void change_rhs1(gimple stmt, tree new_rhs1)
90037 +{
90038 + tree assign_rhs;
90039 + const_tree rhs = gimple_assign_rhs1(stmt);
90040 +
90041 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
90042 + gimple_assign_set_rhs1(stmt, assign_rhs);
90043 + update_stmt(stmt);
90044 +}
90045 +
90046 +static bool check_mode_type(const_gimple stmt)
90047 +{
90048 + const_tree lhs = gimple_get_lhs(stmt);
90049 + const_tree lhs_type = TREE_TYPE(lhs);
90050 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
90051 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
90052 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
90053 +
90054 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
90055 + return false;
90056 +
90057 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
90058 + return false;
90059 +
90060 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
90061 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
90062 + return false;
90063 +
90064 + return true;
90065 +}
90066 +
90067 +static bool check_undefined_integer_operation(const_gimple stmt)
90068 +{
90069 + const_gimple def_stmt;
90070 + const_tree lhs = gimple_get_lhs(stmt);
90071 + const_tree rhs1 = gimple_assign_rhs1(stmt);
90072 + const_tree rhs1_type = TREE_TYPE(rhs1);
90073 + const_tree lhs_type = TREE_TYPE(lhs);
90074 +
90075 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90076 + return false;
90077 +
90078 + def_stmt = get_def_stmt(rhs1);
90079 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
90080 + return false;
90081 +
90082 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
90083 + return false;
90084 + return true;
90085 +}
90086 +
90087 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
90088 +{
90089 + const_tree rhs1, lhs, rhs1_type, lhs_type;
90090 + enum machine_mode lhs_mode, rhs_mode;
90091 + gimple def_stmt = get_def_stmt(no_const_rhs);
90092 +
90093 + if (!gimple_assign_cast_p(def_stmt))
90094 + return false;
90095 +
90096 + rhs1 = gimple_assign_rhs1(def_stmt);
90097 + lhs = gimple_get_lhs(def_stmt);
90098 + rhs1_type = TREE_TYPE(rhs1);
90099 + lhs_type = TREE_TYPE(lhs);
90100 + rhs_mode = TYPE_MODE(rhs1_type);
90101 + lhs_mode = TYPE_MODE(lhs_type);
90102 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
90103 + return false;
90104 +
90105 + return true;
90106 +}
90107 +
90108 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
90109 +{
90110 + tree rhs1 = gimple_assign_rhs1(stmt);
90111 + tree lhs = gimple_get_lhs(stmt);
90112 + const_tree rhs1_type = TREE_TYPE(rhs1);
90113 + const_tree lhs_type = TREE_TYPE(lhs);
90114 +
90115 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90116 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90117 +
90118 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
90119 +}
90120 +
90121 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
90122 +{
90123 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
90124 + tree new_rhs1 = NULL_TREE;
90125 + tree rhs1 = gimple_assign_rhs1(stmt);
90126 + const_tree rhs1_type = TREE_TYPE(rhs1);
90127 + const_tree lhs_type = TREE_TYPE(lhs);
90128 +
90129 + if (gimple_plf(stmt, MY_STMT))
90130 + return lhs;
90131 +
90132 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
90133 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90134 +
90135 + new_rhs1 = expand(visited, rhs1);
90136 +
90137 + if (new_rhs1 == NULL_TREE)
90138 + return create_cast_assign(visited, stmt);
90139 +
90140 + if (gimple_plf(stmt, NO_CAST_CHECK))
90141 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90142 +
90143 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
90144 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90145 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90146 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90147 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90148 + }
90149 +
90150 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
90151 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90152 +
90153 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
90154 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90155 +
90156 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90157 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90158 +
90159 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90160 +
90161 + change_rhs1(stmt, new_rhs1);
90162 +
90163 + if (!check_mode_type(stmt))
90164 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90165 +
90166 + size_overflow_type = get_size_overflow_type(stmt, lhs);
90167 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90168 +
90169 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
90170 +
90171 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90172 +}
90173 +
90174 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
90175 +{
90176 + tree rhs1, lhs = gimple_get_lhs(stmt);
90177 + gimple def_stmt = get_def_stmt(lhs);
90178 +
90179 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
90180 + rhs1 = gimple_assign_rhs1(def_stmt);
90181 +
90182 + if (is_gimple_constant(rhs1))
90183 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90184 +
90185 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
90186 + switch (TREE_CODE(rhs1)) {
90187 + case SSA_NAME:
90188 + return handle_unary_rhs(visited, def_stmt);
90189 + case ARRAY_REF:
90190 + case BIT_FIELD_REF:
90191 + case ADDR_EXPR:
90192 + case COMPONENT_REF:
90193 + case INDIRECT_REF:
90194 +#if BUILDING_GCC_VERSION >= 4006
90195 + case MEM_REF:
90196 +#endif
90197 + case TARGET_MEM_REF:
90198 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90199 + case PARM_DECL:
90200 + case VAR_DECL:
90201 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90202 +
90203 + default:
90204 + debug_gimple_stmt(def_stmt);
90205 + debug_tree(rhs1);
90206 + gcc_unreachable();
90207 + }
90208 +}
90209 +
90210 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
90211 +{
90212 + gimple cond_stmt;
90213 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
90214 +
90215 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
90216 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
90217 + update_stmt(cond_stmt);
90218 +}
90219 +
90220 +static tree create_string_param(tree string)
90221 +{
90222 + tree i_type, a_type;
90223 + const int length = TREE_STRING_LENGTH(string);
90224 +
90225 + gcc_assert(length > 0);
90226 +
90227 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
90228 + a_type = build_array_type(char_type_node, i_type);
90229 +
90230 + TREE_TYPE(string) = a_type;
90231 + TREE_CONSTANT(string) = 1;
90232 + TREE_READONLY(string) = 1;
90233 +
90234 + return build1(ADDR_EXPR, ptr_type_node, string);
90235 +}
90236 +
90237 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
90238 +{
90239 + gimple func_stmt;
90240 + const_gimple def_stmt;
90241 + const_tree loc_line;
90242 + tree loc_file, ssa_name, current_func;
90243 + expanded_location xloc;
90244 + char *ssa_name_buf;
90245 + int len;
90246 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
90247 +
90248 + def_stmt = get_def_stmt(arg);
90249 + xloc = expand_location(gimple_location(def_stmt));
90250 +
90251 + if (!gimple_has_location(def_stmt)) {
90252 + xloc = expand_location(gimple_location(stmt));
90253 + if (!gimple_has_location(stmt))
90254 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
90255 + }
90256 +
90257 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
90258 +
90259 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
90260 + loc_file = create_string_param(loc_file);
90261 +
90262 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
90263 + current_func = create_string_param(current_func);
90264 +
90265 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
90266 + call_count++;
90267 + 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);
90268 + gcc_assert(len > 0);
90269 + ssa_name = build_string(len + 1, ssa_name_buf);
90270 + free(ssa_name_buf);
90271 + ssa_name = create_string_param(ssa_name);
90272 +
90273 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
90274 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
90275 +
90276 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
90277 +}
90278 +
90279 +static void __unused print_the_code_insertions(const_gimple stmt)
90280 +{
90281 + location_t loc = gimple_location(stmt);
90282 +
90283 + inform(loc, "Integer size_overflow check applied here.");
90284 +}
90285 +
90286 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
90287 +{
90288 + basic_block cond_bb, join_bb, bb_true;
90289 + edge e;
90290 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90291 +
90292 + cond_bb = gimple_bb(stmt);
90293 + if (before)
90294 + gsi_prev(&gsi);
90295 + if (gsi_end_p(gsi))
90296 + e = split_block_after_labels(cond_bb);
90297 + else
90298 + e = split_block(cond_bb, gsi_stmt(gsi));
90299 + cond_bb = e->src;
90300 + join_bb = e->dest;
90301 + e->flags = EDGE_FALSE_VALUE;
90302 + e->probability = REG_BR_PROB_BASE;
90303 +
90304 + bb_true = create_empty_bb(cond_bb);
90305 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
90306 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
90307 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
90308 +
90309 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
90310 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
90311 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
90312 +
90313 + if (current_loops != NULL) {
90314 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
90315 + add_bb_to_loop(bb_true, cond_bb->loop_father);
90316 + }
90317 +
90318 + insert_cond(cond_bb, arg, cond_code, type_value);
90319 + insert_cond_result(bb_true, stmt, arg, min);
90320 +
90321 +// print_the_code_insertions(stmt);
90322 +}
90323 +
90324 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
90325 +{
90326 + const_tree rhs_type = TREE_TYPE(rhs);
90327 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
90328 +
90329 + gcc_assert(rhs_type != NULL_TREE);
90330 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
90331 + return;
90332 +
90333 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
90334 +
90335 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
90336 + // typemax (-1) < typemin (0)
90337 + if (TREE_OVERFLOW(type_max))
90338 + return;
90339 +
90340 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
90341 +
90342 + cast_rhs_type = TREE_TYPE(cast_rhs);
90343 + type_max_type = TREE_TYPE(type_max);
90344 + type_min_type = TREE_TYPE(type_min);
90345 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
90346 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
90347 +
90348 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
90349 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
90350 +}
90351 +
90352 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
90353 +{
90354 + gimple change_rhs_def_stmt;
90355 + tree lhs = gimple_get_lhs(def_stmt);
90356 + tree lhs_type = TREE_TYPE(lhs);
90357 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
90358 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
90359 +
90360 + if (change_rhs == NULL_TREE)
90361 + return get_size_overflow_type(def_stmt, lhs);
90362 +
90363 + change_rhs_def_stmt = get_def_stmt(change_rhs);
90364 +
90365 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
90366 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
90367 +
90368 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
90369 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
90370 +
90371 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
90372 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
90373 +
90374 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
90375 + debug_gimple_stmt(def_stmt);
90376 + gcc_unreachable();
90377 + }
90378 +
90379 + return get_size_overflow_type(def_stmt, lhs);
90380 +}
90381 +
90382 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
90383 +{
90384 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
90385 + return false;
90386 + if (!is_gimple_constant(rhs))
90387 + return false;
90388 + return true;
90389 +}
90390 +
90391 +static bool is_subtraction_special(const_gimple stmt)
90392 +{
90393 + gimple rhs1_def_stmt, rhs2_def_stmt;
90394 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
90395 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
90396 + const_tree rhs1 = gimple_assign_rhs1(stmt);
90397 + const_tree rhs2 = gimple_assign_rhs2(stmt);
90398 +
90399 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
90400 + return false;
90401 +
90402 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
90403 +
90404 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
90405 + return false;
90406 +
90407 + rhs1_def_stmt = get_def_stmt(rhs1);
90408 + rhs2_def_stmt = get_def_stmt(rhs2);
90409 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
90410 + return false;
90411 +
90412 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
90413 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
90414 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
90415 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
90416 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
90417 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
90418 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
90419 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
90420 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
90421 + return false;
90422 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
90423 + return false;
90424 +
90425 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
90426 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
90427 + return true;
90428 +}
90429 +
90430 +static tree get_def_stmt_rhs(const_tree var)
90431 +{
90432 + tree rhs1, def_stmt_rhs1;
90433 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
90434 +
90435 + def_stmt = get_def_stmt(var);
90436 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
90437 +
90438 + rhs1 = gimple_assign_rhs1(def_stmt);
90439 + rhs1_def_stmt = get_def_stmt(rhs1);
90440 + if (!gimple_assign_cast_p(rhs1_def_stmt))
90441 + return rhs1;
90442 +
90443 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
90444 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
90445 +
90446 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
90447 + case GIMPLE_CALL:
90448 + case GIMPLE_NOP:
90449 + case GIMPLE_ASM:
90450 + return def_stmt_rhs1;
90451 + case GIMPLE_ASSIGN:
90452 + return rhs1;
90453 + default:
90454 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
90455 + gcc_unreachable();
90456 + }
90457 +}
90458 +
90459 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
90460 +{
90461 + tree new_rhs1, new_rhs2;
90462 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
90463 + gimple assign, stmt = get_def_stmt(lhs);
90464 + tree rhs1 = gimple_assign_rhs1(stmt);
90465 + tree rhs2 = gimple_assign_rhs2(stmt);
90466 +
90467 + if (!is_subtraction_special(stmt))
90468 + return NULL_TREE;
90469 +
90470 + new_rhs1 = expand(visited, rhs1);
90471 + new_rhs2 = expand(visited, rhs2);
90472 +
90473 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
90474 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
90475 +
90476 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
90477 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
90478 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
90479 + }
90480 +
90481 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
90482 + new_lhs = gimple_get_lhs(assign);
90483 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
90484 +
90485 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
90486 +}
90487 +
90488 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
90489 +{
90490 + const_gimple def_stmt;
90491 +
90492 + if (TREE_CODE(rhs) != SSA_NAME)
90493 + return false;
90494 +
90495 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
90496 + return false;
90497 +
90498 + def_stmt = get_def_stmt(rhs);
90499 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
90500 + return false;
90501 +
90502 + return true;
90503 +}
90504 +
90505 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
90506 +{
90507 + tree new_rhs, size_overflow_type, orig_rhs;
90508 + void (*gimple_assign_set_rhs)(gimple, tree);
90509 + tree rhs1 = gimple_assign_rhs1(stmt);
90510 + tree rhs2 = gimple_assign_rhs2(stmt);
90511 + tree lhs = gimple_get_lhs(stmt);
90512 +
90513 + if (change_rhs == NULL_TREE)
90514 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90515 +
90516 + if (new_rhs2 == NULL_TREE) {
90517 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
90518 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
90519 + orig_rhs = rhs1;
90520 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
90521 + } else {
90522 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
90523 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
90524 + orig_rhs = rhs2;
90525 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
90526 + }
90527 +
90528 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
90529 +
90530 + if (check_overflow)
90531 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
90532 +
90533 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
90534 + gimple_assign_set_rhs(stmt, new_rhs);
90535 + update_stmt(stmt);
90536 +
90537 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90538 +}
90539 +
90540 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
90541 +{
90542 + tree rhs1, rhs2, new_lhs;
90543 + gimple def_stmt = get_def_stmt(lhs);
90544 + tree new_rhs1 = NULL_TREE;
90545 + tree new_rhs2 = NULL_TREE;
90546 +
90547 + rhs1 = gimple_assign_rhs1(def_stmt);
90548 + rhs2 = gimple_assign_rhs2(def_stmt);
90549 +
90550 + /* no DImode/TImode division in the 32/64 bit kernel */
90551 + switch (gimple_assign_rhs_code(def_stmt)) {
90552 + case RDIV_EXPR:
90553 + case TRUNC_DIV_EXPR:
90554 + case CEIL_DIV_EXPR:
90555 + case FLOOR_DIV_EXPR:
90556 + case ROUND_DIV_EXPR:
90557 + case TRUNC_MOD_EXPR:
90558 + case CEIL_MOD_EXPR:
90559 + case FLOOR_MOD_EXPR:
90560 + case ROUND_MOD_EXPR:
90561 + case EXACT_DIV_EXPR:
90562 + case POINTER_PLUS_EXPR:
90563 + case BIT_AND_EXPR:
90564 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90565 + default:
90566 + break;
90567 + }
90568 +
90569 + new_lhs = handle_integer_truncation(visited, lhs);
90570 + if (new_lhs != NULL_TREE)
90571 + return new_lhs;
90572 +
90573 + if (TREE_CODE(rhs1) == SSA_NAME)
90574 + new_rhs1 = expand(visited, rhs1);
90575 + if (TREE_CODE(rhs2) == SSA_NAME)
90576 + new_rhs2 = expand(visited, rhs2);
90577 +
90578 + if (is_a_neg_overflow(def_stmt, rhs2))
90579 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
90580 + if (is_a_neg_overflow(def_stmt, rhs1))
90581 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
90582 +
90583 + if (is_a_constant_overflow(def_stmt, rhs2))
90584 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
90585 + if (is_a_constant_overflow(def_stmt, rhs1))
90586 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
90587 +
90588 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
90589 +}
90590 +
90591 +#if BUILDING_GCC_VERSION >= 4007
90592 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
90593 +{
90594 + if (is_gimple_constant(rhs))
90595 + return cast_a_tree(size_overflow_type, rhs);
90596 + if (TREE_CODE(rhs) != SSA_NAME)
90597 + return NULL_TREE;
90598 + return expand(visited, rhs);
90599 +}
90600 +
90601 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
90602 +{
90603 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
90604 + gimple def_stmt = get_def_stmt(lhs);
90605 +
90606 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
90607 +
90608 + rhs1 = gimple_assign_rhs1(def_stmt);
90609 + rhs2 = gimple_assign_rhs2(def_stmt);
90610 + rhs3 = gimple_assign_rhs3(def_stmt);
90611 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
90612 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
90613 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
90614 +
90615 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
90616 +}
90617 +#endif
90618 +
90619 +static tree get_size_overflow_type(gimple stmt, const_tree node)
90620 +{
90621 + const_tree type;
90622 + tree new_type;
90623 +
90624 + gcc_assert(node != NULL_TREE);
90625 +
90626 + type = TREE_TYPE(node);
90627 +
90628 + if (gimple_plf(stmt, MY_STMT))
90629 + return TREE_TYPE(node);
90630 +
90631 + switch (TYPE_MODE(type)) {
90632 + case QImode:
90633 + new_type = intHI_type_node;
90634 + break;
90635 + case HImode:
90636 + new_type = intSI_type_node;
90637 + break;
90638 + case SImode:
90639 + new_type = intDI_type_node;
90640 + break;
90641 + case DImode:
90642 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
90643 + new_type = intDI_type_node;
90644 + else
90645 + new_type = intTI_type_node;
90646 + break;
90647 + default:
90648 + debug_tree((tree)node);
90649 + error("%s: unsupported gcc configuration.", __func__);
90650 + gcc_unreachable();
90651 + }
90652 +
90653 + if (TYPE_QUALS(type) != 0)
90654 + return build_qualified_type(new_type, TYPE_QUALS(type));
90655 + return new_type;
90656 +}
90657 +
90658 +static tree expand_visited(gimple def_stmt)
90659 +{
90660 + const_gimple next_stmt;
90661 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
90662 +
90663 + gsi_next(&gsi);
90664 + next_stmt = gsi_stmt(gsi);
90665 +
90666 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
90667 +
90668 + switch (gimple_code(next_stmt)) {
90669 + case GIMPLE_ASSIGN:
90670 + return gimple_get_lhs(next_stmt);
90671 + case GIMPLE_PHI:
90672 + return gimple_phi_result(next_stmt);
90673 + case GIMPLE_CALL:
90674 + return gimple_call_lhs(next_stmt);
90675 + default:
90676 + return NULL_TREE;
90677 + }
90678 +}
90679 +
90680 +static tree expand(struct pointer_set_t *visited, tree lhs)
90681 +{
90682 + gimple def_stmt;
90683 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
90684 +
90685 + if (is_gimple_constant(lhs))
90686 + return NULL_TREE;
90687 +
90688 + if (TREE_CODE(lhs) == ADDR_EXPR)
90689 + return NULL_TREE;
90690 +
90691 + if (code == REAL_TYPE)
90692 + return NULL_TREE;
90693 +
90694 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
90695 +
90696 + def_stmt = get_def_stmt(lhs);
90697 +
90698 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
90699 + return NULL_TREE;
90700 +
90701 + if (gimple_plf(def_stmt, MY_STMT))
90702 + return lhs;
90703 +
90704 + if (pointer_set_contains(visited, def_stmt))
90705 + return expand_visited(def_stmt);
90706 +
90707 + switch (gimple_code(def_stmt)) {
90708 + case GIMPLE_PHI:
90709 + return build_new_phi(visited, lhs);
90710 + case GIMPLE_CALL:
90711 + case GIMPLE_ASM:
90712 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90713 + case GIMPLE_ASSIGN:
90714 + switch (gimple_num_ops(def_stmt)) {
90715 + case 2:
90716 + return handle_unary_ops(visited, def_stmt);
90717 + case 3:
90718 + return handle_binary_ops(visited, lhs);
90719 +#if BUILDING_GCC_VERSION >= 4007
90720 + case 4:
90721 + return handle_ternary_ops(visited, lhs);
90722 +#endif
90723 + }
90724 + default:
90725 + debug_gimple_stmt(def_stmt);
90726 + error("%s: unknown gimple code", __func__);
90727 + gcc_unreachable();
90728 + }
90729 +}
90730 +
90731 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
90732 +{
90733 + const_gimple assign;
90734 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90735 + tree origtype = TREE_TYPE(origarg);
90736 +
90737 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
90738 +
90739 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90740 +
90741 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
90742 + update_stmt(stmt);
90743 +}
90744 +
90745 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
90746 +{
90747 + const char *origid;
90748 + tree arg;
90749 + const_tree origarg;
90750 +
90751 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
90752 + return true;
90753 +
90754 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
90755 + while (origarg && *argnum) {
90756 + (*argnum)--;
90757 + origarg = TREE_CHAIN(origarg);
90758 + }
90759 +
90760 + gcc_assert(*argnum == 0);
90761 +
90762 + gcc_assert(origarg != NULL_TREE);
90763 + origid = NAME(origarg);
90764 + *argnum = 0;
90765 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
90766 + if (!strcmp(origid, NAME(arg)))
90767 + return true;
90768 + (*argnum)++;
90769 + }
90770 + return false;
90771 +}
90772 +
90773 +static bool skip_types(const_tree var)
90774 +{
90775 + const_tree type;
90776 +
90777 + switch (TREE_CODE(var)) {
90778 + case ADDR_EXPR:
90779 +#if BUILDING_GCC_VERSION >= 4006
90780 + case MEM_REF:
90781 +#endif
90782 + case ARRAY_REF:
90783 + case BIT_FIELD_REF:
90784 + case INDIRECT_REF:
90785 + case TARGET_MEM_REF:
90786 + case VAR_DECL:
90787 + return true;
90788 + default:
90789 + break;
90790 + }
90791 +
90792 + type = TREE_TYPE(TREE_TYPE(var));
90793 + if (!type)
90794 + return false;
90795 + switch (TREE_CODE(type)) {
90796 + case RECORD_TYPE:
90797 + return true;
90798 + default:
90799 + break;
90800 + }
90801 +
90802 + return false;
90803 +}
90804 +
90805 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
90806 +{
90807 + gimple phi = get_def_stmt(result);
90808 + unsigned int i, n = gimple_phi_num_args(phi);
90809 +
90810 + if (!phi)
90811 + return false;
90812 +
90813 + pointer_set_insert(visited, phi);
90814 + for (i = 0; i < n; i++) {
90815 + const_tree arg = gimple_phi_arg_def(phi, i);
90816 + if (pre_expand(visited, arg))
90817 + return true;
90818 + }
90819 + return false;
90820 +}
90821 +
90822 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
90823 +{
90824 + gimple def_stmt = get_def_stmt(lhs);
90825 + const_tree rhs;
90826 +
90827 + if (!def_stmt)
90828 + return false;
90829 +
90830 + rhs = gimple_assign_rhs1(def_stmt);
90831 + if (pre_expand(visited, rhs))
90832 + return true;
90833 + return false;
90834 +}
90835 +
90836 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
90837 +{
90838 + bool rhs1_found, rhs2_found;
90839 + gimple def_stmt = get_def_stmt(lhs);
90840 + const_tree rhs1, rhs2;
90841 +
90842 + if (!def_stmt)
90843 + return false;
90844 +
90845 + rhs1 = gimple_assign_rhs1(def_stmt);
90846 + rhs2 = gimple_assign_rhs2(def_stmt);
90847 + rhs1_found = pre_expand(visited, rhs1);
90848 + rhs2_found = pre_expand(visited, rhs2);
90849 +
90850 + return rhs1_found || rhs2_found;
90851 +}
90852 +
90853 +static const_tree search_field_decl(const_tree comp_ref)
90854 +{
90855 + const_tree field = NULL_TREE;
90856 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
90857 +
90858 + for (i = 0; i < len; i++) {
90859 + field = TREE_OPERAND(comp_ref, i);
90860 + if (TREE_CODE(field) == FIELD_DECL)
90861 + break;
90862 + }
90863 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
90864 + return field;
90865 +}
90866 +
90867 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
90868 +{
90869 + const_tree attr, p;
90870 +
90871 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
90872 + if (!attr || !TREE_VALUE(attr))
90873 + return MARKED_NO;
90874 +
90875 + p = TREE_VALUE(attr);
90876 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
90877 + return MARKED_NOT_INTENTIONAL;
90878 +
90879 + do {
90880 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
90881 + return MARKED_YES;
90882 + p = TREE_CHAIN(p);
90883 + } while (p);
90884 +
90885 + return MARKED_NO;
90886 +}
90887 +
90888 +static void print_missing_msg(tree func, unsigned int argnum)
90889 +{
90890 + unsigned int new_hash;
90891 + size_t len;
90892 + unsigned char tree_codes[CODES_LIMIT];
90893 + location_t loc = DECL_SOURCE_LOCATION(func);
90894 + const char *curfunc = get_asm_name(func);
90895 +
90896 + len = get_function_decl(func, tree_codes);
90897 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
90898 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
90899 +}
90900 +
90901 +static unsigned int search_missing_attribute(const_tree arg)
90902 +{
90903 + const_tree type = TREE_TYPE(arg);
90904 + tree func = get_original_function_decl(current_function_decl);
90905 + unsigned int argnum;
90906 + const struct size_overflow_hash *hash;
90907 +
90908 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
90909 +
90910 + if (TREE_CODE(type) == POINTER_TYPE)
90911 + return 0;
90912 +
90913 + argnum = find_arg_number(arg, func);
90914 + if (argnum == 0)
90915 + return 0;
90916 +
90917 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
90918 + return argnum;
90919 +
90920 + hash = get_function_hash(func);
90921 + if (!hash || !(hash->param & (1U << argnum))) {
90922 + print_missing_msg(func, argnum);
90923 + return 0;
90924 + }
90925 + return argnum;
90926 +}
90927 +
90928 +static bool is_already_marked(const_tree lhs)
90929 +{
90930 + unsigned int argnum;
90931 + const_tree fndecl;
90932 +
90933 + argnum = search_missing_attribute(lhs);
90934 + fndecl = get_original_function_decl(current_function_decl);
90935 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
90936 + return true;
90937 + return false;
90938 +}
90939 +
90940 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
90941 +{
90942 + const_gimple def_stmt;
90943 +
90944 + if (is_gimple_constant(lhs))
90945 + return false;
90946 +
90947 + if (skip_types(lhs))
90948 + return false;
90949 +
90950 + // skip char type (FIXME: only kernel)
90951 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
90952 + return false;
90953 +
90954 + if (TREE_CODE(lhs) == PARM_DECL)
90955 + return is_already_marked(lhs);
90956 +
90957 + if (TREE_CODE(lhs) == COMPONENT_REF) {
90958 + const_tree field, attr;
90959 +
90960 + field = search_field_decl(lhs);
90961 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
90962 + if (!attr || !TREE_VALUE(attr))
90963 + return false;
90964 + return true;
90965 + }
90966 +
90967 + def_stmt = get_def_stmt(lhs);
90968 +
90969 + if (!def_stmt)
90970 + return false;
90971 +
90972 + if (pointer_set_contains(visited, def_stmt))
90973 + return false;
90974 +
90975 + switch (gimple_code(def_stmt)) {
90976 + case GIMPLE_NOP:
90977 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
90978 + return is_already_marked(lhs);
90979 + return false;
90980 + case GIMPLE_PHI:
90981 + return walk_phi(visited, lhs);
90982 + case GIMPLE_CALL:
90983 + case GIMPLE_ASM:
90984 + return false;
90985 + case GIMPLE_ASSIGN:
90986 + switch (gimple_num_ops(def_stmt)) {
90987 + case 2:
90988 + return walk_unary_ops(visited, lhs);
90989 + case 3:
90990 + return walk_binary_ops(visited, lhs);
90991 + }
90992 + default:
90993 + debug_gimple_stmt((gimple)def_stmt);
90994 + error("%s: unknown gimple code", __func__);
90995 + gcc_unreachable();
90996 + }
90997 +}
90998 +
90999 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
91000 +{
91001 + struct pointer_set_t *visited;
91002 + bool is_found;
91003 + enum marked is_marked;
91004 + location_t loc;
91005 +
91006 + visited = pointer_set_create();
91007 + is_found = pre_expand(visited, arg);
91008 + pointer_set_destroy(visited);
91009 +
91010 + is_marked = mark_status(fndecl, argnum + 1);
91011 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
91012 + return true;
91013 +
91014 + if (is_found) {
91015 + loc = DECL_SOURCE_LOCATION(fndecl);
91016 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
91017 + return true;
91018 + }
91019 + return false;
91020 +}
91021 +
91022 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
91023 +{
91024 + struct pointer_set_t *visited;
91025 + tree arg, newarg;
91026 + bool match;
91027 +
91028 + match = get_function_arg(&argnum, fndecl);
91029 + if (!match)
91030 + return;
91031 + gcc_assert(gimple_call_num_args(stmt) > argnum);
91032 + arg = gimple_call_arg(stmt, argnum);
91033 + if (arg == NULL_TREE)
91034 + return;
91035 +
91036 + if (is_gimple_constant(arg))
91037 + return;
91038 +
91039 + if (search_attributes(fndecl, arg, argnum))
91040 + return;
91041 +
91042 + if (TREE_CODE(arg) != SSA_NAME)
91043 + return;
91044 +
91045 + check_arg_type(arg);
91046 +
91047 + visited = pointer_set_create();
91048 + newarg = expand(visited, arg);
91049 + pointer_set_destroy(visited);
91050 +
91051 + if (newarg == NULL_TREE)
91052 + return;
91053 +
91054 + change_function_arg(stmt, arg, argnum, newarg);
91055 +
91056 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
91057 +}
91058 +
91059 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
91060 +{
91061 + tree p = TREE_VALUE(attr);
91062 + do {
91063 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
91064 + p = TREE_CHAIN(p);
91065 + } while (p);
91066 +}
91067 +
91068 +static void handle_function_by_hash(gimple stmt, tree fndecl)
91069 +{
91070 + tree orig_fndecl;
91071 + unsigned int num;
91072 + const struct size_overflow_hash *hash;
91073 +
91074 + orig_fndecl = get_original_function_decl(fndecl);
91075 + if (C_DECL_IMPLICIT(orig_fndecl))
91076 + return;
91077 + hash = get_function_hash(orig_fndecl);
91078 + if (!hash)
91079 + return;
91080 +
91081 + for (num = 1; num <= MAX_PARAM; num++)
91082 + if (hash->param & (1U << num))
91083 + handle_function_arg(stmt, fndecl, num - 1);
91084 +}
91085 +
91086 +static void set_plf_false(void)
91087 +{
91088 + basic_block bb;
91089 +
91090 + FOR_ALL_BB(bb) {
91091 + gimple_stmt_iterator si;
91092 +
91093 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
91094 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91095 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
91096 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91097 + }
91098 +}
91099 +
91100 +static unsigned int handle_function(void)
91101 +{
91102 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
91103 +
91104 + set_plf_false();
91105 +
91106 + do {
91107 + gimple_stmt_iterator gsi;
91108 + next = bb->next_bb;
91109 +
91110 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
91111 + tree fndecl, attr;
91112 + gimple stmt = gsi_stmt(gsi);
91113 +
91114 + if (!(is_gimple_call(stmt)))
91115 + continue;
91116 + fndecl = gimple_call_fndecl(stmt);
91117 + if (fndecl == NULL_TREE)
91118 + continue;
91119 + if (gimple_call_num_args(stmt) == 0)
91120 + continue;
91121 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
91122 + if (!attr || !TREE_VALUE(attr))
91123 + handle_function_by_hash(stmt, fndecl);
91124 + else
91125 + handle_function_by_attribute(stmt, attr, fndecl);
91126 + gsi = gsi_for_stmt(stmt);
91127 + next = gimple_bb(stmt)->next_bb;
91128 + }
91129 + bb = next;
91130 + } while (bb);
91131 + return 0;
91132 +}
91133 +
91134 +static struct gimple_opt_pass size_overflow_pass = {
91135 + .pass = {
91136 + .type = GIMPLE_PASS,
91137 + .name = "size_overflow",
91138 + .gate = NULL,
91139 + .execute = handle_function,
91140 + .sub = NULL,
91141 + .next = NULL,
91142 + .static_pass_number = 0,
91143 + .tv_id = TV_NONE,
91144 + .properties_required = PROP_cfg | PROP_referenced_vars,
91145 + .properties_provided = 0,
91146 + .properties_destroyed = 0,
91147 + .todo_flags_start = 0,
91148 + .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
91149 + }
91150 +};
91151 +
91152 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
91153 +{
91154 + tree fntype;
91155 +
91156 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
91157 +
91158 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
91159 + fntype = build_function_type_list(void_type_node,
91160 + const_char_ptr_type_node,
91161 + unsigned_type_node,
91162 + const_char_ptr_type_node,
91163 + const_char_ptr_type_node,
91164 + NULL_TREE);
91165 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
91166 +
91167 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
91168 + TREE_PUBLIC(report_size_overflow_decl) = 1;
91169 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
91170 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
91171 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
91172 +}
91173 +
91174 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91175 +{
91176 + int i;
91177 + const char * const plugin_name = plugin_info->base_name;
91178 + const int argc = plugin_info->argc;
91179 + const struct plugin_argument * const argv = plugin_info->argv;
91180 + bool enable = true;
91181 +
91182 + struct register_pass_info size_overflow_pass_info = {
91183 + .pass = &size_overflow_pass.pass,
91184 + .reference_pass_name = "ssa",
91185 + .ref_pass_instance_number = 1,
91186 + .pos_op = PASS_POS_INSERT_AFTER
91187 + };
91188 +
91189 + if (!plugin_default_version_check(version, &gcc_version)) {
91190 + error(G_("incompatible gcc/plugin versions"));
91191 + return 1;
91192 + }
91193 +
91194 + for (i = 0; i < argc; ++i) {
91195 + if (!strcmp(argv[i].key, "no-size-overflow")) {
91196 + enable = false;
91197 + continue;
91198 + }
91199 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91200 + }
91201 +
91202 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
91203 + if (enable) {
91204 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
91205 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
91206 + }
91207 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
91208 +
91209 + return 0;
91210 +}
91211 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
91212 new file mode 100644
91213 index 0000000..38d2014
91214 --- /dev/null
91215 +++ b/tools/gcc/stackleak_plugin.c
91216 @@ -0,0 +1,313 @@
91217 +/*
91218 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
91219 + * Licensed under the GPL v2
91220 + *
91221 + * Note: the choice of the license means that the compilation process is
91222 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91223 + * but for the kernel it doesn't matter since it doesn't link against
91224 + * any of the gcc libraries
91225 + *
91226 + * gcc plugin to help implement various PaX features
91227 + *
91228 + * - track lowest stack pointer
91229 + *
91230 + * TODO:
91231 + * - initialize all local variables
91232 + *
91233 + * BUGS:
91234 + * - none known
91235 + */
91236 +#include "gcc-plugin.h"
91237 +#include "config.h"
91238 +#include "system.h"
91239 +#include "coretypes.h"
91240 +#include "tree.h"
91241 +#include "tree-pass.h"
91242 +#include "flags.h"
91243 +#include "intl.h"
91244 +#include "toplev.h"
91245 +#include "plugin.h"
91246 +//#include "expr.h" where are you...
91247 +#include "diagnostic.h"
91248 +#include "plugin-version.h"
91249 +#include "tm.h"
91250 +#include "function.h"
91251 +#include "basic-block.h"
91252 +#include "gimple.h"
91253 +#include "rtl.h"
91254 +#include "emit-rtl.h"
91255 +
91256 +extern void print_gimple_stmt(FILE *, gimple, int, int);
91257 +
91258 +int plugin_is_GPL_compatible;
91259 +
91260 +static int track_frame_size = -1;
91261 +static const char track_function[] = "pax_track_stack";
91262 +static const char check_function[] = "pax_check_alloca";
91263 +static bool init_locals;
91264 +
91265 +static struct plugin_info stackleak_plugin_info = {
91266 + .version = "201203140940",
91267 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
91268 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
91269 +};
91270 +
91271 +static bool gate_stackleak_track_stack(void);
91272 +static unsigned int execute_stackleak_tree_instrument(void);
91273 +static unsigned int execute_stackleak_final(void);
91274 +
91275 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
91276 + .pass = {
91277 + .type = GIMPLE_PASS,
91278 + .name = "stackleak_tree_instrument",
91279 + .gate = gate_stackleak_track_stack,
91280 + .execute = execute_stackleak_tree_instrument,
91281 + .sub = NULL,
91282 + .next = NULL,
91283 + .static_pass_number = 0,
91284 + .tv_id = TV_NONE,
91285 + .properties_required = PROP_gimple_leh | PROP_cfg,
91286 + .properties_provided = 0,
91287 + .properties_destroyed = 0,
91288 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
91289 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
91290 + }
91291 +};
91292 +
91293 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
91294 + .pass = {
91295 + .type = RTL_PASS,
91296 + .name = "stackleak_final",
91297 + .gate = gate_stackleak_track_stack,
91298 + .execute = execute_stackleak_final,
91299 + .sub = NULL,
91300 + .next = NULL,
91301 + .static_pass_number = 0,
91302 + .tv_id = TV_NONE,
91303 + .properties_required = 0,
91304 + .properties_provided = 0,
91305 + .properties_destroyed = 0,
91306 + .todo_flags_start = 0,
91307 + .todo_flags_finish = TODO_dump_func
91308 + }
91309 +};
91310 +
91311 +static bool gate_stackleak_track_stack(void)
91312 +{
91313 + return track_frame_size >= 0;
91314 +}
91315 +
91316 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
91317 +{
91318 + gimple check_alloca;
91319 + tree fntype, fndecl, alloca_size;
91320 +
91321 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
91322 + fndecl = build_fn_decl(check_function, fntype);
91323 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
91324 +
91325 + // insert call to void pax_check_alloca(unsigned long size)
91326 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
91327 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
91328 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
91329 +}
91330 +
91331 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
91332 +{
91333 + gimple track_stack;
91334 + tree fntype, fndecl;
91335 +
91336 + fntype = build_function_type_list(void_type_node, NULL_TREE);
91337 + fndecl = build_fn_decl(track_function, fntype);
91338 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
91339 +
91340 + // insert call to void pax_track_stack(void)
91341 + track_stack = gimple_build_call(fndecl, 0);
91342 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
91343 +}
91344 +
91345 +#if BUILDING_GCC_VERSION == 4005
91346 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
91347 +{
91348 + tree fndecl;
91349 +
91350 + if (!is_gimple_call(stmt))
91351 + return false;
91352 + fndecl = gimple_call_fndecl(stmt);
91353 + if (!fndecl)
91354 + return false;
91355 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
91356 + return false;
91357 +// print_node(stderr, "pax", fndecl, 4);
91358 + return DECL_FUNCTION_CODE(fndecl) == code;
91359 +}
91360 +#endif
91361 +
91362 +static bool is_alloca(gimple stmt)
91363 +{
91364 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
91365 + return true;
91366 +
91367 +#if BUILDING_GCC_VERSION >= 4007
91368 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
91369 + return true;
91370 +#endif
91371 +
91372 + return false;
91373 +}
91374 +
91375 +static unsigned int execute_stackleak_tree_instrument(void)
91376 +{
91377 + basic_block bb, entry_bb;
91378 + bool prologue_instrumented = false, is_leaf = true;
91379 +
91380 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
91381 +
91382 + // 1. loop through BBs and GIMPLE statements
91383 + FOR_EACH_BB(bb) {
91384 + gimple_stmt_iterator gsi;
91385 +
91386 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
91387 + gimple stmt;
91388 +
91389 + stmt = gsi_stmt(gsi);
91390 +
91391 + if (is_gimple_call(stmt))
91392 + is_leaf = false;
91393 +
91394 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
91395 + if (!is_alloca(stmt))
91396 + continue;
91397 +
91398 + // 2. insert stack overflow check before each __builtin_alloca call
91399 + stackleak_check_alloca(&gsi);
91400 +
91401 + // 3. insert track call after each __builtin_alloca call
91402 + stackleak_add_instrumentation(&gsi);
91403 + if (bb == entry_bb)
91404 + prologue_instrumented = true;
91405 + }
91406 + }
91407 +
91408 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
91409 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
91410 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
91411 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
91412 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
91413 + return 0;
91414 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
91415 + return 0;
91416 +
91417 + // 4. insert track call at the beginning
91418 + if (!prologue_instrumented) {
91419 + gimple_stmt_iterator gsi;
91420 +
91421 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
91422 + if (dom_info_available_p(CDI_DOMINATORS))
91423 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
91424 + gsi = gsi_start_bb(bb);
91425 + stackleak_add_instrumentation(&gsi);
91426 + }
91427 +
91428 + return 0;
91429 +}
91430 +
91431 +static unsigned int execute_stackleak_final(void)
91432 +{
91433 + rtx insn;
91434 +
91435 + if (cfun->calls_alloca)
91436 + return 0;
91437 +
91438 + // keep calls only if function frame is big enough
91439 + if (get_frame_size() >= track_frame_size)
91440 + return 0;
91441 +
91442 + // 1. find pax_track_stack calls
91443 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
91444 + // 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))
91445 + rtx body;
91446 +
91447 + if (!CALL_P(insn))
91448 + continue;
91449 + body = PATTERN(insn);
91450 + if (GET_CODE(body) != CALL)
91451 + continue;
91452 + body = XEXP(body, 0);
91453 + if (GET_CODE(body) != MEM)
91454 + continue;
91455 + body = XEXP(body, 0);
91456 + if (GET_CODE(body) != SYMBOL_REF)
91457 + continue;
91458 + if (strcmp(XSTR(body, 0), track_function))
91459 + continue;
91460 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
91461 + // 2. delete call
91462 + insn = delete_insn_and_edges(insn);
91463 +#if BUILDING_GCC_VERSION >= 4007
91464 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
91465 + insn = delete_insn_and_edges(insn);
91466 +#endif
91467 + }
91468 +
91469 +// print_simple_rtl(stderr, get_insns());
91470 +// print_rtl(stderr, get_insns());
91471 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
91472 +
91473 + return 0;
91474 +}
91475 +
91476 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91477 +{
91478 + const char * const plugin_name = plugin_info->base_name;
91479 + const int argc = plugin_info->argc;
91480 + const struct plugin_argument * const argv = plugin_info->argv;
91481 + int i;
91482 + struct register_pass_info stackleak_tree_instrument_pass_info = {
91483 + .pass = &stackleak_tree_instrument_pass.pass,
91484 +// .reference_pass_name = "tree_profile",
91485 + .reference_pass_name = "optimized",
91486 + .ref_pass_instance_number = 1,
91487 + .pos_op = PASS_POS_INSERT_BEFORE
91488 + };
91489 + struct register_pass_info stackleak_final_pass_info = {
91490 + .pass = &stackleak_final_rtl_opt_pass.pass,
91491 + .reference_pass_name = "final",
91492 + .ref_pass_instance_number = 1,
91493 + .pos_op = PASS_POS_INSERT_BEFORE
91494 + };
91495 +
91496 + if (!plugin_default_version_check(version, &gcc_version)) {
91497 + error(G_("incompatible gcc/plugin versions"));
91498 + return 1;
91499 + }
91500 +
91501 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
91502 +
91503 + for (i = 0; i < argc; ++i) {
91504 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
91505 + if (!argv[i].value) {
91506 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91507 + continue;
91508 + }
91509 + track_frame_size = atoi(argv[i].value);
91510 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
91511 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
91512 + continue;
91513 + }
91514 + if (!strcmp(argv[i].key, "initialize-locals")) {
91515 + if (argv[i].value) {
91516 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
91517 + continue;
91518 + }
91519 + init_locals = true;
91520 + continue;
91521 + }
91522 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91523 + }
91524 +
91525 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
91526 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
91527 +
91528 + return 0;
91529 +}
91530 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
91531 index 6789d78..4afd019e 100644
91532 --- a/tools/perf/util/include/asm/alternative-asm.h
91533 +++ b/tools/perf/util/include/asm/alternative-asm.h
91534 @@ -5,4 +5,7 @@
91535
91536 #define altinstruction_entry #
91537
91538 + .macro pax_force_retaddr rip=0, reload=0
91539 + .endm
91540 +
91541 #endif
91542 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
91543 index 6e8fa7e..37f02a5 100644
91544 --- a/virt/kvm/kvm_main.c
91545 +++ b/virt/kvm/kvm_main.c
91546 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
91547
91548 static cpumask_var_t cpus_hardware_enabled;
91549 static int kvm_usage_count = 0;
91550 -static atomic_t hardware_enable_failed;
91551 +static atomic_unchecked_t hardware_enable_failed;
91552
91553 struct kmem_cache *kvm_vcpu_cache;
91554 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
91555
91556 -static __read_mostly struct preempt_ops kvm_preempt_ops;
91557 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
91558 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
91559 +static struct preempt_ops kvm_preempt_ops = {
91560 + .sched_in = kvm_sched_in,
91561 + .sched_out = kvm_sched_out,
91562 +};
91563
91564 struct dentry *kvm_debugfs_dir;
91565
91566 @@ -726,7 +731,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
91567 /* We can read the guest memory with __xxx_user() later on. */
91568 if (user_alloc &&
91569 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
91570 - !access_ok(VERIFY_WRITE,
91571 + !__access_ok(VERIFY_WRITE,
91572 (void __user *)(unsigned long)mem->userspace_addr,
91573 mem->memory_size)))
91574 goto out;
91575 @@ -2450,7 +2455,7 @@ static void hardware_enable_nolock(void *junk)
91576
91577 if (r) {
91578 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
91579 - atomic_inc(&hardware_enable_failed);
91580 + atomic_inc_unchecked(&hardware_enable_failed);
91581 printk(KERN_INFO "kvm: enabling virtualization on "
91582 "CPU%d failed\n", cpu);
91583 }
91584 @@ -2504,10 +2509,10 @@ static int hardware_enable_all(void)
91585
91586 kvm_usage_count++;
91587 if (kvm_usage_count == 1) {
91588 - atomic_set(&hardware_enable_failed, 0);
91589 + atomic_set_unchecked(&hardware_enable_failed, 0);
91590 on_each_cpu(hardware_enable_nolock, NULL, 1);
91591
91592 - if (atomic_read(&hardware_enable_failed)) {
91593 + if (atomic_read_unchecked(&hardware_enable_failed)) {
91594 hardware_disable_all_nolock();
91595 r = -EBUSY;
91596 }
91597 @@ -2865,7 +2870,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
91598 kvm_arch_vcpu_put(vcpu);
91599 }
91600
91601 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
91602 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
91603 struct module *module)
91604 {
91605 int r;
91606 @@ -2901,7 +2906,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
91607 if (!vcpu_align)
91608 vcpu_align = __alignof__(struct kvm_vcpu);
91609 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
91610 - 0, NULL);
91611 + SLAB_USERCOPY, NULL);
91612 if (!kvm_vcpu_cache) {
91613 r = -ENOMEM;
91614 goto out_free_3;
91615 @@ -2911,9 +2916,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
91616 if (r)
91617 goto out_free;
91618
91619 - kvm_chardev_ops.owner = module;
91620 - kvm_vm_fops.owner = module;
91621 - kvm_vcpu_fops.owner = module;
91622 + pax_open_kernel();
91623 + *(void **)&kvm_chardev_ops.owner = module;
91624 + *(void **)&kvm_vm_fops.owner = module;
91625 + *(void **)&kvm_vcpu_fops.owner = module;
91626 + pax_close_kernel();
91627
91628 r = misc_register(&kvm_dev);
91629 if (r) {
91630 @@ -2923,9 +2930,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
91631
91632 register_syscore_ops(&kvm_syscore_ops);
91633
91634 - kvm_preempt_ops.sched_in = kvm_sched_in;
91635 - kvm_preempt_ops.sched_out = kvm_sched_out;
91636 -
91637 r = kvm_init_debug();
91638 if (r) {
91639 printk(KERN_ERR "kvm: create debugfs files failed\n");